@moxt-ai/cli 0.10.0-beta.5 → 0.10.0-beta.7
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 +12 -2
- package/dist/index.cjs +2128 -523
- package/dist/index.cjs.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1174,18 +1174,18 @@ var require_suggestSimilar = __commonJS({
|
|
|
1174
1174
|
}
|
|
1175
1175
|
return d[a.length][b.length];
|
|
1176
1176
|
}
|
|
1177
|
-
function suggestSimilar(word,
|
|
1178
|
-
if (!
|
|
1179
|
-
|
|
1177
|
+
function suggestSimilar(word, candidates2) {
|
|
1178
|
+
if (!candidates2 || candidates2.length === 0) return "";
|
|
1179
|
+
candidates2 = Array.from(new Set(candidates2));
|
|
1180
1180
|
const searchingOptions = word.startsWith("--");
|
|
1181
1181
|
if (searchingOptions) {
|
|
1182
1182
|
word = word.slice(2);
|
|
1183
|
-
|
|
1183
|
+
candidates2 = candidates2.map((candidate) => candidate.slice(2));
|
|
1184
1184
|
}
|
|
1185
1185
|
let similar = [];
|
|
1186
1186
|
let bestDistance = maxDistance;
|
|
1187
1187
|
const minSimilarity = 0.4;
|
|
1188
|
-
|
|
1188
|
+
candidates2.forEach((candidate) => {
|
|
1189
1189
|
if (candidate.length <= 1) return;
|
|
1190
1190
|
const distance = editDistance(word, candidate);
|
|
1191
1191
|
const length = Math.max(word.length, candidate.length);
|
|
@@ -4356,7 +4356,7 @@ function assertClientRequestId(clientRequestId) {
|
|
|
4356
4356
|
}
|
|
4357
4357
|
}
|
|
4358
4358
|
function assertRelativeWorkingDirectory(relativeWorkingDirectory) {
|
|
4359
|
-
if (relativeWorkingDirectory.length === 0 || relativeWorkingDirectory.includes("\0") || (0,
|
|
4359
|
+
if (relativeWorkingDirectory.length === 0 || relativeWorkingDirectory.includes("\0") || (0, import_node_path2.isAbsolute)(relativeWorkingDirectory) || import_node_path2.win32.isAbsolute(relativeWorkingDirectory) || windowsDrivePattern.test(relativeWorkingDirectory)) {
|
|
4360
4360
|
throwRootViolation(relativeWorkingDirectory);
|
|
4361
4361
|
}
|
|
4362
4362
|
const pathSegments = relativeWorkingDirectory.split(/[\\/]/);
|
|
@@ -4365,14 +4365,14 @@ function assertRelativeWorkingDirectory(relativeWorkingDirectory) {
|
|
|
4365
4365
|
}
|
|
4366
4366
|
}
|
|
4367
4367
|
function resolveWorkingDirectory(rootPath, relativeWorkingDirectory) {
|
|
4368
|
-
if (!(0,
|
|
4368
|
+
if (!(0, import_node_path2.isAbsolute)(rootPath)) {
|
|
4369
4369
|
throw new MachineProtocolInvariantError(MachineProtocolErrorCode.RootViolation, "The paired working root must be an absolute path");
|
|
4370
4370
|
}
|
|
4371
4371
|
assertRelativeWorkingDirectory(relativeWorkingDirectory);
|
|
4372
|
-
const resolvedRoot = (0,
|
|
4373
|
-
const resolvedWorkingDirectory = (0,
|
|
4374
|
-
const pathFromRoot = (0,
|
|
4375
|
-
if (pathFromRoot === ".." || pathFromRoot.startsWith(`..${
|
|
4372
|
+
const resolvedRoot = (0, import_node_path2.resolve)(rootPath);
|
|
4373
|
+
const resolvedWorkingDirectory = (0, import_node_path2.resolve)(resolvedRoot, relativeWorkingDirectory);
|
|
4374
|
+
const pathFromRoot = (0, import_node_path2.relative)(resolvedRoot, resolvedWorkingDirectory);
|
|
4375
|
+
if (pathFromRoot === ".." || pathFromRoot.startsWith(`..${import_node_path2.sep}`) || (0, import_node_path2.isAbsolute)(pathFromRoot)) {
|
|
4376
4376
|
throwRootViolation(relativeWorkingDirectory);
|
|
4377
4377
|
}
|
|
4378
4378
|
return resolvedWorkingDirectory;
|
|
@@ -4420,12 +4420,12 @@ function throwRootViolation(relativeWorkingDirectory) {
|
|
|
4420
4420
|
function throwEventSequenceConflict(message) {
|
|
4421
4421
|
throw new MachineProtocolInvariantError(MachineProtocolErrorCode.EventSequenceConflict, message);
|
|
4422
4422
|
}
|
|
4423
|
-
var
|
|
4423
|
+
var import_node_path2, minimumClientRequestIdLength, maximumClientRequestIdLength, minimumWaitTimeoutSeconds, maximumWaitTimeoutSeconds, clientRequestIdPattern, windowsDrivePattern, terminalJobStatuses, validJobTransitions, MachineProtocolInvariantError;
|
|
4424
4424
|
var init_invariants = __esm({
|
|
4425
4425
|
"../machine-connector/dist/protocol/v1/invariants.js"() {
|
|
4426
4426
|
"use strict";
|
|
4427
4427
|
init_cjs_shims();
|
|
4428
|
-
|
|
4428
|
+
import_node_path2 = require("path");
|
|
4429
4429
|
init_contracts();
|
|
4430
4430
|
init_enums();
|
|
4431
4431
|
minimumClientRequestIdLength = 8;
|
|
@@ -4508,7 +4508,7 @@ async function executeProcess(executable, argumentsList, workingDirectory, envir
|
|
|
4508
4508
|
}
|
|
4509
4509
|
const child = (0, import_node_child_process.spawn)(executable, argumentsList, {
|
|
4510
4510
|
cwd: workingDirectory,
|
|
4511
|
-
detached: (0,
|
|
4511
|
+
detached: (0, import_node_os2.platform)() !== "win32",
|
|
4512
4512
|
env: { ...environment },
|
|
4513
4513
|
shell: false,
|
|
4514
4514
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -4642,17 +4642,17 @@ async function executeProcess(executable, argumentsList, workingDirectory, envir
|
|
|
4642
4642
|
};
|
|
4643
4643
|
}
|
|
4644
4644
|
async function resolveCanonicalWorkingDirectory(rootPath, relativeWorkingDirectory) {
|
|
4645
|
-
const canonicalRoot = await (0,
|
|
4645
|
+
const canonicalRoot = await (0, import_promises4.realpath)(rootPath);
|
|
4646
4646
|
const lexicalCandidate = resolveWorkingDirectory(canonicalRoot, relativeWorkingDirectory);
|
|
4647
|
-
const canonicalCandidate = await (0,
|
|
4648
|
-
const relativePath = (0,
|
|
4649
|
-
if (relativePath === ".." || relativePath.startsWith(`..${
|
|
4647
|
+
const canonicalCandidate = await (0, import_promises4.realpath)(lexicalCandidate);
|
|
4648
|
+
const relativePath = (0, import_node_path3.relative)(canonicalRoot, canonicalCandidate);
|
|
4649
|
+
if (relativePath === ".." || relativePath.startsWith(`..${import_node_path3.sep}`) || (0, import_node_path3.isAbsolute)(relativePath)) {
|
|
4650
4650
|
throw new Error(`Working directory escapes paired root: ${relativeWorkingDirectory}`);
|
|
4651
4651
|
}
|
|
4652
4652
|
return canonicalCandidate;
|
|
4653
4653
|
}
|
|
4654
4654
|
async function terminateProcessTree(pid) {
|
|
4655
|
-
if ((0,
|
|
4655
|
+
if ((0, import_node_os2.platform)() === "win32") {
|
|
4656
4656
|
const process2 = (0, import_node_child_process.spawn)("taskkill", ["/pid", String(pid), "/t", "/f"], {
|
|
4657
4657
|
stdio: "ignore",
|
|
4658
4658
|
windowsHide: true
|
|
@@ -4702,15 +4702,15 @@ function delay(milliseconds) {
|
|
|
4702
4702
|
setTimeout(resolvePromise, milliseconds);
|
|
4703
4703
|
});
|
|
4704
4704
|
}
|
|
4705
|
-
var import_node_child_process,
|
|
4705
|
+
var import_node_child_process, import_promises4, import_node_os2, import_node_path3, cancellationDeadlineMilliseconds, RunningProcessHandle;
|
|
4706
4706
|
var init_process_executor = __esm({
|
|
4707
4707
|
"../machine-connector/dist/runtime/process-executor.js"() {
|
|
4708
4708
|
"use strict";
|
|
4709
4709
|
init_cjs_shims();
|
|
4710
4710
|
import_node_child_process = require("child_process");
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4711
|
+
import_promises4 = require("fs/promises");
|
|
4712
|
+
import_node_os2 = require("os");
|
|
4713
|
+
import_node_path3 = require("path");
|
|
4714
4714
|
init_enums();
|
|
4715
4715
|
init_invariants();
|
|
4716
4716
|
cancellationDeadlineMilliseconds = 4e3;
|
|
@@ -5038,7 +5038,7 @@ async function executeCodex(workingDirectory, outputPath, environment, arguments
|
|
|
5038
5038
|
}
|
|
5039
5039
|
}
|
|
5040
5040
|
const finalMessage = (await readOptionalOutput(outputPath)).value;
|
|
5041
|
-
await (0,
|
|
5041
|
+
await (0, import_promises5.rm)(outputPath, { force: true });
|
|
5042
5042
|
return {
|
|
5043
5043
|
...result,
|
|
5044
5044
|
finalMessage,
|
|
@@ -5104,7 +5104,7 @@ function extractCodexFailureMessage(event2) {
|
|
|
5104
5104
|
return {};
|
|
5105
5105
|
}
|
|
5106
5106
|
function createOutputPath(runtimeDirectory) {
|
|
5107
|
-
return (0,
|
|
5107
|
+
return (0, import_node_path4.join)(runtimeDirectory, `codex-last-message-${(0, import_node_crypto2.randomUUID)()}.txt`);
|
|
5108
5108
|
}
|
|
5109
5109
|
function parseCodexEvent(line) {
|
|
5110
5110
|
const trimmed = line.trim();
|
|
@@ -5138,9 +5138,9 @@ function extractThreadId(event2) {
|
|
|
5138
5138
|
}
|
|
5139
5139
|
async function readOptionalOutput(path4) {
|
|
5140
5140
|
try {
|
|
5141
|
-
return { value: (await (0,
|
|
5141
|
+
return { value: (await (0, import_promises5.readFile)(path4, "utf8")).trim() };
|
|
5142
5142
|
} catch (error) {
|
|
5143
|
-
if (
|
|
5143
|
+
if (isNodeErrorCode2(error, "ENOENT")) {
|
|
5144
5144
|
return {};
|
|
5145
5145
|
}
|
|
5146
5146
|
throw error;
|
|
@@ -5149,7 +5149,7 @@ async function readOptionalOutput(path4) {
|
|
|
5149
5149
|
function isRecord2(value) {
|
|
5150
5150
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5151
5151
|
}
|
|
5152
|
-
function
|
|
5152
|
+
function isNodeErrorCode2(error, expectedCode) {
|
|
5153
5153
|
if (!(error instanceof Error) || !("code" in error)) {
|
|
5154
5154
|
return false;
|
|
5155
5155
|
}
|
|
@@ -5160,13 +5160,13 @@ function delay2(milliseconds) {
|
|
|
5160
5160
|
setTimeout(resolvePromise, milliseconds);
|
|
5161
5161
|
});
|
|
5162
5162
|
}
|
|
5163
|
-
var
|
|
5163
|
+
var import_promises5, import_node_path4, import_node_crypto2, codexProcessExitGraceMilliseconds;
|
|
5164
5164
|
var init_codex_executor = __esm({
|
|
5165
5165
|
"../machine-connector/dist/runtime/codex-executor.js"() {
|
|
5166
5166
|
"use strict";
|
|
5167
5167
|
init_cjs_shims();
|
|
5168
|
-
|
|
5169
|
-
|
|
5168
|
+
import_promises5 = require("fs/promises");
|
|
5169
|
+
import_node_path4 = require("path");
|
|
5170
5170
|
import_node_crypto2 = require("crypto");
|
|
5171
5171
|
init_enums();
|
|
5172
5172
|
init_process_executor();
|
|
@@ -5422,14 +5422,14 @@ async function requestLocalIpc(store, action, timeoutMilliseconds) {
|
|
|
5422
5422
|
});
|
|
5423
5423
|
});
|
|
5424
5424
|
}
|
|
5425
|
-
var
|
|
5425
|
+
var import_promises6, import_node_net, import_node_os3, LocalIpcServer;
|
|
5426
5426
|
var init_local_ipc = __esm({
|
|
5427
5427
|
"../machine-connector/dist/runtime/local-ipc.js"() {
|
|
5428
5428
|
"use strict";
|
|
5429
5429
|
init_cjs_shims();
|
|
5430
|
-
|
|
5430
|
+
import_promises6 = require("fs/promises");
|
|
5431
5431
|
import_node_net = require("net");
|
|
5432
|
-
|
|
5432
|
+
import_node_os3 = require("os");
|
|
5433
5433
|
LocalIpcServer = class {
|
|
5434
5434
|
store;
|
|
5435
5435
|
getStatus;
|
|
@@ -5442,8 +5442,8 @@ var init_local_ipc = __esm({
|
|
|
5442
5442
|
}
|
|
5443
5443
|
async start() {
|
|
5444
5444
|
const socketPath = this.store.runtimeSocketPath();
|
|
5445
|
-
if ((0,
|
|
5446
|
-
await (0,
|
|
5445
|
+
if ((0, import_node_os3.platform)() !== "win32") {
|
|
5446
|
+
await (0, import_promises6.rm)(socketPath, { force: true });
|
|
5447
5447
|
}
|
|
5448
5448
|
this.server = (0, import_node_net.createServer)((socket) => {
|
|
5449
5449
|
let requestText = "";
|
|
@@ -5465,8 +5465,8 @@ var init_local_ipc = __esm({
|
|
|
5465
5465
|
this.server?.once("error", rejectPromise);
|
|
5466
5466
|
this.server?.listen(socketPath, resolvePromise);
|
|
5467
5467
|
});
|
|
5468
|
-
if ((0,
|
|
5469
|
-
await (0,
|
|
5468
|
+
if ((0, import_node_os3.platform)() !== "win32") {
|
|
5469
|
+
await (0, import_promises6.chmod)(socketPath, 384);
|
|
5470
5470
|
}
|
|
5471
5471
|
}
|
|
5472
5472
|
async close() {
|
|
@@ -5476,8 +5476,8 @@ var init_local_ipc = __esm({
|
|
|
5476
5476
|
await new Promise((resolvePromise) => {
|
|
5477
5477
|
this.server?.close(() => resolvePromise());
|
|
5478
5478
|
});
|
|
5479
|
-
if ((0,
|
|
5480
|
-
await (0,
|
|
5479
|
+
if ((0, import_node_os3.platform)() !== "win32") {
|
|
5480
|
+
await (0, import_promises6.rm)(this.store.runtimeSocketPath(), { force: true });
|
|
5481
5481
|
}
|
|
5482
5482
|
}
|
|
5483
5483
|
async handleRequest(requestText) {
|
|
@@ -5513,7 +5513,7 @@ function createLocalMachineJobExecutionContext(connectorInstanceId, runtimeDirec
|
|
|
5513
5513
|
return {
|
|
5514
5514
|
connectorInstanceId,
|
|
5515
5515
|
kind: "local_machine_job",
|
|
5516
|
-
runtimeDirectory: (0,
|
|
5516
|
+
runtimeDirectory: (0, import_node_path5.resolve)(runtimeDirectory)
|
|
5517
5517
|
};
|
|
5518
5518
|
}
|
|
5519
5519
|
function serializeLocalMachineJobExecutionContext(context) {
|
|
@@ -5524,7 +5524,7 @@ function parseLocalMachineJobExecutionContext(value) {
|
|
|
5524
5524
|
return void 0;
|
|
5525
5525
|
try {
|
|
5526
5526
|
const decoded = JSON.parse(Buffer.from(value.slice(localMachineJobPrefix.length), "base64url").toString("utf8"));
|
|
5527
|
-
if (decoded.kind !== "local_machine_job" || typeof decoded.connectorInstanceId !== "string" || decoded.connectorInstanceId.length === 0 || typeof decoded.runtimeDirectory !== "string" || decoded.runtimeDirectory.length === 0 || (0,
|
|
5527
|
+
if (decoded.kind !== "local_machine_job" || typeof decoded.connectorInstanceId !== "string" || decoded.connectorInstanceId.length === 0 || typeof decoded.runtimeDirectory !== "string" || decoded.runtimeDirectory.length === 0 || (0, import_node_path5.resolve)(decoded.runtimeDirectory) !== decoded.runtimeDirectory) {
|
|
5528
5528
|
return void 0;
|
|
5529
5529
|
}
|
|
5530
5530
|
return decoded;
|
|
@@ -5536,8 +5536,8 @@ async function localMachineJobTargetRelationship(store, value = process.env[mach
|
|
|
5536
5536
|
const context = parseLocalMachineJobExecutionContext(value);
|
|
5537
5537
|
if (!context)
|
|
5538
5538
|
return void 0;
|
|
5539
|
-
const targetRuntimeDirectory = (0,
|
|
5540
|
-
const carryingRuntimeDirectory = (0,
|
|
5539
|
+
const targetRuntimeDirectory = (0, import_node_path5.resolve)(store.baseDirectory);
|
|
5540
|
+
const carryingRuntimeDirectory = (0, import_node_path5.resolve)(context.runtimeDirectory);
|
|
5541
5541
|
if (targetRuntimeDirectory !== carryingRuntimeDirectory) {
|
|
5542
5542
|
try {
|
|
5543
5543
|
const [canonicalTarget, canonicalCarrying] = await Promise.all([
|
|
@@ -5562,24 +5562,24 @@ async function localMachineJobTargetRelationship(store, value = process.env[mach
|
|
|
5562
5562
|
}
|
|
5563
5563
|
async function canonicalizePotentialRuntimeDirectory(path4) {
|
|
5564
5564
|
try {
|
|
5565
|
-
return await (0,
|
|
5565
|
+
return await (0, import_promises7.realpath)(path4);
|
|
5566
5566
|
} catch (error) {
|
|
5567
5567
|
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") {
|
|
5568
5568
|
throw error;
|
|
5569
5569
|
}
|
|
5570
|
-
const parent = (0,
|
|
5570
|
+
const parent = (0, import_node_path5.dirname)(path4);
|
|
5571
5571
|
if (parent === path4)
|
|
5572
5572
|
return path4;
|
|
5573
|
-
return (0,
|
|
5573
|
+
return (0, import_node_path5.join)(await canonicalizePotentialRuntimeDirectory(parent), (0, import_node_path5.basename)(path4));
|
|
5574
5574
|
}
|
|
5575
5575
|
}
|
|
5576
|
-
var
|
|
5576
|
+
var import_promises7, import_node_path5, machineExecutionContextEnvironmentName, localMachineJobPrefix;
|
|
5577
5577
|
var init_execution_context = __esm({
|
|
5578
5578
|
"../machine-connector/dist/runtime/execution-context.js"() {
|
|
5579
5579
|
"use strict";
|
|
5580
5580
|
init_cjs_shims();
|
|
5581
|
-
|
|
5582
|
-
|
|
5581
|
+
import_promises7 = require("fs/promises");
|
|
5582
|
+
import_node_path5 = require("path");
|
|
5583
5583
|
init_local_ipc();
|
|
5584
5584
|
machineExecutionContextEnvironmentName = "MOXT_MACHINE_EXECUTION_CONTEXT";
|
|
5585
5585
|
localMachineJobPrefix = "local_machine_job:v1:";
|
|
@@ -5612,41 +5612,41 @@ async function viewLocalMachineImage(rootPath, relativeImagePath) {
|
|
|
5612
5612
|
}
|
|
5613
5613
|
async function resolvePairedRoot(rootPath) {
|
|
5614
5614
|
try {
|
|
5615
|
-
return await (0,
|
|
5615
|
+
return await (0, import_promises8.realpath)(rootPath);
|
|
5616
5616
|
} catch {
|
|
5617
5617
|
throw new Error("Paired Local Machine root is unavailable");
|
|
5618
5618
|
}
|
|
5619
5619
|
}
|
|
5620
5620
|
async function resolveImagePath(canonicalRoot, relativeImagePath) {
|
|
5621
5621
|
try {
|
|
5622
|
-
return await (0,
|
|
5622
|
+
return await (0, import_promises8.realpath)((0, import_node_path6.resolve)(canonicalRoot, relativeImagePath));
|
|
5623
5623
|
} catch {
|
|
5624
5624
|
throw new Error(`Image could not be read: ${relativeImagePath}`);
|
|
5625
5625
|
}
|
|
5626
5626
|
}
|
|
5627
5627
|
async function statImage(canonicalImage, relativeImagePath) {
|
|
5628
5628
|
try {
|
|
5629
|
-
return await (0,
|
|
5629
|
+
return await (0, import_promises8.stat)(canonicalImage);
|
|
5630
5630
|
} catch {
|
|
5631
5631
|
throw new Error(`Image could not be read: ${relativeImagePath}`);
|
|
5632
5632
|
}
|
|
5633
5633
|
}
|
|
5634
5634
|
async function readImageBytes(canonicalImage, relativeImagePath) {
|
|
5635
5635
|
try {
|
|
5636
|
-
return await (0,
|
|
5636
|
+
return await (0, import_promises8.readFile)(canonicalImage);
|
|
5637
5637
|
} catch {
|
|
5638
5638
|
throw new Error(`Image could not be read: ${relativeImagePath}`);
|
|
5639
5639
|
}
|
|
5640
5640
|
}
|
|
5641
5641
|
function validateRelativeImagePath(path4) {
|
|
5642
5642
|
const segments = path4.split(/[\\/]/);
|
|
5643
|
-
if (path4.length === 0 || path4.length > 4096 || path4.includes("\0") || (0,
|
|
5643
|
+
if (path4.length === 0 || path4.length > 4096 || path4.includes("\0") || (0, import_node_path6.isAbsolute)(path4) || import_node_path6.win32.isAbsolute(path4) || segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
5644
5644
|
throw new Error(`Invalid relative image path: ${path4}`);
|
|
5645
5645
|
}
|
|
5646
5646
|
}
|
|
5647
5647
|
function requireInsideRoot(canonicalRoot, canonicalImage) {
|
|
5648
|
-
const relativePath = (0,
|
|
5649
|
-
if (relativePath === ".." || relativePath.startsWith(`..${
|
|
5648
|
+
const relativePath = (0, import_node_path6.relative)(canonicalRoot, canonicalImage);
|
|
5649
|
+
if (relativePath === ".." || relativePath.startsWith(`..${import_node_path6.sep}`) || (0, import_node_path6.isAbsolute)(relativePath)) {
|
|
5650
5650
|
throw new Error("Image path escapes paired root");
|
|
5651
5651
|
}
|
|
5652
5652
|
}
|
|
@@ -5846,32 +5846,32 @@ function startsWithAscii(bytes, offset, text3) {
|
|
|
5846
5846
|
}
|
|
5847
5847
|
return true;
|
|
5848
5848
|
}
|
|
5849
|
-
var
|
|
5849
|
+
var import_promises8, import_node_path6, maximumLocalMachineImageBytes;
|
|
5850
5850
|
var init_image_viewer = __esm({
|
|
5851
5851
|
"../machine-connector/dist/runtime/image-viewer.js"() {
|
|
5852
5852
|
"use strict";
|
|
5853
5853
|
init_cjs_shims();
|
|
5854
|
-
|
|
5855
|
-
|
|
5854
|
+
import_promises8 = require("fs/promises");
|
|
5855
|
+
import_node_path6 = require("path");
|
|
5856
5856
|
maximumLocalMachineImageBytes = 1e7;
|
|
5857
5857
|
}
|
|
5858
5858
|
});
|
|
5859
5859
|
|
|
5860
5860
|
// ../machine-connector/dist/runtime/process-lock.js
|
|
5861
5861
|
async function createCompleteLock(path4, record2) {
|
|
5862
|
-
await (0,
|
|
5862
|
+
await (0, import_promises9.mkdir)(path4, { mode: 448 });
|
|
5863
5863
|
let metadata;
|
|
5864
5864
|
try {
|
|
5865
|
-
metadata = await (0,
|
|
5865
|
+
metadata = await (0, import_promises9.stat)(path4);
|
|
5866
5866
|
} catch (error) {
|
|
5867
|
-
if (
|
|
5867
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "ENOTDIR")) {
|
|
5868
5868
|
throw nodeError("EEXIST", "Lock directory changed while publishing");
|
|
5869
5869
|
}
|
|
5870
5870
|
throw error;
|
|
5871
5871
|
}
|
|
5872
|
-
const ownerPath = (0,
|
|
5872
|
+
const ownerPath = (0, import_node_path7.join)(path4, `${metadata.dev}.${metadata.ino}.${record2.pid}.${record2.token}.owner`);
|
|
5873
5873
|
try {
|
|
5874
|
-
await (0,
|
|
5874
|
+
await (0, import_promises9.writeFile)(ownerPath, `${JSON.stringify(record2)}
|
|
5875
5875
|
`, {
|
|
5876
5876
|
encoding: "utf8",
|
|
5877
5877
|
flag: "wx",
|
|
@@ -5879,9 +5879,9 @@ async function createCompleteLock(path4, record2) {
|
|
|
5879
5879
|
});
|
|
5880
5880
|
let current2;
|
|
5881
5881
|
try {
|
|
5882
|
-
current2 = await (0,
|
|
5882
|
+
current2 = await (0, import_promises9.stat)(path4);
|
|
5883
5883
|
} catch (error) {
|
|
5884
|
-
if (
|
|
5884
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "ENOTDIR")) {
|
|
5885
5885
|
throw nodeError("EEXIST", "Lock directory changed while publishing");
|
|
5886
5886
|
}
|
|
5887
5887
|
throw error;
|
|
@@ -5893,7 +5893,7 @@ async function createCompleteLock(path4, record2) {
|
|
|
5893
5893
|
} catch (error) {
|
|
5894
5894
|
await removeFileIfPresent(ownerPath);
|
|
5895
5895
|
await removeEmptyDirectory(path4);
|
|
5896
|
-
if (
|
|
5896
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "ENOTDIR")) {
|
|
5897
5897
|
throw nodeError("EEXIST", "Lock directory changed while publishing");
|
|
5898
5898
|
}
|
|
5899
5899
|
throw error;
|
|
@@ -5902,9 +5902,9 @@ async function createCompleteLock(path4, record2) {
|
|
|
5902
5902
|
async function readLockState(path4) {
|
|
5903
5903
|
let metadata;
|
|
5904
5904
|
try {
|
|
5905
|
-
metadata = await (0,
|
|
5905
|
+
metadata = await (0, import_promises9.stat)(path4);
|
|
5906
5906
|
} catch (error) {
|
|
5907
|
-
if (
|
|
5907
|
+
if (isNodeErrorCode3(error, "ENOENT"))
|
|
5908
5908
|
return void 0;
|
|
5909
5909
|
throw error;
|
|
5910
5910
|
}
|
|
@@ -5917,9 +5917,9 @@ async function readLockState(path4) {
|
|
|
5917
5917
|
const ownerPrefix = `${metadata.dev}.${metadata.ino}.`;
|
|
5918
5918
|
let names;
|
|
5919
5919
|
try {
|
|
5920
|
-
names = await (0,
|
|
5920
|
+
names = await (0, import_promises9.readdir)(path4);
|
|
5921
5921
|
} catch (error) {
|
|
5922
|
-
if (
|
|
5922
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "ENOTDIR")) {
|
|
5923
5923
|
return void 0;
|
|
5924
5924
|
}
|
|
5925
5925
|
throw error;
|
|
@@ -5927,7 +5927,7 @@ async function readLockState(path4) {
|
|
|
5927
5927
|
const ownerName = names.find((name) => name.startsWith(ownerPrefix) && name.endsWith(".owner"));
|
|
5928
5928
|
if (!ownerName)
|
|
5929
5929
|
return { metadata };
|
|
5930
|
-
const ownerPath = (0,
|
|
5930
|
+
const ownerPath = (0, import_node_path7.join)(path4, ownerName);
|
|
5931
5931
|
return {
|
|
5932
5932
|
metadata,
|
|
5933
5933
|
ownerPath,
|
|
@@ -5936,13 +5936,13 @@ async function readLockState(path4) {
|
|
|
5936
5936
|
}
|
|
5937
5937
|
async function readRecord(path4) {
|
|
5938
5938
|
try {
|
|
5939
|
-
const parsed = JSON.parse(await (0,
|
|
5939
|
+
const parsed = JSON.parse(await (0, import_promises9.readFile)(path4, "utf8"));
|
|
5940
5940
|
if (typeof parsed.createdAt !== "number" || !Number.isFinite(parsed.createdAt) || typeof parsed.pid !== "number" || !Number.isSafeInteger(parsed.pid) || parsed.pid <= 0 || typeof parsed.token !== "string" || parsed.token.length === 0) {
|
|
5941
5941
|
return void 0;
|
|
5942
5942
|
}
|
|
5943
5943
|
return parsed;
|
|
5944
5944
|
} catch (error) {
|
|
5945
|
-
if (
|
|
5945
|
+
if (isNodeErrorCode3(error, "ENOENT"))
|
|
5946
5946
|
return void 0;
|
|
5947
5947
|
if (error instanceof SyntaxError)
|
|
5948
5948
|
return void 0;
|
|
@@ -5958,9 +5958,9 @@ async function removeLockIfTokenMatches(path4, token) {
|
|
|
5958
5958
|
return;
|
|
5959
5959
|
}
|
|
5960
5960
|
try {
|
|
5961
|
-
await (0,
|
|
5961
|
+
await (0, import_promises9.rm)(path4);
|
|
5962
5962
|
} catch (error) {
|
|
5963
|
-
if (
|
|
5963
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "EISDIR") || isNodeErrorCode3(error, "ERR_FS_EISDIR") || isNodeErrorCode3(error, "EPERM")) {
|
|
5964
5964
|
return;
|
|
5965
5965
|
}
|
|
5966
5966
|
throw error;
|
|
@@ -5982,10 +5982,10 @@ async function removeStaleIncompleteLock(path4, metadata) {
|
|
|
5982
5982
|
}
|
|
5983
5983
|
if (!metadata.isDirectory()) {
|
|
5984
5984
|
try {
|
|
5985
|
-
await (0,
|
|
5985
|
+
await (0, import_promises9.rm)(path4);
|
|
5986
5986
|
return true;
|
|
5987
5987
|
} catch (error) {
|
|
5988
|
-
if (
|
|
5988
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "EISDIR") || isNodeErrorCode3(error, "ERR_FS_EISDIR") || isNodeErrorCode3(error, "EPERM")) {
|
|
5989
5989
|
return false;
|
|
5990
5990
|
}
|
|
5991
5991
|
throw error;
|
|
@@ -5994,9 +5994,9 @@ async function removeStaleIncompleteLock(path4, metadata) {
|
|
|
5994
5994
|
const ownerPrefix = `${metadata.dev}.${metadata.ino}.`;
|
|
5995
5995
|
let names;
|
|
5996
5996
|
try {
|
|
5997
|
-
names = await (0,
|
|
5997
|
+
names = await (0, import_promises9.readdir)(path4);
|
|
5998
5998
|
} catch (error) {
|
|
5999
|
-
if (
|
|
5999
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "ENOTDIR")) {
|
|
6000
6000
|
return false;
|
|
6001
6001
|
}
|
|
6002
6002
|
throw error;
|
|
@@ -6011,7 +6011,7 @@ async function removeStaleIncompleteLock(path4, metadata) {
|
|
|
6011
6011
|
deadOwnerNames.push(name);
|
|
6012
6012
|
}
|
|
6013
6013
|
for (const name of deadOwnerNames) {
|
|
6014
|
-
await removeFileIfPresent((0,
|
|
6014
|
+
await removeFileIfPresent((0, import_node_path7.join)(path4, name));
|
|
6015
6015
|
}
|
|
6016
6016
|
return await removeEmptyDirectory(path4);
|
|
6017
6017
|
}
|
|
@@ -6028,20 +6028,20 @@ function directoryOwnerProcessId(ownerPrefix, ownerName) {
|
|
|
6028
6028
|
return processId;
|
|
6029
6029
|
}
|
|
6030
6030
|
async function removeStalePendingLockCandidates(path4) {
|
|
6031
|
-
const directory = (0,
|
|
6032
|
-
const lockName = (0,
|
|
6031
|
+
const directory = (0, import_node_path7.dirname)(path4);
|
|
6032
|
+
const lockName = (0, import_node_path7.basename)(path4);
|
|
6033
6033
|
let names;
|
|
6034
6034
|
try {
|
|
6035
|
-
names = await (0,
|
|
6035
|
+
names = await (0, import_promises9.readdir)(directory);
|
|
6036
6036
|
} catch (error) {
|
|
6037
|
-
if (
|
|
6037
|
+
if (isNodeErrorCode3(error, "ENOENT"))
|
|
6038
6038
|
return;
|
|
6039
6039
|
throw error;
|
|
6040
6040
|
}
|
|
6041
6041
|
for (const name of names) {
|
|
6042
6042
|
if (!isPendingLockCandidateName(lockName, name))
|
|
6043
6043
|
continue;
|
|
6044
|
-
await removeOldUnchangedFile((0,
|
|
6044
|
+
await removeOldUnchangedFile((0, import_node_path7.join)(directory, name));
|
|
6045
6045
|
}
|
|
6046
6046
|
}
|
|
6047
6047
|
function isPendingLockCandidateName(lockName, name) {
|
|
@@ -6061,30 +6061,30 @@ function isPendingLockCandidateName(lockName, name) {
|
|
|
6061
6061
|
async function removeOldUnchangedFile(path4) {
|
|
6062
6062
|
let metadata;
|
|
6063
6063
|
try {
|
|
6064
|
-
metadata = await (0,
|
|
6064
|
+
metadata = await (0, import_promises9.stat)(path4);
|
|
6065
6065
|
} catch (error) {
|
|
6066
|
-
return
|
|
6066
|
+
return isNodeErrorCode3(error, "ENOENT");
|
|
6067
6067
|
}
|
|
6068
6068
|
if (Date.now() - Number(metadata.mtimeMs) < incompleteLockStaleMilliseconds) {
|
|
6069
6069
|
return false;
|
|
6070
6070
|
}
|
|
6071
6071
|
let current2;
|
|
6072
6072
|
try {
|
|
6073
|
-
current2 = await (0,
|
|
6073
|
+
current2 = await (0, import_promises9.stat)(path4);
|
|
6074
6074
|
} catch (error) {
|
|
6075
|
-
return
|
|
6075
|
+
return isNodeErrorCode3(error, "ENOENT");
|
|
6076
6076
|
}
|
|
6077
6077
|
if (!sameFileMetadata(metadata, current2))
|
|
6078
6078
|
return false;
|
|
6079
|
-
await (0,
|
|
6079
|
+
await (0, import_promises9.rm)(path4, { force: true });
|
|
6080
6080
|
return true;
|
|
6081
6081
|
}
|
|
6082
6082
|
async function removeEmptyDirectory(path4) {
|
|
6083
6083
|
try {
|
|
6084
|
-
await (0,
|
|
6084
|
+
await (0, import_promises9.rmdir)(path4);
|
|
6085
6085
|
return true;
|
|
6086
6086
|
} catch (error) {
|
|
6087
|
-
if (
|
|
6087
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "ENOTEMPTY") || isNodeErrorCode3(error, "EEXIST") || isNodeErrorCode3(error, "ENOTDIR")) {
|
|
6088
6088
|
return false;
|
|
6089
6089
|
}
|
|
6090
6090
|
throw error;
|
|
@@ -6092,9 +6092,9 @@ async function removeEmptyDirectory(path4) {
|
|
|
6092
6092
|
}
|
|
6093
6093
|
async function removeFileIfPresent(path4) {
|
|
6094
6094
|
try {
|
|
6095
|
-
await (0,
|
|
6095
|
+
await (0, import_promises9.rm)(path4, { force: true });
|
|
6096
6096
|
} catch (error) {
|
|
6097
|
-
if (
|
|
6097
|
+
if (isNodeErrorCode3(error, "ENOENT") || isNodeErrorCode3(error, "ENOTDIR")) {
|
|
6098
6098
|
return;
|
|
6099
6099
|
}
|
|
6100
6100
|
throw error;
|
|
@@ -6111,10 +6111,10 @@ function processIsAlive(pid) {
|
|
|
6111
6111
|
process.kill(pid, 0);
|
|
6112
6112
|
return true;
|
|
6113
6113
|
} catch (error) {
|
|
6114
|
-
return !
|
|
6114
|
+
return !isNodeErrorCode3(error, "ESRCH");
|
|
6115
6115
|
}
|
|
6116
6116
|
}
|
|
6117
|
-
function
|
|
6117
|
+
function isNodeErrorCode3(error, expectedCode) {
|
|
6118
6118
|
return error instanceof Error && "code" in error && error.code === expectedCode;
|
|
6119
6119
|
}
|
|
6120
6120
|
function nodeError(code, message) {
|
|
@@ -6123,14 +6123,14 @@ function nodeError(code, message) {
|
|
|
6123
6123
|
function delay3(milliseconds) {
|
|
6124
6124
|
return new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds));
|
|
6125
6125
|
}
|
|
6126
|
-
var import_node_crypto4,
|
|
6126
|
+
var import_node_crypto4, import_promises9, import_node_path7, incompleteLockStaleMilliseconds, ProcessLock;
|
|
6127
6127
|
var init_process_lock = __esm({
|
|
6128
6128
|
"../machine-connector/dist/runtime/process-lock.js"() {
|
|
6129
6129
|
"use strict";
|
|
6130
6130
|
init_cjs_shims();
|
|
6131
6131
|
import_node_crypto4 = require("crypto");
|
|
6132
|
-
|
|
6133
|
-
|
|
6132
|
+
import_promises9 = require("fs/promises");
|
|
6133
|
+
import_node_path7 = require("path");
|
|
6134
6134
|
incompleteLockStaleMilliseconds = 3e4;
|
|
6135
6135
|
ProcessLock = class _ProcessLock {
|
|
6136
6136
|
path;
|
|
@@ -6155,7 +6155,7 @@ var init_process_lock = __esm({
|
|
|
6155
6155
|
});
|
|
6156
6156
|
return new _ProcessLock(path4, ownerPath, token);
|
|
6157
6157
|
} catch (error) {
|
|
6158
|
-
if (!
|
|
6158
|
+
if (!isNodeErrorCode3(error, "EEXIST"))
|
|
6159
6159
|
throw error;
|
|
6160
6160
|
}
|
|
6161
6161
|
const existing = await readLockState(path4);
|
|
@@ -6270,30 +6270,30 @@ function isConnectorCredentialName(name) {
|
|
|
6270
6270
|
return name.startsWith("MOXT_MACHINE_") && /(?:^|_)(?:TOKEN|SECRET|CREDENTIALS?|PASSWORD|PRIVATE_KEY)(?:_|$)/.test(name.slice("MOXT_MACHINE_".length));
|
|
6271
6271
|
}
|
|
6272
6272
|
async function validateShell(shellPath) {
|
|
6273
|
-
if (!(0,
|
|
6273
|
+
if (!(0, import_node_path8.isAbsolute)(shellPath))
|
|
6274
6274
|
throw new Error("default shell is not absolute");
|
|
6275
6275
|
const canonicalPath = await validateExecutable(shellPath);
|
|
6276
|
-
const shellName = (0,
|
|
6276
|
+
const shellName = (0, import_node_path8.basename)(canonicalPath);
|
|
6277
6277
|
if (shellName !== "bash" && shellName !== "zsh") {
|
|
6278
6278
|
throw new Error("default shell is not Bash or Zsh");
|
|
6279
6279
|
}
|
|
6280
6280
|
return canonicalPath;
|
|
6281
6281
|
}
|
|
6282
6282
|
async function validateExecutable(path4) {
|
|
6283
|
-
const canonicalPath = await (0,
|
|
6284
|
-
const metadata = await (0,
|
|
6283
|
+
const canonicalPath = await (0, import_promises10.realpath)(path4);
|
|
6284
|
+
const metadata = await (0, import_promises10.stat)(canonicalPath);
|
|
6285
6285
|
if (!metadata.isFile())
|
|
6286
6286
|
throw new Error("executable is not a regular file");
|
|
6287
|
-
await (0,
|
|
6287
|
+
await (0, import_promises10.access)(canonicalPath, import_promises10.constants.X_OK);
|
|
6288
6288
|
return canonicalPath;
|
|
6289
6289
|
}
|
|
6290
6290
|
async function findExecutable(name, pathValue) {
|
|
6291
|
-
for (const directory of (pathValue ?? "").split(
|
|
6292
|
-
if (!(0,
|
|
6291
|
+
for (const directory of (pathValue ?? "").split(import_node_path8.delimiter)) {
|
|
6292
|
+
if (!(0, import_node_path8.isAbsolute)(directory))
|
|
6293
6293
|
continue;
|
|
6294
6294
|
try {
|
|
6295
|
-
const candidate = await validateExecutable((0,
|
|
6296
|
-
if ((0,
|
|
6295
|
+
const candidate = await validateExecutable((0, import_node_path8.join)(directory, name));
|
|
6296
|
+
if ((0, import_node_path8.basename)(candidate) === name)
|
|
6297
6297
|
return candidate;
|
|
6298
6298
|
} catch {
|
|
6299
6299
|
}
|
|
@@ -6303,9 +6303,9 @@ async function findExecutable(name, pathValue) {
|
|
|
6303
6303
|
async function findNearestEnvrc(canonicalRoot, canonicalWorkingDirectory) {
|
|
6304
6304
|
let directory = canonicalWorkingDirectory;
|
|
6305
6305
|
while (true) {
|
|
6306
|
-
const candidate = (0,
|
|
6306
|
+
const candidate = (0, import_node_path8.join)(directory, ".envrc");
|
|
6307
6307
|
try {
|
|
6308
|
-
const metadata = await (0,
|
|
6308
|
+
const metadata = await (0, import_promises10.stat)(candidate);
|
|
6309
6309
|
if (!metadata.isFile()) {
|
|
6310
6310
|
throw new JobEnvironmentError("direnv_malformed");
|
|
6311
6311
|
}
|
|
@@ -6316,7 +6316,7 @@ async function findNearestEnvrc(canonicalRoot, canonicalWorkingDirectory) {
|
|
|
6316
6316
|
}
|
|
6317
6317
|
if (directory === canonicalRoot)
|
|
6318
6318
|
return void 0;
|
|
6319
|
-
const parent = (0,
|
|
6319
|
+
const parent = (0, import_node_path8.dirname)(directory);
|
|
6320
6320
|
if (parent === directory)
|
|
6321
6321
|
return void 0;
|
|
6322
6322
|
directory = parent;
|
|
@@ -6334,7 +6334,7 @@ async function executeBounded(options) {
|
|
|
6334
6334
|
return await new Promise((resolvePromise) => {
|
|
6335
6335
|
const child = (0, import_node_child_process2.spawn)(options.executable, options.argumentsList, {
|
|
6336
6336
|
cwd: options.cwd,
|
|
6337
|
-
detached: (0,
|
|
6337
|
+
detached: (0, import_node_os4.platform)() !== "win32",
|
|
6338
6338
|
env: options.environment,
|
|
6339
6339
|
shell: false,
|
|
6340
6340
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -6406,7 +6406,7 @@ function terminateBoundedProcess(pid) {
|
|
|
6406
6406
|
if (pid === void 0)
|
|
6407
6407
|
return;
|
|
6408
6408
|
try {
|
|
6409
|
-
process.kill((0,
|
|
6409
|
+
process.kill((0, import_node_os4.platform)() === "win32" ? pid : -pid, "SIGKILL");
|
|
6410
6410
|
} catch (error) {
|
|
6411
6411
|
if (isNodeError(error, "ESRCH"))
|
|
6412
6412
|
return;
|
|
@@ -6464,15 +6464,15 @@ function degradedCapture(category) {
|
|
|
6464
6464
|
function isNodeError(error, code) {
|
|
6465
6465
|
return error instanceof Error && "code" in error && error.code === code;
|
|
6466
6466
|
}
|
|
6467
|
-
var import_node_child_process2,
|
|
6467
|
+
var import_node_child_process2, import_promises10, import_node_os4, import_node_path8, defaultCaptureTimeoutMilliseconds, defaultCaptureOutputLimitBytes, defaultDirenvTimeoutMilliseconds, defaultDirenvOutputLimitBytes, shellCaptureScript, environmentNamePattern, direnvSessionStateNames, JobEnvironmentError, JobEnvironmentCancelledError, ShellEnvironmentManager;
|
|
6468
6468
|
var init_shell_environment = __esm({
|
|
6469
6469
|
"../machine-connector/dist/runtime/shell-environment.js"() {
|
|
6470
6470
|
"use strict";
|
|
6471
6471
|
init_cjs_shims();
|
|
6472
6472
|
import_node_child_process2 = require("child_process");
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6473
|
+
import_promises10 = require("fs/promises");
|
|
6474
|
+
import_node_os4 = require("os");
|
|
6475
|
+
import_node_path8 = require("path");
|
|
6476
6476
|
init_execution_context();
|
|
6477
6477
|
defaultCaptureTimeoutMilliseconds = 5e3;
|
|
6478
6478
|
defaultCaptureOutputLimitBytes = 1048576;
|
|
@@ -6514,7 +6514,7 @@ var init_shell_environment = __esm({
|
|
|
6514
6514
|
this.captureOutputLimitBytes = options.captureOutputLimitBytes ?? defaultCaptureOutputLimitBytes;
|
|
6515
6515
|
this.captureTimeoutMilliseconds = options.captureTimeoutMilliseconds ?? defaultCaptureTimeoutMilliseconds;
|
|
6516
6516
|
this.daemonEnvironment = freezeEnvironment(sanitizeEnvironment(options.daemonEnvironment ?? process.env));
|
|
6517
|
-
this.defaultShell = options.defaultShell ?? (0,
|
|
6517
|
+
this.defaultShell = options.defaultShell ?? (0, import_node_os4.userInfo)().shell ?? "";
|
|
6518
6518
|
this.direnvOutputLimitBytes = options.direnvOutputLimitBytes ?? defaultDirenvOutputLimitBytes;
|
|
6519
6519
|
this.direnvTimeoutMilliseconds = options.direnvTimeoutMilliseconds ?? defaultDirenvTimeoutMilliseconds;
|
|
6520
6520
|
this.currentEnvironment = this.daemonEnvironment;
|
|
@@ -6545,8 +6545,8 @@ var init_shell_environment = __esm({
|
|
|
6545
6545
|
throw new JobEnvironmentError("reserved_environment");
|
|
6546
6546
|
}
|
|
6547
6547
|
const executionContextValue = serializeLocalMachineJobExecutionContext(options.executionContext);
|
|
6548
|
-
const relativeWorkingDirectory = (0,
|
|
6549
|
-
if (relativeWorkingDirectory === ".." || relativeWorkingDirectory.startsWith(`..${
|
|
6548
|
+
const relativeWorkingDirectory = (0, import_node_path8.relative)(canonicalRoot, canonicalWorkingDirectory);
|
|
6549
|
+
if (relativeWorkingDirectory === ".." || relativeWorkingDirectory.startsWith(`..${import_node_path8.sep}`) || (0, import_node_path8.isAbsolute)(relativeWorkingDirectory)) {
|
|
6550
6550
|
throw new JobEnvironmentError("direnv_malformed");
|
|
6551
6551
|
}
|
|
6552
6552
|
const baseSnapshot = this.currentEnvironment;
|
|
@@ -6686,7 +6686,7 @@ var init_version = __esm({
|
|
|
6686
6686
|
});
|
|
6687
6687
|
|
|
6688
6688
|
// ../machine-connector/dist/runtime/local-codex-runtime/contracts.js
|
|
6689
|
-
var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexDiscoveryKindWire, LocalCodexDiscoveryStatusWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
|
|
6689
|
+
var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexUnavailableReasonWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexDiscoveryKindWire, LocalCodexDiscoveryStatusWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
|
|
6690
6690
|
var init_contracts2 = __esm({
|
|
6691
6691
|
"../machine-connector/dist/runtime/local-codex-runtime/contracts.js"() {
|
|
6692
6692
|
"use strict";
|
|
@@ -6702,6 +6702,10 @@ var init_contracts2 = __esm({
|
|
|
6702
6702
|
LocalCodexComponentStatusWire2["Ready"] = "ready";
|
|
6703
6703
|
LocalCodexComponentStatusWire2["Unknown"] = "unknown";
|
|
6704
6704
|
})(LocalCodexComponentStatusWire || (LocalCodexComponentStatusWire = {}));
|
|
6705
|
+
(function(LocalCodexUnavailableReasonWire2) {
|
|
6706
|
+
LocalCodexUnavailableReasonWire2["AppServerStartupFailed"] = "app_server_startup_failed";
|
|
6707
|
+
LocalCodexUnavailableReasonWire2["CodexVersionUnsupported"] = "codex_version_unsupported";
|
|
6708
|
+
})(LocalCodexUnavailableReasonWire || (LocalCodexUnavailableReasonWire = {}));
|
|
6705
6709
|
(function(LocalCodexTurnStatusWire2) {
|
|
6706
6710
|
LocalCodexTurnStatusWire2["Cancelled"] = "cancelled";
|
|
6707
6711
|
LocalCodexTurnStatusWire2["Failed"] = "failed";
|
|
@@ -7006,12 +7010,12 @@ var init_relay_client = __esm({
|
|
|
7006
7010
|
});
|
|
7007
7011
|
|
|
7008
7012
|
// ../machine-connector/dist/runtime/runtime-logger.js
|
|
7009
|
-
var
|
|
7013
|
+
var import_promises11, RuntimeLogger;
|
|
7010
7014
|
var init_runtime_logger = __esm({
|
|
7011
7015
|
"../machine-connector/dist/runtime/runtime-logger.js"() {
|
|
7012
7016
|
"use strict";
|
|
7013
7017
|
init_cjs_shims();
|
|
7014
|
-
|
|
7018
|
+
import_promises11 = require("fs/promises");
|
|
7015
7019
|
RuntimeLogger = class {
|
|
7016
7020
|
store;
|
|
7017
7021
|
constructor(store) {
|
|
@@ -7025,7 +7029,7 @@ var init_runtime_logger = __esm({
|
|
|
7025
7029
|
await this.write("error", message, { ...context, ...errorMetadata }, this.store.runtimeErrorLogPath());
|
|
7026
7030
|
}
|
|
7027
7031
|
async write(level, message, metadata, path4) {
|
|
7028
|
-
await (0,
|
|
7032
|
+
await (0, import_promises11.appendFile)(path4, `${JSON.stringify({
|
|
7029
7033
|
level,
|
|
7030
7034
|
message,
|
|
7031
7035
|
metadata,
|
|
@@ -7046,28 +7050,28 @@ function defaultRuntimeDirectory() {
|
|
|
7046
7050
|
if (override) {
|
|
7047
7051
|
return override;
|
|
7048
7052
|
}
|
|
7049
|
-
const homeDirectory = process.env.HOME ?? (0,
|
|
7050
|
-
if ((0,
|
|
7051
|
-
return (0,
|
|
7053
|
+
const homeDirectory = process.env.HOME ?? (0, import_node_os5.homedir)();
|
|
7054
|
+
if ((0, import_node_os5.platform)() === "darwin") {
|
|
7055
|
+
return (0, import_node_path9.join)(homeDirectory, "Library", "Application Support", "Moxt", "Machine Connector");
|
|
7052
7056
|
}
|
|
7053
|
-
const stateHome = process.env.XDG_STATE_HOME ?? (0,
|
|
7054
|
-
return (0,
|
|
7057
|
+
const stateHome = process.env.XDG_STATE_HOME ?? (0, import_node_path9.join)(homeDirectory, ".local", "state");
|
|
7058
|
+
return (0, import_node_path9.join)(stateHome, "moxt", "machine-connector");
|
|
7055
7059
|
}
|
|
7056
|
-
function
|
|
7060
|
+
function isNodeErrorCode4(error, expectedCode) {
|
|
7057
7061
|
if (!(error instanceof Error) || !("code" in error)) {
|
|
7058
7062
|
return false;
|
|
7059
7063
|
}
|
|
7060
7064
|
return error.code === expectedCode;
|
|
7061
7065
|
}
|
|
7062
|
-
var
|
|
7066
|
+
var import_promises12, import_node_crypto5, import_node_os5, import_node_path9, privateFileMode, privateDirectoryMode, maximumProcessGeneration, MachineRuntimeStore;
|
|
7063
7067
|
var init_store = __esm({
|
|
7064
7068
|
"../machine-connector/dist/runtime/store.js"() {
|
|
7065
7069
|
"use strict";
|
|
7066
7070
|
init_cjs_shims();
|
|
7067
|
-
|
|
7071
|
+
import_promises12 = require("fs/promises");
|
|
7068
7072
|
import_node_crypto5 = require("crypto");
|
|
7069
|
-
|
|
7070
|
-
|
|
7073
|
+
import_node_os5 = require("os");
|
|
7074
|
+
import_node_path9 = require("path");
|
|
7071
7075
|
privateFileMode = 384;
|
|
7072
7076
|
privateDirectoryMode = 448;
|
|
7073
7077
|
maximumProcessGeneration = 2147483647;
|
|
@@ -7078,30 +7082,30 @@ var init_store = __esm({
|
|
|
7078
7082
|
this.baseDirectory = baseDirectory;
|
|
7079
7083
|
}
|
|
7080
7084
|
async initialize() {
|
|
7081
|
-
await (0,
|
|
7085
|
+
await (0, import_promises12.mkdir)(this.jobsDirectory(), {
|
|
7082
7086
|
mode: privateDirectoryMode,
|
|
7083
7087
|
recursive: true
|
|
7084
7088
|
});
|
|
7085
|
-
await (0,
|
|
7089
|
+
await (0, import_promises12.mkdir)(this.detachedProcessesDirectory(), {
|
|
7086
7090
|
mode: privateDirectoryMode,
|
|
7087
7091
|
recursive: true
|
|
7088
7092
|
});
|
|
7089
|
-
await (0,
|
|
7093
|
+
await (0, import_promises12.mkdir)(this.localCodexAttemptsDirectory(), {
|
|
7090
7094
|
mode: privateDirectoryMode,
|
|
7091
7095
|
recursive: true
|
|
7092
7096
|
});
|
|
7093
|
-
await (0,
|
|
7097
|
+
await (0, import_promises12.mkdir)(this.localCodexProcessGenerationsDirectory(), {
|
|
7094
7098
|
mode: privateDirectoryMode,
|
|
7095
7099
|
recursive: true
|
|
7096
7100
|
});
|
|
7097
|
-
await (0,
|
|
7098
|
-
await (0,
|
|
7099
|
-
await (0,
|
|
7100
|
-
await (0,
|
|
7101
|
-
await (0,
|
|
7101
|
+
await (0, import_promises12.chmod)(this.baseDirectory, privateDirectoryMode);
|
|
7102
|
+
await (0, import_promises12.chmod)(this.jobsDirectory(), privateDirectoryMode);
|
|
7103
|
+
await (0, import_promises12.chmod)(this.detachedProcessesDirectory(), privateDirectoryMode);
|
|
7104
|
+
await (0, import_promises12.chmod)(this.localCodexAttemptsDirectory(), privateDirectoryMode);
|
|
7105
|
+
await (0, import_promises12.chmod)(this.localCodexProcessGenerationsDirectory(), privateDirectoryMode);
|
|
7102
7106
|
}
|
|
7103
7107
|
async getCanonicalRoot(rootPath) {
|
|
7104
|
-
return await (0,
|
|
7108
|
+
return await (0, import_promises12.realpath)(rootPath);
|
|
7105
7109
|
}
|
|
7106
7110
|
async readIdentity() {
|
|
7107
7111
|
return await this.readOptionalJson(this.identityPath());
|
|
@@ -7144,7 +7148,7 @@ var init_store = __esm({
|
|
|
7144
7148
|
await this.writePrivateJson(this.serviceManagerPath(), serviceManager);
|
|
7145
7149
|
}
|
|
7146
7150
|
async removeServiceManager() {
|
|
7147
|
-
await (0,
|
|
7151
|
+
await (0, import_promises12.rm)(this.serviceManagerPath(), { force: true });
|
|
7148
7152
|
}
|
|
7149
7153
|
async readJob(jobId) {
|
|
7150
7154
|
return await this.readOptionalJson(this.jobPath(jobId));
|
|
@@ -7155,16 +7159,16 @@ var init_store = __esm({
|
|
|
7155
7159
|
async listJobs() {
|
|
7156
7160
|
let names = [];
|
|
7157
7161
|
try {
|
|
7158
|
-
names = await (0,
|
|
7162
|
+
names = await (0, import_promises12.readdir)(this.jobsDirectory());
|
|
7159
7163
|
} catch (error) {
|
|
7160
|
-
if (
|
|
7164
|
+
if (isNodeErrorCode4(error, "ENOENT")) {
|
|
7161
7165
|
return [];
|
|
7162
7166
|
}
|
|
7163
7167
|
throw error;
|
|
7164
7168
|
}
|
|
7165
7169
|
const jobs = [];
|
|
7166
7170
|
for (const name of names.filter((entry) => entry.endsWith(".json"))) {
|
|
7167
|
-
const job = await this.readOptionalJson((0,
|
|
7171
|
+
const job = await this.readOptionalJson((0, import_node_path9.join)(this.jobsDirectory(), name));
|
|
7168
7172
|
if (job.value) {
|
|
7169
7173
|
jobs.push(job.value);
|
|
7170
7174
|
}
|
|
@@ -7172,7 +7176,7 @@ var init_store = __esm({
|
|
|
7172
7176
|
return jobs;
|
|
7173
7177
|
}
|
|
7174
7178
|
async deleteJob(jobId) {
|
|
7175
|
-
await (0,
|
|
7179
|
+
await (0, import_promises12.rm)(this.jobPath(jobId), { force: true });
|
|
7176
7180
|
}
|
|
7177
7181
|
async writeDetachedProcess(resource) {
|
|
7178
7182
|
await this.writePrivateJson(this.detachedProcessPath(resource.jobId), resource);
|
|
@@ -7180,16 +7184,16 @@ var init_store = __esm({
|
|
|
7180
7184
|
async listDetachedProcesses() {
|
|
7181
7185
|
let names = [];
|
|
7182
7186
|
try {
|
|
7183
|
-
names = await (0,
|
|
7187
|
+
names = await (0, import_promises12.readdir)(this.detachedProcessesDirectory());
|
|
7184
7188
|
} catch (error) {
|
|
7185
|
-
if (
|
|
7189
|
+
if (isNodeErrorCode4(error, "ENOENT")) {
|
|
7186
7190
|
return [];
|
|
7187
7191
|
}
|
|
7188
7192
|
throw error;
|
|
7189
7193
|
}
|
|
7190
7194
|
const resources = [];
|
|
7191
7195
|
for (const name of names.filter((entry) => entry.endsWith(".json"))) {
|
|
7192
|
-
const resource = await this.readOptionalJson((0,
|
|
7196
|
+
const resource = await this.readOptionalJson((0, import_node_path9.join)(this.detachedProcessesDirectory(), name));
|
|
7193
7197
|
if (resource.value) {
|
|
7194
7198
|
resources.push(resource.value);
|
|
7195
7199
|
}
|
|
@@ -7197,7 +7201,7 @@ var init_store = __esm({
|
|
|
7197
7201
|
return resources;
|
|
7198
7202
|
}
|
|
7199
7203
|
async deleteDetachedProcess(jobId) {
|
|
7200
|
-
await (0,
|
|
7204
|
+
await (0, import_promises12.rm)(this.detachedProcessPath(jobId), { force: true });
|
|
7201
7205
|
}
|
|
7202
7206
|
async readLocalCodexAttempt(attemptId) {
|
|
7203
7207
|
return await this.readOptionalJson(this.localCodexAttemptPath(attemptId));
|
|
@@ -7208,16 +7212,16 @@ var init_store = __esm({
|
|
|
7208
7212
|
async listLocalCodexAttempts() {
|
|
7209
7213
|
let names = [];
|
|
7210
7214
|
try {
|
|
7211
|
-
names = await (0,
|
|
7215
|
+
names = await (0, import_promises12.readdir)(this.localCodexAttemptsDirectory());
|
|
7212
7216
|
} catch (error) {
|
|
7213
|
-
if (
|
|
7217
|
+
if (isNodeErrorCode4(error, "ENOENT")) {
|
|
7214
7218
|
return [];
|
|
7215
7219
|
}
|
|
7216
7220
|
throw error;
|
|
7217
7221
|
}
|
|
7218
7222
|
const attempts = [];
|
|
7219
7223
|
for (const name of names.filter((entry) => entry.endsWith(".json"))) {
|
|
7220
|
-
const attempt = await this.readOptionalJson((0,
|
|
7224
|
+
const attempt = await this.readOptionalJson((0, import_node_path9.join)(this.localCodexAttemptsDirectory(), name));
|
|
7221
7225
|
if (attempt.value !== void 0) {
|
|
7222
7226
|
attempts.push(attempt.value);
|
|
7223
7227
|
}
|
|
@@ -7225,7 +7229,7 @@ var init_store = __esm({
|
|
|
7225
7229
|
return attempts;
|
|
7226
7230
|
}
|
|
7227
7231
|
async deleteLocalCodexAttempt(attemptId) {
|
|
7228
|
-
await (0,
|
|
7232
|
+
await (0, import_promises12.rm)(this.localCodexAttemptPath(attemptId), { force: true });
|
|
7229
7233
|
}
|
|
7230
7234
|
async allocateLocalCodexProcessGeneration(poolKey) {
|
|
7231
7235
|
if (!/^[a-f0-9]{64}$/.test(poolKey)) {
|
|
@@ -7254,62 +7258,62 @@ var init_store = __esm({
|
|
|
7254
7258
|
return allocated;
|
|
7255
7259
|
}
|
|
7256
7260
|
runtimeLogPath() {
|
|
7257
|
-
return (0,
|
|
7261
|
+
return (0, import_node_path9.join)(this.baseDirectory, "machine-connector.log");
|
|
7258
7262
|
}
|
|
7259
7263
|
runtimeErrorLogPath() {
|
|
7260
|
-
return (0,
|
|
7264
|
+
return (0, import_node_path9.join)(this.baseDirectory, "machine-connector.error.log");
|
|
7261
7265
|
}
|
|
7262
7266
|
runtimeStatusPath() {
|
|
7263
|
-
return (0,
|
|
7267
|
+
return (0, import_node_path9.join)(this.baseDirectory, "runtime-status.json");
|
|
7264
7268
|
}
|
|
7265
7269
|
runtimeSocketPath() {
|
|
7266
|
-
if ((0,
|
|
7270
|
+
if ((0, import_node_os5.platform)() === "win32") {
|
|
7267
7271
|
return String.raw`\\.\pipe\moxt-machine-connector`;
|
|
7268
7272
|
}
|
|
7269
|
-
return (0,
|
|
7273
|
+
return (0, import_node_path9.join)(this.baseDirectory, "machine-connector.sock");
|
|
7270
7274
|
}
|
|
7271
7275
|
daemonLockPath() {
|
|
7272
|
-
return (0,
|
|
7276
|
+
return (0, import_node_path9.join)(this.baseDirectory, "daemon.lock");
|
|
7273
7277
|
}
|
|
7274
7278
|
reconcileLockPath() {
|
|
7275
|
-
return (0,
|
|
7279
|
+
return (0, import_node_path9.join)(this.baseDirectory, "daemon-reconcile.lock");
|
|
7276
7280
|
}
|
|
7277
7281
|
connectionsPath() {
|
|
7278
|
-
return (0,
|
|
7282
|
+
return (0, import_node_path9.join)(this.baseDirectory, "connections.json");
|
|
7279
7283
|
}
|
|
7280
7284
|
detachedProcessesDirectory() {
|
|
7281
|
-
return (0,
|
|
7285
|
+
return (0, import_node_path9.join)(this.baseDirectory, "detached-processes");
|
|
7282
7286
|
}
|
|
7283
7287
|
detachedProcessPath(jobId) {
|
|
7284
|
-
return (0,
|
|
7288
|
+
return (0, import_node_path9.join)(this.detachedProcessesDirectory(), `${jobId}.json`);
|
|
7285
7289
|
}
|
|
7286
7290
|
identityPath() {
|
|
7287
|
-
return (0,
|
|
7291
|
+
return (0, import_node_path9.join)(this.baseDirectory, "identity.json");
|
|
7288
7292
|
}
|
|
7289
7293
|
serviceManagerPath() {
|
|
7290
|
-
return (0,
|
|
7294
|
+
return (0, import_node_path9.join)(this.baseDirectory, "service-manager.json");
|
|
7291
7295
|
}
|
|
7292
7296
|
privateKeyPath() {
|
|
7293
|
-
return (0,
|
|
7297
|
+
return (0, import_node_path9.join)(this.baseDirectory, "device-private-key.pem");
|
|
7294
7298
|
}
|
|
7295
7299
|
jobsDirectory() {
|
|
7296
|
-
return (0,
|
|
7300
|
+
return (0, import_node_path9.join)(this.baseDirectory, "jobs");
|
|
7297
7301
|
}
|
|
7298
7302
|
localCodexAttemptsDirectory() {
|
|
7299
|
-
return (0,
|
|
7303
|
+
return (0, import_node_path9.join)(this.baseDirectory, "local-codex-runtime-attempts");
|
|
7300
7304
|
}
|
|
7301
7305
|
localCodexAttemptPath(attemptId) {
|
|
7302
|
-
return (0,
|
|
7306
|
+
return (0, import_node_path9.join)(this.localCodexAttemptsDirectory(), `${attemptId}.json`);
|
|
7303
7307
|
}
|
|
7304
7308
|
localCodexProcessGenerationsDirectory() {
|
|
7305
|
-
return (0,
|
|
7309
|
+
return (0, import_node_path9.join)(this.baseDirectory, "local-codex-runtime-process-generations");
|
|
7306
7310
|
}
|
|
7307
7311
|
localCodexProcessGenerationPath(poolKey) {
|
|
7308
7312
|
const key = (0, import_node_crypto5.createHash)("sha256").update(poolKey).digest("hex");
|
|
7309
|
-
return (0,
|
|
7313
|
+
return (0, import_node_path9.join)(this.localCodexProcessGenerationsDirectory(), `${key}.json`);
|
|
7310
7314
|
}
|
|
7311
7315
|
jobPath(jobId) {
|
|
7312
|
-
return (0,
|
|
7316
|
+
return (0, import_node_path9.join)(this.jobsDirectory(), `${jobId}.json`);
|
|
7313
7317
|
}
|
|
7314
7318
|
async readOptionalJson(path4) {
|
|
7315
7319
|
const content3 = await this.readOptionalText(path4);
|
|
@@ -7320,9 +7324,9 @@ var init_store = __esm({
|
|
|
7320
7324
|
}
|
|
7321
7325
|
async readOptionalText(path4) {
|
|
7322
7326
|
try {
|
|
7323
|
-
return { value: await (0,
|
|
7327
|
+
return { value: await (0, import_promises12.readFile)(path4, "utf8") };
|
|
7324
7328
|
} catch (error) {
|
|
7325
|
-
if (
|
|
7329
|
+
if (isNodeErrorCode4(error, "ENOENT")) {
|
|
7326
7330
|
return {};
|
|
7327
7331
|
}
|
|
7328
7332
|
throw error;
|
|
@@ -7333,17 +7337,17 @@ var init_store = __esm({
|
|
|
7333
7337
|
`);
|
|
7334
7338
|
}
|
|
7335
7339
|
async writePrivateText(path4, value) {
|
|
7336
|
-
await (0,
|
|
7340
|
+
await (0, import_promises12.mkdir)((0, import_node_path9.dirname)(path4), {
|
|
7337
7341
|
mode: privateDirectoryMode,
|
|
7338
7342
|
recursive: true
|
|
7339
7343
|
});
|
|
7340
7344
|
const temporaryPath = `${path4}.${process.pid}.tmp`;
|
|
7341
|
-
await (0,
|
|
7345
|
+
await (0, import_promises12.writeFile)(temporaryPath, value, {
|
|
7342
7346
|
encoding: "utf8",
|
|
7343
7347
|
mode: privateFileMode
|
|
7344
7348
|
});
|
|
7345
|
-
await (0,
|
|
7346
|
-
await (0,
|
|
7349
|
+
await (0, import_promises12.chmod)(temporaryPath, privateFileMode);
|
|
7350
|
+
await (0, import_promises12.rename)(temporaryPath, path4);
|
|
7347
7351
|
}
|
|
7348
7352
|
};
|
|
7349
7353
|
}
|
|
@@ -7379,60 +7383,364 @@ function createAppServerEnvironment(environment) {
|
|
|
7379
7383
|
function digestOpaque(value) {
|
|
7380
7384
|
return (0, import_node_crypto6.createHash)("sha256").update(value).digest("hex");
|
|
7381
7385
|
}
|
|
7382
|
-
function
|
|
7386
|
+
async function resolveCodexVersion(options) {
|
|
7387
|
+
const userAgentVersion = extractKnownCodexVersion(options.userAgent).value;
|
|
7388
|
+
if (userAgentVersion !== void 0) {
|
|
7389
|
+
return userAgentVersion;
|
|
7390
|
+
}
|
|
7391
|
+
const executableVersion = (await probeCodexVersion(options.executable, options.processBaseDirectory, options.environment)).value;
|
|
7392
|
+
return executableVersion ?? options.userAgent.slice(0, 64);
|
|
7393
|
+
}
|
|
7394
|
+
function extractKnownCodexVersion(userAgent) {
|
|
7383
7395
|
const matched = /(?:codex_cli_rs|codex-cli|codex(?: desktop)?)\/([0-9][^\s/]*)/i.exec(userAgent);
|
|
7384
|
-
return matched
|
|
7396
|
+
return matched === null ? {} : { value: matched[1] };
|
|
7397
|
+
}
|
|
7398
|
+
async function probeCodexVersion(executable, processBaseDirectory, environment) {
|
|
7399
|
+
const result = await new Promise((resolve10) => {
|
|
7400
|
+
(0, import_node_child_process3.execFile)(executable, ["--version"], {
|
|
7401
|
+
cwd: processBaseDirectory,
|
|
7402
|
+
encoding: "utf8",
|
|
7403
|
+
env: { ...environment },
|
|
7404
|
+
maxBuffer: maximumCodexVersionOutputBytes,
|
|
7405
|
+
timeout: codexVersionProbeTimeoutMilliseconds,
|
|
7406
|
+
windowsHide: true
|
|
7407
|
+
}, (error, stdout) => {
|
|
7408
|
+
if (error !== null || typeof stdout !== "string") {
|
|
7409
|
+
resolve10({});
|
|
7410
|
+
return;
|
|
7411
|
+
}
|
|
7412
|
+
resolve10({ output: stdout });
|
|
7413
|
+
});
|
|
7414
|
+
});
|
|
7415
|
+
if (result.output === void 0) {
|
|
7416
|
+
return {};
|
|
7417
|
+
}
|
|
7418
|
+
const matched = /(?:^|\s)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)(?=\s|$)/.exec(result.output);
|
|
7419
|
+
return matched === null ? {} : { value: matched[1] };
|
|
7420
|
+
}
|
|
7421
|
+
function assertSupportedCodexVersion(codexVersion) {
|
|
7422
|
+
const parsed = /^(\d+)\.(\d+)\.(\d+)/.exec(codexVersion);
|
|
7423
|
+
const minimum = /^(\d+)\.(\d+)\.(\d+)/.exec(minimumCodexVersion);
|
|
7424
|
+
if (parsed === null || minimum === null) {
|
|
7425
|
+
throw new AppServerUnsupportedVersionError(codexVersion);
|
|
7426
|
+
}
|
|
7427
|
+
const actualParts = parsed.slice(1, 4).map(Number);
|
|
7428
|
+
const minimumParts = minimum.slice(1, 4).map(Number);
|
|
7429
|
+
for (let index2 = 0; index2 < minimumParts.length; index2 += 1) {
|
|
7430
|
+
const actualPart = actualParts[index2];
|
|
7431
|
+
const minimumPart = minimumParts[index2];
|
|
7432
|
+
if (actualPart > minimumPart) {
|
|
7433
|
+
return;
|
|
7434
|
+
}
|
|
7435
|
+
if (actualPart < minimumPart) {
|
|
7436
|
+
throw new AppServerUnsupportedVersionError(codexVersion);
|
|
7437
|
+
}
|
|
7438
|
+
}
|
|
7439
|
+
}
|
|
7440
|
+
function errorMessage2(error) {
|
|
7441
|
+
return error instanceof Error ? error.message : String(error);
|
|
7442
|
+
}
|
|
7443
|
+
function stderrIndicatesUnsupportedAppServerArguments(stderr) {
|
|
7444
|
+
const normalized = stderr.toLowerCase();
|
|
7445
|
+
const mentionsRequiredArgument = normalized.includes("--disable") || normalized.includes("unified_exec");
|
|
7446
|
+
if (!mentionsRequiredArgument) {
|
|
7447
|
+
return false;
|
|
7448
|
+
}
|
|
7449
|
+
return [
|
|
7450
|
+
"unexpected argument",
|
|
7451
|
+
"unknown argument",
|
|
7452
|
+
"unknown feature",
|
|
7453
|
+
"unrecognized option",
|
|
7454
|
+
"unknown option"
|
|
7455
|
+
].some((pattern) => normalized.includes(pattern));
|
|
7385
7456
|
}
|
|
7386
7457
|
async function completionWithinExit(child, milliseconds) {
|
|
7387
7458
|
if (child.exitCode !== null || child.signalCode !== null) {
|
|
7388
7459
|
return;
|
|
7389
7460
|
}
|
|
7390
|
-
await new Promise((
|
|
7391
|
-
const timeout = setTimeout(
|
|
7461
|
+
await new Promise((resolve10) => {
|
|
7462
|
+
const timeout = setTimeout(resolve10, milliseconds);
|
|
7392
7463
|
timeout.unref();
|
|
7393
7464
|
child.once("close", () => {
|
|
7394
7465
|
clearTimeout(timeout);
|
|
7395
|
-
|
|
7466
|
+
resolve10();
|
|
7396
7467
|
});
|
|
7397
7468
|
});
|
|
7398
7469
|
}
|
|
7399
|
-
function
|
|
7400
|
-
|
|
7470
|
+
async function completionWithinProcessTreeExit(child, stopTarget, milliseconds) {
|
|
7471
|
+
const deadline = Date.now() + milliseconds;
|
|
7472
|
+
while (Date.now() < deadline) {
|
|
7473
|
+
if (!await appServerProcessTreeIsRunning(child, stopTarget)) {
|
|
7474
|
+
return;
|
|
7475
|
+
}
|
|
7476
|
+
await new Promise((resolve10) => {
|
|
7477
|
+
setTimeout(resolve10, processTreePollMilliseconds);
|
|
7478
|
+
});
|
|
7479
|
+
}
|
|
7480
|
+
}
|
|
7481
|
+
async function appServerProcessTreeIsRunning(child, stopTarget) {
|
|
7482
|
+
if ((0, import_node_os6.platform)() === "win32" || child.pid === void 0) {
|
|
7483
|
+
return child.exitCode === null && child.signalCode === null;
|
|
7484
|
+
}
|
|
7485
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
7486
|
+
return true;
|
|
7487
|
+
}
|
|
7488
|
+
if (!stopTarget.verificationAvailable) {
|
|
7489
|
+
return true;
|
|
7490
|
+
}
|
|
7491
|
+
if (stopTarget.descendantProcesses.size === 0) {
|
|
7492
|
+
return false;
|
|
7493
|
+
}
|
|
7494
|
+
const processTable = await appServerProcessTableWithRetry();
|
|
7495
|
+
if (!processTable.available) {
|
|
7496
|
+
return true;
|
|
7497
|
+
}
|
|
7498
|
+
for (const processIdentity of stopTarget.descendantProcesses.values()) {
|
|
7499
|
+
if (processIdentityIsCurrent(processIdentity, processTable)) {
|
|
7500
|
+
return true;
|
|
7501
|
+
}
|
|
7502
|
+
}
|
|
7503
|
+
return false;
|
|
7504
|
+
}
|
|
7505
|
+
async function terminateAppServerProcess(child, stopTarget) {
|
|
7506
|
+
if ((0, import_node_os6.platform)() === "win32" || child.pid === void 0) {
|
|
7401
7507
|
child.kill("SIGTERM");
|
|
7402
7508
|
return;
|
|
7403
7509
|
}
|
|
7510
|
+
const processTable = stopTarget.descendantProcesses.size === 0 ? unavailableAppServerProcessTable() : await appServerProcessTableWithRetry();
|
|
7511
|
+
for (const processIdentity of Array.from(stopTarget.descendantProcesses.values()).reverse()) {
|
|
7512
|
+
if (!processIdentityIsCurrent(processIdentity, processTable)) {
|
|
7513
|
+
continue;
|
|
7514
|
+
}
|
|
7515
|
+
try {
|
|
7516
|
+
process.kill(processIdentity.processId, "SIGTERM");
|
|
7517
|
+
} catch {
|
|
7518
|
+
}
|
|
7519
|
+
}
|
|
7520
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
7521
|
+
return;
|
|
7522
|
+
}
|
|
7404
7523
|
try {
|
|
7405
7524
|
process.kill(-child.pid, "SIGTERM");
|
|
7406
7525
|
} catch {
|
|
7407
7526
|
child.kill("SIGTERM");
|
|
7408
7527
|
}
|
|
7409
7528
|
}
|
|
7410
|
-
function killAppServerProcess(child) {
|
|
7411
|
-
if ((0,
|
|
7529
|
+
async function killAppServerProcess(child, stopTarget) {
|
|
7530
|
+
if ((0, import_node_os6.platform)() === "win32" || child.pid === void 0) {
|
|
7412
7531
|
child.kill("SIGKILL");
|
|
7413
7532
|
return;
|
|
7414
7533
|
}
|
|
7534
|
+
const processTable = stopTarget.descendantProcesses.size === 0 ? unavailableAppServerProcessTable() : await appServerProcessTableWithRetry();
|
|
7535
|
+
for (const processIdentity of Array.from(stopTarget.descendantProcesses.values()).reverse()) {
|
|
7536
|
+
if (!processIdentityIsCurrent(processIdentity, processTable)) {
|
|
7537
|
+
continue;
|
|
7538
|
+
}
|
|
7539
|
+
try {
|
|
7540
|
+
process.kill(processIdentity.processId, "SIGKILL");
|
|
7541
|
+
} catch {
|
|
7542
|
+
}
|
|
7543
|
+
}
|
|
7544
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
7545
|
+
return;
|
|
7546
|
+
}
|
|
7415
7547
|
try {
|
|
7416
7548
|
process.kill(-child.pid, "SIGKILL");
|
|
7417
7549
|
} catch {
|
|
7418
7550
|
child.kill("SIGKILL");
|
|
7419
7551
|
}
|
|
7420
7552
|
}
|
|
7421
|
-
|
|
7553
|
+
async function captureAppServerProcessTree(child) {
|
|
7554
|
+
if ((0, import_node_os6.platform)() === "win32" || child.pid === void 0) {
|
|
7555
|
+
return {
|
|
7556
|
+
descendantProcesses: [],
|
|
7557
|
+
status: AppServerProcessTreeCaptureStatus.Complete
|
|
7558
|
+
};
|
|
7559
|
+
}
|
|
7560
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
7561
|
+
return {
|
|
7562
|
+
descendantProcesses: [],
|
|
7563
|
+
status: AppServerProcessTreeCaptureStatus.ProcessExited
|
|
7564
|
+
};
|
|
7565
|
+
}
|
|
7566
|
+
const processTable = await appServerProcessTableWithRetry();
|
|
7567
|
+
if (!processTable.available) {
|
|
7568
|
+
return {
|
|
7569
|
+
descendantProcesses: [],
|
|
7570
|
+
status: AppServerProcessTreeCaptureStatus.ProcessTableUnavailable
|
|
7571
|
+
};
|
|
7572
|
+
}
|
|
7573
|
+
if (!processTable.processes.has(child.pid)) {
|
|
7574
|
+
return {
|
|
7575
|
+
descendantProcesses: [],
|
|
7576
|
+
status: AppServerProcessTreeCaptureStatus.ProcessExited
|
|
7577
|
+
};
|
|
7578
|
+
}
|
|
7579
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
7580
|
+
for (const processRecord of processTable.processes.values()) {
|
|
7581
|
+
const children = childrenByParent.get(processRecord.parentProcessId) ?? [];
|
|
7582
|
+
children.push(processRecord);
|
|
7583
|
+
childrenByParent.set(processRecord.parentProcessId, children);
|
|
7584
|
+
}
|
|
7585
|
+
const descendants = [];
|
|
7586
|
+
const pending = [child.pid];
|
|
7587
|
+
const seen = new Set(pending);
|
|
7588
|
+
while (pending.length > 0) {
|
|
7589
|
+
const parentProcessId = pending.shift();
|
|
7590
|
+
if (parentProcessId === void 0) {
|
|
7591
|
+
continue;
|
|
7592
|
+
}
|
|
7593
|
+
for (const processRecord of childrenByParent.get(parentProcessId) ?? []) {
|
|
7594
|
+
if (seen.has(processRecord.processId)) {
|
|
7595
|
+
continue;
|
|
7596
|
+
}
|
|
7597
|
+
seen.add(processRecord.processId);
|
|
7598
|
+
descendants.push({
|
|
7599
|
+
processId: processRecord.processId,
|
|
7600
|
+
startedAt: processRecord.startedAt
|
|
7601
|
+
});
|
|
7602
|
+
pending.push(processRecord.processId);
|
|
7603
|
+
}
|
|
7604
|
+
}
|
|
7605
|
+
return {
|
|
7606
|
+
descendantProcesses: descendants,
|
|
7607
|
+
status: AppServerProcessTreeCaptureStatus.Complete
|
|
7608
|
+
};
|
|
7609
|
+
}
|
|
7610
|
+
async function appServerProcessTable() {
|
|
7611
|
+
const listed = await new Promise((resolve10) => {
|
|
7612
|
+
(0, import_node_child_process3.execFile)(processTableExecutable(), ["-axo", "pid=,ppid=,lstart="], {
|
|
7613
|
+
encoding: "utf8",
|
|
7614
|
+
maxBuffer: maximumProcessTableBytes,
|
|
7615
|
+
timeout: processTableTimeoutMilliseconds,
|
|
7616
|
+
windowsHide: true
|
|
7617
|
+
}, (error, stdout) => {
|
|
7618
|
+
if (error !== null || typeof stdout !== "string") {
|
|
7619
|
+
resolve10({});
|
|
7620
|
+
return;
|
|
7621
|
+
}
|
|
7622
|
+
resolve10({ output: stdout });
|
|
7623
|
+
});
|
|
7624
|
+
});
|
|
7625
|
+
if (listed.output === void 0) {
|
|
7626
|
+
return unavailableAppServerProcessTable();
|
|
7627
|
+
}
|
|
7628
|
+
const processes = /* @__PURE__ */ new Map();
|
|
7629
|
+
for (const line of listed.output.split("\n")) {
|
|
7630
|
+
if (line.trim() === "") {
|
|
7631
|
+
continue;
|
|
7632
|
+
}
|
|
7633
|
+
const matched = /^\s*(\d+)\s+(\d+)\s+(.+?)\s*$/.exec(line);
|
|
7634
|
+
if (matched === null) {
|
|
7635
|
+
return unavailableAppServerProcessTable();
|
|
7636
|
+
}
|
|
7637
|
+
const processId = Number(matched[1]);
|
|
7638
|
+
const parentProcessId = Number(matched[2]);
|
|
7639
|
+
processes.set(processId, {
|
|
7640
|
+
parentProcessId,
|
|
7641
|
+
processId,
|
|
7642
|
+
startedAt: matched[3].trim()
|
|
7643
|
+
});
|
|
7644
|
+
}
|
|
7645
|
+
return { available: processes.size > 0, processes };
|
|
7646
|
+
}
|
|
7647
|
+
function processTableExecutable() {
|
|
7648
|
+
const configured = process.env.MOXT_LOCAL_CODEX_PS_PATH;
|
|
7649
|
+
if (configured !== void 0 && configured !== "") {
|
|
7650
|
+
return configured;
|
|
7651
|
+
}
|
|
7652
|
+
return defaultProcessTableExecutable;
|
|
7653
|
+
}
|
|
7654
|
+
function resolveDefaultProcessTableExecutable() {
|
|
7655
|
+
const candidates2 = (0, import_node_os6.platform)() === "linux" ? ["/usr/bin/ps", "/bin/ps"] : ["/bin/ps", "/usr/bin/ps"];
|
|
7656
|
+
for (const candidate of candidates2) {
|
|
7657
|
+
try {
|
|
7658
|
+
(0, import_node_fs2.accessSync)(candidate, import_node_fs2.constants.X_OK);
|
|
7659
|
+
return candidate;
|
|
7660
|
+
} catch {
|
|
7661
|
+
continue;
|
|
7662
|
+
}
|
|
7663
|
+
}
|
|
7664
|
+
return "ps";
|
|
7665
|
+
}
|
|
7666
|
+
async function appServerProcessTableWithRetry() {
|
|
7667
|
+
for (let attempt = 1; attempt <= maximumProcessTableAttempts; attempt += 1) {
|
|
7668
|
+
const processTable = await appServerProcessTable();
|
|
7669
|
+
if (processTable.available) {
|
|
7670
|
+
return processTable;
|
|
7671
|
+
}
|
|
7672
|
+
if (attempt < maximumProcessTableAttempts) {
|
|
7673
|
+
await new Promise((resolve10) => {
|
|
7674
|
+
setTimeout(resolve10, processTableRetryMilliseconds);
|
|
7675
|
+
});
|
|
7676
|
+
}
|
|
7677
|
+
}
|
|
7678
|
+
return unavailableAppServerProcessTable();
|
|
7679
|
+
}
|
|
7680
|
+
function unavailableAppServerProcessTable() {
|
|
7681
|
+
return { available: false, processes: /* @__PURE__ */ new Map() };
|
|
7682
|
+
}
|
|
7683
|
+
function processIdentityIsCurrent(processIdentity, processTable) {
|
|
7684
|
+
return processTable.available && processTable.processes.get(processIdentity.processId)?.startedAt === processIdentity.startedAt;
|
|
7685
|
+
}
|
|
7686
|
+
function stopWindowsProcessTree(child) {
|
|
7687
|
+
if (child.pid === void 0 || child.exitCode !== null || child.signalCode !== null) {
|
|
7688
|
+
return {};
|
|
7689
|
+
}
|
|
7690
|
+
const stopped = (0, import_node_child_process3.spawnSync)("taskkill", ["/pid", String(child.pid), "/t", "/f"], {
|
|
7691
|
+
encoding: "utf8",
|
|
7692
|
+
windowsHide: true
|
|
7693
|
+
});
|
|
7694
|
+
if (stopped.error === void 0 && stopped.status === 0) {
|
|
7695
|
+
return {};
|
|
7696
|
+
}
|
|
7697
|
+
return {
|
|
7698
|
+
failureMessage: stopped.error?.message ?? `taskkill exited with status ${String(stopped.status)}`
|
|
7699
|
+
};
|
|
7700
|
+
}
|
|
7701
|
+
var import_node_child_process3, import_node_crypto6, import_node_fs2, import_node_os6, maximumFrameBytes, requestTimeoutMilliseconds2, processExitGraceMilliseconds, processTreePollMilliseconds, processTableTimeoutMilliseconds, processTableRetryMilliseconds, maximumProcessTableAttempts, maximumProcessTableBytes, maximumStderrTailCharacters, codexVersionProbeTimeoutMilliseconds, maximumCodexVersionOutputBytes, minimumCodexVersion, defaultProcessTableExecutable, appServerArguments, AppServerProcessTreeCaptureStatus, AppServerProcessLostError, AppServerProtocolError, AppServerUnsupportedVersionError, AppServerRequestTimeoutError, AppServerResponseError, AppServerClient, LocalCodexAppServerSupervisor;
|
|
7422
7702
|
var init_app_server_client = __esm({
|
|
7423
7703
|
"../machine-connector/dist/runtime/local-codex-runtime/app-server-client.js"() {
|
|
7424
7704
|
"use strict";
|
|
7425
7705
|
init_cjs_shims();
|
|
7426
7706
|
import_node_child_process3 = require("child_process");
|
|
7427
7707
|
import_node_crypto6 = require("crypto");
|
|
7428
|
-
|
|
7708
|
+
import_node_fs2 = require("fs");
|
|
7709
|
+
import_node_os6 = require("os");
|
|
7429
7710
|
init_version();
|
|
7430
7711
|
init_contracts2();
|
|
7431
7712
|
maximumFrameBytes = 8e6;
|
|
7432
7713
|
requestTimeoutMilliseconds2 = 3e4;
|
|
7714
|
+
processExitGraceMilliseconds = 2e3;
|
|
7715
|
+
processTreePollMilliseconds = 250;
|
|
7716
|
+
processTableTimeoutMilliseconds = 1e3;
|
|
7717
|
+
processTableRetryMilliseconds = 100;
|
|
7718
|
+
maximumProcessTableAttempts = 3;
|
|
7719
|
+
maximumProcessTableBytes = 8e6;
|
|
7720
|
+
maximumStderrTailCharacters = 4e3;
|
|
7721
|
+
codexVersionProbeTimeoutMilliseconds = 5e3;
|
|
7722
|
+
maximumCodexVersionOutputBytes = 4096;
|
|
7723
|
+
minimumCodexVersion = "0.146.0";
|
|
7724
|
+
defaultProcessTableExecutable = resolveDefaultProcessTableExecutable();
|
|
7725
|
+
appServerArguments = [
|
|
7726
|
+
"app-server",
|
|
7727
|
+
"--listen",
|
|
7728
|
+
"stdio://",
|
|
7729
|
+
"--disable",
|
|
7730
|
+
"unified_exec"
|
|
7731
|
+
];
|
|
7732
|
+
(function(AppServerProcessTreeCaptureStatus2) {
|
|
7733
|
+
AppServerProcessTreeCaptureStatus2["Complete"] = "complete";
|
|
7734
|
+
AppServerProcessTreeCaptureStatus2["ProcessExited"] = "process_exited";
|
|
7735
|
+
AppServerProcessTreeCaptureStatus2["ProcessTableUnavailable"] = "process_table_unavailable";
|
|
7736
|
+
})(AppServerProcessTreeCaptureStatus || (AppServerProcessTreeCaptureStatus = {}));
|
|
7433
7737
|
AppServerProcessLostError = class extends Error {
|
|
7434
|
-
|
|
7738
|
+
code;
|
|
7739
|
+
unavailableReason;
|
|
7740
|
+
constructor(message, code, unavailableReason) {
|
|
7435
7741
|
super(message);
|
|
7742
|
+
this.code = code;
|
|
7743
|
+
this.unavailableReason = unavailableReason;
|
|
7436
7744
|
this.name = "AppServerProcessLostError";
|
|
7437
7745
|
}
|
|
7438
7746
|
};
|
|
@@ -7442,6 +7750,14 @@ var init_app_server_client = __esm({
|
|
|
7442
7750
|
this.name = "AppServerProtocolError";
|
|
7443
7751
|
}
|
|
7444
7752
|
};
|
|
7753
|
+
AppServerUnsupportedVersionError = class extends AppServerProtocolError {
|
|
7754
|
+
codexVersion;
|
|
7755
|
+
constructor(codexVersion) {
|
|
7756
|
+
super(`Moxt Local Codex Runtime requires Codex ${minimumCodexVersion} or newer; detected ${codexVersion}`);
|
|
7757
|
+
this.codexVersion = codexVersion;
|
|
7758
|
+
this.name = "AppServerUnsupportedVersionError";
|
|
7759
|
+
}
|
|
7760
|
+
};
|
|
7445
7761
|
AppServerRequestTimeoutError = class extends AppServerProtocolError {
|
|
7446
7762
|
method;
|
|
7447
7763
|
constructor(method) {
|
|
@@ -7467,8 +7783,10 @@ var init_app_server_client = __esm({
|
|
|
7467
7783
|
closed = false;
|
|
7468
7784
|
handlerQueue = Promise.resolve();
|
|
7469
7785
|
intentionalStop = false;
|
|
7786
|
+
initializationCompleted = false;
|
|
7470
7787
|
nextRequestId = 1;
|
|
7471
7788
|
pending = /* @__PURE__ */ new Map();
|
|
7789
|
+
stderrTail = "";
|
|
7472
7790
|
writeQueue = Promise.resolve();
|
|
7473
7791
|
constructor(child, handlers, processGeneration) {
|
|
7474
7792
|
this.child = child;
|
|
@@ -7477,21 +7795,32 @@ var init_app_server_client = __esm({
|
|
|
7477
7795
|
child.stdout.on("data", (chunk) => this.receive(chunk));
|
|
7478
7796
|
child.stderr.setEncoding("utf8");
|
|
7479
7797
|
child.stderr.on("data", (text3) => {
|
|
7798
|
+
this.stderrTail = `${this.stderrTail}${text3}`.slice(-maximumStderrTailCharacters);
|
|
7480
7799
|
this.enqueueHandler(async () => await handlers.onStderr(text3), "stderr");
|
|
7481
7800
|
});
|
|
7482
7801
|
child.once("error", (error) => {
|
|
7483
|
-
|
|
7802
|
+
const code = "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
7803
|
+
const unavailableReason = this.initializationCompleted ? void 0 : LocalCodexUnavailableReasonWire.AppServerStartupFailed;
|
|
7804
|
+
this.closeWithError(new AppServerProcessLostError(`Codex App Server process failed: ${error.message}`, code, unavailableReason));
|
|
7484
7805
|
});
|
|
7485
7806
|
child.once("close", (code, signal) => {
|
|
7486
|
-
|
|
7807
|
+
const stderr = this.stderrTail.trim();
|
|
7808
|
+
const unsupportedArguments = !this.initializationCompleted && stderrIndicatesUnsupportedAppServerArguments(stderr);
|
|
7809
|
+
const startupRequirement = unsupportedArguments ? `; Moxt Local Codex Runtime requires Codex ${minimumCodexVersion} or newer` : "";
|
|
7810
|
+
const startupStderr = !this.initializationCompleted && stderr !== "" ? `; stderr: ${stderr}` : "";
|
|
7811
|
+
const unavailableReason = {};
|
|
7812
|
+
if (!this.initializationCompleted) {
|
|
7813
|
+
unavailableReason.value = unsupportedArguments ? LocalCodexUnavailableReasonWire.CodexVersionUnsupported : LocalCodexUnavailableReasonWire.AppServerStartupFailed;
|
|
7814
|
+
}
|
|
7815
|
+
this.closeWithError(new AppServerProcessLostError(`Codex App Server process exited with code ${String(code)} and signal ${String(signal)}${startupStderr}${startupRequirement}`, void 0, unavailableReason.value));
|
|
7487
7816
|
});
|
|
7488
7817
|
}
|
|
7489
7818
|
static async start(options) {
|
|
7490
7819
|
const environment = createAppServerEnvironment(options.environment);
|
|
7491
7820
|
const executable = process.env.MOXT_CODEX_PATH ?? "codex";
|
|
7492
|
-
const child = (0, import_node_child_process3.spawn)(executable,
|
|
7821
|
+
const child = (0, import_node_child_process3.spawn)(executable, appServerArguments, {
|
|
7493
7822
|
cwd: options.processBaseDirectory,
|
|
7494
|
-
detached: (0,
|
|
7823
|
+
detached: (0, import_node_os6.platform)() !== "win32",
|
|
7495
7824
|
env: environment,
|
|
7496
7825
|
shell: false,
|
|
7497
7826
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -7510,6 +7839,14 @@ var init_app_server_client = __esm({
|
|
|
7510
7839
|
version: connectorVersion
|
|
7511
7840
|
}
|
|
7512
7841
|
});
|
|
7842
|
+
const codexVersion = await resolveCodexVersion({
|
|
7843
|
+
environment,
|
|
7844
|
+
executable,
|
|
7845
|
+
processBaseDirectory: options.processBaseDirectory,
|
|
7846
|
+
userAgent: initialized.userAgent
|
|
7847
|
+
});
|
|
7848
|
+
assertSupportedCodexVersion(codexVersion);
|
|
7849
|
+
client.initializationCompleted = true;
|
|
7513
7850
|
await client.notify("initialized");
|
|
7514
7851
|
const account = await client.request("account/read", { refreshToken: false });
|
|
7515
7852
|
await client.request("thread/loaded/list", {
|
|
@@ -7522,14 +7859,21 @@ var init_app_server_client = __esm({
|
|
|
7522
7859
|
appServerStatus: LocalCodexComponentStatusWire.Ready,
|
|
7523
7860
|
codexAuthStatus: authenticated ? LocalCodexComponentStatusWire.Ready : LocalCodexComponentStatusWire.AuthenticationRequired,
|
|
7524
7861
|
codexBinaryStatus: LocalCodexComponentStatusWire.Ready,
|
|
7525
|
-
codexVersion
|
|
7862
|
+
codexVersion,
|
|
7526
7863
|
nativeStoreIdentity: digestOpaque(`${options.nativeStoreIdentitySeed}\0${initialized.codexHome}`),
|
|
7527
7864
|
processGeneration: options.processGeneration
|
|
7528
7865
|
},
|
|
7529
7866
|
client
|
|
7530
7867
|
};
|
|
7531
7868
|
} catch (error) {
|
|
7532
|
-
|
|
7869
|
+
try {
|
|
7870
|
+
await client.stop();
|
|
7871
|
+
} catch (cleanupError) {
|
|
7872
|
+
try {
|
|
7873
|
+
await options.handlers.onStderr(`Failed to clean up Codex App Server after startup failed: ${errorMessage2(cleanupError)}`);
|
|
7874
|
+
} catch {
|
|
7875
|
+
}
|
|
7876
|
+
}
|
|
7533
7877
|
throw error;
|
|
7534
7878
|
}
|
|
7535
7879
|
}
|
|
@@ -7537,19 +7881,22 @@ var init_app_server_client = __esm({
|
|
|
7537
7881
|
return this.closed;
|
|
7538
7882
|
}
|
|
7539
7883
|
async request(method, params) {
|
|
7884
|
+
return await this.requestWithin(method, params, requestTimeoutMilliseconds2);
|
|
7885
|
+
}
|
|
7886
|
+
async requestWithin(method, params, timeoutMilliseconds) {
|
|
7540
7887
|
if (this.closed) {
|
|
7541
7888
|
throw new AppServerProcessLostError("Codex App Server process is closed");
|
|
7542
7889
|
}
|
|
7543
7890
|
const id = this.nextRequestId;
|
|
7544
7891
|
this.nextRequestId += 1;
|
|
7545
7892
|
const key = String(id);
|
|
7546
|
-
const response = new Promise((
|
|
7893
|
+
const response = new Promise((resolve10, reject) => {
|
|
7547
7894
|
const timeout = setTimeout(() => {
|
|
7548
7895
|
this.pending.delete(key);
|
|
7549
7896
|
reject(new AppServerRequestTimeoutError(method));
|
|
7550
|
-
},
|
|
7897
|
+
}, timeoutMilliseconds);
|
|
7551
7898
|
timeout.unref();
|
|
7552
|
-
this.pending.set(key, { reject, resolve:
|
|
7899
|
+
this.pending.set(key, { reject, resolve: resolve10, timeout });
|
|
7553
7900
|
});
|
|
7554
7901
|
await this.write({ id, method, params });
|
|
7555
7902
|
return await response;
|
|
@@ -7566,20 +7913,56 @@ var init_app_server_client = __esm({
|
|
|
7566
7913
|
async respondWithError(id, code, message) {
|
|
7567
7914
|
await this.write({ error: { code, message }, id });
|
|
7568
7915
|
}
|
|
7569
|
-
async
|
|
7570
|
-
|
|
7916
|
+
async captureProcessTree() {
|
|
7917
|
+
return await captureAppServerProcessTree(this.child);
|
|
7918
|
+
}
|
|
7919
|
+
async stop(capture) {
|
|
7920
|
+
const stopAlreadyRequested = this.intentionalStop;
|
|
7921
|
+
this.intentionalStop = true;
|
|
7922
|
+
const currentCapture = await captureAppServerProcessTree(this.child);
|
|
7923
|
+
const stopTarget = {
|
|
7924
|
+
descendantProcesses: /* @__PURE__ */ new Map(),
|
|
7925
|
+
verificationAvailable: currentCapture.status !== AppServerProcessTreeCaptureStatus.ProcessTableUnavailable && capture?.status !== AppServerProcessTreeCaptureStatus.ProcessTableUnavailable
|
|
7926
|
+
};
|
|
7927
|
+
for (const processIdentity of capture?.descendantProcesses ?? []) {
|
|
7928
|
+
stopTarget.descendantProcesses.set(processIdentity.processId, processIdentity);
|
|
7929
|
+
}
|
|
7930
|
+
for (const processIdentity of currentCapture.descendantProcesses) {
|
|
7931
|
+
stopTarget.descendantProcesses.set(processIdentity.processId, processIdentity);
|
|
7932
|
+
}
|
|
7933
|
+
if (stopAlreadyRequested && !await appServerProcessTreeIsRunning(this.child, stopTarget)) {
|
|
7571
7934
|
return;
|
|
7572
7935
|
}
|
|
7573
|
-
this.intentionalStop = true;
|
|
7574
|
-
this.child.stdin.end();
|
|
7575
|
-
await completionWithinExit(this.child, 2e3);
|
|
7576
7936
|
if (!this.closed) {
|
|
7577
|
-
|
|
7578
|
-
await completionWithinExit(this.child,
|
|
7937
|
+
this.child.stdin.end();
|
|
7938
|
+
await completionWithinExit(this.child, processExitGraceMilliseconds);
|
|
7579
7939
|
}
|
|
7580
|
-
if (
|
|
7581
|
-
|
|
7582
|
-
await completionWithinExit(this.child,
|
|
7940
|
+
if ((0, import_node_os6.platform)() === "win32" && await appServerProcessTreeIsRunning(this.child, stopTarget)) {
|
|
7941
|
+
const stopped = stopWindowsProcessTree(this.child);
|
|
7942
|
+
await completionWithinExit(this.child, processExitGraceMilliseconds);
|
|
7943
|
+
if (!await appServerProcessTreeIsRunning(this.child, stopTarget)) {
|
|
7944
|
+
return;
|
|
7945
|
+
}
|
|
7946
|
+
this.child.kill("SIGKILL");
|
|
7947
|
+
await completionWithinExit(this.child, processExitGraceMilliseconds);
|
|
7948
|
+
if (stopped.failureMessage !== void 0) {
|
|
7949
|
+
throw new AppServerProcessLostError(`Failed to stop Codex App Server process tree: ${stopped.failureMessage}`);
|
|
7950
|
+
}
|
|
7951
|
+
if (await appServerProcessTreeIsRunning(this.child, stopTarget)) {
|
|
7952
|
+
throw new AppServerProcessLostError("Codex App Server process tree did not stop");
|
|
7953
|
+
}
|
|
7954
|
+
return;
|
|
7955
|
+
}
|
|
7956
|
+
if (await appServerProcessTreeIsRunning(this.child, stopTarget)) {
|
|
7957
|
+
await terminateAppServerProcess(this.child, stopTarget);
|
|
7958
|
+
await completionWithinProcessTreeExit(this.child, stopTarget, processExitGraceMilliseconds);
|
|
7959
|
+
}
|
|
7960
|
+
if (await appServerProcessTreeIsRunning(this.child, stopTarget)) {
|
|
7961
|
+
await killAppServerProcess(this.child, stopTarget);
|
|
7962
|
+
await completionWithinProcessTreeExit(this.child, stopTarget, processExitGraceMilliseconds);
|
|
7963
|
+
}
|
|
7964
|
+
if (await appServerProcessTreeIsRunning(this.child, stopTarget)) {
|
|
7965
|
+
throw new AppServerProcessLostError(stopTarget.verificationAvailable ? "Codex App Server process tree did not stop" : "Codex App Server process tree could not be enumerated and verified as stopped");
|
|
7583
7966
|
}
|
|
7584
7967
|
}
|
|
7585
7968
|
receive(chunk) {
|
|
@@ -7650,12 +8033,12 @@ var init_app_server_client = __esm({
|
|
|
7650
8033
|
if (Buffer.byteLength(frame, "utf8") > maximumFrameBytes) {
|
|
7651
8034
|
throw new AppServerProtocolError("Codex App Server request exceeds the size limit");
|
|
7652
8035
|
}
|
|
7653
|
-
const operation = this.writeQueue.then(async () => await new Promise((
|
|
8036
|
+
const operation = this.writeQueue.then(async () => await new Promise((resolve10, reject) => {
|
|
7654
8037
|
this.child.stdin.write(frame, (error) => {
|
|
7655
8038
|
if (error) {
|
|
7656
8039
|
reject(error);
|
|
7657
8040
|
} else {
|
|
7658
|
-
|
|
8041
|
+
resolve10();
|
|
7659
8042
|
}
|
|
7660
8043
|
});
|
|
7661
8044
|
}));
|
|
@@ -7687,6 +8070,7 @@ var init_app_server_client = __esm({
|
|
|
7687
8070
|
client = {};
|
|
7688
8071
|
quarantinePromise;
|
|
7689
8072
|
startPromise;
|
|
8073
|
+
unavailableReason;
|
|
7690
8074
|
constructor(processBaseDirectory, environment, nativeStoreIdentitySeed, handlers, allocateProcessGeneration) {
|
|
7691
8075
|
this.processBaseDirectory = processBaseDirectory;
|
|
7692
8076
|
this.environment = environment;
|
|
@@ -7707,6 +8091,9 @@ var init_app_server_client = __esm({
|
|
|
7707
8091
|
currentClient() {
|
|
7708
8092
|
return this.client;
|
|
7709
8093
|
}
|
|
8094
|
+
currentUnavailableReason() {
|
|
8095
|
+
return this.unavailableReason === void 0 ? {} : { value: this.unavailableReason };
|
|
8096
|
+
}
|
|
7710
8097
|
async ensureStarted() {
|
|
7711
8098
|
await this.quarantinePromise;
|
|
7712
8099
|
if (this.client.value !== void 0 && !this.client.value.isClosed()) {
|
|
@@ -7720,7 +8107,7 @@ var init_app_server_client = __esm({
|
|
|
7720
8107
|
return await this.startPromise;
|
|
7721
8108
|
}
|
|
7722
8109
|
markProcessLost(processGeneration) {
|
|
7723
|
-
if (this.
|
|
8110
|
+
if (this.client.value?.processGeneration !== processGeneration) {
|
|
7724
8111
|
return false;
|
|
7725
8112
|
}
|
|
7726
8113
|
this.client = {};
|
|
@@ -7734,7 +8121,7 @@ var init_app_server_client = __esm({
|
|
|
7734
8121
|
await this.client.value?.stop();
|
|
7735
8122
|
this.client = {};
|
|
7736
8123
|
}
|
|
7737
|
-
async quarantineCurrentProcess() {
|
|
8124
|
+
async quarantineCurrentProcess(capture) {
|
|
7738
8125
|
if (this.quarantinePromise !== void 0) {
|
|
7739
8126
|
await this.quarantinePromise;
|
|
7740
8127
|
return;
|
|
@@ -7746,7 +8133,7 @@ var init_app_server_client = __esm({
|
|
|
7746
8133
|
appServerStatus: LocalCodexComponentStatusWire.Error
|
|
7747
8134
|
};
|
|
7748
8135
|
const operation = (async () => {
|
|
7749
|
-
await client?.stop();
|
|
8136
|
+
await client?.stop(capture);
|
|
7750
8137
|
})();
|
|
7751
8138
|
this.quarantinePromise = operation;
|
|
7752
8139
|
try {
|
|
@@ -7769,13 +8156,25 @@ var init_app_server_client = __esm({
|
|
|
7769
8156
|
});
|
|
7770
8157
|
this.capability = started.capability;
|
|
7771
8158
|
this.client = { value: started.client };
|
|
8159
|
+
this.unavailableReason = void 0;
|
|
7772
8160
|
return started.client;
|
|
7773
8161
|
} catch (error) {
|
|
7774
8162
|
const missing = error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
8163
|
+
const unsupportedVersion = error instanceof AppServerUnsupportedVersionError;
|
|
8164
|
+
const unsupportedStartupArguments = error instanceof AppServerProcessLostError && error.unavailableReason === LocalCodexUnavailableReasonWire.CodexVersionUnsupported;
|
|
8165
|
+
const incompatible = unsupportedVersion || unsupportedStartupArguments;
|
|
8166
|
+
this.unavailableReason = void 0;
|
|
8167
|
+
if (incompatible) {
|
|
8168
|
+
this.unavailableReason = LocalCodexUnavailableReasonWire.CodexVersionUnsupported;
|
|
8169
|
+
} else if (error instanceof AppServerProcessLostError && error.unavailableReason !== void 0 && !missing) {
|
|
8170
|
+
this.unavailableReason = error.unavailableReason;
|
|
8171
|
+
}
|
|
8172
|
+
const failureStatus = incompatible ? LocalCodexComponentStatusWire.Incompatible : LocalCodexComponentStatusWire.Error;
|
|
7775
8173
|
this.capability = {
|
|
7776
8174
|
...this.capability,
|
|
7777
|
-
appServerStatus: missing ? LocalCodexComponentStatusWire.Missing :
|
|
7778
|
-
codexBinaryStatus: missing ? LocalCodexComponentStatusWire.Missing :
|
|
8175
|
+
appServerStatus: missing ? LocalCodexComponentStatusWire.Missing : failureStatus,
|
|
8176
|
+
codexBinaryStatus: missing ? LocalCodexComponentStatusWire.Missing : failureStatus,
|
|
8177
|
+
...error instanceof AppServerUnsupportedVersionError ? { codexVersion: error.codexVersion } : {},
|
|
7779
8178
|
processGeneration
|
|
7780
8179
|
};
|
|
7781
8180
|
throw error;
|
|
@@ -8240,10 +8639,10 @@ function redactPath(value, canonicalRoot) {
|
|
|
8240
8639
|
if (value === canonicalRoot) {
|
|
8241
8640
|
return ".";
|
|
8242
8641
|
}
|
|
8243
|
-
if (value.startsWith(`${canonicalRoot}${
|
|
8244
|
-
return (0,
|
|
8642
|
+
if (value.startsWith(`${canonicalRoot}${import_node_path10.sep}`)) {
|
|
8643
|
+
return (0, import_node_path10.relative)(canonicalRoot, value);
|
|
8245
8644
|
}
|
|
8246
|
-
if ((0,
|
|
8645
|
+
if ((0, import_node_path10.isAbsolute)(value) || /^[A-Za-z]:[\\/]/.test(value)) {
|
|
8247
8646
|
return "[redacted-absolute-path]";
|
|
8248
8647
|
}
|
|
8249
8648
|
return value;
|
|
@@ -8292,12 +8691,12 @@ function recordValue(value) {
|
|
|
8292
8691
|
function isRecord3(value) {
|
|
8293
8692
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8294
8693
|
}
|
|
8295
|
-
var
|
|
8694
|
+
var import_node_path10;
|
|
8296
8695
|
var init_event_normalizer = __esm({
|
|
8297
8696
|
"../machine-connector/dist/runtime/local-codex-runtime/event-normalizer.js"() {
|
|
8298
8697
|
"use strict";
|
|
8299
8698
|
init_cjs_shims();
|
|
8300
|
-
|
|
8699
|
+
import_node_path10 = require("path");
|
|
8301
8700
|
init_contracts2();
|
|
8302
8701
|
}
|
|
8303
8702
|
});
|
|
@@ -8311,12 +8710,12 @@ function isThreadNameMetadataPendingResponse(message) {
|
|
|
8311
8710
|
}
|
|
8312
8711
|
function createActiveAttempt(claim, durable, workingDirectory) {
|
|
8313
8712
|
let resolveTerminal = (_value) => void 0;
|
|
8314
|
-
const terminal = new Promise((
|
|
8315
|
-
resolveTerminal =
|
|
8713
|
+
const terminal = new Promise((resolve10) => {
|
|
8714
|
+
resolveTerminal = resolve10;
|
|
8316
8715
|
});
|
|
8317
8716
|
let resolveFatal = (_error) => void 0;
|
|
8318
|
-
const fatal = new Promise((
|
|
8319
|
-
resolveFatal =
|
|
8717
|
+
const fatal = new Promise((resolve10) => {
|
|
8718
|
+
resolveFatal = resolve10;
|
|
8320
8719
|
});
|
|
8321
8720
|
return {
|
|
8322
8721
|
acceptedByAppServer: false,
|
|
@@ -8329,24 +8728,111 @@ function createActiveAttempt(claim, durable, workingDirectory) {
|
|
|
8329
8728
|
eventUploadQueue: Promise.resolve(),
|
|
8330
8729
|
fatal,
|
|
8331
8730
|
finished: new AbortController(),
|
|
8731
|
+
interruptedCleanupStarted: false,
|
|
8332
8732
|
leaseDeadlineMilliseconds: parseLeaseDeadline(claim.leaseExpiresAt),
|
|
8333
8733
|
nativeThreadId: durable.snapshot().nativeThreadId ?? claim.nativeThreadId,
|
|
8334
8734
|
spoolQueue: Promise.resolve(),
|
|
8735
|
+
subagentThreadIds: /* @__PURE__ */ new Set(),
|
|
8335
8736
|
terminal,
|
|
8336
8737
|
resolveFatal,
|
|
8337
8738
|
resolveTerminal,
|
|
8338
8739
|
workingDirectory
|
|
8339
8740
|
};
|
|
8340
8741
|
}
|
|
8341
|
-
function
|
|
8742
|
+
function createThreadTitleGenerationState(threadId) {
|
|
8342
8743
|
let resolveCompletion = () => void 0;
|
|
8343
|
-
const completion = new Promise((
|
|
8344
|
-
resolveCompletion =
|
|
8744
|
+
const completion = new Promise((resolve10) => {
|
|
8745
|
+
resolveCompletion = resolve10;
|
|
8345
8746
|
});
|
|
8346
|
-
|
|
8747
|
+
const state = {
|
|
8748
|
+
completed: false,
|
|
8347
8749
|
completion,
|
|
8348
|
-
|
|
8750
|
+
responseText: "",
|
|
8751
|
+
resolve: () => void 0,
|
|
8752
|
+
threadId
|
|
8753
|
+
};
|
|
8754
|
+
state.resolve = () => {
|
|
8755
|
+
if (state.completed) {
|
|
8756
|
+
return;
|
|
8757
|
+
}
|
|
8758
|
+
state.completed = true;
|
|
8759
|
+
resolveCompletion();
|
|
8349
8760
|
};
|
|
8761
|
+
return state;
|
|
8762
|
+
}
|
|
8763
|
+
function captureThreadTitleGenerationNotification(active, message) {
|
|
8764
|
+
const generation = active.initialThreadName?.generation;
|
|
8765
|
+
if (generation === void 0 || appServerMessageThreadId(message).value !== generation.threadId) {
|
|
8766
|
+
return false;
|
|
8767
|
+
}
|
|
8768
|
+
const method = message.method;
|
|
8769
|
+
const params = safeRecord(message.params);
|
|
8770
|
+
if (method === "item/agentMessage/delta") {
|
|
8771
|
+
const delta = optionalString2(params.delta).value;
|
|
8772
|
+
if (delta !== void 0) {
|
|
8773
|
+
generation.responseText += delta;
|
|
8774
|
+
}
|
|
8775
|
+
} else if (method === "item/completed") {
|
|
8776
|
+
const item = safeRecord(params.item);
|
|
8777
|
+
const text3 = optionalString2(item.text).value;
|
|
8778
|
+
if (item.type === "agentMessage" && text3 !== void 0) {
|
|
8779
|
+
generation.responseText = text3;
|
|
8780
|
+
}
|
|
8781
|
+
} else if (method === "turn/started") {
|
|
8782
|
+
const turnId = optionalString2(safeRecord(params.turn).id).value;
|
|
8783
|
+
if (turnId !== void 0) {
|
|
8784
|
+
generation.turnId = turnId;
|
|
8785
|
+
}
|
|
8786
|
+
} else if (method === "turn/completed") {
|
|
8787
|
+
const turn = safeRecord(params.turn);
|
|
8788
|
+
generation.status = optionalString2(turn.status).value;
|
|
8789
|
+
const turnId = optionalString2(turn.id).value;
|
|
8790
|
+
if (turnId !== void 0) {
|
|
8791
|
+
generation.turnId = turnId;
|
|
8792
|
+
}
|
|
8793
|
+
generation.resolve();
|
|
8794
|
+
}
|
|
8795
|
+
return true;
|
|
8796
|
+
}
|
|
8797
|
+
function captureSubagentThreadIds(active, message) {
|
|
8798
|
+
if (message.method !== "item/started" && message.method !== "item/completed") {
|
|
8799
|
+
return;
|
|
8800
|
+
}
|
|
8801
|
+
const item = safeRecord(safeRecord(message.params).item);
|
|
8802
|
+
const agentThreadId = optionalString2(item.agentThreadId).value;
|
|
8803
|
+
if (agentThreadId !== void 0) {
|
|
8804
|
+
active.subagentThreadIds.add(agentThreadId);
|
|
8805
|
+
}
|
|
8806
|
+
if (!Array.isArray(item.receiverThreadIds)) {
|
|
8807
|
+
return;
|
|
8808
|
+
}
|
|
8809
|
+
for (const threadId of item.receiverThreadIds) {
|
|
8810
|
+
if (typeof threadId === "string") {
|
|
8811
|
+
active.subagentThreadIds.add(threadId);
|
|
8812
|
+
}
|
|
8813
|
+
}
|
|
8814
|
+
}
|
|
8815
|
+
function appServerMessageThreadId(message) {
|
|
8816
|
+
const params = safeRecord(message.params);
|
|
8817
|
+
const direct = optionalString2(params.threadId).value;
|
|
8818
|
+
if (direct !== void 0) {
|
|
8819
|
+
return { value: direct };
|
|
8820
|
+
}
|
|
8821
|
+
return optionalString2(safeRecord(params.thread).id);
|
|
8822
|
+
}
|
|
8823
|
+
function normalizeThreadTitle(value) {
|
|
8824
|
+
const title = Array.from(value.trim().replace(/\s+/g, " ")).slice(0, maximumThreadTitleCharacters).join("");
|
|
8825
|
+
return title === "" ? {} : { value: title };
|
|
8826
|
+
}
|
|
8827
|
+
function parseGeneratedThreadTitle(value) {
|
|
8828
|
+
let parsed;
|
|
8829
|
+
try {
|
|
8830
|
+
parsed = JSON.parse(value);
|
|
8831
|
+
} catch {
|
|
8832
|
+
return {};
|
|
8833
|
+
}
|
|
8834
|
+
const title = optionalString2(safeRecord(parsed).title).value;
|
|
8835
|
+
return title === void 0 ? {} : normalizeThreadTitle(title);
|
|
8350
8836
|
}
|
|
8351
8837
|
function fenceFor(claim, connectorInstanceId) {
|
|
8352
8838
|
return {
|
|
@@ -8577,7 +9063,7 @@ function rpcIdentifier2(value) {
|
|
|
8577
9063
|
}
|
|
8578
9064
|
return {};
|
|
8579
9065
|
}
|
|
8580
|
-
function
|
|
9066
|
+
function errorMessage3(error) {
|
|
8581
9067
|
return error instanceof Error ? error.message : String(error);
|
|
8582
9068
|
}
|
|
8583
9069
|
async function probeExecutable(executable, environment) {
|
|
@@ -8590,7 +9076,7 @@ async function probeExecutable(executable, environment) {
|
|
|
8590
9076
|
const output = [];
|
|
8591
9077
|
child.stdout?.on("data", (chunk) => output.push(chunk));
|
|
8592
9078
|
try {
|
|
8593
|
-
const code = await new Promise((
|
|
9079
|
+
const code = await new Promise((resolve10, reject) => {
|
|
8594
9080
|
const timeout = setTimeout(() => {
|
|
8595
9081
|
child.kill("SIGTERM");
|
|
8596
9082
|
reject(new Error("Executable probe timed out"));
|
|
@@ -8602,7 +9088,7 @@ async function probeExecutable(executable, environment) {
|
|
|
8602
9088
|
});
|
|
8603
9089
|
child.once("close", (exitCode) => {
|
|
8604
9090
|
clearTimeout(timeout);
|
|
8605
|
-
|
|
9091
|
+
resolve10(exitCode ?? 1);
|
|
8606
9092
|
});
|
|
8607
9093
|
});
|
|
8608
9094
|
if (code !== 0) {
|
|
@@ -8623,11 +9109,11 @@ async function waitForAbort(signal, milliseconds) {
|
|
|
8623
9109
|
if (signal.aborted) {
|
|
8624
9110
|
return;
|
|
8625
9111
|
}
|
|
8626
|
-
await new Promise((
|
|
9112
|
+
await new Promise((resolve10) => {
|
|
8627
9113
|
const complete = () => {
|
|
8628
9114
|
clearTimeout(timeout);
|
|
8629
9115
|
signal.removeEventListener("abort", complete);
|
|
8630
|
-
|
|
9116
|
+
resolve10();
|
|
8631
9117
|
};
|
|
8632
9118
|
const timeout = setTimeout(complete, milliseconds);
|
|
8633
9119
|
timeout.unref();
|
|
@@ -8641,14 +9127,15 @@ function parseLeaseDeadline(value) {
|
|
|
8641
9127
|
}
|
|
8642
9128
|
return parsed;
|
|
8643
9129
|
}
|
|
8644
|
-
var import_node_child_process4,
|
|
9130
|
+
var import_node_child_process4, import_promises13, import_node_os7, import_node_path11, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, discoveryWaitSeconds, discoveryRetryMilliseconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, eventUploadRetryMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryRetryMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, maximumThreadTitleCharacters, maximumThreadTitleSourceCharacters, threadTitleGenerationTimeoutMilliseconds, interruptedExecutionCleanupTimeoutMilliseconds, threadTitleGenerationInstructions, threadTitleGenerationOutputSchema, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, LocalCodexRuntimeConnectionWorker;
|
|
8645
9131
|
var init_runtime_worker = __esm({
|
|
8646
9132
|
"../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
|
|
8647
9133
|
"use strict";
|
|
8648
9134
|
init_cjs_shims();
|
|
8649
9135
|
import_node_child_process4 = require("child_process");
|
|
8650
|
-
|
|
8651
|
-
|
|
9136
|
+
import_promises13 = require("fs/promises");
|
|
9137
|
+
import_node_os7 = require("os");
|
|
9138
|
+
import_node_path11 = require("path");
|
|
8652
9139
|
init_process_executor();
|
|
8653
9140
|
init_relay_client();
|
|
8654
9141
|
init_app_server_client();
|
|
@@ -8675,6 +9162,23 @@ var init_runtime_worker = __esm({
|
|
|
8675
9162
|
initialThreadNameRetryMilliseconds = 250;
|
|
8676
9163
|
maximumThreadNameRetryMilliseconds = 2e3;
|
|
8677
9164
|
maximumInitialThreadNameAttempts = 8;
|
|
9165
|
+
maximumThreadTitleCharacters = 40;
|
|
9166
|
+
maximumThreadTitleSourceCharacters = 4e3;
|
|
9167
|
+
threadTitleGenerationTimeoutMilliseconds = 2e4;
|
|
9168
|
+
interruptedExecutionCleanupTimeoutMilliseconds = 3e3;
|
|
9169
|
+
threadTitleGenerationInstructions = "Generate a concise semantic UI title for a coding conversation from its opening request. Use the request language. Prefer a specific noun phrase over a sentence, omit filler and incidental identifiers, and do not copy the full request unless it is already concise. Return only the structured result.";
|
|
9170
|
+
threadTitleGenerationOutputSchema = {
|
|
9171
|
+
additionalProperties: false,
|
|
9172
|
+
properties: {
|
|
9173
|
+
title: {
|
|
9174
|
+
maxLength: maximumThreadTitleCharacters,
|
|
9175
|
+
minLength: 1,
|
|
9176
|
+
type: "string"
|
|
9177
|
+
}
|
|
9178
|
+
},
|
|
9179
|
+
required: ["title"],
|
|
9180
|
+
type: "object"
|
|
9181
|
+
};
|
|
8678
9182
|
ThreadUnavailableError = class extends Error {
|
|
8679
9183
|
constructor(message) {
|
|
8680
9184
|
super(message);
|
|
@@ -8710,6 +9214,7 @@ var init_runtime_worker = __esm({
|
|
|
8710
9214
|
active = {};
|
|
8711
9215
|
configured = false;
|
|
8712
9216
|
enabled = false;
|
|
9217
|
+
lastCapabilityStartError;
|
|
8713
9218
|
lifetimeAbort = new AbortController();
|
|
8714
9219
|
registered = true;
|
|
8715
9220
|
unrecoverableAttemptIds = /* @__PURE__ */ new Set();
|
|
@@ -8747,6 +9252,9 @@ var init_runtime_worker = __esm({
|
|
|
8747
9252
|
if (active === void 0 || active.finished.signal.aborted) {
|
|
8748
9253
|
return;
|
|
8749
9254
|
}
|
|
9255
|
+
if (captureThreadTitleGenerationNotification(active, message)) {
|
|
9256
|
+
return;
|
|
9257
|
+
}
|
|
8750
9258
|
const normalized = normalizeAppServerNotification(message, active.workingDirectory).value;
|
|
8751
9259
|
if (normalized === void 0) {
|
|
8752
9260
|
return;
|
|
@@ -8755,8 +9263,13 @@ var init_runtime_worker = __esm({
|
|
|
8755
9263
|
if (normalized.correlation.nativeThreadId !== void 0 && active.nativeThreadId !== void 0 && normalized.correlation.nativeThreadId !== active.nativeThreadId) {
|
|
8756
9264
|
return;
|
|
8757
9265
|
}
|
|
8758
|
-
if (normalized.kind === "thread_title_updated"
|
|
8759
|
-
|
|
9266
|
+
if (normalized.kind === "thread_title_updated") {
|
|
9267
|
+
if (initialThreadName?.terminalObserved === true) {
|
|
9268
|
+
return;
|
|
9269
|
+
}
|
|
9270
|
+
if (normalized.payload.title === initialThreadName?.projectedTitle) {
|
|
9271
|
+
return;
|
|
9272
|
+
}
|
|
8760
9273
|
}
|
|
8761
9274
|
const notificationTurnId = normalized.correlation.nativeTurnId;
|
|
8762
9275
|
if (notificationTurnId !== void 0) {
|
|
@@ -8772,12 +9285,20 @@ var init_runtime_worker = __esm({
|
|
|
8772
9285
|
return;
|
|
8773
9286
|
}
|
|
8774
9287
|
}
|
|
9288
|
+
captureSubagentThreadIds(active, message);
|
|
8775
9289
|
if (normalized.terminalStatus !== void 0 && initialThreadName !== void 0) {
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
9290
|
+
initialThreadName.terminalObserved = true;
|
|
9291
|
+
}
|
|
9292
|
+
if (normalized.terminalStatus === LocalCodexTurnStatusWire.Interrupted) {
|
|
9293
|
+
await this.stopInterruptedExecution(active, normalized);
|
|
9294
|
+
return;
|
|
9295
|
+
}
|
|
9296
|
+
if (normalized.terminalStatus !== void 0 && initialThreadName !== void 0 && !initialThreadName.completed) {
|
|
9297
|
+
this.completeInitialThreadName(active);
|
|
8780
9298
|
}
|
|
9299
|
+
this.persistNormalizedNotification(active, normalized);
|
|
9300
|
+
}
|
|
9301
|
+
persistNormalizedNotification(active, normalized) {
|
|
8781
9302
|
void this.enqueueSpool(active, async () => {
|
|
8782
9303
|
const persisted = await active.durable.appendEvent(normalized.kind, normalized.payload, normalized.correlation);
|
|
8783
9304
|
if (normalized.correlation.nativeThreadId !== void 0 && active.nativeThreadId === void 0) {
|
|
@@ -8795,6 +9316,45 @@ var init_runtime_worker = __esm({
|
|
|
8795
9316
|
}).catch(() => void 0);
|
|
8796
9317
|
void this.enqueueEventFlush(active).catch(() => void 0);
|
|
8797
9318
|
}
|
|
9319
|
+
async stopInterruptedExecution(active, normalized) {
|
|
9320
|
+
active.interruptedCleanupStarted = true;
|
|
9321
|
+
active.initialThreadName?.generation?.resolve();
|
|
9322
|
+
const client = this.processPool.currentClient().value;
|
|
9323
|
+
if (client !== void 0 && active.nativeThreadId !== void 0) {
|
|
9324
|
+
await Promise.all([active.nativeThreadId, ...active.subagentThreadIds].map(async (threadId) => {
|
|
9325
|
+
try {
|
|
9326
|
+
await client.requestWithin("thread/backgroundTerminals/clean", { threadId }, interruptedExecutionCleanupTimeoutMilliseconds);
|
|
9327
|
+
} catch (error) {
|
|
9328
|
+
await this.logger.error(`Failed to clean background terminals for interrupted Local Codex thread ${threadId}; stopping its App Server process tree`, error);
|
|
9329
|
+
}
|
|
9330
|
+
}));
|
|
9331
|
+
}
|
|
9332
|
+
try {
|
|
9333
|
+
await this.processPool.quarantineCurrentProcess(active.processTreeCapture);
|
|
9334
|
+
} catch (error) {
|
|
9335
|
+
const failure = error instanceof Error ? error : new AppServerProcessLostError(String(error));
|
|
9336
|
+
await this.enqueueSpool(active, async () => {
|
|
9337
|
+
const terminal = await active.durable.appendEvent("turn_failed", {
|
|
9338
|
+
message: failure.message,
|
|
9339
|
+
status: "runtime_lost"
|
|
9340
|
+
}, {
|
|
9341
|
+
nativeThreadId: active.nativeThreadId,
|
|
9342
|
+
nativeTurnId: active.nativeTurnId
|
|
9343
|
+
});
|
|
9344
|
+
const result = {
|
|
9345
|
+
errorCode: "runtime_lost",
|
|
9346
|
+
errorMessage: failure.message,
|
|
9347
|
+
finalSequence: terminal.sequence,
|
|
9348
|
+
status: LocalCodexTurnStatusWire.RuntimeLost
|
|
9349
|
+
};
|
|
9350
|
+
await active.durable.markTerminal(result);
|
|
9351
|
+
this.settleTerminal(active, result);
|
|
9352
|
+
});
|
|
9353
|
+
return;
|
|
9354
|
+
}
|
|
9355
|
+
this.completeInitialThreadName(active);
|
|
9356
|
+
this.persistNormalizedNotification(active, normalized);
|
|
9357
|
+
}
|
|
8798
9358
|
async onServerRequest(message) {
|
|
8799
9359
|
const active = this.active.value;
|
|
8800
9360
|
const client = this.processPool.currentClient().value;
|
|
@@ -8805,6 +9365,11 @@ var init_runtime_worker = __esm({
|
|
|
8805
9365
|
}
|
|
8806
9366
|
return;
|
|
8807
9367
|
}
|
|
9368
|
+
const titleGeneration = active.initialThreadName?.generation;
|
|
9369
|
+
if (titleGeneration !== void 0 && appServerMessageThreadId(message).value === titleGeneration.threadId) {
|
|
9370
|
+
await client.respondWithError(message.id, -32601, "Thread title generation does not support interactive tools");
|
|
9371
|
+
return;
|
|
9372
|
+
}
|
|
8808
9373
|
const interactionKind = interactionKindFor(message.method, message.params).value;
|
|
8809
9374
|
if (interactionKind === void 0) {
|
|
8810
9375
|
await client.respondWithError(message.id, -32601, `Unsupported Local Codex interaction ${message.method}`);
|
|
@@ -8837,6 +9402,7 @@ var init_runtime_worker = __esm({
|
|
|
8837
9402
|
if (active === void 0 || !active.acceptedByAppServer) {
|
|
8838
9403
|
return;
|
|
8839
9404
|
}
|
|
9405
|
+
active.initialThreadName?.generation?.resolve();
|
|
8840
9406
|
await this.enqueueSpool(active, async () => {
|
|
8841
9407
|
await active.durable.appendEvent("runtime_error", { message: error.message }, {
|
|
8842
9408
|
nativeThreadId: active.nativeThreadId,
|
|
@@ -8871,6 +9437,10 @@ var init_runtime_worker = __esm({
|
|
|
8871
9437
|
}
|
|
8872
9438
|
async runHeartbeatLoop() {
|
|
8873
9439
|
while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
|
|
9440
|
+
if (this.active.value?.interruptedCleanupStarted) {
|
|
9441
|
+
await waitForAbort(this.lifetimeAbort.signal, claimRetryMilliseconds);
|
|
9442
|
+
continue;
|
|
9443
|
+
}
|
|
8874
9444
|
try {
|
|
8875
9445
|
await this.ensureCapability();
|
|
8876
9446
|
const response = await this.sendHeartbeat();
|
|
@@ -9000,7 +9570,7 @@ var init_runtime_worker = __esm({
|
|
|
9000
9570
|
async discoverDirectories(relativeDirectory) {
|
|
9001
9571
|
const canonicalRoot = await resolveCanonicalWorkingDirectory(this.connection.rootPath, ".");
|
|
9002
9572
|
const canonicalDirectory = await resolveCanonicalWorkingDirectory(canonicalRoot, relativeDirectory);
|
|
9003
|
-
const entries = (await (0,
|
|
9573
|
+
const entries = (await (0, import_promises13.readdir)(canonicalDirectory, {
|
|
9004
9574
|
withFileTypes: true
|
|
9005
9575
|
})).filter((entry) => entry.isDirectory()).filter((entry) => !entry.name.includes("\\")).sort((left, right) => left.name.localeCompare(right.name, void 0, {
|
|
9006
9576
|
numeric: true,
|
|
@@ -9008,11 +9578,11 @@ var init_runtime_worker = __esm({
|
|
|
9008
9578
|
}));
|
|
9009
9579
|
const eligibleDirectories = entries.map((entry) => ({
|
|
9010
9580
|
name: entry.name,
|
|
9011
|
-
relativePath: portableRelativeDirectory((0,
|
|
9581
|
+
relativePath: portableRelativeDirectory((0, import_node_path11.relative)(canonicalRoot, (0, import_node_path11.join)(canonicalDirectory, entry.name)))
|
|
9012
9582
|
})).filter((entry) => entry.name.length <= 255 && entry.relativePath.length <= 1024);
|
|
9013
9583
|
const directories = eligibleDirectories.slice(0, maximumDiscoveryDirectories);
|
|
9014
9584
|
return {
|
|
9015
|
-
currentRelativeDirectory: portableRelativeDirectory((0,
|
|
9585
|
+
currentRelativeDirectory: portableRelativeDirectory((0, import_node_path11.relative)(canonicalRoot, canonicalDirectory)),
|
|
9016
9586
|
directories,
|
|
9017
9587
|
truncated: eligibleDirectories.length > maximumDiscoveryDirectories
|
|
9018
9588
|
};
|
|
@@ -9042,7 +9612,10 @@ var init_runtime_worker = __esm({
|
|
|
9042
9612
|
await durable.markThreadPrepared(nativeThreadId);
|
|
9043
9613
|
await active.spoolQueue;
|
|
9044
9614
|
if (isNewThread) {
|
|
9045
|
-
active.initialThreadName =
|
|
9615
|
+
active.initialThreadName = {
|
|
9616
|
+
completed: false,
|
|
9617
|
+
terminalObserved: false
|
|
9618
|
+
};
|
|
9046
9619
|
}
|
|
9047
9620
|
if (isNewThread && !active.durable.snapshot().events.some((event2) => event2.kind === "thread_started")) {
|
|
9048
9621
|
await active.durable.appendEvent("thread_started", {}, { nativeThreadId });
|
|
@@ -9072,18 +9645,24 @@ var init_runtime_worker = __esm({
|
|
|
9072
9645
|
active.nativeTurnId = nativeTurnId;
|
|
9073
9646
|
active.acceptedByAppServer = true;
|
|
9074
9647
|
await durable.markRunning(nativeThreadId, nativeTurnId);
|
|
9648
|
+
if (isNewThread) {
|
|
9649
|
+
const initialThreadName = active.initialThreadName;
|
|
9650
|
+
if (initialThreadName === void 0) {
|
|
9651
|
+
throw new AppServerProtocolError("Initial thread name state is unavailable");
|
|
9652
|
+
}
|
|
9653
|
+
initialThreadName.task = this.setInitialThreadName(client, active, nativeThreadId).catch(async (error) => {
|
|
9654
|
+
if (!initialThreadName.completed) {
|
|
9655
|
+
await this.logger.error(`Failed to initialize the Local Codex thread name for ${nativeThreadId}`, error);
|
|
9656
|
+
}
|
|
9657
|
+
}).finally(() => {
|
|
9658
|
+
this.completeInitialThreadName(active);
|
|
9659
|
+
});
|
|
9660
|
+
}
|
|
9075
9661
|
await this.retryStateUpdate(active, {
|
|
9076
9662
|
nativeTurnId,
|
|
9077
9663
|
status: LocalCodexTurnStatusWire.Running
|
|
9078
9664
|
});
|
|
9079
9665
|
await this.interruptActiveTurnIfRequested(active, client);
|
|
9080
|
-
if (isNewThread) {
|
|
9081
|
-
try {
|
|
9082
|
-
await this.setInitialThreadName(client, active, nativeThreadId);
|
|
9083
|
-
} finally {
|
|
9084
|
-
active.initialThreadName?.resolve();
|
|
9085
|
-
}
|
|
9086
|
-
}
|
|
9087
9666
|
const terminal = await Promise.race([
|
|
9088
9667
|
active.terminal,
|
|
9089
9668
|
active.fatal.then((error) => {
|
|
@@ -9102,11 +9681,19 @@ var init_runtime_worker = __esm({
|
|
|
9102
9681
|
});
|
|
9103
9682
|
await durable.markUploaded();
|
|
9104
9683
|
await this.store.deleteLocalCodexAttempt(claim.attemptId);
|
|
9684
|
+
if (active.interruptedCleanupStarted) {
|
|
9685
|
+
active.finished.abort();
|
|
9686
|
+
await this.restoreAppServerAfterInterruption(active);
|
|
9687
|
+
}
|
|
9105
9688
|
} catch (error) {
|
|
9106
9689
|
if (error instanceof LeaseLostError) {
|
|
9107
9690
|
await this.logger.error(`Local Codex attempt ${claim.attemptId} stopped after losing its execution lease`, error);
|
|
9108
9691
|
} else if (error instanceof SpoolPersistenceError) {
|
|
9109
|
-
|
|
9692
|
+
try {
|
|
9693
|
+
await this.processPool.quarantineCurrentProcess();
|
|
9694
|
+
} catch (cleanupError) {
|
|
9695
|
+
await this.logger.error(`Failed to quarantine the Codex App Server after Local Codex attempt ${claim.attemptId} lost its durable spool`, cleanupError);
|
|
9696
|
+
}
|
|
9110
9697
|
await this.logger.error(`Local Codex attempt ${claim.attemptId} stopped after its durable spool failed`, error);
|
|
9111
9698
|
} else if (!active.acceptedByAppServer && error instanceof AppServerProcessLostError) {
|
|
9112
9699
|
await this.logger.error(`Local Codex attempt ${claim.attemptId} failed before App Server accepted the turn; it remains reclaimable`, error);
|
|
@@ -9114,11 +9701,16 @@ var init_runtime_worker = __esm({
|
|
|
9114
9701
|
await this.failAttempt(active, error);
|
|
9115
9702
|
}
|
|
9116
9703
|
} finally {
|
|
9117
|
-
|
|
9704
|
+
this.completeInitialThreadName(active);
|
|
9705
|
+
active.finished.abort();
|
|
9706
|
+
await active.initialThreadName?.task;
|
|
9707
|
+
const titleGenerationTurnId = active.initialThreadName?.generation?.turnId;
|
|
9708
|
+
if (titleGenerationTurnId !== void 0) {
|
|
9709
|
+
this.processPool.retireTurn(titleGenerationTurnId);
|
|
9710
|
+
}
|
|
9118
9711
|
if (active.acceptedByAppServer && active.nativeTurnId !== void 0) {
|
|
9119
9712
|
this.processPool.retireTurn(active.nativeTurnId);
|
|
9120
9713
|
}
|
|
9121
|
-
active.finished.abort();
|
|
9122
9714
|
await Promise.all([leaseLoop, controlLoop]);
|
|
9123
9715
|
}
|
|
9124
9716
|
}
|
|
@@ -9126,7 +9718,10 @@ var init_runtime_worker = __esm({
|
|
|
9126
9718
|
const claim = active.claim;
|
|
9127
9719
|
const parameters = {
|
|
9128
9720
|
approvalPolicy: claim.approvalPolicy,
|
|
9129
|
-
config: {
|
|
9721
|
+
config: {
|
|
9722
|
+
model_reasoning_effort: claim.reasoningEffort,
|
|
9723
|
+
...claim.developerInstructions === void 0 || claim.developerInstructions.length === 0 ? {} : { developer_instructions: claim.developerInstructions }
|
|
9724
|
+
},
|
|
9130
9725
|
cwd: active.workingDirectory,
|
|
9131
9726
|
ephemeral: false,
|
|
9132
9727
|
...claim.model === void 0 ? {} : { model: claim.model },
|
|
@@ -9157,7 +9752,7 @@ var init_runtime_worker = __esm({
|
|
|
9157
9752
|
throw error;
|
|
9158
9753
|
}
|
|
9159
9754
|
if (error instanceof AppServerResponseError && isMissingThreadResponse(error.responseMessage, preparedThreadId)) {
|
|
9160
|
-
throw new ThreadUnavailableError(
|
|
9755
|
+
throw new ThreadUnavailableError(errorMessage3(error));
|
|
9161
9756
|
}
|
|
9162
9757
|
throw error;
|
|
9163
9758
|
}
|
|
@@ -9174,13 +9769,13 @@ var init_runtime_worker = __esm({
|
|
|
9174
9769
|
try {
|
|
9175
9770
|
const createdResult = {};
|
|
9176
9771
|
await this.enqueueSpool(active, async () => {
|
|
9177
|
-
const terminal = await active.durable.appendEvent("turn_failed", { message:
|
|
9772
|
+
const terminal = await active.durable.appendEvent("turn_failed", { message: errorMessage3(error), status: errorCode2 }, {
|
|
9178
9773
|
nativeThreadId: active.nativeThreadId,
|
|
9179
9774
|
nativeTurnId: active.nativeTurnId
|
|
9180
9775
|
});
|
|
9181
9776
|
const result2 = {
|
|
9182
9777
|
errorCode: errorCode2,
|
|
9183
|
-
errorMessage:
|
|
9778
|
+
errorMessage: errorMessage3(error),
|
|
9184
9779
|
finalSequence: terminal.sequence,
|
|
9185
9780
|
status
|
|
9186
9781
|
};
|
|
@@ -9303,7 +9898,7 @@ var init_runtime_worker = __esm({
|
|
|
9303
9898
|
}
|
|
9304
9899
|
await this.logger.error(`Failed to renew Local Codex attempt ${active.claim.attemptId}`, error);
|
|
9305
9900
|
if (error instanceof LeaseLostError || error instanceof RelayHttpError && error.status >= 400 && error.status < 500) {
|
|
9306
|
-
await this.loseLease(active,
|
|
9901
|
+
await this.loseLease(active, errorMessage3(error));
|
|
9307
9902
|
return;
|
|
9308
9903
|
}
|
|
9309
9904
|
const retryRemaining = active.leaseDeadlineMilliseconds - Date.now();
|
|
@@ -9356,7 +9951,7 @@ var init_runtime_worker = __esm({
|
|
|
9356
9951
|
} catch (error) {
|
|
9357
9952
|
if (!active.finished.signal.aborted) {
|
|
9358
9953
|
if (error instanceof RelayHttpError && error.status >= 400 && error.status < 500) {
|
|
9359
|
-
await this.loseLease(active,
|
|
9954
|
+
await this.loseLease(active, errorMessage3(error));
|
|
9360
9955
|
return;
|
|
9361
9956
|
}
|
|
9362
9957
|
await this.logger.error(`Failed to poll Local Codex controls for ${active.claim.attemptId}`, error);
|
|
@@ -9429,6 +10024,7 @@ var init_runtime_worker = __esm({
|
|
|
9429
10024
|
if (!active.abortRequested || active.abortSent || active.nativeThreadId === void 0 || active.nativeTurnId === void 0) {
|
|
9430
10025
|
return;
|
|
9431
10026
|
}
|
|
10027
|
+
active.processTreeCapture = (await this.processPool.captureCurrentProcessTree()).value;
|
|
9432
10028
|
await client.request("turn/interrupt", {
|
|
9433
10029
|
threadId: active.nativeThreadId,
|
|
9434
10030
|
turnId: active.nativeTurnId
|
|
@@ -9548,7 +10144,7 @@ var init_runtime_worker = __esm({
|
|
|
9548
10144
|
await action();
|
|
9549
10145
|
});
|
|
9550
10146
|
active.spoolQueue = operation.catch((error) => {
|
|
9551
|
-
const failure = new SpoolPersistenceError(`Durable Local Codex spool failed: ${
|
|
10147
|
+
const failure = new SpoolPersistenceError(`Durable Local Codex spool failed: ${errorMessage3(error)}`, {
|
|
9552
10148
|
cause: error
|
|
9553
10149
|
});
|
|
9554
10150
|
this.signalFatal(active, failure);
|
|
@@ -9565,19 +10161,41 @@ var init_runtime_worker = __esm({
|
|
|
9565
10161
|
async ensureCapability() {
|
|
9566
10162
|
try {
|
|
9567
10163
|
await this.processPool.ensureStarted();
|
|
9568
|
-
|
|
10164
|
+
this.lastCapabilityStartError = void 0;
|
|
10165
|
+
} catch (error) {
|
|
10166
|
+
const unavailableReason = this.processPool.currentUnavailableReason().value;
|
|
10167
|
+
const errorSignature = unavailableReason ?? errorMessage3(error);
|
|
10168
|
+
if (this.lastCapabilityStartError === errorSignature) {
|
|
10169
|
+
return;
|
|
10170
|
+
}
|
|
10171
|
+
await this.logger.error(`Failed to start the shared Codex App Server for Local Codex connection ${this.connection.connectionId}`, error);
|
|
10172
|
+
this.lastCapabilityStartError = errorSignature;
|
|
10173
|
+
}
|
|
10174
|
+
}
|
|
10175
|
+
async restoreAppServerAfterInterruption(active) {
|
|
10176
|
+
if (this.lifetimeAbort.signal.aborted || this.relay.isRevoked()) {
|
|
9569
10177
|
return;
|
|
9570
10178
|
}
|
|
10179
|
+
try {
|
|
10180
|
+
await this.processPool.ensureStarted();
|
|
10181
|
+
this.applyHeartbeatResponse(await this.sendHeartbeat());
|
|
10182
|
+
} catch (error) {
|
|
10183
|
+
this.configured = false;
|
|
10184
|
+
this.enabled = false;
|
|
10185
|
+
await this.logger.error(`Failed to restore the shared Codex App Server after interrupting thread ${active.nativeThreadId ?? "unknown"}`, error);
|
|
10186
|
+
}
|
|
9571
10187
|
}
|
|
9572
10188
|
async sendHeartbeat() {
|
|
9573
10189
|
const capability = this.processPool.status();
|
|
10190
|
+
const unavailableReason = this.processPool.currentUnavailableReason().value;
|
|
9574
10191
|
const moxt = await probeExecutable(process.env.MOXT_CLI_PATH ?? "moxt", this.environment);
|
|
9575
10192
|
return await this.relay.heartbeatCodexRuntime({
|
|
9576
10193
|
...capability,
|
|
9577
10194
|
connectorInstanceId: this.connectorInstanceId,
|
|
9578
10195
|
moxtCliStatus: moxt.status,
|
|
9579
10196
|
moxtCliVersion: moxt.version,
|
|
9580
|
-
protocolVersion: localCodexRuntimeProtocolVersion
|
|
10197
|
+
protocolVersion: localCodexRuntimeProtocolVersion,
|
|
10198
|
+
...unavailableReason === void 0 ? {} : { unavailableReason }
|
|
9581
10199
|
});
|
|
9582
10200
|
}
|
|
9583
10201
|
applyHeartbeatResponse(response) {
|
|
@@ -9590,21 +10208,138 @@ var init_runtime_worker = __esm({
|
|
|
9590
10208
|
}
|
|
9591
10209
|
async setInitialThreadName(client, active, threadId) {
|
|
9592
10210
|
const claim = active.claim;
|
|
9593
|
-
|
|
10211
|
+
const initialThreadName = active.initialThreadName;
|
|
10212
|
+
if (initialThreadName === void 0 || initialThreadName.completed || active.interruptedCleanupStarted || claim.executionContext.workflowTaskId !== void 0 || claim.executionContext.workflowWatcherId !== void 0) {
|
|
9594
10213
|
return;
|
|
9595
10214
|
}
|
|
9596
10215
|
const text3 = firstTextInput(claim).value;
|
|
9597
10216
|
if (text3 === void 0) {
|
|
9598
10217
|
return;
|
|
9599
10218
|
}
|
|
9600
|
-
const
|
|
9601
|
-
if (
|
|
10219
|
+
const fallbackName = normalizeThreadTitle(text3).value;
|
|
10220
|
+
if (fallbackName === void 0) {
|
|
10221
|
+
return;
|
|
10222
|
+
}
|
|
10223
|
+
let name = fallbackName;
|
|
10224
|
+
try {
|
|
10225
|
+
const generatedName = await this.generateInitialThreadName(client, active, threadId, text3);
|
|
10226
|
+
if (initialThreadName.completed) {
|
|
10227
|
+
return;
|
|
10228
|
+
}
|
|
10229
|
+
if (generatedName.value === void 0) {
|
|
10230
|
+
throw new AppServerProtocolError("Codex returned no valid semantic thread title");
|
|
10231
|
+
}
|
|
10232
|
+
name = generatedName.value;
|
|
10233
|
+
} catch (error) {
|
|
10234
|
+
if (initialThreadName.completed || active.interruptedCleanupStarted) {
|
|
10235
|
+
return;
|
|
10236
|
+
}
|
|
10237
|
+
await this.logger.error(`Failed to generate a semantic title for Local Codex thread ${threadId}; using the opening request`, error);
|
|
10238
|
+
}
|
|
10239
|
+
if (initialThreadName.completed || active.interruptedCleanupStarted) {
|
|
10240
|
+
return;
|
|
10241
|
+
}
|
|
10242
|
+
await this.applyInitialThreadName(client, active, threadId, name);
|
|
10243
|
+
}
|
|
10244
|
+
async generateInitialThreadName(client, active, targetThreadId, openingRequest) {
|
|
10245
|
+
const initialThreadName = active.initialThreadName;
|
|
10246
|
+
if (initialThreadName === void 0) {
|
|
10247
|
+
throw new AppServerProtocolError("Initial thread name state is unavailable");
|
|
10248
|
+
}
|
|
10249
|
+
if (initialThreadName.completed) {
|
|
10250
|
+
return {};
|
|
10251
|
+
}
|
|
10252
|
+
const titleDirectory = (0, import_node_os7.tmpdir)();
|
|
10253
|
+
const titleThreadId = requireThreadId(await client.request("thread/start", {
|
|
10254
|
+
approvalPolicy: "never",
|
|
10255
|
+
baseInstructions: threadTitleGenerationInstructions,
|
|
10256
|
+
config: { model_reasoning_effort: "low" },
|
|
10257
|
+
cwd: titleDirectory,
|
|
10258
|
+
dynamicTools: [],
|
|
10259
|
+
ephemeral: true,
|
|
10260
|
+
...active.claim.model === void 0 ? {} : { model: active.claim.model },
|
|
10261
|
+
sandbox: "read-only",
|
|
10262
|
+
serviceName: "moxt-title-generation",
|
|
10263
|
+
threadSource: "title_generation"
|
|
10264
|
+
}));
|
|
10265
|
+
if (initialThreadName.completed) {
|
|
10266
|
+
return {};
|
|
10267
|
+
}
|
|
10268
|
+
if (titleThreadId === targetThreadId) {
|
|
10269
|
+
throw new AppServerProtocolError("Codex reused the visible thread for title generation");
|
|
10270
|
+
}
|
|
10271
|
+
const generation = createThreadTitleGenerationState(titleThreadId);
|
|
10272
|
+
initialThreadName.generation = generation;
|
|
10273
|
+
const titleInput = Array.from(openingRequest.trim()).slice(0, maximumThreadTitleSourceCharacters).join("");
|
|
10274
|
+
const response = await client.request("turn/start", {
|
|
10275
|
+
approvalPolicy: "never",
|
|
10276
|
+
cwd: titleDirectory,
|
|
10277
|
+
effort: "low",
|
|
10278
|
+
input: [
|
|
10279
|
+
{
|
|
10280
|
+
text: `Generate the title for this opening request:
|
|
10281
|
+
|
|
10282
|
+
${titleInput}`,
|
|
10283
|
+
type: "text"
|
|
10284
|
+
}
|
|
10285
|
+
],
|
|
10286
|
+
outputSchema: threadTitleGenerationOutputSchema,
|
|
10287
|
+
sandboxPolicy: { networkAccess: false, type: "readOnly" },
|
|
10288
|
+
threadId: titleThreadId
|
|
10289
|
+
});
|
|
10290
|
+
const titleTurnId = requireTurnId(response);
|
|
10291
|
+
if (generation.turnId !== void 0 && generation.turnId !== titleTurnId) {
|
|
10292
|
+
throw new AppServerProtocolError("Codex title generation crossed its turn boundary");
|
|
10293
|
+
}
|
|
10294
|
+
generation.turnId = titleTurnId;
|
|
10295
|
+
if (initialThreadName.completed) {
|
|
10296
|
+
if (generation.status !== "completed") {
|
|
10297
|
+
this.interruptInitialThreadNameGeneration(client, targetThreadId, generation);
|
|
10298
|
+
}
|
|
10299
|
+
return {};
|
|
10300
|
+
}
|
|
10301
|
+
await Promise.race([
|
|
10302
|
+
generation.completion,
|
|
10303
|
+
waitForAbort(active.finished.signal, threadTitleGenerationTimeoutMilliseconds),
|
|
10304
|
+
active.fatal.then(() => void 0)
|
|
10305
|
+
]);
|
|
10306
|
+
if (initialThreadName.completed) {
|
|
10307
|
+
if (generation.status !== "completed") {
|
|
10308
|
+
this.interruptInitialThreadNameGeneration(client, targetThreadId, generation);
|
|
10309
|
+
}
|
|
10310
|
+
return {};
|
|
10311
|
+
}
|
|
10312
|
+
if (!generation.completed) {
|
|
10313
|
+
this.interruptInitialThreadNameGeneration(client, targetThreadId, generation);
|
|
10314
|
+
throw new AppServerProtocolError("Codex semantic thread title generation timed out");
|
|
10315
|
+
}
|
|
10316
|
+
this.processPool.retireTurn(titleTurnId);
|
|
10317
|
+
if (generation.status !== "completed") {
|
|
10318
|
+
throw new AppServerProtocolError(`Codex semantic thread title generation ended with status ${generation.status ?? "unknown"}`);
|
|
10319
|
+
}
|
|
10320
|
+
return parseGeneratedThreadTitle(generation.responseText);
|
|
10321
|
+
}
|
|
10322
|
+
interruptInitialThreadNameGeneration(client, targetThreadId, generation) {
|
|
10323
|
+
if (generation.turnId === void 0) {
|
|
9602
10324
|
return;
|
|
9603
10325
|
}
|
|
10326
|
+
this.processPool.retireTurn(generation.turnId);
|
|
10327
|
+
void client.request("turn/interrupt", {
|
|
10328
|
+
threadId: generation.threadId,
|
|
10329
|
+
turnId: generation.turnId
|
|
10330
|
+
}).catch(async (error) => {
|
|
10331
|
+
await this.logger.error(`Failed to interrupt title generation for Local Codex thread ${targetThreadId}`, error);
|
|
10332
|
+
});
|
|
10333
|
+
}
|
|
10334
|
+
async applyInitialThreadName(client, active, threadId, name) {
|
|
9604
10335
|
const signal = active.finished.signal;
|
|
10336
|
+
const initialThreadName = active.initialThreadName;
|
|
10337
|
+
if (initialThreadName === void 0) {
|
|
10338
|
+
throw new AppServerProtocolError("Initial thread name state is unavailable");
|
|
10339
|
+
}
|
|
9605
10340
|
let retryMilliseconds = initialThreadNameRetryMilliseconds;
|
|
9606
10341
|
for (let attempt = 1; attempt <= maximumInitialThreadNameAttempts; attempt += 1) {
|
|
9607
|
-
if (signal.aborted) {
|
|
10342
|
+
if (signal.aborted || initialThreadName.completed) {
|
|
9608
10343
|
return;
|
|
9609
10344
|
}
|
|
9610
10345
|
try {
|
|
@@ -9613,6 +10348,9 @@ var init_runtime_worker = __esm({
|
|
|
9613
10348
|
threadId
|
|
9614
10349
|
});
|
|
9615
10350
|
} catch (error) {
|
|
10351
|
+
if (initialThreadName.completed) {
|
|
10352
|
+
return;
|
|
10353
|
+
}
|
|
9616
10354
|
const metadataPending = error instanceof AppServerResponseError && isThreadNameMetadataPendingResponse(error.responseMessage);
|
|
9617
10355
|
if (!metadataPending || attempt === maximumInitialThreadNameAttempts) {
|
|
9618
10356
|
await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
|
|
@@ -9622,9 +10360,8 @@ var init_runtime_worker = __esm({
|
|
|
9622
10360
|
retryMilliseconds = Math.min(retryMilliseconds * 2, maximumThreadNameRetryMilliseconds);
|
|
9623
10361
|
continue;
|
|
9624
10362
|
}
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
throw new AppServerProtocolError("Initial thread name state is unavailable");
|
|
10363
|
+
if (initialThreadName.completed) {
|
|
10364
|
+
return;
|
|
9628
10365
|
}
|
|
9629
10366
|
initialThreadName.projectedTitle = name;
|
|
9630
10367
|
await this.enqueueSpool(active, async () => {
|
|
@@ -9639,6 +10376,14 @@ var init_runtime_worker = __esm({
|
|
|
9639
10376
|
return;
|
|
9640
10377
|
}
|
|
9641
10378
|
}
|
|
10379
|
+
completeInitialThreadName(active) {
|
|
10380
|
+
const initialThreadName = active.initialThreadName;
|
|
10381
|
+
if (initialThreadName === void 0 || initialThreadName.completed) {
|
|
10382
|
+
return;
|
|
10383
|
+
}
|
|
10384
|
+
initialThreadName.completed = true;
|
|
10385
|
+
initialThreadName.generation?.resolve();
|
|
10386
|
+
}
|
|
9642
10387
|
unregisterRoute() {
|
|
9643
10388
|
if (!this.registered) {
|
|
9644
10389
|
return;
|
|
@@ -9783,12 +10528,19 @@ var init_process_pool = __esm({
|
|
|
9783
10528
|
currentClient() {
|
|
9784
10529
|
return this.supervisor.currentClient();
|
|
9785
10530
|
}
|
|
10531
|
+
currentUnavailableReason() {
|
|
10532
|
+
return this.supervisor.currentUnavailableReason();
|
|
10533
|
+
}
|
|
9786
10534
|
async ensureStarted() {
|
|
9787
10535
|
return await this.supervisor.ensureStarted();
|
|
9788
10536
|
}
|
|
9789
|
-
async
|
|
10537
|
+
async captureCurrentProcessTree() {
|
|
10538
|
+
const client = this.supervisor.currentClient().value;
|
|
10539
|
+
return client === void 0 ? {} : { value: await client.captureProcessTree() };
|
|
10540
|
+
}
|
|
10541
|
+
async quarantineCurrentProcess(capture) {
|
|
9790
10542
|
this.loadedThreadIds.clear();
|
|
9791
|
-
await this.supervisor.quarantineCurrentProcess();
|
|
10543
|
+
await this.supervisor.quarantineCurrentProcess(capture);
|
|
9792
10544
|
}
|
|
9793
10545
|
async stop() {
|
|
9794
10546
|
this.loadedThreadIds.clear();
|
|
@@ -9830,12 +10582,12 @@ function delay4(milliseconds) {
|
|
|
9830
10582
|
setTimeout(resolvePromise, milliseconds);
|
|
9831
10583
|
});
|
|
9832
10584
|
}
|
|
9833
|
-
var
|
|
10585
|
+
var import_node_os8, import_node_crypto9, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, commandOutputBatchMaxBytes, commandOutputFlushIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
|
|
9834
10586
|
var init_daemon = __esm({
|
|
9835
10587
|
"../machine-connector/dist/runtime/daemon.js"() {
|
|
9836
10588
|
"use strict";
|
|
9837
10589
|
init_cjs_shims();
|
|
9838
|
-
|
|
10590
|
+
import_node_os8 = require("os");
|
|
9839
10591
|
import_node_crypto9 = require("crypto");
|
|
9840
10592
|
init_enums();
|
|
9841
10593
|
init_contracts();
|
|
@@ -9952,7 +10704,7 @@ var init_daemon = __esm({
|
|
|
9952
10704
|
this.throwIfStopping();
|
|
9953
10705
|
await this.logger.info("Moxt Machine Connector started", {
|
|
9954
10706
|
connectorInstanceId: this.connectorInstanceId,
|
|
9955
|
-
hostname: (0,
|
|
10707
|
+
hostname: (0, import_node_os8.hostname)(),
|
|
9956
10708
|
version: connectorVersion
|
|
9957
10709
|
});
|
|
9958
10710
|
this.connections = await this.store.listConnections();
|
|
@@ -9983,21 +10735,35 @@ var init_daemon = __esm({
|
|
|
9983
10735
|
}
|
|
9984
10736
|
async stop() {
|
|
9985
10737
|
this.stopping = true;
|
|
9986
|
-
await Promise.all([...this.activeJobs.values()].map(async (activeJob) => {
|
|
9987
|
-
await activeJob.cancellation.request(ExecutionCancellationReason.Stopping);
|
|
9988
|
-
}));
|
|
9989
|
-
await Promise.all([...this.localCodexWorkers.values()].map(async (worker) => await worker.stop()));
|
|
9990
|
-
await Promise.all([...this.localCodexProcessPools.values()].map(async (pool) => await pool.stop()));
|
|
9991
|
-
await this.startupSettled;
|
|
9992
|
-
await this.ipcServer?.close();
|
|
9993
|
-
this.ipcServer = void 0;
|
|
9994
|
-
await this.lifetimeSettled;
|
|
9995
10738
|
try {
|
|
10739
|
+
await Promise.all([...this.activeJobs.values()].map(async (activeJob) => {
|
|
10740
|
+
await this.stopRuntimeComponent(`Failed to cancel Local Machine Job ${activeJob.claim.jobId} while stopping`, async () => await activeJob.cancellation.request(ExecutionCancellationReason.Stopping));
|
|
10741
|
+
}));
|
|
10742
|
+
await Promise.all([...this.localCodexWorkers.entries()].map(async ([connectionId, worker]) => {
|
|
10743
|
+
await this.stopRuntimeComponent(`Failed to stop Local Codex worker ${connectionId}`, async () => await worker.stop());
|
|
10744
|
+
}));
|
|
10745
|
+
await Promise.all([...this.localCodexProcessPools.values()].map(async (pool) => {
|
|
10746
|
+
await this.stopRuntimeComponent(`Failed to stop Local Codex App Server pool ${pool.poolKey}`, async () => await pool.stop());
|
|
10747
|
+
}));
|
|
10748
|
+
await this.stopRuntimeComponent("Failed while waiting for Moxt Machine Connector startup to settle", async () => await this.startupSettled);
|
|
10749
|
+
await this.stopRuntimeComponent("Failed to close Moxt Machine Connector IPC server", async () => {
|
|
10750
|
+
await this.ipcServer?.close();
|
|
10751
|
+
});
|
|
10752
|
+
this.ipcServer = void 0;
|
|
10753
|
+
await this.stopRuntimeComponent("Failed while waiting for Moxt Machine Connector lifetime to settle", async () => await this.lifetimeSettled);
|
|
9996
10754
|
await this.logger.info("Moxt Machine Connector stopped");
|
|
9997
10755
|
} finally {
|
|
10756
|
+
this.ipcServer = void 0;
|
|
9998
10757
|
await this.releaseDaemonLock();
|
|
9999
10758
|
}
|
|
10000
10759
|
}
|
|
10760
|
+
async stopRuntimeComponent(message, action) {
|
|
10761
|
+
try {
|
|
10762
|
+
await action();
|
|
10763
|
+
} catch (error) {
|
|
10764
|
+
await this.logger.error(message, error);
|
|
10765
|
+
}
|
|
10766
|
+
}
|
|
10001
10767
|
getStatus() {
|
|
10002
10768
|
return {
|
|
10003
10769
|
activeJobs: [...this.activeJobs.values()].map((activeJob) => {
|
|
@@ -10863,10 +11629,10 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
10863
11629
|
manager: selection.manager
|
|
10864
11630
|
};
|
|
10865
11631
|
}
|
|
10866
|
-
const
|
|
11632
|
+
const candidates2 = await automaticManagerCandidates(store, capabilities);
|
|
10867
11633
|
const failures = [];
|
|
10868
11634
|
let cleanupFailed = false;
|
|
10869
|
-
for (const manager of
|
|
11635
|
+
for (const manager of candidates2) {
|
|
10870
11636
|
try {
|
|
10871
11637
|
await replaceConfiguredManager(store, manager, options, runtime);
|
|
10872
11638
|
return {
|
|
@@ -10896,12 +11662,12 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
10896
11662
|
}
|
|
10897
11663
|
function createServiceEnvironment(options) {
|
|
10898
11664
|
const inheritedPath = options.environment.PATH ?? process.env.PATH ?? "";
|
|
10899
|
-
const nodeDirectory = (0,
|
|
10900
|
-
const pathEntries = [nodeDirectory, ...inheritedPath.split(
|
|
11665
|
+
const nodeDirectory = (0, import_node_path12.dirname)(options.nodePath);
|
|
11666
|
+
const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path12.delimiter)].filter((entry, index2, entries) => entry.length > 0 && entries.indexOf(entry) === index2);
|
|
10901
11667
|
return {
|
|
10902
11668
|
...options.environment,
|
|
10903
|
-
HOME: options.environment.HOME ?? process.env.HOME ?? (0,
|
|
10904
|
-
PATH: pathEntries.join(
|
|
11669
|
+
HOME: options.environment.HOME ?? process.env.HOME ?? (0, import_node_os9.homedir)(),
|
|
11670
|
+
PATH: pathEntries.join(import_node_path12.delimiter)
|
|
10905
11671
|
};
|
|
10906
11672
|
}
|
|
10907
11673
|
async function restartUserService(store, runtime = defaultServiceManagerRuntime) {
|
|
@@ -10938,7 +11704,7 @@ async function refreshManagedUserService(store, options, runtime = defaultServic
|
|
|
10938
11704
|
try {
|
|
10939
11705
|
await rollback();
|
|
10940
11706
|
} catch (rollbackError) {
|
|
10941
|
-
throw new Error(`${
|
|
11707
|
+
throw new Error(`${errorMessage4(error)}; restoring the previous ${manager} definition also failed: ${errorMessage4(rollbackError)}`, { cause: error });
|
|
10942
11708
|
}
|
|
10943
11709
|
throw error;
|
|
10944
11710
|
}
|
|
@@ -11005,21 +11771,21 @@ async function uninstallUserService(store, runtime = defaultServiceManagerRuntim
|
|
|
11005
11771
|
return manager;
|
|
11006
11772
|
}
|
|
11007
11773
|
async function automaticManagerCandidates(store, capabilities) {
|
|
11008
|
-
const
|
|
11774
|
+
const candidates2 = [];
|
|
11009
11775
|
const storedManager = await readStoredServiceManager(store);
|
|
11010
11776
|
if (storedManager !== UserServiceManager.None && managerIsAvailable(storedManager, capabilities)) {
|
|
11011
|
-
|
|
11777
|
+
candidates2.push(storedManager);
|
|
11012
11778
|
}
|
|
11013
|
-
if (capabilities.operatingSystem === "darwin" && !
|
|
11014
|
-
|
|
11779
|
+
if (capabilities.operatingSystem === "darwin" && !candidates2.includes(UserServiceManager.Launchd)) {
|
|
11780
|
+
candidates2.push(UserServiceManager.Launchd);
|
|
11015
11781
|
}
|
|
11016
|
-
if (capabilities.systemdUserAvailable && !
|
|
11017
|
-
|
|
11782
|
+
if (capabilities.systemdUserAvailable && !candidates2.includes(UserServiceManager.Systemd)) {
|
|
11783
|
+
candidates2.push(UserServiceManager.Systemd);
|
|
11018
11784
|
}
|
|
11019
|
-
if (capabilities.supervisorAvailable && !
|
|
11020
|
-
|
|
11785
|
+
if (capabilities.supervisorAvailable && !candidates2.includes(UserServiceManager.Supervisor)) {
|
|
11786
|
+
candidates2.push(UserServiceManager.Supervisor);
|
|
11021
11787
|
}
|
|
11022
|
-
return
|
|
11788
|
+
return candidates2;
|
|
11023
11789
|
}
|
|
11024
11790
|
async function replaceConfiguredManager(store, manager, options, runtime) {
|
|
11025
11791
|
const configuredManager = await readStoredServiceManager(store);
|
|
@@ -11095,7 +11861,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
11095
11861
|
"bootout",
|
|
11096
11862
|
`gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
|
|
11097
11863
|
]);
|
|
11098
|
-
await (0,
|
|
11864
|
+
await (0, import_promises14.rm)(launchAgentPath(), { force: true });
|
|
11099
11865
|
return;
|
|
11100
11866
|
}
|
|
11101
11867
|
if (manager === UserServiceManager.Systemd) {
|
|
@@ -11105,7 +11871,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
11105
11871
|
"--now",
|
|
11106
11872
|
"moxt-machine-connector.service"
|
|
11107
11873
|
]);
|
|
11108
|
-
await (0,
|
|
11874
|
+
await (0, import_promises14.rm)(systemdUnitPath(), { force: true });
|
|
11109
11875
|
await runCommandIgnoringFailure(runtime, "systemctl", [
|
|
11110
11876
|
"--user",
|
|
11111
11877
|
"daemon-reload"
|
|
@@ -11122,7 +11888,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
11122
11888
|
]);
|
|
11123
11889
|
await waitForSupervisorExit(store, runtime, supervisorProcessId);
|
|
11124
11890
|
}
|
|
11125
|
-
await (0,
|
|
11891
|
+
await (0, import_promises14.rm)(supervisorDirectory(store), {
|
|
11126
11892
|
force: true,
|
|
11127
11893
|
recursive: true
|
|
11128
11894
|
});
|
|
@@ -11148,17 +11914,17 @@ async function readStoredServiceManager(store) {
|
|
|
11148
11914
|
}
|
|
11149
11915
|
async function readManagedServiceDefinition(manager, store) {
|
|
11150
11916
|
try {
|
|
11151
|
-
return await (0,
|
|
11917
|
+
return await (0, import_promises14.readFile)(managedServiceDefinitionPath(manager, store), "utf8");
|
|
11152
11918
|
} catch (error) {
|
|
11153
|
-
if (
|
|
11919
|
+
if (isNodeErrorCode5(error, "ENOENT"))
|
|
11154
11920
|
return void 0;
|
|
11155
11921
|
throw error;
|
|
11156
11922
|
}
|
|
11157
11923
|
}
|
|
11158
11924
|
async function restoreManagedServiceDefinition(manager, store, definition2, runtime) {
|
|
11159
11925
|
const path4 = managedServiceDefinitionPath(manager, store);
|
|
11160
|
-
await (0,
|
|
11161
|
-
await (0,
|
|
11926
|
+
await (0, import_promises14.mkdir)((0, import_node_path12.dirname)(path4), { recursive: true });
|
|
11927
|
+
await (0, import_promises14.writeFile)(path4, definition2, { encoding: "utf8", mode: 384 });
|
|
11162
11928
|
if (manager === UserServiceManager.Launchd) {
|
|
11163
11929
|
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
11164
11930
|
await runCommandIgnoringFailure(runtime, "launchctl", [
|
|
@@ -11207,7 +11973,7 @@ function parseProcessId(value) {
|
|
|
11207
11973
|
async function persistServiceManager(store, manager, managedEntrypointPath, desiredState = ManagedServiceDesiredState.Running) {
|
|
11208
11974
|
await store.writeServiceManager({
|
|
11209
11975
|
desiredState,
|
|
11210
|
-
...managedEntrypointPath ? { managedEntrypointPath: (0,
|
|
11976
|
+
...managedEntrypointPath ? { managedEntrypointPath: (0, import_node_path12.resolve)(managedEntrypointPath) } : {},
|
|
11211
11977
|
manager,
|
|
11212
11978
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11213
11979
|
});
|
|
@@ -11220,9 +11986,9 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
|
|
|
11220
11986
|
const stored = (await store.readServiceManager()).value;
|
|
11221
11987
|
if (!stored || stored.manager === UserServiceManager.None)
|
|
11222
11988
|
return;
|
|
11223
|
-
const candidate = (0,
|
|
11989
|
+
const candidate = (0, import_node_path12.resolve)(candidateEntrypointPath);
|
|
11224
11990
|
if (stored.managedEntrypointPath) {
|
|
11225
|
-
if ((0,
|
|
11991
|
+
if ((0, import_node_path12.resolve)(stored.managedEntrypointPath) !== candidate) {
|
|
11226
11992
|
throw new Error("The managed Connector belongs to a different CLI installation. Run service install from the owning CLI to transfer management.");
|
|
11227
11993
|
}
|
|
11228
11994
|
return;
|
|
@@ -11232,16 +11998,16 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
|
|
|
11232
11998
|
}
|
|
11233
11999
|
}
|
|
11234
12000
|
async function isInsideSourceCheckout(path4) {
|
|
11235
|
-
let directory = (0,
|
|
12001
|
+
let directory = (0, import_node_path12.dirname)(path4);
|
|
11236
12002
|
while (true) {
|
|
11237
12003
|
try {
|
|
11238
|
-
await (0,
|
|
12004
|
+
await (0, import_promises14.stat)((0, import_node_path12.join)(directory, ".git"));
|
|
11239
12005
|
return true;
|
|
11240
12006
|
} catch (error) {
|
|
11241
|
-
if (!
|
|
12007
|
+
if (!isNodeErrorCode5(error, "ENOENT"))
|
|
11242
12008
|
throw error;
|
|
11243
12009
|
}
|
|
11244
|
-
const parent = (0,
|
|
12010
|
+
const parent = (0, import_node_path12.dirname)(directory);
|
|
11245
12011
|
if (parent === directory)
|
|
11246
12012
|
return false;
|
|
11247
12013
|
directory = parent;
|
|
@@ -11270,10 +12036,10 @@ function automaticSelectionDetail(manager) {
|
|
|
11270
12036
|
}
|
|
11271
12037
|
async function installLaunchAgent(store, options, runtime) {
|
|
11272
12038
|
const path4 = launchAgentPath();
|
|
11273
|
-
await (0,
|
|
12039
|
+
await (0, import_promises14.mkdir)((0, import_node_path12.dirname)(path4), { recursive: true });
|
|
11274
12040
|
const programArguments = [
|
|
11275
12041
|
options.nodePath,
|
|
11276
|
-
(0,
|
|
12042
|
+
(0, import_node_path12.resolve)(options.entrypointPath),
|
|
11277
12043
|
...options.commandArguments
|
|
11278
12044
|
];
|
|
11279
12045
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -11304,7 +12070,7 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
11304
12070
|
</dict>
|
|
11305
12071
|
</plist>
|
|
11306
12072
|
`;
|
|
11307
|
-
await (0,
|
|
12073
|
+
await (0, import_promises14.writeFile)(path4, plist, { encoding: "utf8", mode: 384 });
|
|
11308
12074
|
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
11309
12075
|
await runCommandIgnoringFailure(runtime, "launchctl", [
|
|
11310
12076
|
"bootout",
|
|
@@ -11320,10 +12086,10 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
11320
12086
|
}
|
|
11321
12087
|
async function installSystemdUserService(store, options, runtime) {
|
|
11322
12088
|
const path4 = systemdUnitPath();
|
|
11323
|
-
await (0,
|
|
12089
|
+
await (0, import_promises14.mkdir)((0, import_node_path12.dirname)(path4), { recursive: true });
|
|
11324
12090
|
const command = [
|
|
11325
12091
|
options.nodePath,
|
|
11326
|
-
(0,
|
|
12092
|
+
(0, import_node_path12.resolve)(options.entrypointPath),
|
|
11327
12093
|
...options.commandArguments
|
|
11328
12094
|
].map(escapeSystemdArgument).join(" ");
|
|
11329
12095
|
const unit = `[Unit]
|
|
@@ -11342,7 +12108,7 @@ ${Object.entries(options.environment).map(([name, value]) => `Environment=${esca
|
|
|
11342
12108
|
[Install]
|
|
11343
12109
|
WantedBy=default.target
|
|
11344
12110
|
`;
|
|
11345
|
-
await (0,
|
|
12111
|
+
await (0, import_promises14.writeFile)(path4, unit, { encoding: "utf8", mode: 384 });
|
|
11346
12112
|
await runtime.run("systemctl", ["--user", "daemon-reload"]);
|
|
11347
12113
|
await runtime.run("systemctl", [
|
|
11348
12114
|
"--user",
|
|
@@ -11357,14 +12123,14 @@ WantedBy=default.target
|
|
|
11357
12123
|
]);
|
|
11358
12124
|
await runCommandIgnoringFailure(runtime, "loginctl", [
|
|
11359
12125
|
"enable-linger",
|
|
11360
|
-
(0,
|
|
12126
|
+
(0, import_node_os9.userInfo)().username
|
|
11361
12127
|
]);
|
|
11362
12128
|
}
|
|
11363
12129
|
async function installSupervisorUserService(store, options, runtime) {
|
|
11364
12130
|
const directory = supervisorDirectory(store);
|
|
11365
12131
|
const configPath = supervisorConfigPath(store);
|
|
11366
|
-
await (0,
|
|
11367
|
-
await (0,
|
|
12132
|
+
await (0, import_promises14.mkdir)(directory, { recursive: true, mode: 448 });
|
|
12133
|
+
await (0, import_promises14.writeFile)(configPath, createSupervisorConfiguration(store, options), {
|
|
11368
12134
|
encoding: "utf8",
|
|
11369
12135
|
mode: 384
|
|
11370
12136
|
});
|
|
@@ -11378,7 +12144,7 @@ async function installSupervisorUserService(store, options, runtime) {
|
|
|
11378
12144
|
function createSupervisorConfiguration(store, options) {
|
|
11379
12145
|
const command = [
|
|
11380
12146
|
options.nodePath,
|
|
11381
|
-
(0,
|
|
12147
|
+
(0, import_node_path12.resolve)(options.entrypointPath),
|
|
11382
12148
|
...options.commandArguments
|
|
11383
12149
|
].map(escapeSupervisorArgument).join(" ");
|
|
11384
12150
|
const environment = Object.entries(options.environment).map(([name, value]) => `${name}="${escapeSupervisorEnvironment(value)}"`).join(",");
|
|
@@ -11402,7 +12168,7 @@ serverurl=unix://${supervisorSocketPath(store)}
|
|
|
11402
12168
|
|
|
11403
12169
|
[program:${supervisorProgramName}]
|
|
11404
12170
|
command=${command}
|
|
11405
|
-
directory=${escapeSupervisorPath((0,
|
|
12171
|
+
directory=${escapeSupervisorPath((0, import_node_path12.dirname)((0, import_node_path12.resolve)(options.entrypointPath)))}
|
|
11406
12172
|
environment=${environment}
|
|
11407
12173
|
autostart=true
|
|
11408
12174
|
autorestart=true
|
|
@@ -11435,8 +12201,8 @@ async function restartSupervisorUserService(store, runtime) {
|
|
|
11435
12201
|
await startSupervisorUserService(store, runtime, supervisorProcessId, stoppedConnector.processId);
|
|
11436
12202
|
}
|
|
11437
12203
|
async function startSupervisorUserService(store, runtime, previousSupervisorProcessId, previousConnectorProcessId) {
|
|
11438
|
-
await (0,
|
|
11439
|
-
await (0,
|
|
12204
|
+
await (0, import_promises14.rm)(supervisorSocketPath(store), { force: true });
|
|
12205
|
+
await (0, import_promises14.rm)(supervisorPidPath(store), { force: true });
|
|
11440
12206
|
await runtime.run("supervisord", ["-c", supervisorConfigPath(store)], {
|
|
11441
12207
|
environment: sanitizeEnvironment(process.env),
|
|
11442
12208
|
timeoutMilliseconds: serviceManagerMutationTimeoutMilliseconds
|
|
@@ -11517,7 +12283,7 @@ function localProcessIsRunning(processId) {
|
|
|
11517
12283
|
process.kill(processId, 0);
|
|
11518
12284
|
return true;
|
|
11519
12285
|
} catch (error) {
|
|
11520
|
-
if (
|
|
12286
|
+
if (isNodeErrorCode5(error, "ESRCH"))
|
|
11521
12287
|
return false;
|
|
11522
12288
|
throw error;
|
|
11523
12289
|
}
|
|
@@ -11545,10 +12311,10 @@ async function currentSupervisorProcessId(store, runtime) {
|
|
|
11545
12311
|
} catch {
|
|
11546
12312
|
}
|
|
11547
12313
|
try {
|
|
11548
|
-
const processId = parseProcessId(await (0,
|
|
12314
|
+
const processId = parseProcessId(await (0, import_promises14.readFile)(supervisorPidPath(store), "utf8"));
|
|
11549
12315
|
return processId !== void 0 && serviceProcessIsRunning(runtime, processId) ? processId : void 0;
|
|
11550
12316
|
} catch (error) {
|
|
11551
|
-
if (
|
|
12317
|
+
if (isNodeErrorCode5(error, "ENOENT"))
|
|
11552
12318
|
return void 0;
|
|
11553
12319
|
throw error;
|
|
11554
12320
|
}
|
|
@@ -11567,26 +12333,26 @@ async function currentSupervisorProgramProcessId(store, runtime) {
|
|
|
11567
12333
|
}
|
|
11568
12334
|
}
|
|
11569
12335
|
function launchAgentPath() {
|
|
11570
|
-
return (0,
|
|
12336
|
+
return (0, import_node_path12.join)(process.env.HOME ?? (0, import_node_os9.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
|
|
11571
12337
|
}
|
|
11572
12338
|
function systemdUnitPath() {
|
|
11573
|
-
const configHome = process.env.XDG_CONFIG_HOME ?? (0,
|
|
11574
|
-
return (0,
|
|
12339
|
+
const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path12.join)(process.env.HOME ?? (0, import_node_os9.homedir)(), ".config");
|
|
12340
|
+
return (0, import_node_path12.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
|
|
11575
12341
|
}
|
|
11576
12342
|
function supervisorDirectory(store) {
|
|
11577
|
-
return (0,
|
|
12343
|
+
return (0, import_node_path12.join)(store.baseDirectory, "supervisor");
|
|
11578
12344
|
}
|
|
11579
12345
|
function supervisorConfigPath(store) {
|
|
11580
|
-
return (0,
|
|
12346
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisord.conf");
|
|
11581
12347
|
}
|
|
11582
12348
|
function supervisorSocketPath(store) {
|
|
11583
|
-
return (0,
|
|
12349
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisor.sock");
|
|
11584
12350
|
}
|
|
11585
12351
|
function supervisorPidPath(store) {
|
|
11586
|
-
return (0,
|
|
12352
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisord.pid");
|
|
11587
12353
|
}
|
|
11588
12354
|
function supervisorLogPath(store) {
|
|
11589
|
-
return (0,
|
|
12355
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisord.log");
|
|
11590
12356
|
}
|
|
11591
12357
|
async function commandSucceeds(runtime, command, argumentsList) {
|
|
11592
12358
|
try {
|
|
@@ -11629,10 +12395,10 @@ function escapeSupervisorPath(value) {
|
|
|
11629
12395
|
function escapeSupervisorValue(value) {
|
|
11630
12396
|
return value.replaceAll("%", "%%").replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("\n", "\\n");
|
|
11631
12397
|
}
|
|
11632
|
-
function
|
|
12398
|
+
function errorMessage4(error) {
|
|
11633
12399
|
return error instanceof Error ? error.message : String(error);
|
|
11634
12400
|
}
|
|
11635
|
-
function
|
|
12401
|
+
function isNodeErrorCode5(error, expectedCode) {
|
|
11636
12402
|
return error instanceof Error && "code" in error && error.code === expectedCode;
|
|
11637
12403
|
}
|
|
11638
12404
|
function delay5(milliseconds) {
|
|
@@ -11646,15 +12412,15 @@ function serviceManagerCurrentTime(runtime) {
|
|
|
11646
12412
|
async function serviceManagerDelay(runtime, milliseconds) {
|
|
11647
12413
|
await (runtime.delay?.(milliseconds) ?? delay5(milliseconds));
|
|
11648
12414
|
}
|
|
11649
|
-
var import_node_child_process5,
|
|
12415
|
+
var import_node_child_process5, import_promises14, import_node_os9, import_node_path12, import_node_util2, execFileAsync, launchAgentLabel, serviceManagerProbeTimeoutMilliseconds, serviceManagerMutationTimeoutMilliseconds, supervisorProgramName, supervisorControlTimeoutMilliseconds, supervisorProgramStartSeconds, supervisorProgramStartRetries, supervisorProgramStopWaitSeconds, supervisorLifecycleBufferMilliseconds, supervisorExitTimeoutMilliseconds, supervisorProgramStartTimeoutMilliseconds, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
|
|
11650
12416
|
var init_service_manager = __esm({
|
|
11651
12417
|
"../machine-connector/dist/runtime/service-manager.js"() {
|
|
11652
12418
|
"use strict";
|
|
11653
12419
|
init_cjs_shims();
|
|
11654
12420
|
import_node_child_process5 = require("child_process");
|
|
11655
|
-
|
|
11656
|
-
|
|
11657
|
-
|
|
12421
|
+
import_promises14 = require("fs/promises");
|
|
12422
|
+
import_node_os9 = require("os");
|
|
12423
|
+
import_node_path12 = require("path");
|
|
11658
12424
|
import_node_util2 = require("util");
|
|
11659
12425
|
init_runtime_types();
|
|
11660
12426
|
init_shell_environment();
|
|
@@ -11683,7 +12449,7 @@ var init_service_manager = __esm({
|
|
|
11683
12449
|
UserServiceManager2["Systemd"] = "systemd";
|
|
11684
12450
|
})(UserServiceManager || (UserServiceManager = {}));
|
|
11685
12451
|
defaultServiceManagerRuntime = {
|
|
11686
|
-
operatingSystem: (0,
|
|
12452
|
+
operatingSystem: (0, import_node_os9.platform)(),
|
|
11687
12453
|
processIsRunning(processId) {
|
|
11688
12454
|
return localProcessIsRunning(processId);
|
|
11689
12455
|
},
|
|
@@ -11729,7 +12495,7 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
11729
12495
|
try {
|
|
11730
12496
|
managerOwnsProcess = await managedServiceOwnsProcess(manager, initial.pid, store);
|
|
11731
12497
|
} catch (error) {
|
|
11732
|
-
throw new DaemonRefreshError(DaemonRefreshStage.Ownership, `could not verify that the reachable Connector belongs to ${manager}: ${
|
|
12498
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Ownership, `could not verify that the reachable Connector belongs to ${manager}: ${errorMessage5(error)}`, { cause: error });
|
|
11733
12499
|
}
|
|
11734
12500
|
if (!managerOwnsProcess) {
|
|
11735
12501
|
throw new DaemonRefreshError(DaemonRefreshStage.Ownership, `${manager} does not own reachable daemon PID ${initial.pid}; stop that foreground or orphaned daemon before restarting the managed Connector`);
|
|
@@ -11738,7 +12504,7 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
11738
12504
|
try {
|
|
11739
12505
|
await validateCliEntrypoint(options, store);
|
|
11740
12506
|
} catch (error) {
|
|
11741
|
-
throw new DaemonRefreshError(DaemonRefreshStage.Validation,
|
|
12507
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Validation, errorMessage5(error), {
|
|
11742
12508
|
cause: error
|
|
11743
12509
|
});
|
|
11744
12510
|
}
|
|
@@ -11749,9 +12515,9 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
11749
12515
|
try {
|
|
11750
12516
|
refresh = await refreshManagedUserService(store, {
|
|
11751
12517
|
commandArguments: [...options.commandArguments],
|
|
11752
|
-
entrypointPath: (0,
|
|
12518
|
+
entrypointPath: (0, import_node_path13.resolve)(options.entrypointPath),
|
|
11753
12519
|
environment: { ...options.environment },
|
|
11754
|
-
nodePath: (0,
|
|
12520
|
+
nodePath: (0, import_node_path13.resolve)(options.nodePath)
|
|
11755
12521
|
});
|
|
11756
12522
|
if (!refresh) {
|
|
11757
12523
|
throw new Error("The Connector service is no longer managed by Moxt");
|
|
@@ -11771,7 +12537,7 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
11771
12537
|
try {
|
|
11772
12538
|
await refresh.rollback();
|
|
11773
12539
|
} catch (error) {
|
|
11774
|
-
throw new DaemonRefreshError(DaemonRefreshStage.Verification, `${verificationMessage}; restoring the previous service definition also failed: ${
|
|
12540
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Verification, `${verificationMessage}; restoring the previous service definition also failed: ${errorMessage5(error)}`, { cause: error });
|
|
11775
12541
|
}
|
|
11776
12542
|
throw new DaemonRefreshError(DaemonRefreshStage.Verification, verificationMessage);
|
|
11777
12543
|
} finally {
|
|
@@ -11787,10 +12553,10 @@ async function validateCliEntrypoint(options, store) {
|
|
|
11787
12553
|
if (options.commandArguments.length !== 2 || options.commandArguments[0] !== "machine" || options.commandArguments[1] !== "daemon") {
|
|
11788
12554
|
throw new Error("The managed daemon command must be `machine daemon`");
|
|
11789
12555
|
}
|
|
11790
|
-
const nodePath = await (0,
|
|
11791
|
-
const entrypointPath = await (0,
|
|
11792
|
-
await (0,
|
|
11793
|
-
await (0,
|
|
12556
|
+
const nodePath = await (0, import_promises15.realpath)((0, import_node_path13.resolve)(options.nodePath));
|
|
12557
|
+
const entrypointPath = await (0, import_promises15.realpath)((0, import_node_path13.resolve)(options.entrypointPath));
|
|
12558
|
+
await (0, import_promises15.access)(nodePath, import_promises15.constants.X_OK);
|
|
12559
|
+
await (0, import_promises15.access)(entrypointPath, import_promises15.constants.R_OK);
|
|
11794
12560
|
const probe = await execFileAsync2(nodePath, [entrypointPath, "--version"], {
|
|
11795
12561
|
encoding: "utf8",
|
|
11796
12562
|
env: {
|
|
@@ -11820,17 +12586,17 @@ async function reachableRuntimeStatus(store) {
|
|
|
11820
12586
|
function delay6(milliseconds) {
|
|
11821
12587
|
return new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds));
|
|
11822
12588
|
}
|
|
11823
|
-
function
|
|
12589
|
+
function errorMessage5(error) {
|
|
11824
12590
|
return error instanceof Error ? error.message : String(error);
|
|
11825
12591
|
}
|
|
11826
|
-
var import_node_child_process6,
|
|
12592
|
+
var import_node_child_process6, import_promises15, import_node_path13, import_node_util3, reconcileTimeoutMilliseconds, execFileAsync2, DaemonReconcileOutcome, DaemonRefreshStage, DaemonRefreshError;
|
|
11827
12593
|
var init_daemon_reconcile = __esm({
|
|
11828
12594
|
"../machine-connector/dist/runtime/daemon-reconcile.js"() {
|
|
11829
12595
|
"use strict";
|
|
11830
12596
|
init_cjs_shims();
|
|
11831
12597
|
import_node_child_process6 = require("child_process");
|
|
11832
|
-
|
|
11833
|
-
|
|
12598
|
+
import_promises15 = require("fs/promises");
|
|
12599
|
+
import_node_path13 = require("path");
|
|
11834
12600
|
import_node_util3 = require("util");
|
|
11835
12601
|
init_local_ipc();
|
|
11836
12602
|
init_process_lock();
|
|
@@ -11886,14 +12652,14 @@ async function runMachineDoctor(store) {
|
|
|
11886
12652
|
}
|
|
11887
12653
|
} catch (error) {
|
|
11888
12654
|
checks.push({
|
|
11889
|
-
detail:
|
|
12655
|
+
detail: errorMessage6(error),
|
|
11890
12656
|
name: "daemon",
|
|
11891
12657
|
status: DoctorCheckStatus.Failed
|
|
11892
12658
|
});
|
|
11893
12659
|
}
|
|
11894
12660
|
for (const connection of connections) {
|
|
11895
12661
|
try {
|
|
11896
|
-
await (0,
|
|
12662
|
+
await (0, import_promises16.access)(connection.rootPath, import_node_fs3.constants.R_OK | import_node_fs3.constants.X_OK);
|
|
11897
12663
|
checks.push({
|
|
11898
12664
|
detail: connection.rootPath,
|
|
11899
12665
|
name: `root:${connection.connectionId}`,
|
|
@@ -11901,14 +12667,14 @@ async function runMachineDoctor(store) {
|
|
|
11901
12667
|
});
|
|
11902
12668
|
} catch (error) {
|
|
11903
12669
|
checks.push({
|
|
11904
|
-
detail:
|
|
12670
|
+
detail: errorMessage6(error),
|
|
11905
12671
|
name: `root:${connection.connectionId}`,
|
|
11906
12672
|
status: DoctorCheckStatus.Failed
|
|
11907
12673
|
});
|
|
11908
12674
|
}
|
|
11909
12675
|
const relayUrl = new URL(connection.relayOrigin);
|
|
11910
12676
|
try {
|
|
11911
|
-
const address = await (0,
|
|
12677
|
+
const address = await (0, import_promises17.lookup)(relayUrl.hostname);
|
|
11912
12678
|
checks.push({
|
|
11913
12679
|
detail: `${relayUrl.hostname} resolves to ${address.address}`,
|
|
11914
12680
|
name: `dns:${connection.connectionId}`,
|
|
@@ -11916,7 +12682,7 @@ async function runMachineDoctor(store) {
|
|
|
11916
12682
|
});
|
|
11917
12683
|
} catch (error) {
|
|
11918
12684
|
checks.push({
|
|
11919
|
-
detail:
|
|
12685
|
+
detail: errorMessage6(error),
|
|
11920
12686
|
name: `dns:${connection.connectionId}`,
|
|
11921
12687
|
status: DoctorCheckStatus.Failed
|
|
11922
12688
|
});
|
|
@@ -11940,7 +12706,7 @@ async function runMachineDoctor(store) {
|
|
|
11940
12706
|
});
|
|
11941
12707
|
} catch (error) {
|
|
11942
12708
|
checks.push({
|
|
11943
|
-
detail:
|
|
12709
|
+
detail: errorMessage6(error),
|
|
11944
12710
|
name: `tls:${connection.connectionId}`,
|
|
11945
12711
|
status: DoctorCheckStatus.Failed
|
|
11946
12712
|
});
|
|
@@ -11966,7 +12732,7 @@ async function runMachineDoctor(store) {
|
|
|
11966
12732
|
});
|
|
11967
12733
|
} catch (error) {
|
|
11968
12734
|
checks.push({
|
|
11969
|
-
detail:
|
|
12735
|
+
detail: errorMessage6(error),
|
|
11970
12736
|
name: "codex",
|
|
11971
12737
|
status: DoctorCheckStatus.Warning
|
|
11972
12738
|
});
|
|
@@ -11980,25 +12746,25 @@ async function runMachineDoctor(store) {
|
|
|
11980
12746
|
});
|
|
11981
12747
|
} catch (error) {
|
|
11982
12748
|
checks.push({
|
|
11983
|
-
detail:
|
|
12749
|
+
detail: errorMessage6(error),
|
|
11984
12750
|
name: "claude",
|
|
11985
12751
|
status: DoctorCheckStatus.Warning
|
|
11986
12752
|
});
|
|
11987
12753
|
}
|
|
11988
12754
|
return checks;
|
|
11989
12755
|
}
|
|
11990
|
-
function
|
|
12756
|
+
function errorMessage6(error) {
|
|
11991
12757
|
return error instanceof Error ? error.message : String(error);
|
|
11992
12758
|
}
|
|
11993
|
-
var import_node_child_process7,
|
|
12759
|
+
var import_node_child_process7, import_promises16, import_node_fs3, import_promises17, import_node_util4, execFileAsync3, DoctorCheckStatus;
|
|
11994
12760
|
var init_doctor = __esm({
|
|
11995
12761
|
"../machine-connector/dist/runtime/doctor.js"() {
|
|
11996
12762
|
"use strict";
|
|
11997
12763
|
init_cjs_shims();
|
|
11998
12764
|
import_node_child_process7 = require("child_process");
|
|
11999
|
-
|
|
12000
|
-
|
|
12001
|
-
|
|
12765
|
+
import_promises16 = require("fs/promises");
|
|
12766
|
+
import_node_fs3 = require("fs");
|
|
12767
|
+
import_promises17 = require("dns/promises");
|
|
12002
12768
|
import_node_util4 = require("util");
|
|
12003
12769
|
init_local_ipc();
|
|
12004
12770
|
execFileAsync3 = (0, import_node_util4.promisify)(import_node_child_process7.execFile);
|
|
@@ -12268,7 +13034,7 @@ async function readRecentLogLines(store) {
|
|
|
12268
13034
|
}
|
|
12269
13035
|
async function readOptionalFile(path4) {
|
|
12270
13036
|
try {
|
|
12271
|
-
return await (0,
|
|
13037
|
+
return await (0, import_promises18.readFile)(path4, "utf8");
|
|
12272
13038
|
} catch (error) {
|
|
12273
13039
|
if (isMissingFile(error)) {
|
|
12274
13040
|
return "";
|
|
@@ -12324,16 +13090,16 @@ function isRecord4(value) {
|
|
|
12324
13090
|
function isMissingFile(error) {
|
|
12325
13091
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
12326
13092
|
}
|
|
12327
|
-
function
|
|
13093
|
+
function errorMessage7(error) {
|
|
12328
13094
|
return error instanceof Error ? error.message : String(error);
|
|
12329
13095
|
}
|
|
12330
|
-
var
|
|
13096
|
+
var import_promises18, import_promises19, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
|
|
12331
13097
|
var init_machine_manager = __esm({
|
|
12332
13098
|
"../machine-connector/dist/runtime/machine-manager.js"() {
|
|
12333
13099
|
"use strict";
|
|
12334
13100
|
init_cjs_shims();
|
|
12335
|
-
|
|
12336
|
-
|
|
13101
|
+
import_promises18 = require("fs/promises");
|
|
13102
|
+
import_promises19 = require("readline/promises");
|
|
12337
13103
|
import_node_readline = require("readline");
|
|
12338
13104
|
init_doctor();
|
|
12339
13105
|
init_local_ipc();
|
|
@@ -12530,7 +13296,7 @@ var init_machine_manager = __esm({
|
|
|
12530
13296
|
};
|
|
12531
13297
|
this.state.message = void 0;
|
|
12532
13298
|
} catch (error) {
|
|
12533
|
-
this.state.message =
|
|
13299
|
+
this.state.message = errorMessage7(error);
|
|
12534
13300
|
} finally {
|
|
12535
13301
|
this.refreshing = false;
|
|
12536
13302
|
this.render();
|
|
@@ -12567,7 +13333,7 @@ var init_machine_manager = __esm({
|
|
|
12567
13333
|
}
|
|
12568
13334
|
async runCommandAction(action) {
|
|
12569
13335
|
this.suspendTerminal();
|
|
12570
|
-
const reader = (0,
|
|
13336
|
+
const reader = (0, import_promises19.createInterface)({
|
|
12571
13337
|
input: process.stdin,
|
|
12572
13338
|
output: process.stdout
|
|
12573
13339
|
});
|
|
@@ -12578,7 +13344,7 @@ var init_machine_manager = __esm({
|
|
|
12578
13344
|
}
|
|
12579
13345
|
} catch (error) {
|
|
12580
13346
|
process.stdout.write(`
|
|
12581
|
-
Error: ${
|
|
13347
|
+
Error: ${errorMessage7(error)}
|
|
12582
13348
|
`);
|
|
12583
13349
|
}
|
|
12584
13350
|
await reader.question("\nPress Enter to return to the manager...");
|
|
@@ -12747,7 +13513,7 @@ async function pairMachine(store, options) {
|
|
|
12747
13513
|
const canonicalRoot = await store.getCanonicalRoot(options.rootPath);
|
|
12748
13514
|
const rootDisplayName = displayNameForRoot(canonicalRoot);
|
|
12749
13515
|
const identity = await ensureMachineIdentity(store);
|
|
12750
|
-
const machineName = options.machineName ?? (0,
|
|
13516
|
+
const machineName = options.machineName ?? (0, import_node_os10.hostname)();
|
|
12751
13517
|
const operatingSystem = getOperatingSystem();
|
|
12752
13518
|
const rootHandle = (0, import_node_crypto11.createHash)("sha256").update(identity.identity.deviceKeyFingerprint, "utf8").update("\0").update(canonicalRoot, "utf8").digest("base64url");
|
|
12753
13519
|
const client = new PairingRelayClient(options.relayOrigin);
|
|
@@ -12808,20 +13574,20 @@ async function pairMachine(store, options) {
|
|
|
12808
13574
|
throw new Error("Local Machine pairing expired");
|
|
12809
13575
|
}
|
|
12810
13576
|
function displayNameForRoot(canonicalRoot) {
|
|
12811
|
-
const name = (0,
|
|
13577
|
+
const name = (0, import_node_path14.basename)(canonicalRoot);
|
|
12812
13578
|
return name.length > 0 ? name : canonicalRoot;
|
|
12813
13579
|
}
|
|
12814
13580
|
function getOperatingSystem() {
|
|
12815
|
-
if ((0,
|
|
13581
|
+
if ((0, import_node_os10.platform)() === "darwin") {
|
|
12816
13582
|
return MachineOperatingSystem.MacOS;
|
|
12817
13583
|
}
|
|
12818
|
-
if ((0,
|
|
13584
|
+
if ((0, import_node_os10.platform)() === "linux") {
|
|
12819
13585
|
return MachineOperatingSystem.Linux;
|
|
12820
13586
|
}
|
|
12821
13587
|
return MachineOperatingSystem.Windows;
|
|
12822
13588
|
}
|
|
12823
13589
|
function openBrowser(url) {
|
|
12824
|
-
const command = (0,
|
|
13590
|
+
const command = (0, import_node_os10.platform)() === "darwin" ? "open" : "xdg-open";
|
|
12825
13591
|
const child = (0, import_node_child_process8.execFile)(command, [url], () => void 0);
|
|
12826
13592
|
child.unref();
|
|
12827
13593
|
}
|
|
@@ -12830,15 +13596,15 @@ function delay7(milliseconds) {
|
|
|
12830
13596
|
setTimeout(resolvePromise, milliseconds);
|
|
12831
13597
|
});
|
|
12832
13598
|
}
|
|
12833
|
-
var import_node_child_process8, import_node_crypto11,
|
|
13599
|
+
var import_node_child_process8, import_node_crypto11, import_node_os10, import_node_path14, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
|
|
12834
13600
|
var init_pairing = __esm({
|
|
12835
13601
|
"../machine-connector/dist/runtime/pairing.js"() {
|
|
12836
13602
|
"use strict";
|
|
12837
13603
|
init_cjs_shims();
|
|
12838
13604
|
import_node_child_process8 = require("child_process");
|
|
12839
13605
|
import_node_crypto11 = require("crypto");
|
|
12840
|
-
|
|
12841
|
-
|
|
13606
|
+
import_node_os10 = require("os");
|
|
13607
|
+
import_node_path14 = require("path");
|
|
12842
13608
|
init_contracts();
|
|
12843
13609
|
init_version();
|
|
12844
13610
|
init_enums();
|
|
@@ -12926,7 +13692,7 @@ function isMachineLifecycleMutation(command, commandArguments) {
|
|
|
12926
13692
|
async function connectCommand(store, argumentsList, entrypoint) {
|
|
12927
13693
|
const options = parseOptions(argumentsList);
|
|
12928
13694
|
const connectionCode = requiredOption(options, "code");
|
|
12929
|
-
const rootPath = (0,
|
|
13695
|
+
const rootPath = (0, import_node_path15.resolve)(options.root ?? process.cwd());
|
|
12930
13696
|
const serviceManagerPreference = requestedServiceManagerPreference(options);
|
|
12931
13697
|
await validateExplicitServiceManagerPreference(serviceManagerPreference);
|
|
12932
13698
|
await assertConnectionRuntimeCanConverge(store, serviceManagerPreference);
|
|
@@ -13278,7 +14044,7 @@ async function reachableRuntimeStatus2(store) {
|
|
|
13278
14044
|
}
|
|
13279
14045
|
async function readOptionalFile2(path4) {
|
|
13280
14046
|
try {
|
|
13281
|
-
return await (0,
|
|
14047
|
+
return await (0, import_promises20.readFile)(path4, "utf8");
|
|
13282
14048
|
} catch {
|
|
13283
14049
|
return "";
|
|
13284
14050
|
}
|
|
@@ -13307,13 +14073,13 @@ function delay8(milliseconds) {
|
|
|
13307
14073
|
setTimeout(resolvePromise, milliseconds);
|
|
13308
14074
|
});
|
|
13309
14075
|
}
|
|
13310
|
-
var
|
|
14076
|
+
var import_promises20, import_node_path15, defaultRelayOrigin;
|
|
13311
14077
|
var init_cli = __esm({
|
|
13312
14078
|
"../machine-connector/dist/cli.js"() {
|
|
13313
14079
|
"use strict";
|
|
13314
14080
|
init_cjs_shims();
|
|
13315
|
-
|
|
13316
|
-
|
|
14081
|
+
import_promises20 = require("fs/promises");
|
|
14082
|
+
import_node_path15 = require("path");
|
|
13317
14083
|
init_daemon();
|
|
13318
14084
|
init_daemon_reconcile();
|
|
13319
14085
|
init_doctor();
|
|
@@ -13608,7 +14374,7 @@ function getApiKeyOrUndefined() {
|
|
|
13608
14374
|
|
|
13609
14375
|
// src/utils/http.ts
|
|
13610
14376
|
function getUserAgent() {
|
|
13611
|
-
return `moxt-cli/${"0.10.0-beta.
|
|
14377
|
+
return `moxt-cli/${"0.10.0-beta.7"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
|
|
13612
14378
|
}
|
|
13613
14379
|
async function sendRequest(method, path4, init) {
|
|
13614
14380
|
return await fetch(`${getApiBaseUrl()}${path4}`, {
|
|
@@ -13795,8 +14561,8 @@ function readCommentContentFile(path4) {
|
|
|
13795
14561
|
if (!fs.existsSync(path4)) {
|
|
13796
14562
|
throw new FileCommentOptionsError(`Error: comment content file not found: ${path4}`);
|
|
13797
14563
|
}
|
|
13798
|
-
const
|
|
13799
|
-
if (!
|
|
14564
|
+
const stat6 = fs.statSync(path4);
|
|
14565
|
+
if (!stat6.isFile()) {
|
|
13800
14566
|
throw new FileCommentOptionsError(`Error: comment content path is not a file: ${path4}`);
|
|
13801
14567
|
}
|
|
13802
14568
|
const buffer2 = fs.readFileSync(path4);
|
|
@@ -14470,8 +15236,8 @@ var FileTokenizer = class _FileTokenizer extends AbstractTokenizer {
|
|
|
14470
15236
|
*/
|
|
14471
15237
|
static async fromFile(sourceFilePath) {
|
|
14472
15238
|
const fileHandle = await (0, import_promises.open)(sourceFilePath, "r");
|
|
14473
|
-
const
|
|
14474
|
-
return new _FileTokenizer(fileHandle, { fileInfo: { path: sourceFilePath, size:
|
|
15239
|
+
const stat6 = await fileHandle.stat();
|
|
15240
|
+
return new _FileTokenizer(fileHandle, { fileInfo: { path: sourceFilePath, size: stat6.size } });
|
|
14475
15241
|
}
|
|
14476
15242
|
constructor(fileHandle, options) {
|
|
14477
15243
|
super(options);
|
|
@@ -15026,7 +15792,9 @@ var fdt = new u8(32);
|
|
|
15026
15792
|
for (i = 0; i < 32; ++i)
|
|
15027
15793
|
fdt[i] = 5;
|
|
15028
15794
|
var i;
|
|
15795
|
+
var flm = /* @__PURE__ */ hMap(flt, 9, 0);
|
|
15029
15796
|
var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
|
|
15797
|
+
var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
|
|
15030
15798
|
var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
|
|
15031
15799
|
var max = function(a) {
|
|
15032
15800
|
var m = a[0];
|
|
@@ -15222,7 +15990,357 @@ var inflt = function(dat, st, buf, dict) {
|
|
|
15222
15990
|
} while (!final);
|
|
15223
15991
|
return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
|
|
15224
15992
|
};
|
|
15993
|
+
var wbits = function(d, p, v) {
|
|
15994
|
+
v <<= p & 7;
|
|
15995
|
+
var o = p / 8 | 0;
|
|
15996
|
+
d[o] |= v;
|
|
15997
|
+
d[o + 1] |= v >> 8;
|
|
15998
|
+
};
|
|
15999
|
+
var wbits16 = function(d, p, v) {
|
|
16000
|
+
v <<= p & 7;
|
|
16001
|
+
var o = p / 8 | 0;
|
|
16002
|
+
d[o] |= v;
|
|
16003
|
+
d[o + 1] |= v >> 8;
|
|
16004
|
+
d[o + 2] |= v >> 16;
|
|
16005
|
+
};
|
|
16006
|
+
var hTree = function(d, mb) {
|
|
16007
|
+
var t = [];
|
|
16008
|
+
for (var i2 = 0; i2 < d.length; ++i2) {
|
|
16009
|
+
if (d[i2])
|
|
16010
|
+
t.push({ s: i2, f: d[i2] });
|
|
16011
|
+
}
|
|
16012
|
+
var s = t.length;
|
|
16013
|
+
var t2 = t.slice();
|
|
16014
|
+
if (!s)
|
|
16015
|
+
return { t: et, l: 0 };
|
|
16016
|
+
if (s == 1) {
|
|
16017
|
+
var v = new u8(t[0].s + 1);
|
|
16018
|
+
v[t[0].s] = 1;
|
|
16019
|
+
return { t: v, l: 1 };
|
|
16020
|
+
}
|
|
16021
|
+
t.sort(function(a, b) {
|
|
16022
|
+
return a.f - b.f;
|
|
16023
|
+
});
|
|
16024
|
+
t.push({ s: -1, f: 25001 });
|
|
16025
|
+
var l = t[0], r = t[1], i0 = 0, i1 = 1, i22 = 2;
|
|
16026
|
+
t[0] = { s: -1, f: l.f + r.f, l, r };
|
|
16027
|
+
while (i1 != s - 1) {
|
|
16028
|
+
l = t[t[i0].f < t[i22].f ? i0++ : i22++];
|
|
16029
|
+
r = t[i0 != i1 && t[i0].f < t[i22].f ? i0++ : i22++];
|
|
16030
|
+
t[i1++] = { s: -1, f: l.f + r.f, l, r };
|
|
16031
|
+
}
|
|
16032
|
+
var maxSym = t2[0].s;
|
|
16033
|
+
for (var i2 = 1; i2 < s; ++i2) {
|
|
16034
|
+
if (t2[i2].s > maxSym)
|
|
16035
|
+
maxSym = t2[i2].s;
|
|
16036
|
+
}
|
|
16037
|
+
var tr = new u16(maxSym + 1);
|
|
16038
|
+
var mbt = ln(t[i1 - 1], tr, 0);
|
|
16039
|
+
if (mbt > mb) {
|
|
16040
|
+
var i2 = 0, dt = 0;
|
|
16041
|
+
var lft = mbt - mb, cst = 1 << lft;
|
|
16042
|
+
t2.sort(function(a, b) {
|
|
16043
|
+
return tr[b.s] - tr[a.s] || a.f - b.f;
|
|
16044
|
+
});
|
|
16045
|
+
for (; i2 < s; ++i2) {
|
|
16046
|
+
var i2_1 = t2[i2].s;
|
|
16047
|
+
if (tr[i2_1] > mb) {
|
|
16048
|
+
dt += cst - (1 << mbt - tr[i2_1]);
|
|
16049
|
+
tr[i2_1] = mb;
|
|
16050
|
+
} else
|
|
16051
|
+
break;
|
|
16052
|
+
}
|
|
16053
|
+
dt >>= lft;
|
|
16054
|
+
while (dt > 0) {
|
|
16055
|
+
var i2_2 = t2[i2].s;
|
|
16056
|
+
if (tr[i2_2] < mb)
|
|
16057
|
+
dt -= 1 << mb - tr[i2_2]++ - 1;
|
|
16058
|
+
else
|
|
16059
|
+
++i2;
|
|
16060
|
+
}
|
|
16061
|
+
for (; i2 >= 0 && dt; --i2) {
|
|
16062
|
+
var i2_3 = t2[i2].s;
|
|
16063
|
+
if (tr[i2_3] == mb) {
|
|
16064
|
+
--tr[i2_3];
|
|
16065
|
+
++dt;
|
|
16066
|
+
}
|
|
16067
|
+
}
|
|
16068
|
+
mbt = mb;
|
|
16069
|
+
}
|
|
16070
|
+
return { t: new u8(tr), l: mbt };
|
|
16071
|
+
};
|
|
16072
|
+
var ln = function(n, l, d) {
|
|
16073
|
+
return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d;
|
|
16074
|
+
};
|
|
16075
|
+
var lc = function(c) {
|
|
16076
|
+
var s = c.length;
|
|
16077
|
+
while (s && !c[--s])
|
|
16078
|
+
;
|
|
16079
|
+
var cl = new u16(++s);
|
|
16080
|
+
var cli = 0, cln = c[0], cls = 1;
|
|
16081
|
+
var w = function(v) {
|
|
16082
|
+
cl[cli++] = v;
|
|
16083
|
+
};
|
|
16084
|
+
for (var i2 = 1; i2 <= s; ++i2) {
|
|
16085
|
+
if (c[i2] == cln && i2 != s)
|
|
16086
|
+
++cls;
|
|
16087
|
+
else {
|
|
16088
|
+
if (!cln && cls > 2) {
|
|
16089
|
+
for (; cls > 138; cls -= 138)
|
|
16090
|
+
w(32754);
|
|
16091
|
+
if (cls > 2) {
|
|
16092
|
+
w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
|
|
16093
|
+
cls = 0;
|
|
16094
|
+
}
|
|
16095
|
+
} else if (cls > 3) {
|
|
16096
|
+
w(cln), --cls;
|
|
16097
|
+
for (; cls > 6; cls -= 6)
|
|
16098
|
+
w(8304);
|
|
16099
|
+
if (cls > 2)
|
|
16100
|
+
w(cls - 3 << 5 | 8208), cls = 0;
|
|
16101
|
+
}
|
|
16102
|
+
while (cls--)
|
|
16103
|
+
w(cln);
|
|
16104
|
+
cls = 1;
|
|
16105
|
+
cln = c[i2];
|
|
16106
|
+
}
|
|
16107
|
+
}
|
|
16108
|
+
return { c: cl.subarray(0, cli), n: s };
|
|
16109
|
+
};
|
|
16110
|
+
var clen = function(cf, cl) {
|
|
16111
|
+
var l = 0;
|
|
16112
|
+
for (var i2 = 0; i2 < cl.length; ++i2)
|
|
16113
|
+
l += cf[i2] * cl[i2];
|
|
16114
|
+
return l;
|
|
16115
|
+
};
|
|
16116
|
+
var wfblk = function(out, pos, dat) {
|
|
16117
|
+
var s = dat.length;
|
|
16118
|
+
var o = shft(pos + 2);
|
|
16119
|
+
out[o] = s & 255;
|
|
16120
|
+
out[o + 1] = s >> 8;
|
|
16121
|
+
out[o + 2] = out[o] ^ 255;
|
|
16122
|
+
out[o + 3] = out[o + 1] ^ 255;
|
|
16123
|
+
for (var i2 = 0; i2 < s; ++i2)
|
|
16124
|
+
out[o + i2 + 4] = dat[i2];
|
|
16125
|
+
return (o + 4 + s) * 8;
|
|
16126
|
+
};
|
|
16127
|
+
var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
|
|
16128
|
+
wbits(out, p++, final);
|
|
16129
|
+
++lf[256];
|
|
16130
|
+
var _a2 = hTree(lf, 15), dlt = _a2.t, mlb = _a2.l;
|
|
16131
|
+
var _b2 = hTree(df, 15), ddt = _b2.t, mdb = _b2.l;
|
|
16132
|
+
var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
|
|
16133
|
+
var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
|
|
16134
|
+
var lcfreq = new u16(19);
|
|
16135
|
+
for (var i2 = 0; i2 < lclt.length; ++i2)
|
|
16136
|
+
++lcfreq[lclt[i2] & 31];
|
|
16137
|
+
for (var i2 = 0; i2 < lcdt.length; ++i2)
|
|
16138
|
+
++lcfreq[lcdt[i2] & 31];
|
|
16139
|
+
var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
|
|
16140
|
+
var nlcc = 19;
|
|
16141
|
+
for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
|
|
16142
|
+
;
|
|
16143
|
+
var flen = bl + 5 << 3;
|
|
16144
|
+
var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
|
|
16145
|
+
var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
|
|
16146
|
+
if (bs >= 0 && flen <= ftlen && flen <= dtlen)
|
|
16147
|
+
return wfblk(out, p, dat.subarray(bs, bs + bl));
|
|
16148
|
+
var lm, ll, dm, dl;
|
|
16149
|
+
wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
|
|
16150
|
+
if (dtlen < ftlen) {
|
|
16151
|
+
lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
|
|
16152
|
+
var llm = hMap(lct, mlcb, 0);
|
|
16153
|
+
wbits(out, p, nlc - 257);
|
|
16154
|
+
wbits(out, p + 5, ndc - 1);
|
|
16155
|
+
wbits(out, p + 10, nlcc - 4);
|
|
16156
|
+
p += 14;
|
|
16157
|
+
for (var i2 = 0; i2 < nlcc; ++i2)
|
|
16158
|
+
wbits(out, p + 3 * i2, lct[clim[i2]]);
|
|
16159
|
+
p += 3 * nlcc;
|
|
16160
|
+
var lcts = [lclt, lcdt];
|
|
16161
|
+
for (var it = 0; it < 2; ++it) {
|
|
16162
|
+
var clct = lcts[it];
|
|
16163
|
+
for (var i2 = 0; i2 < clct.length; ++i2) {
|
|
16164
|
+
var len = clct[i2] & 31;
|
|
16165
|
+
wbits(out, p, llm[len]), p += lct[len];
|
|
16166
|
+
if (len > 15)
|
|
16167
|
+
wbits(out, p, clct[i2] >> 5 & 127), p += clct[i2] >> 12;
|
|
16168
|
+
}
|
|
16169
|
+
}
|
|
16170
|
+
} else {
|
|
16171
|
+
lm = flm, ll = flt, dm = fdm, dl = fdt;
|
|
16172
|
+
}
|
|
16173
|
+
for (var i2 = 0; i2 < li; ++i2) {
|
|
16174
|
+
var sym = syms[i2];
|
|
16175
|
+
if (sym > 255) {
|
|
16176
|
+
var len = sym >> 18 & 31;
|
|
16177
|
+
wbits16(out, p, lm[len + 257]), p += ll[len + 257];
|
|
16178
|
+
if (len > 7)
|
|
16179
|
+
wbits(out, p, sym >> 23 & 31), p += fleb[len];
|
|
16180
|
+
var dst = sym & 31;
|
|
16181
|
+
wbits16(out, p, dm[dst]), p += dl[dst];
|
|
16182
|
+
if (dst > 3)
|
|
16183
|
+
wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst];
|
|
16184
|
+
} else {
|
|
16185
|
+
wbits16(out, p, lm[sym]), p += ll[sym];
|
|
16186
|
+
}
|
|
16187
|
+
}
|
|
16188
|
+
wbits16(out, p, lm[256]);
|
|
16189
|
+
return p + ll[256];
|
|
16190
|
+
};
|
|
16191
|
+
var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
|
|
15225
16192
|
var et = /* @__PURE__ */ new u8(0);
|
|
16193
|
+
var dflt = function(dat, lvl, plvl, pre, post, st) {
|
|
16194
|
+
var s = st.z || dat.length;
|
|
16195
|
+
var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7e3)) + post);
|
|
16196
|
+
var w = o.subarray(pre, o.length - post);
|
|
16197
|
+
var lst = st.l;
|
|
16198
|
+
var pos = (st.r || 0) & 7;
|
|
16199
|
+
if (lvl) {
|
|
16200
|
+
if (pos)
|
|
16201
|
+
w[0] = st.r >> 3;
|
|
16202
|
+
var opt = deo[lvl - 1];
|
|
16203
|
+
var n = opt >> 13, c = opt & 8191;
|
|
16204
|
+
var msk_1 = (1 << plvl) - 1;
|
|
16205
|
+
var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
|
|
16206
|
+
var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
|
|
16207
|
+
var hsh = function(i3) {
|
|
16208
|
+
return (dat[i3] ^ dat[i3 + 1] << bs1_1 ^ dat[i3 + 2] << bs2_1) & msk_1;
|
|
16209
|
+
};
|
|
16210
|
+
var syms = new i32(25e3);
|
|
16211
|
+
var lf = new u16(288), df = new u16(32);
|
|
16212
|
+
var lc_1 = 0, eb = 0, i2 = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
|
|
16213
|
+
for (; i2 + 2 < s; ++i2) {
|
|
16214
|
+
var hv = hsh(i2);
|
|
16215
|
+
var imod = i2 & 32767, pimod = head[hv];
|
|
16216
|
+
prev[imod] = pimod;
|
|
16217
|
+
head[hv] = imod;
|
|
16218
|
+
if (wi <= i2) {
|
|
16219
|
+
var rem = s - i2;
|
|
16220
|
+
if ((lc_1 > 7e3 || li > 24576) && (rem > 423 || !lst)) {
|
|
16221
|
+
pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i2 - bs, pos);
|
|
16222
|
+
li = lc_1 = eb = 0, bs = i2;
|
|
16223
|
+
for (var j = 0; j < 286; ++j)
|
|
16224
|
+
lf[j] = 0;
|
|
16225
|
+
for (var j = 0; j < 30; ++j)
|
|
16226
|
+
df[j] = 0;
|
|
16227
|
+
}
|
|
16228
|
+
var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
|
|
16229
|
+
if (rem > 2 && hv == hsh(i2 - dif)) {
|
|
16230
|
+
var maxn = Math.min(n, rem) - 1;
|
|
16231
|
+
var maxd = Math.min(32767, i2);
|
|
16232
|
+
var ml = Math.min(258, rem);
|
|
16233
|
+
while (dif <= maxd && --ch_1 && imod != pimod) {
|
|
16234
|
+
if (dat[i2 + l] == dat[i2 + l - dif]) {
|
|
16235
|
+
var nl = 0;
|
|
16236
|
+
for (; nl < ml && dat[i2 + nl] == dat[i2 + nl - dif]; ++nl)
|
|
16237
|
+
;
|
|
16238
|
+
if (nl > l) {
|
|
16239
|
+
l = nl, d = dif;
|
|
16240
|
+
if (nl > maxn)
|
|
16241
|
+
break;
|
|
16242
|
+
var mmd = Math.min(dif, nl - 2);
|
|
16243
|
+
var md = 0;
|
|
16244
|
+
for (var j = 0; j < mmd; ++j) {
|
|
16245
|
+
var ti = i2 - dif + j & 32767;
|
|
16246
|
+
var pti = prev[ti];
|
|
16247
|
+
var cd = ti - pti & 32767;
|
|
16248
|
+
if (cd > md)
|
|
16249
|
+
md = cd, pimod = ti;
|
|
16250
|
+
}
|
|
16251
|
+
}
|
|
16252
|
+
}
|
|
16253
|
+
imod = pimod, pimod = prev[imod];
|
|
16254
|
+
dif += imod - pimod & 32767;
|
|
16255
|
+
}
|
|
16256
|
+
}
|
|
16257
|
+
if (d) {
|
|
16258
|
+
syms[li++] = 268435456 | revfl[l] << 18 | revfd[d];
|
|
16259
|
+
var lin = revfl[l] & 31, din = revfd[d] & 31;
|
|
16260
|
+
eb += fleb[lin] + fdeb[din];
|
|
16261
|
+
++lf[257 + lin];
|
|
16262
|
+
++df[din];
|
|
16263
|
+
wi = i2 + l;
|
|
16264
|
+
++lc_1;
|
|
16265
|
+
} else {
|
|
16266
|
+
syms[li++] = dat[i2];
|
|
16267
|
+
++lf[dat[i2]];
|
|
16268
|
+
}
|
|
16269
|
+
}
|
|
16270
|
+
}
|
|
16271
|
+
for (i2 = Math.max(i2, wi); i2 < s; ++i2) {
|
|
16272
|
+
syms[li++] = dat[i2];
|
|
16273
|
+
++lf[dat[i2]];
|
|
16274
|
+
}
|
|
16275
|
+
pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i2 - bs, pos);
|
|
16276
|
+
if (!lst) {
|
|
16277
|
+
st.r = pos & 7 | w[pos / 8 | 0] << 3;
|
|
16278
|
+
pos -= 7;
|
|
16279
|
+
st.h = head, st.p = prev, st.i = i2, st.w = wi;
|
|
16280
|
+
}
|
|
16281
|
+
} else {
|
|
16282
|
+
for (var i2 = st.w || 0; i2 < s + lst; i2 += 65535) {
|
|
16283
|
+
var e = i2 + 65535;
|
|
16284
|
+
if (e >= s) {
|
|
16285
|
+
w[pos / 8 | 0] = lst;
|
|
16286
|
+
e = s;
|
|
16287
|
+
}
|
|
16288
|
+
pos = wfblk(w, pos + 1, dat.subarray(i2, e));
|
|
16289
|
+
}
|
|
16290
|
+
st.i = s;
|
|
16291
|
+
}
|
|
16292
|
+
return slc(o, 0, pre + shft(pos) + post);
|
|
16293
|
+
};
|
|
16294
|
+
var crct = /* @__PURE__ */ (function() {
|
|
16295
|
+
var t = new Int32Array(256);
|
|
16296
|
+
for (var i2 = 0; i2 < 256; ++i2) {
|
|
16297
|
+
var c = i2, k = 9;
|
|
16298
|
+
while (--k)
|
|
16299
|
+
c = (c & 1 && -306674912) ^ c >>> 1;
|
|
16300
|
+
t[i2] = c;
|
|
16301
|
+
}
|
|
16302
|
+
return t;
|
|
16303
|
+
})();
|
|
16304
|
+
var crc = function() {
|
|
16305
|
+
var c = -1;
|
|
16306
|
+
return {
|
|
16307
|
+
p: function(d) {
|
|
16308
|
+
var cr = c;
|
|
16309
|
+
for (var i2 = 0; i2 < d.length; ++i2)
|
|
16310
|
+
cr = crct[cr & 255 ^ d[i2]] ^ cr >>> 8;
|
|
16311
|
+
c = cr;
|
|
16312
|
+
},
|
|
16313
|
+
d: function() {
|
|
16314
|
+
return ~c;
|
|
16315
|
+
}
|
|
16316
|
+
};
|
|
16317
|
+
};
|
|
16318
|
+
var dopt = function(dat, opt, pre, post, st) {
|
|
16319
|
+
if (!st) {
|
|
16320
|
+
st = { l: 1 };
|
|
16321
|
+
if (opt.dictionary) {
|
|
16322
|
+
var dict = opt.dictionary.subarray(-32768);
|
|
16323
|
+
var newDat = new u8(dict.length + dat.length);
|
|
16324
|
+
newDat.set(dict);
|
|
16325
|
+
newDat.set(dat, dict.length);
|
|
16326
|
+
dat = newDat;
|
|
16327
|
+
st.w = dict.length;
|
|
16328
|
+
}
|
|
16329
|
+
}
|
|
16330
|
+
return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st);
|
|
16331
|
+
};
|
|
16332
|
+
var mrg = function(a, b) {
|
|
16333
|
+
var o = {};
|
|
16334
|
+
for (var k in a)
|
|
16335
|
+
o[k] = a[k];
|
|
16336
|
+
for (var k in b)
|
|
16337
|
+
o[k] = b[k];
|
|
16338
|
+
return o;
|
|
16339
|
+
};
|
|
16340
|
+
var wbytes = function(d, b, v) {
|
|
16341
|
+
for (; v; ++b)
|
|
16342
|
+
d[b] = v, v >>>= 8;
|
|
16343
|
+
};
|
|
15226
16344
|
var gzs = function(d) {
|
|
15227
16345
|
if (d[0] != 31 || d[1] != 139 || d[2] != 8)
|
|
15228
16346
|
err(6, "invalid gzip data");
|
|
@@ -15245,6 +16363,9 @@ var zls = function(d, dict) {
|
|
|
15245
16363
|
err(6, "invalid zlib data: " + (d[1] & 32 ? "need" : "unexpected") + " dictionary");
|
|
15246
16364
|
return (d[1] >> 3 & 4) + 2;
|
|
15247
16365
|
};
|
|
16366
|
+
function deflateSync(data, opts) {
|
|
16367
|
+
return dopt(data, opts || {}, 0, 0);
|
|
16368
|
+
}
|
|
15248
16369
|
function inflateSync(data, opts) {
|
|
15249
16370
|
return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
|
|
15250
16371
|
}
|
|
@@ -15260,6 +16381,20 @@ function unzlibSync(data, opts) {
|
|
|
15260
16381
|
function decompressSync(data, opts) {
|
|
15261
16382
|
return data[0] == 31 && data[1] == 139 && data[2] == 8 ? gunzipSync(data, opts) : (data[0] & 15) != 8 || data[0] >> 4 > 7 || (data[0] << 8 | data[1]) % 31 ? inflateSync(data, opts) : unzlibSync(data, opts);
|
|
15262
16383
|
}
|
|
16384
|
+
var fltn = function(d, p, t, o) {
|
|
16385
|
+
for (var k in d) {
|
|
16386
|
+
var val = d[k], n = p + k, op = o;
|
|
16387
|
+
if (Array.isArray(val))
|
|
16388
|
+
op = mrg(o, val[1]), val = val[0];
|
|
16389
|
+
if (ArrayBuffer.isView(val))
|
|
16390
|
+
t[n] = [val, op];
|
|
16391
|
+
else {
|
|
16392
|
+
t[n += "/"] = [new u8(0), op];
|
|
16393
|
+
fltn(val, n, t, o);
|
|
16394
|
+
}
|
|
16395
|
+
}
|
|
16396
|
+
};
|
|
16397
|
+
var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder();
|
|
15263
16398
|
var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
|
|
15264
16399
|
var tds = 0;
|
|
15265
16400
|
try {
|
|
@@ -15267,6 +16402,140 @@ try {
|
|
|
15267
16402
|
tds = 1;
|
|
15268
16403
|
} catch (e) {
|
|
15269
16404
|
}
|
|
16405
|
+
function strToU8(str, latin1) {
|
|
16406
|
+
if (latin1) {
|
|
16407
|
+
var ar_1 = new u8(str.length);
|
|
16408
|
+
for (var i2 = 0; i2 < str.length; ++i2)
|
|
16409
|
+
ar_1[i2] = str.charCodeAt(i2);
|
|
16410
|
+
return ar_1;
|
|
16411
|
+
}
|
|
16412
|
+
if (te)
|
|
16413
|
+
return te.encode(str);
|
|
16414
|
+
var l = str.length;
|
|
16415
|
+
var ar = new u8(str.length + (str.length >> 1));
|
|
16416
|
+
var ai = 0;
|
|
16417
|
+
var w = function(v) {
|
|
16418
|
+
ar[ai++] = v;
|
|
16419
|
+
};
|
|
16420
|
+
for (var i2 = 0; i2 < l; ++i2) {
|
|
16421
|
+
if (ai + 5 > ar.length) {
|
|
16422
|
+
var n = new u8(ai + 8 + (l - i2 << 1));
|
|
16423
|
+
n.set(ar);
|
|
16424
|
+
ar = n;
|
|
16425
|
+
}
|
|
16426
|
+
var c = str.charCodeAt(i2);
|
|
16427
|
+
if (c < 128 || latin1)
|
|
16428
|
+
w(c);
|
|
16429
|
+
else if (c < 2048)
|
|
16430
|
+
w(192 | c >> 6), w(128 | c & 63);
|
|
16431
|
+
else if (c > 55295 && c < 57344)
|
|
16432
|
+
c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i2) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
|
|
16433
|
+
else
|
|
16434
|
+
w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
|
|
16435
|
+
}
|
|
16436
|
+
return slc(ar, 0, ai);
|
|
16437
|
+
}
|
|
16438
|
+
var exfl = function(ex) {
|
|
16439
|
+
var le = 0;
|
|
16440
|
+
if (ex) {
|
|
16441
|
+
for (var k in ex) {
|
|
16442
|
+
var l = ex[k].length;
|
|
16443
|
+
if (l > 65535)
|
|
16444
|
+
err(9);
|
|
16445
|
+
le += l + 4;
|
|
16446
|
+
}
|
|
16447
|
+
}
|
|
16448
|
+
return le;
|
|
16449
|
+
};
|
|
16450
|
+
var wzh = function(d, b, f, fn, u, c, ce, co) {
|
|
16451
|
+
var fl2 = fn.length, ex = f.extra, col = co && co.length;
|
|
16452
|
+
var exl = exfl(ex);
|
|
16453
|
+
wbytes(d, b, ce != null ? 33639248 : 67324752), b += 4;
|
|
16454
|
+
if (ce != null)
|
|
16455
|
+
d[b++] = 20, d[b++] = f.os;
|
|
16456
|
+
d[b] = 20, b += 2;
|
|
16457
|
+
d[b++] = f.flag << 1 | (c < 0 && 8), d[b++] = u && 8;
|
|
16458
|
+
d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
|
|
16459
|
+
var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
|
|
16460
|
+
if (y < 0 || y > 119)
|
|
16461
|
+
err(10);
|
|
16462
|
+
wbytes(d, b, y << 25 | dt.getMonth() + 1 << 21 | dt.getDate() << 16 | dt.getHours() << 11 | dt.getMinutes() << 5 | dt.getSeconds() >> 1), b += 4;
|
|
16463
|
+
if (c != -1) {
|
|
16464
|
+
wbytes(d, b, f.crc);
|
|
16465
|
+
wbytes(d, b + 4, c < 0 ? -c - 2 : c);
|
|
16466
|
+
wbytes(d, b + 8, f.size);
|
|
16467
|
+
}
|
|
16468
|
+
wbytes(d, b + 12, fl2);
|
|
16469
|
+
wbytes(d, b + 14, exl), b += 16;
|
|
16470
|
+
if (ce != null) {
|
|
16471
|
+
wbytes(d, b, col);
|
|
16472
|
+
wbytes(d, b + 6, f.attrs);
|
|
16473
|
+
wbytes(d, b + 10, ce), b += 14;
|
|
16474
|
+
}
|
|
16475
|
+
d.set(fn, b);
|
|
16476
|
+
b += fl2;
|
|
16477
|
+
if (exl) {
|
|
16478
|
+
for (var k in ex) {
|
|
16479
|
+
var exf = ex[k], l = exf.length;
|
|
16480
|
+
wbytes(d, b, +k);
|
|
16481
|
+
wbytes(d, b + 2, l);
|
|
16482
|
+
d.set(exf, b + 4), b += 4 + l;
|
|
16483
|
+
}
|
|
16484
|
+
}
|
|
16485
|
+
if (col)
|
|
16486
|
+
d.set(co, b), b += col;
|
|
16487
|
+
return b;
|
|
16488
|
+
};
|
|
16489
|
+
var wzf = function(o, b, c, d, e) {
|
|
16490
|
+
wbytes(o, b, 101010256);
|
|
16491
|
+
wbytes(o, b + 8, c);
|
|
16492
|
+
wbytes(o, b + 10, c);
|
|
16493
|
+
wbytes(o, b + 12, d);
|
|
16494
|
+
wbytes(o, b + 16, e);
|
|
16495
|
+
};
|
|
16496
|
+
function zipSync(data, opts) {
|
|
16497
|
+
if (!opts)
|
|
16498
|
+
opts = {};
|
|
16499
|
+
var r = {};
|
|
16500
|
+
var files = [];
|
|
16501
|
+
fltn(data, "", r, opts);
|
|
16502
|
+
var o = 0;
|
|
16503
|
+
var tot = 0;
|
|
16504
|
+
for (var fn in r) {
|
|
16505
|
+
var _a2 = r[fn], file = _a2[0], p = _a2[1];
|
|
16506
|
+
var compression = p.level == 0 ? 0 : 8;
|
|
16507
|
+
var f = strToU8(fn), s = f.length;
|
|
16508
|
+
var com = p.comment, m = com && strToU8(com), ms = m && m.length;
|
|
16509
|
+
var exl = exfl(p.extra);
|
|
16510
|
+
if (s > 65535)
|
|
16511
|
+
err(11);
|
|
16512
|
+
var d = compression ? deflateSync(file, p) : file, l = d.length;
|
|
16513
|
+
var c = crc();
|
|
16514
|
+
c.p(file);
|
|
16515
|
+
files.push(mrg(p, {
|
|
16516
|
+
size: file.length,
|
|
16517
|
+
crc: c.d(),
|
|
16518
|
+
c: d,
|
|
16519
|
+
f,
|
|
16520
|
+
m,
|
|
16521
|
+
u: s != fn.length || m && com.length != ms,
|
|
16522
|
+
o,
|
|
16523
|
+
compression
|
|
16524
|
+
}));
|
|
16525
|
+
o += 30 + s + exl + l;
|
|
16526
|
+
tot += 76 + 2 * (s + exl) + (ms || 0) + l;
|
|
16527
|
+
}
|
|
16528
|
+
var out = new u8(tot + 22), oe = o, cdl = tot - o;
|
|
16529
|
+
for (var i2 = 0; i2 < files.length; ++i2) {
|
|
16530
|
+
var f = files[i2];
|
|
16531
|
+
wzh(out, f.o, f, f.f, f.u, f.c.length);
|
|
16532
|
+
var badd = 30 + f.f.length + exfl(f.extra);
|
|
16533
|
+
out.set(f.c, f.o + badd);
|
|
16534
|
+
wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
|
|
16535
|
+
}
|
|
16536
|
+
wzf(out, o, files.length, cdl, oe);
|
|
16537
|
+
return out;
|
|
16538
|
+
}
|
|
15270
16539
|
|
|
15271
16540
|
// node_modules/.pnpm/@tokenizer+inflate@0.2.7/node_modules/@tokenizer/inflate/lib/index.js
|
|
15272
16541
|
var import_debug = __toESM(require_src(), 1);
|
|
@@ -20017,10 +21286,10 @@ function resolveAll(constructs2, events, context) {
|
|
|
20017
21286
|
const called = [];
|
|
20018
21287
|
let index2 = -1;
|
|
20019
21288
|
while (++index2 < constructs2.length) {
|
|
20020
|
-
const
|
|
20021
|
-
if (
|
|
20022
|
-
events =
|
|
20023
|
-
called.push(
|
|
21289
|
+
const resolve10 = constructs2[index2].resolveAll;
|
|
21290
|
+
if (resolve10 && !called.includes(resolve10)) {
|
|
21291
|
+
events = resolve10(events, context);
|
|
21292
|
+
called.push(resolve10);
|
|
20024
21293
|
}
|
|
20025
21294
|
}
|
|
20026
21295
|
return events;
|
|
@@ -20034,7 +21303,7 @@ var attention = {
|
|
|
20034
21303
|
};
|
|
20035
21304
|
function resolveAllAttention(events, context) {
|
|
20036
21305
|
let index2 = -1;
|
|
20037
|
-
let
|
|
21306
|
+
let open2;
|
|
20038
21307
|
let group;
|
|
20039
21308
|
let text3;
|
|
20040
21309
|
let openingSequence;
|
|
@@ -20044,16 +21313,16 @@ function resolveAllAttention(events, context) {
|
|
|
20044
21313
|
let offset;
|
|
20045
21314
|
while (++index2 < events.length) {
|
|
20046
21315
|
if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
|
|
20047
|
-
|
|
20048
|
-
while (
|
|
20049
|
-
if (events[
|
|
20050
|
-
context.sliceSerialize(events[
|
|
20051
|
-
if ((events[
|
|
21316
|
+
open2 = index2;
|
|
21317
|
+
while (open2--) {
|
|
21318
|
+
if (events[open2][0] === "exit" && events[open2][1].type === "attentionSequence" && events[open2][1]._open && // If the markers are the same:
|
|
21319
|
+
context.sliceSerialize(events[open2][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
|
|
21320
|
+
if ((events[open2][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open2][1].end.offset - events[open2][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) {
|
|
20052
21321
|
continue;
|
|
20053
21322
|
}
|
|
20054
|
-
use = events[
|
|
21323
|
+
use = events[open2][1].end.offset - events[open2][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1;
|
|
20055
21324
|
const start = {
|
|
20056
|
-
...events[
|
|
21325
|
+
...events[open2][1].end
|
|
20057
21326
|
};
|
|
20058
21327
|
const end = {
|
|
20059
21328
|
...events[index2][1].start
|
|
@@ -20064,7 +21333,7 @@ function resolveAllAttention(events, context) {
|
|
|
20064
21333
|
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
20065
21334
|
start,
|
|
20066
21335
|
end: {
|
|
20067
|
-
...events[
|
|
21336
|
+
...events[open2][1].end
|
|
20068
21337
|
}
|
|
20069
21338
|
};
|
|
20070
21339
|
closingSequence = {
|
|
@@ -20077,7 +21346,7 @@ function resolveAllAttention(events, context) {
|
|
|
20077
21346
|
text3 = {
|
|
20078
21347
|
type: use > 1 ? "strongText" : "emphasisText",
|
|
20079
21348
|
start: {
|
|
20080
|
-
...events[
|
|
21349
|
+
...events[open2][1].end
|
|
20081
21350
|
},
|
|
20082
21351
|
end: {
|
|
20083
21352
|
...events[index2][1].start
|
|
@@ -20092,18 +21361,18 @@ function resolveAllAttention(events, context) {
|
|
|
20092
21361
|
...closingSequence.end
|
|
20093
21362
|
}
|
|
20094
21363
|
};
|
|
20095
|
-
events[
|
|
21364
|
+
events[open2][1].end = {
|
|
20096
21365
|
...openingSequence.start
|
|
20097
21366
|
};
|
|
20098
21367
|
events[index2][1].start = {
|
|
20099
21368
|
...closingSequence.end
|
|
20100
21369
|
};
|
|
20101
21370
|
nextEvents = [];
|
|
20102
|
-
if (events[
|
|
20103
|
-
nextEvents = push(nextEvents, [["enter", events[
|
|
21371
|
+
if (events[open2][1].end.offset - events[open2][1].start.offset) {
|
|
21372
|
+
nextEvents = push(nextEvents, [["enter", events[open2][1], context], ["exit", events[open2][1], context]]);
|
|
20104
21373
|
}
|
|
20105
21374
|
nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text3, context]]);
|
|
20106
|
-
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
21375
|
+
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open2 + 1, index2), context));
|
|
20107
21376
|
nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
|
|
20108
21377
|
if (events[index2][1].end.offset - events[index2][1].start.offset) {
|
|
20109
21378
|
offset = 2;
|
|
@@ -20111,8 +21380,8 @@ function resolveAllAttention(events, context) {
|
|
|
20111
21380
|
} else {
|
|
20112
21381
|
offset = 0;
|
|
20113
21382
|
}
|
|
20114
|
-
splice(events,
|
|
20115
|
-
index2 =
|
|
21383
|
+
splice(events, open2 - 1, index2 - open2 + 3, nextEvents);
|
|
21384
|
+
index2 = open2 + nextEvents.length - offset - 2;
|
|
20116
21385
|
break;
|
|
20117
21386
|
}
|
|
20118
21387
|
}
|
|
@@ -20144,10 +21413,10 @@ function tokenizeAttention(effects, ok2) {
|
|
|
20144
21413
|
}
|
|
20145
21414
|
const token = effects.exit("attentionSequence");
|
|
20146
21415
|
const after = classifyCharacter(code);
|
|
20147
|
-
const
|
|
21416
|
+
const open2 = !after || after === 2 && before || attentionMarkers2.includes(code);
|
|
20148
21417
|
const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
|
|
20149
|
-
token._open = Boolean(marker === 42 ?
|
|
20150
|
-
token._close = Boolean(marker === 42 ? close : close && (after || !
|
|
21418
|
+
token._open = Boolean(marker === 42 ? open2 : open2 && (before || !close));
|
|
21419
|
+
token._close = Boolean(marker === 42 ? close : close && (after || !open2));
|
|
20151
21420
|
return ok2(code);
|
|
20152
21421
|
}
|
|
20153
21422
|
}
|
|
@@ -20172,9 +21441,9 @@ function tokenizeAutolink(effects, ok2, nok) {
|
|
|
20172
21441
|
effects.consume(code);
|
|
20173
21442
|
effects.exit("autolinkMarker");
|
|
20174
21443
|
effects.enter("autolinkProtocol");
|
|
20175
|
-
return
|
|
21444
|
+
return open2;
|
|
20176
21445
|
}
|
|
20177
|
-
function
|
|
21446
|
+
function open2(code) {
|
|
20178
21447
|
if (asciiAlpha(code)) {
|
|
20179
21448
|
effects.consume(code);
|
|
20180
21449
|
return schemeOrEmailAtext;
|
|
@@ -20378,9 +21647,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
|
|
|
20378
21647
|
effects.enter("characterReferenceMarker");
|
|
20379
21648
|
effects.consume(code);
|
|
20380
21649
|
effects.exit("characterReferenceMarker");
|
|
20381
|
-
return
|
|
21650
|
+
return open2;
|
|
20382
21651
|
}
|
|
20383
|
-
function
|
|
21652
|
+
function open2(code) {
|
|
20384
21653
|
if (code === 35) {
|
|
20385
21654
|
effects.enter("characterReferenceMarkerNumeric");
|
|
20386
21655
|
effects.consume(code);
|
|
@@ -21772,9 +23041,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
|
|
|
21772
23041
|
effects.enter("htmlFlow");
|
|
21773
23042
|
effects.enter("htmlFlowData");
|
|
21774
23043
|
effects.consume(code);
|
|
21775
|
-
return
|
|
23044
|
+
return open2;
|
|
21776
23045
|
}
|
|
21777
|
-
function
|
|
23046
|
+
function open2(code) {
|
|
21778
23047
|
if (code === 33) {
|
|
21779
23048
|
effects.consume(code);
|
|
21780
23049
|
return declarationOpen;
|
|
@@ -22123,9 +23392,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
|
|
|
22123
23392
|
effects.enter("htmlText");
|
|
22124
23393
|
effects.enter("htmlTextData");
|
|
22125
23394
|
effects.consume(code);
|
|
22126
|
-
return
|
|
23395
|
+
return open2;
|
|
22127
23396
|
}
|
|
22128
|
-
function
|
|
23397
|
+
function open2(code) {
|
|
22129
23398
|
if (code === 33) {
|
|
22130
23399
|
effects.consume(code);
|
|
22131
23400
|
return declarationOpen;
|
|
@@ -22452,12 +23721,12 @@ function resolveToLabelEnd(events, context) {
|
|
|
22452
23721
|
let index2 = events.length;
|
|
22453
23722
|
let offset = 0;
|
|
22454
23723
|
let token;
|
|
22455
|
-
let
|
|
23724
|
+
let open2;
|
|
22456
23725
|
let close;
|
|
22457
23726
|
let media;
|
|
22458
23727
|
while (index2--) {
|
|
22459
23728
|
token = events[index2][1];
|
|
22460
|
-
if (
|
|
23729
|
+
if (open2) {
|
|
22461
23730
|
if (token.type === "link" || token.type === "labelLink" && token._inactive) {
|
|
22462
23731
|
break;
|
|
22463
23732
|
}
|
|
@@ -22466,7 +23735,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
22466
23735
|
}
|
|
22467
23736
|
} else if (close) {
|
|
22468
23737
|
if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
|
|
22469
|
-
|
|
23738
|
+
open2 = index2;
|
|
22470
23739
|
if (token.type !== "labelLink") {
|
|
22471
23740
|
offset = 2;
|
|
22472
23741
|
break;
|
|
@@ -22477,9 +23746,9 @@ function resolveToLabelEnd(events, context) {
|
|
|
22477
23746
|
}
|
|
22478
23747
|
}
|
|
22479
23748
|
const group = {
|
|
22480
|
-
type: events[
|
|
23749
|
+
type: events[open2][1].type === "labelLink" ? "link" : "image",
|
|
22481
23750
|
start: {
|
|
22482
|
-
...events[
|
|
23751
|
+
...events[open2][1].start
|
|
22483
23752
|
},
|
|
22484
23753
|
end: {
|
|
22485
23754
|
...events[events.length - 1][1].end
|
|
@@ -22488,7 +23757,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
22488
23757
|
const label = {
|
|
22489
23758
|
type: "label",
|
|
22490
23759
|
start: {
|
|
22491
|
-
...events[
|
|
23760
|
+
...events[open2][1].start
|
|
22492
23761
|
},
|
|
22493
23762
|
end: {
|
|
22494
23763
|
...events[close][1].end
|
|
@@ -22497,20 +23766,20 @@ function resolveToLabelEnd(events, context) {
|
|
|
22497
23766
|
const text3 = {
|
|
22498
23767
|
type: "labelText",
|
|
22499
23768
|
start: {
|
|
22500
|
-
...events[
|
|
23769
|
+
...events[open2 + offset + 2][1].end
|
|
22501
23770
|
},
|
|
22502
23771
|
end: {
|
|
22503
23772
|
...events[close - 2][1].start
|
|
22504
23773
|
}
|
|
22505
23774
|
};
|
|
22506
23775
|
media = [["enter", group, context], ["enter", label, context]];
|
|
22507
|
-
media = push(media, events.slice(
|
|
23776
|
+
media = push(media, events.slice(open2 + 1, open2 + offset + 3));
|
|
22508
23777
|
media = push(media, [["enter", text3, context]]);
|
|
22509
|
-
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
23778
|
+
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open2 + offset + 4, close - 3), context));
|
|
22510
23779
|
media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
|
|
22511
23780
|
media = push(media, events.slice(close + 1));
|
|
22512
23781
|
media = push(media, [["exit", group, context]]);
|
|
22513
|
-
splice(events,
|
|
23782
|
+
splice(events, open2, events.length, media);
|
|
22514
23783
|
return events;
|
|
22515
23784
|
}
|
|
22516
23785
|
function tokenizeLabelEnd(effects, ok2, nok) {
|
|
@@ -22656,9 +23925,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
|
|
|
22656
23925
|
effects.enter("labelImageMarker");
|
|
22657
23926
|
effects.consume(code);
|
|
22658
23927
|
effects.exit("labelImageMarker");
|
|
22659
|
-
return
|
|
23928
|
+
return open2;
|
|
22660
23929
|
}
|
|
22661
|
-
function
|
|
23930
|
+
function open2(code) {
|
|
22662
23931
|
if (code === 91) {
|
|
22663
23932
|
effects.enter("labelMarker");
|
|
22664
23933
|
effects.consume(code);
|
|
@@ -23979,8 +25248,8 @@ function compiler(options) {
|
|
|
23979
25248
|
return length;
|
|
23980
25249
|
}
|
|
23981
25250
|
function opener(create, and) {
|
|
23982
|
-
return
|
|
23983
|
-
function
|
|
25251
|
+
return open2;
|
|
25252
|
+
function open2(token) {
|
|
23984
25253
|
enter.call(this, create(token), token);
|
|
23985
25254
|
if (and) and.call(this, token);
|
|
23986
25255
|
}
|
|
@@ -24012,18 +25281,18 @@ function compiler(options) {
|
|
|
24012
25281
|
}
|
|
24013
25282
|
function exit2(token, onExitError) {
|
|
24014
25283
|
const node2 = this.stack.pop();
|
|
24015
|
-
const
|
|
24016
|
-
if (!
|
|
25284
|
+
const open2 = this.tokenStack.pop();
|
|
25285
|
+
if (!open2) {
|
|
24017
25286
|
throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
24018
25287
|
start: token.start,
|
|
24019
25288
|
end: token.end
|
|
24020
25289
|
}) + "): it\u2019s not open");
|
|
24021
|
-
} else if (
|
|
25290
|
+
} else if (open2[0].type !== token.type) {
|
|
24022
25291
|
if (onExitError) {
|
|
24023
|
-
onExitError.call(this, token,
|
|
25292
|
+
onExitError.call(this, token, open2[0]);
|
|
24024
25293
|
} else {
|
|
24025
|
-
const handler =
|
|
24026
|
-
handler.call(this, token,
|
|
25294
|
+
const handler = open2[1] || defaultOnError;
|
|
25295
|
+
handler.call(this, token, open2[0]);
|
|
24027
25296
|
}
|
|
24028
25297
|
}
|
|
24029
25298
|
node2.position.end = point2(token.end);
|
|
@@ -24706,7 +25975,7 @@ function collectImageCandidates(content3) {
|
|
|
24706
25975
|
const tree = fromMarkdown(content3);
|
|
24707
25976
|
const syntaxByRange = collectImageSyntax(content3);
|
|
24708
25977
|
const definitions = /* @__PURE__ */ new Map();
|
|
24709
|
-
const
|
|
25978
|
+
const candidates2 = [];
|
|
24710
25979
|
visit(tree, "definition", (node2) => {
|
|
24711
25980
|
definitions.set(node2.identifier, node2);
|
|
24712
25981
|
});
|
|
@@ -24717,7 +25986,7 @@ function collectImageCandidates(content3) {
|
|
|
24717
25986
|
}
|
|
24718
25987
|
const destinationRange = syntaxByRange.get(rangeKey(range))?.destinationRange;
|
|
24719
25988
|
if (destinationRange) {
|
|
24720
|
-
|
|
25989
|
+
candidates2.push({
|
|
24721
25990
|
kind: "inline",
|
|
24722
25991
|
destination: node2.url,
|
|
24723
25992
|
destinationRange
|
|
@@ -24734,7 +26003,7 @@ function collectImageCandidates(content3) {
|
|
|
24734
26003
|
if (!syntax) {
|
|
24735
26004
|
return;
|
|
24736
26005
|
}
|
|
24737
|
-
|
|
26006
|
+
candidates2.push({
|
|
24738
26007
|
kind: "reference",
|
|
24739
26008
|
destination: definition2.url,
|
|
24740
26009
|
range,
|
|
@@ -24742,7 +26011,7 @@ function collectImageCandidates(content3) {
|
|
|
24742
26011
|
title: definition2.title ?? null
|
|
24743
26012
|
});
|
|
24744
26013
|
});
|
|
24745
|
-
return
|
|
26014
|
+
return candidates2;
|
|
24746
26015
|
}
|
|
24747
26016
|
function isRemoteDestination(destination) {
|
|
24748
26017
|
if (WINDOWS_DRIVE_RE.test(destination)) {
|
|
@@ -25076,13 +26345,13 @@ function registerFileCommand(program3) {
|
|
|
25076
26345
|
const outputMode = options.json ? "json" : "text";
|
|
25077
26346
|
const mode = runFileReadResolverOrExit(() => resolveReadMode(options), outputMode);
|
|
25078
26347
|
let response;
|
|
25079
|
-
let
|
|
26348
|
+
let displayPath2;
|
|
25080
26349
|
let requestPath;
|
|
25081
26350
|
if (mode.kind === "by-url") {
|
|
25082
|
-
|
|
26351
|
+
displayPath2 = mode.url;
|
|
25083
26352
|
requestPath = `/files/read-by-url?url=${encodeURIComponent(mode.url)}`;
|
|
25084
26353
|
} else {
|
|
25085
|
-
|
|
26354
|
+
displayPath2 = mode.path;
|
|
25086
26355
|
const spaceParams = runFileReadResolverOrExit(
|
|
25087
26356
|
() => resolveSpaceSelector(options),
|
|
25088
26357
|
outputMode
|
|
@@ -25124,7 +26393,7 @@ function registerFileCommand(program3) {
|
|
|
25124
26393
|
if (response.status === 404) {
|
|
25125
26394
|
exitFileReadJson({
|
|
25126
26395
|
code: "not_found",
|
|
25127
|
-
message: `${
|
|
26396
|
+
message: `${displayPath2} does not exist`,
|
|
25128
26397
|
status: response.status,
|
|
25129
26398
|
details: response.data
|
|
25130
26399
|
});
|
|
@@ -25137,7 +26406,7 @@ function registerFileCommand(program3) {
|
|
|
25137
26406
|
});
|
|
25138
26407
|
}
|
|
25139
26408
|
if (response.status === 404) {
|
|
25140
|
-
print(`${colors.red}\u2620 ${
|
|
26409
|
+
print(`${colors.red}\u2620 ${displayPath2} does not exist${colors.reset}`);
|
|
25141
26410
|
} else {
|
|
25142
26411
|
printError(`Error [${response.status}]: ${JSON.stringify(response.data)}`);
|
|
25143
26412
|
}
|
|
@@ -25148,12 +26417,12 @@ function registerFileCommand(program3) {
|
|
|
25148
26417
|
if (options.json) {
|
|
25149
26418
|
exitFileReadJson({
|
|
25150
26419
|
code: "not_a_file",
|
|
25151
|
-
message: `${
|
|
26420
|
+
message: `${displayPath2} is a directory`,
|
|
25152
26421
|
status: null,
|
|
25153
26422
|
details: null
|
|
25154
26423
|
});
|
|
25155
26424
|
}
|
|
25156
|
-
print(`${colors.red}\u2620 ${
|
|
26425
|
+
print(`${colors.red}\u2620 ${displayPath2} is a directory${colors.reset}`);
|
|
25157
26426
|
process.exit(1);
|
|
25158
26427
|
}
|
|
25159
26428
|
if (options.json) {
|
|
@@ -25198,15 +26467,15 @@ function registerFileCommand(program3) {
|
|
|
25198
26467
|
}
|
|
25199
26468
|
startSpinner("Uploading...");
|
|
25200
26469
|
let response;
|
|
25201
|
-
let
|
|
26470
|
+
let displayPath2;
|
|
25202
26471
|
if (mode.kind === "by-url") {
|
|
25203
|
-
|
|
26472
|
+
displayPath2 = mode.url;
|
|
25204
26473
|
response = await httpPut("/files/write-by-url", {
|
|
25205
26474
|
url: mode.url,
|
|
25206
26475
|
content: content3
|
|
25207
26476
|
});
|
|
25208
26477
|
} else {
|
|
25209
|
-
|
|
26478
|
+
displayPath2 = mode.path;
|
|
25210
26479
|
const spaceParams = runOrExit2(() => resolveSpaceSelector(options));
|
|
25211
26480
|
response = await httpPut(
|
|
25212
26481
|
`/workspaces/${mode.workspace}/files/write`,
|
|
@@ -25222,7 +26491,7 @@ function registerFileCommand(program3) {
|
|
|
25222
26491
|
stopSpinner(false, "Failed");
|
|
25223
26492
|
if (response.status === 404) {
|
|
25224
26493
|
if (mode.kind === "by-url") {
|
|
25225
|
-
print(`${colors.red}\u2620 ${
|
|
26494
|
+
print(`${colors.red}\u2620 ${displayPath2} does not exist${colors.reset}`);
|
|
25226
26495
|
} else {
|
|
25227
26496
|
print(`${colors.red}\u2620 Parent directory does not exist${colors.reset}`);
|
|
25228
26497
|
}
|
|
@@ -25335,6 +26604,284 @@ function registerMemoryCommand(program3) {
|
|
|
25335
26604
|
|
|
25336
26605
|
// src/commands/machine.ts
|
|
25337
26606
|
init_cjs_shims();
|
|
26607
|
+
|
|
26608
|
+
// src/commands/machine-dump.ts
|
|
26609
|
+
init_cjs_shims();
|
|
26610
|
+
var import_node_fs = require("fs");
|
|
26611
|
+
var import_promises3 = require("fs/promises");
|
|
26612
|
+
var import_node_os = require("os");
|
|
26613
|
+
var import_node_path = require("path");
|
|
26614
|
+
var redactedValue = "[REDACTED]";
|
|
26615
|
+
var candidates = [
|
|
26616
|
+
...connectorLogCandidates("machine-connector.log"),
|
|
26617
|
+
...connectorLogCandidates("machine-connector.error.log"),
|
|
26618
|
+
...connectorLogCandidates("supervisor/supervisord.log"),
|
|
26619
|
+
{
|
|
26620
|
+
archivePath: "state/runtime-status.json",
|
|
26621
|
+
sourceName: "runtime-status.json"
|
|
26622
|
+
},
|
|
26623
|
+
{
|
|
26624
|
+
archivePath: "state/service-manager.json",
|
|
26625
|
+
sourceName: "service-manager.json"
|
|
26626
|
+
}
|
|
26627
|
+
];
|
|
26628
|
+
async function createMachineDump(options) {
|
|
26629
|
+
const outputPath = (0, import_node_path.resolve)(
|
|
26630
|
+
options.outputPath ?? defaultDumpFilename(/* @__PURE__ */ new Date())
|
|
26631
|
+
);
|
|
26632
|
+
const entries = {};
|
|
26633
|
+
const included = [];
|
|
26634
|
+
const skipped = [];
|
|
26635
|
+
const runtimeRoot = await canonicalRuntimeRoot(options.runtimeDirectory);
|
|
26636
|
+
for (const candidate of candidates) {
|
|
26637
|
+
const content3 = await readAllowlistedFile(
|
|
26638
|
+
runtimeRoot,
|
|
26639
|
+
candidate.sourceName
|
|
26640
|
+
);
|
|
26641
|
+
if (content3.status !== "available") {
|
|
26642
|
+
skipped.push({
|
|
26643
|
+
reason: content3.status,
|
|
26644
|
+
sourceName: candidate.sourceName
|
|
26645
|
+
});
|
|
26646
|
+
continue;
|
|
26647
|
+
}
|
|
26648
|
+
entries[candidate.archivePath] = strToU8(redactSecrets(content3.value));
|
|
26649
|
+
included.push(candidate.archivePath);
|
|
26650
|
+
}
|
|
26651
|
+
const daemonSocketPresent = await pathExistsInsideRuntime(
|
|
26652
|
+
runtimeRoot,
|
|
26653
|
+
"machine-connector.sock"
|
|
26654
|
+
);
|
|
26655
|
+
entries["diagnostics.json"] = strToU8(
|
|
26656
|
+
`${JSON.stringify(
|
|
26657
|
+
{
|
|
26658
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26659
|
+
cliVersion: options.cliVersion,
|
|
26660
|
+
nodeVersion: process.version,
|
|
26661
|
+
platform: process.platform,
|
|
26662
|
+
architecture: process.arch,
|
|
26663
|
+
runtimeDirectory: displayPath(options.runtimeDirectory),
|
|
26664
|
+
daemonSocketPresent,
|
|
26665
|
+
daemonLockPresent: await pathExistsInsideRuntime(
|
|
26666
|
+
runtimeRoot,
|
|
26667
|
+
"daemon.lock"
|
|
26668
|
+
),
|
|
26669
|
+
reconcileLockPresent: await pathExistsInsideRuntime(
|
|
26670
|
+
runtimeRoot,
|
|
26671
|
+
"daemon-reconcile.lock"
|
|
26672
|
+
),
|
|
26673
|
+
supervisorPidPresent: await pathExistsInsideRuntime(
|
|
26674
|
+
runtimeRoot,
|
|
26675
|
+
"supervisor/supervisord.pid"
|
|
26676
|
+
),
|
|
26677
|
+
included,
|
|
26678
|
+
skipped,
|
|
26679
|
+
security: {
|
|
26680
|
+
redactionApplied: true,
|
|
26681
|
+
excluded: [
|
|
26682
|
+
"connections and pairing credentials",
|
|
26683
|
+
"device private key and identity",
|
|
26684
|
+
"Job payloads, output, and process state",
|
|
26685
|
+
"Local Codex Runtime attempt state",
|
|
26686
|
+
"service definitions and environment variables",
|
|
26687
|
+
"sockets, lock contents, browser data, and .env files",
|
|
26688
|
+
"all unrecognized files"
|
|
26689
|
+
]
|
|
26690
|
+
}
|
|
26691
|
+
},
|
|
26692
|
+
void 0,
|
|
26693
|
+
2
|
|
26694
|
+
)}
|
|
26695
|
+
`
|
|
26696
|
+
);
|
|
26697
|
+
included.unshift("diagnostics.json");
|
|
26698
|
+
await (0, import_promises3.mkdir)((0, import_node_path.dirname)(outputPath), { recursive: true });
|
|
26699
|
+
await (0, import_promises3.writeFile)(outputPath, zipSync(entries, { level: 6 }), {
|
|
26700
|
+
flag: "wx",
|
|
26701
|
+
mode: 384
|
|
26702
|
+
});
|
|
26703
|
+
return { included, outputPath, skipped };
|
|
26704
|
+
}
|
|
26705
|
+
function connectorLogCandidates(sourceName) {
|
|
26706
|
+
return ["", ".1", ".2", ".3"].map((suffix) => ({
|
|
26707
|
+
archivePath: `logs/${sourceName}${suffix}`,
|
|
26708
|
+
sourceName: `${sourceName}${suffix}`
|
|
26709
|
+
}));
|
|
26710
|
+
}
|
|
26711
|
+
async function readAllowlistedFile(runtimeRoot, sourceName) {
|
|
26712
|
+
if (runtimeRoot === void 0) return { status: "missing" };
|
|
26713
|
+
const path4 = (0, import_node_path.resolve)(runtimeRoot, sourceName);
|
|
26714
|
+
try {
|
|
26715
|
+
const metadata = await (0, import_promises3.lstat)(path4);
|
|
26716
|
+
if (!metadata.isFile()) return { status: "not a regular file" };
|
|
26717
|
+
const canonicalPath = await (0, import_promises3.realpath)(path4);
|
|
26718
|
+
if (!pathIsInside(runtimeRoot, canonicalPath)) {
|
|
26719
|
+
return { status: "outside runtime directory" };
|
|
26720
|
+
}
|
|
26721
|
+
const handle = await (0, import_promises3.open)(
|
|
26722
|
+
path4,
|
|
26723
|
+
import_node_fs.constants.O_RDONLY | (import_node_fs.constants.O_NOFOLLOW ?? 0)
|
|
26724
|
+
);
|
|
26725
|
+
try {
|
|
26726
|
+
const openedMetadata = await handle.stat();
|
|
26727
|
+
if (!openedMetadata.isFile()) {
|
|
26728
|
+
return { status: "not a regular file" };
|
|
26729
|
+
}
|
|
26730
|
+
const openedPathStatus = await validateOpenedPath(
|
|
26731
|
+
runtimeRoot,
|
|
26732
|
+
path4,
|
|
26733
|
+
openedMetadata
|
|
26734
|
+
);
|
|
26735
|
+
if (openedPathStatus !== "available") {
|
|
26736
|
+
return { status: openedPathStatus };
|
|
26737
|
+
}
|
|
26738
|
+
return { status: "available", value: await handle.readFile("utf8") };
|
|
26739
|
+
} finally {
|
|
26740
|
+
await handle.close();
|
|
26741
|
+
}
|
|
26742
|
+
} catch (error) {
|
|
26743
|
+
if (isNodeErrorCode(error, "ENOENT")) return { status: "missing" };
|
|
26744
|
+
if (isNodeErrorCode(error, "ENOTDIR")) {
|
|
26745
|
+
return { status: "not a regular file" };
|
|
26746
|
+
}
|
|
26747
|
+
if (isNodeErrorCode(error, "ELOOP")) {
|
|
26748
|
+
return { status: "not a regular file" };
|
|
26749
|
+
}
|
|
26750
|
+
throw error;
|
|
26751
|
+
}
|
|
26752
|
+
}
|
|
26753
|
+
async function validateOpenedPath(runtimeRoot, path4, openedMetadata) {
|
|
26754
|
+
try {
|
|
26755
|
+
const canonicalPath = await (0, import_promises3.realpath)(path4);
|
|
26756
|
+
if (!pathIsInside(runtimeRoot, canonicalPath)) {
|
|
26757
|
+
return "outside runtime directory";
|
|
26758
|
+
}
|
|
26759
|
+
const currentMetadata = await (0, import_promises3.stat)(path4);
|
|
26760
|
+
if (currentMetadata.dev !== openedMetadata.dev || currentMetadata.ino !== openedMetadata.ino) {
|
|
26761
|
+
return "path changed while reading";
|
|
26762
|
+
}
|
|
26763
|
+
return "available";
|
|
26764
|
+
} catch (error) {
|
|
26765
|
+
if (isNodeErrorCode(error, "ENOENT")) {
|
|
26766
|
+
return "path changed while reading";
|
|
26767
|
+
}
|
|
26768
|
+
throw error;
|
|
26769
|
+
}
|
|
26770
|
+
}
|
|
26771
|
+
async function canonicalRuntimeRoot(path4) {
|
|
26772
|
+
try {
|
|
26773
|
+
const canonicalPath = await (0, import_promises3.realpath)(path4);
|
|
26774
|
+
const metadata = await (0, import_promises3.stat)(canonicalPath);
|
|
26775
|
+
return metadata.isDirectory() ? canonicalPath : void 0;
|
|
26776
|
+
} catch (error) {
|
|
26777
|
+
if (isNodeErrorCode(error, "ENOENT") || isNodeErrorCode(error, "ENOTDIR") || isNodeErrorCode(error, "ELOOP")) {
|
|
26778
|
+
return void 0;
|
|
26779
|
+
}
|
|
26780
|
+
throw error;
|
|
26781
|
+
}
|
|
26782
|
+
}
|
|
26783
|
+
function pathIsInside(runtimeRoot, path4) {
|
|
26784
|
+
const relativePath = (0, import_node_path.relative)(runtimeRoot, path4);
|
|
26785
|
+
return relativePath === "" || relativePath !== ".." && !relativePath.startsWith(`..${import_node_path.sep}`) && !(0, import_node_path.isAbsolute)(relativePath);
|
|
26786
|
+
}
|
|
26787
|
+
function redactSecrets(value) {
|
|
26788
|
+
const structured = redactStructuredText(value);
|
|
26789
|
+
return structured.replace(
|
|
26790
|
+
/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/giu,
|
|
26791
|
+
redactedValue
|
|
26792
|
+
).replace(
|
|
26793
|
+
/(\b(?:authorization|proxy-authorization)\s*[:=]\s*(?:bearer|basic)\s+)[^\s,"']+/giu,
|
|
26794
|
+
`$1${redactedValue}`
|
|
26795
|
+
).replace(
|
|
26796
|
+
/(\b(?:cookie|set-cookie)\s*[:=]\s*)[^\r\n]+/giu,
|
|
26797
|
+
`$1${redactedValue}`
|
|
26798
|
+
).replace(
|
|
26799
|
+
/(["'][A-Za-z0-9_-]*(?:token|secret|password|passphrase|api[_-]?key|authorization|private[_-]?key|credential|connection[_-]?string|cookie|pairing[_-]?code)[A-Za-z0-9_-]*["']\s*:\s*["'])[^"']*(["'])/giu,
|
|
26800
|
+
`$1${redactedValue}$2`
|
|
26801
|
+
).replace(
|
|
26802
|
+
/(\b[A-Za-z0-9_-]*(?:token|secret|password|passphrase|api[_-]?key|authorization|private[_-]?key|credential|connection[_-]?string|cookie|pairing[_-]?code)[A-Za-z0-9_-]*\s*=\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu,
|
|
26803
|
+
`$1${redactedValue}`
|
|
26804
|
+
).replace(
|
|
26805
|
+
/(--(?:access-token|refresh-token|token|secret|password|api-key|credential|connection-string|pairing-code)\s+)(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu,
|
|
26806
|
+
`$1${redactedValue}`
|
|
26807
|
+
).replace(
|
|
26808
|
+
/([?&](?:access_token|refresh_token|token|secret|password|api_key|key|code)=)[^&#\s]+/giu,
|
|
26809
|
+
`$1${redactedValue}`
|
|
26810
|
+
).replace(
|
|
26811
|
+
/([a-z][a-z0-9+.-]*:\/\/[^:\s/@]+:)[^@\s/]+(@)/giu,
|
|
26812
|
+
`$1${redactedValue}$2`
|
|
26813
|
+
).replace(
|
|
26814
|
+
/\b(?:github_pat_|gh[pousr]_|sk-|moxt_)[A-Za-z0-9_-]{8,}\b/gu,
|
|
26815
|
+
redactedValue
|
|
26816
|
+
).replace(
|
|
26817
|
+
/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu,
|
|
26818
|
+
redactedValue
|
|
26819
|
+
);
|
|
26820
|
+
}
|
|
26821
|
+
function redactStructuredText(value) {
|
|
26822
|
+
const parsed = parseJson(value);
|
|
26823
|
+
if (parsed !== void 0) {
|
|
26824
|
+
return `${JSON.stringify(redactJsonValue(parsed), void 0, 2)}
|
|
26825
|
+
`;
|
|
26826
|
+
}
|
|
26827
|
+
return value.split("\n").map((line) => {
|
|
26828
|
+
const parsedLine = parseJson(line);
|
|
26829
|
+
return parsedLine === void 0 ? line : JSON.stringify(redactJsonValue(parsedLine));
|
|
26830
|
+
}).join("\n");
|
|
26831
|
+
}
|
|
26832
|
+
function redactJsonValue(value) {
|
|
26833
|
+
if (Array.isArray(value)) return value.map(redactJsonValue);
|
|
26834
|
+
if (value === null || typeof value !== "object") return value;
|
|
26835
|
+
return Object.fromEntries(
|
|
26836
|
+
Object.entries(value).map(([key, nestedValue]) => [
|
|
26837
|
+
key,
|
|
26838
|
+
sensitiveKey(key) ? redactedValue : redactJsonValue(nestedValue)
|
|
26839
|
+
])
|
|
26840
|
+
);
|
|
26841
|
+
}
|
|
26842
|
+
function sensitiveKey(key) {
|
|
26843
|
+
return /token|secret|password|passphrase|api.?key|authorization|private.?key|credential|connection.?string|cookie|pairing.?code/iu.test(
|
|
26844
|
+
key
|
|
26845
|
+
);
|
|
26846
|
+
}
|
|
26847
|
+
function parseJson(value) {
|
|
26848
|
+
if (value.trim() === "") return void 0;
|
|
26849
|
+
try {
|
|
26850
|
+
return JSON.parse(value);
|
|
26851
|
+
} catch {
|
|
26852
|
+
return void 0;
|
|
26853
|
+
}
|
|
26854
|
+
}
|
|
26855
|
+
async function pathExistsInsideRuntime(runtimeRoot, sourceName) {
|
|
26856
|
+
if (runtimeRoot === void 0) return false;
|
|
26857
|
+
const path4 = (0, import_node_path.resolve)(runtimeRoot, sourceName);
|
|
26858
|
+
try {
|
|
26859
|
+
const canonicalPath = await (0, import_promises3.realpath)(path4);
|
|
26860
|
+
return pathIsInside(runtimeRoot, canonicalPath);
|
|
26861
|
+
} catch (error) {
|
|
26862
|
+
if (isNodeErrorCode(error, "ENOENT") || isNodeErrorCode(error, "ENOTDIR") || isNodeErrorCode(error, "ELOOP")) {
|
|
26863
|
+
return false;
|
|
26864
|
+
}
|
|
26865
|
+
throw error;
|
|
26866
|
+
}
|
|
26867
|
+
}
|
|
26868
|
+
function displayPath(path4) {
|
|
26869
|
+
const home = process.env.HOME ?? (0, import_node_os.homedir)();
|
|
26870
|
+
const relativeToHome = (0, import_node_path.relative)(home, path4);
|
|
26871
|
+
if (relativeToHome === "" || !relativeToHome.startsWith(`..${import_node_path.sep}`) && relativeToHome !== "..") {
|
|
26872
|
+
return relativeToHome === "" ? "~" : (0, import_node_path.join)("~", relativeToHome);
|
|
26873
|
+
}
|
|
26874
|
+
return path4;
|
|
26875
|
+
}
|
|
26876
|
+
function defaultDumpFilename(date) {
|
|
26877
|
+
const timestamp = date.toISOString().replace(/[-:]/gu, "").replace(/\.\d{3}Z$/u, "Z");
|
|
26878
|
+
return `moxt-machine-dump-${timestamp}.zip`;
|
|
26879
|
+
}
|
|
26880
|
+
function isNodeErrorCode(error, code) {
|
|
26881
|
+
return error instanceof Error && "code" in error && error.code === code;
|
|
26882
|
+
}
|
|
26883
|
+
|
|
26884
|
+
// src/commands/machine.ts
|
|
25338
26885
|
var serviceManagerOption = new Option(
|
|
25339
26886
|
"--service-manager <manager>",
|
|
25340
26887
|
"Background service manager: auto, systemd, supervisor, or none"
|
|
@@ -25378,6 +26925,24 @@ function registerMachineCommand(program3, cliVersion) {
|
|
|
25378
26925
|
...options.json ? ["--json"] : []
|
|
25379
26926
|
]);
|
|
25380
26927
|
});
|
|
26928
|
+
machine.command("dump").description("Create a redacted Connector support archive").option("--output <path>", "Zip archive output path").action(async (options) => {
|
|
26929
|
+
const { defaultRuntimeDirectory: defaultRuntimeDirectory2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
|
|
26930
|
+
const result = await createMachineDump({
|
|
26931
|
+
cliVersion,
|
|
26932
|
+
outputPath: options.output,
|
|
26933
|
+
runtimeDirectory: defaultRuntimeDirectory2()
|
|
26934
|
+
});
|
|
26935
|
+
for (const path4 of result.included) {
|
|
26936
|
+
console.log(`Included: ${path4}`);
|
|
26937
|
+
}
|
|
26938
|
+
for (const skipped of result.skipped) {
|
|
26939
|
+
const reason = skipped.reason === "missing" ? "not found" : skipped.reason;
|
|
26940
|
+
console.log(
|
|
26941
|
+
`Skipped (${reason}): ${skipped.sourceName}`
|
|
26942
|
+
);
|
|
26943
|
+
}
|
|
26944
|
+
console.log(`Archive: ${result.outputPath}`);
|
|
26945
|
+
});
|
|
25381
26946
|
machine.command("disconnect").description("Remove a local connection").requiredOption("--connection <id>", "Local Machine connection ID").option(
|
|
25382
26947
|
"--local-only",
|
|
25383
26948
|
"Remove local state without contacting the Relay"
|
|
@@ -25686,7 +27251,7 @@ init_cjs_shims();
|
|
|
25686
27251
|
// src/update/install.ts
|
|
25687
27252
|
init_cjs_shims();
|
|
25688
27253
|
var import_node_child_process9 = require("child_process");
|
|
25689
|
-
var
|
|
27254
|
+
var import_node_fs4 = require("fs");
|
|
25690
27255
|
var path3 = __toESM(require("path"), 1);
|
|
25691
27256
|
|
|
25692
27257
|
// src/update/version.ts
|
|
@@ -25879,7 +27444,7 @@ function packageManagerFromUserAgent(userAgent) {
|
|
|
25879
27444
|
function normalizePath(value) {
|
|
25880
27445
|
let resolved = value;
|
|
25881
27446
|
try {
|
|
25882
|
-
resolved =
|
|
27447
|
+
resolved = import_node_fs4.realpathSync.native(value);
|
|
25883
27448
|
} catch {
|
|
25884
27449
|
}
|
|
25885
27450
|
return path3.normalize(resolved).replaceAll(path3.sep, "/");
|
|
@@ -26134,6 +27699,7 @@ function registerWorkspaceCommand(program3) {
|
|
|
26134
27699
|
// src/commands/workflow.ts
|
|
26135
27700
|
init_cjs_shims();
|
|
26136
27701
|
var fs5 = __toESM(require("fs"), 1);
|
|
27702
|
+
var import_node_path16 = require("path");
|
|
26137
27703
|
var import_node_util6 = require("util");
|
|
26138
27704
|
var MAX_DESC_LENGTH = 5e3;
|
|
26139
27705
|
var MAX_COMMENT_CONTENT_LENGTH = 5e3;
|
|
@@ -26216,21 +27782,22 @@ function parseTaskScope(raw) {
|
|
|
26216
27782
|
'Error: --scope must be "all", "assigned_to_me", "subscribed_by_me", or "owner_is_me".'
|
|
26217
27783
|
);
|
|
26218
27784
|
}
|
|
26219
|
-
function
|
|
26220
|
-
|
|
26221
|
-
|
|
26222
|
-
|
|
26223
|
-
|
|
27785
|
+
function parseHttpUrl(raw, label = "--url") {
|
|
27786
|
+
const url = raw.trim();
|
|
27787
|
+
try {
|
|
27788
|
+
const parsed = new URL(url);
|
|
27789
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") return url;
|
|
27790
|
+
} catch {
|
|
26224
27791
|
}
|
|
26225
|
-
|
|
27792
|
+
throw new WorkflowOptionsError(`Error: ${label} must be an HTTP or HTTPS URL.`);
|
|
26226
27793
|
}
|
|
26227
27794
|
function readDescFile(path4) {
|
|
26228
27795
|
if (path4 == null || path4 === "") return void 0;
|
|
26229
27796
|
if (!fs5.existsSync(path4)) {
|
|
26230
27797
|
throw new WorkflowOptionsError(`Error: desc file not found: ${path4}`);
|
|
26231
27798
|
}
|
|
26232
|
-
const
|
|
26233
|
-
if (!
|
|
27799
|
+
const stat6 = fs5.statSync(path4);
|
|
27800
|
+
if (!stat6.isFile()) {
|
|
26234
27801
|
throw new WorkflowOptionsError(`Error: desc file is not a file: ${path4}`);
|
|
26235
27802
|
}
|
|
26236
27803
|
const buffer2 = fs5.readFileSync(path4);
|
|
@@ -26247,11 +27814,11 @@ function readCommentContentFile2(path4) {
|
|
|
26247
27814
|
if (!fs5.existsSync(path4)) {
|
|
26248
27815
|
throw new WorkflowOptionsError(`Error: comment content file not found: ${path4}`);
|
|
26249
27816
|
}
|
|
26250
|
-
const
|
|
26251
|
-
if (!
|
|
27817
|
+
const stat6 = fs5.statSync(path4);
|
|
27818
|
+
if (!stat6.isFile()) {
|
|
26252
27819
|
throw new WorkflowOptionsError(`Error: comment content path is not a file: ${path4}`);
|
|
26253
27820
|
}
|
|
26254
|
-
if (
|
|
27821
|
+
if (stat6.size > MAX_COMMENT_CONTENT_BYTES) {
|
|
26255
27822
|
throw new WorkflowOptionsError(
|
|
26256
27823
|
`Error: comment content file must be at most ${MAX_COMMENT_CONTENT_LENGTH} characters.`
|
|
26257
27824
|
);
|
|
@@ -26505,7 +28072,7 @@ function printTaskSummary(item) {
|
|
|
26505
28072
|
`${colors.bold}#${item.scopedId}${colors.reset} ${item.title} status=${item.statusScopedId} priority=${priorityLabel(item.priority)} assignee=${formatAssignee(item.assignee)} runs=${runIds}`
|
|
26506
28073
|
);
|
|
26507
28074
|
}
|
|
26508
|
-
function printTaskDetail(item) {
|
|
28075
|
+
function printTaskDetail(item, linkedLinkTitles) {
|
|
26509
28076
|
print(`${colors.bold}Task${colors.reset}`);
|
|
26510
28077
|
printDetailField2("scopedId", item.scopedId);
|
|
26511
28078
|
printDetailField2("workflowFileId", item.workflowFileId);
|
|
@@ -26515,11 +28082,14 @@ function printTaskDetail(item) {
|
|
|
26515
28082
|
printDetailField2("statusScopedId", item.statusScopedId);
|
|
26516
28083
|
printDetailField2("priority", `${item.priority} (${priorityLabel(item.priority)})`);
|
|
26517
28084
|
printAssigneeDetail("assignee", item.assignee);
|
|
26518
|
-
if (item.
|
|
26519
|
-
print("
|
|
28085
|
+
if (item.linkedLinks.length === 0) {
|
|
28086
|
+
print("linkedLinks: []");
|
|
26520
28087
|
} else {
|
|
26521
|
-
print("
|
|
26522
|
-
for (const
|
|
28088
|
+
print("linkedLinks:");
|
|
28089
|
+
for (const [index2, link] of item.linkedLinks.entries()) {
|
|
28090
|
+
print(` - title: ${formatDetailScalar2(linkedLinkTitles[index2] ?? link.url)}`);
|
|
28091
|
+
printDetailField2("url", link.url, 4);
|
|
28092
|
+
}
|
|
26523
28093
|
}
|
|
26524
28094
|
printDetailField2("subscribed", item.subscribed);
|
|
26525
28095
|
if (item.runningAgentRuns.length === 0) {
|
|
@@ -26534,6 +28104,36 @@ function printTaskDetail(item) {
|
|
|
26534
28104
|
printDetailField2("createdAt", item.createdAt);
|
|
26535
28105
|
printDetailField2("latestActAt", item.latestActAt);
|
|
26536
28106
|
}
|
|
28107
|
+
async function printResolvedTaskDetail(item, workspaceId) {
|
|
28108
|
+
printTaskDetail(item, await resolveLinkedLinkTitles(item, workspaceId));
|
|
28109
|
+
}
|
|
28110
|
+
async function resolveLinkedLinkTitles(item, workspaceId) {
|
|
28111
|
+
return Promise.all(
|
|
28112
|
+
item.linkedLinks.map(async (link) => {
|
|
28113
|
+
if (link.title.trim().length > 0) return link.title;
|
|
28114
|
+
if (!isWorkspaceFileLink(link.url, workspaceId)) return link.url;
|
|
28115
|
+
try {
|
|
28116
|
+
const response = await httpGet(
|
|
28117
|
+
`/files/read-by-url?url=${encodeURIComponent(link.url)}`
|
|
28118
|
+
);
|
|
28119
|
+
if (!response.ok || response.data.type !== "file") return link.url;
|
|
28120
|
+
return import_node_path16.posix.basename(response.data.path) || link.url;
|
|
28121
|
+
} catch {
|
|
28122
|
+
return link.url;
|
|
28123
|
+
}
|
|
28124
|
+
})
|
|
28125
|
+
);
|
|
28126
|
+
}
|
|
28127
|
+
function isWorkspaceFileLink(url, workspaceId) {
|
|
28128
|
+
try {
|
|
28129
|
+
const segments = new URL(url).pathname.split("/").filter(Boolean);
|
|
28130
|
+
return segments.length === 3 && segments[0] === "w" && segments[1] === workspaceId && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
|
|
28131
|
+
segments[2]
|
|
28132
|
+
);
|
|
28133
|
+
} catch {
|
|
28134
|
+
return false;
|
|
28135
|
+
}
|
|
28136
|
+
}
|
|
26537
28137
|
function printCommentDetail(item) {
|
|
26538
28138
|
print(`${colors.bold}Comment${colors.reset}`);
|
|
26539
28139
|
printDetailField2("id", item.id);
|
|
@@ -26835,7 +28435,7 @@ function registerTaskCommands(workflow) {
|
|
|
26835
28435
|
failResponse(response);
|
|
26836
28436
|
}
|
|
26837
28437
|
stopSpinner(true, "Task fetched");
|
|
26838
|
-
|
|
28438
|
+
await printResolvedTaskDetail(response.data, options.workspace);
|
|
26839
28439
|
});
|
|
26840
28440
|
addAssigneeOptions(
|
|
26841
28441
|
addWorkspaceOption(
|
|
@@ -26875,7 +28475,7 @@ function registerTaskCommands(workflow) {
|
|
|
26875
28475
|
failResponse(response);
|
|
26876
28476
|
}
|
|
26877
28477
|
stopSpinner(true, "Task created");
|
|
26878
|
-
|
|
28478
|
+
await printResolvedTaskDetail(response.data, options.workspace);
|
|
26879
28479
|
}
|
|
26880
28480
|
);
|
|
26881
28481
|
addWorkspaceOption(
|
|
@@ -26914,21 +28514,26 @@ function registerTaskCommands(workflow) {
|
|
|
26914
28514
|
failResponse(response);
|
|
26915
28515
|
}
|
|
26916
28516
|
stopSpinner(true, "Task updated");
|
|
26917
|
-
|
|
28517
|
+
await printResolvedTaskDetail(response.data, options.workspace);
|
|
26918
28518
|
}
|
|
26919
28519
|
);
|
|
26920
|
-
for (const action of ["add-linked-
|
|
26921
|
-
|
|
26922
|
-
|
|
26923
|
-
|
|
28520
|
+
for (const action of ["add-linked-links", "remove-linked-links"]) {
|
|
28521
|
+
const command = task.command(action).description(`${action === "add-linked-links" ? "Add" : "Remove"} a URL link on a workflow task`).argument("<workflowFileId>").argument("<taskScopedId>").requiredOption("--url <url>", "HTTP or HTTPS URL");
|
|
28522
|
+
if (action === "add-linked-links") {
|
|
28523
|
+
command.option("--title <title>", "Optional link title");
|
|
28524
|
+
}
|
|
28525
|
+
addWorkspaceOption(command).action(
|
|
26924
28526
|
async (workflowFileId, taskScopedId, options) => {
|
|
26925
|
-
const { id,
|
|
28527
|
+
const { id, link } = runOrExit4(() => ({
|
|
26926
28528
|
id: parsePositiveInteger(taskScopedId, "taskScopedId"),
|
|
26927
|
-
|
|
28529
|
+
link: {
|
|
28530
|
+
title: action === "add-linked-links" ? options.title?.trim() ?? "" : "",
|
|
28531
|
+
url: parseHttpUrl(options.url)
|
|
28532
|
+
}
|
|
26928
28533
|
}));
|
|
26929
|
-
startSpinner(action === "add-linked-
|
|
26930
|
-
const path4 = `/workspaces/${options.workspace}/workflows/${workflowFileId}/tasks-v2/${id}/linked-
|
|
26931
|
-
const updateResponse = action === "add-linked-
|
|
28534
|
+
startSpinner(action === "add-linked-links" ? "Adding linked URL..." : "Removing linked URL...");
|
|
28535
|
+
const path4 = `/workspaces/${options.workspace}/workflows/${workflowFileId}/tasks-v2/${id}/linked-links`;
|
|
28536
|
+
const updateResponse = action === "add-linked-links" ? await httpPost(path4, { links: [link] }) : await httpDelete(path4, { links: [link] });
|
|
26932
28537
|
if (!updateResponse.ok) {
|
|
26933
28538
|
stopSpinner(false, "Failed");
|
|
26934
28539
|
failResponse(updateResponse);
|
|
@@ -26938,8 +28543,8 @@ function registerTaskCommands(workflow) {
|
|
|
26938
28543
|
stopSpinner(false, "Failed");
|
|
26939
28544
|
failResponse(response);
|
|
26940
28545
|
}
|
|
26941
|
-
stopSpinner(true, action === "add-linked-
|
|
26942
|
-
|
|
28546
|
+
stopSpinner(true, action === "add-linked-links" ? "Linked URL added" : "Linked URL removed");
|
|
28547
|
+
await printResolvedTaskDetail(response.data, options.workspace);
|
|
26943
28548
|
}
|
|
26944
28549
|
);
|
|
26945
28550
|
}
|
|
@@ -26966,7 +28571,7 @@ function registerTaskCommands(workflow) {
|
|
|
26966
28571
|
failResponse(response);
|
|
26967
28572
|
}
|
|
26968
28573
|
stopSpinner(true, "Task moved");
|
|
26969
|
-
|
|
28574
|
+
await printResolvedTaskDetail(response.data, options.workspace);
|
|
26970
28575
|
}
|
|
26971
28576
|
);
|
|
26972
28577
|
addWorkspaceOption(
|
|
@@ -27001,7 +28606,7 @@ function registerTaskCommands(workflow) {
|
|
|
27001
28606
|
failResponse(response);
|
|
27002
28607
|
}
|
|
27003
28608
|
stopSpinner(true, "Task moved");
|
|
27004
|
-
|
|
28609
|
+
await printResolvedTaskDetail(response.data, options.workspace);
|
|
27005
28610
|
}
|
|
27006
28611
|
);
|
|
27007
28612
|
addAssigneeOptions(
|
|
@@ -27031,7 +28636,7 @@ function registerTaskCommands(workflow) {
|
|
|
27031
28636
|
failResponse(response);
|
|
27032
28637
|
}
|
|
27033
28638
|
stopSpinner(true, "Task assignee updated");
|
|
27034
|
-
|
|
28639
|
+
await printResolvedTaskDetail(response.data, options.workspace);
|
|
27035
28640
|
}
|
|
27036
28641
|
);
|
|
27037
28642
|
addWorkspaceOption(
|
|
@@ -27051,7 +28656,7 @@ function registerTaskCommands(workflow) {
|
|
|
27051
28656
|
}
|
|
27052
28657
|
function getWorkflowTask(workspaceId, workflowFileId, taskScopedId) {
|
|
27053
28658
|
return httpGet(
|
|
27054
|
-
`/workspaces/${workspaceId}/workflows/${workflowFileId}/tasks-
|
|
28659
|
+
`/workspaces/${workspaceId}/workflows/${workflowFileId}/tasks-v3/${taskScopedId}`
|
|
27055
28660
|
);
|
|
27056
28661
|
}
|
|
27057
28662
|
function registerCommentCommands(workflow) {
|
|
@@ -27185,16 +28790,16 @@ function createProgram(version) {
|
|
|
27185
28790
|
|
|
27186
28791
|
// src/telemetry/client.ts
|
|
27187
28792
|
init_cjs_shims();
|
|
27188
|
-
var
|
|
28793
|
+
var import_node_os11 = require("os");
|
|
27189
28794
|
var buffer = [];
|
|
27190
28795
|
var FLUSH_TIMEOUT_MS = 3e3;
|
|
27191
28796
|
var MAX_BATCH_SIZE = 100;
|
|
27192
28797
|
function commonLabels() {
|
|
27193
28798
|
return {
|
|
27194
|
-
cli_version: "0.10.0-beta.
|
|
28799
|
+
cli_version: "0.10.0-beta.7",
|
|
27195
28800
|
node_version: process.versions.node,
|
|
27196
|
-
os: (0,
|
|
27197
|
-
arch: (0,
|
|
28801
|
+
os: (0, import_node_os11.platform)(),
|
|
28802
|
+
arch: (0, import_node_os11.arch)(),
|
|
27198
28803
|
is_ci: isCiEnvironment() ? "true" : "false"
|
|
27199
28804
|
};
|
|
27200
28805
|
}
|
|
@@ -27237,7 +28842,7 @@ async function flush() {
|
|
|
27237
28842
|
}
|
|
27238
28843
|
const batch = buffer.splice(0, MAX_BATCH_SIZE);
|
|
27239
28844
|
const payload = {
|
|
27240
|
-
release_id: "0.10.0-beta.
|
|
28845
|
+
release_id: "0.10.0-beta.7",
|
|
27241
28846
|
client_type: "cli",
|
|
27242
28847
|
metric_data_list: batch.map((m) => ({
|
|
27243
28848
|
profile: "cli",
|
|
@@ -27438,7 +29043,7 @@ function registryWorker() {
|
|
|
27438
29043
|
|
|
27439
29044
|
// src/update/prompt.ts
|
|
27440
29045
|
init_cjs_shims();
|
|
27441
|
-
var
|
|
29046
|
+
var import_promises21 = require("readline/promises");
|
|
27442
29047
|
async function promptForUpdate(input, output, currentVersion, latestVersion, timeoutMs) {
|
|
27443
29048
|
output.write(`
|
|
27444
29049
|
A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion}
|
|
@@ -27451,7 +29056,7 @@ A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion
|
|
|
27451
29056
|
const controller = new AbortController();
|
|
27452
29057
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
27453
29058
|
timeout.unref();
|
|
27454
|
-
const readline = (0,
|
|
29059
|
+
const readline = (0, import_promises21.createInterface)({ input, output, terminal: true });
|
|
27455
29060
|
try {
|
|
27456
29061
|
const answer = await readline.question("", { signal: controller.signal });
|
|
27457
29062
|
if (answer.trim() === "1") return "update";
|
|
@@ -27554,7 +29159,7 @@ function commandPath2(command) {
|
|
|
27554
29159
|
|
|
27555
29160
|
// src/update/daemon-reconcile-hook.ts
|
|
27556
29161
|
init_cjs_shims();
|
|
27557
|
-
var
|
|
29162
|
+
var import_node_path17 = require("path");
|
|
27558
29163
|
function installDaemonReconcileHook(program3, cliVersion) {
|
|
27559
29164
|
program3.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
27560
29165
|
if (!isEligible2(actionCommand)) return;
|
|
@@ -27576,9 +29181,9 @@ function installDaemonReconcileHook(program3, cliVersion) {
|
|
|
27576
29181
|
await reconcileManagedDaemon2({
|
|
27577
29182
|
cliVersion,
|
|
27578
29183
|
commandArguments: ["machine", "daemon"],
|
|
27579
|
-
entrypointPath: (0,
|
|
29184
|
+
entrypointPath: (0, import_node_path17.resolve)(entrypointPath),
|
|
27580
29185
|
environment: {},
|
|
27581
|
-
nodePath: (0,
|
|
29186
|
+
nodePath: (0, import_node_path17.resolve)(process.execPath),
|
|
27582
29187
|
onActiveJobs: (count) => {
|
|
27583
29188
|
process.stderr.write(
|
|
27584
29189
|
`Warning: restarting the managed Connector will interrupt ${count} active ${count === 1 ? "Job" : "Jobs"}.
|
|
@@ -27620,9 +29225,9 @@ function commandPath3(command) {
|
|
|
27620
29225
|
}
|
|
27621
29226
|
|
|
27622
29227
|
// src/index.ts
|
|
27623
|
-
var program2 = createProgram("0.10.0-beta.
|
|
27624
|
-
installDaemonReconcileHook(program2, "0.10.0-beta.
|
|
27625
|
-
installUpdateHook(program2, "0.10.0-beta.
|
|
29228
|
+
var program2 = createProgram("0.10.0-beta.7");
|
|
29229
|
+
installDaemonReconcileHook(program2, "0.10.0-beta.7");
|
|
29230
|
+
installUpdateHook(program2, "0.10.0-beta.7");
|
|
27626
29231
|
instrumentProgram(program2);
|
|
27627
29232
|
installExitHandler();
|
|
27628
29233
|
program2.parseAsync(process.argv).then(async () => {
|