@codexhost/cli-linux-arm64 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/host-runtime.mjs +470 -80
- package/app/plugins/claude-code/plugin.mjs +26 -15
- package/app/plugins/codex-usage/plugin.mjs +18 -9
- package/app/plugins/hermes/plugin.mjs +184 -40
- package/app/renderer-extension.js +64 -35
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
|
@@ -57211,7 +57211,7 @@ var ClaudeSdkTransport = class {
|
|
|
57211
57211
|
/** Starts the Segment's autonomous Turn and releases the events it held, in native order. */
|
|
57212
57212
|
#startAutonomousTurn(autonomous, handler) {
|
|
57213
57213
|
autonomous.live = true;
|
|
57214
|
-
handler.start(autonomous.
|
|
57214
|
+
handler.start(autonomous.userMessageId ?? `autonomous-${Date.now()}`, autonomous.userMessageId);
|
|
57215
57215
|
for (const event of autonomous.events.splice(0))
|
|
57216
57216
|
handler.onEvent(event);
|
|
57217
57217
|
}
|
|
@@ -57275,11 +57275,11 @@ var ClaudeSdkTransport = class {
|
|
|
57275
57275
|
const autonomous = this.#autonomous ?? (this.#autonomous = {
|
|
57276
57276
|
accumulator: new ClaudeNativeTurnAccumulator(this.#provider ? { provider: this.#provider } : {}),
|
|
57277
57277
|
events: [],
|
|
57278
|
-
|
|
57278
|
+
userMessageId: null,
|
|
57279
57279
|
live: false
|
|
57280
57280
|
});
|
|
57281
|
-
if (autonomous.
|
|
57282
|
-
autonomous.
|
|
57281
|
+
if (autonomous.userMessageId === null && isRecord10(message) && message.type === "user" && (message.parent_tool_use_id === null || message.parent_tool_use_id === void 0) && typeof message.uuid === "string" && message.uuid.length > 0) {
|
|
57282
|
+
autonomous.userMessageId = message.uuid;
|
|
57283
57283
|
}
|
|
57284
57284
|
const interpreted = autonomous.accumulator.consume(message);
|
|
57285
57285
|
for (const event of interpreted.events) {
|
|
@@ -58810,6 +58810,7 @@ var ClaudeHarnessSession = class {
|
|
|
58810
58810
|
interactionByRequestId: /* @__PURE__ */ new Map(),
|
|
58811
58811
|
agentScopedRequestIds: /* @__PURE__ */ new Set(),
|
|
58812
58812
|
checkpointId: null,
|
|
58813
|
+
userMessageId: null,
|
|
58813
58814
|
nativeTurnKey,
|
|
58814
58815
|
nativeTurnRef: null,
|
|
58815
58816
|
cancellationRequested: false,
|
|
@@ -58840,6 +58841,7 @@ var ClaudeHarnessSession = class {
|
|
|
58840
58841
|
const running = transport.runTurn(text2, nativeTurnRef.nativeTurnKey, (event) => {
|
|
58841
58842
|
this.#handleTurnEvent(active, event);
|
|
58842
58843
|
});
|
|
58844
|
+
active.userMessageId = nativeTurnRef.nativeTurnKey;
|
|
58843
58845
|
active.nativeTurnRef = nativeTurnRef;
|
|
58844
58846
|
void running.then((result) => this.#finishResult(active, result), () => this.#handleTurnTransportFailure(active));
|
|
58845
58847
|
} catch {
|
|
@@ -58939,6 +58941,7 @@ var ClaudeHarnessSession = class {
|
|
|
58939
58941
|
interactionByRequestId: /* @__PURE__ */ new Map(),
|
|
58940
58942
|
agentScopedRequestIds: /* @__PURE__ */ new Set(),
|
|
58941
58943
|
checkpointId: null,
|
|
58944
|
+
userMessageId: null,
|
|
58942
58945
|
nativeTurnKey,
|
|
58943
58946
|
nativeTurnRef: null,
|
|
58944
58947
|
cancellationRequested: false,
|
|
@@ -59483,8 +59486,8 @@ var ClaudeHarnessSession = class {
|
|
|
59483
59486
|
});
|
|
59484
59487
|
this.#transport = transport;
|
|
59485
59488
|
transport.setAutonomousTurnHandler({
|
|
59486
|
-
start: (nativeTurnKey) => {
|
|
59487
|
-
this.#autonomousTarget = this.#startAutonomousTurn(nativeTurnKey);
|
|
59489
|
+
start: (nativeTurnKey, userMessageId) => {
|
|
59490
|
+
this.#autonomousTarget = this.#startAutonomousTurn(nativeTurnKey, userMessageId);
|
|
59488
59491
|
},
|
|
59489
59492
|
onEvent: (event) => this.#deliverLiveEvent(this.#autonomousTarget, event),
|
|
59490
59493
|
onTerminal: (result) => {
|
|
@@ -59966,7 +59969,7 @@ var ClaudeHarnessSession = class {
|
|
|
59966
59969
|
* it; otherwise it becomes a live autonomous Turn, so the Thread shows it running and a new
|
|
59967
59970
|
* request waits instead of absorbing it.
|
|
59968
59971
|
*/
|
|
59969
|
-
#startAutonomousTurn(segmentKey) {
|
|
59972
|
+
#startAutonomousTurn(segmentKey, userMessageId) {
|
|
59970
59973
|
if (this.#phase !== "open")
|
|
59971
59974
|
return null;
|
|
59972
59975
|
const current = this.#active;
|
|
@@ -60016,6 +60019,7 @@ var ClaudeHarnessSession = class {
|
|
|
60016
60019
|
interactionByRequestId: /* @__PURE__ */ new Map(),
|
|
60017
60020
|
agentScopedRequestIds: /* @__PURE__ */ new Set(),
|
|
60018
60021
|
checkpointId: null,
|
|
60022
|
+
userMessageId,
|
|
60019
60023
|
nativeTurnKey,
|
|
60020
60024
|
nativeTurnRef: nativeTurnRefSchema.parse({
|
|
60021
60025
|
harnessId: this.harnessId,
|
|
@@ -60410,12 +60414,15 @@ var ClaudeHarnessSession = class {
|
|
|
60410
60414
|
checkpointId: active.checkpointId,
|
|
60411
60415
|
formatVersion: 1
|
|
60412
60416
|
}) : null;
|
|
60413
|
-
|
|
60414
|
-
|
|
60415
|
-
|
|
60416
|
-
|
|
60417
|
-
|
|
60418
|
-
|
|
60417
|
+
if (active.userMessageId || active.checkpointId) {
|
|
60418
|
+
this.#unpersistedMessageIds = [
|
|
60419
|
+
.../* @__PURE__ */ new Set([
|
|
60420
|
+
...this.#unpersistedMessageIds,
|
|
60421
|
+
...active.userMessageId ? [active.userMessageId] : [],
|
|
60422
|
+
...active.checkpointId ? [active.checkpointId] : []
|
|
60423
|
+
])
|
|
60424
|
+
];
|
|
60425
|
+
}
|
|
60419
60426
|
this.#event({
|
|
60420
60427
|
type: "turn.completed",
|
|
60421
60428
|
turnId: active.command.turnId,
|
|
@@ -60547,6 +60554,7 @@ var ClaudeCodeAdapter = class {
|
|
|
60547
60554
|
#cancelTimeoutMs;
|
|
60548
60555
|
#closeTimeoutMs;
|
|
60549
60556
|
#dependencies;
|
|
60557
|
+
#environment;
|
|
60550
60558
|
#importIndex;
|
|
60551
60559
|
#importScope = new SessionImportScope({
|
|
60552
60560
|
closedMessage: "Claude Code Adapter is closed",
|
|
@@ -60565,6 +60573,7 @@ var ClaudeCodeAdapter = class {
|
|
|
60565
60573
|
#accountInspection = null;
|
|
60566
60574
|
constructor(options = {}, dependencies) {
|
|
60567
60575
|
const environment = options.environment ?? process.env;
|
|
60576
|
+
this.#environment = environment;
|
|
60568
60577
|
this.#importIndex = new ClaudeSessionImportIndex(environment);
|
|
60569
60578
|
this.usageStatistics = createClaudeUsageStatistics(environment);
|
|
60570
60579
|
this.#pendingSessions = new ClaudePendingSessions(environment);
|
|
@@ -60810,7 +60819,8 @@ var ClaudeCodeAdapter = class {
|
|
|
60810
60819
|
}
|
|
60811
60820
|
};
|
|
60812
60821
|
}
|
|
60813
|
-
const
|
|
60822
|
+
const environment = input.environment ? { ...this.#environment, ...input.environment } : void 0;
|
|
60823
|
+
const bypassPermissionsAvailable = this.#dependencies.bypassPermissionsAvailable(environment);
|
|
60814
60824
|
if (!bypassPermissionsAvailable && requestedPermissionModeId === "bypassPermissions") {
|
|
60815
60825
|
if (input.kind === "create") {
|
|
60816
60826
|
return {
|
|
@@ -60901,7 +60911,7 @@ var ClaudeCodeAdapter = class {
|
|
|
60901
60911
|
const sessionId = forked?.ok ? forked.value.sessionId : nativeRef?.success ? nativeRef.data.nativeSessionId : this.#dependencies.randomUUID();
|
|
60902
60912
|
const usageHistory = await this.#readUsageHistory(cwd, sessionId, openMode);
|
|
60903
60913
|
const session = new ClaudeHarnessSession(cwd, this.#dependencies, this.#closeTimeoutMs, () => this.#sessions.delete(session), (planLimit) => this.#recordPlanLimit(session, planLimit), {
|
|
60904
|
-
...
|
|
60914
|
+
...environment ? { environment } : {},
|
|
60905
60915
|
bypassPermissionsAvailable,
|
|
60906
60916
|
openMode,
|
|
60907
60917
|
pendingSessions: this.#pendingSessions,
|
|
@@ -61114,6 +61124,7 @@ async function createHarnessAdapter(context) {
|
|
|
61114
61124
|
const environment = await withUserShellEnvironment({ ...context.environment });
|
|
61115
61125
|
if (context.platform === "darwin" && context.managedRemoteHost) {
|
|
61116
61126
|
return new BrokeredHarnessAdapter({
|
|
61127
|
+
forwardDelegationEnvironment: true,
|
|
61117
61128
|
commandCatalog: claudeCommandCatalog,
|
|
61118
61129
|
liveCommandCatalog: true,
|
|
61119
61130
|
environment,
|
|
@@ -16543,6 +16543,22 @@ async function copyRelation(a, b, signal) {
|
|
|
16543
16543
|
// dist/usage-statistics.js
|
|
16544
16544
|
var ROLLOUT = /^rollout-.*?([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})(?:[_-][0-9a-f-]+)?\.jsonl(?:\.zst)?$/iu;
|
|
16545
16545
|
var text = (value) => typeof value === "string" ? value : "";
|
|
16546
|
+
var ROW_KINDS = /* @__PURE__ */ new Set([
|
|
16547
|
+
"session_meta",
|
|
16548
|
+
"turn_context",
|
|
16549
|
+
"token_usage_record",
|
|
16550
|
+
"compacted",
|
|
16551
|
+
"event_msg",
|
|
16552
|
+
"response_item"
|
|
16553
|
+
]);
|
|
16554
|
+
var HEAD_TYPE = /"type"\s*:\s*"([^"]+)"/u;
|
|
16555
|
+
var TAIL_TYPE = /"type"\s*:\s*"([^"]+)"\s*\}\s*$/u;
|
|
16556
|
+
function rowKind(line) {
|
|
16557
|
+
const head = HEAD_TYPE.exec(line.slice(0, 1024))?.[1];
|
|
16558
|
+
if (head && ROW_KINDS.has(head))
|
|
16559
|
+
return head;
|
|
16560
|
+
return TAIL_TYPE.exec(line.slice(-1024))?.[1] ?? head;
|
|
16561
|
+
}
|
|
16546
16562
|
async function stamp(file2) {
|
|
16547
16563
|
const s = await lstat(file2, { bigint: true });
|
|
16548
16564
|
if (!s.isFile())
|
|
@@ -16601,17 +16617,10 @@ async function readCodexRollouts(files, thread, signal, options = {}) {
|
|
|
16601
16617
|
signal.throwIfAborted();
|
|
16602
16618
|
if (++seen % 128 === 0)
|
|
16603
16619
|
await yieldToEventLoop(void 0, { signal });
|
|
16604
|
-
const kind =
|
|
16620
|
+
const kind = rowKind(line);
|
|
16605
16621
|
if (!kind && line.trim())
|
|
16606
16622
|
options.onIncomplete?.();
|
|
16607
|
-
if (!kind || !
|
|
16608
|
-
"session_meta",
|
|
16609
|
-
"turn_context",
|
|
16610
|
-
"token_usage_record",
|
|
16611
|
-
"compacted",
|
|
16612
|
-
"event_msg",
|
|
16613
|
-
"response_item"
|
|
16614
|
-
].includes(kind))
|
|
16623
|
+
if (!kind || !ROW_KINDS.has(kind))
|
|
16615
16624
|
continue;
|
|
16616
16625
|
if (kind === "response_item" && !/"role"\s*:\s*"user"/u.test(line.slice(0, 1024)))
|
|
16617
16626
|
continue;
|
|
@@ -1138,10 +1138,10 @@ function mergeDefs(...defs) {
|
|
|
1138
1138
|
function cloneDef(schema) {
|
|
1139
1139
|
return mergeDefs(schema._zod.def);
|
|
1140
1140
|
}
|
|
1141
|
-
function getElementAtPath(obj,
|
|
1142
|
-
if (!
|
|
1141
|
+
function getElementAtPath(obj, path9) {
|
|
1142
|
+
if (!path9)
|
|
1143
1143
|
return obj;
|
|
1144
|
-
return
|
|
1144
|
+
return path9.reduce((acc, key) => acc?.[key], obj);
|
|
1145
1145
|
}
|
|
1146
1146
|
function promiseAllObject(promisesObj) {
|
|
1147
1147
|
const keys = Object.keys(promisesObj);
|
|
@@ -1550,11 +1550,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1550
1550
|
}
|
|
1551
1551
|
return false;
|
|
1552
1552
|
}
|
|
1553
|
-
function prefixIssues(
|
|
1553
|
+
function prefixIssues(path9, issues) {
|
|
1554
1554
|
return issues.map((iss) => {
|
|
1555
1555
|
var _a3;
|
|
1556
1556
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1557
|
-
iss.path.unshift(
|
|
1557
|
+
iss.path.unshift(path9);
|
|
1558
1558
|
return iss;
|
|
1559
1559
|
});
|
|
1560
1560
|
}
|
|
@@ -1701,16 +1701,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1701
1701
|
}
|
|
1702
1702
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1703
1703
|
const fieldErrors = { _errors: [] };
|
|
1704
|
-
const processError = (error52,
|
|
1704
|
+
const processError = (error52, path9 = []) => {
|
|
1705
1705
|
for (const issue2 of error52.issues) {
|
|
1706
1706
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1707
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1707
|
+
issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
|
|
1708
1708
|
} else if (issue2.code === "invalid_key") {
|
|
1709
|
-
processError({ issues: issue2.issues }, [...
|
|
1709
|
+
processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
|
|
1710
1710
|
} else if (issue2.code === "invalid_element") {
|
|
1711
|
-
processError({ issues: issue2.issues }, [...
|
|
1711
|
+
processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
|
|
1712
1712
|
} else {
|
|
1713
|
-
const fullpath = [...
|
|
1713
|
+
const fullpath = [...path9, ...issue2.path];
|
|
1714
1714
|
if (fullpath.length === 0) {
|
|
1715
1715
|
fieldErrors._errors.push(mapper(issue2));
|
|
1716
1716
|
} else {
|
|
@@ -1737,17 +1737,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1737
1737
|
}
|
|
1738
1738
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1739
1739
|
const result = { errors: [] };
|
|
1740
|
-
const processError = (error52,
|
|
1740
|
+
const processError = (error52, path9 = []) => {
|
|
1741
1741
|
var _a3, _b;
|
|
1742
1742
|
for (const issue2 of error52.issues) {
|
|
1743
1743
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1744
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1744
|
+
issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
|
|
1745
1745
|
} else if (issue2.code === "invalid_key") {
|
|
1746
|
-
processError({ issues: issue2.issues }, [...
|
|
1746
|
+
processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
|
|
1747
1747
|
} else if (issue2.code === "invalid_element") {
|
|
1748
|
-
processError({ issues: issue2.issues }, [...
|
|
1748
|
+
processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
|
|
1749
1749
|
} else {
|
|
1750
|
-
const fullpath = [...
|
|
1750
|
+
const fullpath = [...path9, ...issue2.path];
|
|
1751
1751
|
if (fullpath.length === 0) {
|
|
1752
1752
|
result.errors.push(mapper(issue2));
|
|
1753
1753
|
continue;
|
|
@@ -1779,8 +1779,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1779
1779
|
}
|
|
1780
1780
|
function toDotPath(_path) {
|
|
1781
1781
|
const segs = [];
|
|
1782
|
-
const
|
|
1783
|
-
for (const seg of
|
|
1782
|
+
const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1783
|
+
for (const seg of path9) {
|
|
1784
1784
|
if (typeof seg === "number")
|
|
1785
1785
|
segs.push(`[${seg}]`);
|
|
1786
1786
|
else if (typeof seg === "symbol")
|
|
@@ -14472,13 +14472,13 @@ function resolveRef(ref, ctx) {
|
|
|
14472
14472
|
if (!ref.startsWith("#")) {
|
|
14473
14473
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14474
14474
|
}
|
|
14475
|
-
const
|
|
14476
|
-
if (
|
|
14475
|
+
const path9 = ref.slice(1).split("/").filter(Boolean);
|
|
14476
|
+
if (path9.length === 0) {
|
|
14477
14477
|
return ctx.rootSchema;
|
|
14478
14478
|
}
|
|
14479
14479
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14480
|
-
if (
|
|
14481
|
-
const key =
|
|
14480
|
+
if (path9[0] === defsKey) {
|
|
14481
|
+
const key = path9[1];
|
|
14482
14482
|
if (!key || !ctx.defs[key]) {
|
|
14483
14483
|
throw new Error(`Reference not found: ${ref}`);
|
|
14484
14484
|
}
|
|
@@ -18010,14 +18010,14 @@ function gatewayDiff(text2) {
|
|
|
18010
18010
|
if (!text2 || text2.length > 1024 * 1024)
|
|
18011
18011
|
return [];
|
|
18012
18012
|
const result = [];
|
|
18013
|
-
let
|
|
18013
|
+
let path9 = "";
|
|
18014
18014
|
let inHunk = false;
|
|
18015
18015
|
let oldLines = [], newLines = [];
|
|
18016
18016
|
const flush = () => {
|
|
18017
|
-
if (
|
|
18017
|
+
if (path9)
|
|
18018
18018
|
result.push({
|
|
18019
18019
|
type: "diff",
|
|
18020
|
-
path:
|
|
18020
|
+
path: path9,
|
|
18021
18021
|
oldText: oldLines.join("\n"),
|
|
18022
18022
|
newText: newLines.join("\n")
|
|
18023
18023
|
});
|
|
@@ -18030,24 +18030,24 @@ function gatewayDiff(text2) {
|
|
|
18030
18030
|
if (header) {
|
|
18031
18031
|
flush();
|
|
18032
18032
|
inHunk = false;
|
|
18033
|
-
|
|
18033
|
+
path9 = (header[2] === "/dev/null" ? header[1] ?? "" : header[2] ?? "").replace(/^[ab]\//u, "");
|
|
18034
18034
|
continue;
|
|
18035
18035
|
}
|
|
18036
18036
|
if (line.startsWith("--- ") && !inHunk) {
|
|
18037
18037
|
flush();
|
|
18038
|
-
|
|
18038
|
+
path9 = line.slice(4).replace(/^a\//u, "");
|
|
18039
18039
|
} else if (line.startsWith("+++ ") && !inHunk) {
|
|
18040
18040
|
const next = line.slice(4);
|
|
18041
18041
|
if (next !== "/dev/null")
|
|
18042
|
-
|
|
18042
|
+
path9 = next.replace(/^b\//u, "");
|
|
18043
18043
|
} else if (line.startsWith("@@")) {
|
|
18044
18044
|
inHunk = true;
|
|
18045
18045
|
continue;
|
|
18046
|
-
} else if (
|
|
18046
|
+
} else if (path9 && line.startsWith("-"))
|
|
18047
18047
|
oldLines.push(line.slice(1));
|
|
18048
|
-
else if (
|
|
18048
|
+
else if (path9 && line.startsWith("+"))
|
|
18049
18049
|
newLines.push(line.slice(1));
|
|
18050
|
-
else if (
|
|
18050
|
+
else if (path9 && line.startsWith(" ")) {
|
|
18051
18051
|
oldLines.push(line.slice(1));
|
|
18052
18052
|
newLines.push(line.slice(1));
|
|
18053
18053
|
}
|
|
@@ -18471,8 +18471,150 @@ var HermesGatewaySessionTransport = class {
|
|
|
18471
18471
|
}
|
|
18472
18472
|
};
|
|
18473
18473
|
|
|
18474
|
-
// dist/
|
|
18474
|
+
// dist/usage-statistics.js
|
|
18475
|
+
import os3 from "node:os";
|
|
18475
18476
|
import path7 from "node:path";
|
|
18477
|
+
import { lstat } from "node:fs/promises";
|
|
18478
|
+
|
|
18479
|
+
// ../../harness-adapter/dist/usage-statistics.js
|
|
18480
|
+
var MAX_SESSION_ID_LENGTH = 512;
|
|
18481
|
+
var MAX_CWD_LENGTH = 4096;
|
|
18482
|
+
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
18483
|
+
function usageSessionTitle(value) {
|
|
18484
|
+
if (typeof value !== "string")
|
|
18485
|
+
return void 0;
|
|
18486
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
18487
|
+
if (!normalized)
|
|
18488
|
+
return void 0;
|
|
18489
|
+
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
18490
|
+
return normalized;
|
|
18491
|
+
const characters = [...normalized];
|
|
18492
|
+
if (characters.length <= MAX_SESSION_TITLE_LENGTH)
|
|
18493
|
+
return normalized;
|
|
18494
|
+
return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
|
|
18495
|
+
}
|
|
18496
|
+
function sessionIdOk(value) {
|
|
18497
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
18498
|
+
}
|
|
18499
|
+
function cwdOk(value) {
|
|
18500
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
18501
|
+
}
|
|
18502
|
+
function withUsageSession(entry, session) {
|
|
18503
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
18504
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
18505
|
+
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
18506
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
18507
|
+
return entry;
|
|
18508
|
+
return {
|
|
18509
|
+
...entry,
|
|
18510
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
18511
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
18512
|
+
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
18513
|
+
};
|
|
18514
|
+
}
|
|
18515
|
+
function usageEntryFromRequest(request, occurredAtMs) {
|
|
18516
|
+
if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
|
|
18517
|
+
return null;
|
|
18518
|
+
return {
|
|
18519
|
+
id: request.requestId,
|
|
18520
|
+
occurredAtMs,
|
|
18521
|
+
...request.model !== void 0 ? { model: request.model } : {},
|
|
18522
|
+
inputTokens: request.inputTokens,
|
|
18523
|
+
...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
|
|
18524
|
+
...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
|
|
18525
|
+
...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
|
|
18526
|
+
outputTokens: request.outputTokens,
|
|
18527
|
+
...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
|
|
18528
|
+
};
|
|
18529
|
+
}
|
|
18530
|
+
|
|
18531
|
+
// dist/usage-statistics.js
|
|
18532
|
+
function hermesStateDatabasePath(environment) {
|
|
18533
|
+
const home = environment.HOME || environment.USERPROFILE || os3.homedir();
|
|
18534
|
+
const configured = environment.HERMES_HOME;
|
|
18535
|
+
return path7.resolve(configured ? path7.join(configured, "state.db") : path7.join(home, ".hermes", "state.db"));
|
|
18536
|
+
}
|
|
18537
|
+
async function fingerprint(file2) {
|
|
18538
|
+
const info = await lstat(file2).catch(() => null);
|
|
18539
|
+
if (!info?.isFile())
|
|
18540
|
+
return null;
|
|
18541
|
+
const wal = await lstat(`${file2}-wal`).catch(() => null);
|
|
18542
|
+
return `${info.ino}:${info.size}:${info.mtimeMs}:${wal ? `${wal.size}:${wal.mtimeMs}` : "-"}`;
|
|
18543
|
+
}
|
|
18544
|
+
function tokenCount(value) {
|
|
18545
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
18546
|
+
}
|
|
18547
|
+
function hermesUsageEntry(row) {
|
|
18548
|
+
const apiCalls = tokenCount(row.api_call_count) ? row.api_call_count : 0;
|
|
18549
|
+
const input = tokenCount(row.input_tokens) ? row.input_tokens : 0;
|
|
18550
|
+
const output = tokenCount(row.output_tokens) ? row.output_tokens : 0;
|
|
18551
|
+
const cacheRead = tokenCount(row.cache_read_tokens) ? row.cache_read_tokens : 0;
|
|
18552
|
+
const cacheWrite = tokenCount(row.cache_write_tokens) ? row.cache_write_tokens : 0;
|
|
18553
|
+
const reasoning = tokenCount(row.reasoning_tokens) ? row.reasoning_tokens : 0;
|
|
18554
|
+
if (apiCalls === 0 && input === 0 && output === 0 && cacheRead === 0 && cacheWrite === 0) {
|
|
18555
|
+
return null;
|
|
18556
|
+
}
|
|
18557
|
+
const id = typeof row.id === "string" && row.id.length > 0 ? row.id : null;
|
|
18558
|
+
const epochSeconds = (value) => {
|
|
18559
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
18560
|
+
return null;
|
|
18561
|
+
const ms = Math.floor(value * 1e3);
|
|
18562
|
+
return Number.isSafeInteger(ms) && !Number.isNaN(new Date(ms).getTime()) ? ms : null;
|
|
18563
|
+
};
|
|
18564
|
+
const at = epochSeconds(row.last_activity_at) ?? epochSeconds(row.started_at);
|
|
18565
|
+
if (id === null || at === null)
|
|
18566
|
+
return null;
|
|
18567
|
+
const request = {
|
|
18568
|
+
requestId: id,
|
|
18569
|
+
...typeof row.model === "string" && row.model.length > 0 ? { model: row.model } : {},
|
|
18570
|
+
inputTokens: input + cacheRead + cacheWrite,
|
|
18571
|
+
outputTokens: output,
|
|
18572
|
+
...reasoning > 0 ? { reasoningOutputTokens: reasoning } : {},
|
|
18573
|
+
// Both buckets exist whenever either does: the writer records them as a pair.
|
|
18574
|
+
...cacheRead > 0 || cacheWrite > 0 ? { cachedInputTokens: cacheRead, cacheWriteInputTokens: cacheWrite } : {}
|
|
18575
|
+
};
|
|
18576
|
+
const entry = usageEntryFromRequest(request, at);
|
|
18577
|
+
if (!entry)
|
|
18578
|
+
return null;
|
|
18579
|
+
return withUsageSession(entry, {
|
|
18580
|
+
sessionId: id,
|
|
18581
|
+
cwd: typeof row.cwd === "string" ? row.cwd : void 0,
|
|
18582
|
+
title: usageSessionTitle(row.title ?? row.display_name)
|
|
18583
|
+
});
|
|
18584
|
+
}
|
|
18585
|
+
var SESSIONS_QUERY = `
|
|
18586
|
+
SELECT id, model, cwd, title, display_name, started_at, last_activity_at,
|
|
18587
|
+
api_call_count, input_tokens, output_tokens, cache_read_tokens,
|
|
18588
|
+
cache_write_tokens, reasoning_tokens
|
|
18589
|
+
FROM sessions`;
|
|
18590
|
+
async function readHermesUsage(file2) {
|
|
18591
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
18592
|
+
const database = new DatabaseSync(file2, { readOnly: true });
|
|
18593
|
+
try {
|
|
18594
|
+
const entries = [];
|
|
18595
|
+
for (const row of database.prepare(SESSIONS_QUERY).iterate()) {
|
|
18596
|
+
const entry = hermesUsageEntry(row);
|
|
18597
|
+
if (entry)
|
|
18598
|
+
entries.push(entry);
|
|
18599
|
+
}
|
|
18600
|
+
return entries;
|
|
18601
|
+
} finally {
|
|
18602
|
+
database.close();
|
|
18603
|
+
}
|
|
18604
|
+
}
|
|
18605
|
+
function createHermesUsageStatistics(environment) {
|
|
18606
|
+
return Object.freeze({
|
|
18607
|
+
async listSources() {
|
|
18608
|
+
const file2 = hermesStateDatabasePath(environment);
|
|
18609
|
+
const stamp = await fingerprint(file2);
|
|
18610
|
+
return stamp ? [{ id: file2, fingerprint: stamp }] : [];
|
|
18611
|
+
},
|
|
18612
|
+
readSource: (id) => readHermesUsage(id)
|
|
18613
|
+
});
|
|
18614
|
+
}
|
|
18615
|
+
|
|
18616
|
+
// dist/gateway-open.js
|
|
18617
|
+
import path8 from "node:path";
|
|
18476
18618
|
import { realpath } from "node:fs/promises";
|
|
18477
18619
|
|
|
18478
18620
|
// dist/hermes-session.js
|
|
@@ -18682,16 +18824,16 @@ var Diff = class {
|
|
|
18682
18824
|
}
|
|
18683
18825
|
}
|
|
18684
18826
|
}
|
|
18685
|
-
addToPath(
|
|
18686
|
-
const last =
|
|
18827
|
+
addToPath(path9, added, removed, oldPosInc, options) {
|
|
18828
|
+
const last = path9.lastComponent;
|
|
18687
18829
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
18688
18830
|
return {
|
|
18689
|
-
oldPos:
|
|
18831
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
18690
18832
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
18691
18833
|
};
|
|
18692
18834
|
} else {
|
|
18693
18835
|
return {
|
|
18694
|
-
oldPos:
|
|
18836
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
18695
18837
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
18696
18838
|
};
|
|
18697
18839
|
}
|
|
@@ -19006,8 +19148,8 @@ function hermesFileChanges(update) {
|
|
|
19006
19148
|
for (const block of update.content ?? []) {
|
|
19007
19149
|
if (block.type !== "diff")
|
|
19008
19150
|
continue;
|
|
19009
|
-
const { path:
|
|
19010
|
-
if (!
|
|
19151
|
+
const { path: path9, oldText, newText } = block;
|
|
19152
|
+
if (!path9.trim() || /[\0\r\n]/u.test(path9) || typeof newText !== "string")
|
|
19011
19153
|
continue;
|
|
19012
19154
|
if (oldText === newText)
|
|
19013
19155
|
continue;
|
|
@@ -19015,10 +19157,10 @@ function hermesFileChanges(update) {
|
|
|
19015
19157
|
if (bytes > MAX_DIFF_BYTES || changes.length === MAX_DIFFS)
|
|
19016
19158
|
return [];
|
|
19017
19159
|
changes.push({
|
|
19018
|
-
path:
|
|
19160
|
+
path: path9,
|
|
19019
19161
|
kind: "update",
|
|
19020
19162
|
diffScope: "fragment",
|
|
19021
|
-
unifiedDiff: createTwoFilesPatch(
|
|
19163
|
+
unifiedDiff: createTwoFilesPatch(path9, path9, oldText ?? "", newText, "", "", {
|
|
19022
19164
|
context: 3
|
|
19023
19165
|
})
|
|
19024
19166
|
});
|
|
@@ -19821,7 +19963,7 @@ ${reason}` }
|
|
|
19821
19963
|
|
|
19822
19964
|
// dist/gateway-open.js
|
|
19823
19965
|
async function sameDirectory(left, right) {
|
|
19824
|
-
return await realpath(left).catch(() =>
|
|
19966
|
+
return await realpath(left).catch(() => path8.resolve(left)) === await realpath(right).catch(() => path8.resolve(right));
|
|
19825
19967
|
}
|
|
19826
19968
|
var gatewayCapabilities = {
|
|
19827
19969
|
configuration: {
|
|
@@ -19963,8 +20105,10 @@ var HermesAdapter = class {
|
|
|
19963
20105
|
#gatewayTransports = /* @__PURE__ */ new Set();
|
|
19964
20106
|
#gatewayProbes = /* @__PURE__ */ new Map();
|
|
19965
20107
|
#openingNativeIds = /* @__PURE__ */ new Set();
|
|
20108
|
+
usageStatistics;
|
|
19966
20109
|
constructor(options = {}) {
|
|
19967
20110
|
this.#options = options;
|
|
20111
|
+
this.usageStatistics = createHermesUsageStatistics(options.environment ?? process.env);
|
|
19968
20112
|
}
|
|
19969
20113
|
async inspect(input = {}) {
|
|
19970
20114
|
const cwd = input.cwd ?? process.cwd();
|