agent-shim 11.51.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 +792 -602
- package/dist/index.cjs +60 -6
- package/dist/index.mjs +60 -6
- package/dist/types/index.d.ts +3636 -28
- 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,6 +25040,9 @@ 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(text3) {
|
|
25044
|
+
return [...GRAPHEMES.segment(text3)].length === 1 && !/[\p{C}\p{Z}]/u.test(text3);
|
|
25045
|
+
}
|
|
25043
25046
|
function isPlainObject2(value2) {
|
|
25044
25047
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
25045
25048
|
}
|
|
@@ -25060,17 +25063,41 @@ function resolveStatusline(settings2) {
|
|
|
25060
25063
|
}
|
|
25061
25064
|
return resolved;
|
|
25062
25065
|
}
|
|
25063
|
-
var STATUSLINE_HEADER_SEGMENTS, STATUSLINE_ROWS, MAX_PERCENT, MAX_STATUSLINE_LABEL_CHARS, MAX_BAR_CELLS, LABEL_RE2, labelText, wholePercent, SHAPES, StatuslineSchema, ResolvedStatuslineSchema, STATUSLINE_DEFAULTS, STATUSLINE_ENV;
|
|
25066
|
+
var STATUSLINE_HEADER_SEGMENTS, STATUSLINE_ROWS, STATUSLINE_COLOUR_NAMES, MAX_PERCENT, MAX_STATUSLINE_PALETTE_INDEX, MAX_STATUSLINE_LABEL_CHARS, MAX_BAR_CELLS, LABEL_RE2, colourValue, GRAPHEMES, barCharacter, labelText, wholePercent, SHAPES, StatuslineSchema, ResolvedStatuslineSchema, STATUSLINE_DEFAULTS, STATUSLINE_ENV;
|
|
25064
25067
|
var init_statusline = __esm({
|
|
25065
25068
|
"src/config/statusline.ts"() {
|
|
25066
25069
|
"use strict";
|
|
25067
25070
|
init_zod();
|
|
25068
25071
|
STATUSLINE_HEADER_SEGMENTS = ["model", "provider", "route", "account", "identity", "headroom"];
|
|
25069
25072
|
STATUSLINE_ROWS = ["context", "quota"];
|
|
25073
|
+
STATUSLINE_COLOUR_NAMES = [
|
|
25074
|
+
"default",
|
|
25075
|
+
"dim",
|
|
25076
|
+
"black",
|
|
25077
|
+
"red",
|
|
25078
|
+
"green",
|
|
25079
|
+
"yellow",
|
|
25080
|
+
"blue",
|
|
25081
|
+
"magenta",
|
|
25082
|
+
"cyan",
|
|
25083
|
+
"white",
|
|
25084
|
+
"brightBlack",
|
|
25085
|
+
"brightRed",
|
|
25086
|
+
"brightGreen",
|
|
25087
|
+
"brightYellow",
|
|
25088
|
+
"brightBlue",
|
|
25089
|
+
"brightMagenta",
|
|
25090
|
+
"brightCyan",
|
|
25091
|
+
"brightWhite"
|
|
25092
|
+
];
|
|
25070
25093
|
MAX_PERCENT = 100;
|
|
25094
|
+
MAX_STATUSLINE_PALETTE_INDEX = 255;
|
|
25071
25095
|
MAX_STATUSLINE_LABEL_CHARS = 12;
|
|
25072
25096
|
MAX_BAR_CELLS = 40;
|
|
25073
25097
|
LABEL_RE2 = /^[^\p{C}\p{Z}]+(?: [^\p{C}\p{Z}]+)*$/u;
|
|
25098
|
+
colourValue = external_exports.union([external_exports.enum(STATUSLINE_COLOUR_NAMES), external_exports.number().int().min(0).max(MAX_STATUSLINE_PALETTE_INDEX), external_exports.string().regex(/^#[0-9a-fA-F]{6}$/, "must be a colour name, a palette index from 0 to 255 or #rrggbb")]);
|
|
25099
|
+
GRAPHEMES = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
25100
|
+
barCharacter = external_exports.string().refine(isSingleVisibleGrapheme, "must be a single visible character");
|
|
25074
25101
|
labelText = external_exports.string().max(MAX_STATUSLINE_LABEL_CHARS).regex(LABEL_RE2, "must be visible text without control characters");
|
|
25075
25102
|
wholePercent = external_exports.number().int().min(1).max(MAX_PERCENT);
|
|
25076
25103
|
SHAPES = {
|
|
@@ -25087,26 +25114,50 @@ var init_statusline = __esm({
|
|
|
25087
25114
|
sevenDay: labelText.describe("The name of the weekly subscription window.")
|
|
25088
25115
|
},
|
|
25089
25116
|
bar: {
|
|
25090
|
-
width: external_exports.number().int().min(1).max(MAX_BAR_CELLS).describe("A bar's width in cells before the line's spare width is shared out among the bars.")
|
|
25117
|
+
width: external_exports.number().int().min(1).max(MAX_BAR_CELLS).describe("A bar's width in cells before the line's spare width is shared out among the bars."),
|
|
25118
|
+
filled: barCharacter.describe("The character that draws the used part of a bar."),
|
|
25119
|
+
empty: barCharacter.describe("The character that draws the unused part of a bar.")
|
|
25120
|
+
},
|
|
25121
|
+
colours: {
|
|
25122
|
+
context: colourValue.describe("The colour of the context bar and its figures below the warning threshold."),
|
|
25123
|
+
usage: colourValue.describe("The colour of the quota bars and their figures below the warning threshold."),
|
|
25124
|
+
warning: colourValue.describe("The colour of the context bar at or above bands.warnAt, and of a cache hit share that is middling."),
|
|
25125
|
+
usageWarning: colourValue.describe("The colour of a quota bar at or above bands.warnAt."),
|
|
25126
|
+
critical: colourValue.describe("The colour of a bar at or above bands.criticalAt, and of a cache hit share that is nearly nothing."),
|
|
25127
|
+
model: colourValue.describe("The colour of the model and provider segments."),
|
|
25128
|
+
label: colourValue.describe("The colour of labels and secondary text: row labels, and the route, account, identity and headroom segments."),
|
|
25129
|
+
empty: colourValue.describe("The colour of the unused part of a bar.")
|
|
25091
25130
|
}
|
|
25092
25131
|
};
|
|
25093
25132
|
StatuslineSchema = external_exports.strictObject({
|
|
25094
25133
|
layout: external_exports.strictObject(SHAPES.layout).partial().optional(),
|
|
25095
25134
|
bands: external_exports.strictObject(SHAPES.bands).partial().optional(),
|
|
25096
25135
|
labels: external_exports.strictObject(SHAPES.labels).partial().optional(),
|
|
25097
|
-
bar: external_exports.strictObject(SHAPES.bar).partial().optional()
|
|
25136
|
+
bar: external_exports.strictObject(SHAPES.bar).partial().optional(),
|
|
25137
|
+
colours: external_exports.strictObject(SHAPES.colours).partial().optional()
|
|
25098
25138
|
});
|
|
25099
25139
|
ResolvedStatuslineSchema = external_exports.strictObject({
|
|
25100
25140
|
layout: external_exports.strictObject(SHAPES.layout),
|
|
25101
25141
|
bands: external_exports.strictObject(SHAPES.bands),
|
|
25102
25142
|
labels: external_exports.strictObject(SHAPES.labels),
|
|
25103
|
-
bar: external_exports.strictObject(SHAPES.bar)
|
|
25143
|
+
bar: external_exports.strictObject(SHAPES.bar),
|
|
25144
|
+
colours: external_exports.strictObject(SHAPES.colours)
|
|
25104
25145
|
});
|
|
25105
25146
|
STATUSLINE_DEFAULTS = {
|
|
25106
25147
|
layout: { header: [...STATUSLINE_HEADER_SEGMENTS], rows: [...STATUSLINE_ROWS] },
|
|
25107
25148
|
bands: { warnAt: 70, criticalAt: 90 },
|
|
25108
25149
|
labels: { fiveHour: "5h", sevenDay: "Wk" },
|
|
25109
|
-
bar: { width: 10 }
|
|
25150
|
+
bar: { width: 10, filled: "\u2588", empty: "\u2591" },
|
|
25151
|
+
colours: {
|
|
25152
|
+
context: "green",
|
|
25153
|
+
usage: "green",
|
|
25154
|
+
warning: "yellow",
|
|
25155
|
+
usageWarning: "yellow",
|
|
25156
|
+
critical: "red",
|
|
25157
|
+
model: "default",
|
|
25158
|
+
label: "default",
|
|
25159
|
+
empty: "brightBlack"
|
|
25160
|
+
}
|
|
25110
25161
|
};
|
|
25111
25162
|
STATUSLINE_ENV = "AGENT_SHIM_STATUSLINE";
|
|
25112
25163
|
}
|
|
@@ -27569,10 +27620,10 @@ var init_schema = __esm({
|
|
|
27569
27620
|
});
|
|
27570
27621
|
|
|
27571
27622
|
// src/frontdoor/state.ts
|
|
27572
|
-
function readFrontDoorState(
|
|
27623
|
+
function readFrontDoorState(fs30, stateFile) {
|
|
27573
27624
|
let raw;
|
|
27574
27625
|
try {
|
|
27575
|
-
raw =
|
|
27626
|
+
raw = fs30.readFileUtf8(stateFile);
|
|
27576
27627
|
} catch {
|
|
27577
27628
|
return void 0;
|
|
27578
27629
|
}
|
|
@@ -27586,9 +27637,9 @@ function readFrontDoorState(fs29, stateFile) {
|
|
|
27586
27637
|
return void 0;
|
|
27587
27638
|
}
|
|
27588
27639
|
}
|
|
27589
|
-
function writeFrontDoorState(
|
|
27590
|
-
|
|
27591
|
-
|
|
27640
|
+
function writeFrontDoorState(fs30, stateFile, state) {
|
|
27641
|
+
fs30.mkdirp(import_node_path5.default.dirname(stateFile));
|
|
27642
|
+
fs30.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
27592
27643
|
`);
|
|
27593
27644
|
}
|
|
27594
27645
|
function directOrigin(port) {
|
|
@@ -27598,37 +27649,37 @@ function frontDoorOrigin(state) {
|
|
|
27598
27649
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
27599
27650
|
return port === void 0 ? void 0 : directOrigin(port);
|
|
27600
27651
|
}
|
|
27601
|
-
function writeFrontDoorDirectRecord(
|
|
27602
|
-
|
|
27603
|
-
|
|
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 })}
|
|
27604
27655
|
`);
|
|
27605
27656
|
}
|
|
27606
|
-
function removeFrontDoorDirectRecord(
|
|
27607
|
-
|
|
27657
|
+
function removeFrontDoorDirectRecord(fs30, recordsDir, pid) {
|
|
27658
|
+
fs30.removeRecursive(import_node_path5.default.join(recordsDir, `${String(pid)}.json`));
|
|
27608
27659
|
}
|
|
27609
|
-
function markFrontDoorDraining(
|
|
27610
|
-
|
|
27611
|
-
|
|
27660
|
+
function markFrontDoorDraining(fs30, markersDir, pid) {
|
|
27661
|
+
fs30.mkdirp(markersDir);
|
|
27662
|
+
fs30.writeFilePrivate(import_node_path5.default.join(markersDir, String(pid)), "\n");
|
|
27612
27663
|
}
|
|
27613
|
-
function unmarkFrontDoorDraining(
|
|
27614
|
-
|
|
27664
|
+
function unmarkFrontDoorDraining(fs30, markersDir, pid) {
|
|
27665
|
+
fs30.removeRecursive(import_node_path5.default.join(markersDir, String(pid)));
|
|
27615
27666
|
}
|
|
27616
|
-
function listDrainingFrontDoors(
|
|
27617
|
-
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);
|
|
27618
27669
|
}
|
|
27619
27670
|
function recordPid(file2) {
|
|
27620
27671
|
const pidText = /^([1-9]\d*)\.json$/.exec(file2)?.[1];
|
|
27621
27672
|
const pid = pidText === void 0 ? void 0 : Number(pidText);
|
|
27622
27673
|
return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
|
|
27623
27674
|
}
|
|
27624
|
-
function readDirectRecordEntry(
|
|
27675
|
+
function readDirectRecordEntry(fs30, recordsDir, file2) {
|
|
27625
27676
|
const pid = recordPid(file2);
|
|
27626
27677
|
if (pid === void 0) {
|
|
27627
27678
|
return void 0;
|
|
27628
27679
|
}
|
|
27629
27680
|
let raw;
|
|
27630
27681
|
try {
|
|
27631
|
-
raw =
|
|
27682
|
+
raw = fs30.readFileUtf8(import_node_path5.default.join(recordsDir, file2));
|
|
27632
27683
|
} catch {
|
|
27633
27684
|
return void 0;
|
|
27634
27685
|
}
|
|
@@ -27642,47 +27693,47 @@ function readDirectRecordEntry(fs29, recordsDir, file2) {
|
|
|
27642
27693
|
return { malformed: true };
|
|
27643
27694
|
}
|
|
27644
27695
|
}
|
|
27645
|
-
function listFrontDoorDirectRecords(
|
|
27646
|
-
return
|
|
27647
|
-
const entry = readDirectRecordEntry(
|
|
27696
|
+
function listFrontDoorDirectRecords(fs30, recordsDir) {
|
|
27697
|
+
return fs30.readdir(recordsDir).flatMap((file2) => {
|
|
27698
|
+
const entry = readDirectRecordEntry(fs30, recordsDir, file2);
|
|
27648
27699
|
return entry?.record === void 0 ? [] : [entry.record];
|
|
27649
27700
|
}).sort((a10, b) => a10.pid - b.pid);
|
|
27650
27701
|
}
|
|
27651
|
-
function pruneMalformedFrontDoorDirectFiles(
|
|
27652
|
-
for (const file2 of
|
|
27702
|
+
function pruneMalformedFrontDoorDirectFiles(fs30, recordsDir, isRunning) {
|
|
27703
|
+
for (const file2 of fs30.readdir(recordsDir)) {
|
|
27653
27704
|
const writer = RECORD_TEMPORARY_FILE.exec(file2)?.[1];
|
|
27654
27705
|
const stale = writer !== void 0 && !isRunning(Number(writer));
|
|
27655
|
-
if (stale || readDirectRecordEntry(
|
|
27656
|
-
|
|
27706
|
+
if (stale || readDirectRecordEntry(fs30, recordsDir, file2)?.malformed === true) {
|
|
27707
|
+
fs30.removeRecursive(import_node_path5.default.join(recordsDir, file2));
|
|
27657
27708
|
}
|
|
27658
27709
|
}
|
|
27659
27710
|
}
|
|
27660
27711
|
function liveFrontDoorDirectRecords(records, liveness) {
|
|
27661
27712
|
return records.filter((record2) => liveness.doors.has(record2.pid) || liveness.unknown.has(record2.pid));
|
|
27662
27713
|
}
|
|
27663
|
-
function pruneDeadFrontDoorDirectRecords(
|
|
27714
|
+
function pruneDeadFrontDoorDirectRecords(fs30, recordsDir, records, liveness) {
|
|
27664
27715
|
for (const record2 of records) {
|
|
27665
27716
|
if (!liveness.doors.has(record2.pid) && !liveness.unknown.has(record2.pid)) {
|
|
27666
|
-
removeFrontDoorDirectRecord(
|
|
27717
|
+
removeFrontDoorDirectRecord(fs30, recordsDir, record2.pid);
|
|
27667
27718
|
}
|
|
27668
27719
|
}
|
|
27669
27720
|
}
|
|
27670
27721
|
function recordOf(details) {
|
|
27671
27722
|
return details === void 0 ? {} : { sessionId: details.sessionId, ...details.models === void 0 ? {} : { models: details.models } };
|
|
27672
27723
|
}
|
|
27673
|
-
function writeFrontDoorSession(
|
|
27674
|
-
|
|
27675
|
-
|
|
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)}
|
|
27676
27727
|
`);
|
|
27677
27728
|
}
|
|
27678
|
-
function listFrontDoorSessions(
|
|
27729
|
+
function listFrontDoorSessions(fs30, sessionsDir) {
|
|
27679
27730
|
const sessions = [];
|
|
27680
|
-
for (const name of
|
|
27731
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27681
27732
|
if (!name.endsWith(".json")) {
|
|
27682
27733
|
continue;
|
|
27683
27734
|
}
|
|
27684
27735
|
try {
|
|
27685
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
27736
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs30.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
|
|
27686
27737
|
if (parsed.success) {
|
|
27687
27738
|
sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt, ...parsed.data.supervisorPid === void 0 ? {} : { supervisorPid: parsed.data.supervisorPid } });
|
|
27688
27739
|
}
|
|
@@ -27692,27 +27743,27 @@ function listFrontDoorSessions(fs29, sessionsDir) {
|
|
|
27692
27743
|
}
|
|
27693
27744
|
return sessions.sort((a10, b) => a10.pid - b.pid);
|
|
27694
27745
|
}
|
|
27695
|
-
function removeFrontDoorSession(
|
|
27696
|
-
|
|
27746
|
+
function removeFrontDoorSession(fs30, sessionsDir, pid) {
|
|
27747
|
+
fs30.removeRecursive(import_node_path5.default.join(sessionsDir, `${String(pid)}.json`));
|
|
27697
27748
|
}
|
|
27698
|
-
function pruneDeadFrontDoorSessions(
|
|
27749
|
+
function pruneDeadFrontDoorSessions(fs30, sessionsDir, isRunning) {
|
|
27699
27750
|
const removed = [];
|
|
27700
|
-
for (const session of listFrontDoorSessions(
|
|
27751
|
+
for (const session of listFrontDoorSessions(fs30, sessionsDir)) {
|
|
27701
27752
|
if (!isRunning(session.pid)) {
|
|
27702
|
-
removeFrontDoorSession(
|
|
27753
|
+
removeFrontDoorSession(fs30, sessionsDir, session.pid);
|
|
27703
27754
|
removed.push(session.pid);
|
|
27704
27755
|
}
|
|
27705
27756
|
}
|
|
27706
27757
|
return removed;
|
|
27707
27758
|
}
|
|
27708
|
-
function liveSessionTokens(
|
|
27759
|
+
function liveSessionTokens(fs30, sessionsDir) {
|
|
27709
27760
|
const tokens = /* @__PURE__ */ new Set();
|
|
27710
|
-
for (const name of
|
|
27761
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27711
27762
|
if (!name.endsWith(".json")) {
|
|
27712
27763
|
continue;
|
|
27713
27764
|
}
|
|
27714
27765
|
try {
|
|
27715
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
27766
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs30.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
|
|
27716
27767
|
if (parsed.success) {
|
|
27717
27768
|
tokens.add(parsed.data.token);
|
|
27718
27769
|
}
|
|
@@ -27722,13 +27773,13 @@ function liveSessionTokens(fs29, sessionsDir) {
|
|
|
27722
27773
|
}
|
|
27723
27774
|
return tokens;
|
|
27724
27775
|
}
|
|
27725
|
-
function readFrontDoorSessionModels(
|
|
27726
|
-
for (const name of
|
|
27776
|
+
function readFrontDoorSessionModels(fs30, sessionsDir, sessionId) {
|
|
27777
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27727
27778
|
if (!name.endsWith(".json")) {
|
|
27728
27779
|
continue;
|
|
27729
27780
|
}
|
|
27730
27781
|
try {
|
|
27731
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
27782
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs30.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
|
|
27732
27783
|
if (parsed.success && parsed.data.sessionId === sessionId) {
|
|
27733
27784
|
return parsed.data.models;
|
|
27734
27785
|
}
|
|
@@ -27791,43 +27842,43 @@ function parseJson(raw, schema) {
|
|
|
27791
27842
|
const parsed = schema.safeParse(JSON.parse(raw));
|
|
27792
27843
|
return parsed.success ? parsed.data : void 0;
|
|
27793
27844
|
}
|
|
27794
|
-
function readHeadroomState(
|
|
27845
|
+
function readHeadroomState(fs30, stateFile) {
|
|
27795
27846
|
try {
|
|
27796
|
-
return parseJson(
|
|
27847
|
+
return parseJson(fs30.readFileUtf8(stateFile), HeadroomStateSchema);
|
|
27797
27848
|
} catch {
|
|
27798
27849
|
return void 0;
|
|
27799
27850
|
}
|
|
27800
27851
|
}
|
|
27801
|
-
function writeHeadroomState(
|
|
27802
|
-
|
|
27803
|
-
|
|
27852
|
+
function writeHeadroomState(fs30, stateFile, state) {
|
|
27853
|
+
fs30.mkdirp(import_node_path6.default.dirname(stateFile));
|
|
27854
|
+
fs30.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
27804
27855
|
`);
|
|
27805
27856
|
}
|
|
27806
|
-
function resolveServingHeadroomState(
|
|
27807
|
-
const current = readHeadroomState(
|
|
27857
|
+
function resolveServingHeadroomState(fs30, files, isRunning) {
|
|
27858
|
+
const current = readHeadroomState(fs30, files.stateFile);
|
|
27808
27859
|
if (current !== void 0) {
|
|
27809
27860
|
return { path: files.stateFile, state: current };
|
|
27810
27861
|
}
|
|
27811
|
-
const legacy = readHeadroomState(
|
|
27862
|
+
const legacy = readHeadroomState(fs30, files.legacyStateFile);
|
|
27812
27863
|
if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
|
|
27813
27864
|
return { path: files.legacyStateFile, state: legacy };
|
|
27814
27865
|
}
|
|
27815
27866
|
return void 0;
|
|
27816
27867
|
}
|
|
27817
|
-
function migrateHeadroomState(
|
|
27818
|
-
const legacy = readHeadroomState(
|
|
27868
|
+
function migrateHeadroomState(fs30, files, isRunning) {
|
|
27869
|
+
const legacy = readHeadroomState(fs30, files.legacyStateFile);
|
|
27819
27870
|
const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
|
|
27820
|
-
const current = readHeadroomState(
|
|
27871
|
+
const current = readHeadroomState(fs30, files.stateFile);
|
|
27821
27872
|
if (current !== void 0 || legacyLive) {
|
|
27822
|
-
if (!legacyLive &&
|
|
27823
|
-
|
|
27873
|
+
if (!legacyLive && fs30.readFileUtf8(files.legacyStateFile) !== void 0) {
|
|
27874
|
+
fs30.removeRecursive(files.legacyStateFile);
|
|
27824
27875
|
}
|
|
27825
27876
|
return;
|
|
27826
27877
|
}
|
|
27827
27878
|
if (legacy !== void 0) {
|
|
27828
|
-
writeHeadroomState(
|
|
27879
|
+
writeHeadroomState(fs30, files.stateFile, legacy);
|
|
27829
27880
|
}
|
|
27830
|
-
|
|
27881
|
+
fs30.removeRecursive(files.legacyStateFile);
|
|
27831
27882
|
}
|
|
27832
27883
|
function hashAllowlist(allowlist) {
|
|
27833
27884
|
return (0, import_node_crypto2.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
@@ -27860,27 +27911,27 @@ function isAdmissibleUrl(entry) {
|
|
|
27860
27911
|
function parseAllowlistFile(content) {
|
|
27861
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)));
|
|
27862
27913
|
}
|
|
27863
|
-
function writeAllowlistFile(
|
|
27864
|
-
|
|
27865
|
-
|
|
27914
|
+
function writeAllowlistFile(fs30, allowlistFile, allowlist) {
|
|
27915
|
+
fs30.mkdirPrivate(import_node_path6.default.dirname(allowlistFile));
|
|
27916
|
+
fs30.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
|
|
27866
27917
|
}
|
|
27867
|
-
function pruneStaleAllowlistTemporaries(
|
|
27918
|
+
function pruneStaleAllowlistTemporaries(fs30, allowlistFile, isRunning) {
|
|
27868
27919
|
const prefix = `${import_node_path6.default.basename(allowlistFile)}.`;
|
|
27869
|
-
for (const name of
|
|
27920
|
+
for (const name of fs30.readdir(import_node_path6.default.dirname(allowlistFile))) {
|
|
27870
27921
|
const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
|
|
27871
27922
|
if (writer !== void 0 && !isRunning(Number(writer))) {
|
|
27872
|
-
|
|
27923
|
+
fs30.removeRecursive(import_node_path6.default.join(import_node_path6.default.dirname(allowlistFile), name));
|
|
27873
27924
|
}
|
|
27874
27925
|
}
|
|
27875
27926
|
}
|
|
27876
|
-
function readAllProviders(
|
|
27927
|
+
function readAllProviders(fs30, providersDir) {
|
|
27877
27928
|
const result = [];
|
|
27878
|
-
for (const name of
|
|
27929
|
+
for (const name of fs30.readdir(providersDir)) {
|
|
27879
27930
|
if (!name.endsWith(".json")) {
|
|
27880
27931
|
continue;
|
|
27881
27932
|
}
|
|
27882
27933
|
try {
|
|
27883
|
-
const parsed = parseJson(
|
|
27934
|
+
const parsed = parseJson(fs30.readFileUtf8(import_node_path6.default.join(providersDir, name)), ProviderSchema);
|
|
27884
27935
|
if (parsed !== void 0) {
|
|
27885
27936
|
result.push({ name: name.slice(0, -".json".length), provider: parsed });
|
|
27886
27937
|
}
|
|
@@ -27890,22 +27941,22 @@ function readAllProviders(fs29, providersDir) {
|
|
|
27890
27941
|
}
|
|
27891
27942
|
return result;
|
|
27892
27943
|
}
|
|
27893
|
-
function writeSession(
|
|
27894
|
-
|
|
27895
|
-
|
|
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)}
|
|
27896
27947
|
`);
|
|
27897
27948
|
}
|
|
27898
|
-
function removeSession(
|
|
27899
|
-
|
|
27949
|
+
function removeSession(fs30, sessionsDir, pid) {
|
|
27950
|
+
fs30.removeRecursive(import_node_path6.default.join(sessionsDir, `${String(pid)}.json`));
|
|
27900
27951
|
}
|
|
27901
|
-
function listSessions(
|
|
27952
|
+
function listSessions(fs30, sessionsDir) {
|
|
27902
27953
|
const sessions = [];
|
|
27903
|
-
for (const name of
|
|
27954
|
+
for (const name of fs30.readdir(sessionsDir)) {
|
|
27904
27955
|
if (!name.endsWith(".json")) {
|
|
27905
27956
|
continue;
|
|
27906
27957
|
}
|
|
27907
27958
|
try {
|
|
27908
|
-
const parsed = parseJson(
|
|
27959
|
+
const parsed = parseJson(fs30.readFileUtf8(import_node_path6.default.join(sessionsDir, name)), HeadroomSessionSchema);
|
|
27909
27960
|
if (parsed !== void 0) {
|
|
27910
27961
|
sessions.push(parsed);
|
|
27911
27962
|
}
|
|
@@ -27915,22 +27966,22 @@ function listSessions(fs29, sessionsDir) {
|
|
|
27915
27966
|
}
|
|
27916
27967
|
return sessions.sort((a10, b) => a10.pid - b.pid);
|
|
27917
27968
|
}
|
|
27918
|
-
function sessionsForSupervisor(
|
|
27919
|
-
return listSessions(
|
|
27969
|
+
function sessionsForSupervisor(fs30, sessionsDir, supervisorPid) {
|
|
27970
|
+
return listSessions(fs30, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
|
|
27920
27971
|
}
|
|
27921
|
-
function pruneDeadSessions(
|
|
27972
|
+
function pruneDeadSessions(fs30, sessionsDir, isRunning) {
|
|
27922
27973
|
const removed = [];
|
|
27923
|
-
for (const session of listSessions(
|
|
27974
|
+
for (const session of listSessions(fs30, sessionsDir)) {
|
|
27924
27975
|
if (!isRunning(session.pid)) {
|
|
27925
|
-
removeSession(
|
|
27976
|
+
removeSession(fs30, sessionsDir, session.pid);
|
|
27926
27977
|
removed.push(session.pid);
|
|
27927
27978
|
}
|
|
27928
27979
|
}
|
|
27929
27980
|
return removed;
|
|
27930
27981
|
}
|
|
27931
|
-
function readStartLock(
|
|
27982
|
+
function readStartLock(fs30, lockFile) {
|
|
27932
27983
|
try {
|
|
27933
|
-
return parseJson(
|
|
27984
|
+
return parseJson(fs30.readFileUtf8(lockFile), HeadroomLockSchema);
|
|
27934
27985
|
} catch {
|
|
27935
27986
|
return void 0;
|
|
27936
27987
|
}
|
|
@@ -28023,12 +28074,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
|
|
|
28023
28074
|
}
|
|
28024
28075
|
return hashAllowlist([...entries].sort());
|
|
28025
28076
|
}
|
|
28026
|
-
function earlierReleaseDaemon(
|
|
28077
|
+
function earlierReleaseDaemon(fs30, paths, daemon) {
|
|
28027
28078
|
if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
|
|
28028
28079
|
return void 0;
|
|
28029
28080
|
}
|
|
28030
|
-
const providers = readAllProviders(
|
|
28031
|
-
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)));
|
|
28032
28083
|
return { admitsServingDoor: daemon.recordedHash === expected };
|
|
28033
28084
|
}
|
|
28034
28085
|
var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
|
|
@@ -28053,8 +28104,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
|
|
|
28053
28104
|
}
|
|
28054
28105
|
return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
|
|
28055
28106
|
}
|
|
28056
|
-
function daemonAdmits(
|
|
28057
|
-
const content =
|
|
28107
|
+
function daemonAdmits(fs30, allowlistFile, recordedHash, required2) {
|
|
28108
|
+
const content = fs30.readFileUtf8(allowlistFile);
|
|
28058
28109
|
if (content === void 0 || recordedHash === void 0) {
|
|
28059
28110
|
return false;
|
|
28060
28111
|
}
|
|
@@ -28194,8 +28245,8 @@ function redactHeaders(headers) {
|
|
|
28194
28245
|
}
|
|
28195
28246
|
return result;
|
|
28196
28247
|
}
|
|
28197
|
-
function redactText(
|
|
28198
|
-
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);
|
|
28199
28250
|
}
|
|
28200
28251
|
function redactJsonValue(value2) {
|
|
28201
28252
|
if (typeof value2 === "string") {
|
|
@@ -28210,12 +28261,12 @@ function redactJsonValue(value2) {
|
|
|
28210
28261
|
return value2;
|
|
28211
28262
|
}
|
|
28212
28263
|
function redactBody(chunk2) {
|
|
28213
|
-
const
|
|
28264
|
+
const text3 = chunk2.toString("utf8");
|
|
28214
28265
|
try {
|
|
28215
|
-
const parsed = JSON.parse(
|
|
28266
|
+
const parsed = JSON.parse(text3);
|
|
28216
28267
|
return JSON.stringify(redactJsonValue(parsed));
|
|
28217
28268
|
} catch {
|
|
28218
|
-
return redactText(
|
|
28269
|
+
return redactText(text3);
|
|
28219
28270
|
}
|
|
28220
28271
|
}
|
|
28221
28272
|
function captureFromEnv(env, logsDir) {
|
|
@@ -28250,8 +28301,8 @@ function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
|
28250
28301
|
}
|
|
28251
28302
|
const excerpt2 = chunk2.subarray(0, Math.min(CHUNK_LOG_CAP_BYTES, budget));
|
|
28252
28303
|
stored[direction] += excerpt2.length;
|
|
28253
|
-
const
|
|
28254
|
-
const faithful = Buffer.from(
|
|
28304
|
+
const text3 = excerpt2.toString("utf8");
|
|
28305
|
+
const faithful = Buffer.from(text3, "utf8").equals(excerpt2);
|
|
28255
28306
|
append({
|
|
28256
28307
|
kind: "stream-chunk",
|
|
28257
28308
|
id: id2,
|
|
@@ -28260,7 +28311,7 @@ function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
|
28260
28311
|
bytes: chunk2.length,
|
|
28261
28312
|
stored: excerpt2.length,
|
|
28262
28313
|
truncated: excerpt2.length < chunk2.length,
|
|
28263
|
-
...faithful ? { body: redactText(
|
|
28314
|
+
...faithful ? { body: redactText(text3) } : { b64: excerpt2.toString("base64") }
|
|
28264
28315
|
});
|
|
28265
28316
|
},
|
|
28266
28317
|
onEnd: () => {
|
|
@@ -28444,7 +28495,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
|
|
|
28444
28495
|
const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
|
|
28445
28496
|
return { message: refusal2, repairable: replaceable };
|
|
28446
28497
|
}
|
|
28447
|
-
function prepareHeadroomSocket(
|
|
28498
|
+
function prepareHeadroomSocket(fs30, ports, paths, supervisorPid) {
|
|
28448
28499
|
const unsupported = platformRefusal(ports.platform);
|
|
28449
28500
|
if (unsupported !== void 0) {
|
|
28450
28501
|
return { refused: unsupported };
|
|
@@ -28459,18 +28510,18 @@ function prepareHeadroomSocket(fs29, ports, paths, supervisorPid) {
|
|
|
28459
28510
|
if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
|
|
28460
28511
|
return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
|
|
28461
28512
|
}
|
|
28462
|
-
|
|
28513
|
+
fs30.mkdirPrivate(paths.headroomSocketDir);
|
|
28463
28514
|
const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
|
|
28464
28515
|
return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
|
|
28465
28516
|
}
|
|
28466
|
-
function pruneStaleHeadroomSockets(
|
|
28517
|
+
function pruneStaleHeadroomSockets(fs30, paths, isRunning) {
|
|
28467
28518
|
const removed = [];
|
|
28468
|
-
for (const name of
|
|
28519
|
+
for (const name of fs30.readdir(paths.headroomSocketDir)) {
|
|
28469
28520
|
const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
|
|
28470
28521
|
if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
|
|
28471
28522
|
continue;
|
|
28472
28523
|
}
|
|
28473
|
-
|
|
28524
|
+
fs30.removeRecursive(import_node_path7.default.join(paths.headroomSocketDir, name));
|
|
28474
28525
|
removed.push(name);
|
|
28475
28526
|
}
|
|
28476
28527
|
return removed;
|
|
@@ -28617,37 +28668,37 @@ function compareVersions2(a10, b) {
|
|
|
28617
28668
|
return 0;
|
|
28618
28669
|
}
|
|
28619
28670
|
async function runSupervisor(initialConfig, ports, options = {}) {
|
|
28620
|
-
const { fs:
|
|
28671
|
+
const { fs: fs30, paths } = ports;
|
|
28621
28672
|
let config2 = initialConfig;
|
|
28622
|
-
migrateHeadroomState(
|
|
28623
|
-
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;
|
|
28624
28675
|
if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
|
|
28625
28676
|
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
|
|
28626
28677
|
return 0;
|
|
28627
28678
|
}
|
|
28628
28679
|
let installedSource = previousState?.installedSource;
|
|
28629
28680
|
const ownsState = () => {
|
|
28630
|
-
const owner = readHeadroomState(
|
|
28681
|
+
const owner = readHeadroomState(fs30, paths.headroomStateFile)?.supervisorPid;
|
|
28631
28682
|
return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
|
|
28632
28683
|
};
|
|
28633
28684
|
const writeOwnState = (state) => {
|
|
28634
28685
|
if (!ownsState()) {
|
|
28635
28686
|
return false;
|
|
28636
28687
|
}
|
|
28637
|
-
writeHeadroomState(
|
|
28688
|
+
writeHeadroomState(fs30, paths.headroomStateFile, state);
|
|
28638
28689
|
return true;
|
|
28639
28690
|
};
|
|
28640
28691
|
const fail = (message) => {
|
|
28641
28692
|
if (writeOwnState({ lastError: message })) {
|
|
28642
|
-
|
|
28693
|
+
fs30.removeRecursive(paths.headroomLockFile);
|
|
28643
28694
|
}
|
|
28644
28695
|
ports.log(`agent-shim headroom supervisor: ${message}`);
|
|
28645
28696
|
return 1;
|
|
28646
28697
|
};
|
|
28647
28698
|
const syncAllowlistFile = (allowlist) => {
|
|
28648
28699
|
try {
|
|
28649
|
-
if (
|
|
28650
|
-
writeAllowlistFile(
|
|
28700
|
+
if (fs30.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
|
|
28701
|
+
writeAllowlistFile(fs30, paths.headroomAllowlistFile, allowlist);
|
|
28651
28702
|
ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
|
|
28652
28703
|
}
|
|
28653
28704
|
return void 0;
|
|
@@ -28665,9 +28716,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28665
28716
|
}
|
|
28666
28717
|
ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
|
|
28667
28718
|
try {
|
|
28668
|
-
|
|
28669
|
-
|
|
28670
|
-
writeAllowlistFile(
|
|
28719
|
+
fs30.mkdirPrivate(paths.headroomDir);
|
|
28720
|
+
fs30.mkdirPrivate(import_node_path8.default.dirname(paths.headroomAllowlistFile));
|
|
28721
|
+
writeAllowlistFile(fs30, paths.headroomAllowlistFile, allowlist);
|
|
28671
28722
|
} catch (error63) {
|
|
28672
28723
|
return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error63 instanceof Error ? error63.message : String(error63)}`;
|
|
28673
28724
|
}
|
|
@@ -28692,20 +28743,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28692
28743
|
installedSource = config2.source;
|
|
28693
28744
|
return void 0;
|
|
28694
28745
|
};
|
|
28695
|
-
const socket = prepareHeadroomSocket(
|
|
28746
|
+
const socket = prepareHeadroomSocket(fs30, ports.socketTrust, paths, ports.ownPid);
|
|
28696
28747
|
if (socket.refused !== void 0) {
|
|
28697
28748
|
return fail(socket.refused);
|
|
28698
28749
|
}
|
|
28699
28750
|
const { socketPath } = socket;
|
|
28700
|
-
pruneStaleHeadroomSockets(
|
|
28701
|
-
pruneStaleAllowlistTemporaries(
|
|
28751
|
+
pruneStaleHeadroomSockets(fs30, paths, ports.isRunning);
|
|
28752
|
+
pruneStaleAllowlistTemporaries(fs30, paths.headroomAllowlistFile, ports.isRunning);
|
|
28702
28753
|
const installFailure = ensureInstalled();
|
|
28703
28754
|
if (installFailure !== void 0) {
|
|
28704
28755
|
return fail(installFailure);
|
|
28705
28756
|
}
|
|
28706
28757
|
const version2 = ports.headroomVersion() ?? "unknown";
|
|
28707
28758
|
writeOwnState({ supervisorPid: ports.ownPid, version: version2, installedSource });
|
|
28708
|
-
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(", ")}]`);
|
|
28709
28760
|
const orphanPid = previousState?.headroomPid;
|
|
28710
28761
|
const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
|
|
28711
28762
|
const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
|
|
@@ -28740,12 +28791,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28740
28791
|
ticks += 1;
|
|
28741
28792
|
config2 = ports.readConfig();
|
|
28742
28793
|
const settingsHash = hashSettings(config2.settings);
|
|
28743
|
-
const inputs = currentHeadroomAllowlistInputs(
|
|
28744
|
-
pruneDeadFrontDoorDirectRecords(
|
|
28745
|
-
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);
|
|
28746
28797
|
const allowlist = inputs.frontDoorOrigins;
|
|
28747
28798
|
const allowlistHash = hashAllowlist(allowlist);
|
|
28748
|
-
pruneDeadSessions(
|
|
28799
|
+
pruneDeadSessions(fs30, paths.headroomSessionsDir, ports.isRunning);
|
|
28749
28800
|
const ownsNow = ownsState();
|
|
28750
28801
|
if (!ownsNow && !superseded) {
|
|
28751
28802
|
ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
|
|
@@ -28792,7 +28843,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28792
28843
|
runningSettingsHash = settingsHash;
|
|
28793
28844
|
const recorded = writeOwnState(servingState(pid));
|
|
28794
28845
|
if (recorded) {
|
|
28795
|
-
|
|
28846
|
+
fs30.removeRecursive(paths.headroomLockFile);
|
|
28796
28847
|
}
|
|
28797
28848
|
idleSince = void 0;
|
|
28798
28849
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
|
|
@@ -28820,7 +28871,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28820
28871
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
|
|
28821
28872
|
}
|
|
28822
28873
|
if (runningSettingsHash !== settingsHash || installedSource !== config2.source) {
|
|
28823
|
-
if (sessionsForSupervisor(
|
|
28874
|
+
if (sessionsForSupervisor(fs30, paths.headroomSessionsDir, ports.ownPid).length === 0) {
|
|
28824
28875
|
ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
|
|
28825
28876
|
ports.stopProcess(headroomPid);
|
|
28826
28877
|
headroomPid = void 0;
|
|
@@ -28829,7 +28880,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
28829
28880
|
continue;
|
|
28830
28881
|
}
|
|
28831
28882
|
}
|
|
28832
|
-
const sessions = sessionsForSupervisor(
|
|
28883
|
+
const sessions = sessionsForSupervisor(fs30, paths.headroomSessionsDir, ports.ownPid);
|
|
28833
28884
|
if (sessions.length === 0) {
|
|
28834
28885
|
idleSince ??= ports.now();
|
|
28835
28886
|
const idleMs = ports.now() - idleSince;
|
|
@@ -28854,9 +28905,9 @@ function undeterminedFrontDoors(inputs) {
|
|
|
28854
28905
|
return reason === void 0 ? [] : [{ pid: record2.pid, origin: directOrigin(record2.directPort), reason }];
|
|
28855
28906
|
});
|
|
28856
28907
|
}
|
|
28857
|
-
function currentHeadroomAllowlistInputs(
|
|
28858
|
-
const named = frontDoorOrigin(readFrontDoorState(
|
|
28859
|
-
const records = listFrontDoorDirectRecords(
|
|
28908
|
+
function currentHeadroomAllowlistInputs(fs30, paths, frontDoorLiveness) {
|
|
28909
|
+
const named = frontDoorOrigin(readFrontDoorState(fs30, paths.frontdoorStateFile));
|
|
28910
|
+
const records = listFrontDoorDirectRecords(fs30, paths.frontdoorDirectRecordsDir);
|
|
28860
28911
|
const liveness = frontDoorLiveness(records.map((record2) => record2.pid));
|
|
28861
28912
|
const live = liveFrontDoorDirectRecords(records, liveness).map((record2) => directOrigin(record2.directPort));
|
|
28862
28913
|
return {
|
|
@@ -28865,8 +28916,8 @@ function currentHeadroomAllowlistInputs(fs29, paths, frontDoorLiveness) {
|
|
|
28865
28916
|
frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
|
|
28866
28917
|
};
|
|
28867
28918
|
}
|
|
28868
|
-
function launchRequiredUpstreams(
|
|
28869
|
-
const door = frontDoorOrigin(readFrontDoorState(
|
|
28919
|
+
function launchRequiredUpstreams(fs30, paths) {
|
|
28920
|
+
const door = frontDoorOrigin(readFrontDoorState(fs30, paths.frontdoorStateFile));
|
|
28870
28921
|
return door === void 0 ? [] : [door];
|
|
28871
28922
|
}
|
|
28872
28923
|
async function waitUntilReady(ports, socketPath, pid) {
|
|
@@ -28944,8 +28995,8 @@ var init_report = __esm({
|
|
|
28944
28995
|
});
|
|
28945
28996
|
|
|
28946
28997
|
// src/logStyle.ts
|
|
28947
|
-
function styledDiagnostic(style, colour,
|
|
28948
|
-
return
|
|
28998
|
+
function styledDiagnostic(style, colour, text3) {
|
|
28999
|
+
return text3.split("\n").map((line, index) => {
|
|
28949
29000
|
const lead = index === 0 ? DIAGNOSTIC_LEAD.exec(line) : null;
|
|
28950
29001
|
if (lead === null) {
|
|
28951
29002
|
return style([colour], line);
|
|
@@ -28973,7 +29024,7 @@ function createLogPort(sinks, styleFor) {
|
|
|
28973
29024
|
};
|
|
28974
29025
|
}
|
|
28975
29026
|
function styleTextFor(stream) {
|
|
28976
|
-
return (formats,
|
|
29027
|
+
return (formats, text3) => (0, import_node_util3.styleText)([...formats], text3, { stream });
|
|
28977
29028
|
}
|
|
28978
29029
|
var import_node_util3, DIAGNOSTIC_LEAD;
|
|
28979
29030
|
var init_logStyle = __esm({
|
|
@@ -31793,8 +31844,8 @@ var init_classify = __esm({
|
|
|
31793
31844
|
function poolNameOf(selector) {
|
|
31794
31845
|
return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
|
|
31795
31846
|
}
|
|
31796
|
-
function readActiveIdentity(
|
|
31797
|
-
const trimmed =
|
|
31847
|
+
function readActiveIdentity(fs30, activeIdentityFile) {
|
|
31848
|
+
const trimmed = fs30.readFileUtf8(activeIdentityFile)?.trim();
|
|
31798
31849
|
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
31799
31850
|
}
|
|
31800
31851
|
function isNonEmpty(value2) {
|
|
@@ -31841,8 +31892,8 @@ function decideConfigProfile(params) {
|
|
|
31841
31892
|
}
|
|
31842
31893
|
return { source: "none" };
|
|
31843
31894
|
}
|
|
31844
|
-
function loadIdentity(identitiesDir, name,
|
|
31845
|
-
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);
|
|
31846
31897
|
}
|
|
31847
31898
|
var import_node_path11, IDENTITY_DECISION_SOURCES, CONFIG_PROFILE_DECISION_SOURCES;
|
|
31848
31899
|
var init_identity = __esm({
|
|
@@ -31901,6 +31952,9 @@ function keyOf(path66, leaf) {
|
|
|
31901
31952
|
if (leaf instanceof external_exports.ZodString) {
|
|
31902
31953
|
return { ...common, kind: "text", choices: [] };
|
|
31903
31954
|
}
|
|
31955
|
+
if (leaf instanceof external_exports.ZodUnion) {
|
|
31956
|
+
return { ...common, kind: "colour", choices: [...STATUSLINE_COLOUR_NAMES] };
|
|
31957
|
+
}
|
|
31904
31958
|
if (leaf instanceof external_exports.ZodEnum) {
|
|
31905
31959
|
return { ...common, kind: "choice", choices: Object.values(leaf.enum).map(String) };
|
|
31906
31960
|
}
|
|
@@ -31917,7 +31971,7 @@ function statuslineKeys() {
|
|
|
31917
31971
|
}
|
|
31918
31972
|
function formatStatuslineKeys(keys) {
|
|
31919
31973
|
return keys.map((key) => {
|
|
31920
|
-
const takes = key.kind === "choice" || key.kind === "list" ? `${key.kind} of ${key.choices.join(", ")}` : key.kind;
|
|
31974
|
+
const takes = key.kind === "choice" || key.kind === "list" || key.kind === "colour" ? `${key.kind} of ${key.choices.join(", ")}` : key.kind;
|
|
31921
31975
|
return `${key.path} (${takes}; default ${JSON.stringify(key.defaultValue)})
|
|
31922
31976
|
${key.description}`;
|
|
31923
31977
|
}).join("\n");
|
|
@@ -31938,25 +31992,27 @@ function keyNamed(path66) {
|
|
|
31938
31992
|
}
|
|
31939
31993
|
return found;
|
|
31940
31994
|
}
|
|
31941
|
-
function parseStatuslineAssignment(
|
|
31942
|
-
const split =
|
|
31995
|
+
function parseStatuslineAssignment(text3) {
|
|
31996
|
+
const split = text3.indexOf("=");
|
|
31943
31997
|
if (split < 1) {
|
|
31944
|
-
throw new UsageError(`"${
|
|
31998
|
+
throw new UsageError(`"${text3}" is not <setting>=<value>.`);
|
|
31945
31999
|
}
|
|
31946
|
-
const path66 =
|
|
31947
|
-
const raw =
|
|
32000
|
+
const path66 = text3.slice(0, split);
|
|
32001
|
+
const raw = text3.slice(split + 1);
|
|
31948
32002
|
const key = keyNamed(path66);
|
|
31949
32003
|
switch (key.kind) {
|
|
31950
32004
|
case "integer": {
|
|
31951
|
-
const
|
|
31952
|
-
if (raw.trim() === "" || !Number.isFinite(
|
|
32005
|
+
const number5 = Number(raw);
|
|
32006
|
+
if (raw.trim() === "" || !Number.isFinite(number5)) {
|
|
31953
32007
|
throw new UsageError(`${path66}: "${raw}" is not a number.`);
|
|
31954
32008
|
}
|
|
31955
|
-
return { path: path66, value:
|
|
32009
|
+
return { path: path66, value: number5 };
|
|
31956
32010
|
}
|
|
31957
32011
|
case "text":
|
|
31958
32012
|
case "choice":
|
|
31959
32013
|
return { path: path66, value: raw };
|
|
32014
|
+
case "colour":
|
|
32015
|
+
return { path: path66, value: /^\d+$/.test(raw) ? Number(raw) : raw };
|
|
31960
32016
|
case "list":
|
|
31961
32017
|
return { path: path66, value: raw === "" ? [] : raw.split(",") };
|
|
31962
32018
|
default:
|
|
@@ -33694,8 +33750,8 @@ var init_pipeline = __esm({
|
|
|
33694
33750
|
});
|
|
33695
33751
|
|
|
33696
33752
|
// src/launcher/farm.ts
|
|
33697
|
-
function readFarmManifest(
|
|
33698
|
-
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));
|
|
33699
33755
|
if (raw === void 0) {
|
|
33700
33756
|
return void 0;
|
|
33701
33757
|
}
|
|
@@ -33753,9 +33809,9 @@ function buildEntryFacts(params) {
|
|
|
33753
33809
|
entries
|
|
33754
33810
|
};
|
|
33755
33811
|
}
|
|
33756
|
-
function listSubtree(
|
|
33812
|
+
function listSubtree(fs30, root, rel) {
|
|
33757
33813
|
const absolute = import_node_path19.default.join(root, rel);
|
|
33758
|
-
const stat =
|
|
33814
|
+
const stat = fs30.lstat(absolute);
|
|
33759
33815
|
if (stat === void 0) {
|
|
33760
33816
|
return [];
|
|
33761
33817
|
}
|
|
@@ -33763,10 +33819,10 @@ function listSubtree(fs29, root, rel) {
|
|
|
33763
33819
|
return [{ rel, kind: "symlink" }];
|
|
33764
33820
|
}
|
|
33765
33821
|
if (stat.kind === "dir") {
|
|
33766
|
-
const children = [...
|
|
33822
|
+
const children = [...fs30.readdir(absolute)].sort().flatMap((name) => listSubtree(fs30, root, `${rel}/${name}`));
|
|
33767
33823
|
return [{ rel, kind: "dir" }, ...children];
|
|
33768
33824
|
}
|
|
33769
|
-
const contentHash =
|
|
33825
|
+
const contentHash = fs30.hashFile(absolute);
|
|
33770
33826
|
return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
|
|
33771
33827
|
}
|
|
33772
33828
|
function topLevelScopeRoots(roots) {
|
|
@@ -33780,25 +33836,25 @@ function topLevelScopeRoots(roots) {
|
|
|
33780
33836
|
}
|
|
33781
33837
|
return kept;
|
|
33782
33838
|
}
|
|
33783
|
-
function reconciliationScope(
|
|
33839
|
+
function reconciliationScope(fs30, farmRoot, manifest) {
|
|
33784
33840
|
if (manifest !== void 0) {
|
|
33785
33841
|
return topLevelScopeRoots(manifest.materialised);
|
|
33786
33842
|
}
|
|
33787
|
-
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();
|
|
33788
33844
|
}
|
|
33789
|
-
function collectFarmListing(
|
|
33790
|
-
return scopeRoots.flatMap((root) => listSubtree(
|
|
33845
|
+
function collectFarmListing(fs30, farmRoot, scopeRoots) {
|
|
33846
|
+
return scopeRoots.flatMap((root) => listSubtree(fs30, farmRoot, root));
|
|
33791
33847
|
}
|
|
33792
|
-
function collectCanonicalCounterparts(
|
|
33848
|
+
function collectCanonicalCounterparts(fs30, claudeHome, farmListing) {
|
|
33793
33849
|
const out = [];
|
|
33794
33850
|
for (const entry of farmListing) {
|
|
33795
33851
|
const absolute = import_node_path19.default.join(claudeHome, entry.rel);
|
|
33796
|
-
const stat =
|
|
33852
|
+
const stat = fs30.lstat(absolute);
|
|
33797
33853
|
if (stat === void 0) {
|
|
33798
33854
|
continue;
|
|
33799
33855
|
}
|
|
33800
33856
|
if (stat.kind === "file") {
|
|
33801
|
-
const contentHash =
|
|
33857
|
+
const contentHash = fs30.hashFile(absolute);
|
|
33802
33858
|
out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
|
|
33803
33859
|
continue;
|
|
33804
33860
|
}
|
|
@@ -35061,7 +35117,7 @@ function keyUsageExtension(bits) {
|
|
|
35061
35117
|
}
|
|
35062
35118
|
function ipv6Groups(address) {
|
|
35063
35119
|
const [head = "", tail] = address.split("::");
|
|
35064
|
-
const split = (
|
|
35120
|
+
const split = (text3) => text3 === "" ? [] : text3.split(":");
|
|
35065
35121
|
const expand = (groups) => groups.flatMap((group) => {
|
|
35066
35122
|
if (!import_node_net.default.isIPv4(group)) {
|
|
35067
35123
|
return [Number.parseInt(group, HEX_RADIX)];
|
|
@@ -35471,9 +35527,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
35471
35527
|
}
|
|
35472
35528
|
}
|
|
35473
35529
|
async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
35474
|
-
const { fs:
|
|
35530
|
+
const { fs: fs30, paths } = ports;
|
|
35475
35531
|
const servingBinary = ports.statOwnExecutable();
|
|
35476
|
-
const previous = readFrontDoorState(
|
|
35532
|
+
const previous = readFrontDoorState(fs30, paths.frontdoorStateFile);
|
|
35477
35533
|
let lastPort = previous?.lastPort;
|
|
35478
35534
|
let lastConnectPort = previous?.lastConnectPort;
|
|
35479
35535
|
let lastDirectPort = previous?.lastDirectPort;
|
|
@@ -35484,12 +35540,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35484
35540
|
});
|
|
35485
35541
|
const fail = (message) => {
|
|
35486
35542
|
ports.closeRcStreamHub();
|
|
35487
|
-
writeFrontDoorState(
|
|
35488
|
-
|
|
35543
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, { lastError: message, ...sticky() });
|
|
35544
|
+
fs30.removeRecursive(paths.frontdoorLockFile);
|
|
35489
35545
|
ports.log(`agent-shim frontdoor supervisor: ${message}`);
|
|
35490
35546
|
return 1;
|
|
35491
35547
|
};
|
|
35492
|
-
writeFrontDoorState(
|
|
35548
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
|
|
35493
35549
|
const previousSticky = lastPort;
|
|
35494
35550
|
let http9;
|
|
35495
35551
|
try {
|
|
@@ -35529,16 +35585,16 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35529
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)`);
|
|
35530
35586
|
}
|
|
35531
35587
|
lastDirectPort = direct.port;
|
|
35532
|
-
writeFrontDoorDirectRecord(
|
|
35533
|
-
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() });
|
|
35534
35590
|
ports.doorHealth.generation({ providerPort: http9.port, connectPort: connect3.port, directPort: direct.port });
|
|
35535
|
-
|
|
35591
|
+
fs30.removeRecursive(paths.frontdoorLockFile);
|
|
35536
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)}`);
|
|
35537
35593
|
const watchdog = ports.startWatchdog?.();
|
|
35538
35594
|
let idleSince;
|
|
35539
35595
|
let ticks = 0;
|
|
35540
35596
|
const supersedingOwner = () => {
|
|
35541
|
-
const owner = readFrontDoorState(
|
|
35597
|
+
const owner = readFrontDoorState(fs30, paths.frontdoorStateFile)?.supervisorPid;
|
|
35542
35598
|
return owner !== void 0 && owner !== ports.ownPid && ports.isRunning(owner) ? owner : void 0;
|
|
35543
35599
|
};
|
|
35544
35600
|
let supersededBy;
|
|
@@ -35565,13 +35621,13 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35565
35621
|
ports.stopBackgroundWork?.();
|
|
35566
35622
|
const drained = [direct.drain(), connect3.drain(), http9.drain()];
|
|
35567
35623
|
if (supersedingOwner() === void 0) {
|
|
35568
|
-
writeFrontDoorState(
|
|
35624
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, sticky());
|
|
35569
35625
|
}
|
|
35570
|
-
markFrontDoorDraining(
|
|
35626
|
+
markFrontDoorDraining(fs30, paths.frontdoorDrainingDir, ports.ownPid);
|
|
35571
35627
|
ports.closeRcStreamHub();
|
|
35572
35628
|
await Promise.all(drained);
|
|
35573
|
-
unmarkFrontDoorDraining(
|
|
35574
|
-
removeFrontDoorDirectRecord(
|
|
35629
|
+
unmarkFrontDoorDraining(fs30, paths.frontdoorDrainingDir, ports.ownPid);
|
|
35630
|
+
removeFrontDoorDirectRecord(fs30, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
35575
35631
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: the connections this door carried have ended; exiting`);
|
|
35576
35632
|
return 0;
|
|
35577
35633
|
};
|
|
@@ -35581,12 +35637,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35581
35637
|
await connect3.close();
|
|
35582
35638
|
await http9.close();
|
|
35583
35639
|
ports.closeRcStreamHub();
|
|
35584
|
-
removeFrontDoorDirectRecord(
|
|
35640
|
+
removeFrontDoorDirectRecord(fs30, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
35585
35641
|
};
|
|
35586
35642
|
const shutdown = async () => {
|
|
35587
35643
|
await closeServing();
|
|
35588
35644
|
if (supersedingOwner() === void 0) {
|
|
35589
|
-
writeFrontDoorState(
|
|
35645
|
+
writeFrontDoorState(fs30, paths.frontdoorStateFile, sticky());
|
|
35590
35646
|
}
|
|
35591
35647
|
return 0;
|
|
35592
35648
|
};
|
|
@@ -35600,8 +35656,8 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
35600
35656
|
return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
|
|
35601
35657
|
}
|
|
35602
35658
|
ticks += 1;
|
|
35603
|
-
const listed = listFrontDoorSessions(
|
|
35604
|
-
const pruned = pruneDeadFrontDoorSessions(
|
|
35659
|
+
const listed = listFrontDoorSessions(fs30, paths.frontdoorSessionsDir);
|
|
35660
|
+
const pruned = pruneDeadFrontDoorSessions(fs30, paths.frontdoorSessionsDir, ports.isRunning);
|
|
35605
35661
|
ports.observeLaunchRegistry(listed, pruned);
|
|
35606
35662
|
ports.checkQuotaExpiry();
|
|
35607
35663
|
const prunedPids = new Set(pruned);
|
|
@@ -36151,7 +36207,7 @@ var init_package = __esm({
|
|
|
36151
36207
|
"package.json"() {
|
|
36152
36208
|
package_default = {
|
|
36153
36209
|
name: "agent-shim",
|
|
36154
|
-
version: "11.
|
|
36210
|
+
version: "11.52.1",
|
|
36155
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.",
|
|
36156
36212
|
license: "MIT",
|
|
36157
36213
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -36264,14 +36320,14 @@ function isIdentityName(name) {
|
|
|
36264
36320
|
function claudeJsonPath(identitiesDir, identity) {
|
|
36265
36321
|
return import_node_path25.default.join(identitiesDir, identity, CLAUDE_JSON);
|
|
36266
36322
|
}
|
|
36267
|
-
function readAccountMetadata(
|
|
36323
|
+
function readAccountMetadata(fs30, identitiesDir, identity) {
|
|
36268
36324
|
if (!isIdentityName(identity)) {
|
|
36269
36325
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
36270
36326
|
}
|
|
36271
|
-
return readAccountMetadataFile(
|
|
36327
|
+
return readAccountMetadataFile(fs30, claudeJsonPath(identitiesDir, identity));
|
|
36272
36328
|
}
|
|
36273
|
-
function readAccountMetadataFile(
|
|
36274
|
-
const raw =
|
|
36329
|
+
function readAccountMetadataFile(fs30, file2) {
|
|
36330
|
+
const raw = fs30.readFileUtf8(file2);
|
|
36275
36331
|
if (raw === void 0) {
|
|
36276
36332
|
return void 0;
|
|
36277
36333
|
}
|
|
@@ -36301,19 +36357,19 @@ function readAccountMetadataFile(fs29, file2) {
|
|
|
36301
36357
|
}
|
|
36302
36358
|
return account.data;
|
|
36303
36359
|
}
|
|
36304
|
-
function createAccountReader(
|
|
36360
|
+
function createAccountReader(fs30, identitiesDir) {
|
|
36305
36361
|
const cache = /* @__PURE__ */ new Map();
|
|
36306
36362
|
return (identity) => {
|
|
36307
36363
|
if (!isIdentityName(identity)) {
|
|
36308
36364
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
36309
36365
|
}
|
|
36310
|
-
const stat =
|
|
36366
|
+
const stat = fs30.lstat(claudeJsonPath(identitiesDir, identity));
|
|
36311
36367
|
const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
|
|
36312
36368
|
const cached2 = cache.get(identity);
|
|
36313
36369
|
if (cached2?.stamp === stamp) {
|
|
36314
36370
|
return cached2.account;
|
|
36315
36371
|
}
|
|
36316
|
-
const account = readAccountMetadata(
|
|
36372
|
+
const account = readAccountMetadata(fs30, identitiesDir, identity);
|
|
36317
36373
|
cache.set(identity, { stamp, account });
|
|
36318
36374
|
return account;
|
|
36319
36375
|
};
|
|
@@ -36415,9 +36471,9 @@ function errorInfo(raw) {
|
|
|
36415
36471
|
function isObject3(value2) {
|
|
36416
36472
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
36417
36473
|
}
|
|
36418
|
-
function parseJson2(
|
|
36474
|
+
function parseJson2(text3) {
|
|
36419
36475
|
try {
|
|
36420
|
-
const parsed = JSON.parse(
|
|
36476
|
+
const parsed = JSON.parse(text3);
|
|
36421
36477
|
return parsed;
|
|
36422
36478
|
} catch {
|
|
36423
36479
|
return void 0;
|
|
@@ -36465,26 +36521,26 @@ function createSseScanner() {
|
|
|
36465
36521
|
return void 0;
|
|
36466
36522
|
};
|
|
36467
36523
|
const completeLine = (complete) => {
|
|
36468
|
-
const
|
|
36469
|
-
if (
|
|
36524
|
+
const text3 = complete.endsWith("\r") ? complete.slice(0, -1) : complete;
|
|
36525
|
+
if (text3 === "") {
|
|
36470
36526
|
dispatch();
|
|
36471
36527
|
return;
|
|
36472
36528
|
}
|
|
36473
|
-
if (
|
|
36474
|
-
eventName =
|
|
36529
|
+
if (text3.startsWith("event:")) {
|
|
36530
|
+
eventName = text3.slice("event:".length).trim();
|
|
36475
36531
|
return;
|
|
36476
36532
|
}
|
|
36477
|
-
if (
|
|
36478
|
-
const value2 =
|
|
36533
|
+
if (text3.startsWith("data:")) {
|
|
36534
|
+
const value2 = text3.slice("data:".length);
|
|
36479
36535
|
data.push(value2.startsWith(" ") ? value2.slice(1) : value2);
|
|
36480
36536
|
}
|
|
36481
36537
|
};
|
|
36482
36538
|
return {
|
|
36483
|
-
push: (
|
|
36539
|
+
push: (text3) => {
|
|
36484
36540
|
let start = 0;
|
|
36485
36541
|
for (; ; ) {
|
|
36486
|
-
const newline =
|
|
36487
|
-
const piece = newline === -1 ?
|
|
36542
|
+
const newline = text3.indexOf("\n", start);
|
|
36543
|
+
const piece = newline === -1 ? text3.slice(start) : text3.slice(start, newline);
|
|
36488
36544
|
if (!skipping) {
|
|
36489
36545
|
line += piece;
|
|
36490
36546
|
if (worthKeeping(line) === false) {
|
|
@@ -36598,8 +36654,8 @@ function createJsonScanner() {
|
|
|
36598
36654
|
}
|
|
36599
36655
|
};
|
|
36600
36656
|
return {
|
|
36601
|
-
push: (
|
|
36602
|
-
for (const char of
|
|
36657
|
+
push: (text3) => {
|
|
36658
|
+
for (const char of text3) {
|
|
36603
36659
|
step2(char);
|
|
36604
36660
|
}
|
|
36605
36661
|
},
|
|
@@ -36726,13 +36782,13 @@ function createUsageMiddleware(deps) {
|
|
|
36726
36782
|
const scanner = scannerFor(event.headers);
|
|
36727
36783
|
const decoder = scanner === void 0 ? null : decoderFor(headerValue(event.headers, "content-encoding"));
|
|
36728
36784
|
let scanning = scanner !== void 0 && decoder !== void 0;
|
|
36729
|
-
const
|
|
36785
|
+
const text3 = new TextDecoder();
|
|
36730
36786
|
const feed = (bytes, final) => {
|
|
36731
36787
|
if (!scanning || scanner === void 0) {
|
|
36732
36788
|
return;
|
|
36733
36789
|
}
|
|
36734
36790
|
try {
|
|
36735
|
-
scanner.push(
|
|
36791
|
+
scanner.push(text3.decode(bytes, { stream: !final }));
|
|
36736
36792
|
} catch (error63) {
|
|
36737
36793
|
scanning = false;
|
|
36738
36794
|
deps.log(`usage: body scan failed for ${event.route}: ${error63 instanceof Error ? error63.message : String(error63)}`);
|
|
@@ -37143,8 +37199,8 @@ function segmentDay(epochMs) {
|
|
|
37143
37199
|
function segmentName(day, pid) {
|
|
37144
37200
|
return `${day}.${String(pid)}.jsonl`;
|
|
37145
37201
|
}
|
|
37146
|
-
function listLogSegments(
|
|
37147
|
-
return
|
|
37202
|
+
function listLogSegments(fs30, logDir) {
|
|
37203
|
+
return fs30.readdir(logDir).flatMap((name) => {
|
|
37148
37204
|
const match = SEGMENT_RE.exec(name);
|
|
37149
37205
|
const day = match?.[1];
|
|
37150
37206
|
if (day === void 0) {
|
|
@@ -37153,15 +37209,15 @@ function listLogSegments(fs29, logDir) {
|
|
|
37153
37209
|
return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
|
|
37154
37210
|
}).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
|
|
37155
37211
|
}
|
|
37156
|
-
function readUsageLog(
|
|
37212
|
+
function readUsageLog(fs30, logDir, options = {}) {
|
|
37157
37213
|
const { sinceMs } = options;
|
|
37158
37214
|
const records = [];
|
|
37159
37215
|
let invalidLines = 0;
|
|
37160
|
-
for (const segment of listLogSegments(
|
|
37216
|
+
for (const segment of listLogSegments(fs30, logDir)) {
|
|
37161
37217
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
37162
37218
|
continue;
|
|
37163
37219
|
}
|
|
37164
|
-
const contents =
|
|
37220
|
+
const contents = fs30.readFileUtf8(import_node_path26.default.join(logDir, segment.name));
|
|
37165
37221
|
if (contents === void 0) {
|
|
37166
37222
|
continue;
|
|
37167
37223
|
}
|
|
@@ -37197,9 +37253,9 @@ function snapshotPath(snapshotsDir, identity) {
|
|
|
37197
37253
|
}
|
|
37198
37254
|
return import_node_path26.default.join(snapshotsDir, `${identity}.json`);
|
|
37199
37255
|
}
|
|
37200
|
-
function readUsageSnapshot(
|
|
37256
|
+
function readUsageSnapshot(fs30, snapshotsDir, identity) {
|
|
37201
37257
|
const file2 = snapshotPath(snapshotsDir, identity);
|
|
37202
|
-
const raw =
|
|
37258
|
+
const raw = fs30.readFileUtf8(file2);
|
|
37203
37259
|
if (raw === void 0) {
|
|
37204
37260
|
return void 0;
|
|
37205
37261
|
}
|
|
@@ -37215,8 +37271,8 @@ function readUsageSnapshot(fs29, snapshotsDir, identity) {
|
|
|
37215
37271
|
}
|
|
37216
37272
|
return snapshot.data;
|
|
37217
37273
|
}
|
|
37218
|
-
function listUsageSnapshots(
|
|
37219
|
-
return
|
|
37274
|
+
function listUsageSnapshots(fs30, snapshotsDir) {
|
|
37275
|
+
return fs30.readdir(snapshotsDir).flatMap((name) => {
|
|
37220
37276
|
if (!name.endsWith(".json")) {
|
|
37221
37277
|
return [];
|
|
37222
37278
|
}
|
|
@@ -37224,7 +37280,7 @@ function listUsageSnapshots(fs29, snapshotsDir) {
|
|
|
37224
37280
|
if (!isIdentityName(identity)) {
|
|
37225
37281
|
return [];
|
|
37226
37282
|
}
|
|
37227
|
-
const snapshot = readUsageSnapshot(
|
|
37283
|
+
const snapshot = readUsageSnapshot(fs30, snapshotsDir, identity);
|
|
37228
37284
|
return snapshot === void 0 ? [] : [snapshot];
|
|
37229
37285
|
}).sort((left, right) => left.identity.localeCompare(right.identity));
|
|
37230
37286
|
}
|
|
@@ -37298,11 +37354,11 @@ var init_read = __esm({
|
|
|
37298
37354
|
});
|
|
37299
37355
|
|
|
37300
37356
|
// src/usage/store.ts
|
|
37301
|
-
function pruneUsageLog(
|
|
37357
|
+
function pruneUsageLog(fs30, logDir, nowMs) {
|
|
37302
37358
|
const cutoff = nowMs - USAGE_RETENTION_MS;
|
|
37303
|
-
for (const segment of listLogSegments(
|
|
37359
|
+
for (const segment of listLogSegments(fs30, logDir)) {
|
|
37304
37360
|
if (segment.endsAt <= cutoff) {
|
|
37305
|
-
|
|
37361
|
+
fs30.removeRecursive(import_node_path27.default.join(logDir, segment.name));
|
|
37306
37362
|
}
|
|
37307
37363
|
}
|
|
37308
37364
|
}
|
|
@@ -37331,7 +37387,7 @@ function foldProviderState(current, record2) {
|
|
|
37331
37387
|
};
|
|
37332
37388
|
}
|
|
37333
37389
|
function createUsageStore(deps) {
|
|
37334
|
-
const { fs:
|
|
37390
|
+
const { fs: fs30, paths } = deps;
|
|
37335
37391
|
let prunedDay;
|
|
37336
37392
|
const rewriteSnapshot = (identity, fold) => {
|
|
37337
37393
|
if (!isIdentityName(identity)) {
|
|
@@ -37340,7 +37396,7 @@ function createUsageStore(deps) {
|
|
|
37340
37396
|
}
|
|
37341
37397
|
let current;
|
|
37342
37398
|
try {
|
|
37343
|
-
current = readUsageSnapshot(
|
|
37399
|
+
current = readUsageSnapshot(fs30, paths.usageSnapshotsDir, identity);
|
|
37344
37400
|
} catch (error63) {
|
|
37345
37401
|
if (!(error63 instanceof UsageSnapshotError)) {
|
|
37346
37402
|
throw error63;
|
|
@@ -37367,8 +37423,8 @@ function createUsageStore(deps) {
|
|
|
37367
37423
|
...account === void 0 ? {} : { account },
|
|
37368
37424
|
providers
|
|
37369
37425
|
});
|
|
37370
|
-
|
|
37371
|
-
|
|
37426
|
+
fs30.mkdirPrivate(paths.usageSnapshotsDir);
|
|
37427
|
+
fs30.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
|
|
37372
37428
|
`);
|
|
37373
37429
|
deps.publish?.(snapshot);
|
|
37374
37430
|
return true;
|
|
@@ -37377,14 +37433,14 @@ function createUsageStore(deps) {
|
|
|
37377
37433
|
record: (input2) => {
|
|
37378
37434
|
const record2 = UsageRecordSchema.parse(input2);
|
|
37379
37435
|
const nowMs = deps.now();
|
|
37380
|
-
|
|
37381
|
-
|
|
37436
|
+
fs30.mkdirPrivate(paths.usageDir);
|
|
37437
|
+
fs30.mkdirPrivate(paths.usageLogDir);
|
|
37382
37438
|
const day = segmentDay(nowMs);
|
|
37383
37439
|
if (prunedDay !== day) {
|
|
37384
|
-
pruneUsageLog(
|
|
37440
|
+
pruneUsageLog(fs30, paths.usageLogDir, nowMs);
|
|
37385
37441
|
prunedDay = day;
|
|
37386
37442
|
}
|
|
37387
|
-
|
|
37443
|
+
fs30.appendFilePrivate(import_node_path27.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
|
|
37388
37444
|
`);
|
|
37389
37445
|
deps.onRecord?.(record2);
|
|
37390
37446
|
if (record2.identity !== void 0) {
|
|
@@ -37427,14 +37483,14 @@ var init_store2 = __esm({
|
|
|
37427
37483
|
function errorMessage(error63) {
|
|
37428
37484
|
return error63 instanceof Error ? error63.message : String(error63);
|
|
37429
37485
|
}
|
|
37430
|
-
function loadPoolMembers(
|
|
37486
|
+
function loadPoolMembers(fs30, paths, identities, nowMs) {
|
|
37431
37487
|
const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
|
|
37432
|
-
const log = readUsageLog(
|
|
37488
|
+
const log = readUsageLog(fs30, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
37433
37489
|
return identities.map((identity) => {
|
|
37434
37490
|
const records = log.records.filter((record2) => record2.identity === identity && record2.provider === ANTHROPIC_PROVIDER && Date.parse(record2.at) >= windowStartMs);
|
|
37435
37491
|
try {
|
|
37436
|
-
const snapshot = readUsageSnapshot(
|
|
37437
|
-
const account = readAccountMetadata(
|
|
37492
|
+
const snapshot = readUsageSnapshot(fs30, paths.usageSnapshotsDir, identity);
|
|
37493
|
+
const account = readAccountMetadata(fs30, paths.identitiesDir, identity) ?? snapshot?.account;
|
|
37438
37494
|
return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
|
|
37439
37495
|
} catch (error63) {
|
|
37440
37496
|
if (error63 instanceof UsageSnapshotError || error63 instanceof AccountMetadataError) {
|
|
@@ -37507,9 +37563,9 @@ function nestedMember(input2, nestedName, childStack, sticky) {
|
|
|
37507
37563
|
missing: nested.missing
|
|
37508
37564
|
};
|
|
37509
37565
|
}
|
|
37510
|
-
function readPicksFile(
|
|
37566
|
+
function readPicksFile(fs30, file2) {
|
|
37511
37567
|
const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
|
|
37512
|
-
const raw =
|
|
37568
|
+
const raw = fs30.readFileUtf8(file2);
|
|
37513
37569
|
if (raw === void 0) {
|
|
37514
37570
|
return { file: empty };
|
|
37515
37571
|
}
|
|
@@ -37522,17 +37578,17 @@ function readPicksFile(fs29, file2) {
|
|
|
37522
37578
|
const result = PicksFileSchema.safeParse(parsed);
|
|
37523
37579
|
return result.success ? { file: result.data } : { file: empty, problem: `${file2} is not a picks file this agent-shim can read` };
|
|
37524
37580
|
}
|
|
37525
|
-
function readStickyPick(
|
|
37526
|
-
const read = readPicksFile(
|
|
37581
|
+
function readStickyPick(fs30, picksFile, directory) {
|
|
37582
|
+
const read = readPicksFile(fs30, picksFile);
|
|
37527
37583
|
const entry = read.file.picks[directory];
|
|
37528
37584
|
return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
|
|
37529
37585
|
}
|
|
37530
|
-
function recordStickyPick(
|
|
37531
|
-
const current = readPicksFile(
|
|
37586
|
+
function recordStickyPick(fs30, picksFile, directory, identity, nowMs) {
|
|
37587
|
+
const current = readPicksFile(fs30, picksFile).file.picks;
|
|
37532
37588
|
const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
|
|
37533
37589
|
const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
|
|
37534
|
-
|
|
37535
|
-
|
|
37590
|
+
fs30.mkdirPrivate(import_node_path28.default.dirname(picksFile));
|
|
37591
|
+
fs30.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
37536
37592
|
`);
|
|
37537
37593
|
}
|
|
37538
37594
|
var import_node_path28, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
@@ -38399,12 +38455,12 @@ function decideSignIn(facts) {
|
|
|
38399
38455
|
function credentialsFilePath(farmRoot) {
|
|
38400
38456
|
return import_node_path31.default.join(farmRoot, CREDENTIALS_FILE);
|
|
38401
38457
|
}
|
|
38402
|
-
function identitySignIn(
|
|
38458
|
+
function identitySignIn(fs30, probe, identity) {
|
|
38403
38459
|
const probing = !identity.hasCredentialBlock;
|
|
38404
38460
|
return decideSignIn({
|
|
38405
38461
|
hasCredentialBlock: identity.hasCredentialBlock,
|
|
38406
38462
|
keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
|
|
38407
|
-
credentialsFile: probing &&
|
|
38463
|
+
credentialsFile: probing && fs30.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
|
|
38408
38464
|
platform: probe.platform
|
|
38409
38465
|
});
|
|
38410
38466
|
}
|
|
@@ -51862,17 +51918,17 @@ var require_mock_call_history = __commonJS({
|
|
|
51862
51918
|
lastCall() {
|
|
51863
51919
|
return this.logs.at(-1);
|
|
51864
51920
|
}
|
|
51865
|
-
nthCall(
|
|
51866
|
-
if (typeof
|
|
51921
|
+
nthCall(number5) {
|
|
51922
|
+
if (typeof number5 !== "number") {
|
|
51867
51923
|
throw new InvalidArgumentError2("nthCall must be called with a number");
|
|
51868
51924
|
}
|
|
51869
|
-
if (!Number.isInteger(
|
|
51925
|
+
if (!Number.isInteger(number5)) {
|
|
51870
51926
|
throw new InvalidArgumentError2("nthCall must be called with an integer");
|
|
51871
51927
|
}
|
|
51872
|
-
if (Math.sign(
|
|
51928
|
+
if (Math.sign(number5) !== 1) {
|
|
51873
51929
|
throw new InvalidArgumentError2("nthCall must be called with a positive value. use firstCall or lastCall instead");
|
|
51874
51930
|
}
|
|
51875
|
-
return this.logs.at(
|
|
51931
|
+
return this.logs.at(number5 - 1);
|
|
51876
51932
|
}
|
|
51877
51933
|
filterCalls(criteria, options) {
|
|
51878
51934
|
if (this.logs.length === 0) {
|
|
@@ -64719,14 +64775,14 @@ var init_selfIdentity = __esm({
|
|
|
64719
64775
|
|
|
64720
64776
|
// src/frontdoor/trust.ts
|
|
64721
64777
|
function resolveTrustBundle(params) {
|
|
64722
|
-
const { caCertFile, bundlesDir, variable, inherited, fs:
|
|
64778
|
+
const { caCertFile, bundlesDir, variable, inherited, fs: fs30 } = params;
|
|
64723
64779
|
if (inherited === void 0 || inherited === "" || import_node_path38.default.resolve(inherited) === import_node_path38.default.resolve(caCertFile)) {
|
|
64724
64780
|
return { path: caCertFile };
|
|
64725
64781
|
}
|
|
64726
|
-
const caPem =
|
|
64782
|
+
const caPem = fs30.readFileUtf8(caCertFile);
|
|
64727
64783
|
let inheritedPem;
|
|
64728
64784
|
try {
|
|
64729
|
-
inheritedPem =
|
|
64785
|
+
inheritedPem = fs30.readFileUtf8(inherited);
|
|
64730
64786
|
} catch (error63) {
|
|
64731
64787
|
return {
|
|
64732
64788
|
path: caCertFile,
|
|
@@ -64739,9 +64795,9 @@ function resolveTrustBundle(params) {
|
|
|
64739
64795
|
const combined = `${inheritedPem.trimEnd()}
|
|
64740
64796
|
${caPem}`;
|
|
64741
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`);
|
|
64742
|
-
if (!
|
|
64743
|
-
|
|
64744
|
-
|
|
64798
|
+
if (!fs30.exists(bundle)) {
|
|
64799
|
+
fs30.mkdirp(bundlesDir);
|
|
64800
|
+
fs30.writeFileAtomic(bundle, combined);
|
|
64745
64801
|
}
|
|
64746
64802
|
return { path: bundle };
|
|
64747
64803
|
}
|
|
@@ -64918,20 +64974,20 @@ function lockHolder(contents) {
|
|
|
64918
64974
|
const pid = Number((contents ?? "").trim());
|
|
64919
64975
|
return Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
64920
64976
|
}
|
|
64921
|
-
function acquireUpdateLock(
|
|
64922
|
-
const take = () =>
|
|
64977
|
+
function acquireUpdateLock(fs30, isProcessAlive, pid, lockPath) {
|
|
64978
|
+
const take = () => fs30.writeFileExclusive(lockPath, `${String(pid)}
|
|
64923
64979
|
`);
|
|
64924
64980
|
const release = () => {
|
|
64925
|
-
|
|
64981
|
+
fs30.unlink(lockPath);
|
|
64926
64982
|
};
|
|
64927
64983
|
if (take()) {
|
|
64928
64984
|
return release;
|
|
64929
64985
|
}
|
|
64930
|
-
const holder = lockHolder(
|
|
64986
|
+
const holder = lockHolder(fs30.readFileUtf8(lockPath));
|
|
64931
64987
|
if (holder !== void 0 && holder !== pid && isProcessAlive(holder)) {
|
|
64932
64988
|
throw new UpdateConflictError(`another agent-shim update (pid ${String(holder)}) is already running`);
|
|
64933
64989
|
}
|
|
64934
|
-
|
|
64990
|
+
fs30.unlink(lockPath);
|
|
64935
64991
|
if (!take()) {
|
|
64936
64992
|
throw new UpdateConflictError("another agent-shim update took the lock while it was being replaced");
|
|
64937
64993
|
}
|
|
@@ -65696,8 +65752,8 @@ function countOf(usage, key) {
|
|
|
65696
65752
|
const value2 = key in usage ? Reflect.get(usage, key) : void 0;
|
|
65697
65753
|
return typeof value2 === "number" && Number.isFinite(value2) && value2 >= 0 ? value2 : 0;
|
|
65698
65754
|
}
|
|
65699
|
-
function contextTokensOfTranscript(
|
|
65700
|
-
const lines =
|
|
65755
|
+
function contextTokensOfTranscript(text3) {
|
|
65756
|
+
const lines = text3.split("\n");
|
|
65701
65757
|
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
65702
65758
|
const line = lines[index];
|
|
65703
65759
|
if (line === void 0 || line === "") {
|
|
@@ -65721,15 +65777,15 @@ function contextTokensOfTranscript(text2) {
|
|
|
65721
65777
|
}
|
|
65722
65778
|
return void 0;
|
|
65723
65779
|
}
|
|
65724
|
-
function newestTranscript(
|
|
65780
|
+
function newestTranscript(fs30, projectDir) {
|
|
65725
65781
|
let newest;
|
|
65726
65782
|
let newestMs = -Infinity;
|
|
65727
|
-
for (const name of
|
|
65783
|
+
for (const name of fs30.readdir(projectDir)) {
|
|
65728
65784
|
if (!name.endsWith(".jsonl")) {
|
|
65729
65785
|
continue;
|
|
65730
65786
|
}
|
|
65731
65787
|
const candidate = import_node_path43.default.join(projectDir, name);
|
|
65732
|
-
const stat =
|
|
65788
|
+
const stat = fs30.lstat(candidate);
|
|
65733
65789
|
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
65734
65790
|
newestMs = stat.mtimeMs;
|
|
65735
65791
|
newest = candidate;
|
|
@@ -65737,19 +65793,19 @@ function newestTranscript(fs29, projectDir) {
|
|
|
65737
65793
|
}
|
|
65738
65794
|
return newest;
|
|
65739
65795
|
}
|
|
65740
|
-
function latestConversationId(
|
|
65741
|
-
const file2 = newestTranscript(
|
|
65796
|
+
function latestConversationId(fs30, params) {
|
|
65797
|
+
const file2 = newestTranscript(fs30, import_node_path43.default.join(params.claudeHome, "projects", projectDirNameOf(params.cwd)));
|
|
65742
65798
|
return file2 === void 0 ? void 0 : import_node_path43.default.basename(file2, ".jsonl");
|
|
65743
65799
|
}
|
|
65744
|
-
function resumedContextTokens(
|
|
65800
|
+
function resumedContextTokens(fs30, params) {
|
|
65745
65801
|
const target = resumeTargetOf(params.passthrough);
|
|
65746
65802
|
if (target === void 0) {
|
|
65747
65803
|
return void 0;
|
|
65748
65804
|
}
|
|
65749
65805
|
const projectDir = import_node_path43.default.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
65750
|
-
const file2 = target.kind === "id" ? import_node_path43.default.join(projectDir, `${target.id}.jsonl`) : newestTranscript(
|
|
65751
|
-
const
|
|
65752
|
-
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);
|
|
65753
65809
|
}
|
|
65754
65810
|
var import_node_path43;
|
|
65755
65811
|
var init_resumeContext = __esm({
|
|
@@ -66012,8 +66068,8 @@ function farmRow(links, builtDirectories, adopted) {
|
|
|
66012
66068
|
const parts = [counted(links, "link", "links"), counted(builtDirectories, "built directory", "built directories"), ...adopted === 0 ? [] : [`${String(adopted)} adopted`]];
|
|
66013
66069
|
return { label: "farm", value: "resynced", detail: parts.join(", ") };
|
|
66014
66070
|
}
|
|
66015
|
-
function noteRow(
|
|
66016
|
-
return { label: "note", value:
|
|
66071
|
+
function noteRow(text3) {
|
|
66072
|
+
return { label: "note", value: text3 };
|
|
66017
66073
|
}
|
|
66018
66074
|
var init_launchReport = __esm({
|
|
66019
66075
|
"src/launcher/launchReport.ts"() {
|
|
@@ -66790,9 +66846,9 @@ function flattenToolResult(content) {
|
|
|
66790
66846
|
}
|
|
66791
66847
|
return content.map((block2) => isTextBlock(block2) ? block2.text : NON_TEXT_TOOL_RESULT).join("\n");
|
|
66792
66848
|
}
|
|
66793
|
-
function systemReminder(
|
|
66849
|
+
function systemReminder(text3) {
|
|
66794
66850
|
return `<system-reminder>
|
|
66795
|
-
${
|
|
66851
|
+
${text3}
|
|
66796
66852
|
</system-reminder>`;
|
|
66797
66853
|
}
|
|
66798
66854
|
function turnBlocks(message) {
|
|
@@ -67029,9 +67085,9 @@ function flattenToolResult2(content) {
|
|
|
67029
67085
|
}
|
|
67030
67086
|
return content.map((block2) => isTextBlock(block2) ? block2.text : NON_TEXT_TOOL_RESULT2).join("\n");
|
|
67031
67087
|
}
|
|
67032
|
-
function systemReminder2(
|
|
67088
|
+
function systemReminder2(text3) {
|
|
67033
67089
|
return `<system-reminder>
|
|
67034
|
-
${
|
|
67090
|
+
${text3}
|
|
67035
67091
|
</system-reminder>`;
|
|
67036
67092
|
}
|
|
67037
67093
|
function turnBlocks2(message) {
|
|
@@ -67156,12 +67212,12 @@ var init_translate2 = __esm({
|
|
|
67156
67212
|
function catalogueCachePath(paths, name) {
|
|
67157
67213
|
return import_node_path44.default.join(paths.catalogueDir, `${name}.json`);
|
|
67158
67214
|
}
|
|
67159
|
-
function parseCatalogueCache(
|
|
67160
|
-
if (
|
|
67215
|
+
function parseCatalogueCache(text3) {
|
|
67216
|
+
if (text3 === void 0) {
|
|
67161
67217
|
return void 0;
|
|
67162
67218
|
}
|
|
67163
67219
|
try {
|
|
67164
|
-
const parsed = CatalogueCacheSchema.safeParse(JSON.parse(
|
|
67220
|
+
const parsed = CatalogueCacheSchema.safeParse(JSON.parse(text3));
|
|
67165
67221
|
return parsed.success ? parsed.data : void 0;
|
|
67166
67222
|
} catch {
|
|
67167
67223
|
return void 0;
|
|
@@ -67778,7 +67834,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
|
|
|
67778
67834
|
return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
|
|
67779
67835
|
}
|
|
67780
67836
|
function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
67781
|
-
const { paths, fs:
|
|
67837
|
+
const { paths, fs: fs30, proc, log } = params;
|
|
67782
67838
|
if (decided.pool === void 0) {
|
|
67783
67839
|
return { identityDecision: decided };
|
|
67784
67840
|
}
|
|
@@ -67797,7 +67853,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
67797
67853
|
selectedVia: decided.source,
|
|
67798
67854
|
pools: params.pools,
|
|
67799
67855
|
paths,
|
|
67800
|
-
fs:
|
|
67856
|
+
fs: fs30,
|
|
67801
67857
|
usageFs: farmRuntime.fs,
|
|
67802
67858
|
cwd: farmRuntime.cwd,
|
|
67803
67859
|
now: farmRuntime.now,
|
|
@@ -67820,7 +67876,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
67820
67876
|
};
|
|
67821
67877
|
}
|
|
67822
67878
|
function decideLaunch(params, readOnly) {
|
|
67823
|
-
const { paths, fs:
|
|
67879
|
+
const { paths, fs: fs30, proc, log } = params;
|
|
67824
67880
|
const { env, argv } = proc;
|
|
67825
67881
|
const parsedArgv = parseLauncherArgv(argv);
|
|
67826
67882
|
const cliOverride = buildCliOverride({
|
|
@@ -67835,7 +67891,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67835
67891
|
argv0Identity: parsedArgv.identity,
|
|
67836
67892
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
67837
67893
|
readActiveIdentityFile: () => {
|
|
67838
|
-
const raw =
|
|
67894
|
+
const raw = fs30.readFileUtf8(paths.activeIdentityFile);
|
|
67839
67895
|
if (raw === void 0) {
|
|
67840
67896
|
return void 0;
|
|
67841
67897
|
}
|
|
@@ -67870,7 +67926,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67870
67926
|
}
|
|
67871
67927
|
let loadedIdentity;
|
|
67872
67928
|
if (identityDecision.name !== void 0) {
|
|
67873
|
-
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name,
|
|
67929
|
+
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs30);
|
|
67874
67930
|
if (loadedIdentity === void 0) {
|
|
67875
67931
|
log.error(
|
|
67876
67932
|
`agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
|
|
@@ -67885,7 +67941,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67885
67941
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
67886
67942
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
67887
67943
|
});
|
|
67888
|
-
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) {
|
|
67889
67945
|
log.error(
|
|
67890
67946
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
67891
67947
|
);
|
|
@@ -67894,7 +67950,7 @@ function decideLaunch(params, readOnly) {
|
|
|
67894
67950
|
const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
|
|
67895
67951
|
const providerParams = {
|
|
67896
67952
|
paths,
|
|
67897
|
-
port:
|
|
67953
|
+
port: fs30,
|
|
67898
67954
|
...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
|
|
67899
67955
|
...farmContext === void 0 ? {} : { cascade: farmContext.cascade }
|
|
67900
67956
|
};
|
|
@@ -67993,9 +68049,9 @@ function decideLaunch(params, readOnly) {
|
|
|
67993
68049
|
const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
|
|
67994
68050
|
const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
|
|
67995
68051
|
const models = launchCascade !== void 0 && params.farm !== void 0 ? cascadeModels : globalModels;
|
|
67996
|
-
const listedProviders = listProviderNames(
|
|
68052
|
+
const listedProviders = listProviderNames(fs30.readdir, paths.providersDir).flatMap((name) => {
|
|
67997
68053
|
try {
|
|
67998
|
-
const definition = loadProvider(paths.providersDir, name,
|
|
68054
|
+
const definition = loadProvider(paths.providersDir, name, fs30);
|
|
67999
68055
|
return definition === void 0 ? [] : [[name, definition, parseCatalogueCache(params.fs.readFileUtf8(catalogueCachePath(paths, name)))?.models ?? []]];
|
|
68000
68056
|
} catch {
|
|
68001
68057
|
return [];
|
|
@@ -106911,7 +106967,7 @@ var require_core2 = __commonJS({
|
|
|
106911
106967
|
errorsText(errors = this.errors, { separator = ", ", dataVar = "data" } = {}) {
|
|
106912
106968
|
if (!errors || errors.length === 0)
|
|
106913
106969
|
return "No errors";
|
|
106914
|
-
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);
|
|
106915
106971
|
}
|
|
106916
106972
|
$dataMetaSchema(metaSchema, keywordsJsonPointers) {
|
|
106917
106973
|
const rules = this.RULES.all;
|
|
@@ -109472,12 +109528,12 @@ var require_dist2 = __commonJS({
|
|
|
109472
109528
|
throw new Error(`Unknown format "${name}"`);
|
|
109473
109529
|
return f;
|
|
109474
109530
|
};
|
|
109475
|
-
function addFormats(ajv, list,
|
|
109531
|
+
function addFormats(ajv, list, fs30, exportName) {
|
|
109476
109532
|
var _a4;
|
|
109477
109533
|
var _b2;
|
|
109478
109534
|
(_a4 = (_b2 = ajv.opts.code).formats) !== null && _a4 !== void 0 ? _a4 : _b2.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
109479
109535
|
for (const f of list)
|
|
109480
|
-
ajv.addFormat(f,
|
|
109536
|
+
ajv.addFormat(f, fs30[f]);
|
|
109481
109537
|
}
|
|
109482
109538
|
module2.exports = exports2 = formatsPlugin;
|
|
109483
109539
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -112618,9 +112674,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
112618
112674
|
helpWidth: context.helpWidth,
|
|
112619
112675
|
outputHasColors: context.hasColors
|
|
112620
112676
|
});
|
|
112621
|
-
const
|
|
112622
|
-
if (context.hasColors) return
|
|
112623
|
-
return this._outputConfiguration.stripColor(
|
|
112677
|
+
const text3 = helper.formatHelp(this, helper);
|
|
112678
|
+
if (context.hasColors) return text3;
|
|
112679
|
+
return this._outputConfiguration.stripColor(text3);
|
|
112624
112680
|
}
|
|
112625
112681
|
/**
|
|
112626
112682
|
* @typedef HelpContext
|
|
@@ -112780,7 +112836,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
112780
112836
|
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
112781
112837
|
* @return {Command} `this` command for chaining
|
|
112782
112838
|
*/
|
|
112783
|
-
addHelpText(position,
|
|
112839
|
+
addHelpText(position, text3) {
|
|
112784
112840
|
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
112785
112841
|
if (!allowedValues.includes(position)) {
|
|
112786
112842
|
throw new Error(`Unexpected value for position to addHelpText.
|
|
@@ -112789,10 +112845,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
112789
112845
|
const helpEvent = `${position}Help`;
|
|
112790
112846
|
this.on(helpEvent, (context) => {
|
|
112791
112847
|
let helpStr;
|
|
112792
|
-
if (typeof
|
|
112793
|
-
helpStr =
|
|
112848
|
+
if (typeof text3 === "function") {
|
|
112849
|
+
helpStr = text3({ error: context.error, command: context.command });
|
|
112794
112850
|
} else {
|
|
112795
|
-
helpStr =
|
|
112851
|
+
helpStr = text3;
|
|
112796
112852
|
}
|
|
112797
112853
|
if (helpStr) {
|
|
112798
112854
|
context.write(`${helpStr}
|
|
@@ -117224,17 +117280,17 @@ function parseEntry2(project, entry) {
|
|
|
117224
117280
|
const base = match?.[1];
|
|
117225
117281
|
return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
|
|
117226
117282
|
}
|
|
117227
|
-
function listSessions2(
|
|
117283
|
+
function listSessions2(fs30, configDir) {
|
|
117228
117284
|
const found = [];
|
|
117229
|
-
for (const project of
|
|
117285
|
+
for (const project of fs30.readdir(import_node_path35.default.join(configDir, PROJECTS_DIR))) {
|
|
117230
117286
|
const projectDir = import_node_path35.default.join(configDir, PROJECTS_DIR, project);
|
|
117231
117287
|
const entries = /* @__PURE__ */ new Set();
|
|
117232
|
-
for (const name of
|
|
117288
|
+
for (const name of fs30.readdir(projectDir)) {
|
|
117233
117289
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
117234
117290
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
117235
117291
|
continue;
|
|
117236
117292
|
}
|
|
117237
|
-
const children =
|
|
117293
|
+
const children = fs30.readdir(import_node_path35.default.join(projectDir, name));
|
|
117238
117294
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
117239
117295
|
entries.add(name);
|
|
117240
117296
|
}
|
|
@@ -117245,9 +117301,9 @@ function listSessions2(fs29, configDir) {
|
|
|
117245
117301
|
}
|
|
117246
117302
|
return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
|
|
117247
117303
|
}
|
|
117248
|
-
function locateAgents(
|
|
117304
|
+
function locateAgents(fs30, configDir, relativeDir, workflowRunId, report) {
|
|
117249
117305
|
const located = [];
|
|
117250
|
-
for (const name of listDirOrReport(
|
|
117306
|
+
for (const name of listDirOrReport(fs30, configDir, relativeDir, report)) {
|
|
117251
117307
|
if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
|
|
117252
117308
|
continue;
|
|
117253
117309
|
}
|
|
@@ -117296,25 +117352,25 @@ function toNode(read, children) {
|
|
|
117296
117352
|
function describeFailure(error63) {
|
|
117297
117353
|
return error63 instanceof Error ? error63.message : String(error63);
|
|
117298
117354
|
}
|
|
117299
|
-
function readFileOrReport(
|
|
117355
|
+
function readFileOrReport(fs30, configDir, relative, report) {
|
|
117300
117356
|
try {
|
|
117301
|
-
return
|
|
117357
|
+
return fs30.readFileUtf8(import_node_path35.default.join(configDir, relative));
|
|
117302
117358
|
} catch (error63) {
|
|
117303
117359
|
report({ path: relative, reason: `could not be read: ${describeFailure(error63)}` });
|
|
117304
117360
|
return void 0;
|
|
117305
117361
|
}
|
|
117306
117362
|
}
|
|
117307
|
-
function listDirOrReport(
|
|
117363
|
+
function listDirOrReport(fs30, configDir, relative, report) {
|
|
117308
117364
|
try {
|
|
117309
|
-
return
|
|
117365
|
+
return fs30.readdir(import_node_path35.default.join(configDir, relative));
|
|
117310
117366
|
} catch (error63) {
|
|
117311
117367
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error63)}` });
|
|
117312
117368
|
return [];
|
|
117313
117369
|
}
|
|
117314
117370
|
}
|
|
117315
|
-
function parseJson3(
|
|
117371
|
+
function parseJson3(text3) {
|
|
117316
117372
|
try {
|
|
117317
|
-
const value2 = JSON.parse(
|
|
117373
|
+
const value2 = JSON.parse(text3);
|
|
117318
117374
|
return value2;
|
|
117319
117375
|
} catch {
|
|
117320
117376
|
return void 0;
|
|
@@ -117329,22 +117385,22 @@ var WorkflowRunFileSchema = external_exports.object({
|
|
|
117329
117385
|
phases: external_exports.array(external_exports.object({ title: external_exports.string() })).default([]),
|
|
117330
117386
|
summary: external_exports.string().optional()
|
|
117331
117387
|
});
|
|
117332
|
-
function summariseSession(
|
|
117388
|
+
function summariseSession(fs30, configDir, ref) {
|
|
117333
117389
|
const sessionRelative = import_node_path35.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
117334
117390
|
const subagentsRelative = import_node_path35.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
117335
117391
|
const workflowsUnderSubagents = import_node_path35.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
117336
117392
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
117337
|
-
let agentCount =
|
|
117338
|
-
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))) {
|
|
117339
117395
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
117340
|
-
agentCount +=
|
|
117396
|
+
agentCount += fs30.readdir(import_node_path35.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
117341
117397
|
}
|
|
117342
117398
|
}
|
|
117343
|
-
const workflowRunCount =
|
|
117344
|
-
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}`));
|
|
117345
117401
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
117346
117402
|
}
|
|
117347
|
-
function readSessionAgentTree(
|
|
117403
|
+
function readSessionAgentTree(fs30, configDir, ref, options = {}) {
|
|
117348
117404
|
const problems = [];
|
|
117349
117405
|
const report = (problem) => {
|
|
117350
117406
|
problems.push(problem);
|
|
@@ -117352,19 +117408,19 @@ function readSessionAgentTree(fs29, configDir, ref, options = {}) {
|
|
|
117352
117408
|
const sessionRelative = import_node_path35.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
117353
117409
|
const subagentsRelative = import_node_path35.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
117354
117410
|
const workflowsUnderSubagents = import_node_path35.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
117355
|
-
const located = locateAgents(
|
|
117356
|
-
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)) {
|
|
117357
117413
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
117358
|
-
located.push(...locateAgents(
|
|
117414
|
+
located.push(...locateAgents(fs30, configDir, import_node_path35.default.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
117359
117415
|
}
|
|
117360
117416
|
}
|
|
117361
117417
|
const agents = /* @__PURE__ */ new Map();
|
|
117362
117418
|
for (const candidate of located) {
|
|
117363
|
-
const
|
|
117364
|
-
if (
|
|
117419
|
+
const text3 = readFileOrReport(fs30, configDir, candidate.metaPath, report);
|
|
117420
|
+
if (text3 === void 0) {
|
|
117365
117421
|
continue;
|
|
117366
117422
|
}
|
|
117367
|
-
const parsed = AgentMetaSchema.safeParse(parseJson3(
|
|
117423
|
+
const parsed = AgentMetaSchema.safeParse(parseJson3(text3));
|
|
117368
117424
|
if (!parsed.success) {
|
|
117369
117425
|
report({ path: candidate.metaPath, reason: "meta file is not a JSON object with an agentType" });
|
|
117370
117426
|
continue;
|
|
@@ -117372,7 +117428,7 @@ function readSessionAgentTree(fs29, configDir, ref, options = {}) {
|
|
|
117372
117428
|
agents.set(candidate.id, { located: candidate, meta: parsed.data });
|
|
117373
117429
|
}
|
|
117374
117430
|
const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
|
|
117375
|
-
const parentOf4 = resolveParents(
|
|
117431
|
+
const parentOf4 = resolveParents(fs30, configDir, agents, report);
|
|
117376
117432
|
const childrenOf = /* @__PURE__ */ new Map();
|
|
117377
117433
|
const roots = [];
|
|
117378
117434
|
for (const id2 of agents.keys()) {
|
|
@@ -117395,12 +117451,12 @@ function readSessionAgentTree(fs29, configDir, ref, options = {}) {
|
|
|
117395
117451
|
sessionId: ref.sessionId,
|
|
117396
117452
|
superseded: ref.superseded,
|
|
117397
117453
|
agents: roots.sort().map(build),
|
|
117398
|
-
tasks: readTasks(
|
|
117399
|
-
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),
|
|
117400
117456
|
problems
|
|
117401
117457
|
};
|
|
117402
117458
|
}
|
|
117403
|
-
function resolveParents(
|
|
117459
|
+
function resolveParents(fs30, configDir, agents, report) {
|
|
117404
117460
|
const parentOf4 = /* @__PURE__ */ new Map();
|
|
117405
117461
|
const transcriptCache = /* @__PURE__ */ new Map();
|
|
117406
117462
|
const transcriptOf = (agent) => {
|
|
@@ -117408,9 +117464,9 @@ function resolveParents(fs29, configDir, agents, report) {
|
|
|
117408
117464
|
if (cached2 !== void 0) {
|
|
117409
117465
|
return cached2;
|
|
117410
117466
|
}
|
|
117411
|
-
const
|
|
117412
|
-
transcriptCache.set(agent.located.id,
|
|
117413
|
-
return
|
|
117467
|
+
const text3 = readFileOrReport(fs30, configDir, agent.located.transcriptPath, report) ?? "";
|
|
117468
|
+
transcriptCache.set(agent.located.id, text3);
|
|
117469
|
+
return text3;
|
|
117414
117470
|
};
|
|
117415
117471
|
const wouldCycle = (child, parent) => {
|
|
117416
117472
|
for (let cursor3 = parent; cursor3 !== void 0; cursor3 = parentOf4.get(cursor3)) {
|
|
@@ -117458,37 +117514,37 @@ function resolveParents(fs29, configDir, agents, report) {
|
|
|
117458
117514
|
function ownTaskLists(sessionId) {
|
|
117459
117515
|
return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
|
|
117460
117516
|
}
|
|
117461
|
-
function readTasks(
|
|
117517
|
+
function readTasks(fs30, configDir, ownLists, sharedLists, report) {
|
|
117462
117518
|
const tasks = [];
|
|
117463
117519
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
117464
117520
|
const relativeDir = import_node_path35.default.join(TASKS_DIR, scope);
|
|
117465
|
-
for (const name of [...listDirOrReport(
|
|
117521
|
+
for (const name of [...listDirOrReport(fs30, configDir, relativeDir, report)].sort()) {
|
|
117466
117522
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
117467
117523
|
continue;
|
|
117468
117524
|
}
|
|
117469
117525
|
const relative = import_node_path35.default.join(relativeDir, name);
|
|
117470
|
-
const
|
|
117471
|
-
const parsed = TaskFileSchema.safeParse(
|
|
117526
|
+
const text3 = readFileOrReport(fs30, configDir, relative, report);
|
|
117527
|
+
const parsed = TaskFileSchema.safeParse(text3 === void 0 ? void 0 : parseJson3(text3));
|
|
117472
117528
|
if (parsed.success) {
|
|
117473
117529
|
tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
|
|
117474
|
-
} else if (
|
|
117530
|
+
} else if (text3 !== void 0) {
|
|
117475
117531
|
report({ path: relative, reason: "task file is not a task" });
|
|
117476
117532
|
}
|
|
117477
117533
|
}
|
|
117478
117534
|
});
|
|
117479
117535
|
return tasks;
|
|
117480
117536
|
}
|
|
117481
|
-
function readWorkflowRuns(
|
|
117537
|
+
function readWorkflowRuns(fs30, configDir, relativeDir, report) {
|
|
117482
117538
|
const runs = [];
|
|
117483
|
-
for (const name of [...listDirOrReport(
|
|
117539
|
+
for (const name of [...listDirOrReport(fs30, configDir, relativeDir, report)].sort()) {
|
|
117484
117540
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
117485
117541
|
continue;
|
|
117486
117542
|
}
|
|
117487
117543
|
const relative = import_node_path35.default.join(relativeDir, name);
|
|
117488
|
-
const
|
|
117489
|
-
const parsed = WorkflowRunFileSchema.safeParse(
|
|
117544
|
+
const text3 = readFileOrReport(fs30, configDir, relative, report);
|
|
117545
|
+
const parsed = WorkflowRunFileSchema.safeParse(text3 === void 0 ? void 0 : parseJson3(text3));
|
|
117490
117546
|
if (!parsed.success) {
|
|
117491
|
-
if (
|
|
117547
|
+
if (text3 !== void 0) {
|
|
117492
117548
|
report({ path: relative, reason: "workflow run file is not a run record" });
|
|
117493
117549
|
}
|
|
117494
117550
|
continue;
|
|
@@ -117509,11 +117565,11 @@ var SessionLookupError = class extends CliError {
|
|
|
117509
117565
|
function identityConfigDir(identitiesDir, identity) {
|
|
117510
117566
|
return import_node_path36.default.join(identitiesDir, identity);
|
|
117511
117567
|
}
|
|
117512
|
-
function historyStores(
|
|
117568
|
+
function historyStores(fs30, identitiesDir, identities) {
|
|
117513
117569
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
117514
117570
|
for (const identity of identities) {
|
|
117515
117571
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
117516
|
-
const real =
|
|
117572
|
+
const real = fs30.realpath(import_node_path36.default.join(configDir, "projects"));
|
|
117517
117573
|
if (real === void 0) {
|
|
117518
117574
|
continue;
|
|
117519
117575
|
}
|
|
@@ -117526,15 +117582,15 @@ function historyStores(fs29, identitiesDir, identities) {
|
|
|
117526
117582
|
}
|
|
117527
117583
|
return [...byRealPath.values()];
|
|
117528
117584
|
}
|
|
117529
|
-
function collectSessionList(
|
|
117585
|
+
function collectSessionList(fs30, identitiesDir, identities, filters) {
|
|
117530
117586
|
const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
|
|
117531
117587
|
if (filters.identity !== void 0 && names.length === 0) {
|
|
117532
117588
|
throw new SessionLookupError(`no identity named "${filters.identity}"`);
|
|
117533
117589
|
}
|
|
117534
117590
|
const sessions = [];
|
|
117535
|
-
for (const store of historyStores(
|
|
117536
|
-
for (const ref of listSessions2(
|
|
117537
|
-
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);
|
|
117538
117594
|
if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
|
|
117539
117595
|
sessions.push({ ...summary, identities: store.identities });
|
|
117540
117596
|
}
|
|
@@ -117542,14 +117598,14 @@ function collectSessionList(fs29, identitiesDir, identities, filters) {
|
|
|
117542
117598
|
}
|
|
117543
117599
|
return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
|
|
117544
117600
|
}
|
|
117545
|
-
function locateSession(
|
|
117601
|
+
function locateSession(fs30, identitiesDir, identities, query, onlyIdentity) {
|
|
117546
117602
|
const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
|
|
117547
117603
|
if (onlyIdentity !== void 0 && names.length === 0) {
|
|
117548
117604
|
throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
|
|
117549
117605
|
}
|
|
117550
117606
|
const matches = [];
|
|
117551
|
-
for (const store of historyStores(
|
|
117552
|
-
for (const ref of listSessions2(
|
|
117607
|
+
for (const store of historyStores(fs30, identitiesDir, names)) {
|
|
117608
|
+
for (const ref of listSessions2(fs30, store.configDir)) {
|
|
117553
117609
|
if (ref.sessionId.startsWith(query)) {
|
|
117554
117610
|
matches.push({ identities: store.identities, configDir: store.configDir, ref });
|
|
117555
117611
|
}
|
|
@@ -117566,9 +117622,9 @@ function locateSession(fs29, identitiesDir, identities, query, onlyIdentity) {
|
|
|
117566
117622
|
}
|
|
117567
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`);
|
|
117568
117624
|
}
|
|
117569
|
-
function showSession(
|
|
117570
|
-
const located = locateSession(
|
|
117571
|
-
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) };
|
|
117572
117628
|
}
|
|
117573
117629
|
|
|
117574
117630
|
// src/frontdoor/commands.ts
|
|
@@ -117614,13 +117670,13 @@ function stateDirOf(paths, pool) {
|
|
|
117614
117670
|
function sessionStatePath(paths, pool, sessionId) {
|
|
117615
117671
|
return import_node_path37.default.join(stateDirOf(paths, pool), `${sessionId}.json`);
|
|
117616
117672
|
}
|
|
117617
|
-
function writeSessionState(
|
|
117618
|
-
|
|
117619
|
-
|
|
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))}
|
|
117620
117676
|
`);
|
|
117621
117677
|
}
|
|
117622
|
-
function readSessionState(
|
|
117623
|
-
const raw =
|
|
117678
|
+
function readSessionState(fs30, paths, pool, sessionId) {
|
|
117679
|
+
const raw = fs30.readFileUtf8(sessionStatePath(paths, pool, sessionId));
|
|
117624
117680
|
if (raw === void 0) {
|
|
117625
117681
|
return void 0;
|
|
117626
117682
|
}
|
|
@@ -117631,20 +117687,20 @@ function readSessionState(fs29, paths, pool, sessionId) {
|
|
|
117631
117687
|
return void 0;
|
|
117632
117688
|
}
|
|
117633
117689
|
}
|
|
117634
|
-
function registerSupervised(
|
|
117635
|
-
|
|
117636
|
-
|
|
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))}
|
|
117637
117693
|
`);
|
|
117638
117694
|
}
|
|
117639
|
-
function unregisterSupervised(
|
|
117640
|
-
|
|
117641
|
-
|
|
117695
|
+
function unregisterSupervised(fs30, paths, pool, sessionId) {
|
|
117696
|
+
fs30.removeRecursive(sessionFileOf(paths, pool, sessionId));
|
|
117697
|
+
fs30.removeRecursive(sessionStatePath(paths, pool, sessionId));
|
|
117642
117698
|
}
|
|
117643
|
-
function liveSupervised(
|
|
117699
|
+
function liveSupervised(fs30, paths, pool, isRunning) {
|
|
117644
117700
|
const live = [];
|
|
117645
|
-
for (const name of
|
|
117701
|
+
for (const name of fs30.readdir(sessionsDirOf(paths, pool))) {
|
|
117646
117702
|
const file2 = import_node_path37.default.join(sessionsDirOf(paths, pool), name);
|
|
117647
|
-
const raw =
|
|
117703
|
+
const raw = fs30.readFileUtf8(file2);
|
|
117648
117704
|
if (raw === void 0) {
|
|
117649
117705
|
continue;
|
|
117650
117706
|
}
|
|
@@ -117652,13 +117708,13 @@ function liveSupervised(fs29, paths, pool, isRunning) {
|
|
|
117652
117708
|
try {
|
|
117653
117709
|
parsed = SupervisedSessionSchema.safeParse(JSON.parse(raw));
|
|
117654
117710
|
} catch {
|
|
117655
|
-
|
|
117711
|
+
fs30.removeRecursive(file2);
|
|
117656
117712
|
continue;
|
|
117657
117713
|
}
|
|
117658
117714
|
if (parsed.success && isRunning(parsed.data.pid)) {
|
|
117659
117715
|
live.push(parsed.data);
|
|
117660
117716
|
} else {
|
|
117661
|
-
|
|
117717
|
+
fs30.removeRecursive(file2);
|
|
117662
117718
|
}
|
|
117663
117719
|
}
|
|
117664
117720
|
return live;
|
|
@@ -117687,13 +117743,13 @@ var ModelMoveRequestSchema = external_exports.strictObject({
|
|
|
117687
117743
|
/** When the door wrote the request, so a supervisor can tell a fresh request from one left behind. */
|
|
117688
117744
|
at: external_exports.iso.datetime()
|
|
117689
117745
|
});
|
|
117690
|
-
function writeModelMove(
|
|
117691
|
-
|
|
117692
|
-
|
|
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))}
|
|
117693
117749
|
`);
|
|
117694
117750
|
}
|
|
117695
|
-
function readModelMove(
|
|
117696
|
-
const raw =
|
|
117751
|
+
function readModelMove(fs30, paths, sessionId) {
|
|
117752
|
+
const raw = fs30.readFileUtf8(import_node_path37.default.join(paths.modelMovesDir, `${sessionId}.json`));
|
|
117697
117753
|
if (raw === void 0) {
|
|
117698
117754
|
return void 0;
|
|
117699
117755
|
}
|
|
@@ -117703,12 +117759,12 @@ function readModelMove(fs29, paths, sessionId) {
|
|
|
117703
117759
|
return void 0;
|
|
117704
117760
|
}
|
|
117705
117761
|
}
|
|
117706
|
-
function removeModelMove(
|
|
117707
|
-
|
|
117762
|
+
function removeModelMove(fs30, paths, sessionId) {
|
|
117763
|
+
fs30.removeRecursive(import_node_path37.default.join(paths.modelMovesDir, `${sessionId}.json`));
|
|
117708
117764
|
}
|
|
117709
|
-
function supervisedSessionOf(
|
|
117710
|
-
for (const pool of
|
|
117711
|
-
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);
|
|
117712
117768
|
const found = sessions.find((session) => session.sessionId === sessionId);
|
|
117713
117769
|
if (found !== void 0) {
|
|
117714
117770
|
return found;
|
|
@@ -117766,9 +117822,9 @@ function blendedPricePerMTok(prices, mix) {
|
|
|
117766
117822
|
|
|
117767
117823
|
// src/selection/targetStore.ts
|
|
117768
117824
|
var SEED_LOOKBACK_RECORDS = 500;
|
|
117769
|
-
function createTargetObservationStore(
|
|
117825
|
+
function createTargetObservationStore(fs30, paths) {
|
|
117770
117826
|
let observations = /* @__PURE__ */ new Map();
|
|
117771
|
-
const seeded = readUsageLog(
|
|
117827
|
+
const seeded = readUsageLog(fs30, paths.usageLogDir, {}).records.slice(-SEED_LOOKBACK_RECORDS);
|
|
117772
117828
|
for (const record2 of seeded) {
|
|
117773
117829
|
observations = observeRecord(observations, record2);
|
|
117774
117830
|
}
|
|
@@ -118188,8 +118244,8 @@ var StampsFileSchema = external_exports.strictObject({
|
|
|
118188
118244
|
schemaVersion: external_exports.literal(STAMPS_SCHEMA_VERSION),
|
|
118189
118245
|
handled: external_exports.record(external_exports.string().min(1), external_exports.iso.datetime())
|
|
118190
118246
|
});
|
|
118191
|
-
function readHandled(
|
|
118192
|
-
const raw =
|
|
118247
|
+
function readHandled(fs30, file2) {
|
|
118248
|
+
const raw = fs30.readFileUtf8(file2);
|
|
118193
118249
|
if (raw === void 0) {
|
|
118194
118250
|
return {};
|
|
118195
118251
|
}
|
|
@@ -118202,10 +118258,10 @@ function readHandled(fs29, file2) {
|
|
|
118202
118258
|
const result = StampsFileSchema.safeParse(parsed);
|
|
118203
118259
|
return result.success ? Object.fromEntries(Object.entries(result.data.handled).map(([key, at2]) => [key, Date.parse(at2)])) : {};
|
|
118204
118260
|
}
|
|
118205
|
-
function writeHandled(
|
|
118261
|
+
function writeHandled(fs30, file2, handled) {
|
|
118206
118262
|
const next = { schemaVersion: STAMPS_SCHEMA_VERSION, handled: Object.fromEntries(Object.entries(handled).map(([key, at2]) => [key, new Date(at2).toISOString()])) };
|
|
118207
|
-
|
|
118208
|
-
|
|
118263
|
+
fs30.mkdirPrivate(import_node_path48.default.dirname(file2));
|
|
118264
|
+
fs30.writeFilePrivate(file2, `${JSON.stringify(next, null, 2)}
|
|
118209
118265
|
`);
|
|
118210
118266
|
}
|
|
118211
118267
|
|
|
@@ -118851,8 +118907,8 @@ function finiteNumber(record2, field) {
|
|
|
118851
118907
|
const value2 = record2 === void 0 ? void 0 : record2[field];
|
|
118852
118908
|
return typeof value2 === "number" && Number.isFinite(value2) ? value2 : void 0;
|
|
118853
118909
|
}
|
|
118854
|
-
function excerpt(
|
|
118855
|
-
return
|
|
118910
|
+
function excerpt(text3) {
|
|
118911
|
+
return text3.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS ? text3 : `${text3.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS)}...`;
|
|
118856
118912
|
}
|
|
118857
118913
|
function payloadEventsOf(body) {
|
|
118858
118914
|
const parsed = parseJsonObject(body);
|
|
@@ -118982,8 +119038,8 @@ function createRcSessionTracker(deps) {
|
|
|
118982
119038
|
if (!accepted2 || buffered2 >= RC_CREATE_RESPONSE_CAP_BYTES) {
|
|
118983
119039
|
return;
|
|
118984
119040
|
}
|
|
118985
|
-
const
|
|
118986
|
-
body = body +
|
|
119041
|
+
const text3 = Buffer.from(chunk2).toString("utf8");
|
|
119042
|
+
body = body + text3.slice(0, RC_CREATE_RESPONSE_CAP_BYTES - buffered2);
|
|
118987
119043
|
buffered2 = body.length;
|
|
118988
119044
|
},
|
|
118989
119045
|
onEnd: () => {
|
|
@@ -119201,13 +119257,13 @@ function teeRoutedResponse(response, observer, onSettled) {
|
|
|
119201
119257
|
}
|
|
119202
119258
|
|
|
119203
119259
|
// src/frontdoor/rcWrites.ts
|
|
119204
|
-
function buildRcUserMessagePayload(uuid3, sessionId,
|
|
119260
|
+
function buildRcUserMessagePayload(uuid3, sessionId, text3) {
|
|
119205
119261
|
return {
|
|
119206
119262
|
type: "user",
|
|
119207
119263
|
uuid: uuid3,
|
|
119208
119264
|
session_id: sessionId,
|
|
119209
119265
|
parent_tool_use_id: null,
|
|
119210
|
-
message: { role: "user", content:
|
|
119266
|
+
message: { role: "user", content: text3 }
|
|
119211
119267
|
};
|
|
119212
119268
|
}
|
|
119213
119269
|
function buildRcEventWriteBody(payload) {
|
|
@@ -119272,7 +119328,7 @@ function rcWriteHeaders(credential) {
|
|
|
119272
119328
|
}
|
|
119273
119329
|
return headers;
|
|
119274
119330
|
}
|
|
119275
|
-
async function injectRcUserMessage(deps, sessionId,
|
|
119331
|
+
async function injectRcUserMessage(deps, sessionId, text3) {
|
|
119276
119332
|
const credential = deps.credentialOf(sessionId);
|
|
119277
119333
|
if (credential === void 0) {
|
|
119278
119334
|
return { ok: false, message: rcSessionNotObservedMessage(sessionId) };
|
|
@@ -119280,7 +119336,7 @@ async function injectRcUserMessage(deps, sessionId, text2) {
|
|
|
119280
119336
|
if (credential.authorization === void 0) {
|
|
119281
119337
|
return noOAuthCredentialResult(sessionId);
|
|
119282
119338
|
}
|
|
119283
|
-
const body = JSON.stringify(buildRcEventWriteBody(buildRcUserMessagePayload(deps.newUuid(), sessionId,
|
|
119339
|
+
const body = JSON.stringify(buildRcEventWriteBody(buildRcUserMessagePayload(deps.newUuid(), sessionId, text3)));
|
|
119284
119340
|
let answer;
|
|
119285
119341
|
try {
|
|
119286
119342
|
answer = await deps.dial.writeEvents(sessionId, rcWriteHeaders(credential), body);
|
|
@@ -119503,9 +119559,9 @@ var RC_PERMISSION_MODE_LIST = RC_PERMISSION_MODES.join(", ");
|
|
|
119503
119559
|
var CONTROL_PATH_PREFIX = "/__agent-shim/rc";
|
|
119504
119560
|
var CONTROL_BODY_CAP_BYTES = 10485760;
|
|
119505
119561
|
function answerJson(response, status, body) {
|
|
119506
|
-
const
|
|
119507
|
-
response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(
|
|
119508
|
-
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);
|
|
119509
119565
|
}
|
|
119510
119566
|
function isJsonObject(value2) {
|
|
119511
119567
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
@@ -119754,12 +119810,12 @@ function createRcControlHandler(deps) {
|
|
|
119754
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" });
|
|
119755
119811
|
return;
|
|
119756
119812
|
}
|
|
119757
|
-
const
|
|
119758
|
-
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 !== "") {
|
|
119759
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" });
|
|
119760
119816
|
return;
|
|
119761
119817
|
}
|
|
119762
|
-
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 });
|
|
119763
119819
|
if (result.ok) {
|
|
119764
119820
|
answerJson(response, HTTP_STATUS.ok, { session: parsed.session, request: parsed.request, sequenceNums: result.sequenceNums });
|
|
119765
119821
|
return;
|
|
@@ -120022,7 +120078,7 @@ function frontDoorRcControl(transport, token) {
|
|
|
120022
120078
|
listSessions: async () => sessionsOf(await listAnswerOf(`${CONTROL_PATH_PREFIX}/sessions`, "listing the door's Remote Control sessions"), "listing the door's Remote Control sessions"),
|
|
120023
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"),
|
|
120024
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"),
|
|
120025
|
-
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}`),
|
|
120026
120082
|
answerRequest: async (sessionId, requestId, decision) => await writeOf(
|
|
120027
120083
|
`${CONTROL_PATH_PREFIX}/answer`,
|
|
120028
120084
|
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message } }),
|
|
@@ -121735,11 +121791,11 @@ var AsyncIteratorClass = class {
|
|
|
121735
121791
|
return this;
|
|
121736
121792
|
}
|
|
121737
121793
|
};
|
|
121738
|
-
function parseEmptyableJSON(
|
|
121739
|
-
if (!
|
|
121794
|
+
function parseEmptyableJSON(text3) {
|
|
121795
|
+
if (!text3) {
|
|
121740
121796
|
return void 0;
|
|
121741
121797
|
}
|
|
121742
|
-
return JSON.parse(
|
|
121798
|
+
return JSON.parse(text3);
|
|
121743
121799
|
}
|
|
121744
121800
|
function stringifyJSON(value2) {
|
|
121745
121801
|
return JSON.stringify(value2);
|
|
@@ -122790,8 +122846,8 @@ function createORPCErrorFromMalformedResponse(options) {
|
|
|
122790
122846
|
}
|
|
122791
122847
|
var INFERRED_MESSAGE_MIN_LENGTH = 1;
|
|
122792
122848
|
var INFERRED_MESSAGE_MAX_LENGTH = 256;
|
|
122793
|
-
function isInferableMessage(
|
|
122794
|
-
return
|
|
122849
|
+
function isInferableMessage(text3) {
|
|
122850
|
+
return text3.length >= INFERRED_MESSAGE_MIN_LENGTH && text3.length <= INFERRED_MESSAGE_MAX_LENGTH;
|
|
122795
122851
|
}
|
|
122796
122852
|
function inferMalformedResponseMessage(response) {
|
|
122797
122853
|
if (typeof response.body === "string" && isInferableMessage(response.body)) {
|
|
@@ -127528,15 +127584,15 @@ async function toStandardBody(re, options) {
|
|
|
127528
127584
|
throw new TypeError("Failed to read body: body stream already read");
|
|
127529
127585
|
}
|
|
127530
127586
|
if (hint === "json") {
|
|
127531
|
-
const
|
|
127532
|
-
return parseEmptyableJSON(
|
|
127587
|
+
const text3 = await re.text();
|
|
127588
|
+
return parseEmptyableJSON(text3);
|
|
127533
127589
|
}
|
|
127534
127590
|
if (hint === "form-data") {
|
|
127535
127591
|
return await re.formData();
|
|
127536
127592
|
}
|
|
127537
127593
|
if (hint === "url-search-params") {
|
|
127538
|
-
const
|
|
127539
|
-
return new URLSearchParams(
|
|
127594
|
+
const text3 = await re.text();
|
|
127595
|
+
return new URLSearchParams(text3);
|
|
127540
127596
|
}
|
|
127541
127597
|
if (hint === "event-stream") {
|
|
127542
127598
|
return toAsyncIteratorObject(re.body);
|
|
@@ -128012,16 +128068,16 @@ async function toStandardBody2(req, options = {}) {
|
|
|
128012
128068
|
throw new TypeError("Failed to read body: body stream already read or destroyed");
|
|
128013
128069
|
}
|
|
128014
128070
|
if (hint === "json") {
|
|
128015
|
-
const
|
|
128016
|
-
return parseEmptyableJSON(
|
|
128071
|
+
const text3 = await _streamToString(req);
|
|
128072
|
+
return parseEmptyableJSON(text3);
|
|
128017
128073
|
}
|
|
128018
128074
|
const contentType = req.headers["content-type"];
|
|
128019
128075
|
if (hint === "form-data") {
|
|
128020
128076
|
return _streamToFormData(req, contentType);
|
|
128021
128077
|
}
|
|
128022
128078
|
if (hint === "url-search-params") {
|
|
128023
|
-
const
|
|
128024
|
-
return new URLSearchParams(
|
|
128079
|
+
const text3 = await _streamToString(req);
|
|
128080
|
+
return new URLSearchParams(text3);
|
|
128025
128081
|
}
|
|
128026
128082
|
if (hint === "event-stream") {
|
|
128027
128083
|
return toAsyncIteratorObject2(req);
|
|
@@ -130803,16 +130859,16 @@ function walk2(body, hashing, parentAfter) {
|
|
|
130803
130859
|
continue;
|
|
130804
130860
|
}
|
|
130805
130861
|
const isKey = kind === STRING && depth >= 1 && expectKey[depth - 1] === true;
|
|
130806
|
-
const
|
|
130807
|
-
if (isKey &&
|
|
130862
|
+
const text3 = isKey ? body.toString("latin1", start, end) : void 0;
|
|
130863
|
+
if (isKey && text3 === CACHE_MARKER_KEY) {
|
|
130808
130864
|
skipNextValue = true;
|
|
130809
130865
|
continue;
|
|
130810
130866
|
}
|
|
130811
130867
|
if (depth === 1 && isKey) {
|
|
130812
|
-
topKey =
|
|
130868
|
+
topKey = text3;
|
|
130813
130869
|
}
|
|
130814
130870
|
const closesMessages = kind === CLOSE && inMessages && depth === MESSAGES_ARRAY_DEPTH;
|
|
130815
|
-
if (hashing && !closesMessages && !(depth === 1 && isKey && !THREAD_MEMBER_KEYS.has(
|
|
130871
|
+
if (hashing && !closesMessages && !(depth === 1 && isKey && !THREAD_MEMBER_KEYS.has(text3 ?? ""))) {
|
|
130816
130872
|
const target = inMessages ? messages : depth >= 1 && topKey !== void 0 && THREAD_MEMBER_KEYS.has(topKey) ? thread : void 0;
|
|
130817
130873
|
if (target !== void 0) {
|
|
130818
130874
|
target.update(body.subarray(start, end));
|
|
@@ -131782,8 +131838,8 @@ function createCodexRoute(ports) {
|
|
|
131782
131838
|
if (!parsed.success) {
|
|
131783
131839
|
return errorResponse(HTTP_STATUS.badRequest, "not a count_tokens request");
|
|
131784
131840
|
}
|
|
131785
|
-
const
|
|
131786
|
-
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) }) };
|
|
131787
131843
|
};
|
|
131788
131844
|
return async (request7) => {
|
|
131789
131845
|
if (request7.method === "GET" && request7.path === "/healthz") {
|
|
@@ -132644,28 +132700,28 @@ async function scanRequestHead(request7, wholeBody = false) {
|
|
|
132644
132700
|
const body = request7.body;
|
|
132645
132701
|
const head = [];
|
|
132646
132702
|
let seen = 0;
|
|
132647
|
-
let
|
|
132703
|
+
let text3 = "";
|
|
132648
132704
|
let decided = false;
|
|
132649
132705
|
let ended = false;
|
|
132650
132706
|
let error63;
|
|
132651
132707
|
const replay = new import_node_stream2.PassThrough();
|
|
132652
|
-
const modelIn = () => /"model"\s*:\s*"([^"]+)"/.exec(
|
|
132708
|
+
const modelIn = () => /"model"\s*:\s*"([^"]+)"/.exec(text3)?.[1];
|
|
132653
132709
|
const settled = new Promise((resolve2) => {
|
|
132654
132710
|
const settle2 = () => {
|
|
132655
132711
|
const model = modelIn();
|
|
132656
|
-
const hasImage = /"type"\s*:\s*"image"/.test(
|
|
132712
|
+
const hasImage = /"type"\s*:\s*"image"/.test(text3);
|
|
132657
132713
|
for (const chunk2 of head) {
|
|
132658
132714
|
replay.write(chunk2);
|
|
132659
132715
|
}
|
|
132660
|
-
const maxTokens = /"max_tokens"\s*:\s*([0-9]+)/.exec(
|
|
132716
|
+
const maxTokens = /"max_tokens"\s*:\s*([0-9]+)/.exec(text3)?.[1];
|
|
132661
132717
|
resolve2({
|
|
132662
132718
|
...model === void 0 ? {} : { model },
|
|
132663
132719
|
hasImage,
|
|
132664
|
-
toolsPresent: /"tools"\s*:\s*\[\s*\{/.test(
|
|
132665
|
-
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),
|
|
132666
132722
|
...maxTokens === void 0 ? {} : { maxTokens: Number(maxTokens) },
|
|
132667
132723
|
isCountTokens: request7.url.includes("/v1/messages/count_tokens"),
|
|
132668
|
-
...wholeBody ? { whole: true, text:
|
|
132724
|
+
...wholeBody ? { whole: true, text: text3 } : {},
|
|
132669
132725
|
replayed: { ...request7, body: replay }
|
|
132670
132726
|
});
|
|
132671
132727
|
};
|
|
@@ -132681,7 +132737,7 @@ async function scanRequestHead(request7, wholeBody = false) {
|
|
|
132681
132737
|
}
|
|
132682
132738
|
head.push(chunk2);
|
|
132683
132739
|
seen += chunk2.length;
|
|
132684
|
-
|
|
132740
|
+
text3 += chunk2.toString("utf8");
|
|
132685
132741
|
if (!wholeBody && (modelIn() !== void 0 || seen >= REQUEST_SCAN_CAP_BYTES)) {
|
|
132686
132742
|
decided = true;
|
|
132687
132743
|
settle2();
|
|
@@ -133184,9 +133240,9 @@ function growthBookFeatures() {
|
|
|
133184
133240
|
};
|
|
133185
133241
|
}
|
|
133186
133242
|
var answerServerJson = (response, status, body) => {
|
|
133187
|
-
const
|
|
133188
|
-
response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(
|
|
133189
|
-
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);
|
|
133190
133246
|
};
|
|
133191
133247
|
function createRcSelfHostLocal(deps) {
|
|
133192
133248
|
return {
|
|
@@ -133270,8 +133326,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
|
133270
133326
|
function isRecord16(value2) {
|
|
133271
133327
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
133272
133328
|
}
|
|
133273
|
-
function readJsonObject(
|
|
133274
|
-
const raw =
|
|
133329
|
+
function readJsonObject(fs30, file2) {
|
|
133330
|
+
const raw = fs30.readFileUtf8(file2);
|
|
133275
133331
|
if (raw === void 0) {
|
|
133276
133332
|
return void 0;
|
|
133277
133333
|
}
|
|
@@ -133283,8 +133339,8 @@ function readJsonObject(fs29, file2) {
|
|
|
133283
133339
|
}
|
|
133284
133340
|
return isRecord16(parsed) ? parsed : void 0;
|
|
133285
133341
|
}
|
|
133286
|
-
function readRcSelfHostRecord(
|
|
133287
|
-
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));
|
|
133288
133344
|
if (parsed === void 0) {
|
|
133289
133345
|
return void 0;
|
|
133290
133346
|
}
|
|
@@ -133397,8 +133453,8 @@ function formatRcPendingList(pending) {
|
|
|
133397
133453
|
}
|
|
133398
133454
|
return pending.map((request7) => `${request7.sessionId} ${request7.requestId} ${request7.type}${request7.summary === "" ? "" : ` ${request7.summary}`} observed ${new Date(request7.observedAt).toISOString()}`);
|
|
133399
133455
|
}
|
|
133400
|
-
function eventExcerpt(
|
|
133401
|
-
return
|
|
133456
|
+
function eventExcerpt(text3) {
|
|
133457
|
+
return text3.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS ? text3 : `${text3.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS)}...`;
|
|
133402
133458
|
}
|
|
133403
133459
|
var PERCENT_SCALE = 100;
|
|
133404
133460
|
var MS_PER_SECOND14 = 1e3;
|
|
@@ -133729,11 +133785,11 @@ function credentialOfJson(parsed) {
|
|
|
133729
133785
|
function sequenceNumOfJson(value2) {
|
|
133730
133786
|
return typeof value2 === "number" && Number.isInteger(value2) && value2 >= 0 ? value2 : void 0;
|
|
133731
133787
|
}
|
|
133732
|
-
function createRcCredentialStore(
|
|
133733
|
-
|
|
133788
|
+
function createRcCredentialStore(fs30, dir) {
|
|
133789
|
+
fs30.mkdirPrivate(dir);
|
|
133734
133790
|
const fileFor = (sessionId) => import_node_path53.default.join(dir, `${sessionId}.json`);
|
|
133735
133791
|
const readParsed = (sessionId) => {
|
|
133736
|
-
const raw =
|
|
133792
|
+
const raw = fs30.readFileUtf8(fileFor(sessionId));
|
|
133737
133793
|
if (raw === void 0) {
|
|
133738
133794
|
return void 0;
|
|
133739
133795
|
}
|
|
@@ -133758,7 +133814,7 @@ function createRcCredentialStore(fs29, dir) {
|
|
|
133758
133814
|
}
|
|
133759
133815
|
const cursor3 = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
|
|
133760
133816
|
const record2 = { ...credential, ...cursor3 === void 0 ? {} : { highestSequenceNum: cursor3 } };
|
|
133761
|
-
|
|
133817
|
+
fs30.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
|
|
133762
133818
|
`);
|
|
133763
133819
|
},
|
|
133764
133820
|
readCursor: (sessionId) => {
|
|
@@ -133773,14 +133829,14 @@ function createRcCredentialStore(fs29, dir) {
|
|
|
133773
133829
|
}
|
|
133774
133830
|
const credential = credentialOfJson(readParsed(sessionId));
|
|
133775
133831
|
const record2 = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
|
|
133776
|
-
|
|
133832
|
+
fs30.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
|
|
133777
133833
|
`);
|
|
133778
133834
|
},
|
|
133779
133835
|
remove: (sessionId) => {
|
|
133780
133836
|
if (!isSafeSessionId(sessionId)) {
|
|
133781
133837
|
return;
|
|
133782
133838
|
}
|
|
133783
|
-
|
|
133839
|
+
fs30.removeRecursive(fileFor(sessionId));
|
|
133784
133840
|
}
|
|
133785
133841
|
};
|
|
133786
133842
|
}
|
|
@@ -135097,9 +135153,9 @@ data: ${JSON.stringify(envelope)}
|
|
|
135097
135153
|
};
|
|
135098
135154
|
const sessionRow = (session) => ({ id: session.id, title: session.title, created_at: new Date(session.createdAt).toISOString(), status: "active", conversation_id: session.conversation.id });
|
|
135099
135155
|
const answerJson2 = async (response, status, body, extraHeaders = {}) => {
|
|
135100
|
-
const
|
|
135101
|
-
response.start(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(
|
|
135102
|
-
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);
|
|
135103
135159
|
response.end();
|
|
135104
135160
|
};
|
|
135105
135161
|
const noCredential = async (response) => {
|
|
@@ -135501,8 +135557,8 @@ function createSseParser() {
|
|
|
135501
135557
|
let dataLines = [];
|
|
135502
135558
|
let seenAnyText = false;
|
|
135503
135559
|
return {
|
|
135504
|
-
write: (
|
|
135505
|
-
let incoming =
|
|
135560
|
+
write: (text3) => {
|
|
135561
|
+
let incoming = text3;
|
|
135506
135562
|
if (!seenAnyText) {
|
|
135507
135563
|
seenAnyText = true;
|
|
135508
135564
|
incoming = incoming.charCodeAt(0) === SSE_BYTE_ORDER_MARK ? incoming.slice(1) : incoming;
|
|
@@ -136394,7 +136450,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, retire, trackTun
|
|
|
136394
136450
|
startProviderListener: async (preferredPort) => {
|
|
136395
136451
|
const authority = loadCa();
|
|
136396
136452
|
const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
|
|
136397
|
-
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);
|
|
136398
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);
|
|
136399
136455
|
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto25.randomUUID };
|
|
136400
136456
|
const rcInterrupt = async (sessionId) => await interruptRcSession(rcControlRequestDeps, sessionId);
|
|
@@ -136678,8 +136734,8 @@ function registerFrontDoorCommand(program2, deps) {
|
|
|
136678
136734
|
}
|
|
136679
136735
|
|
|
136680
136736
|
// src/statusline/commands.ts
|
|
136681
|
-
var
|
|
136682
|
-
var
|
|
136737
|
+
var import_node_child_process8 = require("node:child_process");
|
|
136738
|
+
var import_node_os13 = __toESM(require("node:os"), 1);
|
|
136683
136739
|
var import_node_path56 = __toESM(require("node:path"), 1);
|
|
136684
136740
|
init_commandDeps();
|
|
136685
136741
|
init_statusline();
|
|
@@ -136694,8 +136750,8 @@ function isAntigravityPayload(payload) {
|
|
|
136694
136750
|
return typeof payload === "object" && payload !== null && "product" in payload && payload.product === "antigravity";
|
|
136695
136751
|
}
|
|
136696
136752
|
var ANTIGRAVITY_SETTINGS_SEGMENTS = [".gemini", "antigravity-cli", "settings.json"];
|
|
136697
|
-
function antigravityStacksWithDefault(
|
|
136698
|
-
const raw =
|
|
136753
|
+
function antigravityStacksWithDefault(fs30, homeDir) {
|
|
136754
|
+
const raw = fs30.readFileUtf8(import_node_path55.default.join(homeDir, ...ANTIGRAVITY_SETTINGS_SEGMENTS));
|
|
136699
136755
|
if (raw === void 0) {
|
|
136700
136756
|
return false;
|
|
136701
136757
|
}
|
|
@@ -136999,6 +137055,79 @@ function providerScopedState(snapshot, providerName, providerDisplayName) {
|
|
|
136999
137055
|
// src/statusline/commands.ts
|
|
137000
137056
|
init_read();
|
|
137001
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
|
+
|
|
137002
137131
|
// src/statusline/render.ts
|
|
137003
137132
|
init_statusline();
|
|
137004
137133
|
|
|
@@ -137006,8 +137135,8 @@ init_statusline();
|
|
|
137006
137135
|
var ESCAPE_CHAR_CODE = 27;
|
|
137007
137136
|
var ESCAPE = String.fromCharCode(ESCAPE_CHAR_CODE);
|
|
137008
137137
|
var ANSI_REGEX = new RegExp(`${ESCAPE}\\[[0-9;]*[a-zA-Z]`, "g");
|
|
137009
|
-
function visibleLength(
|
|
137010
|
-
return
|
|
137138
|
+
function visibleLength(text3) {
|
|
137139
|
+
return text3.replace(ANSI_REGEX, "").length;
|
|
137011
137140
|
}
|
|
137012
137141
|
|
|
137013
137142
|
// src/statusline/barGrid.ts
|
|
@@ -137036,8 +137165,8 @@ function measureGrid(rows, separatorLength, baseBarCells) {
|
|
|
137036
137165
|
const fixed = [...prefixWidths, ...suffixWidths].reduce((total, width) => total + width, 0) + columns * (baseBarCells + BRACKET_COLUMNS);
|
|
137037
137166
|
return { rows, columns, prefixWidths, suffixWidths, baseWidth: fixed + separatorLength * (columns - 1) };
|
|
137038
137167
|
}
|
|
137039
|
-
function padTo(
|
|
137040
|
-
return
|
|
137168
|
+
function padTo(text3, width) {
|
|
137169
|
+
return text3 + " ".repeat(Math.max(0, width - visibleLength(text3)));
|
|
137041
137170
|
}
|
|
137042
137171
|
function renderGrid(grid, maxWidth, separator, baseBarCells) {
|
|
137043
137172
|
const separatorLength = visibleLength(separator);
|
|
@@ -137139,6 +137268,62 @@ function accountSegment({ summary }) {
|
|
|
137139
137268
|
return summary.provider === void 0 && loginParts.length > 0 ? loginParts.join(" \xB7 ") : void 0;
|
|
137140
137269
|
}
|
|
137141
137270
|
|
|
137271
|
+
// src/statusline/palette.ts
|
|
137272
|
+
init_statusline();
|
|
137273
|
+
var RESET = `${ESCAPE}[0m`;
|
|
137274
|
+
var SGR_BY_NAME = {
|
|
137275
|
+
default: "",
|
|
137276
|
+
dim: "2",
|
|
137277
|
+
black: "30",
|
|
137278
|
+
red: "31",
|
|
137279
|
+
green: "32",
|
|
137280
|
+
yellow: "33",
|
|
137281
|
+
blue: "34",
|
|
137282
|
+
magenta: "35",
|
|
137283
|
+
cyan: "36",
|
|
137284
|
+
white: "37",
|
|
137285
|
+
brightBlack: "90",
|
|
137286
|
+
brightRed: "91",
|
|
137287
|
+
brightGreen: "92",
|
|
137288
|
+
brightYellow: "93",
|
|
137289
|
+
brightBlue: "94",
|
|
137290
|
+
brightMagenta: "95",
|
|
137291
|
+
brightCyan: "96",
|
|
137292
|
+
brightWhite: "97"
|
|
137293
|
+
};
|
|
137294
|
+
function isColourName(value2) {
|
|
137295
|
+
return STATUSLINE_COLOUR_NAMES.some((name) => name === value2);
|
|
137296
|
+
}
|
|
137297
|
+
var CHANNELS = 3;
|
|
137298
|
+
var CHANNEL_DIGITS = 2;
|
|
137299
|
+
var HEX_RADIX2 = 16;
|
|
137300
|
+
function sgrOf(value2) {
|
|
137301
|
+
if (typeof value2 === "number") {
|
|
137302
|
+
return `38;5;${String(value2)}`;
|
|
137303
|
+
}
|
|
137304
|
+
if (value2.startsWith("#")) {
|
|
137305
|
+
const channels = Array.from({ length: CHANNELS }, (_, index) => Number.parseInt(value2.slice(1 + index * CHANNEL_DIGITS, 1 + (index + 1) * CHANNEL_DIGITS), HEX_RADIX2));
|
|
137306
|
+
return `38;2;${channels.join(";")}`;
|
|
137307
|
+
}
|
|
137308
|
+
return isColourName(value2) ? SGR_BY_NAME[value2] : "";
|
|
137309
|
+
}
|
|
137310
|
+
function colourEnabled(env) {
|
|
137311
|
+
return env.NO_COLOR === void 0;
|
|
137312
|
+
}
|
|
137313
|
+
function createPalette(colours, enabled) {
|
|
137314
|
+
const ansi = (role) => {
|
|
137315
|
+
const sgr = enabled ? sgrOf(colours[role]) : "";
|
|
137316
|
+
return sgr === "" ? "" : `${ESCAPE}[${sgr}m`;
|
|
137317
|
+
};
|
|
137318
|
+
return {
|
|
137319
|
+
ansi,
|
|
137320
|
+
paint: (role, text3) => {
|
|
137321
|
+
const start = ansi(role);
|
|
137322
|
+
return start === "" ? text3 : `${start}${text3}${RESET}`;
|
|
137323
|
+
}
|
|
137324
|
+
};
|
|
137325
|
+
}
|
|
137326
|
+
|
|
137142
137327
|
// src/statusline/style.ts
|
|
137143
137328
|
var SECONDS_PER_MINUTE2 = 60;
|
|
137144
137329
|
var MINUTES_PER_HOUR4 = 60;
|
|
@@ -137149,30 +137334,24 @@ var TEN = 10;
|
|
|
137149
137334
|
var TWENTY = 20;
|
|
137150
137335
|
var FULL_PERCENT3 = 100;
|
|
137151
137336
|
var ONE_PERCENT = 1;
|
|
137152
|
-
|
|
137153
|
-
|
|
137154
|
-
|
|
137155
|
-
|
|
137156
|
-
|
|
137157
|
-
|
|
137158
|
-
|
|
137159
|
-
}
|
|
137160
|
-
function statusColor(fraction, isUsedMetric, bands) {
|
|
137161
|
-
if (!colorize()) {
|
|
137162
|
-
return "";
|
|
137163
|
-
}
|
|
137164
|
-
const yellowAt = bands.warnAt / FULL_PERCENT3;
|
|
137165
|
-
const redAt = bands.criticalAt / FULL_PERCENT3;
|
|
137337
|
+
function withColor(color, text3) {
|
|
137338
|
+
return color === "" ? text3 : `${color}${text3}${RESET}`;
|
|
137339
|
+
}
|
|
137340
|
+
function statusColor(fraction, isUsedMetric, style) {
|
|
137341
|
+
const yellowAt = style.bands.warnAt / FULL_PERCENT3;
|
|
137342
|
+
const redAt = style.bands.criticalAt / FULL_PERCENT3;
|
|
137343
|
+
const warningRole = style.okRole === "usage" ? "usageWarning" : "warning";
|
|
137344
|
+
const { ansi } = style.palette;
|
|
137166
137345
|
if (isUsedMetric) {
|
|
137167
137346
|
if (fraction >= redAt) {
|
|
137168
|
-
return
|
|
137347
|
+
return ansi("critical");
|
|
137169
137348
|
}
|
|
137170
|
-
return fraction >= yellowAt ?
|
|
137349
|
+
return fraction >= yellowAt ? ansi(warningRole) : ansi(style.okRole);
|
|
137171
137350
|
}
|
|
137172
137351
|
if (fraction <= 1 - redAt) {
|
|
137173
|
-
return
|
|
137352
|
+
return ansi("critical");
|
|
137174
137353
|
}
|
|
137175
|
-
return fraction <= 1 - yellowAt ?
|
|
137354
|
+
return fraction <= 1 - yellowAt ? ansi(warningRole) : ansi(style.okRole);
|
|
137176
137355
|
}
|
|
137177
137356
|
function formatTokens(num) {
|
|
137178
137357
|
if (num >= MILLION) {
|
|
@@ -137207,14 +137386,19 @@ function secondsUntil(resetAt, nowMs) {
|
|
|
137207
137386
|
const resetMs = Date.parse(resetAt);
|
|
137208
137387
|
return Number.isNaN(resetMs) ? void 0 : Math.max(0, Math.round((resetMs - nowMs) / THOUSAND));
|
|
137209
137388
|
}
|
|
137210
|
-
function drawBar(fraction, cells,
|
|
137389
|
+
function drawBar(fraction, cells, style) {
|
|
137211
137390
|
const clamped = Math.max(0, Math.min(1, fraction));
|
|
137212
137391
|
const filled = Math.round(clamped * cells);
|
|
137213
|
-
const color = statusColor(clamped, true,
|
|
137214
|
-
|
|
137392
|
+
const color = statusColor(clamped, true, style);
|
|
137393
|
+
const emptyColor = style.palette.ansi("empty");
|
|
137394
|
+
const body = `${style.filled.repeat(filled)}${style.empty.repeat(cells - filled)}`;
|
|
137395
|
+
if (color === "" && emptyColor === "") {
|
|
137396
|
+
return `[${body}]`;
|
|
137397
|
+
}
|
|
137398
|
+
return `[${color}${style.filled.repeat(filled)}${emptyColor}${style.empty.repeat(cells - filled)}${RESET}]`;
|
|
137215
137399
|
}
|
|
137216
|
-
function barCell(prefix, suffix, fraction,
|
|
137217
|
-
return { prefix, suffix, draw: (cells) => drawBar(fraction, cells,
|
|
137400
|
+
function barCell(prefix, suffix, fraction, style) {
|
|
137401
|
+
return { prefix, suffix, draw: (cells) => drawBar(fraction, cells, style) };
|
|
137218
137402
|
}
|
|
137219
137403
|
|
|
137220
137404
|
// src/statusline/elements/header/headroom.ts
|
|
@@ -137266,42 +137450,51 @@ function routeSegment({ summary }) {
|
|
|
137266
137450
|
return summary.routedTarget !== void 0 && !choiceNamesProvider(summary) ? `via ${summary.routedTarget}` : void 0;
|
|
137267
137451
|
}
|
|
137268
137452
|
|
|
137453
|
+
// src/statusline/elements/context.ts
|
|
137454
|
+
function barStyleOf({ settings: settings2, palette }, okRole) {
|
|
137455
|
+
return { bands: settings2.bands, palette, okRole, filled: settings2.bar.filled, empty: settings2.bar.empty };
|
|
137456
|
+
}
|
|
137457
|
+
|
|
137269
137458
|
// src/statusline/elements/rows/context.ts
|
|
137270
|
-
function cacheHitText(hitFraction,
|
|
137459
|
+
function cacheHitText(hitFraction, style) {
|
|
137271
137460
|
const clamped = Math.max(0, Math.min(1, hitFraction));
|
|
137272
|
-
return ` (Cache: ${statusColor(clamped, false,
|
|
137461
|
+
return ` (Cache: ${withColor(statusColor(clamped, false, style), `${(clamped * FULL_PERCENT3).toFixed(0)}%`)})`;
|
|
137273
137462
|
}
|
|
137274
|
-
function cacheShareText(view,
|
|
137463
|
+
function cacheShareText(view, style) {
|
|
137275
137464
|
const hitRatio = view.cacheHitRatio;
|
|
137276
137465
|
if (hitRatio !== void 0 && Number.isFinite(hitRatio)) {
|
|
137277
|
-
return cacheHitText(hitRatio,
|
|
137466
|
+
return cacheHitText(hitRatio, style);
|
|
137278
137467
|
}
|
|
137279
137468
|
const promptTotal = (view.cacheReadTokens ?? 0) + (view.freshInputTokens ?? 0);
|
|
137280
137469
|
if (promptTotal > 0 && (view.cacheReadTokens ?? 0) > 0) {
|
|
137281
|
-
return cacheHitText((view.cacheReadTokens ?? 0) / promptTotal,
|
|
137470
|
+
return cacheHitText((view.cacheReadTokens ?? 0) / promptTotal, style);
|
|
137282
137471
|
}
|
|
137283
137472
|
return "";
|
|
137284
137473
|
}
|
|
137285
|
-
function contextRow(
|
|
137474
|
+
function contextRow(context) {
|
|
137475
|
+
const { view, palette } = context;
|
|
137476
|
+
const style = barStyleOf(context, "context");
|
|
137286
137477
|
const cells = [];
|
|
137287
137478
|
if (view.contextUsedPercentage !== void 0) {
|
|
137288
137479
|
const fraction = Math.max(0, Math.min(1, view.contextUsedPercentage / FULL_PERCENT3));
|
|
137289
|
-
const color = statusColor(fraction, true,
|
|
137290
|
-
const percent2 = `${
|
|
137480
|
+
const color = statusColor(fraction, true, style);
|
|
137481
|
+
const percent2 = withColor(color, `${view.contextUsedPercentage.toFixed(1)}%`);
|
|
137291
137482
|
const tokens = view.contextTotalTokens !== void 0 && view.contextWindowTokens !== void 0 ? `${formatTokens(view.contextTotalTokens)}/${formatTokens(view.contextWindowTokens)} ` : "";
|
|
137292
|
-
const cache = cacheShareText(view,
|
|
137293
|
-
cells.push(barCell(`Ctx ${tokens}
|
|
137483
|
+
const cache = cacheShareText(view, style);
|
|
137484
|
+
cells.push(barCell(palette.paint("label", `Ctx ${tokens}`), ` ${percent2}${cache}`, fraction, style));
|
|
137294
137485
|
}
|
|
137295
137486
|
return { kind: "bars", cells };
|
|
137296
137487
|
}
|
|
137297
137488
|
|
|
137298
137489
|
// src/statusline/elements/rows/quota.ts
|
|
137299
|
-
function quotaRow(
|
|
137490
|
+
function quotaRow(context) {
|
|
137491
|
+
const { summary, nowMs, settings: settings2, palette } = context;
|
|
137492
|
+
const style = barStyleOf(context, "usage");
|
|
137300
137493
|
const cells = [];
|
|
137301
137494
|
const drawWindow = (label, fraction, resetsAt) => {
|
|
137302
137495
|
const clamped = Math.max(0, Math.min(1, fraction));
|
|
137303
|
-
const color = statusColor(clamped, true,
|
|
137304
|
-
cells.push(barCell(`${label}
|
|
137496
|
+
const color = statusColor(clamped, true, style);
|
|
137497
|
+
cells.push(barCell(palette.paint("label", `${label} `), ` ${withColor(color, `${(fraction * FULL_PERCENT3).toFixed(1)}%`)} (${formatDuration(secondsUntil(resetsAt, nowMs))})`, clamped, style));
|
|
137305
137498
|
};
|
|
137306
137499
|
if (summary.quotaFamilies.length > 0) {
|
|
137307
137500
|
for (const window of summary.quotaFamilies) {
|
|
@@ -137324,6 +137517,14 @@ function quotaRow({ summary, nowMs, settings: settings2, bands }) {
|
|
|
137324
137517
|
}
|
|
137325
137518
|
|
|
137326
137519
|
// src/statusline/elements/registry.ts
|
|
137520
|
+
var HEADER_ROLES = {
|
|
137521
|
+
model: "model",
|
|
137522
|
+
provider: "model",
|
|
137523
|
+
route: "label",
|
|
137524
|
+
account: "label",
|
|
137525
|
+
identity: "label",
|
|
137526
|
+
headroom: "label"
|
|
137527
|
+
};
|
|
137327
137528
|
var ELEMENTS = {
|
|
137328
137529
|
header: { model: modelSegment, provider: providerSegment, route: routeSegment, account: accountSegment, identity: identitySegment, headroom: headroomSegment },
|
|
137329
137530
|
rows: { context: contextRow, quota: quotaRow }
|
|
@@ -137335,7 +137536,7 @@ function justify(texts, maxWidth, separator) {
|
|
|
137335
137536
|
return texts.join(separator);
|
|
137336
137537
|
}
|
|
137337
137538
|
const separatorLength = visibleLength(separator);
|
|
137338
|
-
const total = texts.reduce((sum,
|
|
137539
|
+
const total = texts.reduce((sum, text3) => sum + visibleLength(text3), 0) + separatorLength * (texts.length - 1);
|
|
137339
137540
|
const spare = maxWidth - total;
|
|
137340
137541
|
if (spare <= 0) {
|
|
137341
137542
|
return texts.join(separator);
|
|
@@ -137344,7 +137545,7 @@ function justify(texts, maxWidth, separator) {
|
|
|
137344
137545
|
const extraPerGap = Math.floor(spare / gaps);
|
|
137345
137546
|
let remainder = spare % gaps;
|
|
137346
137547
|
const parts = [];
|
|
137347
|
-
texts.forEach((
|
|
137548
|
+
texts.forEach((text3, index) => {
|
|
137348
137549
|
if (index > 0) {
|
|
137349
137550
|
const extra = extraPerGap + (remainder > 0 ? 1 : 0);
|
|
137350
137551
|
if (remainder > 0) {
|
|
@@ -137353,7 +137554,7 @@ function justify(texts, maxWidth, separator) {
|
|
|
137353
137554
|
const left = Math.floor(extra / 2);
|
|
137354
137555
|
parts.push(`${" ".repeat(left + 1)}|${" ".repeat(extra - left + 1)}`);
|
|
137355
137556
|
}
|
|
137356
|
-
parts.push(
|
|
137557
|
+
parts.push(text3);
|
|
137357
137558
|
});
|
|
137358
137559
|
return parts.join("");
|
|
137359
137560
|
}
|
|
@@ -137362,15 +137563,15 @@ function layoutHeader(texts, maxWidth, separator) {
|
|
|
137362
137563
|
const lines = [];
|
|
137363
137564
|
let current = [];
|
|
137364
137565
|
let currentWidth = 0;
|
|
137365
|
-
for (const
|
|
137366
|
-
const width = visibleLength(
|
|
137566
|
+
for (const text3 of texts) {
|
|
137567
|
+
const width = visibleLength(text3);
|
|
137367
137568
|
const added = current.length === 0 ? width : width + separatorLength;
|
|
137368
137569
|
if (current.length > 0 && currentWidth + added > maxWidth) {
|
|
137369
137570
|
lines.push(current);
|
|
137370
|
-
current = [
|
|
137571
|
+
current = [text3];
|
|
137371
137572
|
currentWidth = width;
|
|
137372
137573
|
} else {
|
|
137373
|
-
current.push(
|
|
137574
|
+
current.push(text3);
|
|
137374
137575
|
currentWidth += added;
|
|
137375
137576
|
}
|
|
137376
137577
|
}
|
|
@@ -137383,9 +137584,21 @@ function layoutHeader(texts, maxWidth, separator) {
|
|
|
137383
137584
|
// src/statusline/render.ts
|
|
137384
137585
|
var RESERVED_COLUMNS = 4;
|
|
137385
137586
|
var SEPARATOR2 = " | ";
|
|
137386
|
-
function renderStatuslineBlock(
|
|
137387
|
-
const
|
|
137388
|
-
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
|
+
};
|
|
137598
|
+
const header = settings2.layout.header.flatMap((name) => {
|
|
137599
|
+
const text3 = elements.header[name](context);
|
|
137600
|
+
return text3 === void 0 ? [] : context.palette.paint(HEADER_ROLES[name], text3);
|
|
137601
|
+
});
|
|
137389
137602
|
const width = Math.max(TWENTY, terminalWidth - RESERVED_COLUMNS);
|
|
137390
137603
|
const lines = [];
|
|
137391
137604
|
if (header.length > 0) {
|
|
@@ -137424,30 +137637,6 @@ function terminalWidthOf(payload, env) {
|
|
|
137424
137637
|
}
|
|
137425
137638
|
|
|
137426
137639
|
// src/statusline/commands.ts
|
|
137427
|
-
function payloadViewOf(payload) {
|
|
137428
|
-
const empty = { modelDisplayName: void 0, contextUsedPercentage: void 0, contextTotalTokens: void 0, contextWindowTokens: void 0, cacheHitRatio: void 0, cacheReadTokens: void 0, freshInputTokens: void 0 };
|
|
137429
|
-
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
|
137430
|
-
return empty;
|
|
137431
|
-
}
|
|
137432
|
-
const record2 = {};
|
|
137433
|
-
for (const [key, value2] of Object.entries(payload)) {
|
|
137434
|
-
record2[key] = value2;
|
|
137435
|
-
}
|
|
137436
|
-
const model = record2.model;
|
|
137437
|
-
const displayName = typeof model === "object" && model !== null && !Array.isArray(model) && "display_name" in model && typeof model.display_name === "string" ? model.display_name : void 0;
|
|
137438
|
-
const context = record2.context_window;
|
|
137439
|
-
const ctx = typeof context === "object" && context !== null && !Array.isArray(context) ? context : void 0;
|
|
137440
|
-
const used = ctx !== void 0 && "used_percentage" in ctx && typeof ctx.used_percentage === "number" ? ctx.used_percentage : void 0;
|
|
137441
|
-
const totalIn = ctx !== void 0 && "total_input_tokens" in ctx && typeof ctx.total_input_tokens === "number" ? ctx.total_input_tokens : void 0;
|
|
137442
|
-
const size = ctx !== void 0 && "context_window_size" in ctx && typeof ctx.context_window_size === "number" ? ctx.context_window_size : void 0;
|
|
137443
|
-
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;
|
|
137444
|
-
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;
|
|
137445
|
-
const fresh = current !== void 0 && "input_tokens" in current && typeof current.input_tokens === "number" ? current.input_tokens : void 0;
|
|
137446
|
-
const promptCache = record2.prompt_cache;
|
|
137447
|
-
const cache = typeof promptCache === "object" && promptCache !== null && !Array.isArray(promptCache) ? promptCache : void 0;
|
|
137448
|
-
const hitRatio = cache !== void 0 && "hit_ratio" in cache && typeof cache.hit_ratio === "number" ? cache.hit_ratio : void 0;
|
|
137449
|
-
return { modelDisplayName: displayName, contextUsedPercentage: used, contextTotalTokens: totalIn, contextWindowTokens: size, cacheHitRatio: hitRatio, cacheReadTokens: cacheRead, freshInputTokens: fresh };
|
|
137450
|
-
}
|
|
137451
137640
|
async function readAllStdin() {
|
|
137452
137641
|
return await new Promise((resolve2) => {
|
|
137453
137642
|
const chunks = [];
|
|
@@ -137489,7 +137678,7 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
137489
137678
|
} else {
|
|
137490
137679
|
const configDir = process.env.CLAUDE_CONFIG_DIR;
|
|
137491
137680
|
try {
|
|
137492
|
-
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"));
|
|
137493
137682
|
} catch {
|
|
137494
137683
|
account = void 0;
|
|
137495
137684
|
}
|
|
@@ -137529,7 +137718,7 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
137529
137718
|
const { payload: enriched, summary } = enrichStatuslinePayload({ payload, env: process.env, snapshot, account, providerName, nowMs, headroom, routedTarget, ...modelChoice === void 0 ? {} : { modelChoice } });
|
|
137530
137719
|
const renderer = process.env.AGENT_SHIM_STATUSLINE_CMD;
|
|
137531
137720
|
if (renderer !== void 0 && renderer !== "") {
|
|
137532
|
-
const child = (0,
|
|
137721
|
+
const child = (0, import_node_child_process8.spawn)("/bin/sh", ["-c", renderer], { stdio: ["pipe", "inherit", "inherit"] });
|
|
137533
137722
|
child.stdin.end(`${JSON.stringify(enriched)}
|
|
137534
137723
|
`);
|
|
137535
137724
|
child.on("close", (code) => {
|
|
@@ -137540,15 +137729,16 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
137540
137729
|
let stackedUnderDefault = false;
|
|
137541
137730
|
if (isAntigravityPayload(payload)) {
|
|
137542
137731
|
try {
|
|
137543
|
-
stackedUnderDefault = antigravityStacksWithDefault(realFarmFs,
|
|
137732
|
+
stackedUnderDefault = antigravityStacksWithDefault(realFarmFs, import_node_os13.default.homedir());
|
|
137544
137733
|
} catch {
|
|
137545
137734
|
stackedUnderDefault = false;
|
|
137546
137735
|
}
|
|
137547
137736
|
}
|
|
137548
|
-
const
|
|
137737
|
+
const clientPayload = parseClientPayload(payload);
|
|
137738
|
+
const view = { ...viewOf(clientPayload), ...stackedUnderDefault ? { modelDisplayName: void 0 } : {} };
|
|
137549
137739
|
const rawSettings = process.env[STATUSLINE_ENV];
|
|
137550
137740
|
const settings2 = resolveStatusline(rawSettings === void 0 || rawSettings === "" ? void 0 : statuslineSettingsFromEnv(rawSettings, STATUSLINE_ENV));
|
|
137551
|
-
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) }));
|
|
137552
137742
|
}),
|
|
137553
137743
|
["$ agent-shim statusline # a client's statusline setting names this; it renders or delegates"]
|
|
137554
137744
|
);
|
|
@@ -147314,7 +147504,7 @@ async function serveMcp(mcp, transport, options = {}) {
|
|
|
147314
147504
|
}
|
|
147315
147505
|
|
|
147316
147506
|
// src/mcp/permissions.ts
|
|
147317
|
-
var
|
|
147507
|
+
var import_node_fs23 = __toESM(require("node:fs"), 1);
|
|
147318
147508
|
var import_node_path57 = __toESM(require("node:path"), 1);
|
|
147319
147509
|
init_zod();
|
|
147320
147510
|
init_store();
|
|
@@ -147331,15 +147521,15 @@ function readStoredMcpPermissions(paths) {
|
|
|
147331
147521
|
}
|
|
147332
147522
|
function writeStoredMcpPermissions(paths, permissions) {
|
|
147333
147523
|
writeJsonAtomic(paths.mcpPermissionsFile, { writes: permissions.writes, remoteControl: permissions.remoteControl, history: permissions.history });
|
|
147334
|
-
|
|
147524
|
+
import_node_fs23.default.chmodSync(paths.mcpPermissionsFile, OWNER_ONLY_MODE);
|
|
147335
147525
|
}
|
|
147336
147526
|
function effectiveMcpPermissions(flags, stored) {
|
|
147337
147527
|
return { writes: flags.writes || stored.writes, remoteControl: flags.remoteControl || stored.remoteControl, history: flags.history || stored.history };
|
|
147338
147528
|
}
|
|
147339
147529
|
function watchMcpPermissions(paths, onChange) {
|
|
147340
147530
|
const directory = import_node_path57.default.dirname(paths.mcpPermissionsFile);
|
|
147341
|
-
|
|
147342
|
-
const watcher =
|
|
147531
|
+
import_node_fs23.default.mkdirSync(directory, { recursive: true });
|
|
147532
|
+
const watcher = import_node_fs23.default.watch(directory, (_event, filename) => {
|
|
147343
147533
|
if (filename === null || filename === import_node_path57.default.basename(paths.mcpPermissionsFile)) {
|
|
147344
147534
|
onChange();
|
|
147345
147535
|
}
|
|
@@ -147505,9 +147695,9 @@ init_cliError();
|
|
|
147505
147695
|
init_argv();
|
|
147506
147696
|
init_legacy();
|
|
147507
147697
|
var COMPLETION_SHELLS = ["bash", "zsh", "fish"];
|
|
147508
|
-
function firstSentence(
|
|
147509
|
-
const end =
|
|
147510
|
-
return end === -1 ?
|
|
147698
|
+
function firstSentence(text3) {
|
|
147699
|
+
const end = text3.search(/\.(\s|$)/);
|
|
147700
|
+
return end === -1 ? text3 : text3.slice(0, end);
|
|
147511
147701
|
}
|
|
147512
147702
|
function collectNodes(program2) {
|
|
147513
147703
|
const help = new Help();
|
|
@@ -147528,11 +147718,11 @@ function collectNodes(program2) {
|
|
|
147528
147718
|
visit2(program2, "root");
|
|
147529
147719
|
return nodes;
|
|
147530
147720
|
}
|
|
147531
|
-
function singleQuote(
|
|
147532
|
-
return `'${
|
|
147721
|
+
function singleQuote(text3) {
|
|
147722
|
+
return `'${text3.replaceAll("'", `'\\''`)}'`;
|
|
147533
147723
|
}
|
|
147534
|
-
function fishQuote(
|
|
147535
|
-
return `'${
|
|
147724
|
+
function fishQuote(text3) {
|
|
147725
|
+
return `'${text3.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
147536
147726
|
}
|
|
147537
147727
|
function transitionArms(nodes, indent) {
|
|
147538
147728
|
return nodes.flatMap((node2) => [...node2.children].map(([name, child]) => `${indent}${singleQuote(`${node2.id}:${name}`)}) node=${singleQuote(child)} ;;`)).join("\n");
|
|
@@ -147645,7 +147835,7 @@ function registerCompletionCommand(program2) {
|
|
|
147645
147835
|
}
|
|
147646
147836
|
|
|
147647
147837
|
// src/credentialCommand.ts
|
|
147648
|
-
var
|
|
147838
|
+
var import_node_child_process9 = require("node:child_process");
|
|
147649
147839
|
init_commandDeps();
|
|
147650
147840
|
init_cliError();
|
|
147651
147841
|
init_schema();
|
|
@@ -147653,7 +147843,7 @@ init_credential();
|
|
|
147653
147843
|
init_credentialCache();
|
|
147654
147844
|
|
|
147655
147845
|
// src/identityToken.ts
|
|
147656
|
-
var
|
|
147846
|
+
var import_node_fs24 = __toESM(require("node:fs"), 1);
|
|
147657
147847
|
var import_node_path58 = __toESM(require("node:path"), 1);
|
|
147658
147848
|
init_cliError();
|
|
147659
147849
|
var TOKEN_FILE_MODE = 384;
|
|
@@ -147671,13 +147861,13 @@ function storeIdentityToken(paths, identityName, raw) {
|
|
|
147671
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.");
|
|
147672
147862
|
}
|
|
147673
147863
|
const dir = identityTokenDir(paths);
|
|
147674
|
-
|
|
147675
|
-
|
|
147864
|
+
import_node_fs24.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
|
|
147865
|
+
import_node_fs24.default.chmodSync(dir, TOKEN_DIR_MODE);
|
|
147676
147866
|
const target = identityTokenPath(paths, identityName);
|
|
147677
147867
|
const temp = import_node_path58.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
|
|
147678
|
-
|
|
147868
|
+
import_node_fs24.default.writeFileSync(temp, `${token}
|
|
147679
147869
|
`, { mode: TOKEN_FILE_MODE });
|
|
147680
|
-
|
|
147870
|
+
import_node_fs24.default.renameSync(temp, target);
|
|
147681
147871
|
return target;
|
|
147682
147872
|
}
|
|
147683
147873
|
|
|
@@ -147706,7 +147896,7 @@ function realCommandPorts(deps) {
|
|
|
147706
147896
|
cache: createRealCredentialCache(deps.paths.root),
|
|
147707
147897
|
platform: process.platform,
|
|
147708
147898
|
now: () => Date.now(),
|
|
147709
|
-
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
|
|
147710
147900
|
};
|
|
147711
147901
|
}
|
|
147712
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';
|
|
@@ -147843,10 +148033,10 @@ function registerDoctorCommand(program2, deps) {
|
|
|
147843
148033
|
}
|
|
147844
148034
|
|
|
147845
148035
|
// src/headroom/commands.ts
|
|
147846
|
-
var
|
|
148036
|
+
var import_node_fs25 = __toESM(require("node:fs"), 1);
|
|
147847
148037
|
var import_node_http5 = __toESM(require("node:http"), 1);
|
|
147848
148038
|
var import_node_path59 = __toESM(require("node:path"), 1);
|
|
147849
|
-
var
|
|
148039
|
+
var import_node_child_process10 = require("node:child_process");
|
|
147850
148040
|
init_commandDeps();
|
|
147851
148041
|
init_configProfilesStore();
|
|
147852
148042
|
init_realFrontDoorPort();
|
|
@@ -148031,7 +148221,7 @@ async function readyOverSocket(socketPath) {
|
|
|
148031
148221
|
}
|
|
148032
148222
|
var HEADROOM_TOOL_NAME = "headroom-ai";
|
|
148033
148223
|
function readInstalledHeadroomCommit() {
|
|
148034
|
-
const toolDir = (0,
|
|
148224
|
+
const toolDir = (0, import_node_child_process10.spawnSync)("uv", ["tool", "dir"], { encoding: "utf8" });
|
|
148035
148225
|
if (toolDir.status !== 0) {
|
|
148036
148226
|
return void 0;
|
|
148037
148227
|
}
|
|
@@ -148068,14 +148258,14 @@ function realSupervisorPorts(paths) {
|
|
|
148068
148258
|
readConfig: () => resolveSupervisorConfig(readGlobalConfig(paths)?.headroom ?? {}),
|
|
148069
148259
|
spawnHeadroom: (socketPath, allowlistFile, settings2) => {
|
|
148070
148260
|
const trust = resolveHeadroomTrustBundle({ caCertFile: paths.frontdoorCaCertFile, bundlesDir: paths.frontdoorCaBundlesDir, inherited: process.env[HEADROOM_CA_BUNDLE], fs: realTrustBundleFs });
|
|
148071
|
-
|
|
148261
|
+
import_node_fs25.default.mkdirSync(paths.logsDir, { recursive: true });
|
|
148072
148262
|
if (trust?.warning !== void 0) {
|
|
148073
|
-
|
|
148263
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${trust.warning}
|
|
148074
148264
|
`);
|
|
148075
148265
|
}
|
|
148076
|
-
const logFd =
|
|
148266
|
+
const logFd = import_node_fs25.default.openSync(paths.headroomLogPath, "a");
|
|
148077
148267
|
try {
|
|
148078
|
-
const child = (0,
|
|
148268
|
+
const child = (0, import_node_child_process10.spawn)("headroom", headroomProxyArgs(socketPath, allowlistFile, settings2), {
|
|
148079
148269
|
detached: true,
|
|
148080
148270
|
stdio: ["ignore", logFd, logFd],
|
|
148081
148271
|
env: headroomSpawnEnv(process.env, settings2, trust?.path)
|
|
@@ -148088,12 +148278,12 @@ function realSupervisorPorts(paths) {
|
|
|
148088
148278
|
child.once("exit", (code, signal) => {
|
|
148089
148279
|
ownedHeadroom.delete(pid);
|
|
148090
148280
|
exitedHeadroom.add(pid);
|
|
148091
|
-
|
|
148281
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: headroom exited (${signal ?? `code ${String(code)}`})
|
|
148092
148282
|
`);
|
|
148093
148283
|
});
|
|
148094
148284
|
return pid;
|
|
148095
148285
|
} finally {
|
|
148096
|
-
|
|
148286
|
+
import_node_fs25.default.closeSync(logFd);
|
|
148097
148287
|
}
|
|
148098
148288
|
},
|
|
148099
148289
|
stopProcess: (pid) => {
|
|
@@ -148106,7 +148296,7 @@ function realSupervisorPorts(paths) {
|
|
|
148106
148296
|
now: () => Date.now()
|
|
148107
148297
|
});
|
|
148108
148298
|
if (outcome === "still-running") {
|
|
148109
|
-
|
|
148299
|
+
import_node_fs25.default.appendFileSync(
|
|
148110
148300
|
paths.headroomLogPath,
|
|
148111
148301
|
`${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: pid ${String(pid)} survived SIGKILL within its grace; it is stuck uninterruptibly
|
|
148112
148302
|
`
|
|
@@ -148115,7 +148305,7 @@ function realSupervisorPorts(paths) {
|
|
|
148115
148305
|
},
|
|
148116
148306
|
ready: readyOverSocket,
|
|
148117
148307
|
install: (spec) => {
|
|
148118
|
-
const result = (0,
|
|
148308
|
+
const result = (0, import_node_child_process10.spawnSync)("uv", ["tool", "install", spec], { encoding: "utf8", timeout: HEADROOM_INSTALL_TIMEOUT_MS });
|
|
148119
148309
|
if (result.error !== void 0) {
|
|
148120
148310
|
const timedOut = "code" in result.error && result.error.code === "ETIMEDOUT";
|
|
148121
148311
|
return {
|
|
@@ -148124,21 +148314,21 @@ function realSupervisorPorts(paths) {
|
|
|
148124
148314
|
};
|
|
148125
148315
|
}
|
|
148126
148316
|
if (result.stdout !== "") {
|
|
148127
|
-
|
|
148317
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, result.stdout);
|
|
148128
148318
|
}
|
|
148129
148319
|
if (result.stderr !== "") {
|
|
148130
|
-
|
|
148320
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, result.stderr);
|
|
148131
148321
|
}
|
|
148132
148322
|
return result.status === 0 ? { ok: true } : { ok: false, error: `uv tool install exited ${String(result.status)}` };
|
|
148133
148323
|
},
|
|
148134
148324
|
headroomVersion: () => {
|
|
148135
|
-
const result = (0,
|
|
148325
|
+
const result = (0, import_node_child_process10.spawnSync)("headroom", ["--version"], { encoding: "utf8" });
|
|
148136
148326
|
return result.status === 0 ? result.stdout.trim() : void 0;
|
|
148137
148327
|
},
|
|
148138
148328
|
installedCommit: readInstalledHeadroomCommit,
|
|
148139
148329
|
log: (line) => {
|
|
148140
|
-
|
|
148141
|
-
|
|
148330
|
+
import_node_fs25.default.mkdirSync(paths.logsDir, { recursive: true });
|
|
148331
|
+
import_node_fs25.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
148142
148332
|
`);
|
|
148143
148333
|
}
|
|
148144
148334
|
};
|
|
@@ -148271,9 +148461,9 @@ init_providersStore();
|
|
|
148271
148461
|
init_realPorts();
|
|
148272
148462
|
var realCatalogueFetch = async (url2, headers, timeoutMs) => {
|
|
148273
148463
|
const response = await fetch(url2, { headers: { ...headers }, signal: AbortSignal.timeout(timeoutMs) });
|
|
148274
|
-
const
|
|
148464
|
+
const text3 = await response.text();
|
|
148275
148465
|
try {
|
|
148276
|
-
const body = JSON.parse(
|
|
148466
|
+
const body = JSON.parse(text3);
|
|
148277
148467
|
return { status: response.status, body };
|
|
148278
148468
|
} catch {
|
|
148279
148469
|
return { status: response.status, body: void 0 };
|
|
@@ -148645,12 +148835,12 @@ init_translate();
|
|
|
148645
148835
|
init_schema();
|
|
148646
148836
|
init_cliError();
|
|
148647
148837
|
init_providerCatalogue();
|
|
148648
|
-
var
|
|
148838
|
+
var import_node_fs27 = __toESM(require("node:fs"), 1);
|
|
148649
148839
|
init_credential();
|
|
148650
148840
|
init_providerAliases();
|
|
148651
148841
|
|
|
148652
148842
|
// src/providerRename.ts
|
|
148653
|
-
var
|
|
148843
|
+
var import_node_fs26 = __toESM(require("node:fs"), 1);
|
|
148654
148844
|
var import_node_path62 = __toESM(require("node:path"), 1);
|
|
148655
148845
|
init_schema();
|
|
148656
148846
|
init_store();
|
|
@@ -148716,7 +148906,7 @@ function renameProvider(paths, from, to2, ports) {
|
|
|
148716
148906
|
const previousAliases = readProviderAliases(paths);
|
|
148717
148907
|
writeProviderAliases(paths, aliasesAfterRename(previousAliases, from, to2));
|
|
148718
148908
|
try {
|
|
148719
|
-
|
|
148909
|
+
import_node_fs26.default.renameSync(providerJsonPath(paths, from), providerJsonPath(paths, to2));
|
|
148720
148910
|
} catch (error63) {
|
|
148721
148911
|
writeProviderAliases(paths, previousAliases);
|
|
148722
148912
|
throw error63;
|
|
@@ -148736,8 +148926,8 @@ function moveState(paths, from, to2, ports) {
|
|
|
148736
148926
|
`);
|
|
148737
148927
|
moved.push(`usage ${snapshot.identity}`);
|
|
148738
148928
|
}
|
|
148739
|
-
if (
|
|
148740
|
-
|
|
148929
|
+
if (import_node_fs26.default.existsSync(catalogueCachePath(paths, from))) {
|
|
148930
|
+
import_node_fs26.default.renameSync(catalogueCachePath(paths, from), catalogueCachePath(paths, to2));
|
|
148741
148931
|
moved.push("catalogue");
|
|
148742
148932
|
}
|
|
148743
148933
|
const renamed = readProvider(paths, to2);
|
|
@@ -149068,7 +149258,7 @@ function registerProviderCommand(program2, deps) {
|
|
|
149068
149258
|
throw new UsageError(`Provider "${name}" has no catalogue setting. Set one with \`agent-shim provider set ${name} --catalogue-tier <tier>\`.`);
|
|
149069
149259
|
}
|
|
149070
149260
|
const catalogueSetting = found.catalogue;
|
|
149071
|
-
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);
|
|
149072
149262
|
if (cache === void 0) {
|
|
149073
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\`.`);
|
|
149074
149264
|
}
|
|
@@ -149612,14 +149802,14 @@ function requireIdentity(paths, name) {
|
|
|
149612
149802
|
throw new IdentityNotFoundError(name);
|
|
149613
149803
|
}
|
|
149614
149804
|
}
|
|
149615
|
-
function collectUsageReport(
|
|
149805
|
+
function collectUsageReport(fs30, paths, filters) {
|
|
149616
149806
|
const { identity, provider, sinceMs } = filters;
|
|
149617
149807
|
if (identity !== void 0) {
|
|
149618
149808
|
requireIdentity(paths, identity);
|
|
149619
149809
|
}
|
|
149620
|
-
const log = readUsageLog(
|
|
149810
|
+
const log = readUsageLog(fs30, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
|
|
149621
149811
|
const records = log.records.filter((record2) => (identity === void 0 || record2.identity === identity) && (provider === void 0 || record2.provider === provider));
|
|
149622
|
-
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);
|
|
149623
149813
|
return {
|
|
149624
149814
|
since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
|
|
149625
149815
|
logDir: paths.usageLogDir,
|
|
@@ -149726,16 +149916,16 @@ function formatUsageReport(report) {
|
|
|
149726
149916
|
}
|
|
149727
149917
|
return lines;
|
|
149728
149918
|
}
|
|
149729
|
-
function collectAccounts(
|
|
149919
|
+
function collectAccounts(fs30, paths, identity, probe) {
|
|
149730
149920
|
if (identity !== void 0) {
|
|
149731
149921
|
requireIdentity(paths, identity);
|
|
149732
149922
|
}
|
|
149733
149923
|
const names = identity === void 0 ? listIdentities(paths).map((entry) => entry.name) : [identity];
|
|
149734
149924
|
return names.map((name) => ({
|
|
149735
149925
|
identity: name,
|
|
149736
|
-
account: readAccountMetadata(
|
|
149737
|
-
signIn: identitySignIn(
|
|
149738
|
-
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)
|
|
149739
149929
|
}));
|
|
149740
149930
|
}
|
|
149741
149931
|
function formatAccounts(views) {
|
|
@@ -150071,8 +150261,8 @@ function createRealCompactor(params) {
|
|
|
150071
150261
|
sizes = boundarySizes(message);
|
|
150072
150262
|
}
|
|
150073
150263
|
if (message.type === "result") {
|
|
150074
|
-
const
|
|
150075
|
-
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 };
|
|
150076
150266
|
}
|
|
150077
150267
|
}
|
|
150078
150268
|
throw new Error("the compaction ended without a result");
|
|
@@ -150085,15 +150275,15 @@ function createRealCompactor(params) {
|
|
|
150085
150275
|
// src/supervise/compactionDeps.ts
|
|
150086
150276
|
var COMPACT_SLOT_STALE_MS = COMPACT_TIMEOUT_MS * 2;
|
|
150087
150277
|
function createCompactionDeps(wiring) {
|
|
150088
|
-
const { paths, fs:
|
|
150278
|
+
const { paths, fs: fs30, pool } = wiring;
|
|
150089
150279
|
return {
|
|
150090
150280
|
shouldCompact: (identity, sessionId) => {
|
|
150091
150281
|
const nowMs = wiring.now();
|
|
150092
|
-
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) }));
|
|
150093
150283
|
return decideCompaction({
|
|
150094
150284
|
atUtilisation: wiring.policy.compactAtUtilisation,
|
|
150095
|
-
snapshot: readUsageSnapshot(
|
|
150096
|
-
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),
|
|
150097
150287
|
sessions,
|
|
150098
150288
|
sessionId,
|
|
150099
150289
|
nowMs
|
|
@@ -150101,7 +150291,7 @@ function createCompactionDeps(wiring) {
|
|
|
150101
150291
|
},
|
|
150102
150292
|
acquire: (identity) => {
|
|
150103
150293
|
try {
|
|
150104
|
-
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 });
|
|
150105
150295
|
return { release: lock.release };
|
|
150106
150296
|
} catch (error63) {
|
|
150107
150297
|
if (error63 instanceof IdentityLockBusyError) {
|
|
@@ -150112,8 +150302,8 @@ function createCompactionDeps(wiring) {
|
|
|
150112
150302
|
},
|
|
150113
150303
|
compact: wiring.compact,
|
|
150114
150304
|
markCompacted: (sessionId, compacted) => {
|
|
150115
|
-
const previous = readSessionState(
|
|
150116
|
-
writeSessionState(
|
|
150305
|
+
const previous = readSessionState(fs30, paths, pool, sessionId);
|
|
150306
|
+
writeSessionState(fs30, paths, pool, sessionId, {
|
|
150117
150307
|
mark: previous?.mark ?? "idle",
|
|
150118
150308
|
...previous?.contextTokens === void 0 ? {} : { contextTokens: previous.contextTokens },
|
|
150119
150309
|
...compacted ? { compacted: true } : {},
|
|
@@ -150125,12 +150315,12 @@ function createCompactionDeps(wiring) {
|
|
|
150125
150315
|
|
|
150126
150316
|
// src/supervise/limit.ts
|
|
150127
150317
|
init_read();
|
|
150128
|
-
function quotaHitOf(
|
|
150129
|
-
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);
|
|
150130
150320
|
if (reason === void 0) {
|
|
150131
150321
|
return void 0;
|
|
150132
150322
|
}
|
|
150133
|
-
const { records } = readUsageLog(
|
|
150323
|
+
const { records } = readUsageLog(fs30, paths.usageLogDir, { sinceMs });
|
|
150134
150324
|
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
150135
150325
|
const record2 = records[index];
|
|
150136
150326
|
if (record2?.sessionId === sessionId && record2.identity === identity && record2.limit?.kind === "quota-exhausted") {
|
|
@@ -150249,12 +150439,12 @@ function createIdentityMover(deps) {
|
|
|
150249
150439
|
}
|
|
150250
150440
|
|
|
150251
150441
|
// src/supervise/realPorts.ts
|
|
150252
|
-
var
|
|
150253
|
-
var
|
|
150442
|
+
var import_node_child_process11 = require("node:child_process");
|
|
150443
|
+
var import_node_fs28 = __toESM(require("node:fs"), 1);
|
|
150254
150444
|
init_realPorts();
|
|
150255
150445
|
var realSupervisedSpawnPort = {
|
|
150256
150446
|
spawn(command, args, options) {
|
|
150257
|
-
const child = (0,
|
|
150447
|
+
const child = (0, import_node_child_process11.spawn)(command, [...args], { stdio: options.stdio, env: { ...options.env } });
|
|
150258
150448
|
const exit = new Promise((resolve2) => {
|
|
150259
150449
|
child.once("error", (error63) => {
|
|
150260
150450
|
resolve2({ status: null, signal: null, error: error63 });
|
|
@@ -150296,7 +150486,7 @@ var realTimerPort = {
|
|
|
150296
150486
|
function realWatchDirectory(directory, accepts, what, log) {
|
|
150297
150487
|
return (onChange) => {
|
|
150298
150488
|
realFarmFs.mkdirPrivate(directory);
|
|
150299
|
-
const watcher =
|
|
150489
|
+
const watcher = import_node_fs28.default.watch(directory, { persistent: false }, (_event, filename) => {
|
|
150300
150490
|
if (filename === null || accepts(filename)) {
|
|
150301
150491
|
onChange();
|
|
150302
150492
|
}
|
|
@@ -150316,7 +150506,7 @@ function resetTerminal() {
|
|
|
150316
150506
|
return;
|
|
150317
150507
|
}
|
|
150318
150508
|
process.stdout.write(TERMINAL_RESET);
|
|
150319
|
-
(0,
|
|
150509
|
+
(0, import_node_child_process11.spawnSync)("stty", ["sane"], { stdio: ["inherit", "ignore", "ignore"] });
|
|
150320
150510
|
}
|
|
150321
150511
|
|
|
150322
150512
|
// src/supervise/supervise.ts
|