@moxt-ai/cli 0.11.0-beta.5 → 0.11.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1286 -259
- package/dist/index.cjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4976,7 +4976,7 @@ var init_version = __esm({
|
|
|
4976
4976
|
});
|
|
4977
4977
|
|
|
4978
4978
|
// ../machine-connector/dist/runtime/local-codex-runtime/contracts.js
|
|
4979
|
-
var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexUnavailableReasonWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexDiscoveryKindWire, LocalCodexDiscoveryStatusWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
|
|
4979
|
+
var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexUnavailableReasonWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexDiscoveryKindWire, localFilesCapability, LocalCodexDiscoveryStatusWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
|
|
4980
4980
|
var init_contracts2 = __esm({
|
|
4981
4981
|
"../machine-connector/dist/runtime/local-codex-runtime/contracts.js"() {
|
|
4982
4982
|
"use strict";
|
|
@@ -5016,8 +5016,13 @@ var init_contracts2 = __esm({
|
|
|
5016
5016
|
})(LocalCodexControlOutcomeWire || (LocalCodexControlOutcomeWire = {}));
|
|
5017
5017
|
(function(LocalCodexDiscoveryKindWire2) {
|
|
5018
5018
|
LocalCodexDiscoveryKindWire2["DirectoryList"] = "directory_list";
|
|
5019
|
+
LocalCodexDiscoveryKindWire2["LocalFileList"] = "local_file_list";
|
|
5020
|
+
LocalCodexDiscoveryKindWire2["LocalFileRead"] = "local_file_read";
|
|
5021
|
+
LocalCodexDiscoveryKindWire2["LocalFileSearch"] = "local_file_search";
|
|
5022
|
+
LocalCodexDiscoveryKindWire2["LocalFileValidate"] = "local_file_validate";
|
|
5019
5023
|
LocalCodexDiscoveryKindWire2["ModelList"] = "model_list";
|
|
5020
5024
|
})(LocalCodexDiscoveryKindWire || (LocalCodexDiscoveryKindWire = {}));
|
|
5025
|
+
localFilesCapability = "local_files_v1";
|
|
5021
5026
|
(function(LocalCodexDiscoveryStatusWire2) {
|
|
5022
5027
|
LocalCodexDiscoveryStatusWire2["Failed"] = "failed";
|
|
5023
5028
|
LocalCodexDiscoveryStatusWire2["Succeeded"] = "succeeded";
|
|
@@ -5078,7 +5083,7 @@ function extractKnownCodexVersion(userAgent) {
|
|
|
5078
5083
|
return matched === null ? {} : { value: matched[1] };
|
|
5079
5084
|
}
|
|
5080
5085
|
async function probeCodexVersion(executable, processBaseDirectory, environment) {
|
|
5081
|
-
const result = await new Promise((
|
|
5086
|
+
const result = await new Promise((resolve11) => {
|
|
5082
5087
|
(0, import_node_child_process2.execFile)(executable, ["--version"], {
|
|
5083
5088
|
cwd: processBaseDirectory,
|
|
5084
5089
|
encoding: "utf8",
|
|
@@ -5088,10 +5093,10 @@ async function probeCodexVersion(executable, processBaseDirectory, environment)
|
|
|
5088
5093
|
windowsHide: true
|
|
5089
5094
|
}, (error, stdout) => {
|
|
5090
5095
|
if (error !== null || typeof stdout !== "string") {
|
|
5091
|
-
|
|
5096
|
+
resolve11({});
|
|
5092
5097
|
return;
|
|
5093
5098
|
}
|
|
5094
|
-
|
|
5099
|
+
resolve11({ output: stdout });
|
|
5095
5100
|
});
|
|
5096
5101
|
});
|
|
5097
5102
|
if (result.output === void 0) {
|
|
@@ -5140,12 +5145,12 @@ async function completionWithinExit(child, milliseconds) {
|
|
|
5140
5145
|
if (child.exitCode !== null || child.signalCode !== null) {
|
|
5141
5146
|
return;
|
|
5142
5147
|
}
|
|
5143
|
-
await new Promise((
|
|
5144
|
-
const timeout = setTimeout(
|
|
5148
|
+
await new Promise((resolve11) => {
|
|
5149
|
+
const timeout = setTimeout(resolve11, milliseconds);
|
|
5145
5150
|
timeout.unref();
|
|
5146
5151
|
child.once("close", () => {
|
|
5147
5152
|
clearTimeout(timeout);
|
|
5148
|
-
|
|
5153
|
+
resolve11();
|
|
5149
5154
|
});
|
|
5150
5155
|
});
|
|
5151
5156
|
}
|
|
@@ -5155,8 +5160,8 @@ async function completionWithinProcessTreeExit(child, stopTarget, milliseconds)
|
|
|
5155
5160
|
if (!await appServerProcessTreeIsRunning(child, stopTarget)) {
|
|
5156
5161
|
return;
|
|
5157
5162
|
}
|
|
5158
|
-
await new Promise((
|
|
5159
|
-
setTimeout(
|
|
5163
|
+
await new Promise((resolve11) => {
|
|
5164
|
+
setTimeout(resolve11, processTreePollMilliseconds);
|
|
5160
5165
|
});
|
|
5161
5166
|
}
|
|
5162
5167
|
}
|
|
@@ -5290,7 +5295,7 @@ async function captureAppServerProcessTree(child) {
|
|
|
5290
5295
|
};
|
|
5291
5296
|
}
|
|
5292
5297
|
async function appServerProcessTable() {
|
|
5293
|
-
const listed = await new Promise((
|
|
5298
|
+
const listed = await new Promise((resolve11) => {
|
|
5294
5299
|
(0, import_node_child_process2.execFile)(processTableExecutable(), ["-axo", "pid=,ppid=,lstart="], {
|
|
5295
5300
|
encoding: "utf8",
|
|
5296
5301
|
maxBuffer: maximumProcessTableBytes,
|
|
@@ -5298,10 +5303,10 @@ async function appServerProcessTable() {
|
|
|
5298
5303
|
windowsHide: true
|
|
5299
5304
|
}, (error, stdout) => {
|
|
5300
5305
|
if (error !== null || typeof stdout !== "string") {
|
|
5301
|
-
|
|
5306
|
+
resolve11({});
|
|
5302
5307
|
return;
|
|
5303
5308
|
}
|
|
5304
|
-
|
|
5309
|
+
resolve11({ output: stdout });
|
|
5305
5310
|
});
|
|
5306
5311
|
});
|
|
5307
5312
|
if (listed.output === void 0) {
|
|
@@ -5352,8 +5357,8 @@ async function appServerProcessTableWithRetry() {
|
|
|
5352
5357
|
return processTable;
|
|
5353
5358
|
}
|
|
5354
5359
|
if (attempt < maximumProcessTableAttempts) {
|
|
5355
|
-
await new Promise((
|
|
5356
|
-
setTimeout(
|
|
5360
|
+
await new Promise((resolve11) => {
|
|
5361
|
+
setTimeout(resolve11, processTableRetryMilliseconds);
|
|
5357
5362
|
});
|
|
5358
5363
|
}
|
|
5359
5364
|
}
|
|
@@ -5392,7 +5397,7 @@ var init_app_server_client = __esm({
|
|
|
5392
5397
|
init_version();
|
|
5393
5398
|
init_contracts2();
|
|
5394
5399
|
maximumFrameBytes = 8e6;
|
|
5395
|
-
requestTimeoutMilliseconds =
|
|
5400
|
+
requestTimeoutMilliseconds = 6e4;
|
|
5396
5401
|
processExitGraceMilliseconds = 2e3;
|
|
5397
5402
|
processTreePollMilliseconds = 250;
|
|
5398
5403
|
processTableTimeoutMilliseconds = 1e3;
|
|
@@ -5572,13 +5577,13 @@ var init_app_server_client = __esm({
|
|
|
5572
5577
|
const id = this.nextRequestId;
|
|
5573
5578
|
this.nextRequestId += 1;
|
|
5574
5579
|
const key = String(id);
|
|
5575
|
-
const response = new Promise((
|
|
5580
|
+
const response = new Promise((resolve11, reject) => {
|
|
5576
5581
|
const timeout = setTimeout(() => {
|
|
5577
5582
|
this.pending.delete(key);
|
|
5578
5583
|
reject(new AppServerRequestTimeoutError(method));
|
|
5579
5584
|
}, timeoutMilliseconds);
|
|
5580
5585
|
timeout.unref();
|
|
5581
|
-
this.pending.set(key, { reject, resolve:
|
|
5586
|
+
this.pending.set(key, { reject, resolve: resolve11, timeout });
|
|
5582
5587
|
});
|
|
5583
5588
|
await this.write({ id, method, params });
|
|
5584
5589
|
return await response;
|
|
@@ -5715,12 +5720,12 @@ var init_app_server_client = __esm({
|
|
|
5715
5720
|
if (Buffer.byteLength(frame, "utf8") > maximumFrameBytes) {
|
|
5716
5721
|
throw new AppServerProtocolError("Codex App Server request exceeds the size limit");
|
|
5717
5722
|
}
|
|
5718
|
-
const operation = this.writeQueue.then(async () => await new Promise((
|
|
5723
|
+
const operation = this.writeQueue.then(async () => await new Promise((resolve11, reject) => {
|
|
5719
5724
|
this.child.stdin.write(frame, (error) => {
|
|
5720
5725
|
if (error) {
|
|
5721
5726
|
reject(error);
|
|
5722
5727
|
} else {
|
|
5723
|
-
|
|
5728
|
+
resolve11();
|
|
5724
5729
|
}
|
|
5725
5730
|
});
|
|
5726
5731
|
}));
|
|
@@ -5800,8 +5805,9 @@ var init_app_server_client = __esm({
|
|
|
5800
5805
|
return true;
|
|
5801
5806
|
}
|
|
5802
5807
|
async stop() {
|
|
5803
|
-
|
|
5808
|
+
const client = this.client.value;
|
|
5804
5809
|
this.client = {};
|
|
5810
|
+
await client?.stop();
|
|
5805
5811
|
}
|
|
5806
5812
|
async quarantineCurrentProcess(capture) {
|
|
5807
5813
|
if (this.quarantinePromise !== void 0) {
|
|
@@ -5877,6 +5883,7 @@ async function executeCodex(processPool, ownerId, workingDirectory, environment,
|
|
|
5877
5883
|
const route = new CodexToolRoute(processPool, callbacks, existingThreadId);
|
|
5878
5884
|
processPool.register(ownerId, route);
|
|
5879
5885
|
let slot;
|
|
5886
|
+
let threadLease;
|
|
5880
5887
|
try {
|
|
5881
5888
|
slot = await acquireExecutionSlot(processPool, ownerId, callbacks);
|
|
5882
5889
|
if (slot === void 0) {
|
|
@@ -5887,7 +5894,8 @@ async function executeCodex(processPool, ownerId, workingDirectory, environment,
|
|
|
5887
5894
|
if (!canContinue(callbacks)) {
|
|
5888
5895
|
return cancelledResult(existingThreadId);
|
|
5889
5896
|
}
|
|
5890
|
-
|
|
5897
|
+
threadLease = await prepareThread(processPool, client, workingDirectory, environment, existingThreadId);
|
|
5898
|
+
const threadId = threadLease.threadId;
|
|
5891
5899
|
route.setThreadId(threadId);
|
|
5892
5900
|
await callbacks.onThreadPrepared(threadId);
|
|
5893
5901
|
if (!canContinue(callbacks)) {
|
|
@@ -5937,10 +5945,14 @@ async function executeCodex(processPool, ownerId, workingDirectory, environment,
|
|
|
5937
5945
|
} catch (error) {
|
|
5938
5946
|
return failedResult(error, route.threadId() ?? existingThreadId);
|
|
5939
5947
|
} finally {
|
|
5940
|
-
|
|
5941
|
-
|
|
5948
|
+
try {
|
|
5949
|
+
if (slot !== void 0) {
|
|
5950
|
+
processPool.releaseExecutionSlot(slot);
|
|
5951
|
+
}
|
|
5952
|
+
processPool.unregister(ownerId);
|
|
5953
|
+
} finally {
|
|
5954
|
+
await threadLease?.release();
|
|
5942
5955
|
}
|
|
5943
|
-
processPool.unregister(ownerId);
|
|
5944
5956
|
}
|
|
5945
5957
|
}
|
|
5946
5958
|
async function prepareThread(processPool, client, workingDirectory, environment, existingThreadId) {
|
|
@@ -5957,22 +5969,10 @@ async function prepareThread(processPool, client, workingDirectory, environment,
|
|
|
5957
5969
|
ephemeral: false,
|
|
5958
5970
|
sandbox: "danger-full-access"
|
|
5959
5971
|
};
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
}
|
|
5965
|
-
if (!processPool.isThreadLoaded(existingThreadId)) {
|
|
5966
|
-
const threadId = requireThreadId(await client.request("thread/resume", {
|
|
5967
|
-
...parameters,
|
|
5968
|
-
threadId: existingThreadId
|
|
5969
|
-
}));
|
|
5970
|
-
if (threadId !== existingThreadId) {
|
|
5971
|
-
throw new Error("Codex App Server resumed another thread");
|
|
5972
|
-
}
|
|
5973
|
-
processPool.rememberThreadLoaded(threadId);
|
|
5974
|
-
}
|
|
5975
|
-
return existingThreadId;
|
|
5972
|
+
return await processPool.acquireThread(client, existingThreadId, async () => requireThreadId(existingThreadId === void 0 ? await client.request("thread/start", parameters) : await client.request("thread/resume", {
|
|
5973
|
+
...parameters,
|
|
5974
|
+
threadId: existingThreadId
|
|
5975
|
+
})));
|
|
5976
5976
|
}
|
|
5977
5977
|
async function acquireExecutionSlot(processPool, ownerId, callbacks) {
|
|
5978
5978
|
while (canContinue(callbacks)) {
|
|
@@ -8871,6 +8871,853 @@ var init_store = __esm({
|
|
|
8871
8871
|
}
|
|
8872
8872
|
});
|
|
8873
8873
|
|
|
8874
|
+
// ../machine-connector/node_modules/.pnpm/ignore@7.0.5/node_modules/ignore/index.js
|
|
8875
|
+
var require_ignore = __commonJS({
|
|
8876
|
+
"../machine-connector/node_modules/.pnpm/ignore@7.0.5/node_modules/ignore/index.js"(exports2, module2) {
|
|
8877
|
+
"use strict";
|
|
8878
|
+
init_cjs_shims();
|
|
8879
|
+
function makeArray(subject) {
|
|
8880
|
+
return Array.isArray(subject) ? subject : [subject];
|
|
8881
|
+
}
|
|
8882
|
+
var UNDEFINED = void 0;
|
|
8883
|
+
var EMPTY = "";
|
|
8884
|
+
var SPACE = " ";
|
|
8885
|
+
var ESCAPE = "\\";
|
|
8886
|
+
var REGEX_TEST_BLANK_LINE = /^\s+$/;
|
|
8887
|
+
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
8888
|
+
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
8889
|
+
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
8890
|
+
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
8891
|
+
var REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/;
|
|
8892
|
+
var REGEX_TEST_TRAILING_SLASH = /\/$/;
|
|
8893
|
+
var SLASH = "/";
|
|
8894
|
+
var TMP_KEY_IGNORE = "node-ignore";
|
|
8895
|
+
if (typeof Symbol !== "undefined") {
|
|
8896
|
+
TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
|
|
8897
|
+
}
|
|
8898
|
+
var KEY_IGNORE = TMP_KEY_IGNORE;
|
|
8899
|
+
var define = (object, key, value) => {
|
|
8900
|
+
Object.defineProperty(object, key, { value });
|
|
8901
|
+
return value;
|
|
8902
|
+
};
|
|
8903
|
+
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
|
|
8904
|
+
var RETURN_FALSE = () => false;
|
|
8905
|
+
var sanitizeRange = (range) => range.replace(
|
|
8906
|
+
REGEX_REGEXP_RANGE,
|
|
8907
|
+
(match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match : EMPTY
|
|
8908
|
+
);
|
|
8909
|
+
var cleanRangeBackSlash = (slashes) => {
|
|
8910
|
+
const { length } = slashes;
|
|
8911
|
+
return slashes.slice(0, length - length % 2);
|
|
8912
|
+
};
|
|
8913
|
+
var REPLACERS = [
|
|
8914
|
+
[
|
|
8915
|
+
// Remove BOM
|
|
8916
|
+
// TODO:
|
|
8917
|
+
// Other similar zero-width characters?
|
|
8918
|
+
/^\uFEFF/,
|
|
8919
|
+
() => EMPTY
|
|
8920
|
+
],
|
|
8921
|
+
// > Trailing spaces are ignored unless they are quoted with backslash ("\")
|
|
8922
|
+
[
|
|
8923
|
+
// (a\ ) -> (a )
|
|
8924
|
+
// (a ) -> (a)
|
|
8925
|
+
// (a ) -> (a)
|
|
8926
|
+
// (a \ ) -> (a )
|
|
8927
|
+
/((?:\\\\)*?)(\\?\s+)$/,
|
|
8928
|
+
(_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
|
|
8929
|
+
],
|
|
8930
|
+
// Replace (\ ) with ' '
|
|
8931
|
+
// (\ ) -> ' '
|
|
8932
|
+
// (\\ ) -> '\\ '
|
|
8933
|
+
// (\\\ ) -> '\\ '
|
|
8934
|
+
[
|
|
8935
|
+
/(\\+?)\s/g,
|
|
8936
|
+
(_, m1) => {
|
|
8937
|
+
const { length } = m1;
|
|
8938
|
+
return m1.slice(0, length - length % 2) + SPACE;
|
|
8939
|
+
}
|
|
8940
|
+
],
|
|
8941
|
+
// Escape metacharacters
|
|
8942
|
+
// which is written down by users but means special for regular expressions.
|
|
8943
|
+
// > There are 12 characters with special meanings:
|
|
8944
|
+
// > - the backslash \,
|
|
8945
|
+
// > - the caret ^,
|
|
8946
|
+
// > - the dollar sign $,
|
|
8947
|
+
// > - the period or dot .,
|
|
8948
|
+
// > - the vertical bar or pipe symbol |,
|
|
8949
|
+
// > - the question mark ?,
|
|
8950
|
+
// > - the asterisk or star *,
|
|
8951
|
+
// > - the plus sign +,
|
|
8952
|
+
// > - the opening parenthesis (,
|
|
8953
|
+
// > - the closing parenthesis ),
|
|
8954
|
+
// > - and the opening square bracket [,
|
|
8955
|
+
// > - the opening curly brace {,
|
|
8956
|
+
// > These special characters are often called "metacharacters".
|
|
8957
|
+
[
|
|
8958
|
+
/[\\$.|*+(){^]/g,
|
|
8959
|
+
(match) => `\\${match}`
|
|
8960
|
+
],
|
|
8961
|
+
[
|
|
8962
|
+
// > a question mark (?) matches a single character
|
|
8963
|
+
/(?!\\)\?/g,
|
|
8964
|
+
() => "[^/]"
|
|
8965
|
+
],
|
|
8966
|
+
// leading slash
|
|
8967
|
+
[
|
|
8968
|
+
// > A leading slash matches the beginning of the pathname.
|
|
8969
|
+
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
|
8970
|
+
// A leading slash matches the beginning of the pathname
|
|
8971
|
+
/^\//,
|
|
8972
|
+
() => "^"
|
|
8973
|
+
],
|
|
8974
|
+
// replace special metacharacter slash after the leading slash
|
|
8975
|
+
[
|
|
8976
|
+
/\//g,
|
|
8977
|
+
() => "\\/"
|
|
8978
|
+
],
|
|
8979
|
+
[
|
|
8980
|
+
// > A leading "**" followed by a slash means match in all directories.
|
|
8981
|
+
// > For example, "**/foo" matches file or directory "foo" anywhere,
|
|
8982
|
+
// > the same as pattern "foo".
|
|
8983
|
+
// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
|
8984
|
+
// > under directory "foo".
|
|
8985
|
+
// Notice that the '*'s have been replaced as '\\*'
|
|
8986
|
+
/^\^*\\\*\\\*\\\//,
|
|
8987
|
+
// '**/foo' <-> 'foo'
|
|
8988
|
+
() => "^(?:.*\\/)?"
|
|
8989
|
+
],
|
|
8990
|
+
// starting
|
|
8991
|
+
[
|
|
8992
|
+
// there will be no leading '/'
|
|
8993
|
+
// (which has been replaced by section "leading slash")
|
|
8994
|
+
// If starts with '**', adding a '^' to the regular expression also works
|
|
8995
|
+
/^(?=[^^])/,
|
|
8996
|
+
function startingReplacer() {
|
|
8997
|
+
return !/\/(?!$)/.test(this) ? "(?:^|\\/)" : "^";
|
|
8998
|
+
}
|
|
8999
|
+
],
|
|
9000
|
+
// two globstars
|
|
9001
|
+
[
|
|
9002
|
+
// Use lookahead assertions so that we could match more than one `'/**'`
|
|
9003
|
+
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
9004
|
+
// Zero, one or several directories
|
|
9005
|
+
// should not use '*', or it will be replaced by the next replacer
|
|
9006
|
+
// Check if it is not the last `'/**'`
|
|
9007
|
+
(_, index2, str) => index2 + 6 < str.length ? "(?:\\/[^\\/]+)*" : "\\/.+"
|
|
9008
|
+
],
|
|
9009
|
+
// normal intermediate wildcards
|
|
9010
|
+
[
|
|
9011
|
+
// Never replace escaped '*'
|
|
9012
|
+
// ignore rule '\*' will match the path '*'
|
|
9013
|
+
// 'abc.*/' -> go
|
|
9014
|
+
// 'abc.*' -> skip this rule,
|
|
9015
|
+
// coz trailing single wildcard will be handed by [trailing wildcard]
|
|
9016
|
+
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
9017
|
+
// '*.js' matches '.js'
|
|
9018
|
+
// '*.js' doesn't match 'abc'
|
|
9019
|
+
(_, p1, p2) => {
|
|
9020
|
+
const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
|
|
9021
|
+
return p1 + unescaped;
|
|
9022
|
+
}
|
|
9023
|
+
],
|
|
9024
|
+
[
|
|
9025
|
+
// unescape, revert step 3 except for back slash
|
|
9026
|
+
// For example, if a user escape a '\\*',
|
|
9027
|
+
// after step 3, the result will be '\\\\\\*'
|
|
9028
|
+
/\\\\\\(?=[$.|*+(){^])/g,
|
|
9029
|
+
() => ESCAPE
|
|
9030
|
+
],
|
|
9031
|
+
[
|
|
9032
|
+
// '\\\\' -> '\\'
|
|
9033
|
+
/\\\\/g,
|
|
9034
|
+
() => ESCAPE
|
|
9035
|
+
],
|
|
9036
|
+
[
|
|
9037
|
+
// > The range notation, e.g. [a-zA-Z],
|
|
9038
|
+
// > can be used to match one of the characters in a range.
|
|
9039
|
+
// `\` is escaped by step 3
|
|
9040
|
+
/(\\)?\[([^\]/]*?)(\\*)($|\])/g,
|
|
9041
|
+
(match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}` : close === "]" ? endEscape.length % 2 === 0 ? `[${sanitizeRange(range)}${endEscape}]` : "[]" : "[]"
|
|
9042
|
+
],
|
|
9043
|
+
// ending
|
|
9044
|
+
[
|
|
9045
|
+
// 'js' will not match 'js.'
|
|
9046
|
+
// 'ab' will not match 'abc'
|
|
9047
|
+
/(?:[^*])$/,
|
|
9048
|
+
// WTF!
|
|
9049
|
+
// https://git-scm.com/docs/gitignore
|
|
9050
|
+
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
|
9051
|
+
// which re-fixes #24, #38
|
|
9052
|
+
// > If there is a separator at the end of the pattern then the pattern
|
|
9053
|
+
// > will only match directories, otherwise the pattern can match both
|
|
9054
|
+
// > files and directories.
|
|
9055
|
+
// 'js*' will not match 'a.js'
|
|
9056
|
+
// 'js/' will not match 'a.js'
|
|
9057
|
+
// 'js' will match 'a.js' and 'a.js/'
|
|
9058
|
+
(match) => /\/$/.test(match) ? `${match}$` : `${match}(?=$|\\/$)`
|
|
9059
|
+
]
|
|
9060
|
+
];
|
|
9061
|
+
var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/;
|
|
9062
|
+
var MODE_IGNORE = "regex";
|
|
9063
|
+
var MODE_CHECK_IGNORE = "checkRegex";
|
|
9064
|
+
var UNDERSCORE = "_";
|
|
9065
|
+
var TRAILING_WILD_CARD_REPLACERS = {
|
|
9066
|
+
[MODE_IGNORE](_, p1) {
|
|
9067
|
+
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
9068
|
+
return `${prefix}(?=$|\\/$)`;
|
|
9069
|
+
},
|
|
9070
|
+
[MODE_CHECK_IGNORE](_, p1) {
|
|
9071
|
+
const prefix = p1 ? `${p1}[^/]*` : "[^/]*";
|
|
9072
|
+
return `${prefix}(?=$|\\/$)`;
|
|
9073
|
+
}
|
|
9074
|
+
};
|
|
9075
|
+
var makeRegexPrefix = (pattern) => REPLACERS.reduce(
|
|
9076
|
+
(prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(pattern)),
|
|
9077
|
+
pattern
|
|
9078
|
+
);
|
|
9079
|
+
var isString = (subject) => typeof subject === "string";
|
|
9080
|
+
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
9081
|
+
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
9082
|
+
var IgnoreRule = class {
|
|
9083
|
+
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
9084
|
+
this.pattern = pattern;
|
|
9085
|
+
this.mark = mark;
|
|
9086
|
+
this.negative = negative;
|
|
9087
|
+
define(this, "body", body);
|
|
9088
|
+
define(this, "ignoreCase", ignoreCase);
|
|
9089
|
+
define(this, "regexPrefix", prefix);
|
|
9090
|
+
}
|
|
9091
|
+
get regex() {
|
|
9092
|
+
const key = UNDERSCORE + MODE_IGNORE;
|
|
9093
|
+
if (this[key]) {
|
|
9094
|
+
return this[key];
|
|
9095
|
+
}
|
|
9096
|
+
return this._make(MODE_IGNORE, key);
|
|
9097
|
+
}
|
|
9098
|
+
get checkRegex() {
|
|
9099
|
+
const key = UNDERSCORE + MODE_CHECK_IGNORE;
|
|
9100
|
+
if (this[key]) {
|
|
9101
|
+
return this[key];
|
|
9102
|
+
}
|
|
9103
|
+
return this._make(MODE_CHECK_IGNORE, key);
|
|
9104
|
+
}
|
|
9105
|
+
_make(mode, key) {
|
|
9106
|
+
const str = this.regexPrefix.replace(
|
|
9107
|
+
REGEX_REPLACE_TRAILING_WILDCARD,
|
|
9108
|
+
// It does not need to bind pattern
|
|
9109
|
+
TRAILING_WILD_CARD_REPLACERS[mode]
|
|
9110
|
+
);
|
|
9111
|
+
const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
|
|
9112
|
+
return define(this, key, regex);
|
|
9113
|
+
}
|
|
9114
|
+
};
|
|
9115
|
+
var createRule = ({
|
|
9116
|
+
pattern,
|
|
9117
|
+
mark
|
|
9118
|
+
}, ignoreCase) => {
|
|
9119
|
+
let negative = false;
|
|
9120
|
+
let body = pattern;
|
|
9121
|
+
if (body.indexOf("!") === 0) {
|
|
9122
|
+
negative = true;
|
|
9123
|
+
body = body.substr(1);
|
|
9124
|
+
}
|
|
9125
|
+
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
9126
|
+
const regexPrefix = makeRegexPrefix(body);
|
|
9127
|
+
return new IgnoreRule(
|
|
9128
|
+
pattern,
|
|
9129
|
+
mark,
|
|
9130
|
+
body,
|
|
9131
|
+
ignoreCase,
|
|
9132
|
+
negative,
|
|
9133
|
+
regexPrefix
|
|
9134
|
+
);
|
|
9135
|
+
};
|
|
9136
|
+
var RuleManager = class {
|
|
9137
|
+
constructor(ignoreCase) {
|
|
9138
|
+
this._ignoreCase = ignoreCase;
|
|
9139
|
+
this._rules = [];
|
|
9140
|
+
}
|
|
9141
|
+
_add(pattern) {
|
|
9142
|
+
if (pattern && pattern[KEY_IGNORE]) {
|
|
9143
|
+
this._rules = this._rules.concat(pattern._rules._rules);
|
|
9144
|
+
this._added = true;
|
|
9145
|
+
return;
|
|
9146
|
+
}
|
|
9147
|
+
if (isString(pattern)) {
|
|
9148
|
+
pattern = {
|
|
9149
|
+
pattern
|
|
9150
|
+
};
|
|
9151
|
+
}
|
|
9152
|
+
if (checkPattern(pattern.pattern)) {
|
|
9153
|
+
const rule = createRule(pattern, this._ignoreCase);
|
|
9154
|
+
this._added = true;
|
|
9155
|
+
this._rules.push(rule);
|
|
9156
|
+
}
|
|
9157
|
+
}
|
|
9158
|
+
// @param {Array<string> | string | Ignore} pattern
|
|
9159
|
+
add(pattern) {
|
|
9160
|
+
this._added = false;
|
|
9161
|
+
makeArray(
|
|
9162
|
+
isString(pattern) ? splitPattern(pattern) : pattern
|
|
9163
|
+
).forEach(this._add, this);
|
|
9164
|
+
return this._added;
|
|
9165
|
+
}
|
|
9166
|
+
// Test one single path without recursively checking parent directories
|
|
9167
|
+
//
|
|
9168
|
+
// - checkUnignored `boolean` whether should check if the path is unignored,
|
|
9169
|
+
// setting `checkUnignored` to `false` could reduce additional
|
|
9170
|
+
// path matching.
|
|
9171
|
+
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
9172
|
+
// @returns {TestResult} true if a file is ignored
|
|
9173
|
+
test(path4, checkUnignored, mode) {
|
|
9174
|
+
let ignored = false;
|
|
9175
|
+
let unignored = false;
|
|
9176
|
+
let matchedRule;
|
|
9177
|
+
this._rules.forEach((rule) => {
|
|
9178
|
+
const { negative } = rule;
|
|
9179
|
+
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
|
9180
|
+
return;
|
|
9181
|
+
}
|
|
9182
|
+
const matched = rule[mode].test(path4);
|
|
9183
|
+
if (!matched) {
|
|
9184
|
+
return;
|
|
9185
|
+
}
|
|
9186
|
+
ignored = !negative;
|
|
9187
|
+
unignored = negative;
|
|
9188
|
+
matchedRule = negative ? UNDEFINED : rule;
|
|
9189
|
+
});
|
|
9190
|
+
const ret = {
|
|
9191
|
+
ignored,
|
|
9192
|
+
unignored
|
|
9193
|
+
};
|
|
9194
|
+
if (matchedRule) {
|
|
9195
|
+
ret.rule = matchedRule;
|
|
9196
|
+
}
|
|
9197
|
+
return ret;
|
|
9198
|
+
}
|
|
9199
|
+
};
|
|
9200
|
+
var throwError = (message, Ctor) => {
|
|
9201
|
+
throw new Ctor(message);
|
|
9202
|
+
};
|
|
9203
|
+
var checkPath = (path4, originalPath, doThrow) => {
|
|
9204
|
+
if (!isString(path4)) {
|
|
9205
|
+
return doThrow(
|
|
9206
|
+
`path must be a string, but got \`${originalPath}\``,
|
|
9207
|
+
TypeError
|
|
9208
|
+
);
|
|
9209
|
+
}
|
|
9210
|
+
if (!path4) {
|
|
9211
|
+
return doThrow(`path must not be empty`, TypeError);
|
|
9212
|
+
}
|
|
9213
|
+
if (checkPath.isNotRelative(path4)) {
|
|
9214
|
+
const r = "`path.relative()`d";
|
|
9215
|
+
return doThrow(
|
|
9216
|
+
`path should be a ${r} string, but got "${originalPath}"`,
|
|
9217
|
+
RangeError
|
|
9218
|
+
);
|
|
9219
|
+
}
|
|
9220
|
+
return true;
|
|
9221
|
+
};
|
|
9222
|
+
var isNotRelative = (path4) => REGEX_TEST_INVALID_PATH.test(path4);
|
|
9223
|
+
checkPath.isNotRelative = isNotRelative;
|
|
9224
|
+
checkPath.convert = (p) => p;
|
|
9225
|
+
var Ignore = class {
|
|
9226
|
+
constructor({
|
|
9227
|
+
ignorecase = true,
|
|
9228
|
+
ignoreCase = ignorecase,
|
|
9229
|
+
allowRelativePaths = false
|
|
9230
|
+
} = {}) {
|
|
9231
|
+
define(this, KEY_IGNORE, true);
|
|
9232
|
+
this._rules = new RuleManager(ignoreCase);
|
|
9233
|
+
this._strictPathCheck = !allowRelativePaths;
|
|
9234
|
+
this._initCache();
|
|
9235
|
+
}
|
|
9236
|
+
_initCache() {
|
|
9237
|
+
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
9238
|
+
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
9239
|
+
}
|
|
9240
|
+
add(pattern) {
|
|
9241
|
+
if (this._rules.add(pattern)) {
|
|
9242
|
+
this._initCache();
|
|
9243
|
+
}
|
|
9244
|
+
return this;
|
|
9245
|
+
}
|
|
9246
|
+
// legacy
|
|
9247
|
+
addPattern(pattern) {
|
|
9248
|
+
return this.add(pattern);
|
|
9249
|
+
}
|
|
9250
|
+
// @returns {TestResult}
|
|
9251
|
+
_test(originalPath, cache, checkUnignored, slices) {
|
|
9252
|
+
const path4 = originalPath && checkPath.convert(originalPath);
|
|
9253
|
+
checkPath(
|
|
9254
|
+
path4,
|
|
9255
|
+
originalPath,
|
|
9256
|
+
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
9257
|
+
);
|
|
9258
|
+
return this._t(path4, cache, checkUnignored, slices);
|
|
9259
|
+
}
|
|
9260
|
+
checkIgnore(path4) {
|
|
9261
|
+
if (!REGEX_TEST_TRAILING_SLASH.test(path4)) {
|
|
9262
|
+
return this.test(path4);
|
|
9263
|
+
}
|
|
9264
|
+
const slices = path4.split(SLASH).filter(Boolean);
|
|
9265
|
+
slices.pop();
|
|
9266
|
+
if (slices.length) {
|
|
9267
|
+
const parent = this._t(
|
|
9268
|
+
slices.join(SLASH) + SLASH,
|
|
9269
|
+
this._testCache,
|
|
9270
|
+
true,
|
|
9271
|
+
slices
|
|
9272
|
+
);
|
|
9273
|
+
if (parent.ignored) {
|
|
9274
|
+
return parent;
|
|
9275
|
+
}
|
|
9276
|
+
}
|
|
9277
|
+
return this._rules.test(path4, false, MODE_CHECK_IGNORE);
|
|
9278
|
+
}
|
|
9279
|
+
_t(path4, cache, checkUnignored, slices) {
|
|
9280
|
+
if (path4 in cache) {
|
|
9281
|
+
return cache[path4];
|
|
9282
|
+
}
|
|
9283
|
+
if (!slices) {
|
|
9284
|
+
slices = path4.split(SLASH).filter(Boolean);
|
|
9285
|
+
}
|
|
9286
|
+
slices.pop();
|
|
9287
|
+
if (!slices.length) {
|
|
9288
|
+
return cache[path4] = this._rules.test(path4, checkUnignored, MODE_IGNORE);
|
|
9289
|
+
}
|
|
9290
|
+
const parent = this._t(
|
|
9291
|
+
slices.join(SLASH) + SLASH,
|
|
9292
|
+
cache,
|
|
9293
|
+
checkUnignored,
|
|
9294
|
+
slices
|
|
9295
|
+
);
|
|
9296
|
+
return cache[path4] = parent.ignored ? parent : this._rules.test(path4, checkUnignored, MODE_IGNORE);
|
|
9297
|
+
}
|
|
9298
|
+
ignores(path4) {
|
|
9299
|
+
return this._test(path4, this._ignoreCache, false).ignored;
|
|
9300
|
+
}
|
|
9301
|
+
createFilter() {
|
|
9302
|
+
return (path4) => !this.ignores(path4);
|
|
9303
|
+
}
|
|
9304
|
+
filter(paths) {
|
|
9305
|
+
return makeArray(paths).filter(this.createFilter());
|
|
9306
|
+
}
|
|
9307
|
+
// @returns {TestResult}
|
|
9308
|
+
test(path4) {
|
|
9309
|
+
return this._test(path4, this._testCache, true);
|
|
9310
|
+
}
|
|
9311
|
+
};
|
|
9312
|
+
var factory = (options) => new Ignore(options);
|
|
9313
|
+
var isPathValid = (path4) => checkPath(path4 && checkPath.convert(path4), path4, RETURN_FALSE);
|
|
9314
|
+
var setupWindows = () => {
|
|
9315
|
+
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
9316
|
+
checkPath.convert = makePosix;
|
|
9317
|
+
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
9318
|
+
checkPath.isNotRelative = (path4) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path4) || isNotRelative(path4);
|
|
9319
|
+
};
|
|
9320
|
+
if (
|
|
9321
|
+
// Detect `process` so that it can run in browsers.
|
|
9322
|
+
typeof process !== "undefined" && process.platform === "win32"
|
|
9323
|
+
) {
|
|
9324
|
+
setupWindows();
|
|
9325
|
+
}
|
|
9326
|
+
module2.exports = factory;
|
|
9327
|
+
factory.default = factory;
|
|
9328
|
+
module2.exports.isPathValid = isPathValid;
|
|
9329
|
+
define(module2.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
|
|
9330
|
+
}
|
|
9331
|
+
});
|
|
9332
|
+
|
|
9333
|
+
// ../machine-connector/dist/runtime/local-codex-runtime/local-file-source.js
|
|
9334
|
+
function resolveWithin(root, input) {
|
|
9335
|
+
if (input.length === 0 || input.includes("\0") || (0, import_node_path9.isAbsolute)(input) || import_node_path9.win32.isAbsolute(input) || /^[A-Za-z]:/.test(input) || input.split(/[\\/]/).includes("..")) {
|
|
9336
|
+
throw new Error("Local file path escapes its root");
|
|
9337
|
+
}
|
|
9338
|
+
const resolved = (0, import_node_path9.resolve)(root, input);
|
|
9339
|
+
assertContained(root, resolved);
|
|
9340
|
+
return resolved;
|
|
9341
|
+
}
|
|
9342
|
+
function assertContained(root, candidate) {
|
|
9343
|
+
const rel = (0, import_node_path9.relative)(root, candidate);
|
|
9344
|
+
if (rel === ".." || rel.startsWith(`..${import_node_path9.sep}`) || (0, import_node_path9.isAbsolute)(rel))
|
|
9345
|
+
throw new Error("Local file path escapes its root");
|
|
9346
|
+
}
|
|
9347
|
+
function portable(path4) {
|
|
9348
|
+
const value = path4.split(import_node_path9.sep).join("/");
|
|
9349
|
+
return value === "" ? "." : value;
|
|
9350
|
+
}
|
|
9351
|
+
function isGitPath(path4) {
|
|
9352
|
+
return path4.split("/").includes(".git");
|
|
9353
|
+
}
|
|
9354
|
+
function relativePortable(base, path4) {
|
|
9355
|
+
if (base === "." || base === "")
|
|
9356
|
+
return path4;
|
|
9357
|
+
if (path4 === base)
|
|
9358
|
+
return ".";
|
|
9359
|
+
return path4.startsWith(`${base}/`) ? path4.slice(base.length + 1) : void 0;
|
|
9360
|
+
}
|
|
9361
|
+
function page(entries, cursor, limit) {
|
|
9362
|
+
const offset = cursor === void 0 ? 0 : Number.parseInt(cursor, 10);
|
|
9363
|
+
if (!Number.isSafeInteger(offset) || offset < 0)
|
|
9364
|
+
throw new Error("Local file cursor is invalid");
|
|
9365
|
+
const selected = entries.slice(offset, offset + limit);
|
|
9366
|
+
const nextOffset = offset + selected.length;
|
|
9367
|
+
return { entries: selected, ...nextOffset < entries.length ? { nextCursor: String(nextOffset) } : {}, truncated: nextOffset < entries.length };
|
|
9368
|
+
}
|
|
9369
|
+
function clampLimit(limit) {
|
|
9370
|
+
if (!Number.isSafeInteger(limit) || limit < 1)
|
|
9371
|
+
return defaultPageSize;
|
|
9372
|
+
return Math.min(limit, maximumPageSize);
|
|
9373
|
+
}
|
|
9374
|
+
function compareEntries(left, right) {
|
|
9375
|
+
if (left.kind !== right.kind)
|
|
9376
|
+
return left.kind === "directory" ? -1 : 1;
|
|
9377
|
+
return left.name.localeCompare(right.name, void 0, { numeric: true, sensitivity: "base" });
|
|
9378
|
+
}
|
|
9379
|
+
function isMissing(error) {
|
|
9380
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
9381
|
+
}
|
|
9382
|
+
function isUtf8(buffer2) {
|
|
9383
|
+
try {
|
|
9384
|
+
new TextDecoder("utf-8", { fatal: true }).decode(buffer2);
|
|
9385
|
+
return true;
|
|
9386
|
+
} catch {
|
|
9387
|
+
return false;
|
|
9388
|
+
}
|
|
9389
|
+
}
|
|
9390
|
+
var import_promises12, import_node_path9, import_ignore, maximumReadBytes, defaultPageSize, maximumPageSize, searchScanBudget, LocalFileSource, ScopedIgnoreMatcher;
|
|
9391
|
+
var init_local_file_source = __esm({
|
|
9392
|
+
"../machine-connector/dist/runtime/local-codex-runtime/local-file-source.js"() {
|
|
9393
|
+
"use strict";
|
|
9394
|
+
init_cjs_shims();
|
|
9395
|
+
import_promises12 = require("fs/promises");
|
|
9396
|
+
import_node_path9 = require("path");
|
|
9397
|
+
import_ignore = __toESM(require_ignore(), 1);
|
|
9398
|
+
maximumReadBytes = 5 * 1024 * 1024;
|
|
9399
|
+
defaultPageSize = 100;
|
|
9400
|
+
maximumPageSize = 200;
|
|
9401
|
+
searchScanBudget = 1e4;
|
|
9402
|
+
LocalFileSource = class _LocalFileSource {
|
|
9403
|
+
pairedRoot;
|
|
9404
|
+
workingDirectory;
|
|
9405
|
+
constructor(pairedRoot, workingDirectory) {
|
|
9406
|
+
this.pairedRoot = pairedRoot;
|
|
9407
|
+
this.workingDirectory = workingDirectory;
|
|
9408
|
+
}
|
|
9409
|
+
static async create(pairedRoot, relativeWorkingDirectory) {
|
|
9410
|
+
const root = await (0, import_promises12.realpath)((0, import_node_path9.resolve)(pairedRoot));
|
|
9411
|
+
const requested = resolveWithin(root, relativeWorkingDirectory);
|
|
9412
|
+
const workingDirectory = await (0, import_promises12.realpath)(requested);
|
|
9413
|
+
assertContained(root, workingDirectory);
|
|
9414
|
+
const stat6 = await (0, import_promises12.lstat)(workingDirectory);
|
|
9415
|
+
if (!stat6.isDirectory())
|
|
9416
|
+
throw new Error("Local file working directory is not a directory");
|
|
9417
|
+
return new _LocalFileSource(root, workingDirectory);
|
|
9418
|
+
}
|
|
9419
|
+
async list(relativeDirectory = ".", cursor, requestedLimit = defaultPageSize) {
|
|
9420
|
+
const limit = clampLimit(requestedLimit);
|
|
9421
|
+
const directory = await this.resolveDirectory(relativeDirectory);
|
|
9422
|
+
const matcher = await this.ignoreMatcher(directory);
|
|
9423
|
+
const candidates2 = await Promise.all((await (0, import_promises12.readdir)(directory, { withFileTypes: true })).map(async (entry) => {
|
|
9424
|
+
if (entry.name.includes("\\"))
|
|
9425
|
+
return void 0;
|
|
9426
|
+
const absolute = (0, import_node_path9.join)(directory, entry.name);
|
|
9427
|
+
const path4 = portable((0, import_node_path9.relative)(this.workingDirectory, absolute));
|
|
9428
|
+
const rootPath = portable((0, import_node_path9.relative)(this.pairedRoot, absolute));
|
|
9429
|
+
if (matcher.ignores(rootPath) || isGitPath(rootPath))
|
|
9430
|
+
return void 0;
|
|
9431
|
+
if (entry.isDirectory())
|
|
9432
|
+
return { kind: "directory", name: entry.name, path: path4 };
|
|
9433
|
+
if (!entry.isFile())
|
|
9434
|
+
return void 0;
|
|
9435
|
+
const stat6 = await (0, import_promises12.lstat)(absolute);
|
|
9436
|
+
return { kind: "file", name: entry.name, path: path4, size: stat6.size };
|
|
9437
|
+
}));
|
|
9438
|
+
const entries = candidates2.filter((entry) => entry !== void 0).sort(compareEntries);
|
|
9439
|
+
return page(entries, cursor, limit);
|
|
9440
|
+
}
|
|
9441
|
+
async search(query, cursor, requestedLimit = defaultPageSize) {
|
|
9442
|
+
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
9443
|
+
const limit = clampLimit(requestedLimit);
|
|
9444
|
+
const matches = [];
|
|
9445
|
+
const pending = [this.workingDirectory];
|
|
9446
|
+
let scanned = 0;
|
|
9447
|
+
while (pending.length > 0 && scanned < searchScanBudget) {
|
|
9448
|
+
const directory = pending.shift();
|
|
9449
|
+
if (directory === void 0)
|
|
9450
|
+
break;
|
|
9451
|
+
const matcher = await this.ignoreMatcher(directory);
|
|
9452
|
+
for (const entry of await (0, import_promises12.readdir)(directory, { withFileTypes: true })) {
|
|
9453
|
+
scanned += 1;
|
|
9454
|
+
if (scanned > searchScanBudget)
|
|
9455
|
+
break;
|
|
9456
|
+
if (entry.name.includes("\\"))
|
|
9457
|
+
continue;
|
|
9458
|
+
const absolute = (0, import_node_path9.join)(directory, entry.name);
|
|
9459
|
+
const path4 = portable((0, import_node_path9.relative)(this.workingDirectory, absolute));
|
|
9460
|
+
const rootPath = portable((0, import_node_path9.relative)(this.pairedRoot, absolute));
|
|
9461
|
+
if (matcher.ignores(rootPath) || isGitPath(rootPath))
|
|
9462
|
+
continue;
|
|
9463
|
+
if (entry.isDirectory()) {
|
|
9464
|
+
pending.push(absolute);
|
|
9465
|
+
continue;
|
|
9466
|
+
}
|
|
9467
|
+
if (!entry.isFile())
|
|
9468
|
+
continue;
|
|
9469
|
+
if (normalizedQuery === "" || path4.toLocaleLowerCase().includes(normalizedQuery)) {
|
|
9470
|
+
const stat6 = await (0, import_promises12.lstat)(absolute);
|
|
9471
|
+
matches.push({ kind: "file", name: entry.name, path: path4, size: stat6.size });
|
|
9472
|
+
}
|
|
9473
|
+
}
|
|
9474
|
+
}
|
|
9475
|
+
matches.sort((left, right) => left.path.localeCompare(right.path, void 0, { numeric: true }));
|
|
9476
|
+
const result = page(matches, cursor, limit);
|
|
9477
|
+
return { ...result, truncated: result.truncated || scanned >= searchScanBudget };
|
|
9478
|
+
}
|
|
9479
|
+
async read(path4) {
|
|
9480
|
+
const file = await this.resolveFile(path4);
|
|
9481
|
+
const stat6 = await (0, import_promises12.lstat)(file);
|
|
9482
|
+
if (stat6.size > maximumReadBytes)
|
|
9483
|
+
throw new Error("Local file exceeds the preview size limit");
|
|
9484
|
+
const buffer2 = await (0, import_promises12.readFile)(file);
|
|
9485
|
+
const binary = buffer2.includes(0) || !isUtf8(buffer2);
|
|
9486
|
+
return {
|
|
9487
|
+
content: binary ? buffer2.toString("base64") : buffer2.toString("utf8"),
|
|
9488
|
+
encoding: binary ? "base64" : "utf8",
|
|
9489
|
+
name: (0, import_node_path9.basename)(file),
|
|
9490
|
+
path: portable((0, import_node_path9.relative)(this.workingDirectory, file)),
|
|
9491
|
+
size: stat6.size
|
|
9492
|
+
};
|
|
9493
|
+
}
|
|
9494
|
+
async validate(path4, kind = "file") {
|
|
9495
|
+
const target = kind === "directory" ? await this.resolveDirectory(path4) : await this.resolveFile(path4);
|
|
9496
|
+
const stat6 = await (0, import_promises12.lstat)(target);
|
|
9497
|
+
return {
|
|
9498
|
+
kind,
|
|
9499
|
+
name: (0, import_node_path9.basename)(target),
|
|
9500
|
+
path: portable((0, import_node_path9.relative)(this.workingDirectory, target)),
|
|
9501
|
+
...kind === "file" ? { size: stat6.size } : {}
|
|
9502
|
+
};
|
|
9503
|
+
}
|
|
9504
|
+
async resolveDirectory(path4) {
|
|
9505
|
+
const absolute = resolveWithin(this.workingDirectory, path4);
|
|
9506
|
+
const directStat = await (0, import_promises12.lstat)(absolute);
|
|
9507
|
+
if (directStat.isSymbolicLink() || !directStat.isDirectory()) {
|
|
9508
|
+
throw new Error("Local file path is not a regular directory");
|
|
9509
|
+
}
|
|
9510
|
+
const canonical = await (0, import_promises12.realpath)(absolute);
|
|
9511
|
+
assertContained(this.workingDirectory, canonical);
|
|
9512
|
+
await this.assertVisible(canonical);
|
|
9513
|
+
return canonical;
|
|
9514
|
+
}
|
|
9515
|
+
async resolveFile(path4) {
|
|
9516
|
+
const absolute = resolveWithin(this.workingDirectory, path4);
|
|
9517
|
+
const directStat = await (0, import_promises12.lstat)(absolute);
|
|
9518
|
+
if (directStat.isSymbolicLink() || !directStat.isFile())
|
|
9519
|
+
throw new Error("Local file path is not a regular file");
|
|
9520
|
+
const canonical = await (0, import_promises12.realpath)(absolute);
|
|
9521
|
+
assertContained(this.workingDirectory, canonical);
|
|
9522
|
+
await this.assertVisible(canonical);
|
|
9523
|
+
return canonical;
|
|
9524
|
+
}
|
|
9525
|
+
async assertVisible(absolute) {
|
|
9526
|
+
const rootPath = portable((0, import_node_path9.relative)(this.pairedRoot, absolute));
|
|
9527
|
+
if (rootPath === ".")
|
|
9528
|
+
return;
|
|
9529
|
+
if (isGitPath(rootPath) || (await this.ignoreMatcher((0, import_node_path9.dirname)(absolute))).ignores(rootPath)) {
|
|
9530
|
+
throw new Error("Local file path is ignored");
|
|
9531
|
+
}
|
|
9532
|
+
}
|
|
9533
|
+
async ignoreMatcher(throughDirectory) {
|
|
9534
|
+
const matchers = [{ base: "", matcher: (0, import_ignore.default)().add(".git/").add(".git/**") }];
|
|
9535
|
+
const relativeThrough = (0, import_node_path9.relative)(this.pairedRoot, throughDirectory);
|
|
9536
|
+
const segments = relativeThrough === "" ? [] : relativeThrough.split(import_node_path9.sep);
|
|
9537
|
+
let directory = this.pairedRoot;
|
|
9538
|
+
for (let index2 = 0; index2 <= segments.length; index2 += 1) {
|
|
9539
|
+
const matcher = (0, import_ignore.default)();
|
|
9540
|
+
for (const name of [".gitignore", ".ignore"]) {
|
|
9541
|
+
try {
|
|
9542
|
+
const content3 = await (0, import_promises12.readFile)((0, import_node_path9.join)(directory, name), "utf8");
|
|
9543
|
+
matcher.add(content3);
|
|
9544
|
+
} catch (error) {
|
|
9545
|
+
if (!isMissing(error))
|
|
9546
|
+
throw error;
|
|
9547
|
+
}
|
|
9548
|
+
}
|
|
9549
|
+
matchers.push({ base: portable((0, import_node_path9.relative)(this.pairedRoot, directory)), matcher });
|
|
9550
|
+
const segment = segments[index2];
|
|
9551
|
+
if (segment !== void 0)
|
|
9552
|
+
directory = (0, import_node_path9.join)(directory, segment);
|
|
9553
|
+
}
|
|
9554
|
+
return new ScopedIgnoreMatcher(matchers);
|
|
9555
|
+
}
|
|
9556
|
+
};
|
|
9557
|
+
ScopedIgnoreMatcher = class {
|
|
9558
|
+
rules;
|
|
9559
|
+
constructor(rules) {
|
|
9560
|
+
this.rules = rules;
|
|
9561
|
+
}
|
|
9562
|
+
ignores(rootPath) {
|
|
9563
|
+
let ignored = false;
|
|
9564
|
+
for (const rule of this.rules) {
|
|
9565
|
+
const localPath = relativePortable(rule.base, rootPath);
|
|
9566
|
+
if (localPath === void 0 || localPath === ".")
|
|
9567
|
+
continue;
|
|
9568
|
+
const result = rule.matcher.test(localPath);
|
|
9569
|
+
if (result.ignored)
|
|
9570
|
+
ignored = true;
|
|
9571
|
+
if (result.unignored)
|
|
9572
|
+
ignored = false;
|
|
9573
|
+
}
|
|
9574
|
+
return ignored;
|
|
9575
|
+
}
|
|
9576
|
+
};
|
|
9577
|
+
}
|
|
9578
|
+
});
|
|
9579
|
+
|
|
9580
|
+
// ../machine-connector/dist/runtime/local-codex-runtime/discovery-worker.js
|
|
9581
|
+
async function executeLocalFileDiscovery(pairedRoot, request2) {
|
|
9582
|
+
if (request2.kind !== LocalCodexDiscoveryKindWire.LocalFileList && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileSearch && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileRead && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileValidate) {
|
|
9583
|
+
throw new Error(`Unsupported Local file discovery kind ${request2.kind}`);
|
|
9584
|
+
}
|
|
9585
|
+
const source = await LocalFileSource.create(pairedRoot, request2.workingDirectory ?? ".");
|
|
9586
|
+
if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileList) {
|
|
9587
|
+
const page2 = await source.list(request2.relativeDirectory ?? ".", request2.cursor, request2.limit);
|
|
9588
|
+
return {
|
|
9589
|
+
...page2,
|
|
9590
|
+
requestId: request2.requestId,
|
|
9591
|
+
status: LocalCodexDiscoveryStatusWire.Succeeded
|
|
9592
|
+
};
|
|
9593
|
+
}
|
|
9594
|
+
if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileSearch) {
|
|
9595
|
+
const page2 = await source.search(request2.query ?? "", request2.cursor, request2.limit);
|
|
9596
|
+
return {
|
|
9597
|
+
...page2,
|
|
9598
|
+
requestId: request2.requestId,
|
|
9599
|
+
status: LocalCodexDiscoveryStatusWire.Succeeded
|
|
9600
|
+
};
|
|
9601
|
+
}
|
|
9602
|
+
if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileValidate) {
|
|
9603
|
+
return {
|
|
9604
|
+
entries: [
|
|
9605
|
+
await source.validate(request2.filePath ?? "", request2.fileKind ?? "file")
|
|
9606
|
+
],
|
|
9607
|
+
requestId: request2.requestId,
|
|
9608
|
+
status: LocalCodexDiscoveryStatusWire.Succeeded
|
|
9609
|
+
};
|
|
9610
|
+
}
|
|
9611
|
+
const content3 = await source.read(request2.filePath ?? "");
|
|
9612
|
+
return {
|
|
9613
|
+
content: content3.content,
|
|
9614
|
+
encoding: content3.encoding,
|
|
9615
|
+
entries: [
|
|
9616
|
+
{
|
|
9617
|
+
kind: "file",
|
|
9618
|
+
name: content3.name,
|
|
9619
|
+
path: content3.path,
|
|
9620
|
+
size: content3.size
|
|
9621
|
+
}
|
|
9622
|
+
],
|
|
9623
|
+
requestId: request2.requestId,
|
|
9624
|
+
status: LocalCodexDiscoveryStatusWire.Succeeded
|
|
9625
|
+
};
|
|
9626
|
+
}
|
|
9627
|
+
async function waitForAbort(signal, milliseconds) {
|
|
9628
|
+
if (signal.aborted) {
|
|
9629
|
+
return;
|
|
9630
|
+
}
|
|
9631
|
+
await new Promise((resolvePromise) => {
|
|
9632
|
+
const complete = () => {
|
|
9633
|
+
clearTimeout(timeout);
|
|
9634
|
+
signal.removeEventListener("abort", complete);
|
|
9635
|
+
resolvePromise();
|
|
9636
|
+
};
|
|
9637
|
+
const timeout = setTimeout(complete, milliseconds);
|
|
9638
|
+
timeout.unref();
|
|
9639
|
+
signal.addEventListener("abort", complete, { once: true });
|
|
9640
|
+
});
|
|
9641
|
+
}
|
|
9642
|
+
var discoveryWaitSeconds, defaultNetworkRetryMilliseconds, maximumNetworkRetryMilliseconds, LocalCodexDiscoveryWorker;
|
|
9643
|
+
var init_discovery_worker = __esm({
|
|
9644
|
+
"../machine-connector/dist/runtime/local-codex-runtime/discovery-worker.js"() {
|
|
9645
|
+
"use strict";
|
|
9646
|
+
init_cjs_shims();
|
|
9647
|
+
init_retry_backoff();
|
|
9648
|
+
init_contracts2();
|
|
9649
|
+
init_local_file_source();
|
|
9650
|
+
discoveryWaitSeconds = 25;
|
|
9651
|
+
defaultNetworkRetryMilliseconds = 2e3;
|
|
9652
|
+
maximumNetworkRetryMilliseconds = 6e4;
|
|
9653
|
+
LocalCodexDiscoveryWorker = class {
|
|
9654
|
+
params;
|
|
9655
|
+
lifetimeAbort = new AbortController();
|
|
9656
|
+
running;
|
|
9657
|
+
constructor(params) {
|
|
9658
|
+
this.params = params;
|
|
9659
|
+
}
|
|
9660
|
+
async run() {
|
|
9661
|
+
if (this.running !== void 0) {
|
|
9662
|
+
return await this.running;
|
|
9663
|
+
}
|
|
9664
|
+
this.running = this.runLoop();
|
|
9665
|
+
return await this.running;
|
|
9666
|
+
}
|
|
9667
|
+
async stop() {
|
|
9668
|
+
this.revoke();
|
|
9669
|
+
await this.running;
|
|
9670
|
+
}
|
|
9671
|
+
revoke() {
|
|
9672
|
+
this.lifetimeAbort.abort();
|
|
9673
|
+
}
|
|
9674
|
+
async runLoop() {
|
|
9675
|
+
const retryBackoff = new RetryBackoff({
|
|
9676
|
+
maximumMilliseconds: maximumNetworkRetryMilliseconds,
|
|
9677
|
+
minimumMilliseconds: this.params.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds,
|
|
9678
|
+
random: this.params.random
|
|
9679
|
+
});
|
|
9680
|
+
while (!this.lifetimeAbort.signal.aborted && !this.params.relay.isRevoked()) {
|
|
9681
|
+
try {
|
|
9682
|
+
const response = await this.params.relay.claimCodexRuntimeDiscovery({
|
|
9683
|
+
connectorInstanceId: this.params.connectorInstanceId,
|
|
9684
|
+
protocolVersion: localCodexRuntimeProtocolVersion,
|
|
9685
|
+
waitSeconds: discoveryWaitSeconds
|
|
9686
|
+
}, this.lifetimeAbort.signal);
|
|
9687
|
+
if (response.request !== void 0) {
|
|
9688
|
+
await this.complete(response.request);
|
|
9689
|
+
}
|
|
9690
|
+
retryBackoff.reset();
|
|
9691
|
+
} catch (error) {
|
|
9692
|
+
if (this.lifetimeAbort.signal.aborted || this.params.relay.isRevoked()) {
|
|
9693
|
+
return;
|
|
9694
|
+
}
|
|
9695
|
+
await this.params.logger.error(`Local Codex discovery loop failed for connection ${this.params.connectionId}`, error);
|
|
9696
|
+
await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
|
|
9697
|
+
}
|
|
9698
|
+
}
|
|
9699
|
+
}
|
|
9700
|
+
async complete(request2) {
|
|
9701
|
+
let result;
|
|
9702
|
+
try {
|
|
9703
|
+
result = await this.params.execute(request2);
|
|
9704
|
+
} catch (error) {
|
|
9705
|
+
await this.params.logger.error(`Local Codex ${request2.kind} discovery failed for connection ${this.params.connectionId}`, error);
|
|
9706
|
+
result = {
|
|
9707
|
+
errorCode: this.params.failureErrorCode(request2),
|
|
9708
|
+
requestId: request2.requestId,
|
|
9709
|
+
status: LocalCodexDiscoveryStatusWire.Failed
|
|
9710
|
+
};
|
|
9711
|
+
}
|
|
9712
|
+
const completion = await this.params.relay.completeCodexRuntimeDiscovery(request2.requestId, this.params.connectorInstanceId, result, this.lifetimeAbort.signal);
|
|
9713
|
+
if (!completion.accepted) {
|
|
9714
|
+
await this.params.logger.info(`Local Codex discovery request ${request2.requestId} expired before completion`);
|
|
9715
|
+
}
|
|
9716
|
+
}
|
|
9717
|
+
};
|
|
9718
|
+
}
|
|
9719
|
+
});
|
|
9720
|
+
|
|
8874
9721
|
// ../machine-connector/dist/runtime/local-codex-runtime/durable-attempt.js
|
|
8875
9722
|
function assertCompatibleClaim(persisted, connectionId, claim, allowRestartFenceRotation) {
|
|
8876
9723
|
if (persisted.connectionId !== connectionId || persisted.claim.attemptId !== claim.attemptId || persisted.claim.attemptGeneration !== claim.attemptGeneration || persisted.claim.conversationId !== claim.conversationId || persisted.claim.turnId !== claim.turnId || persisted.claim.expectedNativeStoreIdentity !== claim.expectedNativeStoreIdentity) {
|
|
@@ -9353,10 +10200,10 @@ function redactPath(value, canonicalRoot) {
|
|
|
9353
10200
|
if (value === canonicalRoot) {
|
|
9354
10201
|
return ".";
|
|
9355
10202
|
}
|
|
9356
|
-
if (value.startsWith(`${canonicalRoot}${
|
|
9357
|
-
return (0,
|
|
10203
|
+
if (value.startsWith(`${canonicalRoot}${import_node_path10.sep}`)) {
|
|
10204
|
+
return (0, import_node_path10.relative)(canonicalRoot, value);
|
|
9358
10205
|
}
|
|
9359
|
-
if ((0,
|
|
10206
|
+
if ((0, import_node_path10.isAbsolute)(value) || /^[A-Za-z]:[\\/]/.test(value)) {
|
|
9360
10207
|
return "[redacted-absolute-path]";
|
|
9361
10208
|
}
|
|
9362
10209
|
return value;
|
|
@@ -9405,12 +10252,12 @@ function recordValue(value) {
|
|
|
9405
10252
|
function isRecord2(value) {
|
|
9406
10253
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9407
10254
|
}
|
|
9408
|
-
var
|
|
10255
|
+
var import_node_path10;
|
|
9409
10256
|
var init_event_normalizer = __esm({
|
|
9410
10257
|
"../machine-connector/dist/runtime/local-codex-runtime/event-normalizer.js"() {
|
|
9411
10258
|
"use strict";
|
|
9412
10259
|
init_cjs_shims();
|
|
9413
|
-
|
|
10260
|
+
import_node_path10 = require("path");
|
|
9414
10261
|
init_contracts2();
|
|
9415
10262
|
}
|
|
9416
10263
|
});
|
|
@@ -9427,12 +10274,12 @@ function isInactiveTurnInterruptResponse(error) {
|
|
|
9427
10274
|
}
|
|
9428
10275
|
function createActiveAttempt(claim, durable, workingDirectory) {
|
|
9429
10276
|
let resolveTerminal = (_value) => void 0;
|
|
9430
|
-
const terminal = new Promise((
|
|
9431
|
-
resolveTerminal =
|
|
10277
|
+
const terminal = new Promise((resolve11) => {
|
|
10278
|
+
resolveTerminal = resolve11;
|
|
9432
10279
|
});
|
|
9433
10280
|
let resolveFatal = (_error) => void 0;
|
|
9434
|
-
const fatal = new Promise((
|
|
9435
|
-
resolveFatal =
|
|
10281
|
+
const fatal = new Promise((resolve11) => {
|
|
10282
|
+
resolveFatal = resolve11;
|
|
9436
10283
|
});
|
|
9437
10284
|
return {
|
|
9438
10285
|
acceptedByAppServer: false,
|
|
@@ -9461,8 +10308,8 @@ function createActiveAttempt(claim, durable, workingDirectory) {
|
|
|
9461
10308
|
}
|
|
9462
10309
|
function createThreadTitleGenerationState(threadId) {
|
|
9463
10310
|
let resolveCompletion = () => void 0;
|
|
9464
|
-
const completion = new Promise((
|
|
9465
|
-
resolveCompletion =
|
|
10311
|
+
const completion = new Promise((resolve11) => {
|
|
10312
|
+
resolveCompletion = resolve11;
|
|
9466
10313
|
});
|
|
9467
10314
|
const state = {
|
|
9468
10315
|
completed: false,
|
|
@@ -9636,8 +10483,9 @@ function requireTurnId2(response) {
|
|
|
9636
10483
|
}
|
|
9637
10484
|
return id;
|
|
9638
10485
|
}
|
|
9639
|
-
function toCodexInput(items) {
|
|
9640
|
-
|
|
10486
|
+
async function toCodexInput(items, pairedRoot, relativeWorkingDirectory) {
|
|
10487
|
+
const source = await LocalFileSource.create(pairedRoot, relativeWorkingDirectory);
|
|
10488
|
+
return await Promise.all(items.map(async (item) => {
|
|
9641
10489
|
const payload = safeRecord2(item.payload);
|
|
9642
10490
|
if (item.itemType === "text") {
|
|
9643
10491
|
return {
|
|
@@ -9658,8 +10506,20 @@ function toCodexInput(items) {
|
|
|
9658
10506
|
path: optionalString3(payload.path).value ?? ""
|
|
9659
10507
|
};
|
|
9660
10508
|
}
|
|
10509
|
+
if (item.itemType === "local_file") {
|
|
10510
|
+
const path4 = optionalString3(payload.path).value;
|
|
10511
|
+
if (path4 === void 0)
|
|
10512
|
+
throw new Error("Local file input has no path");
|
|
10513
|
+
const kind = payload.kind === "directory" ? "directory" : "file";
|
|
10514
|
+
await source.validate(path4, kind);
|
|
10515
|
+
return {
|
|
10516
|
+
type: "text",
|
|
10517
|
+
text: `@${path4}${kind === "directory" && !path4.endsWith("/") ? "/" : ""}`,
|
|
10518
|
+
text_elements: []
|
|
10519
|
+
};
|
|
10520
|
+
}
|
|
9661
10521
|
throw new Error(`Unsupported Local Codex input ${item.itemType}`);
|
|
9662
|
-
});
|
|
10522
|
+
}));
|
|
9663
10523
|
}
|
|
9664
10524
|
function localCodexInputItems(value) {
|
|
9665
10525
|
if (!Array.isArray(value)) {
|
|
@@ -9814,7 +10674,7 @@ async function probeExecutable(executable, environment) {
|
|
|
9814
10674
|
const output = [];
|
|
9815
10675
|
child.stdout?.on("data", (chunk) => output.push(chunk));
|
|
9816
10676
|
try {
|
|
9817
|
-
const code = await new Promise((
|
|
10677
|
+
const code = await new Promise((resolve11, reject) => {
|
|
9818
10678
|
const timeout = setTimeout(() => {
|
|
9819
10679
|
child.kill("SIGTERM");
|
|
9820
10680
|
reject(new Error("Executable probe timed out"));
|
|
@@ -9826,7 +10686,7 @@ async function probeExecutable(executable, environment) {
|
|
|
9826
10686
|
});
|
|
9827
10687
|
child.once("close", (exitCode) => {
|
|
9828
10688
|
clearTimeout(timeout);
|
|
9829
|
-
|
|
10689
|
+
resolve11(exitCode ?? 1);
|
|
9830
10690
|
});
|
|
9831
10691
|
});
|
|
9832
10692
|
if (code !== 0) {
|
|
@@ -9843,15 +10703,15 @@ async function probeExecutable(executable, environment) {
|
|
|
9843
10703
|
};
|
|
9844
10704
|
}
|
|
9845
10705
|
}
|
|
9846
|
-
async function
|
|
10706
|
+
async function waitForAbort2(signal, milliseconds) {
|
|
9847
10707
|
if (signal.aborted) {
|
|
9848
10708
|
return;
|
|
9849
10709
|
}
|
|
9850
|
-
await new Promise((
|
|
10710
|
+
await new Promise((resolve11) => {
|
|
9851
10711
|
const complete = () => {
|
|
9852
10712
|
clearTimeout(timeout);
|
|
9853
10713
|
signal.removeEventListener("abort", complete);
|
|
9854
|
-
|
|
10714
|
+
resolve11();
|
|
9855
10715
|
};
|
|
9856
10716
|
const timeout = setTimeout(complete, milliseconds);
|
|
9857
10717
|
timeout.unref();
|
|
@@ -9894,26 +10754,27 @@ function parseLeaseDeadline(value) {
|
|
|
9894
10754
|
function routineLeaseRenewalDelayMilliseconds(remainingLeaseMilliseconds) {
|
|
9895
10755
|
return Math.min(leaseRenewIntervalMilliseconds, Math.max(1, Math.floor(remainingLeaseMilliseconds / leaseRenewalIntervalsBeforeDeadline)));
|
|
9896
10756
|
}
|
|
9897
|
-
var import_node_child_process4,
|
|
10757
|
+
var import_node_child_process4, import_promises13, import_node_os7, import_node_path11, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewalIntervalsBeforeDeadline, defaultNetworkRetryMilliseconds2, maximumNetworkRetryMilliseconds2, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryScanIntervalMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, maximumThreadTitleCharacters, maximumThreadTitleSourceCharacters, threadTitleGenerationTimeoutMilliseconds, interruptedExecutionCleanupTimeoutMilliseconds, threadTitleGenerationInstructions, threadTitleGenerationOutputSchema, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, WorkerStoppedError, LocalCodexRuntimeConnectionWorker;
|
|
9898
10758
|
var init_runtime_worker = __esm({
|
|
9899
10759
|
"../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
|
|
9900
10760
|
"use strict";
|
|
9901
10761
|
init_cjs_shims();
|
|
9902
10762
|
import_node_child_process4 = require("child_process");
|
|
9903
|
-
|
|
10763
|
+
import_promises13 = require("fs/promises");
|
|
9904
10764
|
import_node_os7 = require("os");
|
|
9905
|
-
|
|
10765
|
+
import_node_path11 = require("path");
|
|
9906
10766
|
init_process_executor();
|
|
9907
10767
|
init_relay_client();
|
|
9908
10768
|
init_retry_backoff();
|
|
9909
10769
|
init_app_server_client();
|
|
9910
10770
|
init_contracts2();
|
|
10771
|
+
init_local_file_source();
|
|
10772
|
+
init_discovery_worker();
|
|
9911
10773
|
init_durable_attempt();
|
|
9912
10774
|
init_event_normalizer();
|
|
9913
10775
|
heartbeatIntervalMilliseconds = 2e4;
|
|
9914
10776
|
claimRetryMilliseconds = 250;
|
|
9915
10777
|
claimWaitSeconds = 25;
|
|
9916
|
-
discoveryWaitSeconds = 25;
|
|
9917
10778
|
maximumDiscoveryDirectories = 1e3;
|
|
9918
10779
|
maximumDiscoveryModels = 100;
|
|
9919
10780
|
maximumModelListPages = 10;
|
|
@@ -9922,8 +10783,8 @@ var init_runtime_worker = __esm({
|
|
|
9922
10783
|
preferredEventUploadRequestBytes = 96e3;
|
|
9923
10784
|
leaseRenewIntervalMilliseconds = 1e4;
|
|
9924
10785
|
leaseRenewalIntervalsBeforeDeadline = 3;
|
|
9925
|
-
|
|
9926
|
-
|
|
10786
|
+
defaultNetworkRetryMilliseconds2 = 1e3;
|
|
10787
|
+
maximumNetworkRetryMilliseconds2 = 6e4;
|
|
9927
10788
|
interactionTimeoutMilliseconds = 10 * 60 * 1e3;
|
|
9928
10789
|
executableProbeTimeoutMilliseconds = 5e3;
|
|
9929
10790
|
recoveryScanIntervalMilliseconds = 1e3;
|
|
@@ -9989,6 +10850,7 @@ var init_runtime_worker = __esm({
|
|
|
9989
10850
|
configured = false;
|
|
9990
10851
|
enabled = false;
|
|
9991
10852
|
executionTasks = /* @__PURE__ */ new Map();
|
|
10853
|
+
discoveryWorker;
|
|
9992
10854
|
lastCapabilityStartError;
|
|
9993
10855
|
lifetimeAbort = new AbortController();
|
|
9994
10856
|
networkRetryMilliseconds;
|
|
@@ -10004,8 +10866,18 @@ var init_runtime_worker = __esm({
|
|
|
10004
10866
|
this.environment = environment;
|
|
10005
10867
|
this.connectorInstanceId = connectorInstanceId;
|
|
10006
10868
|
this.logger = logger;
|
|
10007
|
-
this.networkRetryMilliseconds = options.networkRetryMilliseconds ??
|
|
10869
|
+
this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds2;
|
|
10008
10870
|
this.random = options.random ?? Math.random;
|
|
10871
|
+
this.discoveryWorker = new LocalCodexDiscoveryWorker({
|
|
10872
|
+
connectionId: connection.connectionId,
|
|
10873
|
+
connectorInstanceId,
|
|
10874
|
+
execute: async (request2) => await this.executeDiscovery(request2),
|
|
10875
|
+
failureErrorCode: (request2) => request2.kind === LocalCodexDiscoveryKindWire.ModelList ? "model_discovery_failed" : "directory_unavailable",
|
|
10876
|
+
logger,
|
|
10877
|
+
networkRetryMilliseconds: this.networkRetryMilliseconds,
|
|
10878
|
+
random: this.random,
|
|
10879
|
+
relay
|
|
10880
|
+
});
|
|
10009
10881
|
this.processPool.register(connection.connectionId, this);
|
|
10010
10882
|
}
|
|
10011
10883
|
async run() {
|
|
@@ -10021,6 +10893,7 @@ var init_runtime_worker = __esm({
|
|
|
10021
10893
|
}
|
|
10022
10894
|
revoke() {
|
|
10023
10895
|
this.lifetimeAbort.abort();
|
|
10896
|
+
this.discoveryWorker.revoke();
|
|
10024
10897
|
for (const active of this.activeAttempts.values()) {
|
|
10025
10898
|
active.finished.abort();
|
|
10026
10899
|
}
|
|
@@ -10318,7 +11191,7 @@ var init_runtime_worker = __esm({
|
|
|
10318
11191
|
try {
|
|
10319
11192
|
await Promise.all([
|
|
10320
11193
|
this.runHeartbeatLoop(),
|
|
10321
|
-
this.
|
|
11194
|
+
this.discoveryWorker.run(),
|
|
10322
11195
|
this.runAttemptLoops()
|
|
10323
11196
|
]);
|
|
10324
11197
|
} finally {
|
|
@@ -10336,7 +11209,7 @@ var init_runtime_worker = __esm({
|
|
|
10336
11209
|
async runHeartbeatLoop() {
|
|
10337
11210
|
while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
|
|
10338
11211
|
if ([...this.activeAttempts.values()].some((active) => active.interruptedCleanupStarted)) {
|
|
10339
|
-
await
|
|
11212
|
+
await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
|
|
10340
11213
|
continue;
|
|
10341
11214
|
}
|
|
10342
11215
|
try {
|
|
@@ -10349,19 +11222,19 @@ var init_runtime_worker = __esm({
|
|
|
10349
11222
|
}
|
|
10350
11223
|
await this.logger.error(`Local Codex Runtime heartbeat failed for connection ${this.connection.connectionId}`, error);
|
|
10351
11224
|
}
|
|
10352
|
-
await
|
|
11225
|
+
await waitForAbort2(this.lifetimeAbort.signal, heartbeatIntervalMilliseconds);
|
|
10353
11226
|
}
|
|
10354
11227
|
}
|
|
10355
11228
|
async runClaimLoop() {
|
|
10356
11229
|
const retryBackoff = this.createNetworkRetryBackoff();
|
|
10357
11230
|
while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
|
|
10358
11231
|
if (!this.configured || !this.enabled || !this.runtimeReady()) {
|
|
10359
|
-
await
|
|
11232
|
+
await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
|
|
10360
11233
|
continue;
|
|
10361
11234
|
}
|
|
10362
11235
|
const slot = this.processPool.tryAcquireExecutionSlot(this.connection.connectionId).value;
|
|
10363
11236
|
if (slot === void 0) {
|
|
10364
|
-
await
|
|
11237
|
+
await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
|
|
10365
11238
|
continue;
|
|
10366
11239
|
}
|
|
10367
11240
|
let executionScheduled = false;
|
|
@@ -10384,14 +11257,14 @@ var init_runtime_worker = __esm({
|
|
|
10384
11257
|
if (reclaimableClaimWindow.isAccepted()) {
|
|
10385
11258
|
retryBackoff.reset();
|
|
10386
11259
|
} else {
|
|
10387
|
-
await
|
|
11260
|
+
await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
|
|
10388
11261
|
}
|
|
10389
11262
|
} catch (error) {
|
|
10390
11263
|
if (this.lifetimeAbort.signal.aborted || this.relay.isRevoked()) {
|
|
10391
11264
|
return;
|
|
10392
11265
|
}
|
|
10393
11266
|
await this.logger.error(`Local Codex Runtime claim loop failed for connection ${this.connection.connectionId}`, error);
|
|
10394
|
-
await
|
|
11267
|
+
await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
|
|
10395
11268
|
} finally {
|
|
10396
11269
|
if (!executionScheduled) {
|
|
10397
11270
|
this.processPool.releaseExecutionSlot(slot);
|
|
@@ -10413,47 +11286,6 @@ var init_runtime_worker = __esm({
|
|
|
10413
11286
|
this.executionTasks.set(claim.attemptId, task);
|
|
10414
11287
|
return reclaimableClaimWindow;
|
|
10415
11288
|
}
|
|
10416
|
-
async runDiscoveryLoop() {
|
|
10417
|
-
const retryBackoff = this.createNetworkRetryBackoff();
|
|
10418
|
-
while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
|
|
10419
|
-
try {
|
|
10420
|
-
const response = await this.relay.claimCodexRuntimeDiscovery({
|
|
10421
|
-
connectorInstanceId: this.connectorInstanceId,
|
|
10422
|
-
protocolVersion: localCodexRuntimeProtocolVersion,
|
|
10423
|
-
waitSeconds: discoveryWaitSeconds
|
|
10424
|
-
}, this.lifetimeAbort.signal);
|
|
10425
|
-
if (response.request === void 0) {
|
|
10426
|
-
retryBackoff.reset();
|
|
10427
|
-
continue;
|
|
10428
|
-
}
|
|
10429
|
-
await this.completeDiscovery(response.request);
|
|
10430
|
-
retryBackoff.reset();
|
|
10431
|
-
} catch (error) {
|
|
10432
|
-
if (this.lifetimeAbort.signal.aborted || this.relay.isRevoked()) {
|
|
10433
|
-
return;
|
|
10434
|
-
}
|
|
10435
|
-
await this.logger.error(`Local Codex discovery loop failed for connection ${this.connection.connectionId}`, error);
|
|
10436
|
-
await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
|
|
10437
|
-
}
|
|
10438
|
-
}
|
|
10439
|
-
}
|
|
10440
|
-
async completeDiscovery(request2) {
|
|
10441
|
-
let result;
|
|
10442
|
-
try {
|
|
10443
|
-
result = await this.executeDiscovery(request2);
|
|
10444
|
-
} catch (error) {
|
|
10445
|
-
await this.logger.error(`Local Codex ${request2.kind} discovery failed for connection ${this.connection.connectionId}`, error);
|
|
10446
|
-
result = {
|
|
10447
|
-
errorCode: request2.kind === LocalCodexDiscoveryKindWire.ModelList ? "model_discovery_failed" : "directory_unavailable",
|
|
10448
|
-
requestId: request2.requestId,
|
|
10449
|
-
status: LocalCodexDiscoveryStatusWire.Failed
|
|
10450
|
-
};
|
|
10451
|
-
}
|
|
10452
|
-
const completion = await this.relay.completeCodexRuntimeDiscovery(request2.requestId, this.connectorInstanceId, result, this.lifetimeAbort.signal);
|
|
10453
|
-
if (!completion.accepted) {
|
|
10454
|
-
await this.logger.info(`Local Codex discovery request ${request2.requestId} expired before completion`);
|
|
10455
|
-
}
|
|
10456
|
-
}
|
|
10457
11289
|
async executeDiscovery(request2) {
|
|
10458
11290
|
if (request2.kind === LocalCodexDiscoveryKindWire.ModelList) {
|
|
10459
11291
|
return {
|
|
@@ -10470,13 +11302,13 @@ var init_runtime_worker = __esm({
|
|
|
10470
11302
|
status: LocalCodexDiscoveryStatusWire.Succeeded
|
|
10471
11303
|
};
|
|
10472
11304
|
}
|
|
10473
|
-
|
|
11305
|
+
return await executeLocalFileDiscovery(this.connection.rootPath, request2);
|
|
10474
11306
|
}
|
|
10475
11307
|
async discoverModels() {
|
|
10476
11308
|
const client = await this.processPool.ensureStarted();
|
|
10477
11309
|
const models = /* @__PURE__ */ new Map();
|
|
10478
11310
|
const cursor = {};
|
|
10479
|
-
for (let
|
|
11311
|
+
for (let page2 = 0; page2 < maximumModelListPages; page2 += 1) {
|
|
10480
11312
|
const response = await client.request("model/list", {
|
|
10481
11313
|
cursor: cursor.value ?? null,
|
|
10482
11314
|
includeHidden: false,
|
|
@@ -10499,7 +11331,7 @@ var init_runtime_worker = __esm({
|
|
|
10499
11331
|
async discoverDirectories(relativeDirectory) {
|
|
10500
11332
|
const canonicalRoot = await resolveCanonicalWorkingDirectory(this.connection.rootPath, ".");
|
|
10501
11333
|
const canonicalDirectory = await resolveCanonicalWorkingDirectory(canonicalRoot, relativeDirectory);
|
|
10502
|
-
const entries = (await (0,
|
|
11334
|
+
const entries = (await (0, import_promises13.readdir)(canonicalDirectory, {
|
|
10503
11335
|
withFileTypes: true
|
|
10504
11336
|
})).filter((entry) => entry.isDirectory()).filter((entry) => !entry.name.includes("\\")).sort((left, right) => left.name.localeCompare(right.name, void 0, {
|
|
10505
11337
|
numeric: true,
|
|
@@ -10507,11 +11339,11 @@ var init_runtime_worker = __esm({
|
|
|
10507
11339
|
}));
|
|
10508
11340
|
const eligibleDirectories = entries.map((entry) => ({
|
|
10509
11341
|
name: entry.name,
|
|
10510
|
-
relativePath: portableRelativeDirectory((0,
|
|
11342
|
+
relativePath: portableRelativeDirectory((0, import_node_path11.relative)(canonicalRoot, (0, import_node_path11.join)(canonicalDirectory, entry.name)))
|
|
10511
11343
|
})).filter((entry) => entry.name.length <= 255 && entry.relativePath.length <= 1024);
|
|
10512
11344
|
const directories = eligibleDirectories.slice(0, maximumDiscoveryDirectories);
|
|
10513
11345
|
return {
|
|
10514
|
-
currentRelativeDirectory: portableRelativeDirectory((0,
|
|
11346
|
+
currentRelativeDirectory: portableRelativeDirectory((0, import_node_path11.relative)(canonicalRoot, canonicalDirectory)),
|
|
10515
11347
|
directories,
|
|
10516
11348
|
truncated: eligibleDirectories.length > maximumDiscoveryDirectories
|
|
10517
11349
|
};
|
|
@@ -10530,6 +11362,7 @@ var init_runtime_worker = __esm({
|
|
|
10530
11362
|
this.activeAttempts.set(claim.attemptId, active);
|
|
10531
11363
|
const leaseLoop = this.runLeaseLoop(active);
|
|
10532
11364
|
const controlLoop = this.runControlLoop(active);
|
|
11365
|
+
let threadLease;
|
|
10533
11366
|
try {
|
|
10534
11367
|
active.workingDirectory = await resolveCanonicalWorkingDirectory(this.connection.rootPath, claim.relativeWorkingDirectory);
|
|
10535
11368
|
if (active.fatalError !== void 0) {
|
|
@@ -10540,17 +11373,17 @@ var init_runtime_worker = __esm({
|
|
|
10540
11373
|
throw active.fatalError;
|
|
10541
11374
|
}
|
|
10542
11375
|
const isNewThread = active.nativeThreadId === void 0;
|
|
10543
|
-
let nativeThreadId;
|
|
10544
11376
|
try {
|
|
10545
|
-
|
|
11377
|
+
threadLease = await this.prepareThread(client, active);
|
|
10546
11378
|
} catch (error) {
|
|
10547
11379
|
if (!(error instanceof AppServerRequestTimeoutError) || error.method !== "thread/resume") {
|
|
10548
11380
|
throw error;
|
|
10549
11381
|
}
|
|
10550
11382
|
await this.processPool.quarantineCurrentProcess();
|
|
10551
11383
|
client = await this.processPool.ensureStarted();
|
|
10552
|
-
|
|
11384
|
+
threadLease = await this.prepareThread(client, active);
|
|
10553
11385
|
}
|
|
11386
|
+
const nativeThreadId = threadLease.threadId;
|
|
10554
11387
|
active.nativeThreadId = nativeThreadId;
|
|
10555
11388
|
active.appServerClient = client;
|
|
10556
11389
|
if (active.fatalError !== void 0) {
|
|
@@ -10577,7 +11410,7 @@ var init_runtime_worker = __esm({
|
|
|
10577
11410
|
approvalPolicy: claim.approvalPolicy,
|
|
10578
11411
|
cwd: active.workingDirectory,
|
|
10579
11412
|
effort: claim.reasoningEffort,
|
|
10580
|
-
input: toCodexInput(claim.inputItems),
|
|
11413
|
+
input: await toCodexInput(claim.inputItems, this.connection.rootPath, claim.relativeWorkingDirectory),
|
|
10581
11414
|
...claim.model === void 0 ? {} : { model: claim.model },
|
|
10582
11415
|
sandboxPolicy: toSandboxPolicy(claim.sandboxPolicy, active.workingDirectory),
|
|
10583
11416
|
summary: "auto",
|
|
@@ -10673,7 +11506,11 @@ var init_runtime_worker = __esm({
|
|
|
10673
11506
|
}
|
|
10674
11507
|
await Promise.all([leaseLoop, controlLoop]);
|
|
10675
11508
|
} finally {
|
|
10676
|
-
|
|
11509
|
+
try {
|
|
11510
|
+
await threadLease?.release();
|
|
11511
|
+
} finally {
|
|
11512
|
+
this.activeAttempts.delete(claim.attemptId);
|
|
11513
|
+
}
|
|
10677
11514
|
}
|
|
10678
11515
|
}
|
|
10679
11516
|
}
|
|
@@ -10691,30 +11528,21 @@ var init_runtime_worker = __esm({
|
|
|
10691
11528
|
sandbox: claim.sandboxPolicy
|
|
10692
11529
|
};
|
|
10693
11530
|
const preparedThreadId = active.nativeThreadId;
|
|
10694
|
-
if (preparedThreadId === void 0) {
|
|
10695
|
-
const startedThreadId = requireThreadId2(await client.request("thread/start", parameters));
|
|
10696
|
-
this.processPool.rememberThreadLoaded(startedThreadId);
|
|
10697
|
-
return startedThreadId;
|
|
10698
|
-
}
|
|
10699
|
-
if (this.processPool.isThreadLoaded(preparedThreadId)) {
|
|
10700
|
-
return preparedThreadId;
|
|
10701
|
-
}
|
|
10702
11531
|
try {
|
|
10703
|
-
|
|
10704
|
-
|
|
10705
|
-
|
|
11532
|
+
return await this.processPool.acquireThread(client, preparedThreadId, async () => {
|
|
11533
|
+
if (preparedThreadId === void 0) {
|
|
11534
|
+
return requireThreadId2(await client.request("thread/start", parameters));
|
|
11535
|
+
}
|
|
11536
|
+
return requireThreadId2(await client.request("thread/resume", {
|
|
11537
|
+
...parameters,
|
|
11538
|
+
threadId: preparedThreadId
|
|
11539
|
+
}));
|
|
10706
11540
|
});
|
|
10707
|
-
const resumedId = requireThreadId2(resumed);
|
|
10708
|
-
if (resumedId !== preparedThreadId) {
|
|
10709
|
-
throw new AppServerProtocolError("thread/resume returned another native thread");
|
|
10710
|
-
}
|
|
10711
|
-
this.processPool.rememberThreadLoaded(resumedId);
|
|
10712
|
-
return resumedId;
|
|
10713
11541
|
} catch (error) {
|
|
10714
11542
|
if (error instanceof AppServerProcessLostError || error instanceof AppServerRequestTimeoutError) {
|
|
10715
11543
|
throw error;
|
|
10716
11544
|
}
|
|
10717
|
-
if (error instanceof AppServerResponseError && isMissingThreadResponse(error.responseMessage, preparedThreadId)) {
|
|
11545
|
+
if (error instanceof AppServerResponseError && preparedThreadId !== void 0 && isMissingThreadResponse(error.responseMessage, preparedThreadId)) {
|
|
10718
11546
|
throw new ThreadUnavailableError(errorMessage3(error));
|
|
10719
11547
|
}
|
|
10720
11548
|
throw error;
|
|
@@ -10765,7 +11593,7 @@ var init_runtime_worker = __esm({
|
|
|
10765
11593
|
if (scanSucceeded) {
|
|
10766
11594
|
retryBackoff.reset();
|
|
10767
11595
|
}
|
|
10768
|
-
await
|
|
11596
|
+
await waitForAbort2(this.lifetimeAbort.signal, scanSucceeded ? recoveryScanIntervalMilliseconds : retryBackoff.nextDelayMilliseconds());
|
|
10769
11597
|
}
|
|
10770
11598
|
}
|
|
10771
11599
|
async scanPersistedAttempts() {
|
|
@@ -10857,7 +11685,7 @@ var init_runtime_worker = __esm({
|
|
|
10857
11685
|
await this.loseLease(active, "Local Codex execution lease expired");
|
|
10858
11686
|
return;
|
|
10859
11687
|
}
|
|
10860
|
-
await
|
|
11688
|
+
await waitForAbort2(active.finished.signal, Math.min(nextRenewalDelayMilliseconds, remaining));
|
|
10861
11689
|
if (active.finished.signal.aborted) {
|
|
10862
11690
|
return;
|
|
10863
11691
|
}
|
|
@@ -10914,6 +11742,9 @@ var init_runtime_worker = __esm({
|
|
|
10914
11742
|
}
|
|
10915
11743
|
}
|
|
10916
11744
|
async loseLease(active, message) {
|
|
11745
|
+
if (active.terminalValue !== void 0) {
|
|
11746
|
+
return;
|
|
11747
|
+
}
|
|
10917
11748
|
if (active.leaseLossCleanupTask !== void 0) {
|
|
10918
11749
|
await active.leaseLossCleanupTask;
|
|
10919
11750
|
return;
|
|
@@ -10929,8 +11760,8 @@ var init_runtime_worker = __esm({
|
|
|
10929
11760
|
const retryBackoff = this.createNetworkRetryBackoff();
|
|
10930
11761
|
while (!active.finished.signal.aborted && !this.lifetimeAbort.signal.aborted) {
|
|
10931
11762
|
try {
|
|
10932
|
-
const
|
|
10933
|
-
for (const control of
|
|
11763
|
+
const page2 = await this.relay.pollCodexRuntimeControls(active.claim.attemptId, fenceFor(active.claim, this.connectorInstanceId), active.controlCursor, 25, active.finished.signal);
|
|
11764
|
+
for (const control of page2.controls) {
|
|
10934
11765
|
await this.applyControl(active, control);
|
|
10935
11766
|
active.controlCursor = Math.max(active.controlCursor, control.cursor);
|
|
10936
11767
|
}
|
|
@@ -10942,7 +11773,7 @@ var init_runtime_worker = __esm({
|
|
|
10942
11773
|
return;
|
|
10943
11774
|
}
|
|
10944
11775
|
await this.logger.error(`Failed to poll Local Codex controls for ${active.claim.attemptId}`, error);
|
|
10945
|
-
await
|
|
11776
|
+
await waitForAbort2(active.finished.signal, retryBackoff.nextDelayMilliseconds());
|
|
10946
11777
|
}
|
|
10947
11778
|
}
|
|
10948
11779
|
}
|
|
@@ -10990,7 +11821,7 @@ var init_runtime_worker = __esm({
|
|
|
10990
11821
|
const response = await client.request("turn/steer", {
|
|
10991
11822
|
clientUserMessageId: clientMessageId,
|
|
10992
11823
|
expectedTurnId: active.nativeTurnId,
|
|
10993
|
-
input: toCodexInput(inputItems),
|
|
11824
|
+
input: await toCodexInput(inputItems, this.connection.rootPath, active.claim.relativeWorkingDirectory),
|
|
10994
11825
|
threadId: active.nativeThreadId
|
|
10995
11826
|
});
|
|
10996
11827
|
if (response.turnId !== active.nativeTurnId) {
|
|
@@ -11002,7 +11833,7 @@ var init_runtime_worker = __esm({
|
|
|
11002
11833
|
return LocalCodexControlOutcomeWire.Rejected;
|
|
11003
11834
|
}
|
|
11004
11835
|
}
|
|
11005
|
-
await
|
|
11836
|
+
await waitForAbort2(active.finished.signal, 25);
|
|
11006
11837
|
}
|
|
11007
11838
|
return LocalCodexControlOutcomeWire.Stale;
|
|
11008
11839
|
}
|
|
@@ -11076,7 +11907,7 @@ var init_runtime_worker = __esm({
|
|
|
11076
11907
|
active.eventUploadScheduled = true;
|
|
11077
11908
|
const next = active.eventUploadQueue.catch(() => void 0).then(async () => {
|
|
11078
11909
|
try {
|
|
11079
|
-
await
|
|
11910
|
+
await waitForAbort2(active.finished.signal, eventUploadCoalesceMilliseconds);
|
|
11080
11911
|
await active.spoolQueue;
|
|
11081
11912
|
while (active.durable.pendingEvents().length > 0) {
|
|
11082
11913
|
await this.flushEvents(active);
|
|
@@ -11106,7 +11937,7 @@ var init_runtime_worker = __esm({
|
|
|
11106
11937
|
if (active.finished.signal.aborted || this.lifetimeAbort.signal.aborted) {
|
|
11107
11938
|
throw error;
|
|
11108
11939
|
}
|
|
11109
|
-
await
|
|
11940
|
+
await waitForAbort2(active.finished.signal, retryBackoff.nextDelayMilliseconds());
|
|
11110
11941
|
}
|
|
11111
11942
|
}
|
|
11112
11943
|
}
|
|
@@ -11125,14 +11956,14 @@ var init_runtime_worker = __esm({
|
|
|
11125
11956
|
throw error;
|
|
11126
11957
|
}
|
|
11127
11958
|
await this.logger.error(`Failed to update Local Codex state for ${active.claim.attemptId}`, error);
|
|
11128
|
-
await
|
|
11959
|
+
await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
|
|
11129
11960
|
}
|
|
11130
11961
|
}
|
|
11131
11962
|
throw new Error("Local Codex Runtime stopped before state ACK");
|
|
11132
11963
|
}
|
|
11133
11964
|
createNetworkRetryBackoff() {
|
|
11134
11965
|
return new RetryBackoff({
|
|
11135
|
-
maximumMilliseconds:
|
|
11966
|
+
maximumMilliseconds: maximumNetworkRetryMilliseconds2,
|
|
11136
11967
|
minimumMilliseconds: this.networkRetryMilliseconds,
|
|
11137
11968
|
random: this.random
|
|
11138
11969
|
});
|
|
@@ -11199,6 +12030,7 @@ var init_runtime_worker = __esm({
|
|
|
11199
12030
|
const moxt = await probeExecutable(process.env.MOXT_CLI_PATH ?? "moxt", this.environment);
|
|
11200
12031
|
return await this.relay.heartbeatCodexRuntime({
|
|
11201
12032
|
...capability,
|
|
12033
|
+
capabilities: [localFilesCapability],
|
|
11202
12034
|
connectorInstanceId: this.connectorInstanceId,
|
|
11203
12035
|
moxtCliStatus: moxt.status,
|
|
11204
12036
|
moxtCliVersion: moxt.version,
|
|
@@ -11308,7 +12140,7 @@ ${titleInput}`,
|
|
|
11308
12140
|
}
|
|
11309
12141
|
await Promise.race([
|
|
11310
12142
|
generation.completion,
|
|
11311
|
-
|
|
12143
|
+
waitForAbort2(active.finished.signal, threadTitleGenerationTimeoutMilliseconds),
|
|
11312
12144
|
active.fatal.then(() => void 0)
|
|
11313
12145
|
]);
|
|
11314
12146
|
if (initialThreadName.completed) {
|
|
@@ -11364,7 +12196,7 @@ ${titleInput}`,
|
|
|
11364
12196
|
await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
|
|
11365
12197
|
return;
|
|
11366
12198
|
}
|
|
11367
|
-
await
|
|
12199
|
+
await waitForAbort2(signal, retryMilliseconds);
|
|
11368
12200
|
retryMilliseconds = Math.min(retryMilliseconds * 2, maximumThreadNameRetryMilliseconds);
|
|
11369
12201
|
continue;
|
|
11370
12202
|
}
|
|
@@ -11404,6 +12236,15 @@ ${titleInput}`,
|
|
|
11404
12236
|
});
|
|
11405
12237
|
|
|
11406
12238
|
// ../machine-connector/dist/runtime/local-codex-runtime/process-pool.js
|
|
12239
|
+
function requireThreadUnsubscribeStatus(response) {
|
|
12240
|
+
if (typeof response !== "object" || response === null || !("status" in response)) {
|
|
12241
|
+
throw new Error("Codex App Server returned an invalid thread unsubscribe response");
|
|
12242
|
+
}
|
|
12243
|
+
const status = response.status;
|
|
12244
|
+
if (status !== "notLoaded" && status !== "notSubscribed" && status !== "unsubscribed") {
|
|
12245
|
+
throw new Error("Codex App Server returned an invalid thread unsubscribe status");
|
|
12246
|
+
}
|
|
12247
|
+
}
|
|
11407
12248
|
function localCodexProcessPoolKey(environment, nativeStoreIdentitySeed) {
|
|
11408
12249
|
return (0, import_node_crypto7.createHash)("sha256").update([
|
|
11409
12250
|
String(process.getuid?.() ?? process.pid),
|
|
@@ -11425,16 +12266,23 @@ var init_process_pool = __esm({
|
|
|
11425
12266
|
LocalCodexProcessPool = class {
|
|
11426
12267
|
poolKey;
|
|
11427
12268
|
logger;
|
|
12269
|
+
threadCacheCapacity;
|
|
11428
12270
|
activeSlots = /* @__PURE__ */ new Map();
|
|
11429
|
-
|
|
12271
|
+
loadedThreads = /* @__PURE__ */ new Map();
|
|
12272
|
+
loadingThreads = /* @__PURE__ */ new Map();
|
|
11430
12273
|
nextSlotId = 1;
|
|
11431
12274
|
routes = /* @__PURE__ */ new Map();
|
|
11432
12275
|
retiredTurnIds = /* @__PURE__ */ new Set();
|
|
11433
12276
|
supervisor;
|
|
12277
|
+
threadCacheOperation = Promise.resolve();
|
|
11434
12278
|
waitingOwners = [];
|
|
11435
|
-
constructor(poolKey, environment, nativeStoreIdentitySeed, store, logger) {
|
|
12279
|
+
constructor(poolKey, environment, nativeStoreIdentitySeed, store, logger, threadCacheCapacity) {
|
|
11436
12280
|
this.poolKey = poolKey;
|
|
11437
12281
|
this.logger = logger;
|
|
12282
|
+
this.threadCacheCapacity = threadCacheCapacity;
|
|
12283
|
+
if (!Number.isSafeInteger(threadCacheCapacity) || threadCacheCapacity < 1) {
|
|
12284
|
+
throw new Error("Local Codex thread cache capacity must be a positive safe integer");
|
|
12285
|
+
}
|
|
11438
12286
|
this.supervisor = new LocalCodexAppServerSupervisor(environment.HOME ?? process.cwd(), environment, nativeStoreIdentitySeed, {
|
|
11439
12287
|
onNotification: async (message) => {
|
|
11440
12288
|
await this.routeNotification(message);
|
|
@@ -11443,7 +12291,7 @@ var init_process_pool = __esm({
|
|
|
11443
12291
|
if (!this.supervisor.markProcessLost(processGeneration)) {
|
|
11444
12292
|
return;
|
|
11445
12293
|
}
|
|
11446
|
-
this.
|
|
12294
|
+
await this.clearThreadCache();
|
|
11447
12295
|
await this.logger.error(`Shared Codex App Server generation ${processGeneration} exited`, error);
|
|
11448
12296
|
await this.broadcastProcessExit(error);
|
|
11449
12297
|
},
|
|
@@ -11518,18 +12366,70 @@ var init_process_pool = __esm({
|
|
|
11518
12366
|
isRetiredTurn(nativeTurnId) {
|
|
11519
12367
|
return this.retiredTurnIds.has(nativeTurnId);
|
|
11520
12368
|
}
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
12369
|
+
async acquireThread(client, requestedThreadId, loadThread) {
|
|
12370
|
+
const acquisition = await this.withThreadCacheLock(() => {
|
|
12371
|
+
this.requireCurrentClient(client);
|
|
12372
|
+
this.discardOtherProcessGenerations(client.processGeneration);
|
|
12373
|
+
if (requestedThreadId !== void 0) {
|
|
12374
|
+
const loaded = this.loadedThreads.get(requestedThreadId);
|
|
12375
|
+
if (loaded !== void 0) {
|
|
12376
|
+
loaded.activeUses += 1;
|
|
12377
|
+
this.touchLoadedThread(requestedThreadId, loaded);
|
|
12378
|
+
return {
|
|
12379
|
+
kind: "leased",
|
|
12380
|
+
lease: this.createThreadLease(requestedThreadId, client.processGeneration)
|
|
12381
|
+
};
|
|
12382
|
+
}
|
|
12383
|
+
const loading = this.loadingThreads.get(requestedThreadId);
|
|
12384
|
+
if (loading !== void 0) {
|
|
12385
|
+
return {
|
|
12386
|
+
kind: "loading",
|
|
12387
|
+
loadedThreadId: loading.loadedThreadId
|
|
12388
|
+
};
|
|
12389
|
+
}
|
|
12390
|
+
}
|
|
12391
|
+
const loadedThreadId2 = Promise.resolve().then(loadThread);
|
|
12392
|
+
if (requestedThreadId !== void 0) {
|
|
12393
|
+
this.loadingThreads.set(requestedThreadId, {
|
|
12394
|
+
loadedThreadId: loadedThreadId2,
|
|
12395
|
+
processGeneration: client.processGeneration
|
|
12396
|
+
});
|
|
12397
|
+
}
|
|
12398
|
+
return {
|
|
12399
|
+
kind: "loading",
|
|
12400
|
+
loadedThreadId: loadedThreadId2
|
|
12401
|
+
};
|
|
12402
|
+
});
|
|
12403
|
+
if (acquisition.kind === "leased") {
|
|
12404
|
+
return acquisition.lease;
|
|
11528
12405
|
}
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
12406
|
+
let loadedThreadId;
|
|
12407
|
+
try {
|
|
12408
|
+
loadedThreadId = await acquisition.loadedThreadId;
|
|
12409
|
+
} catch (error) {
|
|
12410
|
+
await this.removeLoadingThread(requestedThreadId, acquisition.loadedThreadId);
|
|
12411
|
+
throw error;
|
|
11532
12412
|
}
|
|
12413
|
+
return await this.withThreadCacheLock(async () => {
|
|
12414
|
+
this.removeLoadingThreadWithoutLock(requestedThreadId, acquisition.loadedThreadId);
|
|
12415
|
+
this.requireCurrentClient(client);
|
|
12416
|
+
this.discardOtherProcessGenerations(client.processGeneration);
|
|
12417
|
+
if (requestedThreadId !== void 0 && requestedThreadId !== loadedThreadId) {
|
|
12418
|
+
throw new Error("Codex App Server loaded another thread");
|
|
12419
|
+
}
|
|
12420
|
+
const loaded = this.loadedThreads.get(loadedThreadId);
|
|
12421
|
+
if (loaded === void 0) {
|
|
12422
|
+
this.loadedThreads.set(loadedThreadId, {
|
|
12423
|
+
activeUses: 1,
|
|
12424
|
+
processGeneration: client.processGeneration
|
|
12425
|
+
});
|
|
12426
|
+
} else {
|
|
12427
|
+
loaded.activeUses += 1;
|
|
12428
|
+
this.touchLoadedThread(loadedThreadId, loaded);
|
|
12429
|
+
}
|
|
12430
|
+
await this.evictIdleThreads(client);
|
|
12431
|
+
return this.createThreadLease(loadedThreadId, client.processGeneration);
|
|
12432
|
+
});
|
|
11533
12433
|
}
|
|
11534
12434
|
status() {
|
|
11535
12435
|
return this.supervisor.status();
|
|
@@ -11549,9 +12449,10 @@ var init_process_pool = __esm({
|
|
|
11549
12449
|
}
|
|
11550
12450
|
async quarantineCurrentProcess(capture) {
|
|
11551
12451
|
const processGeneration = this.supervisor.currentClient().value?.processGeneration;
|
|
11552
|
-
this.
|
|
12452
|
+
const quarantine = this.supervisor.quarantineCurrentProcess(capture);
|
|
12453
|
+
await this.clearThreadCache();
|
|
11553
12454
|
try {
|
|
11554
|
-
await
|
|
12455
|
+
await quarantine;
|
|
11555
12456
|
} finally {
|
|
11556
12457
|
if (processGeneration !== void 0) {
|
|
11557
12458
|
await this.broadcastProcessExit(new AppServerProcessLostError(`Shared Codex App Server generation ${processGeneration} was quarantined`));
|
|
@@ -11566,8 +12467,99 @@ var init_process_pool = __esm({
|
|
|
11566
12467
|
await client.stop(capture);
|
|
11567
12468
|
}
|
|
11568
12469
|
async stop() {
|
|
11569
|
-
this.
|
|
11570
|
-
await this.
|
|
12470
|
+
const stop = this.supervisor.stop();
|
|
12471
|
+
await this.clearThreadCache();
|
|
12472
|
+
await stop;
|
|
12473
|
+
}
|
|
12474
|
+
createThreadLease(threadId, processGeneration) {
|
|
12475
|
+
let released = false;
|
|
12476
|
+
return {
|
|
12477
|
+
threadId,
|
|
12478
|
+
release: async () => {
|
|
12479
|
+
if (released) {
|
|
12480
|
+
return;
|
|
12481
|
+
}
|
|
12482
|
+
released = true;
|
|
12483
|
+
await this.withThreadCacheLock(async () => {
|
|
12484
|
+
const loaded = this.loadedThreads.get(threadId);
|
|
12485
|
+
if (loaded === void 0 || loaded.processGeneration !== processGeneration) {
|
|
12486
|
+
return;
|
|
12487
|
+
}
|
|
12488
|
+
if (loaded.activeUses < 1) {
|
|
12489
|
+
throw new Error(`Local Codex thread ${threadId} has no active cache lease`);
|
|
12490
|
+
}
|
|
12491
|
+
loaded.activeUses -= 1;
|
|
12492
|
+
this.touchLoadedThread(threadId, loaded);
|
|
12493
|
+
const client = this.supervisor.currentClient().value;
|
|
12494
|
+
if (client !== void 0) {
|
|
12495
|
+
await this.evictIdleThreads(client);
|
|
12496
|
+
}
|
|
12497
|
+
});
|
|
12498
|
+
}
|
|
12499
|
+
};
|
|
12500
|
+
}
|
|
12501
|
+
async clearThreadCache() {
|
|
12502
|
+
await this.withThreadCacheLock(() => {
|
|
12503
|
+
this.loadedThreads.clear();
|
|
12504
|
+
this.loadingThreads.clear();
|
|
12505
|
+
});
|
|
12506
|
+
}
|
|
12507
|
+
discardOtherProcessGenerations(processGeneration) {
|
|
12508
|
+
for (const [threadId, loaded] of this.loadedThreads) {
|
|
12509
|
+
if (loaded.processGeneration !== processGeneration) {
|
|
12510
|
+
this.loadedThreads.delete(threadId);
|
|
12511
|
+
}
|
|
12512
|
+
}
|
|
12513
|
+
for (const [threadId, loading] of this.loadingThreads) {
|
|
12514
|
+
if (loading.processGeneration !== processGeneration) {
|
|
12515
|
+
this.loadingThreads.delete(threadId);
|
|
12516
|
+
}
|
|
12517
|
+
}
|
|
12518
|
+
}
|
|
12519
|
+
async evictIdleThreads(client) {
|
|
12520
|
+
while (this.loadedThreads.size > this.threadCacheCapacity) {
|
|
12521
|
+
const candidate = [...this.loadedThreads].find(([, loaded]) => loaded.activeUses === 0 && loaded.processGeneration === client.processGeneration);
|
|
12522
|
+
if (candidate === void 0) {
|
|
12523
|
+
return;
|
|
12524
|
+
}
|
|
12525
|
+
const [threadId] = candidate;
|
|
12526
|
+
try {
|
|
12527
|
+
const response = await client.request("thread/unsubscribe", { threadId });
|
|
12528
|
+
requireThreadUnsubscribeStatus(response);
|
|
12529
|
+
this.loadedThreads.delete(threadId);
|
|
12530
|
+
} catch (error) {
|
|
12531
|
+
await this.logger.error(`Failed to unsubscribe least-recently-used Local Codex thread ${threadId}`, error);
|
|
12532
|
+
return;
|
|
12533
|
+
}
|
|
12534
|
+
}
|
|
12535
|
+
}
|
|
12536
|
+
touchLoadedThread(threadId, loaded) {
|
|
12537
|
+
this.loadedThreads.delete(threadId);
|
|
12538
|
+
this.loadedThreads.set(threadId, loaded);
|
|
12539
|
+
}
|
|
12540
|
+
async removeLoadingThread(requestedThreadId, loadedThreadId) {
|
|
12541
|
+
await this.withThreadCacheLock(() => {
|
|
12542
|
+
this.removeLoadingThreadWithoutLock(requestedThreadId, loadedThreadId);
|
|
12543
|
+
});
|
|
12544
|
+
}
|
|
12545
|
+
removeLoadingThreadWithoutLock(requestedThreadId, loadedThreadId) {
|
|
12546
|
+
if (requestedThreadId === void 0) {
|
|
12547
|
+
return;
|
|
12548
|
+
}
|
|
12549
|
+
const loading = this.loadingThreads.get(requestedThreadId);
|
|
12550
|
+
if (loading?.loadedThreadId === loadedThreadId) {
|
|
12551
|
+
this.loadingThreads.delete(requestedThreadId);
|
|
12552
|
+
}
|
|
12553
|
+
}
|
|
12554
|
+
requireCurrentClient(client) {
|
|
12555
|
+
if (this.supervisor.currentClient().value !== client || client.isClosed()) {
|
|
12556
|
+
throw new AppServerProcessLostError(`Shared Codex App Server generation ${client.processGeneration} is no longer current`);
|
|
12557
|
+
}
|
|
12558
|
+
}
|
|
12559
|
+
async withThreadCacheLock(operation) {
|
|
12560
|
+
const result = this.threadCacheOperation.then(operation, operation);
|
|
12561
|
+
this.threadCacheOperation = result.then(() => void 0, () => void 0);
|
|
12562
|
+
return await result;
|
|
11571
12563
|
}
|
|
11572
12564
|
matchingRoutes(message) {
|
|
11573
12565
|
return [...this.routes.values()].filter((route) => route.ownsMessage(message));
|
|
@@ -11649,7 +12641,7 @@ function delay3(milliseconds) {
|
|
|
11649
12641
|
setTimeout(resolvePromise, milliseconds);
|
|
11650
12642
|
});
|
|
11651
12643
|
}
|
|
11652
|
-
var import_node_os8, import_node_crypto8, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, commandOutputBatchMaxBytes, commandOutputFlushIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds,
|
|
12644
|
+
var import_node_os8, import_node_crypto8, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, commandOutputBatchMaxBytes, commandOutputFlushIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds3, defaultLocalCodexThreadCacheCapacity, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
|
|
11653
12645
|
var init_daemon = __esm({
|
|
11654
12646
|
"../machine-connector/dist/runtime/daemon.js"() {
|
|
11655
12647
|
"use strict";
|
|
@@ -11676,6 +12668,8 @@ var init_daemon = __esm({
|
|
|
11676
12668
|
init_store();
|
|
11677
12669
|
init_version();
|
|
11678
12670
|
init_runtime_worker();
|
|
12671
|
+
init_contracts2();
|
|
12672
|
+
init_discovery_worker();
|
|
11679
12673
|
init_process_pool();
|
|
11680
12674
|
claimTimeoutSeconds = 30;
|
|
11681
12675
|
controlTimeoutSeconds = 30;
|
|
@@ -11684,7 +12678,8 @@ var init_daemon = __esm({
|
|
|
11684
12678
|
commandOutputFlushIntervalMilliseconds = 250;
|
|
11685
12679
|
agentOutputLimitBytes = 2e6;
|
|
11686
12680
|
defaultLeaseSeconds = 90;
|
|
11687
|
-
|
|
12681
|
+
defaultNetworkRetryMilliseconds3 = 2e3;
|
|
12682
|
+
defaultLocalCodexThreadCacheCapacity = 64;
|
|
11688
12683
|
defaultLeaseSafetyMarginMilliseconds = 1e4;
|
|
11689
12684
|
defaultTerminalForegroundBudgetMilliseconds = 5e3;
|
|
11690
12685
|
maximumEventUploadRetryMilliseconds = 6e4;
|
|
@@ -11706,6 +12701,7 @@ var init_daemon = __esm({
|
|
|
11706
12701
|
logger;
|
|
11707
12702
|
relayClients = /* @__PURE__ */ new Map();
|
|
11708
12703
|
localCodexWorkers = /* @__PURE__ */ new Map();
|
|
12704
|
+
localFileDiscoveryWorkers = /* @__PURE__ */ new Map();
|
|
11709
12705
|
localCodexProcessPools = /* @__PURE__ */ new Map();
|
|
11710
12706
|
startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
11711
12707
|
connections = [];
|
|
@@ -11720,6 +12716,7 @@ var init_daemon = __esm({
|
|
|
11720
12716
|
leaseSafetyMarginMilliseconds;
|
|
11721
12717
|
leaseSeconds;
|
|
11722
12718
|
networkRetryMilliseconds;
|
|
12719
|
+
localCodexThreadCacheCapacity;
|
|
11723
12720
|
random;
|
|
11724
12721
|
terminalForegroundBudgetMilliseconds;
|
|
11725
12722
|
cliVersion;
|
|
@@ -11737,7 +12734,8 @@ var init_daemon = __esm({
|
|
|
11737
12734
|
this.shellEnvironmentManager = options.shellEnvironmentManager ?? new ShellEnvironmentManager();
|
|
11738
12735
|
this.leaseSafetyMarginMilliseconds = options.leaseSafetyMarginMilliseconds ?? defaultLeaseSafetyMarginMilliseconds;
|
|
11739
12736
|
this.leaseSeconds = options.leaseSeconds ?? defaultLeaseSeconds;
|
|
11740
|
-
this.networkRetryMilliseconds = options.networkRetryMilliseconds ??
|
|
12737
|
+
this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds3;
|
|
12738
|
+
this.localCodexThreadCacheCapacity = options.localCodexThreadCacheCapacity ?? defaultLocalCodexThreadCacheCapacity;
|
|
11741
12739
|
this.random = options.random ?? Math.random;
|
|
11742
12740
|
this.terminalForegroundBudgetMilliseconds = options.terminalForegroundBudgetMilliseconds ?? defaultTerminalForegroundBudgetMilliseconds;
|
|
11743
12741
|
}
|
|
@@ -11813,6 +12811,9 @@ var init_daemon = __esm({
|
|
|
11813
12811
|
await Promise.all([...this.localCodexWorkers.entries()].map(async ([connectionId, worker]) => {
|
|
11814
12812
|
await this.stopRuntimeComponent(`Failed to stop Local Codex worker ${connectionId}`, async () => await worker.stop());
|
|
11815
12813
|
}));
|
|
12814
|
+
await Promise.all([...this.localFileDiscoveryWorkers.entries()].map(async ([connectionId, worker]) => {
|
|
12815
|
+
await this.stopRuntimeComponent(`Failed to stop Local file discovery worker ${connectionId}`, async () => await worker.stop());
|
|
12816
|
+
}));
|
|
11816
12817
|
await Promise.all([...this.localCodexProcessPools.values()].map(async (pool) => {
|
|
11817
12818
|
await this.stopRuntimeComponent(`Failed to stop Local Codex App Server pool ${pool.poolKey}`, async () => await pool.stop());
|
|
11818
12819
|
}));
|
|
@@ -11878,10 +12879,34 @@ var init_daemon = __esm({
|
|
|
11878
12879
|
}
|
|
11879
12880
|
await Promise.all([
|
|
11880
12881
|
this.runHeartbeatLoop(connection, relay),
|
|
12882
|
+
this.runLocalFileDiscovery(connection, relay),
|
|
11881
12883
|
this.runClaimLoop(connection, relay),
|
|
11882
12884
|
this.runControlLoop(connection, relay)
|
|
11883
12885
|
]);
|
|
11884
12886
|
}
|
|
12887
|
+
async runLocalFileDiscovery(connection, relay) {
|
|
12888
|
+
const worker = new LocalCodexDiscoveryWorker({
|
|
12889
|
+
connectionId: connection.connectionId,
|
|
12890
|
+
connectorInstanceId: this.connectorInstanceId,
|
|
12891
|
+
execute: async (request2) => await executeLocalFileDiscovery(connection.rootPath, request2),
|
|
12892
|
+
failureErrorCode: () => "directory_unavailable",
|
|
12893
|
+
logger: this.logger,
|
|
12894
|
+
networkRetryMilliseconds: this.networkRetryMilliseconds,
|
|
12895
|
+
random: this.random,
|
|
12896
|
+
relay
|
|
12897
|
+
});
|
|
12898
|
+
this.localFileDiscoveryWorkers.set(connection.connectionId, worker);
|
|
12899
|
+
if (this.stopping) {
|
|
12900
|
+
await worker.stop();
|
|
12901
|
+
}
|
|
12902
|
+
try {
|
|
12903
|
+
await worker.run();
|
|
12904
|
+
} finally {
|
|
12905
|
+
if (this.localFileDiscoveryWorkers.get(connection.connectionId) === worker) {
|
|
12906
|
+
this.localFileDiscoveryWorkers.delete(connection.connectionId);
|
|
12907
|
+
}
|
|
12908
|
+
}
|
|
12909
|
+
}
|
|
11885
12910
|
async runLocalCodexRuntime(connection, relay) {
|
|
11886
12911
|
const worker = new LocalCodexRuntimeConnectionWorker(connection, relay, this.store, this.localCodexProcessPool(connection.machineId), this.shellEnvironmentManager.snapshot(), this.connectorInstanceId, this.logger, {
|
|
11887
12912
|
networkRetryMilliseconds: this.networkRetryMilliseconds,
|
|
@@ -11906,7 +12931,7 @@ var init_daemon = __esm({
|
|
|
11906
12931
|
if (existing !== void 0) {
|
|
11907
12932
|
return existing;
|
|
11908
12933
|
}
|
|
11909
|
-
const pool = new LocalCodexProcessPool(poolKey, environment, nativeStoreIdentitySeed, this.store, this.logger);
|
|
12934
|
+
const pool = new LocalCodexProcessPool(poolKey, environment, nativeStoreIdentitySeed, this.store, this.logger, this.localCodexThreadCacheCapacity);
|
|
11910
12935
|
this.localCodexProcessPools.set(poolKey, pool);
|
|
11911
12936
|
return pool;
|
|
11912
12937
|
}
|
|
@@ -11940,11 +12965,13 @@ var init_daemon = __esm({
|
|
|
11940
12965
|
await activeJob.cancellation.request(ExecutionCancellationReason.LeaseLost);
|
|
11941
12966
|
}));
|
|
11942
12967
|
this.localCodexWorkers.get(connection.connectionId)?.revoke();
|
|
12968
|
+
this.localFileDiscoveryWorkers.get(connection.connectionId)?.revoke();
|
|
11943
12969
|
}
|
|
11944
12970
|
async runHeartbeatLoop(connection, relay) {
|
|
11945
12971
|
while (!this.stopping && !relay.isRevoked()) {
|
|
11946
12972
|
try {
|
|
11947
12973
|
await relay.heartbeat({
|
|
12974
|
+
capabilities: [localFilesCapability],
|
|
11948
12975
|
connectorInstanceId: this.connectorInstanceId,
|
|
11949
12976
|
connectorVersion,
|
|
11950
12977
|
protocolVersion: machineProtocolVersion
|
|
@@ -12764,12 +13791,12 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
12764
13791
|
}
|
|
12765
13792
|
function createServiceEnvironment(options) {
|
|
12766
13793
|
const inheritedPath = options.environment.PATH ?? process.env.PATH ?? "";
|
|
12767
|
-
const nodeDirectory = (0,
|
|
12768
|
-
const pathEntries = [nodeDirectory, ...inheritedPath.split(
|
|
13794
|
+
const nodeDirectory = (0, import_node_path12.dirname)(options.nodePath);
|
|
13795
|
+
const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path12.delimiter)].filter((entry, index2, entries) => entry.length > 0 && entries.indexOf(entry) === index2);
|
|
12769
13796
|
return {
|
|
12770
13797
|
...options.environment,
|
|
12771
13798
|
HOME: options.environment.HOME ?? process.env.HOME ?? (0, import_node_os9.homedir)(),
|
|
12772
|
-
PATH: pathEntries.join(
|
|
13799
|
+
PATH: pathEntries.join(import_node_path12.delimiter)
|
|
12773
13800
|
};
|
|
12774
13801
|
}
|
|
12775
13802
|
async function restartUserService(store, runtime = defaultServiceManagerRuntime) {
|
|
@@ -12963,7 +13990,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
12963
13990
|
"bootout",
|
|
12964
13991
|
`gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
|
|
12965
13992
|
]);
|
|
12966
|
-
await (0,
|
|
13993
|
+
await (0, import_promises14.rm)(launchAgentPath(), { force: true });
|
|
12967
13994
|
return;
|
|
12968
13995
|
}
|
|
12969
13996
|
if (manager === UserServiceManager.Systemd) {
|
|
@@ -12973,7 +14000,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
12973
14000
|
"--now",
|
|
12974
14001
|
"moxt-machine-connector.service"
|
|
12975
14002
|
]);
|
|
12976
|
-
await (0,
|
|
14003
|
+
await (0, import_promises14.rm)(systemdUnitPath(), { force: true });
|
|
12977
14004
|
await runCommandIgnoringFailure(runtime, "systemctl", [
|
|
12978
14005
|
"--user",
|
|
12979
14006
|
"daemon-reload"
|
|
@@ -12990,7 +14017,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
12990
14017
|
]);
|
|
12991
14018
|
await waitForSupervisorExit(store, runtime, supervisorProcessId);
|
|
12992
14019
|
}
|
|
12993
|
-
await (0,
|
|
14020
|
+
await (0, import_promises14.rm)(supervisorDirectory(store), {
|
|
12994
14021
|
force: true,
|
|
12995
14022
|
recursive: true
|
|
12996
14023
|
});
|
|
@@ -13016,7 +14043,7 @@ async function readStoredServiceManager(store) {
|
|
|
13016
14043
|
}
|
|
13017
14044
|
async function readManagedServiceDefinition(manager, store) {
|
|
13018
14045
|
try {
|
|
13019
|
-
return await (0,
|
|
14046
|
+
return await (0, import_promises14.readFile)(managedServiceDefinitionPath(manager, store), "utf8");
|
|
13020
14047
|
} catch (error) {
|
|
13021
14048
|
if (isNodeErrorCode4(error, "ENOENT"))
|
|
13022
14049
|
return void 0;
|
|
@@ -13025,8 +14052,8 @@ async function readManagedServiceDefinition(manager, store) {
|
|
|
13025
14052
|
}
|
|
13026
14053
|
async function restoreManagedServiceDefinition(manager, store, definition2, runtime) {
|
|
13027
14054
|
const path4 = managedServiceDefinitionPath(manager, store);
|
|
13028
|
-
await (0,
|
|
13029
|
-
await (0,
|
|
14055
|
+
await (0, import_promises14.mkdir)((0, import_node_path12.dirname)(path4), { recursive: true });
|
|
14056
|
+
await (0, import_promises14.writeFile)(path4, definition2, { encoding: "utf8", mode: 384 });
|
|
13030
14057
|
if (manager === UserServiceManager.Launchd) {
|
|
13031
14058
|
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
13032
14059
|
await runCommandIgnoringFailure(runtime, "launchctl", [
|
|
@@ -13075,7 +14102,7 @@ function parseProcessId(value) {
|
|
|
13075
14102
|
async function persistServiceManager(store, manager, managedEntrypointPath, desiredState = ManagedServiceDesiredState.Running) {
|
|
13076
14103
|
await store.writeServiceManager({
|
|
13077
14104
|
desiredState,
|
|
13078
|
-
...managedEntrypointPath ? { managedEntrypointPath: (0,
|
|
14105
|
+
...managedEntrypointPath ? { managedEntrypointPath: (0, import_node_path12.resolve)(managedEntrypointPath) } : {},
|
|
13079
14106
|
manager,
|
|
13080
14107
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
13081
14108
|
});
|
|
@@ -13088,9 +14115,9 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
|
|
|
13088
14115
|
const stored = (await store.readServiceManager()).value;
|
|
13089
14116
|
if (!stored || stored.manager === UserServiceManager.None)
|
|
13090
14117
|
return;
|
|
13091
|
-
const candidate = (0,
|
|
14118
|
+
const candidate = (0, import_node_path12.resolve)(candidateEntrypointPath);
|
|
13092
14119
|
if (stored.managedEntrypointPath) {
|
|
13093
|
-
if ((0,
|
|
14120
|
+
if ((0, import_node_path12.resolve)(stored.managedEntrypointPath) !== candidate) {
|
|
13094
14121
|
throw new Error("The managed Connector belongs to a different CLI installation. Run service install from the owning CLI to transfer management.");
|
|
13095
14122
|
}
|
|
13096
14123
|
return;
|
|
@@ -13100,16 +14127,16 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
|
|
|
13100
14127
|
}
|
|
13101
14128
|
}
|
|
13102
14129
|
async function isInsideSourceCheckout(path4) {
|
|
13103
|
-
let directory = (0,
|
|
14130
|
+
let directory = (0, import_node_path12.dirname)(path4);
|
|
13104
14131
|
while (true) {
|
|
13105
14132
|
try {
|
|
13106
|
-
await (0,
|
|
14133
|
+
await (0, import_promises14.stat)((0, import_node_path12.join)(directory, ".git"));
|
|
13107
14134
|
return true;
|
|
13108
14135
|
} catch (error) {
|
|
13109
14136
|
if (!isNodeErrorCode4(error, "ENOENT"))
|
|
13110
14137
|
throw error;
|
|
13111
14138
|
}
|
|
13112
|
-
const parent = (0,
|
|
14139
|
+
const parent = (0, import_node_path12.dirname)(directory);
|
|
13113
14140
|
if (parent === directory)
|
|
13114
14141
|
return false;
|
|
13115
14142
|
directory = parent;
|
|
@@ -13138,10 +14165,10 @@ function automaticSelectionDetail(manager) {
|
|
|
13138
14165
|
}
|
|
13139
14166
|
async function installLaunchAgent(store, options, runtime) {
|
|
13140
14167
|
const path4 = launchAgentPath();
|
|
13141
|
-
await (0,
|
|
14168
|
+
await (0, import_promises14.mkdir)((0, import_node_path12.dirname)(path4), { recursive: true });
|
|
13142
14169
|
const programArguments = [
|
|
13143
14170
|
options.nodePath,
|
|
13144
|
-
(0,
|
|
14171
|
+
(0, import_node_path12.resolve)(options.entrypointPath),
|
|
13145
14172
|
...options.commandArguments
|
|
13146
14173
|
];
|
|
13147
14174
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -13172,7 +14199,7 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
13172
14199
|
</dict>
|
|
13173
14200
|
</plist>
|
|
13174
14201
|
`;
|
|
13175
|
-
await (0,
|
|
14202
|
+
await (0, import_promises14.writeFile)(path4, plist, { encoding: "utf8", mode: 384 });
|
|
13176
14203
|
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
13177
14204
|
await runCommandIgnoringFailure(runtime, "launchctl", [
|
|
13178
14205
|
"bootout",
|
|
@@ -13188,10 +14215,10 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
13188
14215
|
}
|
|
13189
14216
|
async function installSystemdUserService(store, options, runtime) {
|
|
13190
14217
|
const path4 = systemdUnitPath();
|
|
13191
|
-
await (0,
|
|
14218
|
+
await (0, import_promises14.mkdir)((0, import_node_path12.dirname)(path4), { recursive: true });
|
|
13192
14219
|
const command = [
|
|
13193
14220
|
options.nodePath,
|
|
13194
|
-
(0,
|
|
14221
|
+
(0, import_node_path12.resolve)(options.entrypointPath),
|
|
13195
14222
|
...options.commandArguments
|
|
13196
14223
|
].map(escapeSystemdArgument).join(" ");
|
|
13197
14224
|
const unit = `[Unit]
|
|
@@ -13210,7 +14237,7 @@ ${Object.entries(options.environment).map(([name, value]) => `Environment=${esca
|
|
|
13210
14237
|
[Install]
|
|
13211
14238
|
WantedBy=default.target
|
|
13212
14239
|
`;
|
|
13213
|
-
await (0,
|
|
14240
|
+
await (0, import_promises14.writeFile)(path4, unit, { encoding: "utf8", mode: 384 });
|
|
13214
14241
|
await runtime.run("systemctl", ["--user", "daemon-reload"]);
|
|
13215
14242
|
await runtime.run("systemctl", [
|
|
13216
14243
|
"--user",
|
|
@@ -13231,8 +14258,8 @@ WantedBy=default.target
|
|
|
13231
14258
|
async function installSupervisorUserService(store, options, runtime) {
|
|
13232
14259
|
const directory = supervisorDirectory(store);
|
|
13233
14260
|
const configPath = supervisorConfigPath(store);
|
|
13234
|
-
await (0,
|
|
13235
|
-
await (0,
|
|
14261
|
+
await (0, import_promises14.mkdir)(directory, { recursive: true, mode: 448 });
|
|
14262
|
+
await (0, import_promises14.writeFile)(configPath, createSupervisorConfiguration(store, options), {
|
|
13236
14263
|
encoding: "utf8",
|
|
13237
14264
|
mode: 384
|
|
13238
14265
|
});
|
|
@@ -13246,7 +14273,7 @@ async function installSupervisorUserService(store, options, runtime) {
|
|
|
13246
14273
|
function createSupervisorConfiguration(store, options) {
|
|
13247
14274
|
const command = [
|
|
13248
14275
|
options.nodePath,
|
|
13249
|
-
(0,
|
|
14276
|
+
(0, import_node_path12.resolve)(options.entrypointPath),
|
|
13250
14277
|
...options.commandArguments
|
|
13251
14278
|
].map(escapeSupervisorArgument).join(" ");
|
|
13252
14279
|
const environment = Object.entries(options.environment).map(([name, value]) => `${name}="${escapeSupervisorEnvironment(value)}"`).join(",");
|
|
@@ -13270,7 +14297,7 @@ serverurl=unix://${supervisorSocketPath(store)}
|
|
|
13270
14297
|
|
|
13271
14298
|
[program:${supervisorProgramName}]
|
|
13272
14299
|
command=${command}
|
|
13273
|
-
directory=${escapeSupervisorPath((0,
|
|
14300
|
+
directory=${escapeSupervisorPath((0, import_node_path12.dirname)((0, import_node_path12.resolve)(options.entrypointPath)))}
|
|
13274
14301
|
environment=${environment}
|
|
13275
14302
|
autostart=true
|
|
13276
14303
|
autorestart=true
|
|
@@ -13303,8 +14330,8 @@ async function restartSupervisorUserService(store, runtime) {
|
|
|
13303
14330
|
await startSupervisorUserService(store, runtime, supervisorProcessId, stoppedConnector.processId);
|
|
13304
14331
|
}
|
|
13305
14332
|
async function startSupervisorUserService(store, runtime, previousSupervisorProcessId, previousConnectorProcessId) {
|
|
13306
|
-
await (0,
|
|
13307
|
-
await (0,
|
|
14333
|
+
await (0, import_promises14.rm)(supervisorSocketPath(store), { force: true });
|
|
14334
|
+
await (0, import_promises14.rm)(supervisorPidPath(store), { force: true });
|
|
13308
14335
|
await runtime.run("supervisord", ["-c", supervisorConfigPath(store)], {
|
|
13309
14336
|
environment: sanitizeEnvironment(process.env),
|
|
13310
14337
|
timeoutMilliseconds: serviceManagerMutationTimeoutMilliseconds
|
|
@@ -13413,7 +14440,7 @@ async function currentSupervisorProcessId(store, runtime) {
|
|
|
13413
14440
|
} catch {
|
|
13414
14441
|
}
|
|
13415
14442
|
try {
|
|
13416
|
-
const processId = parseProcessId(await (0,
|
|
14443
|
+
const processId = parseProcessId(await (0, import_promises14.readFile)(supervisorPidPath(store), "utf8"));
|
|
13417
14444
|
return processId !== void 0 && serviceProcessIsRunning(runtime, processId) ? processId : void 0;
|
|
13418
14445
|
} catch (error) {
|
|
13419
14446
|
if (isNodeErrorCode4(error, "ENOENT"))
|
|
@@ -13435,26 +14462,26 @@ async function currentSupervisorProgramProcessId(store, runtime) {
|
|
|
13435
14462
|
}
|
|
13436
14463
|
}
|
|
13437
14464
|
function launchAgentPath() {
|
|
13438
|
-
return (0,
|
|
14465
|
+
return (0, import_node_path12.join)(process.env.HOME ?? (0, import_node_os9.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
|
|
13439
14466
|
}
|
|
13440
14467
|
function systemdUnitPath() {
|
|
13441
|
-
const configHome = process.env.XDG_CONFIG_HOME ?? (0,
|
|
13442
|
-
return (0,
|
|
14468
|
+
const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path12.join)(process.env.HOME ?? (0, import_node_os9.homedir)(), ".config");
|
|
14469
|
+
return (0, import_node_path12.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
|
|
13443
14470
|
}
|
|
13444
14471
|
function supervisorDirectory(store) {
|
|
13445
|
-
return (0,
|
|
14472
|
+
return (0, import_node_path12.join)(store.baseDirectory, "supervisor");
|
|
13446
14473
|
}
|
|
13447
14474
|
function supervisorConfigPath(store) {
|
|
13448
|
-
return (0,
|
|
14475
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisord.conf");
|
|
13449
14476
|
}
|
|
13450
14477
|
function supervisorSocketPath(store) {
|
|
13451
|
-
return (0,
|
|
14478
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisor.sock");
|
|
13452
14479
|
}
|
|
13453
14480
|
function supervisorPidPath(store) {
|
|
13454
|
-
return (0,
|
|
14481
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisord.pid");
|
|
13455
14482
|
}
|
|
13456
14483
|
function supervisorLogPath(store) {
|
|
13457
|
-
return (0,
|
|
14484
|
+
return (0, import_node_path12.join)(supervisorDirectory(store), "supervisord.log");
|
|
13458
14485
|
}
|
|
13459
14486
|
async function commandSucceeds(runtime, command, argumentsList) {
|
|
13460
14487
|
try {
|
|
@@ -13514,15 +14541,15 @@ function serviceManagerCurrentTime(runtime) {
|
|
|
13514
14541
|
async function serviceManagerDelay(runtime, milliseconds) {
|
|
13515
14542
|
await (runtime.delay?.(milliseconds) ?? delay4(milliseconds));
|
|
13516
14543
|
}
|
|
13517
|
-
var import_node_child_process5,
|
|
14544
|
+
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;
|
|
13518
14545
|
var init_service_manager = __esm({
|
|
13519
14546
|
"../machine-connector/dist/runtime/service-manager.js"() {
|
|
13520
14547
|
"use strict";
|
|
13521
14548
|
init_cjs_shims();
|
|
13522
14549
|
import_node_child_process5 = require("child_process");
|
|
13523
|
-
|
|
14550
|
+
import_promises14 = require("fs/promises");
|
|
13524
14551
|
import_node_os9 = require("os");
|
|
13525
|
-
|
|
14552
|
+
import_node_path12 = require("path");
|
|
13526
14553
|
import_node_util2 = require("util");
|
|
13527
14554
|
init_runtime_types();
|
|
13528
14555
|
init_shell_environment();
|
|
@@ -13617,9 +14644,9 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
13617
14644
|
try {
|
|
13618
14645
|
refresh = await refreshManagedUserService(store, {
|
|
13619
14646
|
commandArguments: [...options.commandArguments],
|
|
13620
|
-
entrypointPath: (0,
|
|
14647
|
+
entrypointPath: (0, import_node_path13.resolve)(options.entrypointPath),
|
|
13621
14648
|
environment: { ...options.environment },
|
|
13622
|
-
nodePath: (0,
|
|
14649
|
+
nodePath: (0, import_node_path13.resolve)(options.nodePath)
|
|
13623
14650
|
});
|
|
13624
14651
|
if (!refresh) {
|
|
13625
14652
|
throw new Error("The Connector service is no longer managed by Moxt");
|
|
@@ -13655,10 +14682,10 @@ async function validateCliEntrypoint(options, store) {
|
|
|
13655
14682
|
if (options.commandArguments.length !== 2 || options.commandArguments[0] !== "machine" || options.commandArguments[1] !== "daemon") {
|
|
13656
14683
|
throw new Error("The managed daemon command must be `machine daemon`");
|
|
13657
14684
|
}
|
|
13658
|
-
const nodePath = await (0,
|
|
13659
|
-
const entrypointPath = await (0,
|
|
13660
|
-
await (0,
|
|
13661
|
-
await (0,
|
|
14685
|
+
const nodePath = await (0, import_promises15.realpath)((0, import_node_path13.resolve)(options.nodePath));
|
|
14686
|
+
const entrypointPath = await (0, import_promises15.realpath)((0, import_node_path13.resolve)(options.entrypointPath));
|
|
14687
|
+
await (0, import_promises15.access)(nodePath, import_promises15.constants.X_OK);
|
|
14688
|
+
await (0, import_promises15.access)(entrypointPath, import_promises15.constants.R_OK);
|
|
13662
14689
|
const probe = await execFileAsync2(nodePath, [entrypointPath, "--version"], {
|
|
13663
14690
|
encoding: "utf8",
|
|
13664
14691
|
env: {
|
|
@@ -13691,14 +14718,14 @@ function delay5(milliseconds) {
|
|
|
13691
14718
|
function errorMessage5(error) {
|
|
13692
14719
|
return error instanceof Error ? error.message : String(error);
|
|
13693
14720
|
}
|
|
13694
|
-
var import_node_child_process6,
|
|
14721
|
+
var import_node_child_process6, import_promises15, import_node_path13, import_node_util3, reconcileTimeoutMilliseconds, execFileAsync2, DaemonReconcileOutcome, DaemonRefreshStage, DaemonRefreshError;
|
|
13695
14722
|
var init_daemon_reconcile = __esm({
|
|
13696
14723
|
"../machine-connector/dist/runtime/daemon-reconcile.js"() {
|
|
13697
14724
|
"use strict";
|
|
13698
14725
|
init_cjs_shims();
|
|
13699
14726
|
import_node_child_process6 = require("child_process");
|
|
13700
|
-
|
|
13701
|
-
|
|
14727
|
+
import_promises15 = require("fs/promises");
|
|
14728
|
+
import_node_path13 = require("path");
|
|
13702
14729
|
import_node_util3 = require("util");
|
|
13703
14730
|
init_local_ipc();
|
|
13704
14731
|
init_process_lock();
|
|
@@ -13761,7 +14788,7 @@ async function runMachineDoctor(store) {
|
|
|
13761
14788
|
}
|
|
13762
14789
|
for (const connection of connections) {
|
|
13763
14790
|
try {
|
|
13764
|
-
await (0,
|
|
14791
|
+
await (0, import_promises16.access)(connection.rootPath, import_node_fs3.constants.R_OK | import_node_fs3.constants.X_OK);
|
|
13765
14792
|
checks.push({
|
|
13766
14793
|
detail: connection.rootPath,
|
|
13767
14794
|
name: `root:${connection.connectionId}`,
|
|
@@ -13776,7 +14803,7 @@ async function runMachineDoctor(store) {
|
|
|
13776
14803
|
}
|
|
13777
14804
|
const relayUrl = new URL(connection.relayOrigin);
|
|
13778
14805
|
try {
|
|
13779
|
-
const address = await (0,
|
|
14806
|
+
const address = await (0, import_promises17.lookup)(relayUrl.hostname);
|
|
13780
14807
|
checks.push({
|
|
13781
14808
|
detail: `${relayUrl.hostname} resolves to ${address.address}`,
|
|
13782
14809
|
name: `dns:${connection.connectionId}`,
|
|
@@ -13858,15 +14885,15 @@ async function runMachineDoctor(store) {
|
|
|
13858
14885
|
function errorMessage6(error) {
|
|
13859
14886
|
return error instanceof Error ? error.message : String(error);
|
|
13860
14887
|
}
|
|
13861
|
-
var import_node_child_process7,
|
|
14888
|
+
var import_node_child_process7, import_promises16, import_node_fs3, import_promises17, import_node_util4, execFileAsync3, DoctorCheckStatus;
|
|
13862
14889
|
var init_doctor = __esm({
|
|
13863
14890
|
"../machine-connector/dist/runtime/doctor.js"() {
|
|
13864
14891
|
"use strict";
|
|
13865
14892
|
init_cjs_shims();
|
|
13866
14893
|
import_node_child_process7 = require("child_process");
|
|
13867
|
-
|
|
14894
|
+
import_promises16 = require("fs/promises");
|
|
13868
14895
|
import_node_fs3 = require("fs");
|
|
13869
|
-
|
|
14896
|
+
import_promises17 = require("dns/promises");
|
|
13870
14897
|
import_node_util4 = require("util");
|
|
13871
14898
|
init_local_ipc();
|
|
13872
14899
|
execFileAsync3 = (0, import_node_util4.promisify)(import_node_child_process7.execFile);
|
|
@@ -14136,7 +15163,7 @@ async function readRecentLogLines(store) {
|
|
|
14136
15163
|
}
|
|
14137
15164
|
async function readOptionalFile(path4) {
|
|
14138
15165
|
try {
|
|
14139
|
-
return await (0,
|
|
15166
|
+
return await (0, import_promises18.readFile)(path4, "utf8");
|
|
14140
15167
|
} catch (error) {
|
|
14141
15168
|
if (isMissingFile(error)) {
|
|
14142
15169
|
return "";
|
|
@@ -14195,13 +15222,13 @@ function isMissingFile(error) {
|
|
|
14195
15222
|
function errorMessage7(error) {
|
|
14196
15223
|
return error instanceof Error ? error.message : String(error);
|
|
14197
15224
|
}
|
|
14198
|
-
var
|
|
15225
|
+
var import_promises18, import_promises19, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
|
|
14199
15226
|
var init_machine_manager = __esm({
|
|
14200
15227
|
"../machine-connector/dist/runtime/machine-manager.js"() {
|
|
14201
15228
|
"use strict";
|
|
14202
15229
|
init_cjs_shims();
|
|
14203
|
-
|
|
14204
|
-
|
|
15230
|
+
import_promises18 = require("fs/promises");
|
|
15231
|
+
import_promises19 = require("readline/promises");
|
|
14205
15232
|
import_node_readline = require("readline");
|
|
14206
15233
|
init_doctor();
|
|
14207
15234
|
init_local_ipc();
|
|
@@ -14435,7 +15462,7 @@ var init_machine_manager = __esm({
|
|
|
14435
15462
|
}
|
|
14436
15463
|
async runCommandAction(action) {
|
|
14437
15464
|
this.suspendTerminal();
|
|
14438
|
-
const reader = (0,
|
|
15465
|
+
const reader = (0, import_promises19.createInterface)({
|
|
14439
15466
|
input: process.stdin,
|
|
14440
15467
|
output: process.stdout
|
|
14441
15468
|
});
|
|
@@ -14676,7 +15703,7 @@ async function pairMachine(store, options) {
|
|
|
14676
15703
|
throw new Error("Local Machine pairing expired");
|
|
14677
15704
|
}
|
|
14678
15705
|
function displayNameForRoot(canonicalRoot) {
|
|
14679
|
-
const name = (0,
|
|
15706
|
+
const name = (0, import_node_path14.basename)(canonicalRoot);
|
|
14680
15707
|
return name.length > 0 ? name : canonicalRoot;
|
|
14681
15708
|
}
|
|
14682
15709
|
function getOperatingSystem() {
|
|
@@ -14698,7 +15725,7 @@ function delay6(milliseconds) {
|
|
|
14698
15725
|
setTimeout(resolvePromise, milliseconds);
|
|
14699
15726
|
});
|
|
14700
15727
|
}
|
|
14701
|
-
var import_node_child_process8, import_node_crypto10, import_node_os10,
|
|
15728
|
+
var import_node_child_process8, import_node_crypto10, import_node_os10, import_node_path14, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
|
|
14702
15729
|
var init_pairing = __esm({
|
|
14703
15730
|
"../machine-connector/dist/runtime/pairing.js"() {
|
|
14704
15731
|
"use strict";
|
|
@@ -14706,7 +15733,7 @@ var init_pairing = __esm({
|
|
|
14706
15733
|
import_node_child_process8 = require("child_process");
|
|
14707
15734
|
import_node_crypto10 = require("crypto");
|
|
14708
15735
|
import_node_os10 = require("os");
|
|
14709
|
-
|
|
15736
|
+
import_node_path14 = require("path");
|
|
14710
15737
|
init_contracts();
|
|
14711
15738
|
init_version();
|
|
14712
15739
|
init_enums();
|
|
@@ -14794,7 +15821,7 @@ function isMachineLifecycleMutation(command, commandArguments) {
|
|
|
14794
15821
|
async function connectCommand(store, argumentsList, entrypoint) {
|
|
14795
15822
|
const options = parseOptions(argumentsList);
|
|
14796
15823
|
const connectionCode = requiredOption(options, "code");
|
|
14797
|
-
const rootPath = (0,
|
|
15824
|
+
const rootPath = (0, import_node_path15.resolve)(options.root ?? process.cwd());
|
|
14798
15825
|
const serviceManagerPreference = requestedServiceManagerPreference(options);
|
|
14799
15826
|
await validateExplicitServiceManagerPreference(serviceManagerPreference);
|
|
14800
15827
|
await assertConnectionRuntimeCanConverge(store, serviceManagerPreference);
|
|
@@ -15146,7 +16173,7 @@ async function reachableRuntimeStatus2(store) {
|
|
|
15146
16173
|
}
|
|
15147
16174
|
async function readOptionalFile2(path4) {
|
|
15148
16175
|
try {
|
|
15149
|
-
return await (0,
|
|
16176
|
+
return await (0, import_promises20.readFile)(path4, "utf8");
|
|
15150
16177
|
} catch {
|
|
15151
16178
|
return "";
|
|
15152
16179
|
}
|
|
@@ -15175,13 +16202,13 @@ function delay7(milliseconds) {
|
|
|
15175
16202
|
setTimeout(resolvePromise, milliseconds);
|
|
15176
16203
|
});
|
|
15177
16204
|
}
|
|
15178
|
-
var
|
|
16205
|
+
var import_promises20, import_node_path15, defaultRelayOrigin;
|
|
15179
16206
|
var init_cli = __esm({
|
|
15180
16207
|
"../machine-connector/dist/cli.js"() {
|
|
15181
16208
|
"use strict";
|
|
15182
16209
|
init_cjs_shims();
|
|
15183
|
-
|
|
15184
|
-
|
|
16210
|
+
import_promises20 = require("fs/promises");
|
|
16211
|
+
import_node_path15 = require("path");
|
|
15185
16212
|
init_daemon();
|
|
15186
16213
|
init_daemon_reconcile();
|
|
15187
16214
|
init_doctor();
|
|
@@ -15478,7 +16505,7 @@ function getApiKeyOrUndefined() {
|
|
|
15478
16505
|
|
|
15479
16506
|
// src/utils/http.ts
|
|
15480
16507
|
function getUserAgent() {
|
|
15481
|
-
return `moxt-cli/${"0.11.0-beta.
|
|
16508
|
+
return `moxt-cli/${"0.11.0-beta.8"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
|
|
15482
16509
|
}
|
|
15483
16510
|
async function sendRequest(method, path4, init) {
|
|
15484
16511
|
return await fetch(`${getApiBaseUrl()}${path4}`, {
|
|
@@ -22390,10 +23417,10 @@ function resolveAll(constructs2, events, context) {
|
|
|
22390
23417
|
const called = [];
|
|
22391
23418
|
let index2 = -1;
|
|
22392
23419
|
while (++index2 < constructs2.length) {
|
|
22393
|
-
const
|
|
22394
|
-
if (
|
|
22395
|
-
events =
|
|
22396
|
-
called.push(
|
|
23420
|
+
const resolve11 = constructs2[index2].resolveAll;
|
|
23421
|
+
if (resolve11 && !called.includes(resolve11)) {
|
|
23422
|
+
events = resolve11(events, context);
|
|
23423
|
+
called.push(resolve11);
|
|
22397
23424
|
}
|
|
22398
23425
|
}
|
|
22399
23426
|
return events;
|
|
@@ -28876,7 +29903,7 @@ function registerWorkspaceCommand(program3) {
|
|
|
28876
29903
|
// src/commands/workflow.ts
|
|
28877
29904
|
init_cjs_shims();
|
|
28878
29905
|
var fs5 = __toESM(require("fs"), 1);
|
|
28879
|
-
var
|
|
29906
|
+
var import_node_path16 = require("path");
|
|
28880
29907
|
var import_node_util6 = require("util");
|
|
28881
29908
|
var MAX_DESC_LENGTH = 5e3;
|
|
28882
29909
|
var MAX_COMMENT_CONTENT_LENGTH = 5e3;
|
|
@@ -29370,7 +30397,7 @@ async function resolveLinkedLinkTitles(item, workspaceId) {
|
|
|
29370
30397
|
`/files/read-by-url?url=${encodeURIComponent(link.url)}`
|
|
29371
30398
|
);
|
|
29372
30399
|
if (!response.ok || response.data.type !== "file") return link.url;
|
|
29373
|
-
return
|
|
30400
|
+
return import_node_path16.posix.basename(response.data.path) || link.url;
|
|
29374
30401
|
} catch {
|
|
29375
30402
|
return link.url;
|
|
29376
30403
|
}
|
|
@@ -30064,7 +31091,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
|
|
|
30064
31091
|
var MAX_BATCH_SIZE = 100;
|
|
30065
31092
|
function commonLabels() {
|
|
30066
31093
|
return {
|
|
30067
|
-
cli_version: "0.11.0-beta.
|
|
31094
|
+
cli_version: "0.11.0-beta.8",
|
|
30068
31095
|
node_version: process.versions.node,
|
|
30069
31096
|
os: (0, import_node_os11.platform)(),
|
|
30070
31097
|
arch: (0, import_node_os11.arch)(),
|
|
@@ -30110,7 +31137,7 @@ async function flush() {
|
|
|
30110
31137
|
}
|
|
30111
31138
|
const batch = buffer.splice(0, MAX_BATCH_SIZE);
|
|
30112
31139
|
const payload = {
|
|
30113
|
-
release_id: "0.11.0-beta.
|
|
31140
|
+
release_id: "0.11.0-beta.8",
|
|
30114
31141
|
client_type: "cli",
|
|
30115
31142
|
metric_data_list: batch.map((m) => ({
|
|
30116
31143
|
profile: "cli",
|
|
@@ -30311,7 +31338,7 @@ function registryWorker() {
|
|
|
30311
31338
|
|
|
30312
31339
|
// src/update/prompt.ts
|
|
30313
31340
|
init_cjs_shims();
|
|
30314
|
-
var
|
|
31341
|
+
var import_promises21 = require("readline/promises");
|
|
30315
31342
|
async function promptForUpdate(input, output, currentVersion, latestVersion, timeoutMs) {
|
|
30316
31343
|
output.write(`
|
|
30317
31344
|
A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion}
|
|
@@ -30324,7 +31351,7 @@ A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion
|
|
|
30324
31351
|
const controller = new AbortController();
|
|
30325
31352
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
30326
31353
|
timeout.unref();
|
|
30327
|
-
const readline = (0,
|
|
31354
|
+
const readline = (0, import_promises21.createInterface)({ input, output, terminal: true });
|
|
30328
31355
|
try {
|
|
30329
31356
|
const answer = await readline.question("", { signal: controller.signal });
|
|
30330
31357
|
if (answer.trim() === "1") return "update";
|
|
@@ -30427,7 +31454,7 @@ function commandPath2(command) {
|
|
|
30427
31454
|
|
|
30428
31455
|
// src/update/daemon-reconcile-hook.ts
|
|
30429
31456
|
init_cjs_shims();
|
|
30430
|
-
var
|
|
31457
|
+
var import_node_path17 = require("path");
|
|
30431
31458
|
function installDaemonReconcileHook(program3, cliVersion) {
|
|
30432
31459
|
program3.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
30433
31460
|
if (!isEligible2(actionCommand)) return;
|
|
@@ -30449,9 +31476,9 @@ function installDaemonReconcileHook(program3, cliVersion) {
|
|
|
30449
31476
|
await reconcileManagedDaemon2({
|
|
30450
31477
|
cliVersion,
|
|
30451
31478
|
commandArguments: ["machine", "daemon"],
|
|
30452
|
-
entrypointPath: (0,
|
|
31479
|
+
entrypointPath: (0, import_node_path17.resolve)(entrypointPath),
|
|
30453
31480
|
environment: {},
|
|
30454
|
-
nodePath: (0,
|
|
31481
|
+
nodePath: (0, import_node_path17.resolve)(process.execPath),
|
|
30455
31482
|
onActiveJobs: (count) => {
|
|
30456
31483
|
process.stderr.write(
|
|
30457
31484
|
`Warning: restarting the managed Connector will interrupt ${count} active ${count === 1 ? "Job" : "Jobs"}.
|
|
@@ -30493,9 +31520,9 @@ function commandPath3(command) {
|
|
|
30493
31520
|
}
|
|
30494
31521
|
|
|
30495
31522
|
// src/index.ts
|
|
30496
|
-
var program2 = createProgram("0.11.0-beta.
|
|
30497
|
-
installDaemonReconcileHook(program2, "0.11.0-beta.
|
|
30498
|
-
installUpdateHook(program2, "0.11.0-beta.
|
|
31523
|
+
var program2 = createProgram("0.11.0-beta.8");
|
|
31524
|
+
installDaemonReconcileHook(program2, "0.11.0-beta.8");
|
|
31525
|
+
installUpdateHook(program2, "0.11.0-beta.8");
|
|
30499
31526
|
instrumentProgram(program2);
|
|
30500
31527
|
installExitHandler();
|
|
30501
31528
|
program2.parseAsync(process.argv).then(async () => {
|