@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/codex-hook.js
CHANGED
|
@@ -980,7 +980,7 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// hooks/codex-hook.ts
|
|
983
|
-
import { rm as
|
|
983
|
+
import { rm as rm5 } from "fs/promises";
|
|
984
984
|
// ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/core/core.js
|
|
985
985
|
var NEVER = Object.freeze({
|
|
986
986
|
status: "aborted"
|
|
@@ -20620,17 +20620,16 @@ function isFinalRefusal(error) {
|
|
|
20620
20620
|
|
|
20621
20621
|
// ../envoy-client/src/envoy-config.ts
|
|
20622
20622
|
import {
|
|
20623
|
-
|
|
20624
|
-
|
|
20625
|
-
|
|
20626
|
-
|
|
20627
|
-
|
|
20628
|
-
|
|
20629
|
-
|
|
20630
|
-
|
|
20631
|
-
|
|
20632
|
-
|
|
20633
|
-
} from "fs";
|
|
20623
|
+
access,
|
|
20624
|
+
chmod,
|
|
20625
|
+
lstat,
|
|
20626
|
+
mkdtemp,
|
|
20627
|
+
open,
|
|
20628
|
+
readFile as readFile3,
|
|
20629
|
+
readlink,
|
|
20630
|
+
rm,
|
|
20631
|
+
stat
|
|
20632
|
+
} from "fs/promises";
|
|
20634
20633
|
import { homedir, tmpdir } from "os";
|
|
20635
20634
|
import * as path from "path";
|
|
20636
20635
|
|
|
@@ -20720,15 +20719,44 @@ function jsonErrorPosition(text) {
|
|
|
20720
20719
|
}
|
|
20721
20720
|
}
|
|
20722
20721
|
|
|
20722
|
+
// ../envoy-client/src/process-group.ts
|
|
20723
|
+
function killGroup(pid) {
|
|
20724
|
+
try {
|
|
20725
|
+
process.kill(-pid, "SIGKILL");
|
|
20726
|
+
} catch {}
|
|
20727
|
+
}
|
|
20728
|
+
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<&-';
|
|
20729
|
+
function groupWatchedBy(argv) {
|
|
20730
|
+
return ["/bin/sh", "-c", WATCH, ...argv];
|
|
20731
|
+
}
|
|
20732
|
+
function spawnWatched(argv, options) {
|
|
20733
|
+
const child = Bun.spawn(groupWatchedBy(argv), {
|
|
20734
|
+
...options,
|
|
20735
|
+
stdin: "pipe",
|
|
20736
|
+
detached: true
|
|
20737
|
+
});
|
|
20738
|
+
let closed = false;
|
|
20739
|
+
return {
|
|
20740
|
+
child,
|
|
20741
|
+
endGroup: () => {
|
|
20742
|
+
killGroup(child.pid);
|
|
20743
|
+
if (closed)
|
|
20744
|
+
return;
|
|
20745
|
+
closed = true;
|
|
20746
|
+
child.stdin.end();
|
|
20747
|
+
}
|
|
20748
|
+
};
|
|
20749
|
+
}
|
|
20750
|
+
|
|
20723
20751
|
// ../envoy-client/src/secret-file.ts
|
|
20724
|
-
import {
|
|
20752
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
20725
20753
|
function sendable(value) {
|
|
20726
20754
|
return !/[\s\p{Cc}]/u.test(value);
|
|
20727
20755
|
}
|
|
20728
|
-
function readSecretFile(variable, filePath) {
|
|
20756
|
+
async function readSecretFile(variable, filePath) {
|
|
20729
20757
|
let contents;
|
|
20730
20758
|
try {
|
|
20731
|
-
contents =
|
|
20759
|
+
contents = await readFile2(filePath, "utf8");
|
|
20732
20760
|
} catch (error) {
|
|
20733
20761
|
throw new Error(`${variable} names a file that could not be read (${readErrorCode(error)})`);
|
|
20734
20762
|
}
|
|
@@ -20863,20 +20891,28 @@ function describeSchemaIssue(filePath, error) {
|
|
|
20863
20891
|
}
|
|
20864
20892
|
return `${filePath}: ${issue.path.join(".")}: ${issue.message}`;
|
|
20865
20893
|
}
|
|
20866
|
-
function danglingLink(filePath) {
|
|
20894
|
+
async function danglingLink(filePath) {
|
|
20867
20895
|
try {
|
|
20868
|
-
return
|
|
20896
|
+
return (await lstat(filePath)).isSymbolicLink() ? await readlink(filePath) : null;
|
|
20869
20897
|
} catch {
|
|
20870
20898
|
return null;
|
|
20871
20899
|
}
|
|
20872
20900
|
}
|
|
20873
|
-
function
|
|
20901
|
+
async function exists(file) {
|
|
20902
|
+
try {
|
|
20903
|
+
await access(file);
|
|
20904
|
+
return true;
|
|
20905
|
+
} catch {
|
|
20906
|
+
return false;
|
|
20907
|
+
}
|
|
20908
|
+
}
|
|
20909
|
+
async function parseFile(filePath, schema, checkout) {
|
|
20874
20910
|
let raw;
|
|
20875
20911
|
try {
|
|
20876
|
-
raw =
|
|
20912
|
+
raw = await readFile3(filePath, "utf-8");
|
|
20877
20913
|
} catch (error) {
|
|
20878
20914
|
if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
|
|
20879
|
-
return { kind: "absent", link: danglingLink(filePath) };
|
|
20915
|
+
return { kind: "absent", link: checkout ? null : await danglingLink(filePath) };
|
|
20880
20916
|
}
|
|
20881
20917
|
return { kind: "invalid", reason: `${filePath}: could not be read (${messageFor(error)})` };
|
|
20882
20918
|
}
|
|
@@ -20904,53 +20940,77 @@ function parseFile(filePath, schema, checkout) {
|
|
|
20904
20940
|
}
|
|
20905
20941
|
var FAILURE_KEPT_MS = 60000;
|
|
20906
20942
|
var COMMAND_OUTCOMES = Symbol.for("legion.envoy-config.commands.v1");
|
|
20943
|
+
var COMMAND_RUNS = Symbol.for("legion.envoy-config.command-runs.v1");
|
|
20907
20944
|
var processGlobal = globalThis;
|
|
20908
20945
|
var commandOutcomes = processGlobal[COMMAND_OUTCOMES] ?? new Map;
|
|
20909
20946
|
processGlobal[COMMAND_OUTCOMES] = commandOutcomes;
|
|
20910
|
-
|
|
20947
|
+
var commandRuns = processGlobal[COMMAND_RUNS] ?? new Map;
|
|
20948
|
+
processGlobal[COMMAND_RUNS] = commandRuns;
|
|
20949
|
+
async function unnamedFile() {
|
|
20950
|
+
const directory = await mkdtemp(path.join(tmpdir(), "envoy-command-"));
|
|
20951
|
+
try {
|
|
20952
|
+
await chmod(directory, 448);
|
|
20953
|
+
return await open(path.join(directory, "stdout"), "wx+", 384);
|
|
20954
|
+
} finally {
|
|
20955
|
+
await rm(directory, { recursive: true, force: true });
|
|
20956
|
+
}
|
|
20957
|
+
}
|
|
20958
|
+
async function readOutput(file) {
|
|
20959
|
+
const output = Buffer.alloc((await file.stat()).size);
|
|
20960
|
+
let read = 0;
|
|
20961
|
+
while (read < output.length) {
|
|
20962
|
+
const { bytesRead } = await file.read(output, read, output.length - read, read);
|
|
20963
|
+
if (bytesRead === 0)
|
|
20964
|
+
break;
|
|
20965
|
+
read += bytesRead;
|
|
20966
|
+
}
|
|
20967
|
+
return output.toString("utf-8", 0, read);
|
|
20968
|
+
}
|
|
20969
|
+
async function runCommand(command, env, cwd) {
|
|
20911
20970
|
const timeoutMs = commandTimeoutMs(env);
|
|
20912
20971
|
const childEnv = {};
|
|
20913
20972
|
for (const [name, variable] of Object.entries(env)) {
|
|
20914
20973
|
if (variable !== undefined)
|
|
20915
20974
|
childEnv[name] = variable;
|
|
20916
20975
|
}
|
|
20917
|
-
const
|
|
20976
|
+
const file = await unnamedFile();
|
|
20918
20977
|
try {
|
|
20919
|
-
|
|
20920
|
-
const output = path.join(directory, "stdout");
|
|
20921
|
-
const fd = openSync(output, "wx", 384);
|
|
20922
|
-
let result;
|
|
20978
|
+
let watched;
|
|
20923
20979
|
try {
|
|
20924
|
-
|
|
20980
|
+
watched = spawnWatched(["/bin/sh", "-c", command], {
|
|
20925
20981
|
cwd,
|
|
20926
20982
|
env: childEnv,
|
|
20927
|
-
|
|
20928
|
-
|
|
20929
|
-
stderr: "ignore",
|
|
20930
|
-
timeout: timeoutMs,
|
|
20931
|
-
detached: true
|
|
20983
|
+
stdout: file.fd,
|
|
20984
|
+
stderr: "ignore"
|
|
20932
20985
|
});
|
|
20933
20986
|
} catch (error) {
|
|
20934
20987
|
return { failure: `could not start: ${messageFor(error)}`, timedOut: false };
|
|
20935
|
-
} finally {
|
|
20936
|
-
closeSync(fd);
|
|
20937
20988
|
}
|
|
20989
|
+
const { child, endGroup } = watched;
|
|
20990
|
+
let timedOut = false;
|
|
20991
|
+
const timer = setTimeout(() => {
|
|
20992
|
+
timedOut = true;
|
|
20993
|
+
endGroup();
|
|
20994
|
+
}, timeoutMs);
|
|
20938
20995
|
try {
|
|
20939
|
-
|
|
20940
|
-
}
|
|
20941
|
-
|
|
20996
|
+
await child.exited;
|
|
20997
|
+
} finally {
|
|
20998
|
+
clearTimeout(timer);
|
|
20999
|
+
}
|
|
21000
|
+
endGroup();
|
|
21001
|
+
if (timedOut) {
|
|
20942
21002
|
return {
|
|
20943
21003
|
failure: `did not finish within ${timeoutMs / 1000} s, and does not run again in this process`,
|
|
20944
21004
|
timedOut: true
|
|
20945
21005
|
};
|
|
20946
21006
|
}
|
|
20947
|
-
if (
|
|
21007
|
+
if (child.exitCode !== 0) {
|
|
20948
21008
|
return {
|
|
20949
|
-
failure: `exited with ${
|
|
21009
|
+
failure: `exited with ${child.signalCode ?? `status ${child.exitCode}`}`,
|
|
20950
21010
|
timedOut: false
|
|
20951
21011
|
};
|
|
20952
21012
|
}
|
|
20953
|
-
const value =
|
|
21013
|
+
const value = (await readOutput(file)).trim();
|
|
20954
21014
|
if (value.length === 0)
|
|
20955
21015
|
return { failure: "printed nothing", timedOut: false };
|
|
20956
21016
|
if (!sendable(value)) {
|
|
@@ -20961,10 +21021,10 @@ function runCommand(command, env, cwd) {
|
|
|
20961
21021
|
}
|
|
20962
21022
|
return { value };
|
|
20963
21023
|
} finally {
|
|
20964
|
-
|
|
21024
|
+
await file.close();
|
|
20965
21025
|
}
|
|
20966
21026
|
}
|
|
20967
|
-
function fileValue(value, field, filePath, env, commands = "run") {
|
|
21027
|
+
async function fileValue(value, field, filePath, env, commands = "run") {
|
|
20968
21028
|
if (!value.startsWith("!")) {
|
|
20969
21029
|
if (!sendable(value)) {
|
|
20970
21030
|
throw new Error(`${filePath}: ${field} holds whitespace or a control character`);
|
|
@@ -20980,42 +21040,50 @@ function fileValue(value, field, filePath, env, commands = "run") {
|
|
|
20980
21040
|
throw new Error(`${filePath}: ${field}'s command has not run in this process yet, and this read does not run it`);
|
|
20981
21041
|
}
|
|
20982
21042
|
} else if (outcome === undefined || "failure" in outcome && !outcome.timedOut && Date.now() - outcome.at >= FAILURE_KEPT_MS) {
|
|
20983
|
-
|
|
20984
|
-
|
|
21043
|
+
let run = commandRuns.get(key);
|
|
21044
|
+
if (run === undefined) {
|
|
21045
|
+
run = runCommand(command, env, cwd).then((ran) => {
|
|
21046
|
+
const kept = { ...ran, at: Date.now() };
|
|
21047
|
+
commandOutcomes.set(key, kept);
|
|
21048
|
+
return kept;
|
|
21049
|
+
}).finally(() => commandRuns.delete(key));
|
|
21050
|
+
commandRuns.set(key, run);
|
|
21051
|
+
}
|
|
21052
|
+
outcome = await run;
|
|
20985
21053
|
}
|
|
20986
21054
|
if ("failure" in outcome)
|
|
20987
21055
|
throw new Error(`${filePath}: ${field}'s command ${outcome.failure}`);
|
|
20988
21056
|
return outcome.value;
|
|
20989
21057
|
}
|
|
20990
|
-
function statDevice(directory) {
|
|
21058
|
+
async function statDevice(directory) {
|
|
20991
21059
|
try {
|
|
20992
|
-
return
|
|
21060
|
+
return (await stat(directory)).dev;
|
|
20993
21061
|
} catch {
|
|
20994
21062
|
return;
|
|
20995
21063
|
}
|
|
20996
21064
|
}
|
|
20997
|
-
function moveNotice(oldFile, newFile, move, deviceOf) {
|
|
20998
|
-
const oldDevice = deviceOf(path.dirname(oldFile));
|
|
21065
|
+
async function moveNotice(oldFile, newFile, move, deviceOf) {
|
|
21066
|
+
const oldDevice = await deviceOf(path.dirname(oldFile));
|
|
20999
21067
|
let ancestor = path.dirname(newFile);
|
|
21000
|
-
let newDevice = deviceOf(ancestor);
|
|
21068
|
+
let newDevice = await deviceOf(ancestor);
|
|
21001
21069
|
while (newDevice === undefined && path.dirname(ancestor) !== ancestor) {
|
|
21002
21070
|
ancestor = path.dirname(ancestor);
|
|
21003
|
-
newDevice = deviceOf(ancestor);
|
|
21071
|
+
newDevice = await deviceOf(ancestor);
|
|
21004
21072
|
}
|
|
21005
21073
|
if (oldDevice !== undefined && newDevice !== undefined && oldDevice !== newDevice) {
|
|
21006
21074
|
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`;
|
|
21007
21075
|
}
|
|
21008
21076
|
return `${oldFile} is not read: ${move}`;
|
|
21009
21077
|
}
|
|
21010
|
-
function oldUserFileNotice(filePath, env, deviceOf) {
|
|
21078
|
+
async function oldUserFileNotice(filePath, env, deviceOf) {
|
|
21011
21079
|
const home = nonEmpty(env.HOME) ?? homedir();
|
|
21012
21080
|
const old = path.join(home, ".config", "opencode", "envoy.json");
|
|
21013
|
-
if (!
|
|
21081
|
+
if (!await exists(old))
|
|
21014
21082
|
return;
|
|
21015
21083
|
const selected = path.resolve(filePath);
|
|
21016
21084
|
const userFile = path.resolve(home, ".config", "legion", "envoy.json");
|
|
21017
21085
|
if (selected === userFile) {
|
|
21018
|
-
return moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
|
|
21086
|
+
return await moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
|
|
21019
21087
|
}
|
|
21020
21088
|
const profileFile = PLUGIN_HARNESSES.map((harness) => namedDirectory(harness, env)).some((directory) => directory !== undefined && path.isAbsolute(directory) && selected === path.resolve(directory, "envoy.json"));
|
|
21021
21089
|
if (profileFile) {
|
|
@@ -21033,14 +21101,18 @@ function missingConfigNotice(filePath, missing, off) {
|
|
|
21033
21101
|
const old = missing.oldUserFileNotice === undefined ? "" : `; ${missing.oldUserFileNotice}`;
|
|
21034
21102
|
return `no envoy.json at ${filePath}${link}: ${off}${old}`;
|
|
21035
21103
|
}
|
|
21036
|
-
function readEnvoyConfig(filePath, env, options) {
|
|
21104
|
+
async function readEnvoyConfig(filePath, env, options) {
|
|
21037
21105
|
const deviceOf = options.deviceOf ?? statDevice;
|
|
21038
|
-
const chosen = parseFile(filePath, EnvoyFileSchema, false);
|
|
21039
|
-
if (chosen.kind === "invalid")
|
|
21040
|
-
return { kind: "failed", path: filePath, error: chosen.reason };
|
|
21041
21106
|
const resolvedChosen = path.resolve(filePath);
|
|
21042
21107
|
const checkoutPath = path.resolve(options.cwd, ".envoy", "envoy.json");
|
|
21043
|
-
const
|
|
21108
|
+
const oldCheckout = path.resolve(options.cwd, ".opencode", "envoy.json");
|
|
21109
|
+
const [chosen, checkoutFile, oldCheckoutThere] = await Promise.all([
|
|
21110
|
+
parseFile(filePath, EnvoyFileSchema, false),
|
|
21111
|
+
checkoutPath === resolvedChosen ? Promise.resolve({ kind: "absent", link: null }) : parseFile(checkoutPath, CheckoutFileSchema, true),
|
|
21112
|
+
oldCheckout === resolvedChosen ? Promise.resolve(false) : exists(oldCheckout)
|
|
21113
|
+
]);
|
|
21114
|
+
if (chosen.kind === "invalid")
|
|
21115
|
+
return { kind: "failed", path: filePath, error: chosen.reason };
|
|
21044
21116
|
const own = chosen.kind === "valid" ? chosen.settings : {};
|
|
21045
21117
|
let checkout = null;
|
|
21046
21118
|
if (checkoutFile.kind === "invalid") {
|
|
@@ -21054,11 +21126,11 @@ function readEnvoyConfig(filePath, env, options) {
|
|
|
21054
21126
|
askgateError: Object.hasOwn(checkoutFile.settings, "askgate") ? `askgate in ${checkoutPath} is not read; set it in ${filePath}` : null
|
|
21055
21127
|
};
|
|
21056
21128
|
}
|
|
21057
|
-
const
|
|
21058
|
-
const warnings = oldCheckout !== resolvedChosen &&
|
|
21059
|
-
moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
|
|
21129
|
+
const checkoutMissing = checkoutPath === resolvedChosen ? chosen.kind === "absent" : checkoutFile.kind === "absent" || checkoutFile.kind === "invalid" && !await exists(checkoutPath);
|
|
21130
|
+
const warnings = oldCheckout !== resolvedChosen && checkoutMissing && oldCheckoutThere ? [
|
|
21131
|
+
await moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
|
|
21060
21132
|
] : [];
|
|
21061
|
-
const unreadOldUserFile = chosen.kind === "absent" ? oldUserFileNotice(filePath, env, deviceOf) : undefined;
|
|
21133
|
+
const unreadOldUserFile = chosen.kind === "absent" ? await oldUserFileNotice(filePath, env, deviceOf) : undefined;
|
|
21062
21134
|
return {
|
|
21063
21135
|
kind: "read",
|
|
21064
21136
|
path: filePath,
|
|
@@ -21086,10 +21158,10 @@ function bearerCredential(token) {
|
|
|
21086
21158
|
secret: () => token
|
|
21087
21159
|
};
|
|
21088
21160
|
}
|
|
21089
|
-
function bearerSource(env, section, written) {
|
|
21161
|
+
async function bearerSource(env, section, written) {
|
|
21090
21162
|
const pointer = nonEmpty(env[`${section}_TOKEN_FILE`]);
|
|
21091
21163
|
if (pointer !== undefined) {
|
|
21092
|
-
return { kind: "variable", token: readSecretFile(`${section}_TOKEN_FILE`, pointer) };
|
|
21164
|
+
return { kind: "variable", token: await readSecretFile(`${section}_TOKEN_FILE`, pointer) };
|
|
21093
21165
|
}
|
|
21094
21166
|
const plain = nonEmpty(env[`${section}_TOKEN`]);
|
|
21095
21167
|
if (plain !== undefined) {
|
|
@@ -21101,7 +21173,7 @@ function bearerSource(env, section, written) {
|
|
|
21101
21173
|
const bearer = written();
|
|
21102
21174
|
return bearer === undefined ? { kind: "none" } : { kind: "file", ...bearer };
|
|
21103
21175
|
}
|
|
21104
|
-
function fileBearer(bearer, url, section, env, commands = "run") {
|
|
21176
|
+
async function fileBearer(bearer, url, section, env, commands = "run") {
|
|
21105
21177
|
const named = httpUrl2(url)?.origin;
|
|
21106
21178
|
const paired = httpUrl2(bearer.server)?.origin;
|
|
21107
21179
|
if (named !== paired) {
|
|
@@ -28868,12 +28940,12 @@ async function reviewCommand(context) {
|
|
|
28868
28940
|
}
|
|
28869
28941
|
|
|
28870
28942
|
// ../envoy-client/src/session-answers.ts
|
|
28871
|
-
import { mkdirSync, readFileSync
|
|
28943
|
+
import { mkdirSync, readFileSync } from "fs";
|
|
28872
28944
|
import { join as join4 } from "path";
|
|
28873
28945
|
|
|
28874
28946
|
// ../envoy-client/src/dispatch-session-directory.ts
|
|
28875
28947
|
import { randomUUID } from "crypto";
|
|
28876
|
-
import { renameSync, rmSync
|
|
28948
|
+
import { renameSync, rmSync, writeFileSync } from "fs";
|
|
28877
28949
|
import { homedir as homedir2 } from "os";
|
|
28878
28950
|
import { join as join3 } from "path";
|
|
28879
28951
|
var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
|
|
@@ -28896,7 +28968,7 @@ function writeAtomically(path, text) {
|
|
|
28896
28968
|
writeFileSync(temporary, text, { mode: PRIVATE_FILE });
|
|
28897
28969
|
renameSync(temporary, path);
|
|
28898
28970
|
} catch (error) {
|
|
28899
|
-
|
|
28971
|
+
rmSync(temporary, { force: true });
|
|
28900
28972
|
throw error;
|
|
28901
28973
|
}
|
|
28902
28974
|
}
|
|
@@ -29039,7 +29111,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
29039
29111
|
var CACHE_FILE = "answers.json";
|
|
29040
29112
|
function readCacheFile(directory, url) {
|
|
29041
29113
|
try {
|
|
29042
|
-
const value = JSON.parse(
|
|
29114
|
+
const value = JSON.parse(readFileSync(join4(directory, CACHE_FILE), "utf-8"));
|
|
29043
29115
|
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)) {
|
|
29044
29116
|
return {
|
|
29045
29117
|
dispatch_url: value.dispatch_url,
|
|
@@ -31577,30 +31649,30 @@ async function sendWithProof(proved, url, options, signal) {
|
|
|
31577
31649
|
import { createPrivateKey, randomUUID as randomUUID3 } from "crypto";
|
|
31578
31650
|
import { constants as constants2 } from "fs";
|
|
31579
31651
|
import {
|
|
31580
|
-
access,
|
|
31581
|
-
lstat as
|
|
31652
|
+
access as access2,
|
|
31653
|
+
lstat as lstat3,
|
|
31582
31654
|
mkdir,
|
|
31583
|
-
open as
|
|
31584
|
-
readFile as
|
|
31585
|
-
readlink,
|
|
31655
|
+
open as open3,
|
|
31656
|
+
readFile as readFile4,
|
|
31657
|
+
readlink as readlink2,
|
|
31586
31658
|
rename as rename2,
|
|
31587
|
-
rm as
|
|
31588
|
-
stat as
|
|
31659
|
+
rm as rm3,
|
|
31660
|
+
stat as stat3
|
|
31589
31661
|
} from "fs/promises";
|
|
31590
31662
|
import { userInfo } from "os";
|
|
31591
31663
|
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join6 } from "path";
|
|
31592
31664
|
|
|
31593
31665
|
// ../cipher-client/src/device-login-lock.ts
|
|
31594
31666
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
31595
|
-
import { closeSync
|
|
31667
|
+
import { closeSync, constants, fstatSync, openSync, readSync } from "fs";
|
|
31596
31668
|
import {
|
|
31597
31669
|
link,
|
|
31598
|
-
lstat,
|
|
31599
|
-
open,
|
|
31670
|
+
lstat as lstat2,
|
|
31671
|
+
open as open2,
|
|
31600
31672
|
readdir as readdir2,
|
|
31601
31673
|
rename,
|
|
31602
|
-
rm,
|
|
31603
|
-
stat,
|
|
31674
|
+
rm as rm2,
|
|
31675
|
+
stat as stat2,
|
|
31604
31676
|
utimes
|
|
31605
31677
|
} from "fs/promises";
|
|
31606
31678
|
import { basename as basename2, dirname as dirname2, join as join5 } from "path";
|
|
@@ -32018,7 +32090,7 @@ var LOCK_RETRY_MS = 100;
|
|
|
32018
32090
|
var STEAL_STALE_MS = 5000;
|
|
32019
32091
|
async function statOrNone(path, what) {
|
|
32020
32092
|
try {
|
|
32021
|
-
return await
|
|
32093
|
+
return await lstat2(path);
|
|
32022
32094
|
} catch (error) {
|
|
32023
32095
|
if (readErrorCode(error) === "ENOENT")
|
|
32024
32096
|
return null;
|
|
@@ -32028,7 +32100,7 @@ async function statOrNone(path, what) {
|
|
|
32028
32100
|
async function createOwn(path, value, named) {
|
|
32029
32101
|
let handle;
|
|
32030
32102
|
try {
|
|
32031
|
-
handle = await
|
|
32103
|
+
handle = await open2(path, "wx", 384);
|
|
32032
32104
|
} catch (error) {
|
|
32033
32105
|
if (readErrorCode(error) === "EEXIST")
|
|
32034
32106
|
return false;
|
|
@@ -32044,7 +32116,7 @@ async function createOwn(path, value, named) {
|
|
|
32044
32116
|
async function look(path, what) {
|
|
32045
32117
|
let handle;
|
|
32046
32118
|
try {
|
|
32047
|
-
handle = await
|
|
32119
|
+
handle = await open2(path, LOCK_READ);
|
|
32048
32120
|
} catch (error) {
|
|
32049
32121
|
if (readErrorCode(error) === "ENOENT")
|
|
32050
32122
|
return null;
|
|
@@ -32081,7 +32153,7 @@ async function removeIfStill(path, isIt, what) {
|
|
|
32081
32153
|
const same = took !== null && isIt(took);
|
|
32082
32154
|
if (!same)
|
|
32083
32155
|
await link(moved, path).catch(() => {});
|
|
32084
|
-
await
|
|
32156
|
+
await rm2(moved, { force: true }).catch((error) => {
|
|
32085
32157
|
throw new Error(`remove ${what}, moved aside: ${readErrorCode(error)}`);
|
|
32086
32158
|
});
|
|
32087
32159
|
return same;
|
|
@@ -32168,7 +32240,7 @@ async function withLoginLock(path, named, work, options = {}) {
|
|
|
32168
32240
|
function loginLockHeldBy(path, pid) {
|
|
32169
32241
|
let fd;
|
|
32170
32242
|
try {
|
|
32171
|
-
fd =
|
|
32243
|
+
fd = openSync(`${path}.lock`, LOCK_READ);
|
|
32172
32244
|
} catch {
|
|
32173
32245
|
return false;
|
|
32174
32246
|
}
|
|
@@ -32182,7 +32254,7 @@ function loginLockHeldBy(path, pid) {
|
|
|
32182
32254
|
return false;
|
|
32183
32255
|
} finally {
|
|
32184
32256
|
try {
|
|
32185
|
-
|
|
32257
|
+
closeSync(fd);
|
|
32186
32258
|
} catch {}
|
|
32187
32259
|
}
|
|
32188
32260
|
}
|
|
@@ -32193,9 +32265,9 @@ async function removeUntouched(dir, left) {
|
|
|
32193
32265
|
const names = await readdir2(dir).catch(() => []);
|
|
32194
32266
|
for (const name of names.filter(left)) {
|
|
32195
32267
|
const path = join5(dir, name);
|
|
32196
|
-
const info = await
|
|
32268
|
+
const info = await stat2(path).catch(() => null);
|
|
32197
32269
|
if (info !== null && Date.now() - info.mtimeMs > DEVICE_LOGIN_STALE_LOCK_MS) {
|
|
32198
|
-
await
|
|
32270
|
+
await rm2(path, { force: true }).catch(() => {});
|
|
32199
32271
|
}
|
|
32200
32272
|
}
|
|
32201
32273
|
}
|
|
@@ -32244,7 +32316,7 @@ var systemFiles = new Map;
|
|
|
32244
32316
|
async function systemFile(file) {
|
|
32245
32317
|
let info;
|
|
32246
32318
|
try {
|
|
32247
|
-
info = await
|
|
32319
|
+
info = await stat3(file);
|
|
32248
32320
|
} catch {
|
|
32249
32321
|
return null;
|
|
32250
32322
|
}
|
|
@@ -32252,7 +32324,7 @@ async function systemFile(file) {
|
|
|
32252
32324
|
const kept = systemFiles.get(file);
|
|
32253
32325
|
if (kept?.status === status)
|
|
32254
32326
|
return kept.text;
|
|
32255
|
-
const text = await
|
|
32327
|
+
const text = await readFile4(file, "utf8").catch(() => null);
|
|
32256
32328
|
if (text === null)
|
|
32257
32329
|
systemFiles.delete(file);
|
|
32258
32330
|
else
|
|
@@ -32340,7 +32412,7 @@ async function checkLinkOnTheWay(info, what) {
|
|
|
32340
32412
|
}
|
|
32341
32413
|
async function lstatOnTheWay(path, what) {
|
|
32342
32414
|
try {
|
|
32343
|
-
return await
|
|
32415
|
+
return await lstat3(path);
|
|
32344
32416
|
} catch (error) {
|
|
32345
32417
|
if (readErrorCode(error) === "ENOENT")
|
|
32346
32418
|
return null;
|
|
@@ -32376,7 +32448,7 @@ async function walkTheWay(path, what, meet) {
|
|
|
32376
32448
|
throw notARegularFile("a loop of links");
|
|
32377
32449
|
let target;
|
|
32378
32450
|
try {
|
|
32379
|
-
target = await
|
|
32451
|
+
target = await readlink2(next);
|
|
32380
32452
|
} catch (error) {
|
|
32381
32453
|
const code = readErrorCode(error);
|
|
32382
32454
|
if (code !== "EINVAL" && code !== "ENOENT") {
|
|
@@ -32425,7 +32497,7 @@ async function checkDirectoriesOnTheWay(dir, what) {
|
|
|
32425
32497
|
async function checkLoginDirectory(dir, absent, what = `the directory of ${DEVICE_LOGIN_FILE_NAMED}`) {
|
|
32426
32498
|
let info;
|
|
32427
32499
|
try {
|
|
32428
|
-
info = await
|
|
32500
|
+
info = await stat3(dir);
|
|
32429
32501
|
} catch (error) {
|
|
32430
32502
|
if (absent !== undefined && readErrorCode(error) === "ENOENT")
|
|
32431
32503
|
throw absent();
|
|
@@ -32462,14 +32534,14 @@ async function deviceLoginPlace(path) {
|
|
|
32462
32534
|
await deviceLoginDirectory(path);
|
|
32463
32535
|
const dir = dirname3(path);
|
|
32464
32536
|
try {
|
|
32465
|
-
await
|
|
32537
|
+
await access2(dir, constants2.W_OK | constants2.X_OK);
|
|
32466
32538
|
} catch (error) {
|
|
32467
32539
|
const code = readErrorCode(error);
|
|
32468
32540
|
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" : ""}`);
|
|
32469
32541
|
}
|
|
32470
32542
|
let info;
|
|
32471
32543
|
try {
|
|
32472
|
-
info = await
|
|
32544
|
+
info = await stat3(path);
|
|
32473
32545
|
} catch (error) {
|
|
32474
32546
|
if (readErrorCode(error) === "ENOENT")
|
|
32475
32547
|
return;
|
|
@@ -32490,7 +32562,7 @@ async function checkLinkDirectories(path, absent) {
|
|
|
32490
32562
|
}
|
|
32491
32563
|
let info;
|
|
32492
32564
|
try {
|
|
32493
|
-
info = await
|
|
32565
|
+
info = await lstat3(at);
|
|
32494
32566
|
} catch (error) {
|
|
32495
32567
|
if (readErrorCode(error) === "ENOENT")
|
|
32496
32568
|
return;
|
|
@@ -32502,7 +32574,7 @@ async function checkLinkDirectories(path, absent) {
|
|
|
32502
32574
|
throw notARegularFile("a loop of links");
|
|
32503
32575
|
let target;
|
|
32504
32576
|
try {
|
|
32505
|
-
target = await
|
|
32577
|
+
target = await readlink2(at);
|
|
32506
32578
|
} catch (error) {
|
|
32507
32579
|
const code = readErrorCode(error);
|
|
32508
32580
|
if (code === "EINVAL" || code === "ENOENT")
|
|
@@ -32519,7 +32591,7 @@ async function readDeviceLogin(path) {
|
|
|
32519
32591
|
await checkLinkDirectories(path, absent);
|
|
32520
32592
|
let handle;
|
|
32521
32593
|
try {
|
|
32522
|
-
handle = await
|
|
32594
|
+
handle = await open3(path, LOGIN_READ);
|
|
32523
32595
|
} catch (error) {
|
|
32524
32596
|
throw readErrorCode(error) === "ENOENT" ? absent() : refusedBy(error, `read ${DEVICE_LOGIN_FILE_NAMED}`);
|
|
32525
32597
|
}
|
|
@@ -32630,7 +32702,7 @@ async function saveDeviceLogin(path, login, held, keep = false) {
|
|
|
32630
32702
|
let whole = false;
|
|
32631
32703
|
try {
|
|
32632
32704
|
try {
|
|
32633
|
-
const handle = await
|
|
32705
|
+
const handle = await open3(temp, "wx", 384);
|
|
32634
32706
|
try {
|
|
32635
32707
|
await handle.writeFile(data);
|
|
32636
32708
|
await handle.sync();
|
|
@@ -32649,10 +32721,10 @@ async function saveDeviceLogin(path, login, held, keep = false) {
|
|
|
32649
32721
|
} catch (error) {
|
|
32650
32722
|
throw keep && whole ? await keptCopy(temp, path, error) : error;
|
|
32651
32723
|
} finally {
|
|
32652
|
-
await
|
|
32724
|
+
await rm3(temp, { force: true }).catch(() => {});
|
|
32653
32725
|
}
|
|
32654
32726
|
try {
|
|
32655
|
-
const handle = await
|
|
32727
|
+
const handle = await open3(dir, "r");
|
|
32656
32728
|
try {
|
|
32657
32729
|
await handle.sync();
|
|
32658
32730
|
} finally {
|
|
@@ -33299,14 +33371,14 @@ function poolIdentity(options) {
|
|
|
33299
33371
|
}
|
|
33300
33372
|
|
|
33301
33373
|
// ../cipher-client/src/projected-token.ts
|
|
33302
|
-
import { readFile as
|
|
33374
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
33303
33375
|
function projectedToken(path, variable) {
|
|
33304
33376
|
const named = `the projected service-account token ${variable} names`;
|
|
33305
33377
|
return {
|
|
33306
33378
|
async read(signal) {
|
|
33307
33379
|
let contents;
|
|
33308
33380
|
try {
|
|
33309
|
-
contents = await
|
|
33381
|
+
contents = await readFile5(path, {
|
|
33310
33382
|
encoding: "utf8",
|
|
33311
33383
|
...signal === undefined ? {} : { signal }
|
|
33312
33384
|
});
|
|
@@ -33624,14 +33696,14 @@ function brokerCredential(env, session, read) {
|
|
|
33624
33696
|
}
|
|
33625
33697
|
|
|
33626
33698
|
// ../envoy-client/src/file-token-credential.ts
|
|
33627
|
-
import { readFileSync as
|
|
33699
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
33628
33700
|
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
33629
33701
|
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
33630
33702
|
var PKCS8_LABEL = "PRIVATE KEY";
|
|
33631
33703
|
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
33632
33704
|
function readNamed(variable, filePath) {
|
|
33633
33705
|
try {
|
|
33634
|
-
return
|
|
33706
|
+
return readFileSync2(filePath, "utf8");
|
|
33635
33707
|
} catch (error) {
|
|
33636
33708
|
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
33637
33709
|
}
|
|
@@ -33719,8 +33791,8 @@ function lostDispatchUrlNotice(env, config) {
|
|
|
33719
33791
|
...old === undefined ? [] : [old]
|
|
33720
33792
|
].join("; ");
|
|
33721
33793
|
}
|
|
33722
|
-
function dispatchSettings(env, config, options = {}) {
|
|
33723
|
-
const target = dispatchTarget(env, config, options.tokenFiles === true);
|
|
33794
|
+
async function dispatchSettings(env, config, options = {}) {
|
|
33795
|
+
const target = await dispatchTarget(env, config, options.tokenFiles === true);
|
|
33724
33796
|
if (!target.enabled)
|
|
33725
33797
|
return target;
|
|
33726
33798
|
const { url, urlSetting, source } = target;
|
|
@@ -33731,7 +33803,7 @@ function dispatchSettings(env, config, options = {}) {
|
|
|
33731
33803
|
else if (source.kind === "files")
|
|
33732
33804
|
credential = fileTokenCredential(source, url);
|
|
33733
33805
|
else {
|
|
33734
|
-
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "DISPATCH", env, options.commands));
|
|
33806
|
+
credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "DISPATCH", env, options.commands));
|
|
33735
33807
|
}
|
|
33736
33808
|
} catch (error) {
|
|
33737
33809
|
return offWithError(messageFor(error));
|
|
@@ -33751,8 +33823,8 @@ function dispatchSettings(env, config, options = {}) {
|
|
|
33751
33823
|
...linkNotice === undefined ? {} : { linkNotice }
|
|
33752
33824
|
};
|
|
33753
33825
|
}
|
|
33754
|
-
function dispatchUrl(env, config) {
|
|
33755
|
-
const target = dispatchTarget(env, config);
|
|
33826
|
+
async function dispatchUrl(env, config) {
|
|
33827
|
+
const target = await dispatchTarget(env, config);
|
|
33756
33828
|
return target.enabled ? target.url : undefined;
|
|
33757
33829
|
}
|
|
33758
33830
|
var BESIDE_TOKEN_FILES = [
|
|
@@ -33856,7 +33928,7 @@ function readTradeSetting(env) {
|
|
|
33856
33928
|
}
|
|
33857
33929
|
return { asOf: cut };
|
|
33858
33930
|
}
|
|
33859
|
-
function dispatchTarget(env, config, tokenFiles = false) {
|
|
33931
|
+
async function dispatchTarget(env, config, tokenFiles = false) {
|
|
33860
33932
|
if (config.kind === "failed")
|
|
33861
33933
|
return offWithError(config.error);
|
|
33862
33934
|
const files = tokenFilesTarget(env, config, tokenFiles);
|
|
@@ -33895,7 +33967,7 @@ function dispatchTarget(env, config, tokenFiles = false) {
|
|
|
33895
33967
|
let source = { kind: "none" };
|
|
33896
33968
|
if (!forced) {
|
|
33897
33969
|
try {
|
|
33898
|
-
source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
|
|
33970
|
+
source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : await bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
|
|
33899
33971
|
} catch (error) {
|
|
33900
33972
|
return offWithError(messageFor(error));
|
|
33901
33973
|
}
|
|
@@ -34329,13 +34401,13 @@ function resolvedInterval(raw, fallback) {
|
|
|
34329
34401
|
return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
|
|
34330
34402
|
}
|
|
34331
34403
|
var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
|
|
34332
|
-
function natsSeedFromEnvironment(env) {
|
|
34404
|
+
async function natsSeedFromEnvironment(env) {
|
|
34333
34405
|
const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
|
|
34334
34406
|
if (file !== undefined) {
|
|
34335
34407
|
if (file === "")
|
|
34336
34408
|
throw new Error("NATS_NKEY_SEED_FILE is set but empty");
|
|
34337
34409
|
return {
|
|
34338
|
-
value: readSecretFile("NATS_NKEY_SEED_FILE", file),
|
|
34410
|
+
value: await readSecretFile("NATS_NKEY_SEED_FILE", file),
|
|
34339
34411
|
source: "the file NATS_NKEY_SEED_FILE names"
|
|
34340
34412
|
};
|
|
34341
34413
|
}
|
|
@@ -34364,23 +34436,23 @@ function requireFileServers(section, namedNatsUrls, filePath, remedy) {
|
|
|
34364
34436
|
throw new Error(`ENVOY_NATS_URL names other servers than ${filePath}'s envoy.natsUrls; set ${remedy} for them`);
|
|
34365
34437
|
}
|
|
34366
34438
|
}
|
|
34367
|
-
function natsSeed(env, section, namedNatsUrls, filePath) {
|
|
34368
|
-
const fromEnvironment = natsSeedFromEnvironment(env);
|
|
34439
|
+
async function natsSeed(env, section, namedNatsUrls, filePath) {
|
|
34440
|
+
const fromEnvironment = await natsSeedFromEnvironment(env);
|
|
34369
34441
|
if (fromEnvironment !== undefined || section.natsSeed === undefined)
|
|
34370
34442
|
return fromEnvironment;
|
|
34371
34443
|
requireFileServers(section, namedNatsUrls, filePath, "NATS_NKEY_SEED_FILE");
|
|
34372
34444
|
return {
|
|
34373
|
-
value: fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
|
|
34445
|
+
value: await fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
|
|
34374
34446
|
source: `envoy.natsSeed in ${filePath}`
|
|
34375
34447
|
};
|
|
34376
34448
|
}
|
|
34377
|
-
function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
34449
|
+
async function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
34378
34450
|
const named = nonEmpty(env.NATS_AUTH);
|
|
34379
34451
|
const auth = named !== undefined ? { value: named, source: NATS_AUTH_VAR } : section.natsAuth === undefined ? undefined : { value: section.natsAuth, source: `envoy.natsAuth in ${filePath}` };
|
|
34380
34452
|
if (auth !== undefined && auth.value !== "broker" && auth.value !== "none") {
|
|
34381
34453
|
throw new Error(`${auth.source} is neither broker nor none`);
|
|
34382
34454
|
}
|
|
34383
|
-
const seed = natsSeed(env, section, namedNatsUrls, filePath);
|
|
34455
|
+
const seed = await natsSeed(env, section, namedNatsUrls, filePath);
|
|
34384
34456
|
if (seed !== undefined) {
|
|
34385
34457
|
if (auth?.value === "broker") {
|
|
34386
34458
|
throw new Error(`${auth.source} is ${auth.value}, and ${seed.source} names an nkey seed: set one of the two`);
|
|
@@ -34425,7 +34497,7 @@ function plainHttpOffMachine(url) {
|
|
|
34425
34497
|
const host = URL.canParse(url) ? new URL(url) : undefined;
|
|
34426
34498
|
return host?.protocol === "http:" && !LOOPBACK_HOST2.test(host.hostname) ? host.hostname : undefined;
|
|
34427
34499
|
}
|
|
34428
|
-
function envoySettings(env, config, options = {}) {
|
|
34500
|
+
async function envoySettings(env, config, options = {}) {
|
|
34429
34501
|
if (config.kind === "failed")
|
|
34430
34502
|
return offWithError(config.error);
|
|
34431
34503
|
const section = config.envoy;
|
|
@@ -34456,7 +34528,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
34456
34528
|
let credential;
|
|
34457
34529
|
let noBrokerRoute = "";
|
|
34458
34530
|
try {
|
|
34459
|
-
const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
34531
|
+
const source = await bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
34460
34532
|
token: section.token,
|
|
34461
34533
|
field: "envoy.token",
|
|
34462
34534
|
path: config.path,
|
|
@@ -34469,7 +34541,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
34469
34541
|
if (!route.traded)
|
|
34470
34542
|
noBrokerRoute = route.gap;
|
|
34471
34543
|
} else {
|
|
34472
|
-
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
|
|
34544
|
+
credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "ENVOY", env));
|
|
34473
34545
|
}
|
|
34474
34546
|
} catch (error) {
|
|
34475
34547
|
return offWithError(messageFor(error));
|
|
@@ -34489,7 +34561,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
34489
34561
|
inbound = {
|
|
34490
34562
|
natsUrls,
|
|
34491
34563
|
natsServersSetting: natsSetting,
|
|
34492
|
-
natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
34564
|
+
natsCredential: await natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
34493
34565
|
};
|
|
34494
34566
|
} catch (error) {
|
|
34495
34567
|
inbound = error instanceof NoSessionNamedError ? { off: messageFor(error), noSessionNamed: true } : { off: messageFor(error) };
|
|
@@ -34573,26 +34645,28 @@ function startNotice(config, dispatch, envoy, nats, lost) {
|
|
|
34573
34645
|
}
|
|
34574
34646
|
return parts.length === 0 ? null : parts.join("; ");
|
|
34575
34647
|
}
|
|
34576
|
-
function sessionSettings(file, env, options) {
|
|
34648
|
+
async function sessionSettings(file, env, options) {
|
|
34577
34649
|
if (file.path === null) {
|
|
34578
34650
|
const off = offWithError(file.error);
|
|
34579
34651
|
return { dispatch: off, envoy: off, notice: `${file.error}: Dispatch and Envoy are off` };
|
|
34580
34652
|
}
|
|
34581
|
-
const config = readEnvoyConfig(file.path, env, options);
|
|
34582
|
-
const dispatch
|
|
34583
|
-
|
|
34653
|
+
const config = await readEnvoyConfig(file.path, env, options);
|
|
34654
|
+
const [dispatch, envoy] = await Promise.all([
|
|
34655
|
+
dispatchSettings(env, config, { session: options.session }),
|
|
34656
|
+
envoySettings(env, config, { nats: options.nats, session: options.session })
|
|
34657
|
+
]);
|
|
34584
34658
|
return {
|
|
34585
34659
|
dispatch,
|
|
34586
34660
|
envoy,
|
|
34587
34661
|
notice: startNotice(config, dispatch, envoy, options.nats !== false, config.kind === "read" ? lostDispatchUrlNotice(env, config) : undefined)
|
|
34588
34662
|
};
|
|
34589
34663
|
}
|
|
34590
|
-
function sessionDispatchSettings(file, env, options) {
|
|
34664
|
+
async function sessionDispatchSettings(file, env, options) {
|
|
34591
34665
|
if (file.path === null)
|
|
34592
34666
|
return { dispatch: offWithError(file.error), warnings: [], missing: null };
|
|
34593
|
-
const config = readEnvoyConfig(file.path, env, options);
|
|
34667
|
+
const config = await readEnvoyConfig(file.path, env, options);
|
|
34594
34668
|
return {
|
|
34595
|
-
dispatch: dispatchSettings(env, config, {
|
|
34669
|
+
dispatch: await dispatchSettings(env, config, {
|
|
34596
34670
|
commands: options.commands,
|
|
34597
34671
|
session: options.session,
|
|
34598
34672
|
tokenFiles: options.tokenFiles
|
|
@@ -34601,15 +34675,15 @@ function sessionDispatchSettings(file, env, options) {
|
|
|
34601
34675
|
missing: config.kind === "read" ? config.missing : null
|
|
34602
34676
|
};
|
|
34603
34677
|
}
|
|
34604
|
-
function sessionDispatchUrl(file, env, options) {
|
|
34678
|
+
async function sessionDispatchUrl(file, env, options) {
|
|
34605
34679
|
if (file.path === null)
|
|
34606
34680
|
return;
|
|
34607
|
-
return dispatchUrl(env, readEnvoyConfig(file.path, env, options));
|
|
34681
|
+
return dispatchUrl(env, await readEnvoyConfig(file.path, env, options));
|
|
34608
34682
|
}
|
|
34609
|
-
function sessionEnvoySettings(file, env, options) {
|
|
34683
|
+
async function sessionEnvoySettings(file, env, options) {
|
|
34610
34684
|
if (file.path === null)
|
|
34611
34685
|
return offWithError(file.error);
|
|
34612
|
-
return envoySettings(env, readEnvoyConfig(file.path, env, options), {
|
|
34686
|
+
return envoySettings(env, await readEnvoyConfig(file.path, env, options), {
|
|
34613
34687
|
nats: options.nats,
|
|
34614
34688
|
session: options.session
|
|
34615
34689
|
});
|
|
@@ -34634,18 +34708,18 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
34634
34708
|
|
|
34635
34709
|
// src/codex/codex-session-record.ts
|
|
34636
34710
|
import { spawnSync } from "child_process";
|
|
34637
|
-
import { readFileSync as
|
|
34638
|
-
import { mkdir as mkdir3, readFile as
|
|
34711
|
+
import { readFileSync as readFileSync4, readlinkSync, unwatchFile, watchFile } from "fs";
|
|
34712
|
+
import { mkdir as mkdir3, readFile as readFile7, rename as rename4, utimes as utimes3, writeFile as writeFile2 } from "fs/promises";
|
|
34639
34713
|
import { homedir as homedir3 } from "os";
|
|
34640
34714
|
import { basename as basename4, dirname as dirname5, join as join9 } from "path";
|
|
34641
34715
|
|
|
34642
34716
|
// src/session-identity.ts
|
|
34643
|
-
import { readFile as
|
|
34717
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
34644
34718
|
import { basename as basename3, join as join8 } from "path";
|
|
34645
34719
|
|
|
34646
34720
|
// src/session-state.ts
|
|
34647
|
-
import { readFileSync as
|
|
34648
|
-
import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as
|
|
34721
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
34722
|
+
import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
|
|
34649
34723
|
import { dirname as dirname4, join as join7 } from "path";
|
|
34650
34724
|
async function writeAtomicStateFile(file, contents) {
|
|
34651
34725
|
await mkdir2(dirname4(file), { recursive: true, mode: 448 });
|
|
@@ -34667,12 +34741,12 @@ async function pruneStateDirectory(directory, isStale) {
|
|
|
34667
34741
|
const file = join7(directory, entry);
|
|
34668
34742
|
if (!await isStale(file))
|
|
34669
34743
|
continue;
|
|
34670
|
-
await
|
|
34744
|
+
await rm4(file, { recursive: true, force: true });
|
|
34671
34745
|
}
|
|
34672
34746
|
}
|
|
34673
34747
|
var STATE_FILE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
34674
34748
|
async function writtenLongAgo(file) {
|
|
34675
|
-
const modified = await
|
|
34749
|
+
const modified = await stat4(file).then((stats) => stats.mtimeMs, () => {
|
|
34676
34750
|
return;
|
|
34677
34751
|
});
|
|
34678
34752
|
return modified !== undefined && Date.now() - modified > STATE_FILE_MAX_AGE_MS;
|
|
@@ -34686,11 +34760,11 @@ async function writeChosenTitle(file, title) {
|
|
|
34686
34760
|
`);
|
|
34687
34761
|
}
|
|
34688
34762
|
async function removeChosenTitle(file) {
|
|
34689
|
-
await
|
|
34763
|
+
await rm4(file, { force: true });
|
|
34690
34764
|
}
|
|
34691
34765
|
function readChosenTitleSync(file) {
|
|
34692
34766
|
try {
|
|
34693
|
-
return
|
|
34767
|
+
return readFileSync3(file, "utf8");
|
|
34694
34768
|
} catch {
|
|
34695
34769
|
return;
|
|
34696
34770
|
}
|
|
@@ -34751,7 +34825,7 @@ class UnparseableRoleRecordError extends Error {
|
|
|
34751
34825
|
async function readPersistedRole(roleFile) {
|
|
34752
34826
|
let bytes;
|
|
34753
34827
|
try {
|
|
34754
|
-
bytes = await
|
|
34828
|
+
bytes = await readFile6(roleFile, "utf8");
|
|
34755
34829
|
} catch (error) {
|
|
34756
34830
|
if (hasErrnoCode(error, "ENOENT"))
|
|
34757
34831
|
return;
|
|
@@ -34773,7 +34847,7 @@ async function writeSessionHandoff(file, sessionId) {
|
|
|
34773
34847
|
}
|
|
34774
34848
|
async function readSessionHandoff(file) {
|
|
34775
34849
|
try {
|
|
34776
|
-
const id = (await
|
|
34850
|
+
const id = (await readFile6(file, "utf8")).trim();
|
|
34777
34851
|
return id.length === 0 ? undefined : id;
|
|
34778
34852
|
} catch (error) {
|
|
34779
34853
|
if (hasErrnoCode(error, "ENOENT"))
|
|
@@ -34837,7 +34911,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
|
|
|
34837
34911
|
}
|
|
34838
34912
|
async function sessionEnded(file) {
|
|
34839
34913
|
try {
|
|
34840
|
-
await
|
|
34914
|
+
await readFile7(file);
|
|
34841
34915
|
return true;
|
|
34842
34916
|
} catch {
|
|
34843
34917
|
return false;
|
|
@@ -34851,7 +34925,7 @@ async function writeCodexSessionRecord(file, value) {
|
|
|
34851
34925
|
}
|
|
34852
34926
|
async function readCodexSessionRecord(file) {
|
|
34853
34927
|
try {
|
|
34854
|
-
const parsed = CodexSessionRecord.safeParse(JSON.parse(await
|
|
34928
|
+
const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile7(file, "utf8")));
|
|
34855
34929
|
return parsed.success ? parsed.data : undefined;
|
|
34856
34930
|
} catch {
|
|
34857
34931
|
return;
|
|
@@ -34883,14 +34957,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
34883
34957
|
}
|
|
34884
34958
|
function procComm(pid) {
|
|
34885
34959
|
try {
|
|
34886
|
-
return
|
|
34960
|
+
return readFileSync4(`/proc/${pid}/comm`, "utf8").trim();
|
|
34887
34961
|
} catch {
|
|
34888
34962
|
return;
|
|
34889
34963
|
}
|
|
34890
34964
|
}
|
|
34891
34965
|
function procParent(pid) {
|
|
34892
34966
|
try {
|
|
34893
|
-
const stat =
|
|
34967
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
34894
34968
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
34895
34969
|
return Number.isInteger(parent) ? parent : undefined;
|
|
34896
34970
|
} catch {
|
|
@@ -34904,7 +34978,7 @@ var PS_OPTIONS = {
|
|
|
34904
34978
|
};
|
|
34905
34979
|
function procStarted(pid) {
|
|
34906
34980
|
try {
|
|
34907
|
-
const stat =
|
|
34981
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
34908
34982
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
34909
34983
|
} catch {
|
|
34910
34984
|
return;
|
|
@@ -34925,7 +34999,7 @@ function recordOfProcess(record, pid) {
|
|
|
34925
34999
|
function sharedAppServer(pid) {
|
|
34926
35000
|
let argv;
|
|
34927
35001
|
try {
|
|
34928
|
-
argv =
|
|
35002
|
+
argv = readFileSync4(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
34929
35003
|
} catch {
|
|
34930
35004
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
34931
35005
|
if (ps.status !== 0)
|
|
@@ -34982,7 +35056,7 @@ async function pruneCodexSessionRecords(stateDirectory) {
|
|
|
34982
35056
|
}
|
|
34983
35057
|
function codexExecutable(pid) {
|
|
34984
35058
|
try {
|
|
34985
|
-
return
|
|
35059
|
+
return readlinkSync(`/proc/${pid}/exe`);
|
|
34986
35060
|
} catch {
|
|
34987
35061
|
return;
|
|
34988
35062
|
}
|
|
@@ -35041,7 +35115,7 @@ async function sessionStart(raw) {
|
|
|
35041
35115
|
process.stderr.write(`envoy: this session was not recorded, because the start of codex process ${pid} cannot be read; it gets no Envoy messages
|
|
35042
35116
|
`);
|
|
35043
35117
|
} else {
|
|
35044
|
-
await
|
|
35118
|
+
await rm5(codexEndedFile(pluginData, pid, input.session_id), { force: true });
|
|
35045
35119
|
await writeCodexSessionRecord(codexSessionRecordFile(pluginData, pid), {
|
|
35046
35120
|
codex_executable: codexExecutable(pid) ?? null,
|
|
35047
35121
|
codex_home: codexHome(process.env),
|
|
@@ -35059,7 +35133,7 @@ async function sessionStart(raw) {
|
|
|
35059
35133
|
}
|
|
35060
35134
|
}
|
|
35061
35135
|
const chosen = sessionConfigFile("codex", process.env);
|
|
35062
|
-
const { dispatch, warnings } = sessionDispatchSettings(chosen, process.env, {
|
|
35136
|
+
const { dispatch, warnings } = await sessionDispatchSettings(chosen, process.env, {
|
|
35063
35137
|
cwd: input.cwd,
|
|
35064
35138
|
session: input.session_id
|
|
35065
35139
|
});
|