@sjawhar/claude-envoy 5.25.0 → 5.25.1
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/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/session-hook.js
CHANGED
|
@@ -980,7 +980,7 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// hooks/session-hook.ts
|
|
983
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync2, readFileSync as
|
|
983
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync6, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
984
984
|
import { join as join11 } from "path";
|
|
985
985
|
|
|
986
986
|
// ../cipher-client/src/device-login-file.ts
|
|
@@ -23454,17 +23454,16 @@ function askAnswerText(answer) {
|
|
|
23454
23454
|
|
|
23455
23455
|
// ../envoy-client/src/envoy-config.ts
|
|
23456
23456
|
import {
|
|
23457
|
-
|
|
23458
|
-
|
|
23459
|
-
|
|
23460
|
-
|
|
23461
|
-
|
|
23462
|
-
|
|
23463
|
-
|
|
23464
|
-
|
|
23465
|
-
|
|
23466
|
-
|
|
23467
|
-
} from "fs";
|
|
23457
|
+
access as access2,
|
|
23458
|
+
chmod,
|
|
23459
|
+
lstat as lstat3,
|
|
23460
|
+
mkdtemp,
|
|
23461
|
+
open as open3,
|
|
23462
|
+
readFile as readFile4,
|
|
23463
|
+
readlink as readlink2,
|
|
23464
|
+
rm as rm3,
|
|
23465
|
+
stat as stat3
|
|
23466
|
+
} from "fs/promises";
|
|
23468
23467
|
import { homedir, tmpdir } from "os";
|
|
23469
23468
|
import * as path from "path";
|
|
23470
23469
|
|
|
@@ -23554,15 +23553,44 @@ function jsonErrorPosition(text) {
|
|
|
23554
23553
|
}
|
|
23555
23554
|
}
|
|
23556
23555
|
|
|
23556
|
+
// ../envoy-client/src/process-group.ts
|
|
23557
|
+
function killGroup(pid) {
|
|
23558
|
+
try {
|
|
23559
|
+
process.kill(-pid, "SIGKILL");
|
|
23560
|
+
} catch {}
|
|
23561
|
+
}
|
|
23562
|
+
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<&-';
|
|
23563
|
+
function groupWatchedBy(argv) {
|
|
23564
|
+
return ["/bin/sh", "-c", WATCH, ...argv];
|
|
23565
|
+
}
|
|
23566
|
+
function spawnWatched(argv, options) {
|
|
23567
|
+
const child = Bun.spawn(groupWatchedBy(argv), {
|
|
23568
|
+
...options,
|
|
23569
|
+
stdin: "pipe",
|
|
23570
|
+
detached: true
|
|
23571
|
+
});
|
|
23572
|
+
let closed = false;
|
|
23573
|
+
return {
|
|
23574
|
+
child,
|
|
23575
|
+
endGroup: () => {
|
|
23576
|
+
killGroup(child.pid);
|
|
23577
|
+
if (closed)
|
|
23578
|
+
return;
|
|
23579
|
+
closed = true;
|
|
23580
|
+
child.stdin.end();
|
|
23581
|
+
}
|
|
23582
|
+
};
|
|
23583
|
+
}
|
|
23584
|
+
|
|
23557
23585
|
// ../envoy-client/src/secret-file.ts
|
|
23558
|
-
import {
|
|
23586
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
23559
23587
|
function sendable(value) {
|
|
23560
23588
|
return !/[\s\p{Cc}]/u.test(value);
|
|
23561
23589
|
}
|
|
23562
|
-
function readSecretFile(variable, filePath) {
|
|
23590
|
+
async function readSecretFile(variable, filePath) {
|
|
23563
23591
|
let contents;
|
|
23564
23592
|
try {
|
|
23565
|
-
contents =
|
|
23593
|
+
contents = await readFile3(filePath, "utf8");
|
|
23566
23594
|
} catch (error) {
|
|
23567
23595
|
throw new Error(`${variable} names a file that could not be read (${readErrorCode(error)})`);
|
|
23568
23596
|
}
|
|
@@ -23697,20 +23725,28 @@ function describeSchemaIssue(filePath, error) {
|
|
|
23697
23725
|
}
|
|
23698
23726
|
return `${filePath}: ${issue.path.join(".")}: ${issue.message}`;
|
|
23699
23727
|
}
|
|
23700
|
-
function danglingLink(filePath) {
|
|
23728
|
+
async function danglingLink(filePath) {
|
|
23701
23729
|
try {
|
|
23702
|
-
return
|
|
23730
|
+
return (await lstat3(filePath)).isSymbolicLink() ? await readlink2(filePath) : null;
|
|
23703
23731
|
} catch {
|
|
23704
23732
|
return null;
|
|
23705
23733
|
}
|
|
23706
23734
|
}
|
|
23707
|
-
function
|
|
23735
|
+
async function exists(file) {
|
|
23736
|
+
try {
|
|
23737
|
+
await access2(file);
|
|
23738
|
+
return true;
|
|
23739
|
+
} catch {
|
|
23740
|
+
return false;
|
|
23741
|
+
}
|
|
23742
|
+
}
|
|
23743
|
+
async function parseFile(filePath, schema, checkout) {
|
|
23708
23744
|
let raw;
|
|
23709
23745
|
try {
|
|
23710
|
-
raw =
|
|
23746
|
+
raw = await readFile4(filePath, "utf-8");
|
|
23711
23747
|
} catch (error) {
|
|
23712
23748
|
if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
|
|
23713
|
-
return { kind: "absent", link: danglingLink(filePath) };
|
|
23749
|
+
return { kind: "absent", link: checkout ? null : await danglingLink(filePath) };
|
|
23714
23750
|
}
|
|
23715
23751
|
return { kind: "invalid", reason: `${filePath}: could not be read (${messageFor(error)})` };
|
|
23716
23752
|
}
|
|
@@ -23738,53 +23774,77 @@ function parseFile(filePath, schema, checkout) {
|
|
|
23738
23774
|
}
|
|
23739
23775
|
var FAILURE_KEPT_MS = 60000;
|
|
23740
23776
|
var COMMAND_OUTCOMES = Symbol.for("legion.envoy-config.commands.v1");
|
|
23777
|
+
var COMMAND_RUNS = Symbol.for("legion.envoy-config.command-runs.v1");
|
|
23741
23778
|
var processGlobal = globalThis;
|
|
23742
23779
|
var commandOutcomes = processGlobal[COMMAND_OUTCOMES] ?? new Map;
|
|
23743
23780
|
processGlobal[COMMAND_OUTCOMES] = commandOutcomes;
|
|
23744
|
-
|
|
23781
|
+
var commandRuns = processGlobal[COMMAND_RUNS] ?? new Map;
|
|
23782
|
+
processGlobal[COMMAND_RUNS] = commandRuns;
|
|
23783
|
+
async function unnamedFile() {
|
|
23784
|
+
const directory = await mkdtemp(path.join(tmpdir(), "envoy-command-"));
|
|
23785
|
+
try {
|
|
23786
|
+
await chmod(directory, 448);
|
|
23787
|
+
return await open3(path.join(directory, "stdout"), "wx+", 384);
|
|
23788
|
+
} finally {
|
|
23789
|
+
await rm3(directory, { recursive: true, force: true });
|
|
23790
|
+
}
|
|
23791
|
+
}
|
|
23792
|
+
async function readOutput(file) {
|
|
23793
|
+
const output = Buffer.alloc((await file.stat()).size);
|
|
23794
|
+
let read = 0;
|
|
23795
|
+
while (read < output.length) {
|
|
23796
|
+
const { bytesRead } = await file.read(output, read, output.length - read, read);
|
|
23797
|
+
if (bytesRead === 0)
|
|
23798
|
+
break;
|
|
23799
|
+
read += bytesRead;
|
|
23800
|
+
}
|
|
23801
|
+
return output.toString("utf-8", 0, read);
|
|
23802
|
+
}
|
|
23803
|
+
async function runCommand(command, env, cwd) {
|
|
23745
23804
|
const timeoutMs = commandTimeoutMs(env);
|
|
23746
23805
|
const childEnv = {};
|
|
23747
23806
|
for (const [name, variable] of Object.entries(env)) {
|
|
23748
23807
|
if (variable !== undefined)
|
|
23749
23808
|
childEnv[name] = variable;
|
|
23750
23809
|
}
|
|
23751
|
-
const
|
|
23810
|
+
const file = await unnamedFile();
|
|
23752
23811
|
try {
|
|
23753
|
-
|
|
23754
|
-
const output = path.join(directory, "stdout");
|
|
23755
|
-
const fd = openSync2(output, "wx", 384);
|
|
23756
|
-
let result;
|
|
23812
|
+
let watched;
|
|
23757
23813
|
try {
|
|
23758
|
-
|
|
23814
|
+
watched = spawnWatched(["/bin/sh", "-c", command], {
|
|
23759
23815
|
cwd,
|
|
23760
23816
|
env: childEnv,
|
|
23761
|
-
|
|
23762
|
-
|
|
23763
|
-
stderr: "ignore",
|
|
23764
|
-
timeout: timeoutMs,
|
|
23765
|
-
detached: true
|
|
23817
|
+
stdout: file.fd,
|
|
23818
|
+
stderr: "ignore"
|
|
23766
23819
|
});
|
|
23767
23820
|
} catch (error) {
|
|
23768
23821
|
return { failure: `could not start: ${messageFor(error)}`, timedOut: false };
|
|
23769
|
-
} finally {
|
|
23770
|
-
closeSync2(fd);
|
|
23771
23822
|
}
|
|
23823
|
+
const { child, endGroup } = watched;
|
|
23824
|
+
let timedOut = false;
|
|
23825
|
+
const timer = setTimeout(() => {
|
|
23826
|
+
timedOut = true;
|
|
23827
|
+
endGroup();
|
|
23828
|
+
}, timeoutMs);
|
|
23772
23829
|
try {
|
|
23773
|
-
|
|
23774
|
-
}
|
|
23775
|
-
|
|
23830
|
+
await child.exited;
|
|
23831
|
+
} finally {
|
|
23832
|
+
clearTimeout(timer);
|
|
23833
|
+
}
|
|
23834
|
+
endGroup();
|
|
23835
|
+
if (timedOut) {
|
|
23776
23836
|
return {
|
|
23777
23837
|
failure: `did not finish within ${timeoutMs / 1000} s, and does not run again in this process`,
|
|
23778
23838
|
timedOut: true
|
|
23779
23839
|
};
|
|
23780
23840
|
}
|
|
23781
|
-
if (
|
|
23841
|
+
if (child.exitCode !== 0) {
|
|
23782
23842
|
return {
|
|
23783
|
-
failure: `exited with ${
|
|
23843
|
+
failure: `exited with ${child.signalCode ?? `status ${child.exitCode}`}`,
|
|
23784
23844
|
timedOut: false
|
|
23785
23845
|
};
|
|
23786
23846
|
}
|
|
23787
|
-
const value =
|
|
23847
|
+
const value = (await readOutput(file)).trim();
|
|
23788
23848
|
if (value.length === 0)
|
|
23789
23849
|
return { failure: "printed nothing", timedOut: false };
|
|
23790
23850
|
if (!sendable(value)) {
|
|
@@ -23795,10 +23855,10 @@ function runCommand(command, env, cwd) {
|
|
|
23795
23855
|
}
|
|
23796
23856
|
return { value };
|
|
23797
23857
|
} finally {
|
|
23798
|
-
|
|
23858
|
+
await file.close();
|
|
23799
23859
|
}
|
|
23800
23860
|
}
|
|
23801
|
-
function fileValue(value, field, filePath, env, commands = "run") {
|
|
23861
|
+
async function fileValue(value, field, filePath, env, commands = "run") {
|
|
23802
23862
|
if (!value.startsWith("!")) {
|
|
23803
23863
|
if (!sendable(value)) {
|
|
23804
23864
|
throw new Error(`${filePath}: ${field} holds whitespace or a control character`);
|
|
@@ -23814,42 +23874,50 @@ function fileValue(value, field, filePath, env, commands = "run") {
|
|
|
23814
23874
|
throw new Error(`${filePath}: ${field}'s command has not run in this process yet, and this read does not run it`);
|
|
23815
23875
|
}
|
|
23816
23876
|
} else if (outcome === undefined || "failure" in outcome && !outcome.timedOut && Date.now() - outcome.at >= FAILURE_KEPT_MS) {
|
|
23817
|
-
|
|
23818
|
-
|
|
23877
|
+
let run = commandRuns.get(key);
|
|
23878
|
+
if (run === undefined) {
|
|
23879
|
+
run = runCommand(command, env, cwd).then((ran) => {
|
|
23880
|
+
const kept = { ...ran, at: Date.now() };
|
|
23881
|
+
commandOutcomes.set(key, kept);
|
|
23882
|
+
return kept;
|
|
23883
|
+
}).finally(() => commandRuns.delete(key));
|
|
23884
|
+
commandRuns.set(key, run);
|
|
23885
|
+
}
|
|
23886
|
+
outcome = await run;
|
|
23819
23887
|
}
|
|
23820
23888
|
if ("failure" in outcome)
|
|
23821
23889
|
throw new Error(`${filePath}: ${field}'s command ${outcome.failure}`);
|
|
23822
23890
|
return outcome.value;
|
|
23823
23891
|
}
|
|
23824
|
-
function statDevice(directory) {
|
|
23892
|
+
async function statDevice(directory) {
|
|
23825
23893
|
try {
|
|
23826
|
-
return
|
|
23894
|
+
return (await stat3(directory)).dev;
|
|
23827
23895
|
} catch {
|
|
23828
23896
|
return;
|
|
23829
23897
|
}
|
|
23830
23898
|
}
|
|
23831
|
-
function moveNotice(oldFile, newFile, move, deviceOf) {
|
|
23832
|
-
const oldDevice = deviceOf(path.dirname(oldFile));
|
|
23899
|
+
async function moveNotice(oldFile, newFile, move, deviceOf) {
|
|
23900
|
+
const oldDevice = await deviceOf(path.dirname(oldFile));
|
|
23833
23901
|
let ancestor = path.dirname(newFile);
|
|
23834
|
-
let newDevice = deviceOf(ancestor);
|
|
23902
|
+
let newDevice = await deviceOf(ancestor);
|
|
23835
23903
|
while (newDevice === undefined && path.dirname(ancestor) !== ancestor) {
|
|
23836
23904
|
ancestor = path.dirname(ancestor);
|
|
23837
|
-
newDevice = deviceOf(ancestor);
|
|
23905
|
+
newDevice = await deviceOf(ancestor);
|
|
23838
23906
|
}
|
|
23839
23907
|
if (oldDevice !== undefined && newDevice !== undefined && oldDevice !== newDevice) {
|
|
23840
23908
|
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`;
|
|
23841
23909
|
}
|
|
23842
23910
|
return `${oldFile} is not read: ${move}`;
|
|
23843
23911
|
}
|
|
23844
|
-
function oldUserFileNotice(filePath, env, deviceOf) {
|
|
23912
|
+
async function oldUserFileNotice(filePath, env, deviceOf) {
|
|
23845
23913
|
const home = nonEmpty(env.HOME) ?? homedir();
|
|
23846
23914
|
const old = path.join(home, ".config", "opencode", "envoy.json");
|
|
23847
|
-
if (!
|
|
23915
|
+
if (!await exists(old))
|
|
23848
23916
|
return;
|
|
23849
23917
|
const selected = path.resolve(filePath);
|
|
23850
23918
|
const userFile = path.resolve(home, ".config", "legion", "envoy.json");
|
|
23851
23919
|
if (selected === userFile) {
|
|
23852
|
-
return moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
|
|
23920
|
+
return await moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
|
|
23853
23921
|
}
|
|
23854
23922
|
const profileFile = PLUGIN_HARNESSES.map((harness) => namedDirectory(harness, env)).some((directory) => directory !== undefined && path.isAbsolute(directory) && selected === path.resolve(directory, "envoy.json"));
|
|
23855
23923
|
if (profileFile) {
|
|
@@ -23867,14 +23935,18 @@ function missingConfigNotice(filePath, missing, off) {
|
|
|
23867
23935
|
const old = missing.oldUserFileNotice === undefined ? "" : `; ${missing.oldUserFileNotice}`;
|
|
23868
23936
|
return `no envoy.json at ${filePath}${link}: ${off}${old}`;
|
|
23869
23937
|
}
|
|
23870
|
-
function readEnvoyConfig(filePath, env, options) {
|
|
23938
|
+
async function readEnvoyConfig(filePath, env, options) {
|
|
23871
23939
|
const deviceOf = options.deviceOf ?? statDevice;
|
|
23872
|
-
const chosen = parseFile(filePath, EnvoyFileSchema, false);
|
|
23873
|
-
if (chosen.kind === "invalid")
|
|
23874
|
-
return { kind: "failed", path: filePath, error: chosen.reason };
|
|
23875
23940
|
const resolvedChosen = path.resolve(filePath);
|
|
23876
23941
|
const checkoutPath = path.resolve(options.cwd, ".envoy", "envoy.json");
|
|
23877
|
-
const
|
|
23942
|
+
const oldCheckout = path.resolve(options.cwd, ".opencode", "envoy.json");
|
|
23943
|
+
const [chosen, checkoutFile, oldCheckoutThere] = await Promise.all([
|
|
23944
|
+
parseFile(filePath, EnvoyFileSchema, false),
|
|
23945
|
+
checkoutPath === resolvedChosen ? Promise.resolve({ kind: "absent", link: null }) : parseFile(checkoutPath, CheckoutFileSchema, true),
|
|
23946
|
+
oldCheckout === resolvedChosen ? Promise.resolve(false) : exists(oldCheckout)
|
|
23947
|
+
]);
|
|
23948
|
+
if (chosen.kind === "invalid")
|
|
23949
|
+
return { kind: "failed", path: filePath, error: chosen.reason };
|
|
23878
23950
|
const own = chosen.kind === "valid" ? chosen.settings : {};
|
|
23879
23951
|
let checkout = null;
|
|
23880
23952
|
if (checkoutFile.kind === "invalid") {
|
|
@@ -23888,11 +23960,11 @@ function readEnvoyConfig(filePath, env, options) {
|
|
|
23888
23960
|
askgateError: Object.hasOwn(checkoutFile.settings, "askgate") ? `askgate in ${checkoutPath} is not read; set it in ${filePath}` : null
|
|
23889
23961
|
};
|
|
23890
23962
|
}
|
|
23891
|
-
const
|
|
23892
|
-
const warnings = oldCheckout !== resolvedChosen &&
|
|
23893
|
-
moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
|
|
23963
|
+
const checkoutMissing = checkoutPath === resolvedChosen ? chosen.kind === "absent" : checkoutFile.kind === "absent" || checkoutFile.kind === "invalid" && !await exists(checkoutPath);
|
|
23964
|
+
const warnings = oldCheckout !== resolvedChosen && checkoutMissing && oldCheckoutThere ? [
|
|
23965
|
+
await moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
|
|
23894
23966
|
] : [];
|
|
23895
|
-
const unreadOldUserFile = chosen.kind === "absent" ? oldUserFileNotice(filePath, env, deviceOf) : undefined;
|
|
23967
|
+
const unreadOldUserFile = chosen.kind === "absent" ? await oldUserFileNotice(filePath, env, deviceOf) : undefined;
|
|
23896
23968
|
return {
|
|
23897
23969
|
kind: "read",
|
|
23898
23970
|
path: filePath,
|
|
@@ -23920,10 +23992,10 @@ function bearerCredential(token) {
|
|
|
23920
23992
|
secret: () => token
|
|
23921
23993
|
};
|
|
23922
23994
|
}
|
|
23923
|
-
function bearerSource(env, section, written) {
|
|
23995
|
+
async function bearerSource(env, section, written) {
|
|
23924
23996
|
const pointer = nonEmpty(env[`${section}_TOKEN_FILE`]);
|
|
23925
23997
|
if (pointer !== undefined) {
|
|
23926
|
-
return { kind: "variable", token: readSecretFile(`${section}_TOKEN_FILE`, pointer) };
|
|
23998
|
+
return { kind: "variable", token: await readSecretFile(`${section}_TOKEN_FILE`, pointer) };
|
|
23927
23999
|
}
|
|
23928
24000
|
const plain = nonEmpty(env[`${section}_TOKEN`]);
|
|
23929
24001
|
if (plain !== undefined) {
|
|
@@ -23935,7 +24007,7 @@ function bearerSource(env, section, written) {
|
|
|
23935
24007
|
const bearer = written();
|
|
23936
24008
|
return bearer === undefined ? { kind: "none" } : { kind: "file", ...bearer };
|
|
23937
24009
|
}
|
|
23938
|
-
function fileBearer(bearer, url, section, env, commands = "run") {
|
|
24010
|
+
async function fileBearer(bearer, url, section, env, commands = "run") {
|
|
23939
24011
|
const named = httpUrl2(url)?.origin;
|
|
23940
24012
|
const paired = httpUrl2(bearer.server)?.origin;
|
|
23941
24013
|
if (named !== paired) {
|
|
@@ -31702,12 +31774,12 @@ async function reviewCommand(context) {
|
|
|
31702
31774
|
}
|
|
31703
31775
|
|
|
31704
31776
|
// ../envoy-client/src/session-answers.ts
|
|
31705
|
-
import { mkdirSync, readFileSync
|
|
31777
|
+
import { mkdirSync, readFileSync } from "fs";
|
|
31706
31778
|
import { join as join6 } from "path";
|
|
31707
31779
|
|
|
31708
31780
|
// ../envoy-client/src/dispatch-session-directory.ts
|
|
31709
31781
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
31710
|
-
import { renameSync, rmSync
|
|
31782
|
+
import { renameSync, rmSync, writeFileSync } from "fs";
|
|
31711
31783
|
import { homedir as homedir2 } from "os";
|
|
31712
31784
|
import { join as join5 } from "path";
|
|
31713
31785
|
var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
|
|
@@ -31730,7 +31802,7 @@ function writeAtomically(path, text) {
|
|
|
31730
31802
|
writeFileSync(temporary, text, { mode: PRIVATE_FILE });
|
|
31731
31803
|
renameSync(temporary, path);
|
|
31732
31804
|
} catch (error) {
|
|
31733
|
-
|
|
31805
|
+
rmSync(temporary, { force: true });
|
|
31734
31806
|
throw error;
|
|
31735
31807
|
}
|
|
31736
31808
|
}
|
|
@@ -31873,7 +31945,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
31873
31945
|
var CACHE_FILE = "answers.json";
|
|
31874
31946
|
function readCacheFile(directory, url) {
|
|
31875
31947
|
try {
|
|
31876
|
-
const value = JSON.parse(
|
|
31948
|
+
const value = JSON.parse(readFileSync(join6(directory, CACHE_FILE), "utf-8"));
|
|
31877
31949
|
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)) {
|
|
31878
31950
|
return {
|
|
31879
31951
|
dispatch_url: value.dispatch_url,
|
|
@@ -32366,7 +32438,7 @@ async function executeDispatchTool(input) {
|
|
|
32366
32438
|
}
|
|
32367
32439
|
|
|
32368
32440
|
// ../envoy-client/src/dispatch-first.ts
|
|
32369
|
-
import { readFileSync as
|
|
32441
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
32370
32442
|
import { join as join7 } from "path";
|
|
32371
32443
|
var DISPATCH_FIRST_MARKER = "<dispatch-first-skill>";
|
|
32372
32444
|
function dispatchFirstSkillFile(skillsDirectory) {
|
|
@@ -32375,7 +32447,7 @@ function dispatchFirstSkillFile(skillsDirectory) {
|
|
|
32375
32447
|
function readDispatchFirstContext(skillFile) {
|
|
32376
32448
|
let skill;
|
|
32377
32449
|
try {
|
|
32378
|
-
skill =
|
|
32450
|
+
skill = readFileSync2(skillFile, "utf8");
|
|
32379
32451
|
} catch (error) {
|
|
32380
32452
|
throw new Error(`the dispatch-first skill ${skillFile} could not be read: ${messageFor(error)}`);
|
|
32381
32453
|
}
|
|
@@ -33323,14 +33395,14 @@ function poolIdentity(options) {
|
|
|
33323
33395
|
}
|
|
33324
33396
|
|
|
33325
33397
|
// ../cipher-client/src/projected-token.ts
|
|
33326
|
-
import { readFile as
|
|
33398
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
33327
33399
|
function projectedToken(path, variable) {
|
|
33328
33400
|
const named = `the projected service-account token ${variable} names`;
|
|
33329
33401
|
return {
|
|
33330
33402
|
async read(signal) {
|
|
33331
33403
|
let contents;
|
|
33332
33404
|
try {
|
|
33333
|
-
contents = await
|
|
33405
|
+
contents = await readFile5(path, {
|
|
33334
33406
|
encoding: "utf8",
|
|
33335
33407
|
...signal === undefined ? {} : { signal }
|
|
33336
33408
|
});
|
|
@@ -33648,14 +33720,14 @@ function brokerCredential(env, session, read) {
|
|
|
33648
33720
|
}
|
|
33649
33721
|
|
|
33650
33722
|
// ../envoy-client/src/file-token-credential.ts
|
|
33651
|
-
import { readFileSync as
|
|
33723
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
33652
33724
|
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
33653
33725
|
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
33654
33726
|
var PKCS8_LABEL = "PRIVATE KEY";
|
|
33655
33727
|
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
33656
33728
|
function readNamed(variable, filePath) {
|
|
33657
33729
|
try {
|
|
33658
|
-
return
|
|
33730
|
+
return readFileSync3(filePath, "utf8");
|
|
33659
33731
|
} catch (error) {
|
|
33660
33732
|
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
33661
33733
|
}
|
|
@@ -33743,8 +33815,8 @@ function lostDispatchUrlNotice(env, config) {
|
|
|
33743
33815
|
...old === undefined ? [] : [old]
|
|
33744
33816
|
].join("; ");
|
|
33745
33817
|
}
|
|
33746
|
-
function dispatchSettings(env, config, options = {}) {
|
|
33747
|
-
const target = dispatchTarget(env, config, options.tokenFiles === true);
|
|
33818
|
+
async function dispatchSettings(env, config, options = {}) {
|
|
33819
|
+
const target = await dispatchTarget(env, config, options.tokenFiles === true);
|
|
33748
33820
|
if (!target.enabled)
|
|
33749
33821
|
return target;
|
|
33750
33822
|
const { url, urlSetting, source } = target;
|
|
@@ -33755,7 +33827,7 @@ function dispatchSettings(env, config, options = {}) {
|
|
|
33755
33827
|
else if (source.kind === "files")
|
|
33756
33828
|
credential = fileTokenCredential(source, url);
|
|
33757
33829
|
else {
|
|
33758
|
-
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "DISPATCH", env, options.commands));
|
|
33830
|
+
credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "DISPATCH", env, options.commands));
|
|
33759
33831
|
}
|
|
33760
33832
|
} catch (error) {
|
|
33761
33833
|
return offWithError(messageFor(error));
|
|
@@ -33775,8 +33847,8 @@ function dispatchSettings(env, config, options = {}) {
|
|
|
33775
33847
|
...linkNotice === undefined ? {} : { linkNotice }
|
|
33776
33848
|
};
|
|
33777
33849
|
}
|
|
33778
|
-
function dispatchUrl(env, config) {
|
|
33779
|
-
const target = dispatchTarget(env, config);
|
|
33850
|
+
async function dispatchUrl(env, config) {
|
|
33851
|
+
const target = await dispatchTarget(env, config);
|
|
33780
33852
|
return target.enabled ? target.url : undefined;
|
|
33781
33853
|
}
|
|
33782
33854
|
var BESIDE_TOKEN_FILES = [
|
|
@@ -33880,7 +33952,7 @@ function readTradeSetting(env) {
|
|
|
33880
33952
|
}
|
|
33881
33953
|
return { asOf: cut };
|
|
33882
33954
|
}
|
|
33883
|
-
function dispatchTarget(env, config, tokenFiles = false) {
|
|
33955
|
+
async function dispatchTarget(env, config, tokenFiles = false) {
|
|
33884
33956
|
if (config.kind === "failed")
|
|
33885
33957
|
return offWithError(config.error);
|
|
33886
33958
|
const files = tokenFilesTarget(env, config, tokenFiles);
|
|
@@ -33919,7 +33991,7 @@ function dispatchTarget(env, config, tokenFiles = false) {
|
|
|
33919
33991
|
let source = { kind: "none" };
|
|
33920
33992
|
if (!forced) {
|
|
33921
33993
|
try {
|
|
33922
|
-
source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
|
|
33994
|
+
source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : await bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
|
|
33923
33995
|
} catch (error) {
|
|
33924
33996
|
return offWithError(messageFor(error));
|
|
33925
33997
|
}
|
|
@@ -34353,13 +34425,13 @@ function resolvedInterval(raw, fallback) {
|
|
|
34353
34425
|
return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
|
|
34354
34426
|
}
|
|
34355
34427
|
var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
|
|
34356
|
-
function natsSeedFromEnvironment(env) {
|
|
34428
|
+
async function natsSeedFromEnvironment(env) {
|
|
34357
34429
|
const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
|
|
34358
34430
|
if (file !== undefined) {
|
|
34359
34431
|
if (file === "")
|
|
34360
34432
|
throw new Error("NATS_NKEY_SEED_FILE is set but empty");
|
|
34361
34433
|
return {
|
|
34362
|
-
value: readSecretFile("NATS_NKEY_SEED_FILE", file),
|
|
34434
|
+
value: await readSecretFile("NATS_NKEY_SEED_FILE", file),
|
|
34363
34435
|
source: "the file NATS_NKEY_SEED_FILE names"
|
|
34364
34436
|
};
|
|
34365
34437
|
}
|
|
@@ -34388,23 +34460,23 @@ function requireFileServers(section, namedNatsUrls, filePath, remedy) {
|
|
|
34388
34460
|
throw new Error(`ENVOY_NATS_URL names other servers than ${filePath}'s envoy.natsUrls; set ${remedy} for them`);
|
|
34389
34461
|
}
|
|
34390
34462
|
}
|
|
34391
|
-
function natsSeed(env, section, namedNatsUrls, filePath) {
|
|
34392
|
-
const fromEnvironment = natsSeedFromEnvironment(env);
|
|
34463
|
+
async function natsSeed(env, section, namedNatsUrls, filePath) {
|
|
34464
|
+
const fromEnvironment = await natsSeedFromEnvironment(env);
|
|
34393
34465
|
if (fromEnvironment !== undefined || section.natsSeed === undefined)
|
|
34394
34466
|
return fromEnvironment;
|
|
34395
34467
|
requireFileServers(section, namedNatsUrls, filePath, "NATS_NKEY_SEED_FILE");
|
|
34396
34468
|
return {
|
|
34397
|
-
value: fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
|
|
34469
|
+
value: await fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
|
|
34398
34470
|
source: `envoy.natsSeed in ${filePath}`
|
|
34399
34471
|
};
|
|
34400
34472
|
}
|
|
34401
|
-
function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
34473
|
+
async function natsCredential(env, section, namedNatsUrls, filePath, session) {
|
|
34402
34474
|
const named = nonEmpty(env.NATS_AUTH);
|
|
34403
34475
|
const auth = named !== undefined ? { value: named, source: NATS_AUTH_VAR } : section.natsAuth === undefined ? undefined : { value: section.natsAuth, source: `envoy.natsAuth in ${filePath}` };
|
|
34404
34476
|
if (auth !== undefined && auth.value !== "broker" && auth.value !== "none") {
|
|
34405
34477
|
throw new Error(`${auth.source} is neither broker nor none`);
|
|
34406
34478
|
}
|
|
34407
|
-
const seed = natsSeed(env, section, namedNatsUrls, filePath);
|
|
34479
|
+
const seed = await natsSeed(env, section, namedNatsUrls, filePath);
|
|
34408
34480
|
if (seed !== undefined) {
|
|
34409
34481
|
if (auth?.value === "broker") {
|
|
34410
34482
|
throw new Error(`${auth.source} is ${auth.value}, and ${seed.source} names an nkey seed: set one of the two`);
|
|
@@ -34449,7 +34521,7 @@ function plainHttpOffMachine(url) {
|
|
|
34449
34521
|
const host = URL.canParse(url) ? new URL(url) : undefined;
|
|
34450
34522
|
return host?.protocol === "http:" && !LOOPBACK_HOST2.test(host.hostname) ? host.hostname : undefined;
|
|
34451
34523
|
}
|
|
34452
|
-
function envoySettings(env, config, options = {}) {
|
|
34524
|
+
async function envoySettings(env, config, options = {}) {
|
|
34453
34525
|
if (config.kind === "failed")
|
|
34454
34526
|
return offWithError(config.error);
|
|
34455
34527
|
const section = config.envoy;
|
|
@@ -34480,7 +34552,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
34480
34552
|
let credential;
|
|
34481
34553
|
let noBrokerRoute = "";
|
|
34482
34554
|
try {
|
|
34483
|
-
const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
34555
|
+
const source = await bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
|
|
34484
34556
|
token: section.token,
|
|
34485
34557
|
field: "envoy.token",
|
|
34486
34558
|
path: config.path,
|
|
@@ -34493,7 +34565,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
34493
34565
|
if (!route.traded)
|
|
34494
34566
|
noBrokerRoute = route.gap;
|
|
34495
34567
|
} else {
|
|
34496
|
-
credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
|
|
34568
|
+
credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "ENVOY", env));
|
|
34497
34569
|
}
|
|
34498
34570
|
} catch (error) {
|
|
34499
34571
|
return offWithError(messageFor(error));
|
|
@@ -34513,7 +34585,7 @@ function envoySettings(env, config, options = {}) {
|
|
|
34513
34585
|
inbound = {
|
|
34514
34586
|
natsUrls,
|
|
34515
34587
|
natsServersSetting: natsSetting,
|
|
34516
|
-
natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
34588
|
+
natsCredential: await natsCredential(env, section, namedNatsUrls, config.path, options.session)
|
|
34517
34589
|
};
|
|
34518
34590
|
} catch (error) {
|
|
34519
34591
|
inbound = error instanceof NoSessionNamedError ? { off: messageFor(error), noSessionNamed: true } : { off: messageFor(error) };
|
|
@@ -34597,26 +34669,28 @@ function startNotice(config, dispatch, envoy, nats, lost) {
|
|
|
34597
34669
|
}
|
|
34598
34670
|
return parts.length === 0 ? null : parts.join("; ");
|
|
34599
34671
|
}
|
|
34600
|
-
function sessionSettings(file, env, options) {
|
|
34672
|
+
async function sessionSettings(file, env, options) {
|
|
34601
34673
|
if (file.path === null) {
|
|
34602
34674
|
const off = offWithError(file.error);
|
|
34603
34675
|
return { dispatch: off, envoy: off, notice: `${file.error}: Dispatch and Envoy are off` };
|
|
34604
34676
|
}
|
|
34605
|
-
const config = readEnvoyConfig(file.path, env, options);
|
|
34606
|
-
const dispatch
|
|
34607
|
-
|
|
34677
|
+
const config = await readEnvoyConfig(file.path, env, options);
|
|
34678
|
+
const [dispatch, envoy] = await Promise.all([
|
|
34679
|
+
dispatchSettings(env, config, { session: options.session }),
|
|
34680
|
+
envoySettings(env, config, { nats: options.nats, session: options.session })
|
|
34681
|
+
]);
|
|
34608
34682
|
return {
|
|
34609
34683
|
dispatch,
|
|
34610
34684
|
envoy,
|
|
34611
34685
|
notice: startNotice(config, dispatch, envoy, options.nats !== false, config.kind === "read" ? lostDispatchUrlNotice(env, config) : undefined)
|
|
34612
34686
|
};
|
|
34613
34687
|
}
|
|
34614
|
-
function sessionDispatchSettings(file, env, options) {
|
|
34688
|
+
async function sessionDispatchSettings(file, env, options) {
|
|
34615
34689
|
if (file.path === null)
|
|
34616
34690
|
return { dispatch: offWithError(file.error), warnings: [], missing: null };
|
|
34617
|
-
const config = readEnvoyConfig(file.path, env, options);
|
|
34691
|
+
const config = await readEnvoyConfig(file.path, env, options);
|
|
34618
34692
|
return {
|
|
34619
|
-
dispatch: dispatchSettings(env, config, {
|
|
34693
|
+
dispatch: await dispatchSettings(env, config, {
|
|
34620
34694
|
commands: options.commands,
|
|
34621
34695
|
session: options.session,
|
|
34622
34696
|
tokenFiles: options.tokenFiles
|
|
@@ -34625,15 +34699,15 @@ function sessionDispatchSettings(file, env, options) {
|
|
|
34625
34699
|
missing: config.kind === "read" ? config.missing : null
|
|
34626
34700
|
};
|
|
34627
34701
|
}
|
|
34628
|
-
function sessionDispatchUrl(file, env, options) {
|
|
34702
|
+
async function sessionDispatchUrl(file, env, options) {
|
|
34629
34703
|
if (file.path === null)
|
|
34630
34704
|
return;
|
|
34631
|
-
return dispatchUrl(env, readEnvoyConfig(file.path, env, options));
|
|
34705
|
+
return dispatchUrl(env, await readEnvoyConfig(file.path, env, options));
|
|
34632
34706
|
}
|
|
34633
|
-
function sessionEnvoySettings(file, env, options) {
|
|
34707
|
+
async function sessionEnvoySettings(file, env, options) {
|
|
34634
34708
|
if (file.path === null)
|
|
34635
34709
|
return offWithError(file.error);
|
|
34636
|
-
return envoySettings(env, readEnvoyConfig(file.path, env, options), {
|
|
34710
|
+
return envoySettings(env, await readEnvoyConfig(file.path, env, options), {
|
|
34637
34711
|
nats: options.nats,
|
|
34638
34712
|
session: options.session
|
|
34639
34713
|
});
|
|
@@ -34731,12 +34805,7 @@ async function userConfigChain(timeoutMs = JJ_CONFIG_PATH_TIMEOUT_MS, env = proc
|
|
|
34731
34805
|
stdout: "pipe",
|
|
34732
34806
|
stderr: "pipe"
|
|
34733
34807
|
});
|
|
34734
|
-
const
|
|
34735
|
-
try {
|
|
34736
|
-
process.kill(-child.pid, "SIGKILL");
|
|
34737
|
-
} catch {}
|
|
34738
|
-
};
|
|
34739
|
-
const exited = child.exited.finally(killGroup);
|
|
34808
|
+
const exited = child.exited.finally(() => killGroup(child.pid));
|
|
34740
34809
|
const completed = Promise.all([
|
|
34741
34810
|
exited,
|
|
34742
34811
|
new Response(child.stdout).text(),
|
|
@@ -34745,7 +34814,7 @@ async function userConfigChain(timeoutMs = JJ_CONFIG_PATH_TIMEOUT_MS, env = proc
|
|
|
34745
34814
|
const stdout = await new Promise((resolve) => {
|
|
34746
34815
|
const stop = () => {
|
|
34747
34816
|
clearTimeout(timer);
|
|
34748
|
-
killGroup();
|
|
34817
|
+
killGroup(child.pid);
|
|
34749
34818
|
resolve(undefined);
|
|
34750
34819
|
};
|
|
34751
34820
|
const timer = setTimeout(stop, timeoutMs);
|
|
@@ -34829,18 +34898,18 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
34829
34898
|
|
|
34830
34899
|
// src/codex/codex-session-record.ts
|
|
34831
34900
|
import { spawnSync } from "child_process";
|
|
34832
|
-
import { readFileSync as
|
|
34833
|
-
import { mkdir as mkdir4, readFile as
|
|
34901
|
+
import { readFileSync as readFileSync5, readlinkSync, unwatchFile, watchFile } from "fs";
|
|
34902
|
+
import { mkdir as mkdir4, readFile as readFile7, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
34834
34903
|
import { homedir as homedir3 } from "os";
|
|
34835
34904
|
import { basename as basename4, dirname as dirname5, join as join10 } from "path";
|
|
34836
34905
|
|
|
34837
34906
|
// src/session-identity.ts
|
|
34838
|
-
import { readFile as
|
|
34907
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
34839
34908
|
import { basename as basename3, join as join9 } from "path";
|
|
34840
34909
|
|
|
34841
34910
|
// src/session-state.ts
|
|
34842
|
-
import { readFileSync as
|
|
34843
|
-
import { mkdir as mkdir3, readdir as readdir3, rename as rename4, rm as
|
|
34911
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
34912
|
+
import { mkdir as mkdir3, readdir as readdir3, rename as rename4, rm as rm4, stat as stat4, utimes as utimes2, writeFile as writeFile2 } from "fs/promises";
|
|
34844
34913
|
import { dirname as dirname4, join as join8 } from "path";
|
|
34845
34914
|
async function writeAtomicStateFile(file, contents) {
|
|
34846
34915
|
await mkdir3(dirname4(file), { recursive: true, mode: 448 });
|
|
@@ -34862,12 +34931,12 @@ async function pruneStateDirectory(directory, isStale) {
|
|
|
34862
34931
|
const file = join8(directory, entry);
|
|
34863
34932
|
if (!await isStale(file))
|
|
34864
34933
|
continue;
|
|
34865
|
-
await
|
|
34934
|
+
await rm4(file, { recursive: true, force: true });
|
|
34866
34935
|
}
|
|
34867
34936
|
}
|
|
34868
34937
|
var STATE_FILE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
34869
34938
|
async function writtenLongAgo(file) {
|
|
34870
|
-
const modified = await
|
|
34939
|
+
const modified = await stat4(file).then((stats) => stats.mtimeMs, () => {
|
|
34871
34940
|
return;
|
|
34872
34941
|
});
|
|
34873
34942
|
return modified !== undefined && Date.now() - modified > STATE_FILE_MAX_AGE_MS;
|
|
@@ -34881,11 +34950,11 @@ async function writeChosenTitle(file, title) {
|
|
|
34881
34950
|
`);
|
|
34882
34951
|
}
|
|
34883
34952
|
async function removeChosenTitle(file) {
|
|
34884
|
-
await
|
|
34953
|
+
await rm4(file, { force: true });
|
|
34885
34954
|
}
|
|
34886
34955
|
function readChosenTitleSync(file) {
|
|
34887
34956
|
try {
|
|
34888
|
-
return
|
|
34957
|
+
return readFileSync4(file, "utf8");
|
|
34889
34958
|
} catch {
|
|
34890
34959
|
return;
|
|
34891
34960
|
}
|
|
@@ -34946,7 +35015,7 @@ class UnparseableRoleRecordError extends Error {
|
|
|
34946
35015
|
async function readPersistedRole(roleFile) {
|
|
34947
35016
|
let bytes;
|
|
34948
35017
|
try {
|
|
34949
|
-
bytes = await
|
|
35018
|
+
bytes = await readFile6(roleFile, "utf8");
|
|
34950
35019
|
} catch (error) {
|
|
34951
35020
|
if (hasErrnoCode(error, "ENOENT"))
|
|
34952
35021
|
return;
|
|
@@ -34968,7 +35037,7 @@ async function writeSessionHandoff(file, sessionId) {
|
|
|
34968
35037
|
}
|
|
34969
35038
|
async function readSessionHandoff(file) {
|
|
34970
35039
|
try {
|
|
34971
|
-
const id = (await
|
|
35040
|
+
const id = (await readFile6(file, "utf8")).trim();
|
|
34972
35041
|
return id.length === 0 ? undefined : id;
|
|
34973
35042
|
} catch (error) {
|
|
34974
35043
|
if (hasErrnoCode(error, "ENOENT"))
|
|
@@ -35032,7 +35101,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
|
|
|
35032
35101
|
}
|
|
35033
35102
|
async function sessionEnded(file) {
|
|
35034
35103
|
try {
|
|
35035
|
-
await
|
|
35104
|
+
await readFile7(file);
|
|
35036
35105
|
return true;
|
|
35037
35106
|
} catch {
|
|
35038
35107
|
return false;
|
|
@@ -35046,7 +35115,7 @@ async function writeCodexSessionRecord(file, value) {
|
|
|
35046
35115
|
}
|
|
35047
35116
|
async function readCodexSessionRecord(file) {
|
|
35048
35117
|
try {
|
|
35049
|
-
const parsed = CodexSessionRecord.safeParse(JSON.parse(await
|
|
35118
|
+
const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile7(file, "utf8")));
|
|
35050
35119
|
return parsed.success ? parsed.data : undefined;
|
|
35051
35120
|
} catch {
|
|
35052
35121
|
return;
|
|
@@ -35078,14 +35147,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
35078
35147
|
}
|
|
35079
35148
|
function procComm(pid) {
|
|
35080
35149
|
try {
|
|
35081
|
-
return
|
|
35150
|
+
return readFileSync5(`/proc/${pid}/comm`, "utf8").trim();
|
|
35082
35151
|
} catch {
|
|
35083
35152
|
return;
|
|
35084
35153
|
}
|
|
35085
35154
|
}
|
|
35086
35155
|
function procParent(pid) {
|
|
35087
35156
|
try {
|
|
35088
|
-
const stat =
|
|
35157
|
+
const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
|
|
35089
35158
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
35090
35159
|
return Number.isInteger(parent) ? parent : undefined;
|
|
35091
35160
|
} catch {
|
|
@@ -35099,7 +35168,7 @@ var PS_OPTIONS = {
|
|
|
35099
35168
|
};
|
|
35100
35169
|
function procStarted(pid) {
|
|
35101
35170
|
try {
|
|
35102
|
-
const stat =
|
|
35171
|
+
const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
|
|
35103
35172
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
35104
35173
|
} catch {
|
|
35105
35174
|
return;
|
|
@@ -35120,7 +35189,7 @@ function recordOfProcess(record, pid) {
|
|
|
35120
35189
|
function sharedAppServer(pid) {
|
|
35121
35190
|
let argv;
|
|
35122
35191
|
try {
|
|
35123
|
-
argv =
|
|
35192
|
+
argv = readFileSync5(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
35124
35193
|
} catch {
|
|
35125
35194
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
35126
35195
|
if (ps.status !== 0)
|
|
@@ -35177,7 +35246,7 @@ async function pruneCodexSessionRecords(stateDirectory) {
|
|
|
35177
35246
|
}
|
|
35178
35247
|
function codexExecutable(pid) {
|
|
35179
35248
|
try {
|
|
35180
|
-
return
|
|
35249
|
+
return readlinkSync(`/proc/${pid}/exe`);
|
|
35181
35250
|
} catch {
|
|
35182
35251
|
return;
|
|
35183
35252
|
}
|
|
@@ -35273,7 +35342,7 @@ function singleQuoted(value) {
|
|
|
35273
35342
|
}
|
|
35274
35343
|
function envFileText(envFile) {
|
|
35275
35344
|
try {
|
|
35276
|
-
return
|
|
35345
|
+
return readFileSync6(envFile, "utf8");
|
|
35277
35346
|
} catch (error) {
|
|
35278
35347
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
35279
35348
|
throw error;
|
|
@@ -35350,7 +35419,7 @@ async function openAsks(raw) {
|
|
|
35350
35419
|
`);
|
|
35351
35420
|
}
|
|
35352
35421
|
const directory = claudeProjectDirectory({ CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] }, input.cwd ?? process.cwd());
|
|
35353
|
-
const { dispatch, warnings, missing } = sessionDispatchSettings(chosen, process.env, {
|
|
35422
|
+
const { dispatch, warnings, missing } = await sessionDispatchSettings(chosen, process.env, {
|
|
35354
35423
|
cwd: directory,
|
|
35355
35424
|
session: input.session_id
|
|
35356
35425
|
});
|
|
@@ -35377,12 +35446,13 @@ ${formatOpenAsksSummary(snapshot, linkBaseOf(dispatch.publicUrl ?? dispatch.url)
|
|
|
35377
35446
|
`);
|
|
35378
35447
|
}
|
|
35379
35448
|
}
|
|
35380
|
-
function dispatchFirst(raw) {
|
|
35449
|
+
async function dispatchFirst(raw) {
|
|
35381
35450
|
const input = DispatchFirstInput.parse(raw);
|
|
35382
35451
|
const directory = claudeProjectDirectory({ CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] }, input.cwd ?? process.cwd());
|
|
35383
35452
|
const chosen = sessionConfigFile(HOST, process.env);
|
|
35384
|
-
if (!sessionDispatchSettings(chosen, process.env, { cwd: directory }).dispatch.enabled)
|
|
35453
|
+
if (!(await sessionDispatchSettings(chosen, process.env, { cwd: directory })).dispatch.enabled) {
|
|
35385
35454
|
return;
|
|
35455
|
+
}
|
|
35386
35456
|
const pluginRoot = configuredValue(process.env["CLAUDE_PLUGIN_ROOT"]);
|
|
35387
35457
|
if (pluginRoot === undefined) {
|
|
35388
35458
|
throw new Error("CLAUDE_PLUGIN_ROOT is unset; Claude Code sets it for every plugin hook");
|
|
@@ -35398,8 +35468,8 @@ function refreshLockHeld(lock) {
|
|
|
35398
35468
|
let age;
|
|
35399
35469
|
let text;
|
|
35400
35470
|
try {
|
|
35401
|
-
age = Date.now() -
|
|
35402
|
-
text =
|
|
35471
|
+
age = Date.now() - statSync(lock).mtimeMs;
|
|
35472
|
+
text = readFileSync6(lock, "utf8");
|
|
35403
35473
|
} catch (error) {
|
|
35404
35474
|
if (hasErrnoCode(error, "ENOENT"))
|
|
35405
35475
|
return false;
|
|
@@ -35428,14 +35498,14 @@ function takeRefreshLock(lock) {
|
|
|
35428
35498
|
}
|
|
35429
35499
|
if (refreshLockHeld(lock))
|
|
35430
35500
|
return false;
|
|
35431
|
-
|
|
35501
|
+
rmSync2(lock, { force: true });
|
|
35432
35502
|
}
|
|
35433
35503
|
return false;
|
|
35434
35504
|
}
|
|
35435
35505
|
function refreshOutcome(file, since) {
|
|
35436
35506
|
let value;
|
|
35437
35507
|
try {
|
|
35438
|
-
value = JSON.parse(
|
|
35508
|
+
value = JSON.parse(readFileSync6(file, "utf8"));
|
|
35439
35509
|
} catch {
|
|
35440
35510
|
return;
|
|
35441
35511
|
}
|
|
@@ -35478,14 +35548,14 @@ async function refreshedAnswers(session, cwd, dispatchUrl, startedAt, by) {
|
|
|
35478
35548
|
}
|
|
35479
35549
|
async function answersMessage(session, cwd, startedAt, by) {
|
|
35480
35550
|
const file = sessionConfigFile(HOST, process.env);
|
|
35481
|
-
let { dispatch } = sessionDispatchSettings(file, process.env, {
|
|
35551
|
+
let { dispatch } = await sessionDispatchSettings(file, process.env, {
|
|
35482
35552
|
cwd,
|
|
35483
35553
|
commands: "kept",
|
|
35484
35554
|
session
|
|
35485
35555
|
});
|
|
35486
35556
|
let dispatchUrl;
|
|
35487
35557
|
if (!dispatch.enabled && dispatch.error !== null) {
|
|
35488
|
-
dispatchUrl = sessionDispatchUrl(file, process.env, { cwd });
|
|
35558
|
+
dispatchUrl = await sessionDispatchUrl(file, process.env, { cwd });
|
|
35489
35559
|
if (dispatchUrl !== undefined) {
|
|
35490
35560
|
const refreshed = await refreshedAnswers(session, cwd, dispatchUrl, startedAt, by);
|
|
35491
35561
|
if ("text" in refreshed)
|
|
@@ -35540,8 +35610,8 @@ async function answersRefresh(session, cwd) {
|
|
|
35540
35610
|
if (takeRefreshLock(lock)) {
|
|
35541
35611
|
try {
|
|
35542
35612
|
const file = sessionConfigFile(HOST, process.env);
|
|
35543
|
-
const dispatchUrl = sessionDispatchUrl(file, process.env, { cwd }) ?? null;
|
|
35544
|
-
const { dispatch } = sessionDispatchSettings(file, process.env, { cwd, session });
|
|
35613
|
+
const dispatchUrl = await sessionDispatchUrl(file, process.env, { cwd }) ?? null;
|
|
35614
|
+
const { dispatch } = await sessionDispatchSettings(file, process.env, { cwd, session });
|
|
35545
35615
|
const read = await readSessionAnswers({
|
|
35546
35616
|
session,
|
|
35547
35617
|
dispatch,
|
|
@@ -35556,7 +35626,7 @@ async function answersRefresh(session, cwd) {
|
|
|
35556
35626
|
};
|
|
35557
35627
|
writeAtomically(join11(directory, REFRESH_OUTCOME), JSON.stringify(outcome));
|
|
35558
35628
|
} finally {
|
|
35559
|
-
|
|
35629
|
+
rmSync2(lock, { force: true });
|
|
35560
35630
|
}
|
|
35561
35631
|
}
|
|
35562
35632
|
process.exit(0);
|
|
@@ -35588,4 +35658,4 @@ if (mode === "open-asks") {
|
|
|
35588
35658
|
await openAsks(input);
|
|
35589
35659
|
await endOnceWritten([process.stdout, process.stderr], holdsDeviceLoginLock, (code) => process.exit(code));
|
|
35590
35660
|
} else
|
|
35591
|
-
dispatchFirst(input);
|
|
35661
|
+
await dispatchFirst(input);
|