claude-use 11.52.0 → 11.52.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/dist/cli.cjs +626 -567
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -9022,8 +9022,8 @@ var init_ko = __esm({
|
|
|
9022
9022
|
});
|
|
9023
9023
|
|
|
9024
9024
|
// node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/locales/lt.js
|
|
9025
|
-
function getUnitTypeFromNumber(
|
|
9026
|
-
const abs = Math.abs(
|
|
9025
|
+
function getUnitTypeFromNumber(number5) {
|
|
9026
|
+
const abs = Math.abs(number5);
|
|
9027
9027
|
const last = abs % 10;
|
|
9028
9028
|
const last2 = abs % 100;
|
|
9029
9029
|
if (last2 >= 11 && last2 <= 19 || last === 0)
|
|
@@ -9041,8 +9041,8 @@ var capitalizeFirstCharacter, error33;
|
|
|
9041
9041
|
var init_lt = __esm({
|
|
9042
9042
|
"node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/locales/lt.js"() {
|
|
9043
9043
|
init_util();
|
|
9044
|
-
capitalizeFirstCharacter = (
|
|
9045
|
-
return
|
|
9044
|
+
capitalizeFirstCharacter = (text3) => {
|
|
9045
|
+
return text3.charAt(0).toUpperCase() + text3.slice(1);
|
|
9046
9046
|
};
|
|
9047
9047
|
error33 = () => {
|
|
9048
9048
|
const Sizable = {
|
|
@@ -20530,8 +20530,8 @@ var require_common = __commonJS({
|
|
|
20530
20530
|
}
|
|
20531
20531
|
return result;
|
|
20532
20532
|
}
|
|
20533
|
-
function isNegativeZero(
|
|
20534
|
-
return
|
|
20533
|
+
function isNegativeZero(number5) {
|
|
20534
|
+
return number5 === 0 && Number.NEGATIVE_INFINITY === 1 / number5;
|
|
20535
20535
|
}
|
|
20536
20536
|
module2.exports.isNothing = isNothing;
|
|
20537
20537
|
module2.exports.isObject = isObject5;
|
|
@@ -23713,9 +23713,9 @@ var require_env_paths = __commonJS({
|
|
|
23713
23713
|
"node_modules/.pnpm/env-paths@2.2.1/node_modules/env-paths/index.js"(exports2, module2) {
|
|
23714
23714
|
"use strict";
|
|
23715
23715
|
var path66 = require("path");
|
|
23716
|
-
var
|
|
23717
|
-
var homedir =
|
|
23718
|
-
var tmpdir =
|
|
23716
|
+
var os14 = require("os");
|
|
23717
|
+
var homedir = os14.homedir();
|
|
23718
|
+
var tmpdir = os14.tmpdir();
|
|
23719
23719
|
var { env } = process;
|
|
23720
23720
|
var macos = (name) => {
|
|
23721
23721
|
const library = path66.join(homedir, "Library");
|
|
@@ -25040,8 +25040,8 @@ var init_proxyBypass = __esm({
|
|
|
25040
25040
|
function distinctList(member) {
|
|
25041
25041
|
return external_exports.array(member).refine((items) => new Set(items).size === items.length, "must not repeat a segment");
|
|
25042
25042
|
}
|
|
25043
|
-
function isSingleVisibleGrapheme(
|
|
25044
|
-
return [...GRAPHEMES.segment(
|
|
25043
|
+
function isSingleVisibleGrapheme(text3) {
|
|
25044
|
+
return [...GRAPHEMES.segment(text3)].length === 1 && !/[\p{C}\p{Z}]/u.test(text3);
|
|
25045
25045
|
}
|
|
25046
25046
|
function isPlainObject2(value2) {
|
|
25047
25047
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
@@ -27620,10 +27620,10 @@ var init_schema = __esm({
|
|
|
27620
27620
|
});
|
|
27621
27621
|
|
|
27622
27622
|
// src/frontdoor/state.ts
|
|
27623
|
-
function readFrontDoorState(
|
|
27623
|
+
function readFrontDoorState(fs30, stateFile) {
|
|
27624
27624
|
let raw;
|
|
27625
27625
|
try {
|
|
27626
|
-
raw =
|
|
27626
|
+
raw = fs30.readFileUtf8(stateFile);
|
|
27627
27627
|
} catch {
|
|
27628
27628
|
return void 0;
|
|
27629
27629
|
}
|
|
@@ -27637,9 +27637,9 @@ function readFrontDoorState(fs29, stateFile) {
|
|
|
27637
27637
|
return void 0;
|
|
27638
27638
|
}
|
|
27639
27639
|
}
|
|
27640
|
-
function writeFrontDoorState(
|
|
27641
|
-
|
|
27642
|
-
|
|
27640
|
+
function writeFrontDoorState(fs30, stateFile, state) {
|
|
27641
|
+
fs30.mkdirp(import_node_path5.default.dirname(stateFile));
|
|
27642
|
+
fs30.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
27643
27643
|
`);
|
|
27644
27644
|
}
|
|
27645
27645
|
function directOrigin(port) {
|
|
@@ -27649,37 +27649,37 @@ function frontDoorOrigin(state) {
|
|
|
27649
27649
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
27650
27650
|
return port === void 0 ? void 0 : directOrigin(port);
|
|
27651
27651
|
}
|
|
27652
|
-
function writeFrontDoorDirectRecord(
|
|
27653
|
-
|
|
27654
|
-
|
|
27652
|
+
function writeFrontDoorDirectRecord(fs30, recordsDir, record2) {
|
|
27653
|
+
fs30.mkdirp(recordsDir);
|
|
27654
|
+
fs30.writeFilePrivate(import_node_path5.default.join(recordsDir, `${String(record2.pid)}.json`), `${JSON.stringify({ directPort: record2.directPort })}
|
|
27655
27655
|
`);
|
|
27656
27656
|
}
|
|
27657
|
-
function removeFrontDoorDirectRecord(
|
|
27658
|
-
|
|
27657
|
+
function removeFrontDoorDirectRecord(fs30, recordsDir, pid) {
|
|
27658
|
+
fs30.removeRecursive(import_node_path5.default.join(recordsDir, `${String(pid)}.json`));
|
|
27659
27659
|
}
|
|
27660
|
-
function markFrontDoorDraining(
|
|
27661
|
-
|
|
27662
|
-
|
|
27660
|
+
function markFrontDoorDraining(fs30, markersDir, pid) {
|
|
27661
|
+
fs30.mkdirp(markersDir);
|
|
27662
|
+
fs30.writeFilePrivate(import_node_path5.default.join(markersDir, String(pid)), "\n");
|
|
27663
27663
|
}
|
|
27664
|
-
function unmarkFrontDoorDraining(
|
|
27665
|
-
|
|
27664
|
+
function unmarkFrontDoorDraining(fs30, markersDir, pid) {
|
|
27665
|
+
fs30.removeRecursive(import_node_path5.default.join(markersDir, String(pid)));
|
|
27666
27666
|
}
|
|
27667
|
-
function listDrainingFrontDoors(
|
|
27668
|
-
return
|
|
27667
|
+
function listDrainingFrontDoors(fs30, markersDir, isRunning) {
|
|
27668
|
+
return fs30.readdir(markersDir).flatMap((file2) => /^[1-9]\d*$/.test(file2) && Number.isSafeInteger(Number(file2)) ? [Number(file2)] : []).filter(isRunning).sort((a10, b) => a10 - b);
|
|
27669
27669
|
}
|
|
27670
27670
|
function recordPid(file2) {
|
|
27671
27671
|
const pidText = /^([1-9]\d*)\.json$/.exec(file2)?.[1];
|
|
27672
27672
|
const pid = pidText === void 0 ? void 0 : Number(pidText);
|
|
27673
27673
|
return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
|
|
27674
27674
|
}
|
|
27675
|
-
function readDirectRecordEntry(
|
|
27675
|
+
function readDirectRecordEntry(fs30, recordsDir, file2) {
|
|
27676
27676
|
const pid = recordPid(file2);
|
|
27677
27677
|
if (pid === void 0) {
|
|
27678
27678
|
return void 0;
|
|
27679
27679
|
}
|
|
27680
27680
|
let raw;
|
|
27681
27681
|
try {
|
|
27682
|
-
raw =
|
|
27682
|
+
raw = fs30.readFileUtf8(import_node_path5.default.join(recordsDir, file2));
|
|
27683
27683
|
} catch {
|
|
27684
27684
|
return void 0;
|
|
27685
27685
|
}
|
|
@@ -27693,47 +27693,47 @@ function readDirectRecordEntry(fs29, recordsDir, file2) {
|
|
|
27693
27693
|
return { malformed: true };
|
|
27694
27694
|
}
|
|
27695
27695
|
}
|
|
27696
|
-
function listFrontDoorDirectRecords(
|
|
27697
|
-
return
|
|
27698
|
-
const entry = readDirectRecordEntry(
|
|
27696
|
+
function listFrontDoorDirectRecords(fs30, recordsDir) {
|
|
27697
|
+
return fs30.readdir(recordsDir).flatMap((file2) => {
|
|
27698
|
+
const entry = readDirectRecordEntry(fs30, recordsDir, file2);
|
|
27699
27699
|
return entry?.record === void 0 ? [] : [entry.record];
|
|
27700
27700
|
}).sort((a10, b) => a10.pid - b.pid);
|
|
27701
27701
|
}
|
|
27702
|
-
function pruneMalformedFrontDoorDirectFiles(
|
|
27703
|
-
for (const file2 of
|
|
27702
|
+
function pruneMalformedFrontDoorDirectFiles(fs30, recordsDir, isRunning) {
|
|
27703
|
+
for (const file2 of fs30.readdir(recordsDir)) {
|
|
27704
27704
|
const writer = RECORD_TEMPORARY_FILE.exec(file2)?.[1];
|
|
27705
27705
|
const stale = writer !== void 0 && !isRunning(Number(writer));
|
|
27706
|
-
if (stale || readDirectRecordEntry(
|
|
27707
|
-
|
|
27706
|
+
if (stale || readDirectRecordEntry(fs30, recordsDir, file2)?.malformed === true) {
|
|
27707
|
+
fs30.removeRecursive(import_node_path5.default.join(recordsDir, file2));
|
|
27708
27708
|
}
|
|
27709
27709
|
}
|
|
27710
27710
|
}
|
|
27711
27711
|
function liveFrontDoorDirectRecords(records, liveness) {
|
|
27712
27712
|
return records.filter((record2) => liveness.doors.has(record2.pid) || liveness.unknown.has(record2.pid));
|
|
27713
27713
|
}
|
|
27714
|
-
function pruneDeadFrontDoorDirectRecords(
|
|
27714
|
+
function pruneDeadFrontDoorDirectRecords(fs30, recordsDir, records, liveness) {
|
|
27715
27715
|
for (const record2 of records) {
|
|
27716
27716
|
if (!liveness.doors.has(record2.pid) && !liveness.unknown.has(record2.pid)) {
|
|
27717
|
-
removeFrontDoorDirectRecord(
|
|
27717
|
+
removeFrontDoorDirectRecord(fs30, recordsDir, record2.pid);
|
|
27718
27718
|
}
|
|
27719
27719
|
}
|
|
27720
27720
|
}
|
|
27721
27721
|
function recordOf(details) {
|
|
27722
27722
|
return details === void 0 ? {} : { sessionId: details.sessionId, ...details.models === void 0 ? {} : { models: details.models } };
|
|
27723
27723
|
}
|
|
27724
|
-
function writeFrontDoorSession(
|
|
27725
|
-
|
|
27726
|
-
|
|
27724
|
+
function writeFrontDoorSession(fs30, sessionsDir, session) {
|
|
27725
|
+
fs30.mkdirPrivate(sessionsDir);
|
|
27726
|
+
fs30.writeFilePrivate(import_node_path5.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
27727
27727
|
`);
|
|
27728
27728
|
}
|
|
27729
|
-
function listFrontDoorSessions(
|
|
27729
|
+
function listFrontDoorSessions(fs30, sessionsDir) {
|
|
27730
27730
|
const sessions = [];
|
|
27731
|
-
for (const name of
|
|
27731
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27732
27732
|
if (!name.endsWith(".json")) {
|
|
27733
27733
|
continue;
|
|
27734
27734
|
}
|
|
27735
27735
|
try {
|
|
27736
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
27736
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs30.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
|
|
27737
27737
|
if (parsed.success) {
|
|
27738
27738
|
sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt, ...parsed.data.supervisorPid === void 0 ? {} : { supervisorPid: parsed.data.supervisorPid } });
|
|
27739
27739
|
}
|
|
@@ -27743,27 +27743,27 @@ function listFrontDoorSessions(fs29, sessionsDir) {
|
|
|
27743
27743
|
}
|
|
27744
27744
|
return sessions.sort((a10, b) => a10.pid - b.pid);
|
|
27745
27745
|
}
|
|
27746
|
-
function removeFrontDoorSession(
|
|
27747
|
-
|
|
27746
|
+
function removeFrontDoorSession(fs30, sessionsDir, pid) {
|
|
27747
|
+
fs30.removeRecursive(import_node_path5.default.join(sessionsDir, `${String(pid)}.json`));
|
|
27748
27748
|
}
|
|
27749
|
-
function pruneDeadFrontDoorSessions(
|
|
27749
|
+
function pruneDeadFrontDoorSessions(fs30, sessionsDir, isRunning) {
|
|
27750
27750
|
const removed = [];
|
|
27751
|
-
for (const session of listFrontDoorSessions(
|
|
27751
|
+
for (const session of listFrontDoorSessions(fs30, sessionsDir)) {
|
|
27752
27752
|
if (!isRunning(session.pid)) {
|
|
27753
|
-
removeFrontDoorSession(
|
|
27753
|
+
removeFrontDoorSession(fs30, sessionsDir, session.pid);
|
|
27754
27754
|
removed.push(session.pid);
|
|
27755
27755
|
}
|
|
27756
27756
|
}
|
|
27757
27757
|
return removed;
|
|
27758
27758
|
}
|
|
27759
|
-
function liveSessionTokens(
|
|
27759
|
+
function liveSessionTokens(fs30, sessionsDir) {
|
|
27760
27760
|
const tokens = /* @__PURE__ */ new Set();
|
|
27761
|
-
for (const name of
|
|
27761
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27762
27762
|
if (!name.endsWith(".json")) {
|
|
27763
27763
|
continue;
|
|
27764
27764
|
}
|
|
27765
27765
|
try {
|
|
27766
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
27766
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs30.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
|
|
27767
27767
|
if (parsed.success) {
|
|
27768
27768
|
tokens.add(parsed.data.token);
|
|
27769
27769
|
}
|
|
@@ -27773,13 +27773,13 @@ function liveSessionTokens(fs29, sessionsDir) {
|
|
|
27773
27773
|
}
|
|
27774
27774
|
return tokens;
|
|
27775
27775
|
}
|
|
27776
|
-
function readFrontDoorSessionModels(
|
|
27777
|
-
for (const name of
|
|
27776
|
+
function readFrontDoorSessionModels(fs30, sessionsDir, sessionId) {
|
|
27777
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27778
27778
|
if (!name.endsWith(".json")) {
|
|
27779
27779
|
continue;
|
|
27780
27780
|
}
|
|
27781
27781
|
try {
|
|
27782
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
27782
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs30.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
|
|
27783
27783
|
if (parsed.success && parsed.data.sessionId === sessionId) {
|
|
27784
27784
|
return parsed.data.models;
|
|
27785
27785
|
}
|
|
@@ -27842,43 +27842,43 @@ function parseJson(raw, schema) {
|
|
|
27842
27842
|
const parsed = schema.safeParse(JSON.parse(raw));
|
|
27843
27843
|
return parsed.success ? parsed.data : void 0;
|
|
27844
27844
|
}
|
|
27845
|
-
function readHeadroomState(
|
|
27845
|
+
function readHeadroomState(fs30, stateFile) {
|
|
27846
27846
|
try {
|
|
27847
|
-
return parseJson(
|
|
27847
|
+
return parseJson(fs30.readFileUtf8(stateFile), HeadroomStateSchema);
|
|
27848
27848
|
} catch {
|
|
27849
27849
|
return void 0;
|
|
27850
27850
|
}
|
|
27851
27851
|
}
|
|
27852
|
-
function writeHeadroomState(
|
|
27853
|
-
|
|
27854
|
-
|
|
27852
|
+
function writeHeadroomState(fs30, stateFile, state) {
|
|
27853
|
+
fs30.mkdirp(import_node_path6.default.dirname(stateFile));
|
|
27854
|
+
fs30.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
27855
27855
|
`);
|
|
27856
27856
|
}
|
|
27857
|
-
function resolveServingHeadroomState(
|
|
27858
|
-
const current = readHeadroomState(
|
|
27857
|
+
function resolveServingHeadroomState(fs30, files, isRunning) {
|
|
27858
|
+
const current = readHeadroomState(fs30, files.stateFile);
|
|
27859
27859
|
if (current !== void 0) {
|
|
27860
27860
|
return { path: files.stateFile, state: current };
|
|
27861
27861
|
}
|
|
27862
|
-
const legacy = readHeadroomState(
|
|
27862
|
+
const legacy = readHeadroomState(fs30, files.legacyStateFile);
|
|
27863
27863
|
if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
|
|
27864
27864
|
return { path: files.legacyStateFile, state: legacy };
|
|
27865
27865
|
}
|
|
27866
27866
|
return void 0;
|
|
27867
27867
|
}
|
|
27868
|
-
function migrateHeadroomState(
|
|
27869
|
-
const legacy = readHeadroomState(
|
|
27868
|
+
function migrateHeadroomState(fs30, files, isRunning) {
|
|
27869
|
+
const legacy = readHeadroomState(fs30, files.legacyStateFile);
|
|
27870
27870
|
const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
|
|
27871
|
-
const current = readHeadroomState(
|
|
27871
|
+
const current = readHeadroomState(fs30, files.stateFile);
|
|
27872
27872
|
if (current !== void 0 || legacyLive) {
|
|
27873
|
-
if (!legacyLive &&
|
|
27874
|
-
|
|
27873
|
+
if (!legacyLive && fs30.readFileUtf8(files.legacyStateFile) !== void 0) {
|
|
27874
|
+
fs30.removeRecursive(files.legacyStateFile);
|
|
27875
27875
|
}
|
|
27876
27876
|
return;
|
|
27877
27877
|
}
|
|
27878
27878
|
if (legacy !== void 0) {
|
|
27879
|
-
writeHeadroomState(
|
|
27879
|
+
writeHeadroomState(fs30, files.stateFile, legacy);
|
|
27880
27880
|
}
|
|
27881
|
-
|
|
27881
|
+
fs30.removeRecursive(files.legacyStateFile);
|
|
27882
27882
|
}
|
|
27883
27883
|
function hashAllowlist(allowlist) {
|
|
27884
27884
|
return (0, import_node_crypto2.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
@@ -27911,27 +27911,27 @@ function isAdmissibleUrl(entry) {
|
|
|
27911
27911
|
function parseAllowlistFile(content) {
|
|
27912
27912
|
return content.replace(/^\uFEFF/, "").replace(ALLOWLIST_FILE_COMMENT, "").split(ALLOWLIST_FILE_SEPARATORS).map((entry) => entry.replace(ALLOWLIST_SURROUNDING_WHITESPACE, "")).filter((entry) => entry !== "" && !ALLOWLIST_ENTRY_WHITESPACE.test(entry) && (entry.includes("://") ? isAdmissibleUrl(entry) : isBareHost(entry)));
|
|
27913
27913
|
}
|
|
27914
|
-
function writeAllowlistFile(
|
|
27915
|
-
|
|
27916
|
-
|
|
27914
|
+
function writeAllowlistFile(fs30, allowlistFile, allowlist) {
|
|
27915
|
+
fs30.mkdirPrivate(import_node_path6.default.dirname(allowlistFile));
|
|
27916
|
+
fs30.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
|
|
27917
27917
|
}
|
|
27918
|
-
function pruneStaleAllowlistTemporaries(
|
|
27918
|
+
function pruneStaleAllowlistTemporaries(fs30, allowlistFile, isRunning) {
|
|
27919
27919
|
const prefix = `${import_node_path6.default.basename(allowlistFile)}.`;
|
|
27920
|
-
for (const name of
|
|
27920
|
+
for (const name of fs30.readdir(import_node_path6.default.dirname(allowlistFile))) {
|
|
27921
27921
|
const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
|
|
27922
27922
|
if (writer !== void 0 && !isRunning(Number(writer))) {
|
|
27923
|
-
|
|
27923
|
+
fs30.removeRecursive(import_node_path6.default.join(import_node_path6.default.dirname(allowlistFile), name));
|
|
27924
27924
|
}
|
|
27925
27925
|
}
|
|
27926
27926
|
}
|
|
27927
|
-
function readAllProviders(
|
|
27927
|
+
function readAllProviders(fs30, providersDir) {
|
|
27928
27928
|
const result = [];
|
|
27929
|
-
for (const name of
|
|
27929
|
+
for (const name of fs30.readdir(providersDir)) {
|
|
27930
27930
|
if (!name.endsWith(".json")) {
|
|
27931
27931
|
continue;
|
|
27932
27932
|
}
|
|
27933
27933
|
try {
|
|
27934
|
-
const parsed = parseJson(
|
|
27934
|
+
const parsed = parseJson(fs30.readFileUtf8(import_node_path6.default.join(providersDir, name)), ProviderSchema);
|
|
27935
27935
|
if (parsed !== void 0) {
|
|
27936
27936
|
result.push({ name: name.slice(0, -".json".length), provider: parsed });
|
|
27937
27937
|
}
|
|
@@ -27941,22 +27941,22 @@ function readAllProviders(fs29, providersDir) {
|
|
|
27941
27941
|
}
|
|
27942
27942
|
return result;
|
|
27943
27943
|
}
|
|
27944
|
-
function writeSession(
|
|
27945
|
-
|
|
27946
|
-
|
|
27944
|
+
function writeSession(fs30, sessionsDir, session) {
|
|
27945
|
+
fs30.mkdirp(sessionsDir);
|
|
27946
|
+
fs30.writeFileUtf8(import_node_path6.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
27947
27947
|
`);
|
|
27948
27948
|
}
|
|
27949
|
-
function removeSession(
|
|
27950
|
-
|
|
27949
|
+
function removeSession(fs30, sessionsDir, pid) {
|
|
27950
|
+
fs30.removeRecursive(import_node_path6.default.join(sessionsDir, `${String(pid)}.json`));
|
|
27951
27951
|
}
|
|
27952
|
-
function listSessions(
|
|
27952
|
+
function listSessions(fs30, sessionsDir) {
|
|
27953
27953
|
const sessions = [];
|
|
27954
|
-
for (const name of
|
|
27954
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27955
27955
|
if (!name.endsWith(".json")) {
|
|
27956
27956
|
continue;
|
|
27957
27957
|
}
|
|
27958
27958
|
try {
|
|
27959
|
-
const parsed = parseJson(
|
|
27959
|
+
const parsed = parseJson(fs30.readFileUtf8(import_node_path6.default.join(sessionsDir, name)), HeadroomSessionSchema);
|
|
27960
27960
|
if (parsed !== void 0) {
|
|
27961
27961
|
sessions.push(parsed);
|
|
27962
27962
|
}
|
|
@@ -27966,22 +27966,22 @@ function listSessions(fs29, sessionsDir) {
|
|
|
27966
27966
|
}
|
|
27967
27967
|
return sessions.sort((a10, b) => a10.pid - b.pid);
|
|
27968
27968
|
}
|
|
27969
|
-
function sessionsForSupervisor(
|
|
27970
|
-
return listSessions(
|
|
27969
|
+
function sessionsForSupervisor(fs30, sessionsDir, supervisorPid) {
|
|
27970
|
+
return listSessions(fs30, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
|
|
27971
27971
|
}
|
|
27972
|
-
function pruneDeadSessions(
|
|
27972
|
+
function pruneDeadSessions(fs30, sessionsDir, isRunning) {
|
|
27973
27973
|
const removed = [];
|
|
27974
|
-
for (const session of listSessions(
|
|
27974
|
+
for (const session of listSessions(fs30, sessionsDir)) {
|
|
27975
27975
|
if (!isRunning(session.pid)) {
|
|
27976
|
-
removeSession(
|
|
27976
|
+
removeSession(fs30, sessionsDir, session.pid);
|
|
27977
27977
|
removed.push(session.pid);
|
|
27978
27978
|
}
|
|
27979
27979
|
}
|
|
27980
27980
|
return removed;
|
|
27981
27981
|
}
|
|
27982
|
-
function readStartLock(
|
|
27982
|
+
function readStartLock(fs30, lockFile) {
|
|
27983
27983
|
try {
|
|
27984
|
-
return parseJson(
|
|
27984
|
+
return parseJson(fs30.readFileUtf8(lockFile), HeadroomLockSchema);
|
|
27985
27985
|
} catch {
|
|
27986
27986
|
return void 0;
|
|
27987
27987
|
}
|
|
@@ -28074,12 +28074,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
|
|
|
28074
28074
|
}
|
|
28075
28075
|
return hashAllowlist([...entries].sort());
|
|
28076
28076
|
}
|
|
28077
|
-
function earlierReleaseDaemon(
|
|
28077
|
+
function earlierReleaseDaemon(fs30, paths, daemon) {
|
|
28078
28078
|
if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
|
|
28079
28079
|
return void 0;
|
|
28080
28080
|
}
|
|
28081
|
-
const providers = readAllProviders(
|
|
28082
|
-
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(
|
|
28081
|
+
const providers = readAllProviders(fs30, paths.providersDir).map((entry) => entry.provider);
|
|
28082
|
+
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs30, paths.frontdoorStateFile)));
|
|
28083
28083
|
return { admitsServingDoor: daemon.recordedHash === expected };
|
|
28084
28084
|
}
|
|
28085
28085
|
var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
|
|
@@ -28104,8 +28104,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
|
|
|
28104
28104
|
}
|
|
28105
28105
|
return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
|
|
28106
28106
|
}
|
|
28107
|
-
function daemonAdmits(
|
|
28108
|
-
const content =
|
|
28107
|
+
function daemonAdmits(fs30, allowlistFile, recordedHash, required2) {
|
|
28108
|
+
const content = fs30.readFileUtf8(allowlistFile);
|
|
28109
28109
|
if (content === void 0 || recordedHash === void 0) {
|
|
28110
28110
|
return false;
|
|
28111
28111
|
}
|
|
@@ -28245,8 +28245,8 @@ function redactHeaders(headers) {
|
|
|
28245
28245
|
}
|
|
28246
28246
|
return result;
|
|
28247
28247
|
}
|
|
28248
|
-
function redactText(
|
|
28249
|
-
return SECRET_BODY_PATTERNS.reduce((accumulated, { pattern, replacement }) => accumulated.replace(pattern, replacement),
|
|
28248
|
+
function redactText(text3) {
|
|
28249
|
+
return SECRET_BODY_PATTERNS.reduce((accumulated, { pattern, replacement }) => accumulated.replace(pattern, replacement), text3);
|
|
28250
28250
|
}
|
|
28251
28251
|
function redactJsonValue(value2) {
|
|
28252
28252
|
if (typeof value2 === "string") {
|
|
@@ -28261,12 +28261,12 @@ function redactJsonValue(value2) {
|
|
|
28261
28261
|
return value2;
|
|
28262
28262
|
}
|
|
28263
28263
|
function redactBody(chunk2) {
|
|
28264
|
-
const
|
|
28264
|
+
const text3 = chunk2.toString("utf8");
|
|
28265
28265
|
try {
|
|
28266
|
-
const parsed = JSON.parse(
|
|
28266
|
+
const parsed = JSON.parse(text3);
|
|
28267
28267
|
return JSON.stringify(redactJsonValue(parsed));
|
|
28268
28268
|
} catch {
|
|
28269
|
-
return redactText(
|
|
28269
|
+
return redactText(text3);
|
|
28270
28270
|
}
|
|
28271
28271
|
}
|
|
28272
28272
|
function captureFromEnv(env, logsDir) {
|
|
@@ -28301,8 +28301,8 @@ function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
|
28301
28301
|
}
|
|
28302
28302
|
const excerpt2 = chunk2.subarray(0, Math.min(CHUNK_LOG_CAP_BYTES, budget));
|
|
28303
28303
|
stored[direction] += excerpt2.length;
|
|
28304
|
-
const
|
|
28305
|
-
const faithful = Buffer.from(
|
|
28304
|
+
const text3 = excerpt2.toString("utf8");
|
|
28305
|
+
const faithful = Buffer.from(text3, "utf8").equals(excerpt2);
|
|
28306
28306
|
append({
|
|
28307
28307
|
kind: "stream-chunk",
|
|
28308
28308
|
id: id2,
|
|
@@ -28311,7 +28311,7 @@ function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
|
28311
28311
|
bytes: chunk2.length,
|
|
28312
28312
|
stored: excerpt2.length,
|
|
28313
28313
|
truncated: excerpt2.length < chunk2.length,
|
|
28314
|
-
...faithful ? { body: redactText(
|
|
28314
|
+
...faithful ? { body: redactText(text3) } : { b64: excerpt2.toString("base64") }
|
|
28315
28315
|
});
|
|
28316
28316
|
},
|
|
28317
28317
|
onEnd: () => {
|
|
@@ -28495,7 +28495,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
|
|
|
28495
28495
|
const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
|
|
28496
28496
|
return { message: refusal2, repairable: replaceable };
|
|
28497
28497
|
}
|
|
28498
|
-
function prepareHeadroomSocket(
|
|
28498
|
+
function prepareHeadroomSocket(fs30, ports, paths, supervisorPid) {
|
|
28499
28499
|
const unsupported = platformRefusal(ports.platform);
|
|
28500
28500
|
if (unsupported !== void 0) {
|
|
28501
28501
|
return { refused: unsupported };
|
|
@@ -28510,18 +28510,18 @@ function prepareHeadroomSocket(fs29, ports, paths, supervisorPid) {
|
|
|
28510
28510
|
if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
|
|
28511
28511
|
return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
|
|
28512
28512
|
}
|
|
28513
|
-
|
|
28513
|
+
fs30.mkdirPrivate(paths.headroomSocketDir);
|
|
28514
28514
|
const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
|
|
28515
28515
|
return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
|
|
28516
28516
|
}
|
|
28517
|
-
function pruneStaleHeadroomSockets(
|
|
28517
|
+
function pruneStaleHeadroomSockets(fs30, paths, isRunning) {
|
|
28518
28518
|
const removed = [];
|
|
28519
|
-
for (const name of
|
|
28519
|
+
for (const name of fs30.readdir(paths.headroomSocketDir)) {
|
|
28520
28520
|
const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
|
|
28521
28521
|
if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
|
|
28522
28522
|
continue;
|
|
28523
28523
|
}
|
|
28524
|
-
|
|
28524
|
+
fs30.removeRecursive(import_node_path7.default.join(paths.headroomSocketDir, name));
|
|
28525
28525
|
removed.push(name);
|
|
28526
28526
|
}
|
|
28527
28527
|
return removed;
|
|
@@ -28668,37 +28668,37 @@ function compareVersions2(a10, b) {
|
|
|
28668
28668
|
return 0;
|
|
28669
28669
|
}
|
|
28670
28670
|
async function runSupervisor(initialConfig, ports, options = {}) {
|
|
28671
|
-
const { fs:
|
|
28671
|
+
const { fs: fs30, paths } = ports;
|
|
28672
28672
|
let config2 = initialConfig;
|
|
28673
|
-
migrateHeadroomState(
|
|
28674
|
-
const previousState = resolveServingHeadroomState(
|
|
28673
|
+
migrateHeadroomState(fs30, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
|
|
28674
|
+
const previousState = resolveServingHeadroomState(fs30, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
|
|
28675
28675
|
if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
|
|
28676
28676
|
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
|
|
28677
28677
|
return 0;
|
|
28678
28678
|
}
|
|
28679
28679
|
let installedSource = previousState?.installedSource;
|
|
28680
28680
|
const ownsState = () => {
|
|
28681
|
-
const owner = readHeadroomState(
|
|
28681
|
+
const owner = readHeadroomState(fs30, paths.headroomStateFile)?.supervisorPid;
|
|
28682
28682
|
return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
|
|
28683
28683
|
};
|
|
28684
28684
|
const writeOwnState = (state) => {
|
|
28685
28685
|
if (!ownsState()) {
|
|
28686
28686
|
return false;
|
|
28687
28687
|
}
|
|
28688
|
-
writeHeadroomState(
|
|
28688
|
+
writeHeadroomState(fs30, paths.headroomStateFile, state);
|
|
28689
28689
|
return true;
|
|
28690
28690
|
};
|
|
28691
28691
|
const fail = (message) => {
|
|
28692
28692
|
if (writeOwnState({ lastError: message })) {
|
|
28693
|
-
|
|
28693
|
+
fs30.removeRecursive(paths.headroomLockFile);
|
|
28694
28694
|
}
|
|
28695
28695
|
ports.log(`agent-shim headroom supervisor: ${message}`);
|
|
28696
28696
|
return 1;
|
|
28697
28697
|
};
|
|
28698
28698
|
const syncAllowlistFile = (allowlist) => {
|
|
28699
28699
|
try {
|
|
28700
|
-
if (
|
|
28701
|
-
writeAllowlistFile(
|
|
28700
|
+
if (fs30.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
|
|
28701
|
+
writeAllowlistFile(fs30, paths.headroomAllowlistFile, allowlist);
|
|
28702
28702
|
ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
|
|
28703
28703
|
}
|
|
28704
28704
|
return void 0;
|
|
@@ -28716,9 +28716,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28716
28716
|
}
|
|
28717
28717
|
ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
|
|
28718
28718
|
try {
|
|
28719
|
-
|
|
28720
|
-
|
|
28721
|
-
writeAllowlistFile(
|
|
28719
|
+
fs30.mkdirPrivate(paths.headroomDir);
|
|
28720
|
+
fs30.mkdirPrivate(import_node_path8.default.dirname(paths.headroomAllowlistFile));
|
|
28721
|
+
writeAllowlistFile(fs30, paths.headroomAllowlistFile, allowlist);
|
|
28722
28722
|
} catch (error63) {
|
|
28723
28723
|
return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error63 instanceof Error ? error63.message : String(error63)}`;
|
|
28724
28724
|
}
|
|
@@ -28743,20 +28743,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28743
28743
|
installedSource = config2.source;
|
|
28744
28744
|
return void 0;
|
|
28745
28745
|
};
|
|
28746
|
-
const socket = prepareHeadroomSocket(
|
|
28746
|
+
const socket = prepareHeadroomSocket(fs30, ports.socketTrust, paths, ports.ownPid);
|
|
28747
28747
|
if (socket.refused !== void 0) {
|
|
28748
28748
|
return fail(socket.refused);
|
|
28749
28749
|
}
|
|
28750
28750
|
const { socketPath } = socket;
|
|
28751
|
-
pruneStaleHeadroomSockets(
|
|
28752
|
-
pruneStaleAllowlistTemporaries(
|
|
28751
|
+
pruneStaleHeadroomSockets(fs30, paths, ports.isRunning);
|
|
28752
|
+
pruneStaleAllowlistTemporaries(fs30, paths.headroomAllowlistFile, ports.isRunning);
|
|
28753
28753
|
const installFailure = ensureInstalled();
|
|
28754
28754
|
if (installFailure !== void 0) {
|
|
28755
28755
|
return fail(installFailure);
|
|
28756
28756
|
}
|
|
28757
28757
|
const version2 = ports.headroomVersion() ?? "unknown";
|
|
28758
28758
|
writeOwnState({ supervisorPid: ports.ownPid, version: version2, installedSource });
|
|
28759
|
-
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(
|
|
28759
|
+
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs30, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
|
|
28760
28760
|
const orphanPid = previousState?.headroomPid;
|
|
28761
28761
|
const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
|
|
28762
28762
|
const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
|
|
@@ -28791,12 +28791,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28791
28791
|
ticks += 1;
|
|
28792
28792
|
config2 = ports.readConfig();
|
|
28793
28793
|
const settingsHash = hashSettings(config2.settings);
|
|
28794
|
-
const inputs = currentHeadroomAllowlistInputs(
|
|
28795
|
-
pruneDeadFrontDoorDirectRecords(
|
|
28796
|
-
pruneMalformedFrontDoorDirectFiles(
|
|
28794
|
+
const inputs = currentHeadroomAllowlistInputs(fs30, paths, ports.frontDoorLiveness);
|
|
28795
|
+
pruneDeadFrontDoorDirectRecords(fs30, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
|
|
28796
|
+
pruneMalformedFrontDoorDirectFiles(fs30, paths.frontdoorDirectRecordsDir, ports.isRunning);
|
|
28797
28797
|
const allowlist = inputs.frontDoorOrigins;
|
|
28798
28798
|
const allowlistHash = hashAllowlist(allowlist);
|
|
28799
|
-
pruneDeadSessions(
|
|
28799
|
+
pruneDeadSessions(fs30, paths.headroomSessionsDir, ports.isRunning);
|
|
28800
28800
|
const ownsNow = ownsState();
|
|
28801
28801
|
if (!ownsNow && !superseded) {
|
|
28802
28802
|
ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
|
|
@@ -28843,7 +28843,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28843
28843
|
runningSettingsHash = settingsHash;
|
|
28844
28844
|
const recorded = writeOwnState(servingState(pid));
|
|
28845
28845
|
if (recorded) {
|
|
28846
|
-
|
|
28846
|
+
fs30.removeRecursive(paths.headroomLockFile);
|
|
28847
28847
|
}
|
|
28848
28848
|
idleSince = void 0;
|
|
28849
28849
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
|
|
@@ -28871,7 +28871,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28871
28871
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
|
|
28872
28872
|
}
|
|
28873
28873
|
if (runningSettingsHash !== settingsHash || installedSource !== config2.source) {
|
|
28874
|
-
if (sessionsForSupervisor(
|
|
28874
|
+
if (sessionsForSupervisor(fs30, paths.headroomSessionsDir, ports.ownPid).length === 0) {
|
|
28875
28875
|
ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
|
|
28876
28876
|
ports.stopProcess(headroomPid);
|
|
28877
28877
|
headroomPid = void 0;
|
|
@@ -28880,7 +28880,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28880
28880
|
continue;
|
|
28881
28881
|
}
|
|
28882
28882
|
}
|
|
28883
|
-
const sessions = sessionsForSupervisor(
|
|
28883
|
+
const sessions = sessionsForSupervisor(fs30, paths.headroomSessionsDir, ports.ownPid);
|
|
28884
28884
|
if (sessions.length === 0) {
|
|
28885
28885
|
idleSince ??= ports.now();
|
|
28886
28886
|
const idleMs = ports.now() - idleSince;
|
|
@@ -28905,9 +28905,9 @@ function undeterminedFrontDoors(inputs) {
|
|
|
28905
28905
|
return reason === void 0 ? [] : [{ pid: record2.pid, origin: directOrigin(record2.directPort), reason }];
|
|
28906
28906
|
});
|
|
28907
28907
|
}
|
|
28908
|
-
function currentHeadroomAllowlistInputs(
|
|
28909
|
-
const named = frontDoorOrigin(readFrontDoorState(
|
|
28910
|
-
const records = listFrontDoorDirectRecords(
|
|
28908
|
+
function currentHeadroomAllowlistInputs(fs30, paths, frontDoorLiveness) {
|
|
28909
|
+
const named = frontDoorOrigin(readFrontDoorState(fs30, paths.frontdoorStateFile));
|
|
28910
|
+
const records = listFrontDoorDirectRecords(fs30, paths.frontdoorDirectRecordsDir);
|
|
28911
28911
|
const liveness = frontDoorLiveness(records.map((record2) => record2.pid));
|
|
28912
28912
|
const live = liveFrontDoorDirectRecords(records, liveness).map((record2) => directOrigin(record2.directPort));
|
|
28913
28913
|
return {
|
|
@@ -28916,8 +28916,8 @@ function currentHeadroomAllowlistInputs(fs29, paths, frontDoorLiveness) {
|
|
|
28916
28916
|
frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
|
|
28917
28917
|
};
|
|
28918
28918
|
}
|
|
28919
|
-
function launchRequiredUpstreams(
|
|
28920
|
-
const door = frontDoorOrigin(readFrontDoorState(
|
|
28919
|
+
function launchRequiredUpstreams(fs30, paths) {
|
|
28920
|
+
const door = frontDoorOrigin(readFrontDoorState(fs30, paths.frontdoorStateFile));
|
|
28921
28921
|
return door === void 0 ? [] : [door];
|
|
28922
28922
|
}
|
|
28923
28923
|
async function waitUntilReady(ports, socketPath, pid) {
|
|
@@ -28995,8 +28995,8 @@ var init_report = __esm({
|
|
|
28995
28995
|
});
|
|
28996
28996
|
|
|
28997
28997
|
// src/logStyle.ts
|
|
28998
|
-
function styledDiagnostic(style, colour,
|
|
28999
|
-
return
|
|
28998
|
+
function styledDiagnostic(style, colour, text3) {
|
|
28999
|
+
return text3.split("\n").map((line, index) => {
|
|
29000
29000
|
const lead = index === 0 ? DIAGNOSTIC_LEAD.exec(line) : null;
|
|
29001
29001
|
if (lead === null) {
|
|
29002
29002
|
return style([colour], line);
|
|
@@ -29024,7 +29024,7 @@ function createLogPort(sinks, styleFor) {
|
|
|
29024
29024
|
};
|
|
29025
29025
|
}
|
|
29026
29026
|
function styleTextFor(stream) {
|
|
29027
|
-
return (formats,
|
|
29027
|
+
return (formats, text3) => (0, import_node_util3.styleText)([...formats], text3, { stream });
|
|
29028
29028
|
}
|
|
29029
29029
|
var import_node_util3, DIAGNOSTIC_LEAD;
|
|
29030
29030
|
var init_logStyle = __esm({
|
|
@@ -31844,8 +31844,8 @@ var init_classify = __esm({
|
|
|
31844
31844
|
function poolNameOf(selector) {
|
|
31845
31845
|
return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
|
|
31846
31846
|
}
|
|
31847
|
-
function readActiveIdentity(
|
|
31848
|
-
const trimmed =
|
|
31847
|
+
function readActiveIdentity(fs30, activeIdentityFile) {
|
|
31848
|
+
const trimmed = fs30.readFileUtf8(activeIdentityFile)?.trim();
|
|
31849
31849
|
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
31850
31850
|
}
|
|
31851
31851
|
function isNonEmpty(value2) {
|
|
@@ -31892,8 +31892,8 @@ function decideConfigProfile(params) {
|
|
|
31892
31892
|
}
|
|
31893
31893
|
return { source: "none" };
|
|
31894
31894
|
}
|
|
31895
|
-
function loadIdentity(identitiesDir, name,
|
|
31896
|
-
return loadConfigFile(import_node_path11.default.join(identitiesDir, name, "identity.json"), IdentitySchema,
|
|
31895
|
+
function loadIdentity(identitiesDir, name, fs30) {
|
|
31896
|
+
return loadConfigFile(import_node_path11.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs30.readConfigFile);
|
|
31897
31897
|
}
|
|
31898
31898
|
var import_node_path11, IDENTITY_DECISION_SOURCES, CONFIG_PROFILE_DECISION_SOURCES;
|
|
31899
31899
|
var init_identity = __esm({
|
|
@@ -31992,21 +31992,21 @@ function keyNamed(path66) {
|
|
|
31992
31992
|
}
|
|
31993
31993
|
return found;
|
|
31994
31994
|
}
|
|
31995
|
-
function parseStatuslineAssignment(
|
|
31996
|
-
const split =
|
|
31995
|
+
function parseStatuslineAssignment(text3) {
|
|
31996
|
+
const split = text3.indexOf("=");
|
|
31997
31997
|
if (split < 1) {
|
|
31998
|
-
throw new UsageError(`"${
|
|
31998
|
+
throw new UsageError(`"${text3}" is not <setting>=<value>.`);
|
|
31999
31999
|
}
|
|
32000
|
-
const path66 =
|
|
32001
|
-
const raw =
|
|
32000
|
+
const path66 = text3.slice(0, split);
|
|
32001
|
+
const raw = text3.slice(split + 1);
|
|
32002
32002
|
const key = keyNamed(path66);
|
|
32003
32003
|
switch (key.kind) {
|
|
32004
32004
|
case "integer": {
|
|
32005
|
-
const
|
|
32006
|
-
if (raw.trim() === "" || !Number.isFinite(
|
|
32005
|
+
const number5 = Number(raw);
|
|
32006
|
+
if (raw.trim() === "" || !Number.isFinite(number5)) {
|
|
32007
32007
|
throw new UsageError(`${path66}: "${raw}" is not a number.`);
|
|
32008
32008
|
}
|
|
32009
|
-
return { path: path66, value:
|
|
32009
|
+
return { path: path66, value: number5 };
|
|
32010
32010
|
}
|
|
32011
32011
|
case "text":
|
|
32012
32012
|
case "choice":
|
|
@@ -33750,8 +33750,8 @@ var init_pipeline = __esm({
|
|
|
33750
33750
|
});
|
|
33751
33751
|
|
|
33752
33752
|
// src/launcher/farm.ts
|
|
33753
|
-
function readFarmManifest(
|
|
33754
|
-
const raw =
|
|
33753
|
+
function readFarmManifest(fs30, farmRoot) {
|
|
33754
|
+
const raw = fs30.readFileUtf8(import_node_path19.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs30.readFileUtf8(import_node_path19.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
|
|
33755
33755
|
if (raw === void 0) {
|
|
33756
33756
|
return void 0;
|
|
33757
33757
|
}
|
|
@@ -33809,9 +33809,9 @@ function buildEntryFacts(params) {
|
|
|
33809
33809
|
entries
|
|
33810
33810
|
};
|
|
33811
33811
|
}
|
|
33812
|
-
function listSubtree(
|
|
33812
|
+
function listSubtree(fs30, root, rel) {
|
|
33813
33813
|
const absolute = import_node_path19.default.join(root, rel);
|
|
33814
|
-
const stat =
|
|
33814
|
+
const stat = fs30.lstat(absolute);
|
|
33815
33815
|
if (stat === void 0) {
|
|
33816
33816
|
return [];
|
|
33817
33817
|
}
|
|
@@ -33819,10 +33819,10 @@ function listSubtree(fs29, root, rel) {
|
|
|
33819
33819
|
return [{ rel, kind: "symlink" }];
|
|
33820
33820
|
}
|
|
33821
33821
|
if (stat.kind === "dir") {
|
|
33822
|
-
const children = [...
|
|
33822
|
+
const children = [...fs30.readdir(absolute)].sort().flatMap((name) => listSubtree(fs30, root, `${rel}/${name}`));
|
|
33823
33823
|
return [{ rel, kind: "dir" }, ...children];
|
|
33824
33824
|
}
|
|
33825
|
-
const contentHash =
|
|
33825
|
+
const contentHash = fs30.hashFile(absolute);
|
|
33826
33826
|
return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
|
|
33827
33827
|
}
|
|
33828
33828
|
function topLevelScopeRoots(roots) {
|
|
@@ -33836,25 +33836,25 @@ function topLevelScopeRoots(roots) {
|
|
|
33836
33836
|
}
|
|
33837
33837
|
return kept;
|
|
33838
33838
|
}
|
|
33839
|
-
function reconciliationScope(
|
|
33839
|
+
function reconciliationScope(fs30, farmRoot, manifest) {
|
|
33840
33840
|
if (manifest !== void 0) {
|
|
33841
33841
|
return topLevelScopeRoots(manifest.materialised);
|
|
33842
33842
|
}
|
|
33843
|
-
return [...
|
|
33843
|
+
return [...fs30.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs30.lstat(import_node_path19.default.join(farmRoot, name))?.kind === "dir").sort();
|
|
33844
33844
|
}
|
|
33845
|
-
function collectFarmListing(
|
|
33846
|
-
return scopeRoots.flatMap((root) => listSubtree(
|
|
33845
|
+
function collectFarmListing(fs30, farmRoot, scopeRoots) {
|
|
33846
|
+
return scopeRoots.flatMap((root) => listSubtree(fs30, farmRoot, root));
|
|
33847
33847
|
}
|
|
33848
|
-
function collectCanonicalCounterparts(
|
|
33848
|
+
function collectCanonicalCounterparts(fs30, claudeHome, farmListing) {
|
|
33849
33849
|
const out = [];
|
|
33850
33850
|
for (const entry of farmListing) {
|
|
33851
33851
|
const absolute = import_node_path19.default.join(claudeHome, entry.rel);
|
|
33852
|
-
const stat =
|
|
33852
|
+
const stat = fs30.lstat(absolute);
|
|
33853
33853
|
if (stat === void 0) {
|
|
33854
33854
|
continue;
|
|
33855
33855
|
}
|
|
33856
33856
|
if (stat.kind === "file") {
|
|
33857
|
-
const contentHash =
|
|
33857
|
+
const contentHash = fs30.hashFile(absolute);
|
|
33858
33858
|
out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
|
|
33859
33859
|
continue;
|
|
33860
33860
|
}
|
|
@@ -35117,7 +35117,7 @@ function keyUsageExtension(bits) {
|
|
|
35117
35117
|
}
|
|
35118
35118
|
function ipv6Groups(address) {
|
|
35119
35119
|
const [head = "", tail] = address.split("::");
|
|
35120
|
-
const split = (
|
|
35120
|
+
const split = (text3) => text3 === "" ? [] : text3.split(":");
|
|
35121
35121
|
const expand = (groups) => groups.flatMap((group) => {
|
|
35122
35122
|
if (!import_node_net.default.isIPv4(group)) {
|
|
35123
35123
|
return [Number.parseInt(group, HEX_RADIX)];
|
|
@@ -35527,9 +35527,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
35527
35527
|
}
|
|
35528
35528
|
}
|
|
35529
35529
|
async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
35530
|
-
const { fs:
|
|
35530
|
+
const { fs: fs30, paths } = ports;
|
|
35531
35531
|
const servingBinary = ports.statOwnExecutable();
|
|
35532
|
-
const previous = readFrontDoorState(
|
|
35532
|
+
const previous = readFrontDoorState(fs30, paths.frontdoorStateFile);
|
|
35533
35533
|
let lastPort = previous?.lastPort;
|
|
35534
35534
|
let lastConnectPort = previous?.lastConnectPort;
|
|
35535
35535
|
let lastDirectPort = previous?.lastDirectPort;
|
|
@@ -35540,12 +35540,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35540
35540
|
});
|
|
35541
35541
|
const fail = (message) => {
|
|
35542
35542
|
ports.closeRcStreamHub();
|
|
35543
|
-
writeFrontDoorState(
|
|
35544
|
-
|
|
35543
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, { lastError: message, ...sticky() });
|
|
35544
|
+
fs30.removeRecursive(paths.frontdoorLockFile);
|
|
35545
35545
|
ports.log(`agent-shim frontdoor supervisor: ${message}`);
|
|
35546
35546
|
return 1;
|
|
35547
35547
|
};
|
|
35548
|
-
writeFrontDoorState(
|
|
35548
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
|
|
35549
35549
|
const previousSticky = lastPort;
|
|
35550
35550
|
let http9;
|
|
35551
35551
|
try {
|
|
@@ -35585,16 +35585,16 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35585
35585
|
ports.log(`agent-shim frontdoor supervisor: sticky direct port ${String(previousStickyDirect)} was occupied; moving to ${String(direct.port)} (headroom admits the new address once its supervisor rewrites the allowlist file)`);
|
|
35586
35586
|
}
|
|
35587
35587
|
lastDirectPort = direct.port;
|
|
35588
|
-
writeFrontDoorDirectRecord(
|
|
35589
|
-
writeFrontDoorState(
|
|
35588
|
+
writeFrontDoorDirectRecord(fs30, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
|
|
35589
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http9.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
|
|
35590
35590
|
ports.doorHealth.generation({ providerPort: http9.port, connectPort: connect3.port, directPort: direct.port });
|
|
35591
|
-
|
|
35591
|
+
fs30.removeRecursive(paths.frontdoorLockFile);
|
|
35592
35592
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http9.port)}, CONNECT surface on 127.0.0.1:${String(connect3.port)}`);
|
|
35593
35593
|
const watchdog = ports.startWatchdog?.();
|
|
35594
35594
|
let idleSince;
|
|
35595
35595
|
let ticks = 0;
|
|
35596
35596
|
const supersedingOwner = () => {
|
|
35597
|
-
const owner = readFrontDoorState(
|
|
35597
|
+
const owner = readFrontDoorState(fs30, paths.frontdoorStateFile)?.supervisorPid;
|
|
35598
35598
|
return owner !== void 0 && owner !== ports.ownPid && ports.isRunning(owner) ? owner : void 0;
|
|
35599
35599
|
};
|
|
35600
35600
|
let supersededBy;
|
|
@@ -35621,13 +35621,13 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35621
35621
|
ports.stopBackgroundWork?.();
|
|
35622
35622
|
const drained = [direct.drain(), connect3.drain(), http9.drain()];
|
|
35623
35623
|
if (supersedingOwner() === void 0) {
|
|
35624
|
-
writeFrontDoorState(
|
|
35624
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, sticky());
|
|
35625
35625
|
}
|
|
35626
|
-
markFrontDoorDraining(
|
|
35626
|
+
markFrontDoorDraining(fs30, paths.frontdoorDrainingDir, ports.ownPid);
|
|
35627
35627
|
ports.closeRcStreamHub();
|
|
35628
35628
|
await Promise.all(drained);
|
|
35629
|
-
unmarkFrontDoorDraining(
|
|
35630
|
-
removeFrontDoorDirectRecord(
|
|
35629
|
+
unmarkFrontDoorDraining(fs30, paths.frontdoorDrainingDir, ports.ownPid);
|
|
35630
|
+
removeFrontDoorDirectRecord(fs30, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
35631
35631
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: the connections this door carried have ended; exiting`);
|
|
35632
35632
|
return 0;
|
|
35633
35633
|
};
|
|
@@ -35637,12 +35637,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35637
35637
|
await connect3.close();
|
|
35638
35638
|
await http9.close();
|
|
35639
35639
|
ports.closeRcStreamHub();
|
|
35640
|
-
removeFrontDoorDirectRecord(
|
|
35640
|
+
removeFrontDoorDirectRecord(fs30, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
35641
35641
|
};
|
|
35642
35642
|
const shutdown = async () => {
|
|
35643
35643
|
await closeServing();
|
|
35644
35644
|
if (supersedingOwner() === void 0) {
|
|
35645
|
-
writeFrontDoorState(
|
|
35645
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, sticky());
|
|
35646
35646
|
}
|
|
35647
35647
|
return 0;
|
|
35648
35648
|
};
|
|
@@ -35656,8 +35656,8 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35656
35656
|
return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
|
|
35657
35657
|
}
|
|
35658
35658
|
ticks += 1;
|
|
35659
|
-
const listed = listFrontDoorSessions(
|
|
35660
|
-
const pruned = pruneDeadFrontDoorSessions(
|
|
35659
|
+
const listed = listFrontDoorSessions(fs30, paths.frontdoorSessionsDir);
|
|
35660
|
+
const pruned = pruneDeadFrontDoorSessions(fs30, paths.frontdoorSessionsDir, ports.isRunning);
|
|
35661
35661
|
ports.observeLaunchRegistry(listed, pruned);
|
|
35662
35662
|
ports.checkQuotaExpiry();
|
|
35663
35663
|
const prunedPids = new Set(pruned);
|
|
@@ -36207,7 +36207,7 @@ var init_package = __esm({
|
|
|
36207
36207
|
"package.json"() {
|
|
36208
36208
|
package_default = {
|
|
36209
36209
|
name: "claude-use",
|
|
36210
|
-
version: "11.52.
|
|
36210
|
+
version: "11.52.1",
|
|
36211
36211
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
36212
36212
|
license: "MIT",
|
|
36213
36213
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -36320,14 +36320,14 @@ function isIdentityName(name) {
|
|
|
36320
36320
|
function claudeJsonPath(identitiesDir, identity) {
|
|
36321
36321
|
return import_node_path25.default.join(identitiesDir, identity, CLAUDE_JSON);
|
|
36322
36322
|
}
|
|
36323
|
-
function readAccountMetadata(
|
|
36323
|
+
function readAccountMetadata(fs30, identitiesDir, identity) {
|
|
36324
36324
|
if (!isIdentityName(identity)) {
|
|
36325
36325
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
36326
36326
|
}
|
|
36327
|
-
return readAccountMetadataFile(
|
|
36327
|
+
return readAccountMetadataFile(fs30, claudeJsonPath(identitiesDir, identity));
|
|
36328
36328
|
}
|
|
36329
|
-
function readAccountMetadataFile(
|
|
36330
|
-
const raw =
|
|
36329
|
+
function readAccountMetadataFile(fs30, file2) {
|
|
36330
|
+
const raw = fs30.readFileUtf8(file2);
|
|
36331
36331
|
if (raw === void 0) {
|
|
36332
36332
|
return void 0;
|
|
36333
36333
|
}
|
|
@@ -36357,19 +36357,19 @@ function readAccountMetadataFile(fs29, file2) {
|
|
|
36357
36357
|
}
|
|
36358
36358
|
return account.data;
|
|
36359
36359
|
}
|
|
36360
|
-
function createAccountReader(
|
|
36360
|
+
function createAccountReader(fs30, identitiesDir) {
|
|
36361
36361
|
const cache = /* @__PURE__ */ new Map();
|
|
36362
36362
|
return (identity) => {
|
|
36363
36363
|
if (!isIdentityName(identity)) {
|
|
36364
36364
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
36365
36365
|
}
|
|
36366
|
-
const stat =
|
|
36366
|
+
const stat = fs30.lstat(claudeJsonPath(identitiesDir, identity));
|
|
36367
36367
|
const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
|
|
36368
36368
|
const cached2 = cache.get(identity);
|
|
36369
36369
|
if (cached2?.stamp === stamp) {
|
|
36370
36370
|
return cached2.account;
|
|
36371
36371
|
}
|
|
36372
|
-
const account = readAccountMetadata(
|
|
36372
|
+
const account = readAccountMetadata(fs30, identitiesDir, identity);
|
|
36373
36373
|
cache.set(identity, { stamp, account });
|
|
36374
36374
|
return account;
|
|
36375
36375
|
};
|
|
@@ -36471,9 +36471,9 @@ function errorInfo(raw) {
|
|
|
36471
36471
|
function isObject3(value2) {
|
|
36472
36472
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
36473
36473
|
}
|
|
36474
|
-
function parseJson2(
|
|
36474
|
+
function parseJson2(text3) {
|
|
36475
36475
|
try {
|
|
36476
|
-
const parsed = JSON.parse(
|
|
36476
|
+
const parsed = JSON.parse(text3);
|
|
36477
36477
|
return parsed;
|
|
36478
36478
|
} catch {
|
|
36479
36479
|
return void 0;
|
|
@@ -36521,26 +36521,26 @@ function createSseScanner() {
|
|
|
36521
36521
|
return void 0;
|
|
36522
36522
|
};
|
|
36523
36523
|
const completeLine = (complete) => {
|
|
36524
|
-
const
|
|
36525
|
-
if (
|
|
36524
|
+
const text3 = complete.endsWith("\r") ? complete.slice(0, -1) : complete;
|
|
36525
|
+
if (text3 === "") {
|
|
36526
36526
|
dispatch();
|
|
36527
36527
|
return;
|
|
36528
36528
|
}
|
|
36529
|
-
if (
|
|
36530
|
-
eventName =
|
|
36529
|
+
if (text3.startsWith("event:")) {
|
|
36530
|
+
eventName = text3.slice("event:".length).trim();
|
|
36531
36531
|
return;
|
|
36532
36532
|
}
|
|
36533
|
-
if (
|
|
36534
|
-
const value2 =
|
|
36533
|
+
if (text3.startsWith("data:")) {
|
|
36534
|
+
const value2 = text3.slice("data:".length);
|
|
36535
36535
|
data.push(value2.startsWith(" ") ? value2.slice(1) : value2);
|
|
36536
36536
|
}
|
|
36537
36537
|
};
|
|
36538
36538
|
return {
|
|
36539
|
-
push: (
|
|
36539
|
+
push: (text3) => {
|
|
36540
36540
|
let start = 0;
|
|
36541
36541
|
for (; ; ) {
|
|
36542
|
-
const newline =
|
|
36543
|
-
const piece = newline === -1 ?
|
|
36542
|
+
const newline = text3.indexOf("\n", start);
|
|
36543
|
+
const piece = newline === -1 ? text3.slice(start) : text3.slice(start, newline);
|
|
36544
36544
|
if (!skipping) {
|
|
36545
36545
|
line += piece;
|
|
36546
36546
|
if (worthKeeping(line) === false) {
|
|
@@ -36654,8 +36654,8 @@ function createJsonScanner() {
|
|
|
36654
36654
|
}
|
|
36655
36655
|
};
|
|
36656
36656
|
return {
|
|
36657
|
-
push: (
|
|
36658
|
-
for (const char of
|
|
36657
|
+
push: (text3) => {
|
|
36658
|
+
for (const char of text3) {
|
|
36659
36659
|
step2(char);
|
|
36660
36660
|
}
|
|
36661
36661
|
},
|
|
@@ -36782,13 +36782,13 @@ function createUsageMiddleware(deps) {
|
|
|
36782
36782
|
const scanner = scannerFor(event.headers);
|
|
36783
36783
|
const decoder = scanner === void 0 ? null : decoderFor(headerValue(event.headers, "content-encoding"));
|
|
36784
36784
|
let scanning = scanner !== void 0 && decoder !== void 0;
|
|
36785
|
-
const
|
|
36785
|
+
const text3 = new TextDecoder();
|
|
36786
36786
|
const feed = (bytes, final) => {
|
|
36787
36787
|
if (!scanning || scanner === void 0) {
|
|
36788
36788
|
return;
|
|
36789
36789
|
}
|
|
36790
36790
|
try {
|
|
36791
|
-
scanner.push(
|
|
36791
|
+
scanner.push(text3.decode(bytes, { stream: !final }));
|
|
36792
36792
|
} catch (error63) {
|
|
36793
36793
|
scanning = false;
|
|
36794
36794
|
deps.log(`usage: body scan failed for ${event.route}: ${error63 instanceof Error ? error63.message : String(error63)}`);
|
|
@@ -37199,8 +37199,8 @@ function segmentDay(epochMs) {
|
|
|
37199
37199
|
function segmentName(day, pid) {
|
|
37200
37200
|
return `${day}.${String(pid)}.jsonl`;
|
|
37201
37201
|
}
|
|
37202
|
-
function listLogSegments(
|
|
37203
|
-
return
|
|
37202
|
+
function listLogSegments(fs30, logDir) {
|
|
37203
|
+
return fs30.readdir(logDir).flatMap((name) => {
|
|
37204
37204
|
const match = SEGMENT_RE.exec(name);
|
|
37205
37205
|
const day = match?.[1];
|
|
37206
37206
|
if (day === void 0) {
|
|
@@ -37209,15 +37209,15 @@ function listLogSegments(fs29, logDir) {
|
|
|
37209
37209
|
return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
|
|
37210
37210
|
}).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
|
|
37211
37211
|
}
|
|
37212
|
-
function readUsageLog(
|
|
37212
|
+
function readUsageLog(fs30, logDir, options = {}) {
|
|
37213
37213
|
const { sinceMs } = options;
|
|
37214
37214
|
const records = [];
|
|
37215
37215
|
let invalidLines = 0;
|
|
37216
|
-
for (const segment of listLogSegments(
|
|
37216
|
+
for (const segment of listLogSegments(fs30, logDir)) {
|
|
37217
37217
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
37218
37218
|
continue;
|
|
37219
37219
|
}
|
|
37220
|
-
const contents =
|
|
37220
|
+
const contents = fs30.readFileUtf8(import_node_path26.default.join(logDir, segment.name));
|
|
37221
37221
|
if (contents === void 0) {
|
|
37222
37222
|
continue;
|
|
37223
37223
|
}
|
|
@@ -37253,9 +37253,9 @@ function snapshotPath(snapshotsDir, identity) {
|
|
|
37253
37253
|
}
|
|
37254
37254
|
return import_node_path26.default.join(snapshotsDir, `${identity}.json`);
|
|
37255
37255
|
}
|
|
37256
|
-
function readUsageSnapshot(
|
|
37256
|
+
function readUsageSnapshot(fs30, snapshotsDir, identity) {
|
|
37257
37257
|
const file2 = snapshotPath(snapshotsDir, identity);
|
|
37258
|
-
const raw =
|
|
37258
|
+
const raw = fs30.readFileUtf8(file2);
|
|
37259
37259
|
if (raw === void 0) {
|
|
37260
37260
|
return void 0;
|
|
37261
37261
|
}
|
|
@@ -37271,8 +37271,8 @@ function readUsageSnapshot(fs29, snapshotsDir, identity) {
|
|
|
37271
37271
|
}
|
|
37272
37272
|
return snapshot.data;
|
|
37273
37273
|
}
|
|
37274
|
-
function listUsageSnapshots(
|
|
37275
|
-
return
|
|
37274
|
+
function listUsageSnapshots(fs30, snapshotsDir) {
|
|
37275
|
+
return fs30.readdir(snapshotsDir).flatMap((name) => {
|
|
37276
37276
|
if (!name.endsWith(".json")) {
|
|
37277
37277
|
return [];
|
|
37278
37278
|
}
|
|
@@ -37280,7 +37280,7 @@ function listUsageSnapshots(fs29, snapshotsDir) {
|
|
|
37280
37280
|
if (!isIdentityName(identity)) {
|
|
37281
37281
|
return [];
|
|
37282
37282
|
}
|
|
37283
|
-
const snapshot = readUsageSnapshot(
|
|
37283
|
+
const snapshot = readUsageSnapshot(fs30, snapshotsDir, identity);
|
|
37284
37284
|
return snapshot === void 0 ? [] : [snapshot];
|
|
37285
37285
|
}).sort((left, right) => left.identity.localeCompare(right.identity));
|
|
37286
37286
|
}
|
|
@@ -37354,11 +37354,11 @@ var init_read = __esm({
|
|
|
37354
37354
|
});
|
|
37355
37355
|
|
|
37356
37356
|
// src/usage/store.ts
|
|
37357
|
-
function pruneUsageLog(
|
|
37357
|
+
function pruneUsageLog(fs30, logDir, nowMs) {
|
|
37358
37358
|
const cutoff = nowMs - USAGE_RETENTION_MS;
|
|
37359
|
-
for (const segment of listLogSegments(
|
|
37359
|
+
for (const segment of listLogSegments(fs30, logDir)) {
|
|
37360
37360
|
if (segment.endsAt <= cutoff) {
|
|
37361
|
-
|
|
37361
|
+
fs30.removeRecursive(import_node_path27.default.join(logDir, segment.name));
|
|
37362
37362
|
}
|
|
37363
37363
|
}
|
|
37364
37364
|
}
|
|
@@ -37387,7 +37387,7 @@ function foldProviderState(current, record2) {
|
|
|
37387
37387
|
};
|
|
37388
37388
|
}
|
|
37389
37389
|
function createUsageStore(deps) {
|
|
37390
|
-
const { fs:
|
|
37390
|
+
const { fs: fs30, paths } = deps;
|
|
37391
37391
|
let prunedDay;
|
|
37392
37392
|
const rewriteSnapshot = (identity, fold) => {
|
|
37393
37393
|
if (!isIdentityName(identity)) {
|
|
@@ -37396,7 +37396,7 @@ function createUsageStore(deps) {
|
|
|
37396
37396
|
}
|
|
37397
37397
|
let current;
|
|
37398
37398
|
try {
|
|
37399
|
-
current = readUsageSnapshot(
|
|
37399
|
+
current = readUsageSnapshot(fs30, paths.usageSnapshotsDir, identity);
|
|
37400
37400
|
} catch (error63) {
|
|
37401
37401
|
if (!(error63 instanceof UsageSnapshotError)) {
|
|
37402
37402
|
throw error63;
|
|
@@ -37423,8 +37423,8 @@ function createUsageStore(deps) {
|
|
|
37423
37423
|
...account === void 0 ? {} : { account },
|
|
37424
37424
|
providers
|
|
37425
37425
|
});
|
|
37426
|
-
|
|
37427
|
-
|
|
37426
|
+
fs30.mkdirPrivate(paths.usageSnapshotsDir);
|
|
37427
|
+
fs30.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
|
|
37428
37428
|
`);
|
|
37429
37429
|
deps.publish?.(snapshot);
|
|
37430
37430
|
return true;
|
|
@@ -37433,14 +37433,14 @@ function createUsageStore(deps) {
|
|
|
37433
37433
|
record: (input2) => {
|
|
37434
37434
|
const record2 = UsageRecordSchema.parse(input2);
|
|
37435
37435
|
const nowMs = deps.now();
|
|
37436
|
-
|
|
37437
|
-
|
|
37436
|
+
fs30.mkdirPrivate(paths.usageDir);
|
|
37437
|
+
fs30.mkdirPrivate(paths.usageLogDir);
|
|
37438
37438
|
const day = segmentDay(nowMs);
|
|
37439
37439
|
if (prunedDay !== day) {
|
|
37440
|
-
pruneUsageLog(
|
|
37440
|
+
pruneUsageLog(fs30, paths.usageLogDir, nowMs);
|
|
37441
37441
|
prunedDay = day;
|
|
37442
37442
|
}
|
|
37443
|
-
|
|
37443
|
+
fs30.appendFilePrivate(import_node_path27.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
|
|
37444
37444
|
`);
|
|
37445
37445
|
deps.onRecord?.(record2);
|
|
37446
37446
|
if (record2.identity !== void 0) {
|
|
@@ -37483,14 +37483,14 @@ var init_store2 = __esm({
|
|
|
37483
37483
|
function errorMessage(error63) {
|
|
37484
37484
|
return error63 instanceof Error ? error63.message : String(error63);
|
|
37485
37485
|
}
|
|
37486
|
-
function loadPoolMembers(
|
|
37486
|
+
function loadPoolMembers(fs30, paths, identities, nowMs) {
|
|
37487
37487
|
const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
|
|
37488
|
-
const log = readUsageLog(
|
|
37488
|
+
const log = readUsageLog(fs30, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
37489
37489
|
return identities.map((identity) => {
|
|
37490
37490
|
const records = log.records.filter((record2) => record2.identity === identity && record2.provider === ANTHROPIC_PROVIDER && Date.parse(record2.at) >= windowStartMs);
|
|
37491
37491
|
try {
|
|
37492
|
-
const snapshot = readUsageSnapshot(
|
|
37493
|
-
const account = readAccountMetadata(
|
|
37492
|
+
const snapshot = readUsageSnapshot(fs30, paths.usageSnapshotsDir, identity);
|
|
37493
|
+
const account = readAccountMetadata(fs30, paths.identitiesDir, identity) ?? snapshot?.account;
|
|
37494
37494
|
return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
|
|
37495
37495
|
} catch (error63) {
|
|
37496
37496
|
if (error63 instanceof UsageSnapshotError || error63 instanceof AccountMetadataError) {
|
|
@@ -37563,9 +37563,9 @@ function nestedMember(input2, nestedName, childStack, sticky) {
|
|
|
37563
37563
|
missing: nested.missing
|
|
37564
37564
|
};
|
|
37565
37565
|
}
|
|
37566
|
-
function readPicksFile(
|
|
37566
|
+
function readPicksFile(fs30, file2) {
|
|
37567
37567
|
const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
|
|
37568
|
-
const raw =
|
|
37568
|
+
const raw = fs30.readFileUtf8(file2);
|
|
37569
37569
|
if (raw === void 0) {
|
|
37570
37570
|
return { file: empty };
|
|
37571
37571
|
}
|
|
@@ -37578,17 +37578,17 @@ function readPicksFile(fs29, file2) {
|
|
|
37578
37578
|
const result = PicksFileSchema.safeParse(parsed);
|
|
37579
37579
|
return result.success ? { file: result.data } : { file: empty, problem: `${file2} is not a picks file this agent-shim can read` };
|
|
37580
37580
|
}
|
|
37581
|
-
function readStickyPick(
|
|
37582
|
-
const read = readPicksFile(
|
|
37581
|
+
function readStickyPick(fs30, picksFile, directory) {
|
|
37582
|
+
const read = readPicksFile(fs30, picksFile);
|
|
37583
37583
|
const entry = read.file.picks[directory];
|
|
37584
37584
|
return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
|
|
37585
37585
|
}
|
|
37586
|
-
function recordStickyPick(
|
|
37587
|
-
const current = readPicksFile(
|
|
37586
|
+
function recordStickyPick(fs30, picksFile, directory, identity, nowMs) {
|
|
37587
|
+
const current = readPicksFile(fs30, picksFile).file.picks;
|
|
37588
37588
|
const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
|
|
37589
37589
|
const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
|
|
37590
|
-
|
|
37591
|
-
|
|
37590
|
+
fs30.mkdirPrivate(import_node_path28.default.dirname(picksFile));
|
|
37591
|
+
fs30.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
37592
37592
|
`);
|
|
37593
37593
|
}
|
|
37594
37594
|
var import_node_path28, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
@@ -38455,12 +38455,12 @@ function decideSignIn(facts) {
|
|
|
38455
38455
|
function credentialsFilePath(farmRoot) {
|
|
38456
38456
|
return import_node_path31.default.join(farmRoot, CREDENTIALS_FILE);
|
|
38457
38457
|
}
|
|
38458
|
-
function identitySignIn(
|
|
38458
|
+
function identitySignIn(fs30, probe, identity) {
|
|
38459
38459
|
const probing = !identity.hasCredentialBlock;
|
|
38460
38460
|
return decideSignIn({
|
|
38461
38461
|
hasCredentialBlock: identity.hasCredentialBlock,
|
|
38462
38462
|
keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
|
|
38463
|
-
credentialsFile: probing &&
|
|
38463
|
+
credentialsFile: probing && fs30.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
|
|
38464
38464
|
platform: probe.platform
|
|
38465
38465
|
});
|
|
38466
38466
|
}
|
|
@@ -51918,17 +51918,17 @@ var require_mock_call_history = __commonJS({
|
|
|
51918
51918
|
lastCall() {
|
|
51919
51919
|
return this.logs.at(-1);
|
|
51920
51920
|
}
|
|
51921
|
-
nthCall(
|
|
51922
|
-
if (typeof
|
|
51921
|
+
nthCall(number5) {
|
|
51922
|
+
if (typeof number5 !== "number") {
|
|
51923
51923
|
throw new InvalidArgumentError2("nthCall must be called with a number");
|
|
51924
51924
|
}
|
|
51925
|
-
if (!Number.isInteger(
|
|
51925
|
+
if (!Number.isInteger(number5)) {
|
|
51926
51926
|
throw new InvalidArgumentError2("nthCall must be called with an integer");
|
|
51927
51927
|
}
|
|
51928
|
-
if (Math.sign(
|
|
51928
|
+
if (Math.sign(number5) !== 1) {
|
|
51929
51929
|
throw new InvalidArgumentError2("nthCall must be called with a positive value. use firstCall or lastCall instead");
|
|
51930
51930
|
}
|
|
51931
|
-
return this.logs.at(
|
|
51931
|
+
return this.logs.at(number5 - 1);
|
|
51932
51932
|
}
|
|
51933
51933
|
filterCalls(criteria, options) {
|
|
51934
51934
|
if (this.logs.length === 0) {
|
|
@@ -64775,14 +64775,14 @@ var init_selfIdentity = __esm({
|
|
|
64775
64775
|
|
|
64776
64776
|
// src/frontdoor/trust.ts
|
|
64777
64777
|
function resolveTrustBundle(params) {
|
|
64778
|
-
const { caCertFile, bundlesDir, variable, inherited, fs:
|
|
64778
|
+
const { caCertFile, bundlesDir, variable, inherited, fs: fs30 } = params;
|
|
64779
64779
|
if (inherited === void 0 || inherited === "" || import_node_path38.default.resolve(inherited) === import_node_path38.default.resolve(caCertFile)) {
|
|
64780
64780
|
return { path: caCertFile };
|
|
64781
64781
|
}
|
|
64782
|
-
const caPem =
|
|
64782
|
+
const caPem = fs30.readFileUtf8(caCertFile);
|
|
64783
64783
|
let inheritedPem;
|
|
64784
64784
|
try {
|
|
64785
|
-
inheritedPem =
|
|
64785
|
+
inheritedPem = fs30.readFileUtf8(inherited);
|
|
64786
64786
|
} catch (error63) {
|
|
64787
64787
|
return {
|
|
64788
64788
|
path: caCertFile,
|
|
@@ -64795,9 +64795,9 @@ function resolveTrustBundle(params) {
|
|
|
64795
64795
|
const combined = `${inheritedPem.trimEnd()}
|
|
64796
64796
|
${caPem}`;
|
|
64797
64797
|
const bundle = import_node_path38.default.join(bundlesDir, `${(0, import_node_crypto15.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
64798
|
-
if (!
|
|
64799
|
-
|
|
64800
|
-
|
|
64798
|
+
if (!fs30.exists(bundle)) {
|
|
64799
|
+
fs30.mkdirp(bundlesDir);
|
|
64800
|
+
fs30.writeFileAtomic(bundle, combined);
|
|
64801
64801
|
}
|
|
64802
64802
|
return { path: bundle };
|
|
64803
64803
|
}
|
|
@@ -64974,20 +64974,20 @@ function lockHolder(contents) {
|
|
|
64974
64974
|
const pid = Number((contents ?? "").trim());
|
|
64975
64975
|
return Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
64976
64976
|
}
|
|
64977
|
-
function acquireUpdateLock(
|
|
64978
|
-
const take = () =>
|
|
64977
|
+
function acquireUpdateLock(fs30, isProcessAlive, pid, lockPath) {
|
|
64978
|
+
const take = () => fs30.writeFileExclusive(lockPath, `${String(pid)}
|
|
64979
64979
|
`);
|
|
64980
64980
|
const release = () => {
|
|
64981
|
-
|
|
64981
|
+
fs30.unlink(lockPath);
|
|
64982
64982
|
};
|
|
64983
64983
|
if (take()) {
|
|
64984
64984
|
return release;
|
|
64985
64985
|
}
|
|
64986
|
-
const holder = lockHolder(
|
|
64986
|
+
const holder = lockHolder(fs30.readFileUtf8(lockPath));
|
|
64987
64987
|
if (holder !== void 0 && holder !== pid && isProcessAlive(holder)) {
|
|
64988
64988
|
throw new UpdateConflictError(`another agent-shim update (pid ${String(holder)}) is already running`);
|
|
64989
64989
|
}
|
|
64990
|
-
|
|
64990
|
+
fs30.unlink(lockPath);
|
|
64991
64991
|
if (!take()) {
|
|
64992
64992
|
throw new UpdateConflictError("another agent-shim update took the lock while it was being replaced");
|
|
64993
64993
|
}
|
|
@@ -65752,8 +65752,8 @@ function countOf(usage, key) {
|
|
|
65752
65752
|
const value2 = key in usage ? Reflect.get(usage, key) : void 0;
|
|
65753
65753
|
return typeof value2 === "number" && Number.isFinite(value2) && value2 >= 0 ? value2 : 0;
|
|
65754
65754
|
}
|
|
65755
|
-
function contextTokensOfTranscript(
|
|
65756
|
-
const lines =
|
|
65755
|
+
function contextTokensOfTranscript(text3) {
|
|
65756
|
+
const lines = text3.split("\n");
|
|
65757
65757
|
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
65758
65758
|
const line = lines[index];
|
|
65759
65759
|
if (line === void 0 || line === "") {
|
|
@@ -65777,15 +65777,15 @@ function contextTokensOfTranscript(text2) {
|
|
|
65777
65777
|
}
|
|
65778
65778
|
return void 0;
|
|
65779
65779
|
}
|
|
65780
|
-
function newestTranscript(
|
|
65780
|
+
function newestTranscript(fs30, projectDir) {
|
|
65781
65781
|
let newest;
|
|
65782
65782
|
let newestMs = -Infinity;
|
|
65783
|
-
for (const name of
|
|
65783
|
+
for (const name of fs30.readdir(projectDir)) {
|
|
65784
65784
|
if (!name.endsWith(".jsonl")) {
|
|
65785
65785
|
continue;
|
|
65786
65786
|
}
|
|
65787
65787
|
const candidate = import_node_path43.default.join(projectDir, name);
|
|
65788
|
-
const stat =
|
|
65788
|
+
const stat = fs30.lstat(candidate);
|
|
65789
65789
|
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
65790
65790
|
newestMs = stat.mtimeMs;
|
|
65791
65791
|
newest = candidate;
|
|
@@ -65793,19 +65793,19 @@ function newestTranscript(fs29, projectDir) {
|
|
|
65793
65793
|
}
|
|
65794
65794
|
return newest;
|
|
65795
65795
|
}
|
|
65796
|
-
function latestConversationId(
|
|
65797
|
-
const file2 = newestTranscript(
|
|
65796
|
+
function latestConversationId(fs30, params) {
|
|
65797
|
+
const file2 = newestTranscript(fs30, import_node_path43.default.join(params.claudeHome, "projects", projectDirNameOf(params.cwd)));
|
|
65798
65798
|
return file2 === void 0 ? void 0 : import_node_path43.default.basename(file2, ".jsonl");
|
|
65799
65799
|
}
|
|
65800
|
-
function resumedContextTokens(
|
|
65800
|
+
function resumedContextTokens(fs30, params) {
|
|
65801
65801
|
const target = resumeTargetOf(params.passthrough);
|
|
65802
65802
|
if (target === void 0) {
|
|
65803
65803
|
return void 0;
|
|
65804
65804
|
}
|
|
65805
65805
|
const projectDir = import_node_path43.default.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
65806
|
-
const file2 = target.kind === "id" ? import_node_path43.default.join(projectDir, `${target.id}.jsonl`) : newestTranscript(
|
|
65807
|
-
const
|
|
65808
|
-
return
|
|
65806
|
+
const file2 = target.kind === "id" ? import_node_path43.default.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs30, projectDir);
|
|
65807
|
+
const text3 = file2 === void 0 ? void 0 : fs30.readFileUtf8(file2);
|
|
65808
|
+
return text3 === void 0 ? void 0 : contextTokensOfTranscript(text3);
|
|
65809
65809
|
}
|
|
65810
65810
|
var import_node_path43;
|
|
65811
65811
|
var init_resumeContext = __esm({
|
|
@@ -66068,8 +66068,8 @@ function farmRow(links, builtDirectories, adopted) {
|
|
|
66068
66068
|
const parts = [counted(links, "link", "links"), counted(builtDirectories, "built directory", "built directories"), ...adopted === 0 ? [] : [`${String(adopted)} adopted`]];
|
|
66069
66069
|
return { label: "farm", value: "resynced", detail: parts.join(", ") };
|
|
66070
66070
|
}
|
|
66071
|
-
function noteRow(
|
|
66072
|
-
return { label: "note", value:
|
|
66071
|
+
function noteRow(text3) {
|
|
66072
|
+
return { label: "note", value: text3 };
|
|
66073
66073
|
}
|
|
66074
66074
|
var init_launchReport = __esm({
|
|
66075
66075
|
"src/launcher/launchReport.ts"() {
|
|
@@ -66846,9 +66846,9 @@ function flattenToolResult(content) {
|
|
|
66846
66846
|
}
|
|
66847
66847
|
return content.map((block2) => isTextBlock(block2) ? block2.text : NON_TEXT_TOOL_RESULT).join("\n");
|
|
66848
66848
|
}
|
|
66849
|
-
function systemReminder(
|
|
66849
|
+
function systemReminder(text3) {
|
|
66850
66850
|
return `<system-reminder>
|
|
66851
|
-
${
|
|
66851
|
+
${text3}
|
|
66852
66852
|
</system-reminder>`;
|
|
66853
66853
|
}
|
|
66854
66854
|
function turnBlocks(message) {
|
|
@@ -67085,9 +67085,9 @@ function flattenToolResult2(content) {
|
|
|
67085
67085
|
}
|
|
67086
67086
|
return content.map((block2) => isTextBlock(block2) ? block2.text : NON_TEXT_TOOL_RESULT2).join("\n");
|
|
67087
67087
|
}
|
|
67088
|
-
function systemReminder2(
|
|
67088
|
+
function systemReminder2(text3) {
|
|
67089
67089
|
return `<system-reminder>
|
|
67090
|
-
${
|
|
67090
|
+
${text3}
|
|
67091
67091
|
</system-reminder>`;
|
|
67092
67092
|
}
|
|
67093
67093
|
function turnBlocks2(message) {
|
|
@@ -67212,12 +67212,12 @@ var init_translate2 = __esm({
|
|
|
67212
67212
|
function catalogueCachePath(paths, name) {
|
|
67213
67213
|
return import_node_path44.default.join(paths.catalogueDir, `${name}.json`);
|
|
67214
67214
|
}
|
|
67215
|
-
function parseCatalogueCache(
|
|
67216
|
-
if (
|
|
67215
|
+
function parseCatalogueCache(text3) {
|
|
67216
|
+
if (text3 === void 0) {
|
|
67217
67217
|
return void 0;
|
|
67218
67218
|
}
|
|
67219
67219
|
try {
|
|
67220
|
-
const parsed = CatalogueCacheSchema.safeParse(JSON.parse(
|
|
67220
|
+
const parsed = CatalogueCacheSchema.safeParse(JSON.parse(text3));
|
|
67221
67221
|
return parsed.success ? parsed.data : void 0;
|
|
67222
67222
|
} catch {
|
|
67223
67223
|
return void 0;
|
|
@@ -67834,7 +67834,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
|
|
|
67834
67834
|
return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
|
|
67835
67835
|
}
|
|
67836
67836
|
function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
67837
|
-
const { paths, fs:
|
|
67837
|
+
const { paths, fs: fs30, proc, log } = params;
|
|
67838
67838
|
if (decided.pool === void 0) {
|
|
67839
67839
|
return { identityDecision: decided };
|
|
67840
67840
|
}
|
|
@@ -67853,7 +67853,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
67853
67853
|
selectedVia: decided.source,
|
|
67854
67854
|
pools: params.pools,
|
|
67855
67855
|
paths,
|
|
67856
|
-
fs:
|
|
67856
|
+
fs: fs30,
|
|
67857
67857
|
usageFs: farmRuntime.fs,
|
|
67858
67858
|
cwd: farmRuntime.cwd,
|
|
67859
67859
|
now: farmRuntime.now,
|
|
@@ -67876,7 +67876,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
67876
67876
|
};
|
|
67877
67877
|
}
|
|
67878
67878
|
function decideLaunch(params, readOnly) {
|
|
67879
|
-
const { paths, fs:
|
|
67879
|
+
const { paths, fs: fs30, proc, log } = params;
|
|
67880
67880
|
const { env, argv } = proc;
|
|
67881
67881
|
const parsedArgv = parseLauncherArgv(argv);
|
|
67882
67882
|
const cliOverride = buildCliOverride({
|
|
@@ -67891,7 +67891,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67891
67891
|
argv0Identity: parsedArgv.identity,
|
|
67892
67892
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
67893
67893
|
readActiveIdentityFile: () => {
|
|
67894
|
-
const raw =
|
|
67894
|
+
const raw = fs30.readFileUtf8(paths.activeIdentityFile);
|
|
67895
67895
|
if (raw === void 0) {
|
|
67896
67896
|
return void 0;
|
|
67897
67897
|
}
|
|
@@ -67926,7 +67926,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67926
67926
|
}
|
|
67927
67927
|
let loadedIdentity;
|
|
67928
67928
|
if (identityDecision.name !== void 0) {
|
|
67929
|
-
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name,
|
|
67929
|
+
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs30);
|
|
67930
67930
|
if (loadedIdentity === void 0) {
|
|
67931
67931
|
log.error(
|
|
67932
67932
|
`agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
|
|
@@ -67941,7 +67941,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67941
67941
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
67942
67942
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
67943
67943
|
});
|
|
67944
|
-
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true &&
|
|
67944
|
+
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs30.readConfigFile(import_node_path45.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
|
|
67945
67945
|
log.error(
|
|
67946
67946
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
67947
67947
|
);
|
|
@@ -67950,7 +67950,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67950
67950
|
const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
|
|
67951
67951
|
const providerParams = {
|
|
67952
67952
|
paths,
|
|
67953
|
-
port:
|
|
67953
|
+
port: fs30,
|
|
67954
67954
|
...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
|
|
67955
67955
|
...farmContext === void 0 ? {} : { cascade: farmContext.cascade }
|
|
67956
67956
|
};
|
|
@@ -68049,9 +68049,9 @@ function decideLaunch(params, readOnly) {
|
|
|
68049
68049
|
const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
|
|
68050
68050
|
const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
|
|
68051
68051
|
const models = launchCascade !== void 0 && params.farm !== void 0 ? cascadeModels : globalModels;
|
|
68052
|
-
const listedProviders = listProviderNames(
|
|
68052
|
+
const listedProviders = listProviderNames(fs30.readdir, paths.providersDir).flatMap((name) => {
|
|
68053
68053
|
try {
|
|
68054
|
-
const definition = loadProvider(paths.providersDir, name,
|
|
68054
|
+
const definition = loadProvider(paths.providersDir, name, fs30);
|
|
68055
68055
|
return definition === void 0 ? [] : [[name, definition, parseCatalogueCache(params.fs.readFileUtf8(catalogueCachePath(paths, name)))?.models ?? []]];
|
|
68056
68056
|
} catch {
|
|
68057
68057
|
return [];
|
|
@@ -106967,7 +106967,7 @@ var require_core2 = __commonJS({
|
|
|
106967
106967
|
errorsText(errors = this.errors, { separator = ", ", dataVar = "data" } = {}) {
|
|
106968
106968
|
if (!errors || errors.length === 0)
|
|
106969
106969
|
return "No errors";
|
|
106970
|
-
return errors.map((e14) => `${dataVar}${e14.instancePath} ${e14.message}`).reduce((
|
|
106970
|
+
return errors.map((e14) => `${dataVar}${e14.instancePath} ${e14.message}`).reduce((text3, msg) => text3 + separator + msg);
|
|
106971
106971
|
}
|
|
106972
106972
|
$dataMetaSchema(metaSchema, keywordsJsonPointers) {
|
|
106973
106973
|
const rules = this.RULES.all;
|
|
@@ -109528,12 +109528,12 @@ var require_dist2 = __commonJS({
|
|
|
109528
109528
|
throw new Error(`Unknown format "${name}"`);
|
|
109529
109529
|
return f;
|
|
109530
109530
|
};
|
|
109531
|
-
function addFormats(ajv, list,
|
|
109531
|
+
function addFormats(ajv, list, fs30, exportName) {
|
|
109532
109532
|
var _a4;
|
|
109533
109533
|
var _b2;
|
|
109534
109534
|
(_a4 = (_b2 = ajv.opts.code).formats) !== null && _a4 !== void 0 ? _a4 : _b2.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
109535
109535
|
for (const f of list)
|
|
109536
|
-
ajv.addFormat(f,
|
|
109536
|
+
ajv.addFormat(f, fs30[f]);
|
|
109537
109537
|
}
|
|
109538
109538
|
module2.exports = exports2 = formatsPlugin;
|
|
109539
109539
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -112674,9 +112674,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
112674
112674
|
helpWidth: context.helpWidth,
|
|
112675
112675
|
outputHasColors: context.hasColors
|
|
112676
112676
|
});
|
|
112677
|
-
const
|
|
112678
|
-
if (context.hasColors) return
|
|
112679
|
-
return this._outputConfiguration.stripColor(
|
|
112677
|
+
const text3 = helper.formatHelp(this, helper);
|
|
112678
|
+
if (context.hasColors) return text3;
|
|
112679
|
+
return this._outputConfiguration.stripColor(text3);
|
|
112680
112680
|
}
|
|
112681
112681
|
/**
|
|
112682
112682
|
* @typedef HelpContext
|
|
@@ -112836,7 +112836,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
112836
112836
|
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
112837
112837
|
* @return {Command} `this` command for chaining
|
|
112838
112838
|
*/
|
|
112839
|
-
addHelpText(position,
|
|
112839
|
+
addHelpText(position, text3) {
|
|
112840
112840
|
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
112841
112841
|
if (!allowedValues.includes(position)) {
|
|
112842
112842
|
throw new Error(`Unexpected value for position to addHelpText.
|
|
@@ -112845,10 +112845,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
112845
112845
|
const helpEvent = `${position}Help`;
|
|
112846
112846
|
this.on(helpEvent, (context) => {
|
|
112847
112847
|
let helpStr;
|
|
112848
|
-
if (typeof
|
|
112849
|
-
helpStr =
|
|
112848
|
+
if (typeof text3 === "function") {
|
|
112849
|
+
helpStr = text3({ error: context.error, command: context.command });
|
|
112850
112850
|
} else {
|
|
112851
|
-
helpStr =
|
|
112851
|
+
helpStr = text3;
|
|
112852
112852
|
}
|
|
112853
112853
|
if (helpStr) {
|
|
112854
112854
|
context.write(`${helpStr}
|
|
@@ -117280,17 +117280,17 @@ function parseEntry2(project, entry) {
|
|
|
117280
117280
|
const base = match?.[1];
|
|
117281
117281
|
return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
|
|
117282
117282
|
}
|
|
117283
|
-
function listSessions2(
|
|
117283
|
+
function listSessions2(fs30, configDir) {
|
|
117284
117284
|
const found = [];
|
|
117285
|
-
for (const project of
|
|
117285
|
+
for (const project of fs30.readdir(import_node_path35.default.join(configDir, PROJECTS_DIR))) {
|
|
117286
117286
|
const projectDir = import_node_path35.default.join(configDir, PROJECTS_DIR, project);
|
|
117287
117287
|
const entries = /* @__PURE__ */ new Set();
|
|
117288
|
-
for (const name of
|
|
117288
|
+
for (const name of fs30.readdir(projectDir)) {
|
|
117289
117289
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
117290
117290
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
117291
117291
|
continue;
|
|
117292
117292
|
}
|
|
117293
|
-
const children =
|
|
117293
|
+
const children = fs30.readdir(import_node_path35.default.join(projectDir, name));
|
|
117294
117294
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
117295
117295
|
entries.add(name);
|
|
117296
117296
|
}
|
|
@@ -117301,9 +117301,9 @@ function listSessions2(fs29, configDir) {
|
|
|
117301
117301
|
}
|
|
117302
117302
|
return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
|
|
117303
117303
|
}
|
|
117304
|
-
function locateAgents(
|
|
117304
|
+
function locateAgents(fs30, configDir, relativeDir, workflowRunId, report) {
|
|
117305
117305
|
const located = [];
|
|
117306
|
-
for (const name of listDirOrReport(
|
|
117306
|
+
for (const name of listDirOrReport(fs30, configDir, relativeDir, report)) {
|
|
117307
117307
|
if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
|
|
117308
117308
|
continue;
|
|
117309
117309
|
}
|
|
@@ -117352,25 +117352,25 @@ function toNode(read, children) {
|
|
|
117352
117352
|
function describeFailure(error63) {
|
|
117353
117353
|
return error63 instanceof Error ? error63.message : String(error63);
|
|
117354
117354
|
}
|
|
117355
|
-
function readFileOrReport(
|
|
117355
|
+
function readFileOrReport(fs30, configDir, relative, report) {
|
|
117356
117356
|
try {
|
|
117357
|
-
return
|
|
117357
|
+
return fs30.readFileUtf8(import_node_path35.default.join(configDir, relative));
|
|
117358
117358
|
} catch (error63) {
|
|
117359
117359
|
report({ path: relative, reason: `could not be read: ${describeFailure(error63)}` });
|
|
117360
117360
|
return void 0;
|
|
117361
117361
|
}
|
|
117362
117362
|
}
|
|
117363
|
-
function listDirOrReport(
|
|
117363
|
+
function listDirOrReport(fs30, configDir, relative, report) {
|
|
117364
117364
|
try {
|
|
117365
|
-
return
|
|
117365
|
+
return fs30.readdir(import_node_path35.default.join(configDir, relative));
|
|
117366
117366
|
} catch (error63) {
|
|
117367
117367
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error63)}` });
|
|
117368
117368
|
return [];
|
|
117369
117369
|
}
|
|
117370
117370
|
}
|
|
117371
|
-
function parseJson3(
|
|
117371
|
+
function parseJson3(text3) {
|
|
117372
117372
|
try {
|
|
117373
|
-
const value2 = JSON.parse(
|
|
117373
|
+
const value2 = JSON.parse(text3);
|
|
117374
117374
|
return value2;
|
|
117375
117375
|
} catch {
|
|
117376
117376
|
return void 0;
|
|
@@ -117385,22 +117385,22 @@ var WorkflowRunFileSchema = external_exports.object({
|
|
|
117385
117385
|
phases: external_exports.array(external_exports.object({ title: external_exports.string() })).default([]),
|
|
117386
117386
|
summary: external_exports.string().optional()
|
|
117387
117387
|
});
|
|
117388
|
-
function summariseSession(
|
|
117388
|
+
function summariseSession(fs30, configDir, ref) {
|
|
117389
117389
|
const sessionRelative = import_node_path35.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
117390
117390
|
const subagentsRelative = import_node_path35.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
117391
117391
|
const workflowsUnderSubagents = import_node_path35.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
117392
117392
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
117393
|
-
let agentCount =
|
|
117394
|
-
for (const runDir of
|
|
117393
|
+
let agentCount = fs30.readdir(import_node_path35.default.join(configDir, subagentsRelative)).filter(isMeta).length;
|
|
117394
|
+
for (const runDir of fs30.readdir(import_node_path35.default.join(configDir, workflowsUnderSubagents))) {
|
|
117395
117395
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
117396
|
-
agentCount +=
|
|
117396
|
+
agentCount += fs30.readdir(import_node_path35.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
117397
117397
|
}
|
|
117398
117398
|
}
|
|
117399
|
-
const workflowRunCount =
|
|
117400
|
-
const transcript =
|
|
117399
|
+
const workflowRunCount = fs30.readdir(import_node_path35.default.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
|
|
117400
|
+
const transcript = fs30.lstat(import_node_path35.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
|
|
117401
117401
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
117402
117402
|
}
|
|
117403
|
-
function readSessionAgentTree(
|
|
117403
|
+
function readSessionAgentTree(fs30, configDir, ref, options = {}) {
|
|
117404
117404
|
const problems = [];
|
|
117405
117405
|
const report = (problem) => {
|
|
117406
117406
|
problems.push(problem);
|
|
@@ -117408,19 +117408,19 @@ function readSessionAgentTree(fs29, configDir, ref, options = {}) {
|
|
|
117408
117408
|
const sessionRelative = import_node_path35.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
117409
117409
|
const subagentsRelative = import_node_path35.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
117410
117410
|
const workflowsUnderSubagents = import_node_path35.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
117411
|
-
const located = locateAgents(
|
|
117412
|
-
for (const runDir of listDirOrReport(
|
|
117411
|
+
const located = locateAgents(fs30, configDir, subagentsRelative, void 0, report);
|
|
117412
|
+
for (const runDir of listDirOrReport(fs30, configDir, workflowsUnderSubagents, report)) {
|
|
117413
117413
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
117414
|
-
located.push(...locateAgents(
|
|
117414
|
+
located.push(...locateAgents(fs30, configDir, import_node_path35.default.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
117415
117415
|
}
|
|
117416
117416
|
}
|
|
117417
117417
|
const agents = /* @__PURE__ */ new Map();
|
|
117418
117418
|
for (const candidate of located) {
|
|
117419
|
-
const
|
|
117420
|
-
if (
|
|
117419
|
+
const text3 = readFileOrReport(fs30, configDir, candidate.metaPath, report);
|
|
117420
|
+
if (text3 === void 0) {
|
|
117421
117421
|
continue;
|
|
117422
117422
|
}
|
|
117423
|
-
const parsed = AgentMetaSchema.safeParse(parseJson3(
|
|
117423
|
+
const parsed = AgentMetaSchema.safeParse(parseJson3(text3));
|
|
117424
117424
|
if (!parsed.success) {
|
|
117425
117425
|
report({ path: candidate.metaPath, reason: "meta file is not a JSON object with an agentType" });
|
|
117426
117426
|
continue;
|
|
@@ -117428,7 +117428,7 @@ function readSessionAgentTree(fs29, configDir, ref, options = {}) {
|
|
|
117428
117428
|
agents.set(candidate.id, { located: candidate, meta: parsed.data });
|
|
117429
117429
|
}
|
|
117430
117430
|
const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
|
|
117431
|
-
const parentOf4 = resolveParents(
|
|
117431
|
+
const parentOf4 = resolveParents(fs30, configDir, agents, report);
|
|
117432
117432
|
const childrenOf = /* @__PURE__ */ new Map();
|
|
117433
117433
|
const roots = [];
|
|
117434
117434
|
for (const id2 of agents.keys()) {
|
|
@@ -117451,12 +117451,12 @@ function readSessionAgentTree(fs29, configDir, ref, options = {}) {
|
|
|
117451
117451
|
sessionId: ref.sessionId,
|
|
117452
117452
|
superseded: ref.superseded,
|
|
117453
117453
|
agents: roots.sort().map(build),
|
|
117454
|
-
tasks: readTasks(
|
|
117455
|
-
workflowRuns: readWorkflowRuns(
|
|
117454
|
+
tasks: readTasks(fs30, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id2) => !ownTaskLists(ref.sessionId).includes(id2)), report),
|
|
117455
|
+
workflowRuns: readWorkflowRuns(fs30, configDir, import_node_path35.default.join(sessionRelative, WORKFLOWS_DIR), report),
|
|
117456
117456
|
problems
|
|
117457
117457
|
};
|
|
117458
117458
|
}
|
|
117459
|
-
function resolveParents(
|
|
117459
|
+
function resolveParents(fs30, configDir, agents, report) {
|
|
117460
117460
|
const parentOf4 = /* @__PURE__ */ new Map();
|
|
117461
117461
|
const transcriptCache = /* @__PURE__ */ new Map();
|
|
117462
117462
|
const transcriptOf = (agent) => {
|
|
@@ -117464,9 +117464,9 @@ function resolveParents(fs29, configDir, agents, report) {
|
|
|
117464
117464
|
if (cached2 !== void 0) {
|
|
117465
117465
|
return cached2;
|
|
117466
117466
|
}
|
|
117467
|
-
const
|
|
117468
|
-
transcriptCache.set(agent.located.id,
|
|
117469
|
-
return
|
|
117467
|
+
const text3 = readFileOrReport(fs30, configDir, agent.located.transcriptPath, report) ?? "";
|
|
117468
|
+
transcriptCache.set(agent.located.id, text3);
|
|
117469
|
+
return text3;
|
|
117470
117470
|
};
|
|
117471
117471
|
const wouldCycle = (child, parent) => {
|
|
117472
117472
|
for (let cursor3 = parent; cursor3 !== void 0; cursor3 = parentOf4.get(cursor3)) {
|
|
@@ -117514,37 +117514,37 @@ function resolveParents(fs29, configDir, agents, report) {
|
|
|
117514
117514
|
function ownTaskLists(sessionId) {
|
|
117515
117515
|
return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
|
|
117516
117516
|
}
|
|
117517
|
-
function readTasks(
|
|
117517
|
+
function readTasks(fs30, configDir, ownLists, sharedLists, report) {
|
|
117518
117518
|
const tasks = [];
|
|
117519
117519
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
117520
117520
|
const relativeDir = import_node_path35.default.join(TASKS_DIR, scope);
|
|
117521
|
-
for (const name of [...listDirOrReport(
|
|
117521
|
+
for (const name of [...listDirOrReport(fs30, configDir, relativeDir, report)].sort()) {
|
|
117522
117522
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
117523
117523
|
continue;
|
|
117524
117524
|
}
|
|
117525
117525
|
const relative = import_node_path35.default.join(relativeDir, name);
|
|
117526
|
-
const
|
|
117527
|
-
const parsed = TaskFileSchema.safeParse(
|
|
117526
|
+
const text3 = readFileOrReport(fs30, configDir, relative, report);
|
|
117527
|
+
const parsed = TaskFileSchema.safeParse(text3 === void 0 ? void 0 : parseJson3(text3));
|
|
117528
117528
|
if (parsed.success) {
|
|
117529
117529
|
tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
|
|
117530
|
-
} else if (
|
|
117530
|
+
} else if (text3 !== void 0) {
|
|
117531
117531
|
report({ path: relative, reason: "task file is not a task" });
|
|
117532
117532
|
}
|
|
117533
117533
|
}
|
|
117534
117534
|
});
|
|
117535
117535
|
return tasks;
|
|
117536
117536
|
}
|
|
117537
|
-
function readWorkflowRuns(
|
|
117537
|
+
function readWorkflowRuns(fs30, configDir, relativeDir, report) {
|
|
117538
117538
|
const runs = [];
|
|
117539
|
-
for (const name of [...listDirOrReport(
|
|
117539
|
+
for (const name of [...listDirOrReport(fs30, configDir, relativeDir, report)].sort()) {
|
|
117540
117540
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
117541
117541
|
continue;
|
|
117542
117542
|
}
|
|
117543
117543
|
const relative = import_node_path35.default.join(relativeDir, name);
|
|
117544
|
-
const
|
|
117545
|
-
const parsed = WorkflowRunFileSchema.safeParse(
|
|
117544
|
+
const text3 = readFileOrReport(fs30, configDir, relative, report);
|
|
117545
|
+
const parsed = WorkflowRunFileSchema.safeParse(text3 === void 0 ? void 0 : parseJson3(text3));
|
|
117546
117546
|
if (!parsed.success) {
|
|
117547
|
-
if (
|
|
117547
|
+
if (text3 !== void 0) {
|
|
117548
117548
|
report({ path: relative, reason: "workflow run file is not a run record" });
|
|
117549
117549
|
}
|
|
117550
117550
|
continue;
|
|
@@ -117565,11 +117565,11 @@ var SessionLookupError = class extends CliError {
|
|
|
117565
117565
|
function identityConfigDir(identitiesDir, identity) {
|
|
117566
117566
|
return import_node_path36.default.join(identitiesDir, identity);
|
|
117567
117567
|
}
|
|
117568
|
-
function historyStores(
|
|
117568
|
+
function historyStores(fs30, identitiesDir, identities) {
|
|
117569
117569
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
117570
117570
|
for (const identity of identities) {
|
|
117571
117571
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
117572
|
-
const real =
|
|
117572
|
+
const real = fs30.realpath(import_node_path36.default.join(configDir, "projects"));
|
|
117573
117573
|
if (real === void 0) {
|
|
117574
117574
|
continue;
|
|
117575
117575
|
}
|
|
@@ -117582,15 +117582,15 @@ function historyStores(fs29, identitiesDir, identities) {
|
|
|
117582
117582
|
}
|
|
117583
117583
|
return [...byRealPath.values()];
|
|
117584
117584
|
}
|
|
117585
|
-
function collectSessionList(
|
|
117585
|
+
function collectSessionList(fs30, identitiesDir, identities, filters) {
|
|
117586
117586
|
const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
|
|
117587
117587
|
if (filters.identity !== void 0 && names.length === 0) {
|
|
117588
117588
|
throw new SessionLookupError(`no identity named "${filters.identity}"`);
|
|
117589
117589
|
}
|
|
117590
117590
|
const sessions = [];
|
|
117591
|
-
for (const store of historyStores(
|
|
117592
|
-
for (const ref of listSessions2(
|
|
117593
|
-
const summary = summariseSession(
|
|
117591
|
+
for (const store of historyStores(fs30, identitiesDir, names)) {
|
|
117592
|
+
for (const ref of listSessions2(fs30, store.configDir)) {
|
|
117593
|
+
const summary = summariseSession(fs30, store.configDir, ref);
|
|
117594
117594
|
if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
|
|
117595
117595
|
sessions.push({ ...summary, identities: store.identities });
|
|
117596
117596
|
}
|
|
@@ -117598,14 +117598,14 @@ function collectSessionList(fs29, identitiesDir, identities, filters) {
|
|
|
117598
117598
|
}
|
|
117599
117599
|
return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
|
|
117600
117600
|
}
|
|
117601
|
-
function locateSession(
|
|
117601
|
+
function locateSession(fs30, identitiesDir, identities, query, onlyIdentity) {
|
|
117602
117602
|
const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
|
|
117603
117603
|
if (onlyIdentity !== void 0 && names.length === 0) {
|
|
117604
117604
|
throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
|
|
117605
117605
|
}
|
|
117606
117606
|
const matches = [];
|
|
117607
|
-
for (const store of historyStores(
|
|
117608
|
-
for (const ref of listSessions2(
|
|
117607
|
+
for (const store of historyStores(fs30, identitiesDir, names)) {
|
|
117608
|
+
for (const ref of listSessions2(fs30, store.configDir)) {
|
|
117609
117609
|
if (ref.sessionId.startsWith(query)) {
|
|
117610
117610
|
matches.push({ identities: store.identities, configDir: store.configDir, ref });
|
|
117611
117611
|
}
|
|
@@ -117622,9 +117622,9 @@ function locateSession(fs29, identitiesDir, identities, query, onlyIdentity) {
|
|
|
117622
117622
|
}
|
|
117623
117623
|
throw new SessionLookupError(`"${query}" matches ${String(candidates.length)} sessions: ${candidates.map((match) => `${match.ref.sessionId} (${match.identities.join(", ")})`).join("; ")}; give more of the id or pass --identity`);
|
|
117624
117624
|
}
|
|
117625
|
-
function showSession(
|
|
117626
|
-
const located = locateSession(
|
|
117627
|
-
return { identities: located.identities, tree: readSessionAgentTree(
|
|
117625
|
+
function showSession(fs30, identitiesDir, identities, query, onlyIdentity) {
|
|
117626
|
+
const located = locateSession(fs30, identitiesDir, identities, query, onlyIdentity);
|
|
117627
|
+
return { identities: located.identities, tree: readSessionAgentTree(fs30, located.configDir, located.ref) };
|
|
117628
117628
|
}
|
|
117629
117629
|
|
|
117630
117630
|
// src/frontdoor/commands.ts
|
|
@@ -117670,13 +117670,13 @@ function stateDirOf(paths, pool) {
|
|
|
117670
117670
|
function sessionStatePath(paths, pool, sessionId) {
|
|
117671
117671
|
return import_node_path37.default.join(stateDirOf(paths, pool), `${sessionId}.json`);
|
|
117672
117672
|
}
|
|
117673
|
-
function writeSessionState(
|
|
117674
|
-
|
|
117675
|
-
|
|
117673
|
+
function writeSessionState(fs30, paths, pool, sessionId, state) {
|
|
117674
|
+
fs30.mkdirPrivate(stateDirOf(paths, pool));
|
|
117675
|
+
fs30.writeFilePrivate(sessionStatePath(paths, pool, sessionId), `${JSON.stringify(SessionStateSchema.parse(state))}
|
|
117676
117676
|
`);
|
|
117677
117677
|
}
|
|
117678
|
-
function readSessionState(
|
|
117679
|
-
const raw =
|
|
117678
|
+
function readSessionState(fs30, paths, pool, sessionId) {
|
|
117679
|
+
const raw = fs30.readFileUtf8(sessionStatePath(paths, pool, sessionId));
|
|
117680
117680
|
if (raw === void 0) {
|
|
117681
117681
|
return void 0;
|
|
117682
117682
|
}
|
|
@@ -117687,20 +117687,20 @@ function readSessionState(fs29, paths, pool, sessionId) {
|
|
|
117687
117687
|
return void 0;
|
|
117688
117688
|
}
|
|
117689
117689
|
}
|
|
117690
|
-
function registerSupervised(
|
|
117691
|
-
|
|
117692
|
-
|
|
117690
|
+
function registerSupervised(fs30, paths, session) {
|
|
117691
|
+
fs30.mkdirPrivate(sessionsDirOf(paths, session.pool));
|
|
117692
|
+
fs30.writeFilePrivate(sessionFileOf(paths, session.pool, session.sessionId), `${JSON.stringify(SupervisedSessionSchema.parse(session))}
|
|
117693
117693
|
`);
|
|
117694
117694
|
}
|
|
117695
|
-
function unregisterSupervised(
|
|
117696
|
-
|
|
117697
|
-
|
|
117695
|
+
function unregisterSupervised(fs30, paths, pool, sessionId) {
|
|
117696
|
+
fs30.removeRecursive(sessionFileOf(paths, pool, sessionId));
|
|
117697
|
+
fs30.removeRecursive(sessionStatePath(paths, pool, sessionId));
|
|
117698
117698
|
}
|
|
117699
|
-
function liveSupervised(
|
|
117699
|
+
function liveSupervised(fs30, paths, pool, isRunning) {
|
|
117700
117700
|
const live = [];
|
|
117701
|
-
for (const name of
|
|
117701
|
+
for (const name of fs30.readdir(sessionsDirOf(paths, pool))) {
|
|
117702
117702
|
const file2 = import_node_path37.default.join(sessionsDirOf(paths, pool), name);
|
|
117703
|
-
const raw =
|
|
117703
|
+
const raw = fs30.readFileUtf8(file2);
|
|
117704
117704
|
if (raw === void 0) {
|
|
117705
117705
|
continue;
|
|
117706
117706
|
}
|
|
@@ -117708,13 +117708,13 @@ function liveSupervised(fs29, paths, pool, isRunning) {
|
|
|
117708
117708
|
try {
|
|
117709
117709
|
parsed = SupervisedSessionSchema.safeParse(JSON.parse(raw));
|
|
117710
117710
|
} catch {
|
|
117711
|
-
|
|
117711
|
+
fs30.removeRecursive(file2);
|
|
117712
117712
|
continue;
|
|
117713
117713
|
}
|
|
117714
117714
|
if (parsed.success && isRunning(parsed.data.pid)) {
|
|
117715
117715
|
live.push(parsed.data);
|
|
117716
117716
|
} else {
|
|
117717
|
-
|
|
117717
|
+
fs30.removeRecursive(file2);
|
|
117718
117718
|
}
|
|
117719
117719
|
}
|
|
117720
117720
|
return live;
|
|
@@ -117743,13 +117743,13 @@ var ModelMoveRequestSchema = external_exports.strictObject({
|
|
|
117743
117743
|
/** When the door wrote the request, so a supervisor can tell a fresh request from one left behind. */
|
|
117744
117744
|
at: external_exports.iso.datetime()
|
|
117745
117745
|
});
|
|
117746
|
-
function writeModelMove(
|
|
117747
|
-
|
|
117748
|
-
|
|
117746
|
+
function writeModelMove(fs30, paths, request7) {
|
|
117747
|
+
fs30.mkdirPrivate(paths.modelMovesDir);
|
|
117748
|
+
fs30.writeFilePrivate(import_node_path37.default.join(paths.modelMovesDir, `${request7.sessionId}.json`), `${JSON.stringify(ModelMoveRequestSchema.parse(request7))}
|
|
117749
117749
|
`);
|
|
117750
117750
|
}
|
|
117751
|
-
function readModelMove(
|
|
117752
|
-
const raw =
|
|
117751
|
+
function readModelMove(fs30, paths, sessionId) {
|
|
117752
|
+
const raw = fs30.readFileUtf8(import_node_path37.default.join(paths.modelMovesDir, `${sessionId}.json`));
|
|
117753
117753
|
if (raw === void 0) {
|
|
117754
117754
|
return void 0;
|
|
117755
117755
|
}
|
|
@@ -117759,12 +117759,12 @@ function readModelMove(fs29, paths, sessionId) {
|
|
|
117759
117759
|
return void 0;
|
|
117760
117760
|
}
|
|
117761
117761
|
}
|
|
117762
|
-
function removeModelMove(
|
|
117763
|
-
|
|
117762
|
+
function removeModelMove(fs30, paths, sessionId) {
|
|
117763
|
+
fs30.removeRecursive(import_node_path37.default.join(paths.modelMovesDir, `${sessionId}.json`));
|
|
117764
117764
|
}
|
|
117765
|
-
function supervisedSessionOf(
|
|
117766
|
-
for (const pool of
|
|
117767
|
-
const sessions = liveSupervised(
|
|
117765
|
+
function supervisedSessionOf(fs30, paths, sessionId, isRunning) {
|
|
117766
|
+
for (const pool of fs30.readdir(paths.superviseDir)) {
|
|
117767
|
+
const sessions = liveSupervised(fs30, paths, pool, isRunning);
|
|
117768
117768
|
const found = sessions.find((session) => session.sessionId === sessionId);
|
|
117769
117769
|
if (found !== void 0) {
|
|
117770
117770
|
return found;
|
|
@@ -117822,9 +117822,9 @@ function blendedPricePerMTok(prices, mix) {
|
|
|
117822
117822
|
|
|
117823
117823
|
// src/selection/targetStore.ts
|
|
117824
117824
|
var SEED_LOOKBACK_RECORDS = 500;
|
|
117825
|
-
function createTargetObservationStore(
|
|
117825
|
+
function createTargetObservationStore(fs30, paths) {
|
|
117826
117826
|
let observations = /* @__PURE__ */ new Map();
|
|
117827
|
-
const seeded = readUsageLog(
|
|
117827
|
+
const seeded = readUsageLog(fs30, paths.usageLogDir, {}).records.slice(-SEED_LOOKBACK_RECORDS);
|
|
117828
117828
|
for (const record2 of seeded) {
|
|
117829
117829
|
observations = observeRecord(observations, record2);
|
|
117830
117830
|
}
|
|
@@ -118244,8 +118244,8 @@ var StampsFileSchema = external_exports.strictObject({
|
|
|
118244
118244
|
schemaVersion: external_exports.literal(STAMPS_SCHEMA_VERSION),
|
|
118245
118245
|
handled: external_exports.record(external_exports.string().min(1), external_exports.iso.datetime())
|
|
118246
118246
|
});
|
|
118247
|
-
function readHandled(
|
|
118248
|
-
const raw =
|
|
118247
|
+
function readHandled(fs30, file2) {
|
|
118248
|
+
const raw = fs30.readFileUtf8(file2);
|
|
118249
118249
|
if (raw === void 0) {
|
|
118250
118250
|
return {};
|
|
118251
118251
|
}
|
|
@@ -118258,10 +118258,10 @@ function readHandled(fs29, file2) {
|
|
|
118258
118258
|
const result = StampsFileSchema.safeParse(parsed);
|
|
118259
118259
|
return result.success ? Object.fromEntries(Object.entries(result.data.handled).map(([key, at2]) => [key, Date.parse(at2)])) : {};
|
|
118260
118260
|
}
|
|
118261
|
-
function writeHandled(
|
|
118261
|
+
function writeHandled(fs30, file2, handled) {
|
|
118262
118262
|
const next = { schemaVersion: STAMPS_SCHEMA_VERSION, handled: Object.fromEntries(Object.entries(handled).map(([key, at2]) => [key, new Date(at2).toISOString()])) };
|
|
118263
|
-
|
|
118264
|
-
|
|
118263
|
+
fs30.mkdirPrivate(import_node_path48.default.dirname(file2));
|
|
118264
|
+
fs30.writeFilePrivate(file2, `${JSON.stringify(next, null, 2)}
|
|
118265
118265
|
`);
|
|
118266
118266
|
}
|
|
118267
118267
|
|
|
@@ -118907,8 +118907,8 @@ function finiteNumber(record2, field) {
|
|
|
118907
118907
|
const value2 = record2 === void 0 ? void 0 : record2[field];
|
|
118908
118908
|
return typeof value2 === "number" && Number.isFinite(value2) ? value2 : void 0;
|
|
118909
118909
|
}
|
|
118910
|
-
function excerpt(
|
|
118911
|
-
return
|
|
118910
|
+
function excerpt(text3) {
|
|
118911
|
+
return text3.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS ? text3 : `${text3.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS)}...`;
|
|
118912
118912
|
}
|
|
118913
118913
|
function payloadEventsOf(body) {
|
|
118914
118914
|
const parsed = parseJsonObject(body);
|
|
@@ -119038,8 +119038,8 @@ function createRcSessionTracker(deps) {
|
|
|
119038
119038
|
if (!accepted2 || buffered2 >= RC_CREATE_RESPONSE_CAP_BYTES) {
|
|
119039
119039
|
return;
|
|
119040
119040
|
}
|
|
119041
|
-
const
|
|
119042
|
-
body = body +
|
|
119041
|
+
const text3 = Buffer.from(chunk2).toString("utf8");
|
|
119042
|
+
body = body + text3.slice(0, RC_CREATE_RESPONSE_CAP_BYTES - buffered2);
|
|
119043
119043
|
buffered2 = body.length;
|
|
119044
119044
|
},
|
|
119045
119045
|
onEnd: () => {
|
|
@@ -119257,13 +119257,13 @@ function teeRoutedResponse(response, observer, onSettled) {
|
|
|
119257
119257
|
}
|
|
119258
119258
|
|
|
119259
119259
|
// src/frontdoor/rcWrites.ts
|
|
119260
|
-
function buildRcUserMessagePayload(uuid3, sessionId,
|
|
119260
|
+
function buildRcUserMessagePayload(uuid3, sessionId, text3) {
|
|
119261
119261
|
return {
|
|
119262
119262
|
type: "user",
|
|
119263
119263
|
uuid: uuid3,
|
|
119264
119264
|
session_id: sessionId,
|
|
119265
119265
|
parent_tool_use_id: null,
|
|
119266
|
-
message: { role: "user", content:
|
|
119266
|
+
message: { role: "user", content: text3 }
|
|
119267
119267
|
};
|
|
119268
119268
|
}
|
|
119269
119269
|
function buildRcEventWriteBody(payload) {
|
|
@@ -119328,7 +119328,7 @@ function rcWriteHeaders(credential) {
|
|
|
119328
119328
|
}
|
|
119329
119329
|
return headers;
|
|
119330
119330
|
}
|
|
119331
|
-
async function injectRcUserMessage(deps, sessionId,
|
|
119331
|
+
async function injectRcUserMessage(deps, sessionId, text3) {
|
|
119332
119332
|
const credential = deps.credentialOf(sessionId);
|
|
119333
119333
|
if (credential === void 0) {
|
|
119334
119334
|
return { ok: false, message: rcSessionNotObservedMessage(sessionId) };
|
|
@@ -119336,7 +119336,7 @@ async function injectRcUserMessage(deps, sessionId, text2) {
|
|
|
119336
119336
|
if (credential.authorization === void 0) {
|
|
119337
119337
|
return noOAuthCredentialResult(sessionId);
|
|
119338
119338
|
}
|
|
119339
|
-
const body = JSON.stringify(buildRcEventWriteBody(buildRcUserMessagePayload(deps.newUuid(), sessionId,
|
|
119339
|
+
const body = JSON.stringify(buildRcEventWriteBody(buildRcUserMessagePayload(deps.newUuid(), sessionId, text3)));
|
|
119340
119340
|
let answer;
|
|
119341
119341
|
try {
|
|
119342
119342
|
answer = await deps.dial.writeEvents(sessionId, rcWriteHeaders(credential), body);
|
|
@@ -119559,9 +119559,9 @@ var RC_PERMISSION_MODE_LIST = RC_PERMISSION_MODES.join(", ");
|
|
|
119559
119559
|
var CONTROL_PATH_PREFIX = "/__agent-shim/rc";
|
|
119560
119560
|
var CONTROL_BODY_CAP_BYTES = 10485760;
|
|
119561
119561
|
function answerJson(response, status, body) {
|
|
119562
|
-
const
|
|
119563
|
-
response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(
|
|
119564
|
-
response.end(
|
|
119562
|
+
const text3 = JSON.stringify(body);
|
|
119563
|
+
response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(text3, "utf8")) });
|
|
119564
|
+
response.end(text3);
|
|
119565
119565
|
}
|
|
119566
119566
|
function isJsonObject(value2) {
|
|
119567
119567
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
@@ -119810,12 +119810,12 @@ function createRcControlHandler(deps) {
|
|
|
119810
119810
|
answerJson(response, HTTP_STATUS.badRequest, { error: "the answer body must be JSON naming a non-empty session id, request id, and an approve boolean" });
|
|
119811
119811
|
return;
|
|
119812
119812
|
}
|
|
119813
|
-
const
|
|
119814
|
-
if (parsed.approve &&
|
|
119813
|
+
const text3 = "text" in parsed && typeof parsed.text === "string" ? parsed.text : void 0;
|
|
119814
|
+
if (parsed.approve && text3 !== void 0 && text3 !== "") {
|
|
119815
119815
|
answerJson(response, HTTP_STATUS.badRequest, { error: "an approval carries no text (the protocol's allow result has no message field); text is the denial message" });
|
|
119816
119816
|
return;
|
|
119817
119817
|
}
|
|
119818
|
-
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 :
|
|
119818
|
+
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 : text3 });
|
|
119819
119819
|
if (result.ok) {
|
|
119820
119820
|
answerJson(response, HTTP_STATUS.ok, { session: parsed.session, request: parsed.request, sequenceNums: result.sequenceNums });
|
|
119821
119821
|
return;
|
|
@@ -120078,7 +120078,7 @@ function frontDoorRcControl(transport, token) {
|
|
|
120078
120078
|
listSessions: async () => sessionsOf(await listAnswerOf(`${CONTROL_PATH_PREFIX}/sessions`, "listing the door's Remote Control sessions"), "listing the door's Remote Control sessions"),
|
|
120079
120079
|
statusOf: async (sessionId) => statusesOf(await listAnswerOf(`${CONTROL_PATH_PREFIX}/status${sessionQuery(sessionId)}`, "reading the door's Remote Control session status"), "reading the door's Remote Control session status"),
|
|
120080
120080
|
pendingOf: async (sessionId) => pendingOfAnswer(await listAnswerOf(`${CONTROL_PATH_PREFIX}/pending${sessionQuery(sessionId)}`, "listing the door's pending Remote Control control requests"), "listing the door's pending Remote Control control requests"),
|
|
120081
|
-
sendPrompt: async (sessionId,
|
|
120081
|
+
sendPrompt: async (sessionId, text3) => await writeOf(`${CONTROL_PATH_PREFIX}/inject`, JSON.stringify({ session: sessionId, text: text3 }), (status, message) => `injecting into ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
120082
120082
|
answerRequest: async (sessionId, requestId, decision) => await writeOf(
|
|
120083
120083
|
`${CONTROL_PATH_PREFIX}/answer`,
|
|
120084
120084
|
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message } }),
|
|
@@ -121791,11 +121791,11 @@ var AsyncIteratorClass = class {
|
|
|
121791
121791
|
return this;
|
|
121792
121792
|
}
|
|
121793
121793
|
};
|
|
121794
|
-
function parseEmptyableJSON(
|
|
121795
|
-
if (!
|
|
121794
|
+
function parseEmptyableJSON(text3) {
|
|
121795
|
+
if (!text3) {
|
|
121796
121796
|
return void 0;
|
|
121797
121797
|
}
|
|
121798
|
-
return JSON.parse(
|
|
121798
|
+
return JSON.parse(text3);
|
|
121799
121799
|
}
|
|
121800
121800
|
function stringifyJSON(value2) {
|
|
121801
121801
|
return JSON.stringify(value2);
|
|
@@ -122846,8 +122846,8 @@ function createORPCErrorFromMalformedResponse(options) {
|
|
|
122846
122846
|
}
|
|
122847
122847
|
var INFERRED_MESSAGE_MIN_LENGTH = 1;
|
|
122848
122848
|
var INFERRED_MESSAGE_MAX_LENGTH = 256;
|
|
122849
|
-
function isInferableMessage(
|
|
122850
|
-
return
|
|
122849
|
+
function isInferableMessage(text3) {
|
|
122850
|
+
return text3.length >= INFERRED_MESSAGE_MIN_LENGTH && text3.length <= INFERRED_MESSAGE_MAX_LENGTH;
|
|
122851
122851
|
}
|
|
122852
122852
|
function inferMalformedResponseMessage(response) {
|
|
122853
122853
|
if (typeof response.body === "string" && isInferableMessage(response.body)) {
|
|
@@ -127584,15 +127584,15 @@ async function toStandardBody(re, options) {
|
|
|
127584
127584
|
throw new TypeError("Failed to read body: body stream already read");
|
|
127585
127585
|
}
|
|
127586
127586
|
if (hint === "json") {
|
|
127587
|
-
const
|
|
127588
|
-
return parseEmptyableJSON(
|
|
127587
|
+
const text3 = await re.text();
|
|
127588
|
+
return parseEmptyableJSON(text3);
|
|
127589
127589
|
}
|
|
127590
127590
|
if (hint === "form-data") {
|
|
127591
127591
|
return await re.formData();
|
|
127592
127592
|
}
|
|
127593
127593
|
if (hint === "url-search-params") {
|
|
127594
|
-
const
|
|
127595
|
-
return new URLSearchParams(
|
|
127594
|
+
const text3 = await re.text();
|
|
127595
|
+
return new URLSearchParams(text3);
|
|
127596
127596
|
}
|
|
127597
127597
|
if (hint === "event-stream") {
|
|
127598
127598
|
return toAsyncIteratorObject(re.body);
|
|
@@ -128068,16 +128068,16 @@ async function toStandardBody2(req, options = {}) {
|
|
|
128068
128068
|
throw new TypeError("Failed to read body: body stream already read or destroyed");
|
|
128069
128069
|
}
|
|
128070
128070
|
if (hint === "json") {
|
|
128071
|
-
const
|
|
128072
|
-
return parseEmptyableJSON(
|
|
128071
|
+
const text3 = await _streamToString(req);
|
|
128072
|
+
return parseEmptyableJSON(text3);
|
|
128073
128073
|
}
|
|
128074
128074
|
const contentType = req.headers["content-type"];
|
|
128075
128075
|
if (hint === "form-data") {
|
|
128076
128076
|
return _streamToFormData(req, contentType);
|
|
128077
128077
|
}
|
|
128078
128078
|
if (hint === "url-search-params") {
|
|
128079
|
-
const
|
|
128080
|
-
return new URLSearchParams(
|
|
128079
|
+
const text3 = await _streamToString(req);
|
|
128080
|
+
return new URLSearchParams(text3);
|
|
128081
128081
|
}
|
|
128082
128082
|
if (hint === "event-stream") {
|
|
128083
128083
|
return toAsyncIteratorObject2(req);
|
|
@@ -130859,16 +130859,16 @@ function walk2(body, hashing, parentAfter) {
|
|
|
130859
130859
|
continue;
|
|
130860
130860
|
}
|
|
130861
130861
|
const isKey = kind === STRING && depth >= 1 && expectKey[depth - 1] === true;
|
|
130862
|
-
const
|
|
130863
|
-
if (isKey &&
|
|
130862
|
+
const text3 = isKey ? body.toString("latin1", start, end) : void 0;
|
|
130863
|
+
if (isKey && text3 === CACHE_MARKER_KEY) {
|
|
130864
130864
|
skipNextValue = true;
|
|
130865
130865
|
continue;
|
|
130866
130866
|
}
|
|
130867
130867
|
if (depth === 1 && isKey) {
|
|
130868
|
-
topKey =
|
|
130868
|
+
topKey = text3;
|
|
130869
130869
|
}
|
|
130870
130870
|
const closesMessages = kind === CLOSE && inMessages && depth === MESSAGES_ARRAY_DEPTH;
|
|
130871
|
-
if (hashing && !closesMessages && !(depth === 1 && isKey && !THREAD_MEMBER_KEYS.has(
|
|
130871
|
+
if (hashing && !closesMessages && !(depth === 1 && isKey && !THREAD_MEMBER_KEYS.has(text3 ?? ""))) {
|
|
130872
130872
|
const target = inMessages ? messages : depth >= 1 && topKey !== void 0 && THREAD_MEMBER_KEYS.has(topKey) ? thread : void 0;
|
|
130873
130873
|
if (target !== void 0) {
|
|
130874
130874
|
target.update(body.subarray(start, end));
|
|
@@ -131838,8 +131838,8 @@ function createCodexRoute(ports) {
|
|
|
131838
131838
|
if (!parsed.success) {
|
|
131839
131839
|
return errorResponse(HTTP_STATUS.badRequest, "not a count_tokens request");
|
|
131840
131840
|
}
|
|
131841
|
-
const
|
|
131842
|
-
return { status: HTTP_STATUS.ok, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ input_tokens: Math.ceil(
|
|
131841
|
+
const text3 = JSON.stringify({ system: parsed.data.system, messages: parsed.data.messages, tools: parsed.data.tools });
|
|
131842
|
+
return { status: HTTP_STATUS.ok, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ input_tokens: Math.ceil(text3.length / CHARS_PER_TOKEN) }) };
|
|
131843
131843
|
};
|
|
131844
131844
|
return async (request7) => {
|
|
131845
131845
|
if (request7.method === "GET" && request7.path === "/healthz") {
|
|
@@ -132700,28 +132700,28 @@ async function scanRequestHead(request7, wholeBody = false) {
|
|
|
132700
132700
|
const body = request7.body;
|
|
132701
132701
|
const head = [];
|
|
132702
132702
|
let seen = 0;
|
|
132703
|
-
let
|
|
132703
|
+
let text3 = "";
|
|
132704
132704
|
let decided = false;
|
|
132705
132705
|
let ended = false;
|
|
132706
132706
|
let error63;
|
|
132707
132707
|
const replay = new import_node_stream2.PassThrough();
|
|
132708
|
-
const modelIn = () => /"model"\s*:\s*"([^"]+)"/.exec(
|
|
132708
|
+
const modelIn = () => /"model"\s*:\s*"([^"]+)"/.exec(text3)?.[1];
|
|
132709
132709
|
const settled = new Promise((resolve2) => {
|
|
132710
132710
|
const settle2 = () => {
|
|
132711
132711
|
const model = modelIn();
|
|
132712
|
-
const hasImage = /"type"\s*:\s*"image"/.test(
|
|
132712
|
+
const hasImage = /"type"\s*:\s*"image"/.test(text3);
|
|
132713
132713
|
for (const chunk2 of head) {
|
|
132714
132714
|
replay.write(chunk2);
|
|
132715
132715
|
}
|
|
132716
|
-
const maxTokens = /"max_tokens"\s*:\s*([0-9]+)/.exec(
|
|
132716
|
+
const maxTokens = /"max_tokens"\s*:\s*([0-9]+)/.exec(text3)?.[1];
|
|
132717
132717
|
resolve2({
|
|
132718
132718
|
...model === void 0 ? {} : { model },
|
|
132719
132719
|
hasImage,
|
|
132720
|
-
toolsPresent: /"tools"\s*:\s*\[\s*\{/.test(
|
|
132721
|
-
thinking: /"thinking"\s*:\s*\{\s*"type"\s*:\s*"enabled"/.test(
|
|
132720
|
+
toolsPresent: /"tools"\s*:\s*\[\s*\{/.test(text3),
|
|
132721
|
+
thinking: /"thinking"\s*:\s*\{\s*"type"\s*:\s*"enabled"/.test(text3),
|
|
132722
132722
|
...maxTokens === void 0 ? {} : { maxTokens: Number(maxTokens) },
|
|
132723
132723
|
isCountTokens: request7.url.includes("/v1/messages/count_tokens"),
|
|
132724
|
-
...wholeBody ? { whole: true, text:
|
|
132724
|
+
...wholeBody ? { whole: true, text: text3 } : {},
|
|
132725
132725
|
replayed: { ...request7, body: replay }
|
|
132726
132726
|
});
|
|
132727
132727
|
};
|
|
@@ -132737,7 +132737,7 @@ async function scanRequestHead(request7, wholeBody = false) {
|
|
|
132737
132737
|
}
|
|
132738
132738
|
head.push(chunk2);
|
|
132739
132739
|
seen += chunk2.length;
|
|
132740
|
-
|
|
132740
|
+
text3 += chunk2.toString("utf8");
|
|
132741
132741
|
if (!wholeBody && (modelIn() !== void 0 || seen >= REQUEST_SCAN_CAP_BYTES)) {
|
|
132742
132742
|
decided = true;
|
|
132743
132743
|
settle2();
|
|
@@ -133240,9 +133240,9 @@ function growthBookFeatures() {
|
|
|
133240
133240
|
};
|
|
133241
133241
|
}
|
|
133242
133242
|
var answerServerJson = (response, status, body) => {
|
|
133243
|
-
const
|
|
133244
|
-
response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(
|
|
133245
|
-
response.end(
|
|
133243
|
+
const text3 = JSON.stringify(body);
|
|
133244
|
+
response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(text3, "utf8")) });
|
|
133245
|
+
response.end(text3);
|
|
133246
133246
|
};
|
|
133247
133247
|
function createRcSelfHostLocal(deps) {
|
|
133248
133248
|
return {
|
|
@@ -133326,8 +133326,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
|
133326
133326
|
function isRecord16(value2) {
|
|
133327
133327
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
133328
133328
|
}
|
|
133329
|
-
function readJsonObject(
|
|
133330
|
-
const raw =
|
|
133329
|
+
function readJsonObject(fs30, file2) {
|
|
133330
|
+
const raw = fs30.readFileUtf8(file2);
|
|
133331
133331
|
if (raw === void 0) {
|
|
133332
133332
|
return void 0;
|
|
133333
133333
|
}
|
|
@@ -133339,8 +133339,8 @@ function readJsonObject(fs29, file2) {
|
|
|
133339
133339
|
}
|
|
133340
133340
|
return isRecord16(parsed) ? parsed : void 0;
|
|
133341
133341
|
}
|
|
133342
|
-
function readRcSelfHostRecord(
|
|
133343
|
-
const parsed = readJsonObject(
|
|
133342
|
+
function readRcSelfHostRecord(fs30, frontdoorDir) {
|
|
133343
|
+
const parsed = readJsonObject(fs30, import_node_path52.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
133344
133344
|
if (parsed === void 0) {
|
|
133345
133345
|
return void 0;
|
|
133346
133346
|
}
|
|
@@ -133453,8 +133453,8 @@ function formatRcPendingList(pending) {
|
|
|
133453
133453
|
}
|
|
133454
133454
|
return pending.map((request7) => `${request7.sessionId} ${request7.requestId} ${request7.type}${request7.summary === "" ? "" : ` ${request7.summary}`} observed ${new Date(request7.observedAt).toISOString()}`);
|
|
133455
133455
|
}
|
|
133456
|
-
function eventExcerpt(
|
|
133457
|
-
return
|
|
133456
|
+
function eventExcerpt(text3) {
|
|
133457
|
+
return text3.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS ? text3 : `${text3.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS)}...`;
|
|
133458
133458
|
}
|
|
133459
133459
|
var PERCENT_SCALE = 100;
|
|
133460
133460
|
var MS_PER_SECOND14 = 1e3;
|
|
@@ -133785,11 +133785,11 @@ function credentialOfJson(parsed) {
|
|
|
133785
133785
|
function sequenceNumOfJson(value2) {
|
|
133786
133786
|
return typeof value2 === "number" && Number.isInteger(value2) && value2 >= 0 ? value2 : void 0;
|
|
133787
133787
|
}
|
|
133788
|
-
function createRcCredentialStore(
|
|
133789
|
-
|
|
133788
|
+
function createRcCredentialStore(fs30, dir) {
|
|
133789
|
+
fs30.mkdirPrivate(dir);
|
|
133790
133790
|
const fileFor = (sessionId) => import_node_path53.default.join(dir, `${sessionId}.json`);
|
|
133791
133791
|
const readParsed = (sessionId) => {
|
|
133792
|
-
const raw =
|
|
133792
|
+
const raw = fs30.readFileUtf8(fileFor(sessionId));
|
|
133793
133793
|
if (raw === void 0) {
|
|
133794
133794
|
return void 0;
|
|
133795
133795
|
}
|
|
@@ -133814,7 +133814,7 @@ function createRcCredentialStore(fs29, dir) {
|
|
|
133814
133814
|
}
|
|
133815
133815
|
const cursor3 = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
|
|
133816
133816
|
const record2 = { ...credential, ...cursor3 === void 0 ? {} : { highestSequenceNum: cursor3 } };
|
|
133817
|
-
|
|
133817
|
+
fs30.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
|
|
133818
133818
|
`);
|
|
133819
133819
|
},
|
|
133820
133820
|
readCursor: (sessionId) => {
|
|
@@ -133829,14 +133829,14 @@ function createRcCredentialStore(fs29, dir) {
|
|
|
133829
133829
|
}
|
|
133830
133830
|
const credential = credentialOfJson(readParsed(sessionId));
|
|
133831
133831
|
const record2 = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
|
|
133832
|
-
|
|
133832
|
+
fs30.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
|
|
133833
133833
|
`);
|
|
133834
133834
|
},
|
|
133835
133835
|
remove: (sessionId) => {
|
|
133836
133836
|
if (!isSafeSessionId(sessionId)) {
|
|
133837
133837
|
return;
|
|
133838
133838
|
}
|
|
133839
|
-
|
|
133839
|
+
fs30.removeRecursive(fileFor(sessionId));
|
|
133840
133840
|
}
|
|
133841
133841
|
};
|
|
133842
133842
|
}
|
|
@@ -135153,9 +135153,9 @@ data: ${JSON.stringify(envelope)}
|
|
|
135153
135153
|
};
|
|
135154
135154
|
const sessionRow = (session) => ({ id: session.id, title: session.title, created_at: new Date(session.createdAt).toISOString(), status: "active", conversation_id: session.conversation.id });
|
|
135155
135155
|
const answerJson2 = async (response, status, body, extraHeaders = {}) => {
|
|
135156
|
-
const
|
|
135157
|
-
response.start(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(
|
|
135158
|
-
await response.write(
|
|
135156
|
+
const text3 = JSON.stringify(body);
|
|
135157
|
+
response.start(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(text3, "utf8")), ...extraHeaders });
|
|
135158
|
+
await response.write(text3);
|
|
135159
135159
|
response.end();
|
|
135160
135160
|
};
|
|
135161
135161
|
const noCredential = async (response) => {
|
|
@@ -135557,8 +135557,8 @@ function createSseParser() {
|
|
|
135557
135557
|
let dataLines = [];
|
|
135558
135558
|
let seenAnyText = false;
|
|
135559
135559
|
return {
|
|
135560
|
-
write: (
|
|
135561
|
-
let incoming =
|
|
135560
|
+
write: (text3) => {
|
|
135561
|
+
let incoming = text3;
|
|
135562
135562
|
if (!seenAnyText) {
|
|
135563
135563
|
seenAnyText = true;
|
|
135564
135564
|
incoming = incoming.charCodeAt(0) === SSE_BYTE_ORDER_MARK ? incoming.slice(1) : incoming;
|
|
@@ -136450,7 +136450,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, retire, trackTun
|
|
|
136450
136450
|
startProviderListener: async (preferredPort) => {
|
|
136451
136451
|
const authority = loadCa();
|
|
136452
136452
|
const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
|
|
136453
|
-
const rcInject = async (sessionId,
|
|
136453
|
+
const rcInject = async (sessionId, text3) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto25.randomUUID }, sessionId, text3);
|
|
136454
136454
|
const rcAnswer = async (sessionId, requestId, decision) => await answerRcControlRequest({ credentialOf: rcTracker.credentialOf, pendingOf: (id2) => rcTracker.pendingOf(id2), completePending: rcTracker.completePending, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial }, sessionId, requestId, decision);
|
|
136455
136455
|
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto25.randomUUID };
|
|
136456
136456
|
const rcInterrupt = async (sessionId) => await interruptRcSession(rcControlRequestDeps, sessionId);
|
|
@@ -136734,8 +136734,8 @@ function registerFrontDoorCommand(program2, deps) {
|
|
|
136734
136734
|
}
|
|
136735
136735
|
|
|
136736
136736
|
// src/statusline/commands.ts
|
|
136737
|
-
var
|
|
136738
|
-
var
|
|
136737
|
+
var import_node_child_process8 = require("node:child_process");
|
|
136738
|
+
var import_node_os13 = __toESM(require("node:os"), 1);
|
|
136739
136739
|
var import_node_path56 = __toESM(require("node:path"), 1);
|
|
136740
136740
|
init_commandDeps();
|
|
136741
136741
|
init_statusline();
|
|
@@ -136750,8 +136750,8 @@ function isAntigravityPayload(payload) {
|
|
|
136750
136750
|
return typeof payload === "object" && payload !== null && "product" in payload && payload.product === "antigravity";
|
|
136751
136751
|
}
|
|
136752
136752
|
var ANTIGRAVITY_SETTINGS_SEGMENTS = [".gemini", "antigravity-cli", "settings.json"];
|
|
136753
|
-
function antigravityStacksWithDefault(
|
|
136754
|
-
const raw =
|
|
136753
|
+
function antigravityStacksWithDefault(fs30, homeDir) {
|
|
136754
|
+
const raw = fs30.readFileUtf8(import_node_path55.default.join(homeDir, ...ANTIGRAVITY_SETTINGS_SEGMENTS));
|
|
136755
136755
|
if (raw === void 0) {
|
|
136756
136756
|
return false;
|
|
136757
136757
|
}
|
|
@@ -137055,6 +137055,79 @@ function providerScopedState(snapshot, providerName, providerDisplayName) {
|
|
|
137055
137055
|
// src/statusline/commands.ts
|
|
137056
137056
|
init_read();
|
|
137057
137057
|
|
|
137058
|
+
// src/statusline/payload.ts
|
|
137059
|
+
init_zod();
|
|
137060
|
+
var number4 = external_exports.number().optional().catch(void 0);
|
|
137061
|
+
var text2 = external_exports.string().optional().catch(void 0);
|
|
137062
|
+
var ClientPayloadSchema = external_exports.looseObject({
|
|
137063
|
+
session_id: text2,
|
|
137064
|
+
transcript_path: text2,
|
|
137065
|
+
cwd: text2,
|
|
137066
|
+
workspace: external_exports.looseObject({
|
|
137067
|
+
current_dir: text2,
|
|
137068
|
+
project_dir: text2,
|
|
137069
|
+
added_dirs: external_exports.array(external_exports.string()).optional().catch(void 0),
|
|
137070
|
+
git_worktree: text2
|
|
137071
|
+
}).optional().catch(void 0),
|
|
137072
|
+
model: external_exports.looseObject({ id: text2, display_name: text2 }).optional().catch(void 0),
|
|
137073
|
+
context_window: external_exports.looseObject({
|
|
137074
|
+
context_window_size: number4,
|
|
137075
|
+
total_input_tokens: number4,
|
|
137076
|
+
total_output_tokens: number4,
|
|
137077
|
+
used_percentage: number4,
|
|
137078
|
+
remaining_percentage: number4,
|
|
137079
|
+
current_usage: external_exports.looseObject({ input_tokens: number4, output_tokens: number4, cache_creation_input_tokens: number4, cache_read_input_tokens: number4 }).optional().catch(void 0)
|
|
137080
|
+
}).optional().catch(void 0),
|
|
137081
|
+
prompt_cache: external_exports.looseObject({ hit_ratio: number4 }).optional().catch(void 0),
|
|
137082
|
+
cost: external_exports.looseObject({ total_cost_usd: number4, total_duration_ms: number4, total_api_duration_ms: number4, total_lines_added: number4, total_lines_removed: number4 }).optional().catch(void 0),
|
|
137083
|
+
rate_limits: external_exports.looseObject({
|
|
137084
|
+
five_hour: external_exports.looseObject({ used_percentage: number4, resets_at: number4 }).optional().catch(void 0),
|
|
137085
|
+
seven_day: external_exports.looseObject({ used_percentage: number4, resets_at: number4 }).optional().catch(void 0),
|
|
137086
|
+
model_scoped: external_exports.array(external_exports.looseObject({ display_name: text2, utilization: number4, resets_at: text2 })).optional().catch(void 0)
|
|
137087
|
+
}).optional().catch(void 0)
|
|
137088
|
+
}).catch({});
|
|
137089
|
+
function parseClientPayload(raw) {
|
|
137090
|
+
return ClientPayloadSchema.parse(raw);
|
|
137091
|
+
}
|
|
137092
|
+
function viewOf(payload) {
|
|
137093
|
+
return {
|
|
137094
|
+
modelDisplayName: payload.model?.display_name,
|
|
137095
|
+
contextUsedPercentage: payload.context_window?.used_percentage,
|
|
137096
|
+
contextTotalTokens: payload.context_window?.total_input_tokens,
|
|
137097
|
+
contextWindowTokens: payload.context_window?.context_window_size,
|
|
137098
|
+
cacheHitRatio: payload.prompt_cache?.hit_ratio,
|
|
137099
|
+
cacheReadTokens: payload.context_window?.current_usage?.cache_read_input_tokens,
|
|
137100
|
+
freshInputTokens: payload.context_window?.current_usage?.input_tokens
|
|
137101
|
+
};
|
|
137102
|
+
}
|
|
137103
|
+
|
|
137104
|
+
// src/statusline/ports.ts
|
|
137105
|
+
var import_node_child_process7 = require("node:child_process");
|
|
137106
|
+
var import_node_fs22 = __toESM(require("node:fs"), 1);
|
|
137107
|
+
var import_node_os12 = __toESM(require("node:os"), 1);
|
|
137108
|
+
var RUN_TIMEOUT_MS = 2e3;
|
|
137109
|
+
var RUN_MAX_BUFFER_BYTES = 1048576;
|
|
137110
|
+
function realStatuslinePorts(env) {
|
|
137111
|
+
return {
|
|
137112
|
+
env,
|
|
137113
|
+
homeDirectory: import_node_os12.default.homedir(),
|
|
137114
|
+
readText: (path66) => {
|
|
137115
|
+
try {
|
|
137116
|
+
return import_node_fs22.default.readFileSync(path66, "utf8");
|
|
137117
|
+
} catch {
|
|
137118
|
+
return void 0;
|
|
137119
|
+
}
|
|
137120
|
+
},
|
|
137121
|
+
run: (file2, args, cwd) => {
|
|
137122
|
+
try {
|
|
137123
|
+
return (0, import_node_child_process7.execFileSync)(file2, [...args], { cwd, encoding: "utf8", timeout: RUN_TIMEOUT_MS, maxBuffer: RUN_MAX_BUFFER_BYTES, stdio: ["ignore", "pipe", "ignore"] });
|
|
137124
|
+
} catch {
|
|
137125
|
+
return void 0;
|
|
137126
|
+
}
|
|
137127
|
+
}
|
|
137128
|
+
};
|
|
137129
|
+
}
|
|
137130
|
+
|
|
137058
137131
|
// src/statusline/render.ts
|
|
137059
137132
|
init_statusline();
|
|
137060
137133
|
|
|
@@ -137062,8 +137135,8 @@ init_statusline();
|
|
|
137062
137135
|
var ESCAPE_CHAR_CODE = 27;
|
|
137063
137136
|
var ESCAPE = String.fromCharCode(ESCAPE_CHAR_CODE);
|
|
137064
137137
|
var ANSI_REGEX = new RegExp(`${ESCAPE}\\[[0-9;]*[a-zA-Z]`, "g");
|
|
137065
|
-
function visibleLength(
|
|
137066
|
-
return
|
|
137138
|
+
function visibleLength(text3) {
|
|
137139
|
+
return text3.replace(ANSI_REGEX, "").length;
|
|
137067
137140
|
}
|
|
137068
137141
|
|
|
137069
137142
|
// src/statusline/barGrid.ts
|
|
@@ -137092,8 +137165,8 @@ function measureGrid(rows, separatorLength, baseBarCells) {
|
|
|
137092
137165
|
const fixed = [...prefixWidths, ...suffixWidths].reduce((total, width) => total + width, 0) + columns * (baseBarCells + BRACKET_COLUMNS);
|
|
137093
137166
|
return { rows, columns, prefixWidths, suffixWidths, baseWidth: fixed + separatorLength * (columns - 1) };
|
|
137094
137167
|
}
|
|
137095
|
-
function padTo(
|
|
137096
|
-
return
|
|
137168
|
+
function padTo(text3, width) {
|
|
137169
|
+
return text3 + " ".repeat(Math.max(0, width - visibleLength(text3)));
|
|
137097
137170
|
}
|
|
137098
137171
|
function renderGrid(grid, maxWidth, separator, baseBarCells) {
|
|
137099
137172
|
const separatorLength = visibleLength(separator);
|
|
@@ -137244,9 +137317,9 @@ function createPalette(colours, enabled) {
|
|
|
137244
137317
|
};
|
|
137245
137318
|
return {
|
|
137246
137319
|
ansi,
|
|
137247
|
-
paint: (role,
|
|
137320
|
+
paint: (role, text3) => {
|
|
137248
137321
|
const start = ansi(role);
|
|
137249
|
-
return start === "" ?
|
|
137322
|
+
return start === "" ? text3 : `${start}${text3}${RESET}`;
|
|
137250
137323
|
}
|
|
137251
137324
|
};
|
|
137252
137325
|
}
|
|
@@ -137261,8 +137334,8 @@ var TEN = 10;
|
|
|
137261
137334
|
var TWENTY = 20;
|
|
137262
137335
|
var FULL_PERCENT3 = 100;
|
|
137263
137336
|
var ONE_PERCENT = 1;
|
|
137264
|
-
function withColor(color,
|
|
137265
|
-
return color === "" ?
|
|
137337
|
+
function withColor(color, text3) {
|
|
137338
|
+
return color === "" ? text3 : `${color}${text3}${RESET}`;
|
|
137266
137339
|
}
|
|
137267
137340
|
function statusColor(fraction, isUsedMetric, style) {
|
|
137268
137341
|
const yellowAt = style.bands.warnAt / FULL_PERCENT3;
|
|
@@ -137463,7 +137536,7 @@ function justify(texts, maxWidth, separator) {
|
|
|
137463
137536
|
return texts.join(separator);
|
|
137464
137537
|
}
|
|
137465
137538
|
const separatorLength = visibleLength(separator);
|
|
137466
|
-
const total = texts.reduce((sum,
|
|
137539
|
+
const total = texts.reduce((sum, text3) => sum + visibleLength(text3), 0) + separatorLength * (texts.length - 1);
|
|
137467
137540
|
const spare = maxWidth - total;
|
|
137468
137541
|
if (spare <= 0) {
|
|
137469
137542
|
return texts.join(separator);
|
|
@@ -137472,7 +137545,7 @@ function justify(texts, maxWidth, separator) {
|
|
|
137472
137545
|
const extraPerGap = Math.floor(spare / gaps);
|
|
137473
137546
|
let remainder = spare % gaps;
|
|
137474
137547
|
const parts = [];
|
|
137475
|
-
texts.forEach((
|
|
137548
|
+
texts.forEach((text3, index) => {
|
|
137476
137549
|
if (index > 0) {
|
|
137477
137550
|
const extra = extraPerGap + (remainder > 0 ? 1 : 0);
|
|
137478
137551
|
if (remainder > 0) {
|
|
@@ -137481,7 +137554,7 @@ function justify(texts, maxWidth, separator) {
|
|
|
137481
137554
|
const left = Math.floor(extra / 2);
|
|
137482
137555
|
parts.push(`${" ".repeat(left + 1)}|${" ".repeat(extra - left + 1)}`);
|
|
137483
137556
|
}
|
|
137484
|
-
parts.push(
|
|
137557
|
+
parts.push(text3);
|
|
137485
137558
|
});
|
|
137486
137559
|
return parts.join("");
|
|
137487
137560
|
}
|
|
@@ -137490,15 +137563,15 @@ function layoutHeader(texts, maxWidth, separator) {
|
|
|
137490
137563
|
const lines = [];
|
|
137491
137564
|
let current = [];
|
|
137492
137565
|
let currentWidth = 0;
|
|
137493
|
-
for (const
|
|
137494
|
-
const width = visibleLength(
|
|
137566
|
+
for (const text3 of texts) {
|
|
137567
|
+
const width = visibleLength(text3);
|
|
137495
137568
|
const added = current.length === 0 ? width : width + separatorLength;
|
|
137496
137569
|
if (current.length > 0 && currentWidth + added > maxWidth) {
|
|
137497
137570
|
lines.push(current);
|
|
137498
|
-
current = [
|
|
137571
|
+
current = [text3];
|
|
137499
137572
|
currentWidth = width;
|
|
137500
137573
|
} else {
|
|
137501
|
-
current.push(
|
|
137574
|
+
current.push(text3);
|
|
137502
137575
|
currentWidth += added;
|
|
137503
137576
|
}
|
|
137504
137577
|
}
|
|
@@ -137511,11 +137584,20 @@ function layoutHeader(texts, maxWidth, separator) {
|
|
|
137511
137584
|
// src/statusline/render.ts
|
|
137512
137585
|
var RESERVED_COLUMNS = 4;
|
|
137513
137586
|
var SEPARATOR2 = " | ";
|
|
137514
|
-
function renderStatuslineBlock(
|
|
137515
|
-
const
|
|
137587
|
+
function renderStatuslineBlock(input2) {
|
|
137588
|
+
const { terminalWidth, settings: settings2 = STATUSLINE_DEFAULTS, elements = ELEMENTS } = input2;
|
|
137589
|
+
const context = {
|
|
137590
|
+
summary: input2.summary,
|
|
137591
|
+
view: input2.view,
|
|
137592
|
+
payload: input2.payload,
|
|
137593
|
+
nowMs: input2.nowMs,
|
|
137594
|
+
settings: settings2,
|
|
137595
|
+
palette: createPalette(settings2.colours, colourEnabled(input2.ports.env)),
|
|
137596
|
+
ports: input2.ports
|
|
137597
|
+
};
|
|
137516
137598
|
const header = settings2.layout.header.flatMap((name) => {
|
|
137517
|
-
const
|
|
137518
|
-
return
|
|
137599
|
+
const text3 = elements.header[name](context);
|
|
137600
|
+
return text3 === void 0 ? [] : context.palette.paint(HEADER_ROLES[name], text3);
|
|
137519
137601
|
});
|
|
137520
137602
|
const width = Math.max(TWENTY, terminalWidth - RESERVED_COLUMNS);
|
|
137521
137603
|
const lines = [];
|
|
@@ -137555,30 +137637,6 @@ function terminalWidthOf(payload, env) {
|
|
|
137555
137637
|
}
|
|
137556
137638
|
|
|
137557
137639
|
// src/statusline/commands.ts
|
|
137558
|
-
function payloadViewOf(payload) {
|
|
137559
|
-
const empty = { modelDisplayName: void 0, contextUsedPercentage: void 0, contextTotalTokens: void 0, contextWindowTokens: void 0, cacheHitRatio: void 0, cacheReadTokens: void 0, freshInputTokens: void 0 };
|
|
137560
|
-
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
|
137561
|
-
return empty;
|
|
137562
|
-
}
|
|
137563
|
-
const record2 = {};
|
|
137564
|
-
for (const [key, value2] of Object.entries(payload)) {
|
|
137565
|
-
record2[key] = value2;
|
|
137566
|
-
}
|
|
137567
|
-
const model = record2.model;
|
|
137568
|
-
const displayName = typeof model === "object" && model !== null && !Array.isArray(model) && "display_name" in model && typeof model.display_name === "string" ? model.display_name : void 0;
|
|
137569
|
-
const context = record2.context_window;
|
|
137570
|
-
const ctx = typeof context === "object" && context !== null && !Array.isArray(context) ? context : void 0;
|
|
137571
|
-
const used = ctx !== void 0 && "used_percentage" in ctx && typeof ctx.used_percentage === "number" ? ctx.used_percentage : void 0;
|
|
137572
|
-
const totalIn = ctx !== void 0 && "total_input_tokens" in ctx && typeof ctx.total_input_tokens === "number" ? ctx.total_input_tokens : void 0;
|
|
137573
|
-
const size = ctx !== void 0 && "context_window_size" in ctx && typeof ctx.context_window_size === "number" ? ctx.context_window_size : void 0;
|
|
137574
|
-
const current = ctx !== void 0 && "current_usage" in ctx && typeof ctx.current_usage === "object" && ctx.current_usage !== null && !Array.isArray(ctx.current_usage) ? ctx.current_usage : void 0;
|
|
137575
|
-
const cacheRead = current !== void 0 && "cache_read_input_tokens" in current && typeof current.cache_read_input_tokens === "number" ? current.cache_read_input_tokens : void 0;
|
|
137576
|
-
const fresh = current !== void 0 && "input_tokens" in current && typeof current.input_tokens === "number" ? current.input_tokens : void 0;
|
|
137577
|
-
const promptCache = record2.prompt_cache;
|
|
137578
|
-
const cache = typeof promptCache === "object" && promptCache !== null && !Array.isArray(promptCache) ? promptCache : void 0;
|
|
137579
|
-
const hitRatio = cache !== void 0 && "hit_ratio" in cache && typeof cache.hit_ratio === "number" ? cache.hit_ratio : void 0;
|
|
137580
|
-
return { modelDisplayName: displayName, contextUsedPercentage: used, contextTotalTokens: totalIn, contextWindowTokens: size, cacheHitRatio: hitRatio, cacheReadTokens: cacheRead, freshInputTokens: fresh };
|
|
137581
|
-
}
|
|
137582
137640
|
async function readAllStdin() {
|
|
137583
137641
|
return await new Promise((resolve2) => {
|
|
137584
137642
|
const chunks = [];
|
|
@@ -137620,7 +137678,7 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
137620
137678
|
} else {
|
|
137621
137679
|
const configDir = process.env.CLAUDE_CONFIG_DIR;
|
|
137622
137680
|
try {
|
|
137623
|
-
account = readAccountMetadataFile(realFarmFs, configDir === void 0 || configDir === "" ? import_node_path56.default.join(
|
|
137681
|
+
account = readAccountMetadataFile(realFarmFs, configDir === void 0 || configDir === "" ? import_node_path56.default.join(import_node_os13.default.homedir(), ".claude.json") : import_node_path56.default.join(configDir, ".claude.json"));
|
|
137624
137682
|
} catch {
|
|
137625
137683
|
account = void 0;
|
|
137626
137684
|
}
|
|
@@ -137660,7 +137718,7 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
137660
137718
|
const { payload: enriched, summary } = enrichStatuslinePayload({ payload, env: process.env, snapshot, account, providerName, nowMs, headroom, routedTarget, ...modelChoice === void 0 ? {} : { modelChoice } });
|
|
137661
137719
|
const renderer = process.env.AGENT_SHIM_STATUSLINE_CMD;
|
|
137662
137720
|
if (renderer !== void 0 && renderer !== "") {
|
|
137663
|
-
const child = (0,
|
|
137721
|
+
const child = (0, import_node_child_process8.spawn)("/bin/sh", ["-c", renderer], { stdio: ["pipe", "inherit", "inherit"] });
|
|
137664
137722
|
child.stdin.end(`${JSON.stringify(enriched)}
|
|
137665
137723
|
`);
|
|
137666
137724
|
child.on("close", (code) => {
|
|
@@ -137671,15 +137729,16 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
137671
137729
|
let stackedUnderDefault = false;
|
|
137672
137730
|
if (isAntigravityPayload(payload)) {
|
|
137673
137731
|
try {
|
|
137674
|
-
stackedUnderDefault = antigravityStacksWithDefault(realFarmFs,
|
|
137732
|
+
stackedUnderDefault = antigravityStacksWithDefault(realFarmFs, import_node_os13.default.homedir());
|
|
137675
137733
|
} catch {
|
|
137676
137734
|
stackedUnderDefault = false;
|
|
137677
137735
|
}
|
|
137678
137736
|
}
|
|
137679
|
-
const
|
|
137737
|
+
const clientPayload = parseClientPayload(payload);
|
|
137738
|
+
const view = { ...viewOf(clientPayload), ...stackedUnderDefault ? { modelDisplayName: void 0 } : {} };
|
|
137680
137739
|
const rawSettings = process.env[STATUSLINE_ENV];
|
|
137681
137740
|
const settings2 = resolveStatusline(rawSettings === void 0 || rawSettings === "" ? void 0 : statuslineSettingsFromEnv(rawSettings, STATUSLINE_ENV));
|
|
137682
|
-
console.log(renderStatuslineBlock(summary, view, terminalWidthOf(payload, process.env), nowMs, settings2));
|
|
137741
|
+
console.log(renderStatuslineBlock({ summary, view, payload: clientPayload, terminalWidth: terminalWidthOf(payload, process.env), nowMs, settings: settings2, ports: realStatuslinePorts(process.env) }));
|
|
137683
137742
|
}),
|
|
137684
137743
|
["$ agent-shim statusline # a client's statusline setting names this; it renders or delegates"]
|
|
137685
137744
|
);
|
|
@@ -147445,7 +147504,7 @@ async function serveMcp(mcp, transport, options = {}) {
|
|
|
147445
147504
|
}
|
|
147446
147505
|
|
|
147447
147506
|
// src/mcp/permissions.ts
|
|
147448
|
-
var
|
|
147507
|
+
var import_node_fs23 = __toESM(require("node:fs"), 1);
|
|
147449
147508
|
var import_node_path57 = __toESM(require("node:path"), 1);
|
|
147450
147509
|
init_zod();
|
|
147451
147510
|
init_store();
|
|
@@ -147462,15 +147521,15 @@ function readStoredMcpPermissions(paths) {
|
|
|
147462
147521
|
}
|
|
147463
147522
|
function writeStoredMcpPermissions(paths, permissions) {
|
|
147464
147523
|
writeJsonAtomic(paths.mcpPermissionsFile, { writes: permissions.writes, remoteControl: permissions.remoteControl, history: permissions.history });
|
|
147465
|
-
|
|
147524
|
+
import_node_fs23.default.chmodSync(paths.mcpPermissionsFile, OWNER_ONLY_MODE);
|
|
147466
147525
|
}
|
|
147467
147526
|
function effectiveMcpPermissions(flags, stored) {
|
|
147468
147527
|
return { writes: flags.writes || stored.writes, remoteControl: flags.remoteControl || stored.remoteControl, history: flags.history || stored.history };
|
|
147469
147528
|
}
|
|
147470
147529
|
function watchMcpPermissions(paths, onChange) {
|
|
147471
147530
|
const directory = import_node_path57.default.dirname(paths.mcpPermissionsFile);
|
|
147472
|
-
|
|
147473
|
-
const watcher =
|
|
147531
|
+
import_node_fs23.default.mkdirSync(directory, { recursive: true });
|
|
147532
|
+
const watcher = import_node_fs23.default.watch(directory, (_event, filename) => {
|
|
147474
147533
|
if (filename === null || filename === import_node_path57.default.basename(paths.mcpPermissionsFile)) {
|
|
147475
147534
|
onChange();
|
|
147476
147535
|
}
|
|
@@ -147636,9 +147695,9 @@ init_cliError();
|
|
|
147636
147695
|
init_argv();
|
|
147637
147696
|
init_legacy();
|
|
147638
147697
|
var COMPLETION_SHELLS = ["bash", "zsh", "fish"];
|
|
147639
|
-
function firstSentence(
|
|
147640
|
-
const end =
|
|
147641
|
-
return end === -1 ?
|
|
147698
|
+
function firstSentence(text3) {
|
|
147699
|
+
const end = text3.search(/\.(\s|$)/);
|
|
147700
|
+
return end === -1 ? text3 : text3.slice(0, end);
|
|
147642
147701
|
}
|
|
147643
147702
|
function collectNodes(program2) {
|
|
147644
147703
|
const help = new Help();
|
|
@@ -147659,11 +147718,11 @@ function collectNodes(program2) {
|
|
|
147659
147718
|
visit2(program2, "root");
|
|
147660
147719
|
return nodes;
|
|
147661
147720
|
}
|
|
147662
|
-
function singleQuote(
|
|
147663
|
-
return `'${
|
|
147721
|
+
function singleQuote(text3) {
|
|
147722
|
+
return `'${text3.replaceAll("'", `'\\''`)}'`;
|
|
147664
147723
|
}
|
|
147665
|
-
function fishQuote(
|
|
147666
|
-
return `'${
|
|
147724
|
+
function fishQuote(text3) {
|
|
147725
|
+
return `'${text3.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
147667
147726
|
}
|
|
147668
147727
|
function transitionArms(nodes, indent) {
|
|
147669
147728
|
return nodes.flatMap((node2) => [...node2.children].map(([name, child]) => `${indent}${singleQuote(`${node2.id}:${name}`)}) node=${singleQuote(child)} ;;`)).join("\n");
|
|
@@ -147776,7 +147835,7 @@ function registerCompletionCommand(program2) {
|
|
|
147776
147835
|
}
|
|
147777
147836
|
|
|
147778
147837
|
// src/credentialCommand.ts
|
|
147779
|
-
var
|
|
147838
|
+
var import_node_child_process9 = require("node:child_process");
|
|
147780
147839
|
init_commandDeps();
|
|
147781
147840
|
init_cliError();
|
|
147782
147841
|
init_schema();
|
|
@@ -147784,7 +147843,7 @@ init_credential();
|
|
|
147784
147843
|
init_credentialCache();
|
|
147785
147844
|
|
|
147786
147845
|
// src/identityToken.ts
|
|
147787
|
-
var
|
|
147846
|
+
var import_node_fs24 = __toESM(require("node:fs"), 1);
|
|
147788
147847
|
var import_node_path58 = __toESM(require("node:path"), 1);
|
|
147789
147848
|
init_cliError();
|
|
147790
147849
|
var TOKEN_FILE_MODE = 384;
|
|
@@ -147802,13 +147861,13 @@ function storeIdentityToken(paths, identityName, raw) {
|
|
|
147802
147861
|
throw new UsageError("That is not a claude setup-token token (expected it to start with sk-ant-oat). Run `claude setup-token` and pass its token on standard input.");
|
|
147803
147862
|
}
|
|
147804
147863
|
const dir = identityTokenDir(paths);
|
|
147805
|
-
|
|
147806
|
-
|
|
147864
|
+
import_node_fs24.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
|
|
147865
|
+
import_node_fs24.default.chmodSync(dir, TOKEN_DIR_MODE);
|
|
147807
147866
|
const target = identityTokenPath(paths, identityName);
|
|
147808
147867
|
const temp = import_node_path58.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
|
|
147809
|
-
|
|
147868
|
+
import_node_fs24.default.writeFileSync(temp, `${token}
|
|
147810
147869
|
`, { mode: TOKEN_FILE_MODE });
|
|
147811
|
-
|
|
147870
|
+
import_node_fs24.default.renameSync(temp, target);
|
|
147812
147871
|
return target;
|
|
147813
147872
|
}
|
|
147814
147873
|
|
|
@@ -147837,7 +147896,7 @@ function realCommandPorts(deps) {
|
|
|
147837
147896
|
cache: createRealCredentialCache(deps.paths.root),
|
|
147838
147897
|
platform: process.platform,
|
|
147839
147898
|
now: () => Date.now(),
|
|
147840
|
-
ssh: (host, remoteCommand, input2) => (0,
|
|
147899
|
+
ssh: (host, remoteCommand, input2) => (0, import_node_child_process9.spawnSync)("ssh", ["--", host, remoteCommand], { input: input2, stdio: ["pipe", "inherit", "inherit"] }).status
|
|
147841
147900
|
};
|
|
147842
147901
|
}
|
|
147843
147902
|
var REMOTE_ROOT_SCRIPT = 'root="${AGENT_SHIM_HOME:-${CLAUDE_USE_HOME:-}}"; if [ -z "$root" ]; then if [ ! -d "$HOME/.agent-shim" ] && [ -d "$HOME/.claude-use" ]; then root="$HOME/.claude-use"; else root="$HOME/.agent-shim"; fi; fi';
|
|
@@ -147974,10 +148033,10 @@ function registerDoctorCommand(program2, deps) {
|
|
|
147974
148033
|
}
|
|
147975
148034
|
|
|
147976
148035
|
// src/headroom/commands.ts
|
|
147977
|
-
var
|
|
148036
|
+
var import_node_fs25 = __toESM(require("node:fs"), 1);
|
|
147978
148037
|
var import_node_http5 = __toESM(require("node:http"), 1);
|
|
147979
148038
|
var import_node_path59 = __toESM(require("node:path"), 1);
|
|
147980
|
-
var
|
|
148039
|
+
var import_node_child_process10 = require("node:child_process");
|
|
147981
148040
|
init_commandDeps();
|
|
147982
148041
|
init_configProfilesStore();
|
|
147983
148042
|
init_realFrontDoorPort();
|
|
@@ -148162,7 +148221,7 @@ async function readyOverSocket(socketPath) {
|
|
|
148162
148221
|
}
|
|
148163
148222
|
var HEADROOM_TOOL_NAME = "headroom-ai";
|
|
148164
148223
|
function readInstalledHeadroomCommit() {
|
|
148165
|
-
const toolDir = (0,
|
|
148224
|
+
const toolDir = (0, import_node_child_process10.spawnSync)("uv", ["tool", "dir"], { encoding: "utf8" });
|
|
148166
148225
|
if (toolDir.status !== 0) {
|
|
148167
148226
|
return void 0;
|
|
148168
148227
|
}
|
|
@@ -148199,14 +148258,14 @@ function realSupervisorPorts(paths) {
|
|
|
148199
148258
|
readConfig: () => resolveSupervisorConfig(readGlobalConfig(paths)?.headroom ?? {}),
|
|
148200
148259
|
spawnHeadroom: (socketPath, allowlistFile, settings2) => {
|
|
148201
148260
|
const trust = resolveHeadroomTrustBundle({ caCertFile: paths.frontdoorCaCertFile, bundlesDir: paths.frontdoorCaBundlesDir, inherited: process.env[HEADROOM_CA_BUNDLE], fs: realTrustBundleFs });
|
|
148202
|
-
|
|
148261
|
+
import_node_fs25.default.mkdirSync(paths.logsDir, { recursive: true });
|
|
148203
148262
|
if (trust?.warning !== void 0) {
|
|
148204
|
-
|
|
148263
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${trust.warning}
|
|
148205
148264
|
`);
|
|
148206
148265
|
}
|
|
148207
|
-
const logFd =
|
|
148266
|
+
const logFd = import_node_fs25.default.openSync(paths.headroomLogPath, "a");
|
|
148208
148267
|
try {
|
|
148209
|
-
const child = (0,
|
|
148268
|
+
const child = (0, import_node_child_process10.spawn)("headroom", headroomProxyArgs(socketPath, allowlistFile, settings2), {
|
|
148210
148269
|
detached: true,
|
|
148211
148270
|
stdio: ["ignore", logFd, logFd],
|
|
148212
148271
|
env: headroomSpawnEnv(process.env, settings2, trust?.path)
|
|
@@ -148219,12 +148278,12 @@ function realSupervisorPorts(paths) {
|
|
|
148219
148278
|
child.once("exit", (code, signal) => {
|
|
148220
148279
|
ownedHeadroom.delete(pid);
|
|
148221
148280
|
exitedHeadroom.add(pid);
|
|
148222
|
-
|
|
148281
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: headroom exited (${signal ?? `code ${String(code)}`})
|
|
148223
148282
|
`);
|
|
148224
148283
|
});
|
|
148225
148284
|
return pid;
|
|
148226
148285
|
} finally {
|
|
148227
|
-
|
|
148286
|
+
import_node_fs25.default.closeSync(logFd);
|
|
148228
148287
|
}
|
|
148229
148288
|
},
|
|
148230
148289
|
stopProcess: (pid) => {
|
|
@@ -148237,7 +148296,7 @@ function realSupervisorPorts(paths) {
|
|
|
148237
148296
|
now: () => Date.now()
|
|
148238
148297
|
});
|
|
148239
148298
|
if (outcome === "still-running") {
|
|
148240
|
-
|
|
148299
|
+
import_node_fs25.default.appendFileSync(
|
|
148241
148300
|
paths.headroomLogPath,
|
|
148242
148301
|
`${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: pid ${String(pid)} survived SIGKILL within its grace; it is stuck uninterruptibly
|
|
148243
148302
|
`
|
|
@@ -148246,7 +148305,7 @@ function realSupervisorPorts(paths) {
|
|
|
148246
148305
|
},
|
|
148247
148306
|
ready: readyOverSocket,
|
|
148248
148307
|
install: (spec) => {
|
|
148249
|
-
const result = (0,
|
|
148308
|
+
const result = (0, import_node_child_process10.spawnSync)("uv", ["tool", "install", spec], { encoding: "utf8", timeout: HEADROOM_INSTALL_TIMEOUT_MS });
|
|
148250
148309
|
if (result.error !== void 0) {
|
|
148251
148310
|
const timedOut = "code" in result.error && result.error.code === "ETIMEDOUT";
|
|
148252
148311
|
return {
|
|
@@ -148255,21 +148314,21 @@ function realSupervisorPorts(paths) {
|
|
|
148255
148314
|
};
|
|
148256
148315
|
}
|
|
148257
148316
|
if (result.stdout !== "") {
|
|
148258
|
-
|
|
148317
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, result.stdout);
|
|
148259
148318
|
}
|
|
148260
148319
|
if (result.stderr !== "") {
|
|
148261
|
-
|
|
148320
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, result.stderr);
|
|
148262
148321
|
}
|
|
148263
148322
|
return result.status === 0 ? { ok: true } : { ok: false, error: `uv tool install exited ${String(result.status)}` };
|
|
148264
148323
|
},
|
|
148265
148324
|
headroomVersion: () => {
|
|
148266
|
-
const result = (0,
|
|
148325
|
+
const result = (0, import_node_child_process10.spawnSync)("headroom", ["--version"], { encoding: "utf8" });
|
|
148267
148326
|
return result.status === 0 ? result.stdout.trim() : void 0;
|
|
148268
148327
|
},
|
|
148269
148328
|
installedCommit: readInstalledHeadroomCommit,
|
|
148270
148329
|
log: (line) => {
|
|
148271
|
-
|
|
148272
|
-
|
|
148330
|
+
import_node_fs25.default.mkdirSync(paths.logsDir, { recursive: true });
|
|
148331
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
148273
148332
|
`);
|
|
148274
148333
|
}
|
|
148275
148334
|
};
|
|
@@ -148402,9 +148461,9 @@ init_providersStore();
|
|
|
148402
148461
|
init_realPorts();
|
|
148403
148462
|
var realCatalogueFetch = async (url2, headers, timeoutMs) => {
|
|
148404
148463
|
const response = await fetch(url2, { headers: { ...headers }, signal: AbortSignal.timeout(timeoutMs) });
|
|
148405
|
-
const
|
|
148464
|
+
const text3 = await response.text();
|
|
148406
148465
|
try {
|
|
148407
|
-
const body = JSON.parse(
|
|
148466
|
+
const body = JSON.parse(text3);
|
|
148408
148467
|
return { status: response.status, body };
|
|
148409
148468
|
} catch {
|
|
148410
148469
|
return { status: response.status, body: void 0 };
|
|
@@ -148776,12 +148835,12 @@ init_translate();
|
|
|
148776
148835
|
init_schema();
|
|
148777
148836
|
init_cliError();
|
|
148778
148837
|
init_providerCatalogue();
|
|
148779
|
-
var
|
|
148838
|
+
var import_node_fs27 = __toESM(require("node:fs"), 1);
|
|
148780
148839
|
init_credential();
|
|
148781
148840
|
init_providerAliases();
|
|
148782
148841
|
|
|
148783
148842
|
// src/providerRename.ts
|
|
148784
|
-
var
|
|
148843
|
+
var import_node_fs26 = __toESM(require("node:fs"), 1);
|
|
148785
148844
|
var import_node_path62 = __toESM(require("node:path"), 1);
|
|
148786
148845
|
init_schema();
|
|
148787
148846
|
init_store();
|
|
@@ -148847,7 +148906,7 @@ function renameProvider(paths, from, to2, ports) {
|
|
|
148847
148906
|
const previousAliases = readProviderAliases(paths);
|
|
148848
148907
|
writeProviderAliases(paths, aliasesAfterRename(previousAliases, from, to2));
|
|
148849
148908
|
try {
|
|
148850
|
-
|
|
148909
|
+
import_node_fs26.default.renameSync(providerJsonPath(paths, from), providerJsonPath(paths, to2));
|
|
148851
148910
|
} catch (error63) {
|
|
148852
148911
|
writeProviderAliases(paths, previousAliases);
|
|
148853
148912
|
throw error63;
|
|
@@ -148867,8 +148926,8 @@ function moveState(paths, from, to2, ports) {
|
|
|
148867
148926
|
`);
|
|
148868
148927
|
moved.push(`usage ${snapshot.identity}`);
|
|
148869
148928
|
}
|
|
148870
|
-
if (
|
|
148871
|
-
|
|
148929
|
+
if (import_node_fs26.default.existsSync(catalogueCachePath(paths, from))) {
|
|
148930
|
+
import_node_fs26.default.renameSync(catalogueCachePath(paths, from), catalogueCachePath(paths, to2));
|
|
148872
148931
|
moved.push("catalogue");
|
|
148873
148932
|
}
|
|
148874
148933
|
const renamed = readProvider(paths, to2);
|
|
@@ -149199,7 +149258,7 @@ function registerProviderCommand(program2, deps) {
|
|
|
149199
149258
|
throw new UsageError(`Provider "${name}" has no catalogue setting. Set one with \`agent-shim provider set ${name} --catalogue-tier <tier>\`.`);
|
|
149200
149259
|
}
|
|
149201
149260
|
const catalogueSetting = found.catalogue;
|
|
149202
|
-
const cache = options.refresh === true ? await refreshCatalogueForReal(paths, name, process.env) : parseCatalogueCache(
|
|
149261
|
+
const cache = options.refresh === true ? await refreshCatalogueForReal(paths, name, process.env) : parseCatalogueCache(import_node_fs27.default.existsSync(catalogueCachePath(paths, name)) ? import_node_fs27.default.readFileSync(catalogueCachePath(paths, name), "utf8") : void 0);
|
|
149203
149262
|
if (cache === void 0) {
|
|
149204
149263
|
throw new UsageError(`No catalogue has been fetched for "${name}" yet: the front door fetches it shortly after it starts, or run \`agent-shim provider models ${name} --refresh\`.`);
|
|
149205
149264
|
}
|
|
@@ -149743,14 +149802,14 @@ function requireIdentity(paths, name) {
|
|
|
149743
149802
|
throw new IdentityNotFoundError(name);
|
|
149744
149803
|
}
|
|
149745
149804
|
}
|
|
149746
|
-
function collectUsageReport(
|
|
149805
|
+
function collectUsageReport(fs30, paths, filters) {
|
|
149747
149806
|
const { identity, provider, sinceMs } = filters;
|
|
149748
149807
|
if (identity !== void 0) {
|
|
149749
149808
|
requireIdentity(paths, identity);
|
|
149750
149809
|
}
|
|
149751
|
-
const log = readUsageLog(
|
|
149810
|
+
const log = readUsageLog(fs30, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
|
|
149752
149811
|
const records = log.records.filter((record2) => (identity === void 0 || record2.identity === identity) && (provider === void 0 || record2.provider === provider));
|
|
149753
|
-
const snapshots = (identity === void 0 ? listUsageSnapshots(
|
|
149812
|
+
const snapshots = (identity === void 0 ? listUsageSnapshots(fs30, paths.usageSnapshotsDir) : [readUsageSnapshot(fs30, paths.usageSnapshotsDir, identity)].flatMap((snapshot) => snapshot === void 0 ? [] : [snapshot])).map((snapshot) => provider === void 0 ? snapshot : { ...snapshot, providers: Object.fromEntries(Object.entries(snapshot.providers).filter(([name]) => name === provider)) }).filter((snapshot) => Object.keys(snapshot.providers).length > 0);
|
|
149754
149813
|
return {
|
|
149755
149814
|
since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
|
|
149756
149815
|
logDir: paths.usageLogDir,
|
|
@@ -149857,16 +149916,16 @@ function formatUsageReport(report) {
|
|
|
149857
149916
|
}
|
|
149858
149917
|
return lines;
|
|
149859
149918
|
}
|
|
149860
|
-
function collectAccounts(
|
|
149919
|
+
function collectAccounts(fs30, paths, identity, probe) {
|
|
149861
149920
|
if (identity !== void 0) {
|
|
149862
149921
|
requireIdentity(paths, identity);
|
|
149863
149922
|
}
|
|
149864
149923
|
const names = identity === void 0 ? listIdentities(paths).map((entry) => entry.name) : [identity];
|
|
149865
149924
|
return names.map((name) => ({
|
|
149866
149925
|
identity: name,
|
|
149867
|
-
account: readAccountMetadata(
|
|
149868
|
-
signIn: identitySignIn(
|
|
149869
|
-
usage: readUsageSnapshot(
|
|
149926
|
+
account: readAccountMetadata(fs30, paths.identitiesDir, name),
|
|
149927
|
+
signIn: identitySignIn(fs30, probe, { farmRoot: import_node_path63.default.join(paths.identitiesDir, name), hasCredentialBlock: readIdentity(paths, name)?.credential !== void 0 }),
|
|
149928
|
+
usage: readUsageSnapshot(fs30, paths.usageSnapshotsDir, name)
|
|
149870
149929
|
}));
|
|
149871
149930
|
}
|
|
149872
149931
|
function formatAccounts(views) {
|
|
@@ -150202,8 +150261,8 @@ function createRealCompactor(params) {
|
|
|
150202
150261
|
sizes = boundarySizes(message);
|
|
150203
150262
|
}
|
|
150204
150263
|
if (message.type === "result") {
|
|
150205
|
-
const
|
|
150206
|
-
return sizes === void 0 ? { kind: "unchanged", reason:
|
|
150264
|
+
const text3 = successfulResult(message);
|
|
150265
|
+
return sizes === void 0 ? { kind: "unchanged", reason: text3 === "" ? "nothing was compacted" : text3 } : { kind: "compacted", ...sizes };
|
|
150207
150266
|
}
|
|
150208
150267
|
}
|
|
150209
150268
|
throw new Error("the compaction ended without a result");
|
|
@@ -150216,15 +150275,15 @@ function createRealCompactor(params) {
|
|
|
150216
150275
|
// src/supervise/compactionDeps.ts
|
|
150217
150276
|
var COMPACT_SLOT_STALE_MS = COMPACT_TIMEOUT_MS * 2;
|
|
150218
150277
|
function createCompactionDeps(wiring) {
|
|
150219
|
-
const { paths, fs:
|
|
150278
|
+
const { paths, fs: fs30, pool } = wiring;
|
|
150220
150279
|
return {
|
|
150221
150280
|
shouldCompact: (identity, sessionId) => {
|
|
150222
150281
|
const nowMs = wiring.now();
|
|
150223
|
-
const sessions = liveSupervised(
|
|
150282
|
+
const sessions = liveSupervised(fs30, paths, pool, wiring.isRunning).filter((session) => session.identity === identity).map((session) => ({ sessionId: session.sessionId, state: readSessionState(fs30, paths, pool, session.sessionId) }));
|
|
150224
150283
|
return decideCompaction({
|
|
150225
150284
|
atUtilisation: wiring.policy.compactAtUtilisation,
|
|
150226
|
-
snapshot: readUsageSnapshot(
|
|
150227
|
-
records: () => readUsageLog(
|
|
150285
|
+
snapshot: readUsageSnapshot(fs30, paths.usageSnapshotsDir, identity),
|
|
150286
|
+
records: () => readUsageLog(fs30, paths.usageLogDir, { sinceMs: nowMs - FIVE_HOUR_WINDOW_MS }).records.filter((record2) => record2.identity === identity),
|
|
150228
150287
|
sessions,
|
|
150229
150288
|
sessionId,
|
|
150230
150289
|
nowMs
|
|
@@ -150232,7 +150291,7 @@ function createCompactionDeps(wiring) {
|
|
|
150232
150291
|
},
|
|
150233
150292
|
acquire: (identity) => {
|
|
150234
150293
|
try {
|
|
150235
|
-
const lock = acquireIdentityLock({ identity: `compact-${identity}`, dir: superviseDirOf(paths, pool), fs:
|
|
150294
|
+
const lock = acquireIdentityLock({ identity: `compact-${identity}`, dir: superviseDirOf(paths, pool), fs: fs30, nowMs: wiring.now, pid: wiring.pid, isRunning: wiring.isRunning, sleep: wiring.sleep, maxAttempts: 1, staleAfterMs: COMPACT_SLOT_STALE_MS });
|
|
150236
150295
|
return { release: lock.release };
|
|
150237
150296
|
} catch (error63) {
|
|
150238
150297
|
if (error63 instanceof IdentityLockBusyError) {
|
|
@@ -150243,8 +150302,8 @@ function createCompactionDeps(wiring) {
|
|
|
150243
150302
|
},
|
|
150244
150303
|
compact: wiring.compact,
|
|
150245
150304
|
markCompacted: (sessionId, compacted) => {
|
|
150246
|
-
const previous = readSessionState(
|
|
150247
|
-
writeSessionState(
|
|
150305
|
+
const previous = readSessionState(fs30, paths, pool, sessionId);
|
|
150306
|
+
writeSessionState(fs30, paths, pool, sessionId, {
|
|
150248
150307
|
mark: previous?.mark ?? "idle",
|
|
150249
150308
|
...previous?.contextTokens === void 0 ? {} : { contextTokens: previous.contextTokens },
|
|
150250
150309
|
...compacted ? { compacted: true } : {},
|
|
@@ -150256,12 +150315,12 @@ function createCompactionDeps(wiring) {
|
|
|
150256
150315
|
|
|
150257
150316
|
// src/supervise/limit.ts
|
|
150258
150317
|
init_read();
|
|
150259
|
-
function quotaHitOf(
|
|
150260
|
-
const reason = refusalReason(identity, readUsageSnapshot(
|
|
150318
|
+
function quotaHitOf(fs30, paths, identity, sessionId, sinceMs, nowMs) {
|
|
150319
|
+
const reason = refusalReason(identity, readUsageSnapshot(fs30, paths.usageSnapshotsDir, identity), nowMs);
|
|
150261
150320
|
if (reason === void 0) {
|
|
150262
150321
|
return void 0;
|
|
150263
150322
|
}
|
|
150264
|
-
const { records } = readUsageLog(
|
|
150323
|
+
const { records } = readUsageLog(fs30, paths.usageLogDir, { sinceMs });
|
|
150265
150324
|
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
150266
150325
|
const record2 = records[index];
|
|
150267
150326
|
if (record2?.sessionId === sessionId && record2.identity === identity && record2.limit?.kind === "quota-exhausted") {
|
|
@@ -150380,12 +150439,12 @@ function createIdentityMover(deps) {
|
|
|
150380
150439
|
}
|
|
150381
150440
|
|
|
150382
150441
|
// src/supervise/realPorts.ts
|
|
150383
|
-
var
|
|
150384
|
-
var
|
|
150442
|
+
var import_node_child_process11 = require("node:child_process");
|
|
150443
|
+
var import_node_fs28 = __toESM(require("node:fs"), 1);
|
|
150385
150444
|
init_realPorts();
|
|
150386
150445
|
var realSupervisedSpawnPort = {
|
|
150387
150446
|
spawn(command, args, options) {
|
|
150388
|
-
const child = (0,
|
|
150447
|
+
const child = (0, import_node_child_process11.spawn)(command, [...args], { stdio: options.stdio, env: { ...options.env } });
|
|
150389
150448
|
const exit = new Promise((resolve2) => {
|
|
150390
150449
|
child.once("error", (error63) => {
|
|
150391
150450
|
resolve2({ status: null, signal: null, error: error63 });
|
|
@@ -150427,7 +150486,7 @@ var realTimerPort = {
|
|
|
150427
150486
|
function realWatchDirectory(directory, accepts, what, log) {
|
|
150428
150487
|
return (onChange) => {
|
|
150429
150488
|
realFarmFs.mkdirPrivate(directory);
|
|
150430
|
-
const watcher =
|
|
150489
|
+
const watcher = import_node_fs28.default.watch(directory, { persistent: false }, (_event, filename) => {
|
|
150431
150490
|
if (filename === null || accepts(filename)) {
|
|
150432
150491
|
onChange();
|
|
150433
150492
|
}
|
|
@@ -150447,7 +150506,7 @@ function resetTerminal() {
|
|
|
150447
150506
|
return;
|
|
150448
150507
|
}
|
|
150449
150508
|
process.stdout.write(TERMINAL_RESET);
|
|
150450
|
-
(0,
|
|
150509
|
+
(0, import_node_child_process11.spawnSync)("stty", ["sane"], { stdio: ["inherit", "ignore", "ignore"] });
|
|
150451
150510
|
}
|
|
150452
150511
|
|
|
150453
150512
|
// src/supervise/supervise.ts
|