@sjawhar/claude-envoy 5.25.0 → 5.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/bin/envoy-send.ts +1 -1
- package/dist/codex-hook.js +229 -155
- package/dist/dispatch.js +233 -155
- package/dist/envoy-channel.js +285 -206
- package/dist/session-hook.js +213 -143
- package/hooks/codex-hook.ts +1 -1
- package/hooks/session-hook.ts +10 -8
- package/legion/skills/legion-architect/SKILL.md +1 -1
- package/legion/skills/legion-architect/references/design-gate.md +10 -9
- package/legion/skills/legion-retro/SKILL.md +2 -2
- package/legion/skills/legion-retro/references/pr-body-content.md +1 -1
- package/legion/skills/legion-worker/references/ci-checks.md +10 -6
- package/legion/skills/legion-worker/references/withheld-capability.md +1 -1
- package/package.json +1 -1
- package/src/codex/codex-server.ts +4 -3
- package/src/codex/codex-user-turns.ts +3 -1
- package/src/envoy-channel-server.ts +10 -8
- package/src/legion-claim.ts +4 -4
- package/src/legion-phase-hook.ts +1 -1
- package/src/user-turn-router.ts +2 -2
package/dist/dispatch.js
CHANGED
|
@@ -980,10 +980,10 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// ../envoy-client/bin/dispatch.ts
|
|
983
|
-
import { readFileSync as
|
|
983
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
984
984
|
|
|
985
985
|
// ../envoy-client/src/dispatch-cli.ts
|
|
986
|
-
import { closeSync as
|
|
986
|
+
import { closeSync as closeSync4, constants as constants4, fstatSync as fstatSync3, openSync as openSync4, readFileSync as readFileSync6 } from "fs";
|
|
987
987
|
|
|
988
988
|
// ../envoy-client/src/askgate-marker.ts
|
|
989
989
|
import { createHash, randomBytes } from "crypto";
|
|
@@ -19689,17 +19689,16 @@ function isFinalRefusal(error) {
|
|
|
19689
19689
|
|
|
19690
19690
|
// ../envoy-client/src/envoy-config.ts
|
|
19691
19691
|
import {
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
|
|
19695
|
-
|
|
19696
|
-
|
|
19697
|
-
|
|
19698
|
-
|
|
19699
|
-
|
|
19700
|
-
|
|
19701
|
-
|
|
19702
|
-
} from "fs";
|
|
19692
|
+
access,
|
|
19693
|
+
chmod,
|
|
19694
|
+
lstat,
|
|
19695
|
+
mkdtemp,
|
|
19696
|
+
open,
|
|
19697
|
+
readFile as readFile3,
|
|
19698
|
+
readlink,
|
|
19699
|
+
rm,
|
|
19700
|
+
stat
|
|
19701
|
+
} from "fs/promises";
|
|
19703
19702
|
import { homedir, tmpdir } from "os";
|
|
19704
19703
|
import * as path from "path";
|
|
19705
19704
|
|
|
@@ -19789,15 +19788,44 @@ function jsonErrorPosition(text) {
|
|
|
19789
19788
|
}
|
|
19790
19789
|
}
|
|
19791
19790
|
|
|
19791
|
+
// ../envoy-client/src/process-group.ts
|
|
19792
|
+
function killGroup(pid) {
|
|
19793
|
+
try {
|
|
19794
|
+
process.kill(-pid, "SIGKILL");
|
|
19795
|
+
} catch {}
|
|
19796
|
+
}
|
|
19797
|
+
var WATCH = 'exec 3<&0; (while read -r line <&3; do :; done; kill -s KILL -- -$$) </dev/null >/dev/null 2>&1 & exec "$0" "$@" </dev/null 3<&-';
|
|
19798
|
+
function groupWatchedBy(argv) {
|
|
19799
|
+
return ["/bin/sh", "-c", WATCH, ...argv];
|
|
19800
|
+
}
|
|
19801
|
+
function spawnWatched(argv, options) {
|
|
19802
|
+
const child = Bun.spawn(groupWatchedBy(argv), {
|
|
19803
|
+
...options,
|
|
19804
|
+
stdin: "pipe",
|
|
19805
|
+
detached: true
|
|
19806
|
+
});
|
|
19807
|
+
let closed = false;
|
|
19808
|
+
return {
|
|
19809
|
+
child,
|
|
19810
|
+
endGroup: () => {
|
|
19811
|
+
killGroup(child.pid);
|
|
19812
|
+
if (closed)
|
|
19813
|
+
return;
|
|
19814
|
+
closed = true;
|
|
19815
|
+
child.stdin.end();
|
|
19816
|
+
}
|
|
19817
|
+
};
|
|
19818
|
+
}
|
|
19819
|
+
|
|
19792
19820
|
// ../envoy-client/src/secret-file.ts
|
|
19793
|
-
import {
|
|
19821
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
19794
19822
|
function sendable(value) {
|
|
19795
19823
|
return !/[\s\p{Cc}]/u.test(value);
|
|
19796
19824
|
}
|
|
19797
|
-
function readSecretFile(variable, filePath) {
|
|
19825
|
+
async function readSecretFile(variable, filePath) {
|
|
19798
19826
|
let contents;
|
|
19799
19827
|
try {
|
|
19800
|
-
contents =
|
|
19828
|
+
contents = await readFile2(filePath, "utf8");
|
|
19801
19829
|
} catch (error) {
|
|
19802
19830
|
throw new Error(`${variable} names a file that could not be read (${readErrorCode(error)})`);
|
|
19803
19831
|
}
|
|
@@ -19932,20 +19960,28 @@ function describeSchemaIssue(filePath, error) {
|
|
|
19932
19960
|
}
|
|
19933
19961
|
return `${filePath}: ${issue.path.join(".")}: ${issue.message}`;
|
|
19934
19962
|
}
|
|
19935
|
-
function danglingLink(filePath) {
|
|
19963
|
+
async function danglingLink(filePath) {
|
|
19936
19964
|
try {
|
|
19937
|
-
return
|
|
19965
|
+
return (await lstat(filePath)).isSymbolicLink() ? await readlink(filePath) : null;
|
|
19938
19966
|
} catch {
|
|
19939
19967
|
return null;
|
|
19940
19968
|
}
|
|
19941
19969
|
}
|
|
19942
|
-
function
|
|
19970
|
+
async function exists(file) {
|
|
19971
|
+
try {
|
|
19972
|
+
await access(file);
|
|
19973
|
+
return true;
|
|
19974
|
+
} catch {
|
|
19975
|
+
return false;
|
|
19976
|
+
}
|
|
19977
|
+
}
|
|
19978
|
+
async function parseFile(filePath, schema, checkout) {
|
|
19943
19979
|
let raw;
|
|
19944
19980
|
try {
|
|
19945
|
-
raw =
|
|
19981
|
+
raw = await readFile3(filePath, "utf-8");
|
|
19946
19982
|
} catch (error) {
|
|
19947
19983
|
if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
|
|
19948
|
-
return { kind: "absent", link: danglingLink(filePath) };
|
|
19984
|
+
return { kind: "absent", link: checkout ? null : await danglingLink(filePath) };
|
|
19949
19985
|
}
|
|
19950
19986
|
return { kind: "invalid", reason: `${filePath}: could not be read (${messageFor(error)})` };
|
|
19951
19987
|
}
|
|
@@ -19973,53 +20009,77 @@ function parseFile(filePath, schema, checkout) {
|
|
|
19973
20009
|
}
|
|
19974
20010
|
var FAILURE_KEPT_MS = 60000;
|
|
19975
20011
|
var COMMAND_OUTCOMES = Symbol.for("legion.envoy-config.commands.v1");
|
|
20012
|
+
var COMMAND_RUNS = Symbol.for("legion.envoy-config.command-runs.v1");
|
|
19976
20013
|
var processGlobal = globalThis;
|
|
19977
20014
|
var commandOutcomes = processGlobal[COMMAND_OUTCOMES] ?? new Map;
|
|
19978
20015
|
processGlobal[COMMAND_OUTCOMES] = commandOutcomes;
|
|
19979
|
-
|
|
20016
|
+
var commandRuns = processGlobal[COMMAND_RUNS] ?? new Map;
|
|
20017
|
+
processGlobal[COMMAND_RUNS] = commandRuns;
|
|
20018
|
+
async function unnamedFile() {
|
|
20019
|
+
const directory = await mkdtemp(path.join(tmpdir(), "envoy-command-"));
|
|
20020
|
+
try {
|
|
20021
|
+
await chmod(directory, 448);
|
|
20022
|
+
return await open(path.join(directory, "stdout"), "wx+", 384);
|
|
20023
|
+
} finally {
|
|
20024
|
+
await rm(directory, { recursive: true, force: true });
|
|
20025
|
+
}
|
|
20026
|
+
}
|
|
20027
|
+
async function readOutput(file) {
|
|
20028
|
+
const output = Buffer.alloc((await file.stat()).size);
|
|
20029
|
+
let read = 0;
|
|
20030
|
+
while (read < output.length) {
|
|
20031
|
+
const { bytesRead } = await file.read(output, read, output.length - read, read);
|
|
20032
|
+
if (bytesRead === 0)
|
|
20033
|
+
break;
|
|
20034
|
+
read += bytesRead;
|
|
20035
|
+
}
|
|
20036
|
+
return output.toString("utf-8", 0, read);
|
|
20037
|
+
}
|
|
20038
|
+
async function runCommand(command, env, cwd) {
|
|
19980
20039
|
const timeoutMs = commandTimeoutMs(env);
|
|
19981
20040
|
const childEnv = {};
|
|
19982
20041
|
for (const [name, variable] of Object.entries(env)) {
|
|
19983
20042
|
if (variable !== undefined)
|
|
19984
20043
|
childEnv[name] = variable;
|
|
19985
20044
|
}
|
|
19986
|
-
const
|
|
20045
|
+
const file = await unnamedFile();
|
|
19987
20046
|
try {
|
|
19988
|
-
|
|
19989
|
-
const output = path.join(directory, "stdout");
|
|
19990
|
-
const fd = openSync2(output, "wx", 384);
|
|
19991
|
-
let result;
|
|
20047
|
+
let watched;
|
|
19992
20048
|
try {
|
|
19993
|
-
|
|
20049
|
+
watched = spawnWatched(["/bin/sh", "-c", command], {
|
|
19994
20050
|
cwd,
|
|
19995
20051
|
env: childEnv,
|
|
19996
|
-
|
|
19997
|
-
|
|
19998
|
-
stderr: "ignore",
|
|
19999
|
-
timeout: timeoutMs,
|
|
20000
|
-
detached: true
|
|
20052
|
+
stdout: file.fd,
|
|
20053
|
+
stderr: "ignore"
|
|
20001
20054
|
});
|
|
20002
20055
|
} catch (error) {
|
|
20003
20056
|
return { failure: `could not start: ${messageFor(error)}`, timedOut: false };
|
|
20004
|
-
} finally {
|
|
20005
|
-
closeSync2(fd);
|
|
20006
20057
|
}
|
|
20058
|
+
const { child, endGroup } = watched;
|
|
20059
|
+
let timedOut = false;
|
|
20060
|
+
const timer = setTimeout(() => {
|
|
20061
|
+
timedOut = true;
|
|
20062
|
+
endGroup();
|
|
20063
|
+
}, timeoutMs);
|
|
20007
20064
|
try {
|
|
20008
|
-
|
|
20009
|
-
}
|
|
20010
|
-
|
|
20065
|
+
await child.exited;
|
|
20066
|
+
} finally {
|
|
20067
|
+
clearTimeout(timer);
|
|
20068
|
+
}
|
|
20069
|
+
endGroup();
|
|
20070
|
+
if (timedOut) {
|
|
20011
20071
|
return {
|
|
20012
20072
|
failure: `did not finish within ${timeoutMs / 1000} s, and does not run again in this process`,
|
|
20013
20073
|
timedOut: true
|
|
20014
20074
|
};
|
|
20015
20075
|
}
|
|
20016
|
-
if (
|
|
20076
|
+
if (child.exitCode !== 0) {
|
|
20017
20077
|
return {
|
|
20018
|
-
failure: `exited with ${
|
|
20078
|
+
failure: `exited with ${child.signalCode ?? `status ${child.exitCode}`}`,
|
|
20019
20079
|
timedOut: false
|
|
20020
20080
|
};
|
|
20021
20081
|
}
|
|
20022
|
-
const value =
|
|
20082
|
+
const value = (await readOutput(file)).trim();
|
|
20023
20083
|
if (value.length === 0)
|
|
20024
20084
|
return { failure: "printed nothing", timedOut: false };
|
|
20025
20085
|
if (!sendable(value)) {
|
|
@@ -20030,10 +20090,10 @@ function runCommand(command, env, cwd) {
|
|
|
20030
20090
|
}
|
|
20031
20091
|
return { value };
|
|
20032
20092
|
} finally {
|
|
20033
|
-
|
|
20093
|
+
await file.close();
|
|
20034
20094
|
}
|
|
20035
20095
|
}
|
|
20036
|
-
function fileValue(value, field, filePath, env, commands = "run") {
|
|
20096
|
+
async function fileValue(value, field, filePath, env, commands = "run") {
|
|
20037
20097
|
if (!value.startsWith("!")) {
|
|
20038
20098
|
if (!sendable(value)) {
|
|
20039
20099
|
throw new Error(`${filePath}: ${field} holds whitespace or a control character`);
|
|
@@ -20049,42 +20109,50 @@ function fileValue(value, field, filePath, env, commands = "run") {
|
|
|
20049
20109
|
throw new Error(`${filePath}: ${field}'s command has not run in this process yet, and this read does not run it`);
|
|
20050
20110
|
}
|
|
20051
20111
|
} else if (outcome === undefined || "failure" in outcome && !outcome.timedOut && Date.now() - outcome.at >= FAILURE_KEPT_MS) {
|
|
20052
|
-
|
|
20053
|
-
|
|
20112
|
+
let run = commandRuns.get(key);
|
|
20113
|
+
if (run === undefined) {
|
|
20114
|
+
run = runCommand(command, env, cwd).then((ran) => {
|
|
20115
|
+
const kept = { ...ran, at: Date.now() };
|
|
20116
|
+
commandOutcomes.set(key, kept);
|
|
20117
|
+
return kept;
|
|
20118
|
+
}).finally(() => commandRuns.delete(key));
|
|
20119
|
+
commandRuns.set(key, run);
|
|
20120
|
+
}
|
|
20121
|
+
outcome = await run;
|
|
20054
20122
|
}
|
|
20055
20123
|
if ("failure" in outcome)
|
|
20056
20124
|
throw new Error(`${filePath}: ${field}'s command ${outcome.failure}`);
|
|
20057
20125
|
return outcome.value;
|
|
20058
20126
|
}
|
|
20059
|
-
function statDevice(directory) {
|
|
20127
|
+
async function statDevice(directory) {
|
|
20060
20128
|
try {
|
|
20061
|
-
return
|
|
20129
|
+
return (await stat(directory)).dev;
|
|
20062
20130
|
} catch {
|
|
20063
20131
|
return;
|
|
20064
20132
|
}
|
|
20065
20133
|
}
|
|
20066
|
-
function moveNotice(oldFile, newFile, move, deviceOf) {
|
|
20067
|
-
const oldDevice = deviceOf(path.dirname(oldFile));
|
|
20134
|
+
async function moveNotice(oldFile, newFile, move, deviceOf) {
|
|
20135
|
+
const oldDevice = await deviceOf(path.dirname(oldFile));
|
|
20068
20136
|
let ancestor = path.dirname(newFile);
|
|
20069
|
-
let newDevice = deviceOf(ancestor);
|
|
20137
|
+
let newDevice = await deviceOf(ancestor);
|
|
20070
20138
|
while (newDevice === undefined && path.dirname(ancestor) !== ancestor) {
|
|
20071
20139
|
ancestor = path.dirname(ancestor);
|
|
20072
|
-
newDevice = deviceOf(ancestor);
|
|
20140
|
+
newDevice = await deviceOf(ancestor);
|
|
20073
20141
|
}
|
|
20074
20142
|
if (oldDevice !== undefined && newDevice !== undefined && oldDevice !== newDevice) {
|
|
20075
20143
|
return `${oldFile} is not read, and is on another filesystem than ${newFile} (a mount): create ${newFile}, and move ${oldFile} on the machine that owns it`;
|
|
20076
20144
|
}
|
|
20077
20145
|
return `${oldFile} is not read: ${move}`;
|
|
20078
20146
|
}
|
|
20079
|
-
function oldUserFileNotice(filePath, env, deviceOf) {
|
|
20147
|
+
async function oldUserFileNotice(filePath, env, deviceOf) {
|
|
20080
20148
|
const home = nonEmpty(env.HOME) ?? homedir();
|
|
20081
20149
|
const old = path.join(home, ".config", "opencode", "envoy.json");
|
|
20082
|
-
if (!
|
|
20150
|
+
if (!await exists(old))
|
|
20083
20151
|
return;
|
|
20084
20152
|
const selected = path.resolve(filePath);
|
|
20085
20153
|
const userFile = path.resolve(home, ".config", "legion", "envoy.json");
|
|
20086
20154
|
if (selected === userFile) {
|
|
20087
|
-
return moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
|
|
20155
|
+
return await moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
|
|
20088
20156
|
}
|
|
20089
20157
|
const profileFile = PLUGIN_HARNESSES.map((harness) => namedDirectory(harness, env)).some((directory) => directory !== undefined && path.isAbsolute(directory) && selected === path.resolve(directory, "envoy.json"));
|
|
20090
20158
|
if (profileFile) {
|
|
@@ -20102,14 +20170,18 @@ function missingConfigNotice(filePath, missing, off) {
|
|
|
20102
20170
|
const old = missing.oldUserFileNotice === undefined ? "" : `; ${missing.oldUserFileNotice}`;
|
|
20103
20171
|
return `no envoy.json at ${filePath}${link}: ${off}${old}`;
|
|
20104
20172
|
}
|
|
20105
|
-
function readEnvoyConfig(filePath, env, options) {
|
|
20173
|
+
async function readEnvoyConfig(filePath, env, options) {
|
|
20106
20174
|
const deviceOf = options.deviceOf ?? statDevice;
|
|
20107
|
-
const chosen = parseFile(filePath, EnvoyFileSchema, false);
|
|
20108
|
-
if (chosen.kind === "invalid")
|
|
20109
|
-
return { kind: "failed", path: filePath, error: chosen.reason };
|
|
20110
20175
|
const resolvedChosen = path.resolve(filePath);
|
|
20111
20176
|
const checkoutPath = path.resolve(options.cwd, ".envoy", "envoy.json");
|
|
20112
|
-
const
|
|
20177
|
+
const oldCheckout = path.resolve(options.cwd, ".opencode", "envoy.json");
|
|
20178
|
+
const [chosen, checkoutFile, oldCheckoutThere] = await Promise.all([
|
|
20179
|
+
parseFile(filePath, EnvoyFileSchema, false),
|
|
20180
|
+
checkoutPath === resolvedChosen ? Promise.resolve({ kind: "absent", link: null }) : parseFile(checkoutPath, CheckoutFileSchema, true),
|
|
20181
|
+
oldCheckout === resolvedChosen ? Promise.resolve(false) : exists(oldCheckout)
|
|
20182
|
+
]);
|
|
20183
|
+
if (chosen.kind === "invalid")
|
|
20184
|
+
return { kind: "failed", path: filePath, error: chosen.reason };
|
|
20113
20185
|
const own = chosen.kind === "valid" ? chosen.settings : {};
|
|
20114
20186
|
let checkout = null;
|
|
20115
20187
|
if (checkoutFile.kind === "invalid") {
|
|
@@ -20123,11 +20195,11 @@ function readEnvoyConfig(filePath, env, options) {
|
|
|
20123
20195
|
askgateError: Object.hasOwn(checkoutFile.settings, "askgate") ? `askgate in ${checkoutPath} is not read; set it in ${filePath}` : null
|
|
20124
20196
|
};
|
|
20125
20197
|
}
|
|
20126
|
-
const
|
|
20127
|
-
const warnings = oldCheckout !== resolvedChosen &&
|
|
20128
|
-
moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
|
|
20198
|
+
const checkoutMissing = checkoutPath === resolvedChosen ? chosen.kind === "absent" : checkoutFile.kind === "absent" || checkoutFile.kind === "invalid" && !await exists(checkoutPath);
|
|
20199
|
+
const warnings = oldCheckout !== resolvedChosen && checkoutMissing && oldCheckoutThere ? [
|
|
20200
|
+
await moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
|
|
20129
20201
|
] : [];
|
|
20130
|
-
const unreadOldUserFile = chosen.kind === "absent" ? oldUserFileNotice(filePath, env, deviceOf) : undefined;
|
|
20202
|
+
const unreadOldUserFile = chosen.kind === "absent" ? await oldUserFileNotice(filePath, env, deviceOf) : undefined;
|
|
20131
20203
|
return {
|
|
20132
20204
|
kind: "read",
|
|
20133
20205
|
path: filePath,
|
|
@@ -20155,10 +20227,10 @@ function bearerCredential(token) {
|
|
|
20155
20227
|
secret: () => token
|
|
20156
20228
|
};
|
|
20157
20229
|
}
|
|
20158
|
-
function bearerSource(env, section, written) {
|
|
20230
|
+
async function bearerSource(env, section, written) {
|
|
20159
20231
|
const pointer = nonEmpty(env[`${section}_TOKEN_FILE`]);
|
|
20160
20232
|
if (pointer !== undefined) {
|
|
20161
|
-
return { kind: "variable", token: readSecretFile(`${section}_TOKEN_FILE`, pointer) };
|
|
20233
|
+
return { kind: "variable", token: await readSecretFile(`${section}_TOKEN_FILE`, pointer) };
|
|
20162
20234
|
}
|
|
20163
20235
|
const plain = nonEmpty(env[`${section}_TOKEN`]);
|
|
20164
20236
|
if (plain !== undefined) {
|
|
@@ -20170,7 +20242,7 @@ function bearerSource(env, section, written) {
|
|
|
20170
20242
|
const bearer = written();
|
|
20171
20243
|
return bearer === undefined ? { kind: "none" } : { kind: "file", ...bearer };
|
|
20172
20244
|
}
|
|
20173
|
-
function fileBearer(bearer, url, section, env, commands = "run") {
|
|
20245
|
+
async function fileBearer(bearer, url, section, env, commands = "run") {
|
|
20174
20246
|
const named = httpUrl2(url)?.origin;
|
|
20175
20247
|
const paired = httpUrl2(bearer.server)?.origin;
|
|
20176
20248
|
if (named !== paired) {
|
|
@@ -29725,30 +29797,30 @@ async function sendWithProof(proved, url, options, signal) {
|
|
|
29725
29797
|
import { createPrivateKey, randomUUID as randomUUID2 } from "crypto";
|
|
29726
29798
|
import { constants as constants3 } from "fs";
|
|
29727
29799
|
import {
|
|
29728
|
-
access,
|
|
29729
|
-
lstat as
|
|
29800
|
+
access as access2,
|
|
29801
|
+
lstat as lstat3,
|
|
29730
29802
|
mkdir,
|
|
29731
|
-
open as
|
|
29732
|
-
readFile as
|
|
29733
|
-
readlink,
|
|
29803
|
+
open as open3,
|
|
29804
|
+
readFile as readFile4,
|
|
29805
|
+
readlink as readlink2,
|
|
29734
29806
|
rename as rename2,
|
|
29735
|
-
rm as
|
|
29736
|
-
stat as
|
|
29807
|
+
rm as rm3,
|
|
29808
|
+
stat as stat3
|
|
29737
29809
|
} from "fs/promises";
|
|
29738
29810
|
import { userInfo } from "os";
|
|
29739
29811
|
import { dirname as dirname3, isAbsolute as isAbsolute3, join as join5 } from "path";
|
|
29740
29812
|
|
|
29741
29813
|
// ../cipher-client/src/device-login-lock.ts
|
|
29742
29814
|
import { randomUUID } from "crypto";
|
|
29743
|
-
import { closeSync as
|
|
29815
|
+
import { closeSync as closeSync2, constants as constants2, fstatSync, openSync as openSync2, readSync } from "fs";
|
|
29744
29816
|
import {
|
|
29745
29817
|
link,
|
|
29746
|
-
lstat,
|
|
29747
|
-
open,
|
|
29818
|
+
lstat as lstat2,
|
|
29819
|
+
open as open2,
|
|
29748
29820
|
readdir as readdir2,
|
|
29749
29821
|
rename,
|
|
29750
|
-
rm,
|
|
29751
|
-
stat,
|
|
29822
|
+
rm as rm2,
|
|
29823
|
+
stat as stat2,
|
|
29752
29824
|
utimes
|
|
29753
29825
|
} from "fs/promises";
|
|
29754
29826
|
import { basename as basename2, dirname as dirname2, join as join4 } from "path";
|
|
@@ -30166,7 +30238,7 @@ var LOCK_RETRY_MS = 100;
|
|
|
30166
30238
|
var STEAL_STALE_MS = 5000;
|
|
30167
30239
|
async function statOrNone(path, what) {
|
|
30168
30240
|
try {
|
|
30169
|
-
return await
|
|
30241
|
+
return await lstat2(path);
|
|
30170
30242
|
} catch (error) {
|
|
30171
30243
|
if (readErrorCode(error) === "ENOENT")
|
|
30172
30244
|
return null;
|
|
@@ -30176,7 +30248,7 @@ async function statOrNone(path, what) {
|
|
|
30176
30248
|
async function createOwn(path, value, named) {
|
|
30177
30249
|
let handle;
|
|
30178
30250
|
try {
|
|
30179
|
-
handle = await
|
|
30251
|
+
handle = await open2(path, "wx", 384);
|
|
30180
30252
|
} catch (error) {
|
|
30181
30253
|
if (readErrorCode(error) === "EEXIST")
|
|
30182
30254
|
return false;
|
|
@@ -30192,7 +30264,7 @@ async function createOwn(path, value, named) {
|
|
|
30192
30264
|
async function look(path, what) {
|
|
30193
30265
|
let handle;
|
|
30194
30266
|
try {
|
|
30195
|
-
handle = await
|
|
30267
|
+
handle = await open2(path, LOCK_READ);
|
|
30196
30268
|
} catch (error) {
|
|
30197
30269
|
if (readErrorCode(error) === "ENOENT")
|
|
30198
30270
|
return null;
|
|
@@ -30229,7 +30301,7 @@ async function removeIfStill(path, isIt, what) {
|
|
|
30229
30301
|
const same = took !== null && isIt(took);
|
|
30230
30302
|
if (!same)
|
|
30231
30303
|
await link(moved, path).catch(() => {});
|
|
30232
|
-
await
|
|
30304
|
+
await rm2(moved, { force: true }).catch((error) => {
|
|
30233
30305
|
throw new Error(`remove ${what}, moved aside: ${readErrorCode(error)}`);
|
|
30234
30306
|
});
|
|
30235
30307
|
return same;
|
|
@@ -30316,7 +30388,7 @@ async function withLoginLock(path, named, work, options = {}) {
|
|
|
30316
30388
|
function loginLockHeldBy(path, pid) {
|
|
30317
30389
|
let fd;
|
|
30318
30390
|
try {
|
|
30319
|
-
fd =
|
|
30391
|
+
fd = openSync2(`${path}.lock`, LOCK_READ);
|
|
30320
30392
|
} catch {
|
|
30321
30393
|
return false;
|
|
30322
30394
|
}
|
|
@@ -30330,7 +30402,7 @@ function loginLockHeldBy(path, pid) {
|
|
|
30330
30402
|
return false;
|
|
30331
30403
|
} finally {
|
|
30332
30404
|
try {
|
|
30333
|
-
|
|
30405
|
+
closeSync2(fd);
|
|
30334
30406
|
} catch {}
|
|
30335
30407
|
}
|
|
30336
30408
|
}
|
|
@@ -30341,9 +30413,9 @@ async function removeUntouched(dir, left) {
|
|
|
30341
30413
|
const names = await readdir2(dir).catch(() => []);
|
|
30342
30414
|
for (const name of names.filter(left)) {
|
|
30343
30415
|
const path = join4(dir, name);
|
|
30344
|
-
const info = await
|
|
30416
|
+
const info = await stat2(path).catch(() => null);
|
|
30345
30417
|
if (info !== null && Date.now() - info.mtimeMs > DEVICE_LOGIN_STALE_LOCK_MS) {
|
|
30346
|
-
await
|
|
30418
|
+
await rm2(path, { force: true }).catch(() => {});
|
|
30347
30419
|
}
|
|
30348
30420
|
}
|
|
30349
30421
|
}
|
|
@@ -30392,7 +30464,7 @@ var systemFiles = new Map;
|
|
|
30392
30464
|
async function systemFile(file) {
|
|
30393
30465
|
let info;
|
|
30394
30466
|
try {
|
|
30395
|
-
info = await
|
|
30467
|
+
info = await stat3(file);
|
|
30396
30468
|
} catch {
|
|
30397
30469
|
return null;
|
|
30398
30470
|
}
|
|
@@ -30400,7 +30472,7 @@ async function systemFile(file) {
|
|
|
30400
30472
|
const kept = systemFiles.get(file);
|
|
30401
30473
|
if (kept?.status === status)
|
|
30402
30474
|
return kept.text;
|
|
30403
|
-
const text = await
|
|
30475
|
+
const text = await readFile4(file, "utf8").catch(() => null);
|
|
30404
30476
|
if (text === null)
|
|
30405
30477
|
systemFiles.delete(file);
|
|
30406
30478
|
else
|
|
@@ -30488,7 +30560,7 @@ async function checkLinkOnTheWay(info, what) {
|
|
|
30488
30560
|
}
|
|
30489
30561
|
async function lstatOnTheWay(path, what) {
|
|
30490
30562
|
try {
|
|
30491
|
-
return await
|
|
30563
|
+
return await lstat3(path);
|
|
30492
30564
|
} catch (error) {
|
|
30493
30565
|
if (readErrorCode(error) === "ENOENT")
|
|
30494
30566
|
return null;
|
|
@@ -30524,7 +30596,7 @@ async function walkTheWay(path, what, meet) {
|
|
|
30524
30596
|
throw notARegularFile("a loop of links");
|
|
30525
30597
|
let target;
|
|
30526
30598
|
try {
|
|
30527
|
-
target = await
|
|
30599
|
+
target = await readlink2(next);
|
|
30528
30600
|
} catch (error) {
|
|
30529
30601
|
const code = readErrorCode(error);
|
|
30530
30602
|
if (code !== "EINVAL" && code !== "ENOENT") {
|
|
@@ -30573,7 +30645,7 @@ async function checkDirectoriesOnTheWay(dir, what) {
|
|
|
30573
30645
|
async function checkLoginDirectory(dir, absent, what = `the directory of ${DEVICE_LOGIN_FILE_NAMED}`) {
|
|
30574
30646
|
let info;
|
|
30575
30647
|
try {
|
|
30576
|
-
info = await
|
|
30648
|
+
info = await stat3(dir);
|
|
30577
30649
|
} catch (error) {
|
|
30578
30650
|
if (absent !== undefined && readErrorCode(error) === "ENOENT")
|
|
30579
30651
|
throw absent();
|
|
@@ -30610,14 +30682,14 @@ async function deviceLoginPlace(path) {
|
|
|
30610
30682
|
await deviceLoginDirectory(path);
|
|
30611
30683
|
const dir = dirname3(path);
|
|
30612
30684
|
try {
|
|
30613
|
-
await
|
|
30685
|
+
await access2(dir, constants3.W_OK | constants3.X_OK);
|
|
30614
30686
|
} catch (error) {
|
|
30615
30687
|
const code = readErrorCode(error);
|
|
30616
30688
|
throw new Error(`this user cannot enter and write to the directory of ${DEVICE_LOGIN_FILE_NAMED}: ${code}${code === "EACCES" ? "; run chmod 700 on it" : ""}`);
|
|
30617
30689
|
}
|
|
30618
30690
|
let info;
|
|
30619
30691
|
try {
|
|
30620
|
-
info = await
|
|
30692
|
+
info = await stat3(path);
|
|
30621
30693
|
} catch (error) {
|
|
30622
30694
|
if (readErrorCode(error) === "ENOENT")
|
|
30623
30695
|
return;
|
|
@@ -30638,7 +30710,7 @@ async function checkLinkDirectories(path, absent) {
|
|
|
30638
30710
|
}
|
|
30639
30711
|
let info;
|
|
30640
30712
|
try {
|
|
30641
|
-
info = await
|
|
30713
|
+
info = await lstat3(at);
|
|
30642
30714
|
} catch (error) {
|
|
30643
30715
|
if (readErrorCode(error) === "ENOENT")
|
|
30644
30716
|
return;
|
|
@@ -30650,7 +30722,7 @@ async function checkLinkDirectories(path, absent) {
|
|
|
30650
30722
|
throw notARegularFile("a loop of links");
|
|
30651
30723
|
let target;
|
|
30652
30724
|
try {
|
|
30653
|
-
target = await
|
|
30725
|
+
target = await readlink2(at);
|
|
30654
30726
|
} catch (error) {
|
|
30655
30727
|
const code = readErrorCode(error);
|
|
30656
30728
|
if (code === "EINVAL" || code === "ENOENT")
|
|
@@ -30667,7 +30739,7 @@ async function readDeviceLogin(path) {
|
|
|
30667
30739
|
await checkLinkDirectories(path, absent);
|
|
30668
30740
|
let handle;
|
|
30669
30741
|
try {
|
|
30670
|
-
handle = await
|
|
30742
|
+
handle = await open3(path, LOGIN_READ);
|
|
30671
30743
|
} catch (error) {
|
|
30672
30744
|
throw readErrorCode(error) === "ENOENT" ? absent() : refusedBy(error, `read ${DEVICE_LOGIN_FILE_NAMED}`);
|
|
30673
30745
|
}
|
|
@@ -30778,7 +30850,7 @@ async function saveDeviceLogin(path, login, held, keep = false) {
|
|
|
30778
30850
|
let whole = false;
|
|
30779
30851
|
try {
|
|
30780
30852
|
try {
|
|
30781
|
-
const handle = await
|
|
30853
|
+
const handle = await open3(temp, "wx", 384);
|
|
30782
30854
|
try {
|
|
30783
30855
|
await handle.writeFile(data);
|
|
30784
30856
|
await handle.sync();
|
|
@@ -30797,10 +30869,10 @@ async function saveDeviceLogin(path, login, held, keep = false) {
|
|
|
30797
30869
|
} catch (error) {
|
|
30798
30870
|
throw keep && whole ? await keptCopy(temp, path, error) : error;
|
|
30799
30871
|
} finally {
|
|
30800
|
-
await
|
|
30872
|
+
await rm3(temp, { force: true }).catch(() => {});
|
|
30801
30873
|
}
|
|
30802
30874
|
try {
|
|
30803
|
-
const handle = await
|
|
30875
|
+
const handle = await open3(dir, "r");
|
|
30804
30876
|
try {
|
|
30805
30877
|
await handle.sync();
|
|
30806
30878
|
} finally {
|
|
@@ -31447,14 +31519,14 @@ function poolIdentity(options) {
|
|
|
31447
31519
|
}
|
|
31448
31520
|
|
|
31449
31521
|
// ../cipher-client/src/projected-token.ts
|
|
31450
|
-
import { readFile as
|
|
31522
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
31451
31523
|
function projectedToken(path, variable) {
|
|
31452
31524
|
const named = `the projected service-account token ${variable} names`;
|
|
31453
31525
|
return {
|
|
31454
31526
|
async read(signal) {
|
|
31455
31527
|
let contents;
|
|
31456
31528
|
try {
|
|
31457
|
-
contents = await
|
|
31529
|
+
contents = await readFile5(path, {
|
|
31458
31530
|
encoding: "utf8",
|
|
31459
31531
|
...signal === undefined ? {} : { signal }
|
|
31460
31532
|
});
|
|
@@ -31772,14 +31844,14 @@ function brokerCredential(env, session, read) {
|
|
|
31772
31844
|
}
|
|
31773
31845
|
|
|
31774
31846
|
// ../envoy-client/src/file-token-credential.ts
|
|
31775
|
-
import { readFileSync as
|
|
31847
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
31776
31848
|
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
31777
31849
|
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
31778
31850
|
var PKCS8_LABEL = "PRIVATE KEY";
|
|
31779
31851
|
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
31780
31852
|
function readNamed(variable, filePath) {
|
|
31781
31853
|
try {
|
|
31782
|
-
return
|
|
31854
|
+
return readFileSync2(filePath, "utf8");
|
|
31783
31855
|
} catch (error) {
|
|
31784
31856
|
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
31785
31857
|
}
|
|
@@ -31867,8 +31939,8 @@ function lostDispatchUrlNotice(env, config) {
|
|
|
31867
31939
|
...old === undefined ? [] : [old]
|
|
31868
31940
|
].join("; ");
|
|
31869
31941
|
}
|
|
31870
|
-
function dispatchSettings(env, config, options = {}) {
|
|
31871
|
-
const target = dispatchTarget(env, config, options.tokenFiles === true);
|
|
31942
|
+
async function dispatchSettings(env, config, options = {}) {
|
|
31943
|
+
const target = await dispatchTarget(env, config, options.tokenFiles === true);
|
|
31872
31944
|
if (!target.enabled)
|
|
31873
31945
|
return target;
|
|
31874
31946
|
const { url, urlSetting, source } = target;
|
|
@@ -31879,7 +31951,7 @@ function dispatchSettings(env, config, options = {}) {
|
|
|
31879
31951
|
else if (source.kind === "files")
|
|
31880
31952
|
credential = fileTokenCredential(source, url);
|
|
31881
31953
|
else {
|
|
31882
|
-
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "DISPATCH", env, options.commands));
|
|
31954
|
+
credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "DISPATCH", env, options.commands));
|
|
31883
31955
|
}
|
|
31884
31956
|
} catch (error) {
|
|
31885
31957
|
return offWithError(messageFor(error));
|
|
@@ -31899,8 +31971,8 @@ function dispatchSettings(env, config, options = {}) {
|
|
|
31899
31971
|
...linkNotice === undefined ? {} : { linkNotice }
|
|
31900
31972
|
};
|
|
31901
31973
|
}
|
|
31902
|
-
function dispatchUrl(env, config) {
|
|
31903
|
-
const target = dispatchTarget(env, config);
|
|
31974
|
+
async function dispatchUrl(env, config) {
|
|
31975
|
+
const target = await dispatchTarget(env, config);
|
|
31904
31976
|
return target.enabled ? target.url : undefined;
|
|
31905
31977
|
}
|
|
31906
31978
|
var BESIDE_TOKEN_FILES = [
|
|
@@ -32004,7 +32076,7 @@ function readTradeSetting(env) {
|
|
|
32004
32076
|
}
|
|
32005
32077
|
return { asOf: cut };
|
|
32006
32078
|
}
|
|
32007
|
-
function dispatchTarget(env, config, tokenFiles = false) {
|
|
32079
|
+
async function dispatchTarget(env, config, tokenFiles = false) {
|
|
32008
32080
|
if (config.kind === "failed")
|
|
32009
32081
|
return offWithError(config.error);
|
|
32010
32082
|
const files = tokenFilesTarget(env, config, tokenFiles);
|
|
@@ -32043,7 +32115,7 @@ function dispatchTarget(env, config, tokenFiles = false) {
|
|
|
32043
32115
|
let source = { kind: "none" };
|
|
32044
32116
|
if (!forced) {
|
|
32045
32117
|
try {
|
|
32046
|
-
source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
|
|
32118
|
+
source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : await bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
|
|
32047
32119
|
} catch (error) {
|
|
32048
32120
|
return offWithError(messageFor(error));
|
|
32049
32121
|
}
|
|
@@ -34333,12 +34405,12 @@ async function reviewCommand(context) {
|
|
|
34333
34405
|
}
|
|
34334
34406
|
|
|
34335
34407
|
// ../envoy-client/src/session-answers.ts
|
|
34336
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
34408
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
|
|
34337
34409
|
import { join as join7 } from "path";
|
|
34338
34410
|
|
|
34339
34411
|
// ../envoy-client/src/dispatch-session-directory.ts
|
|
34340
34412
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
34341
|
-
import { renameSync as renameSync2, rmSync as
|
|
34413
|
+
import { renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
34342
34414
|
import { homedir as homedir2 } from "os";
|
|
34343
34415
|
import { join as join6 } from "path";
|
|
34344
34416
|
var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
|
|
@@ -34361,7 +34433,7 @@ function writeAtomically(path, text) {
|
|
|
34361
34433
|
writeFileSync2(temporary, text, { mode: PRIVATE_FILE });
|
|
34362
34434
|
renameSync2(temporary, path);
|
|
34363
34435
|
} catch (error) {
|
|
34364
|
-
|
|
34436
|
+
rmSync2(temporary, { force: true });
|
|
34365
34437
|
throw error;
|
|
34366
34438
|
}
|
|
34367
34439
|
}
|
|
@@ -34504,7 +34576,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
34504
34576
|
var CACHE_FILE = "answers.json";
|
|
34505
34577
|
function readCacheFile(directory, url) {
|
|
34506
34578
|
try {
|
|
34507
|
-
const value = JSON.parse(
|
|
34579
|
+
const value = JSON.parse(readFileSync3(join7(directory, CACHE_FILE), "utf-8"));
|
|
34508
34580
|
if (typeof value === "object" && value !== null && "dispatch_url" in value && typeof value.dispatch_url === "string" && value.dispatch_url === url && "read_at" in value && typeof value.read_at === "string" && "total" in value && typeof value.total === "number" && "items" in value && Array.isArray(value.items)) {
|
|
34509
34581
|
return {
|
|
34510
34582
|
dispatch_url: value.dispatch_url,
|
|
@@ -35000,15 +35072,15 @@ async function executeDispatchTool(input) {
|
|
|
35000
35072
|
import { createHash as createHash3 } from "crypto";
|
|
35001
35073
|
import {
|
|
35002
35074
|
appendFileSync as appendFileSync2,
|
|
35003
|
-
closeSync as
|
|
35075
|
+
closeSync as closeSync3,
|
|
35004
35076
|
fstatSync as fstatSync2,
|
|
35005
35077
|
mkdirSync as mkdirSync3,
|
|
35006
|
-
openSync as
|
|
35078
|
+
openSync as openSync3,
|
|
35007
35079
|
readdirSync as readdirSync2,
|
|
35008
|
-
readFileSync as
|
|
35080
|
+
readFileSync as readFileSync4,
|
|
35009
35081
|
readSync as readSync2,
|
|
35010
|
-
rmSync as
|
|
35011
|
-
statSync as
|
|
35082
|
+
rmSync as rmSync3,
|
|
35083
|
+
statSync as statSync2,
|
|
35012
35084
|
writeFileSync as writeFileSync3
|
|
35013
35085
|
} from "fs";
|
|
35014
35086
|
import { join as join8 } from "path";
|
|
@@ -35028,7 +35100,7 @@ function ensureDirectory(dir) {
|
|
|
35028
35100
|
}
|
|
35029
35101
|
function readIfPresent(path) {
|
|
35030
35102
|
try {
|
|
35031
|
-
return
|
|
35103
|
+
return readFileSync4(path, "utf-8");
|
|
35032
35104
|
} catch (error) {
|
|
35033
35105
|
if (hasErrnoCode(error, "ENOENT"))
|
|
35034
35106
|
return;
|
|
@@ -35111,7 +35183,7 @@ function readSessionTitle(dir) {
|
|
|
35111
35183
|
function pruneSessions(root, now) {
|
|
35112
35184
|
const stamp = join8(root, PRUNED_STAMP);
|
|
35113
35185
|
try {
|
|
35114
|
-
if (now -
|
|
35186
|
+
if (now - statSync2(stamp).mtimeMs < PRUNE_INTERVAL_MS)
|
|
35115
35187
|
return;
|
|
35116
35188
|
} catch (error) {
|
|
35117
35189
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
@@ -35130,9 +35202,9 @@ function pruneSessions(root, now) {
|
|
|
35130
35202
|
continue;
|
|
35131
35203
|
const dir = join8(sessions, entry.name);
|
|
35132
35204
|
try {
|
|
35133
|
-
const idle = now -
|
|
35205
|
+
const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
|
|
35134
35206
|
if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {
|
|
35135
|
-
|
|
35207
|
+
rmSync3(dir, { recursive: true, force: true });
|
|
35136
35208
|
}
|
|
35137
35209
|
} catch (error) {
|
|
35138
35210
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
@@ -35146,12 +35218,12 @@ function pruneSessions(root, now) {
|
|
|
35146
35218
|
|
|
35147
35219
|
// ../envoy-client/src/process-ancestry.ts
|
|
35148
35220
|
import { execFileSync } from "child_process";
|
|
35149
|
-
import { readFileSync as
|
|
35221
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
35150
35222
|
var MAX_ANCESTORS = 64;
|
|
35151
35223
|
var PARENT_LOOKUP_MS = 1000;
|
|
35152
35224
|
function procParentPid(pid) {
|
|
35153
35225
|
try {
|
|
35154
|
-
const stat =
|
|
35226
|
+
const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
|
|
35155
35227
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
35156
35228
|
return Number.isInteger(parent) ? parent : undefined;
|
|
35157
35229
|
} catch {
|
|
@@ -35193,7 +35265,7 @@ function isAncestor(candidate, pid = process.pid) {
|
|
|
35193
35265
|
}
|
|
35194
35266
|
function procCommand(pid) {
|
|
35195
35267
|
try {
|
|
35196
|
-
return
|
|
35268
|
+
return readFileSync5(`/proc/${pid}/comm`, "utf8").trim();
|
|
35197
35269
|
} catch {
|
|
35198
35270
|
return;
|
|
35199
35271
|
}
|
|
@@ -35606,13 +35678,13 @@ function resolvedInterval(raw, fallback) {
|
|
|
35606
35678
|
return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
|
|
35607
35679
|
}
|
|
35608
35680
|
var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
|
|
35609
|
-
function natsSeedFromEnvironment(env) {
|
|
35681
|
+
async function natsSeedFromEnvironment(env) {
|
|
35610
35682
|
const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
|
|
35611
35683
|
if (file !== undefined) {
|
|
35612
35684
|
if (file === "")
|
|
35613
35685
|
throw new Error("NATS_NKEY_SEED_FILE is set but empty");
|
|
35614
35686
|
return {
|
|
35615
|
-
value: readSecretFile("NATS_NKEY_SEED_FILE", file),
|
|
35687
|
+
value: await readSecretFile("NATS_NKEY_SEED_FILE", file),
|
|
35616
35688
|
source: "the file NATS_NKEY_SEED_FILE names"
|
|
35617
35689
|
};
|
|
35618
35690
|
}
|
|
@@ -35641,23 +35713,23 @@ function requireFileServers(section, namedNatsUrls, filePath, remedy) {
|
|
|
35641
35713
|
throw new Error(`ENVOY_NATS_URL names other servers than ${filePath}'s envoy.natsUrls; set ${remedy} for them`);
|
|
35642
35714
|
}
|
|
35643
35715
|
}
|
|
35644
|
-
function natsSeed(env, section, namedNatsUrls, filePath) {
|
|
35645
|
-
const fromEnvironment = natsSeedFromEnvironment(env);
|
|
35716
|
+
async function natsSeed(env, section, namedNatsUrls, filePath) {
|
|
35717
|
+
const fromEnvironment = await natsSeedFromEnvironment(env);
|
|
35646
35718
|
if (fromEnvironment !== undefined || section.natsSeed === undefined)
|
|
35647
35719
|
return fromEnvironment;
|
|
35648
35720
|
requireFileServers(section, namedNatsUrls, filePath, "NATS_NKEY_SEED_FILE");
|
|
35649
35721
|
return {
|
|
35650
|
-
value: fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
|
|
35722
|
+
value: await fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
|
|
35651
35723
|
source: `envoy.natsSeed in ${filePath}`
|
|
35652
35724
|
};
|
|
35653
35725
|
}
|
|
35654
|
-
function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
35726
|
+
async function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
35655
35727
|
const named = nonEmpty(env.NATS_AUTH);
|
|
35656
35728
|
const auth = named !== undefined ? { value: named, source: NATS_AUTH_VAR } : section.natsAuth === undefined ? undefined : { value: section.natsAuth, source: `envoy.natsAuth in ${filePath}` };
|
|
35657
35729
|
if (auth !== undefined && auth.value !== "broker" && auth.value !== "none") {
|
|
35658
35730
|
throw new Error(`${auth.source} is neither broker nor none`);
|
|
35659
35731
|
}
|
|
35660
|
-
const seed = natsSeed(env, section, namedNatsUrls, filePath);
|
|
35732
|
+
const seed = await natsSeed(env, section, namedNatsUrls, filePath);
|
|
35661
35733
|
if (seed !== undefined) {
|
|
35662
35734
|
if (auth?.value === "broker") {
|
|
35663
35735
|
throw new Error(`${auth.source} is ${auth.value}, and ${seed.source} names an nkey seed: set one of the two`);
|
|
@@ -35702,7 +35774,7 @@ function plainHttpOffMachine(url) {
|
|
|
35702
35774
|
const host = URL.canParse(url) ? new URL(url) : undefined;
|
|
35703
35775
|
return host?.protocol === "http:" && !LOOPBACK_HOST2.test(host.hostname) ? host.hostname : undefined;
|
|
35704
35776
|
}
|
|
35705
|
-
function envoySettings(env, config, options = {}) {
|
|
35777
|
+
async function envoySettings(env, config, options = {}) {
|
|
35706
35778
|
if (config.kind === "failed")
|
|
35707
35779
|
return offWithError(config.error);
|
|
35708
35780
|
const section = config.envoy;
|
|
@@ -35733,7 +35805,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
35733
35805
|
let credential;
|
|
35734
35806
|
let noBrokerRoute = "";
|
|
35735
35807
|
try {
|
|
35736
|
-
const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
35808
|
+
const source = await bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
35737
35809
|
token: section.token,
|
|
35738
35810
|
field: "envoy.token",
|
|
35739
35811
|
path: config.path,
|
|
@@ -35746,7 +35818,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
35746
35818
|
if (!route.traded)
|
|
35747
35819
|
noBrokerRoute = route.gap;
|
|
35748
35820
|
} else {
|
|
35749
|
-
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
|
|
35821
|
+
credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "ENVOY", env));
|
|
35750
35822
|
}
|
|
35751
35823
|
} catch (error) {
|
|
35752
35824
|
return offWithError(messageFor(error));
|
|
@@ -35766,7 +35838,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
35766
35838
|
inbound = {
|
|
35767
35839
|
natsUrls,
|
|
35768
35840
|
natsServersSetting: natsSetting,
|
|
35769
|
-
natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
35841
|
+
natsCredential: await natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
35770
35842
|
};
|
|
35771
35843
|
} catch (error) {
|
|
35772
35844
|
inbound = error instanceof NoSessionNamedError ? { off: messageFor(error), noSessionNamed: true } : { off: messageFor(error) };
|
|
@@ -35850,26 +35922,28 @@ function startNotice(config, dispatch, envoy, nats, lost) {
|
|
|
35850
35922
|
}
|
|
35851
35923
|
return parts.length === 0 ? null : parts.join("; ");
|
|
35852
35924
|
}
|
|
35853
|
-
function sessionSettings(file, env, options) {
|
|
35925
|
+
async function sessionSettings(file, env, options) {
|
|
35854
35926
|
if (file.path === null) {
|
|
35855
35927
|
const off = offWithError(file.error);
|
|
35856
35928
|
return { dispatch: off, envoy: off, notice: `${file.error}: Dispatch and Envoy are off` };
|
|
35857
35929
|
}
|
|
35858
|
-
const config = readEnvoyConfig(file.path, env, options);
|
|
35859
|
-
const dispatch
|
|
35860
|
-
|
|
35930
|
+
const config = await readEnvoyConfig(file.path, env, options);
|
|
35931
|
+
const [dispatch, envoy] = await Promise.all([
|
|
35932
|
+
dispatchSettings(env, config, { session: options.session }),
|
|
35933
|
+
envoySettings(env, config, { nats: options.nats, session: options.session })
|
|
35934
|
+
]);
|
|
35861
35935
|
return {
|
|
35862
35936
|
dispatch,
|
|
35863
35937
|
envoy,
|
|
35864
35938
|
notice: startNotice(config, dispatch, envoy, options.nats !== false, config.kind === "read" ? lostDispatchUrlNotice(env, config) : undefined)
|
|
35865
35939
|
};
|
|
35866
35940
|
}
|
|
35867
|
-
function sessionDispatchSettings(file, env, options) {
|
|
35941
|
+
async function sessionDispatchSettings(file, env, options) {
|
|
35868
35942
|
if (file.path === null)
|
|
35869
35943
|
return { dispatch: offWithError(file.error), warnings: [], missing: null };
|
|
35870
|
-
const config = readEnvoyConfig(file.path, env, options);
|
|
35944
|
+
const config = await readEnvoyConfig(file.path, env, options);
|
|
35871
35945
|
return {
|
|
35872
|
-
dispatch: dispatchSettings(env, config, {
|
|
35946
|
+
dispatch: await dispatchSettings(env, config, {
|
|
35873
35947
|
commands: options.commands,
|
|
35874
35948
|
session: options.session,
|
|
35875
35949
|
tokenFiles: options.tokenFiles
|
|
@@ -35878,15 +35952,15 @@ function sessionDispatchSettings(file, env, options) {
|
|
|
35878
35952
|
missing: config.kind === "read" ? config.missing : null
|
|
35879
35953
|
};
|
|
35880
35954
|
}
|
|
35881
|
-
function sessionDispatchUrl(file, env, options) {
|
|
35955
|
+
async function sessionDispatchUrl(file, env, options) {
|
|
35882
35956
|
if (file.path === null)
|
|
35883
35957
|
return;
|
|
35884
|
-
return dispatchUrl(env, readEnvoyConfig(file.path, env, options));
|
|
35958
|
+
return dispatchUrl(env, await readEnvoyConfig(file.path, env, options));
|
|
35885
35959
|
}
|
|
35886
|
-
function sessionEnvoySettings(file, env, options) {
|
|
35960
|
+
async function sessionEnvoySettings(file, env, options) {
|
|
35887
35961
|
if (file.path === null)
|
|
35888
35962
|
return offWithError(file.error);
|
|
35889
|
-
return envoySettings(env, readEnvoyConfig(file.path, env, options), {
|
|
35963
|
+
return envoySettings(env, await readEnvoyConfig(file.path, env, options), {
|
|
35890
35964
|
nats: options.nats,
|
|
35891
35965
|
session: options.session
|
|
35892
35966
|
});
|
|
@@ -36635,7 +36709,11 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
36635
36709
|
}
|
|
36636
36710
|
const file = (env.DISPATCH_HOST === undefined ? null : handedConfigFile(env)) ?? sessionConfigFile(host, env);
|
|
36637
36711
|
if (parsed.dryRun && !dryRunAsksDispatch(parsed.tool, parsed.args)) {
|
|
36638
|
-
const settings = file.path === null ? null : sessionDispatchSettings(file, env, {
|
|
36712
|
+
const settings = file.path === null ? null : (await sessionDispatchSettings(file, env, {
|
|
36713
|
+
cwd: io.cwd,
|
|
36714
|
+
session: sessionId,
|
|
36715
|
+
tokenFiles: true
|
|
36716
|
+
})).dispatch;
|
|
36639
36717
|
const { problems } = await checkDispatchCall({
|
|
36640
36718
|
tool: parsed.tool,
|
|
36641
36719
|
args: parsed.args,
|
|
@@ -36652,7 +36730,7 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
36652
36730
|
if (file.path === null) {
|
|
36653
36731
|
return refuse(`dispatch: ${file.error}`, USAGE2, parsed.tool);
|
|
36654
36732
|
}
|
|
36655
|
-
const { dispatch: resolution, warnings } = sessionDispatchSettings(file, env, {
|
|
36733
|
+
const { dispatch: resolution, warnings } = await sessionDispatchSettings(file, env, {
|
|
36656
36734
|
cwd: io.cwd,
|
|
36657
36735
|
session: sessionId,
|
|
36658
36736
|
tokenFiles: true
|
|
@@ -36701,12 +36779,12 @@ ${result.text}`);
|
|
|
36701
36779
|
for (const file of fileOperands(argv)) {
|
|
36702
36780
|
let bytes;
|
|
36703
36781
|
try {
|
|
36704
|
-
const fd =
|
|
36782
|
+
const fd = openSync4(operandPath(io.cwd, file), constants4.O_RDONLY | constants4.O_NONBLOCK);
|
|
36705
36783
|
try {
|
|
36706
36784
|
if (fstatSync3(fd).isFile())
|
|
36707
|
-
bytes =
|
|
36785
|
+
bytes = readFileSync6(fd);
|
|
36708
36786
|
} finally {
|
|
36709
|
-
|
|
36787
|
+
closeSync4(fd);
|
|
36710
36788
|
}
|
|
36711
36789
|
} catch {}
|
|
36712
36790
|
files.push({ ...file, sha256: bytes === undefined ? null : bytesDigest(bytes) });
|
|
@@ -36737,7 +36815,7 @@ ${result.text}`);
|
|
|
36737
36815
|
let topics;
|
|
36738
36816
|
const readTopics = async () => {
|
|
36739
36817
|
try {
|
|
36740
|
-
const envoy = sessionEnvoySettings(file, env, {
|
|
36818
|
+
const envoy = await sessionEnvoySettings(file, env, {
|
|
36741
36819
|
cwd: io.cwd,
|
|
36742
36820
|
nats: false,
|
|
36743
36821
|
session: sessionId
|
|
@@ -36840,7 +36918,7 @@ ${result.text}`);
|
|
|
36840
36918
|
}
|
|
36841
36919
|
|
|
36842
36920
|
// ../envoy-client/bin/dispatch.ts
|
|
36843
|
-
var readText = (path) =>
|
|
36921
|
+
var readText = (path) => readFileSync7(path === "-" ? 0 : path, "utf-8");
|
|
36844
36922
|
var pending = [];
|
|
36845
36923
|
var writeTo = (stream) => (text) => {
|
|
36846
36924
|
const { promise, resolve } = Promise.withResolvers();
|