@botiverse/oar 0.0.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/LICENSE +202 -0
- package/README.md +13 -0
- package/dist/contracts/account-usage.d.ts +33 -0
- package/dist/contracts/account-usage.d.ts.map +1 -0
- package/dist/contracts/account-usage.js +2 -0
- package/dist/contracts/account-usage.js.map +1 -0
- package/dist/contracts/installation.d.ts +27 -0
- package/dist/contracts/installation.d.ts.map +1 -0
- package/dist/contracts/installation.js +2 -0
- package/dist/contracts/installation.js.map +1 -0
- package/dist/contracts/runtime.d.ts +12 -0
- package/dist/contracts/runtime.d.ts.map +1 -0
- package/dist/contracts/runtime.js +4 -0
- package/dist/contracts/runtime.js.map +1 -0
- package/dist/contracts/session.d.ts +188 -0
- package/dist/contracts/session.d.ts.map +1 -0
- package/dist/contracts/session.js +2 -0
- package/dist/contracts/session.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/installation.d.ts +15 -0
- package/dist/installation.d.ts.map +1 -0
- package/dist/installation.js +60 -0
- package/dist/installation.js.map +1 -0
- package/dist/observe/agent-status.d.ts +39 -0
- package/dist/observe/agent-status.d.ts.map +1 -0
- package/dist/observe/agent-status.js +31 -0
- package/dist/observe/agent-status.js.map +1 -0
- package/dist/observe/aggregate-events.d.ts +15 -0
- package/dist/observe/aggregate-events.d.ts.map +1 -0
- package/dist/observe/aggregate-events.js +70 -0
- package/dist/observe/aggregate-events.js.map +1 -0
- package/dist/observe/index.d.ts +17 -0
- package/dist/observe/index.d.ts.map +1 -0
- package/dist/observe/index.js +13 -0
- package/dist/observe/index.js.map +1 -0
- package/dist/observe/observe-agent.d.ts +38 -0
- package/dist/observe/observe-agent.d.ts.map +1 -0
- package/dist/observe/observe-agent.js +61 -0
- package/dist/observe/observe-agent.js.map +1 -0
- package/dist/observe/stall-observer.d.ts +19 -0
- package/dist/observe/stall-observer.d.ts.map +1 -0
- package/dist/observe/stall-observer.js +36 -0
- package/dist/observe/stall-observer.js.map +1 -0
- package/dist/observe/tool-activity.d.ts +21 -0
- package/dist/observe/tool-activity.d.ts.map +1 -0
- package/dist/observe/tool-activity.js +87 -0
- package/dist/observe/tool-activity.js.map +1 -0
- package/dist/registry.d.ts +10 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +30 -0
- package/dist/registry.js.map +1 -0
- package/dist/runtimes/claude/account-usage.d.ts +29 -0
- package/dist/runtimes/claude/account-usage.d.ts.map +1 -0
- package/dist/runtimes/claude/account-usage.js +179 -0
- package/dist/runtimes/claude/account-usage.js.map +1 -0
- package/dist/runtimes/claude/context-usage.d.ts +10 -0
- package/dist/runtimes/claude/context-usage.d.ts.map +1 -0
- package/dist/runtimes/claude/context-usage.js +23 -0
- package/dist/runtimes/claude/context-usage.js.map +1 -0
- package/dist/runtimes/claude/index.d.ts +9 -0
- package/dist/runtimes/claude/index.d.ts.map +1 -0
- package/dist/runtimes/claude/index.js +13 -0
- package/dist/runtimes/claude/index.js.map +1 -0
- package/dist/runtimes/claude/installation.d.ts +2 -0
- package/dist/runtimes/claude/installation.d.ts.map +1 -0
- package/dist/runtimes/claude/installation.js +3 -0
- package/dist/runtimes/claude/installation.js.map +1 -0
- package/dist/runtimes/claude/projection.d.ts +46 -0
- package/dist/runtimes/claude/projection.d.ts.map +1 -0
- package/dist/runtimes/claude/projection.js +110 -0
- package/dist/runtimes/claude/projection.js.map +1 -0
- package/dist/runtimes/claude/session.d.ts +3 -0
- package/dist/runtimes/claude/session.d.ts.map +1 -0
- package/dist/runtimes/claude/session.js +166 -0
- package/dist/runtimes/claude/session.js.map +1 -0
- package/dist/runtimes/codex/account-usage.d.ts +40 -0
- package/dist/runtimes/codex/account-usage.d.ts.map +1 -0
- package/dist/runtimes/codex/account-usage.js +185 -0
- package/dist/runtimes/codex/account-usage.js.map +1 -0
- package/dist/runtimes/codex/app-server-client.d.ts +17 -0
- package/dist/runtimes/codex/app-server-client.d.ts.map +1 -0
- package/dist/runtimes/codex/app-server-client.js +68 -0
- package/dist/runtimes/codex/app-server-client.js.map +1 -0
- package/dist/runtimes/codex/context-usage.d.ts +10 -0
- package/dist/runtimes/codex/context-usage.d.ts.map +1 -0
- package/dist/runtimes/codex/context-usage.js +16 -0
- package/dist/runtimes/codex/context-usage.js.map +1 -0
- package/dist/runtimes/codex/index.d.ts +9 -0
- package/dist/runtimes/codex/index.d.ts.map +1 -0
- package/dist/runtimes/codex/index.js +13 -0
- package/dist/runtimes/codex/index.js.map +1 -0
- package/dist/runtimes/codex/installation.d.ts +2 -0
- package/dist/runtimes/codex/installation.d.ts.map +1 -0
- package/dist/runtimes/codex/installation.js +17 -0
- package/dist/runtimes/codex/installation.js.map +1 -0
- package/dist/runtimes/codex/item-detail.d.ts +4 -0
- package/dist/runtimes/codex/item-detail.d.ts.map +1 -0
- package/dist/runtimes/codex/item-detail.js +47 -0
- package/dist/runtimes/codex/item-detail.js.map +1 -0
- package/dist/runtimes/codex/projection.d.ts +28 -0
- package/dist/runtimes/codex/projection.d.ts.map +1 -0
- package/dist/runtimes/codex/projection.js +98 -0
- package/dist/runtimes/codex/projection.js.map +1 -0
- package/dist/runtimes/codex/reasoning.d.ts +4 -0
- package/dist/runtimes/codex/reasoning.d.ts.map +1 -0
- package/dist/runtimes/codex/reasoning.js +23 -0
- package/dist/runtimes/codex/reasoning.js.map +1 -0
- package/dist/runtimes/codex/session.d.ts +3 -0
- package/dist/runtimes/codex/session.d.ts.map +1 -0
- package/dist/runtimes/codex/session.js +199 -0
- package/dist/runtimes/codex/session.js.map +1 -0
- package/dist/runtimes/pi/index.d.ts +12 -0
- package/dist/runtimes/pi/index.d.ts.map +1 -0
- package/dist/runtimes/pi/index.js +15 -0
- package/dist/runtimes/pi/index.js.map +1 -0
- package/dist/runtimes/pi/installation.d.ts +10 -0
- package/dist/runtimes/pi/installation.d.ts.map +1 -0
- package/dist/runtimes/pi/installation.js +33 -0
- package/dist/runtimes/pi/installation.js.map +1 -0
- package/dist/runtimes/pi/projection.d.ts +39 -0
- package/dist/runtimes/pi/projection.d.ts.map +1 -0
- package/dist/runtimes/pi/projection.js +112 -0
- package/dist/runtimes/pi/projection.js.map +1 -0
- package/dist/runtimes/pi/session.d.ts +11 -0
- package/dist/runtimes/pi/session.d.ts.map +1 -0
- package/dist/runtimes/pi/session.js +201 -0
- package/dist/runtimes/pi/session.js.map +1 -0
- package/dist/runtimes/pi/tool-detail.d.ts +4 -0
- package/dist/runtimes/pi/tool-detail.d.ts.map +1 -0
- package/dist/runtimes/pi/tool-detail.js +14 -0
- package/dist/runtimes/pi/tool-detail.js.map +1 -0
- package/dist/shared/diagnostic-text.d.ts +2 -0
- package/dist/shared/diagnostic-text.d.ts.map +1 -0
- package/dist/shared/diagnostic-text.js +15 -0
- package/dist/shared/diagnostic-text.js.map +1 -0
- package/dist/shared/executable/index.d.ts +8 -0
- package/dist/shared/executable/index.d.ts.map +1 -0
- package/dist/shared/executable/index.js +5 -0
- package/dist/shared/executable/index.js.map +1 -0
- package/dist/shared/executable/process.d.ts +27 -0
- package/dist/shared/executable/process.d.ts.map +1 -0
- package/dist/shared/executable/process.js +77 -0
- package/dist/shared/executable/process.js.map +1 -0
- package/dist/shared/executable/resolve.d.ts +16 -0
- package/dist/shared/executable/resolve.d.ts.map +1 -0
- package/dist/shared/executable/resolve.js +63 -0
- package/dist/shared/executable/resolve.js.map +1 -0
- package/dist/shared/executable/run.d.ts +13 -0
- package/dist/shared/executable/run.d.ts.map +1 -0
- package/dist/shared/executable/run.js +26 -0
- package/dist/shared/executable/run.js.map +1 -0
- package/dist/shared/executable/version.d.ts +6 -0
- package/dist/shared/executable/version.d.ts.map +1 -0
- package/dist/shared/executable/version.js +17 -0
- package/dist/shared/executable/version.js.map +1 -0
- package/dist/shared/failure-class.d.ts +8 -0
- package/dist/shared/failure-class.d.ts.map +1 -0
- package/dist/shared/failure-class.js +24 -0
- package/dist/shared/failure-class.js.map +1 -0
- package/dist/shared/installation.d.ts +9 -0
- package/dist/shared/installation.d.ts.map +1 -0
- package/dist/shared/installation.js +53 -0
- package/dist/shared/installation.js.map +1 -0
- package/dist/shared/instant.d.ts +4 -0
- package/dist/shared/instant.d.ts.map +1 -0
- package/dist/shared/instant.js +4 -0
- package/dist/shared/instant.js.map +1 -0
- package/dist/shared/json.d.ts +10 -0
- package/dist/shared/json.d.ts.map +1 -0
- package/dist/shared/json.js +29 -0
- package/dist/shared/json.js.map +1 -0
- package/dist/shared/seal-session.d.ts +8 -0
- package/dist/shared/seal-session.d.ts.map +1 -0
- package/dist/shared/seal-session.js +24 -0
- package/dist/shared/seal-session.js.map +1 -0
- package/dist/shared/session-kernel.d.ts +25 -0
- package/dist/shared/session-kernel.d.ts.map +1 -0
- package/dist/shared/session-kernel.js +64 -0
- package/dist/shared/session-kernel.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AccountUsageReader, AccountUsageSnapshot } from "../../contracts/account-usage.js";
|
|
2
|
+
export declare function projectClaudeUsage(content: string, referenceInstant?: Date): AccountUsageSnapshot;
|
|
3
|
+
/**
|
|
4
|
+
* `claude -p /usage --output-format json` has two observed shapes.
|
|
5
|
+
* Without login, `result` is only an invocation summary:
|
|
6
|
+
*
|
|
7
|
+
* ```json
|
|
8
|
+
* {
|
|
9
|
+
* "type": "result",
|
|
10
|
+
* "total_cost_usd": 0,
|
|
11
|
+
* "usage": { "input_tokens": 0, "output_tokens": 0 },
|
|
12
|
+
* "result": "Total cost: $0.0000\nUsage: 0 input, 0 output, 0 cache read, 0 cache write"
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* With a subscription login, `result` contains account usage windows:
|
|
17
|
+
*
|
|
18
|
+
* ```json
|
|
19
|
+
* {
|
|
20
|
+
* "type": "result",
|
|
21
|
+
* "result": "You are currently using your subscription to power your Claude Code usage\n\nCurrent session: 7% used · resets Aug 21 at 7:39pm (Asia/Shanghai)\nCurrent week (all models): 0% used · resets Aug 28 at 2:59pm (Asia/Shanghai)\nCurrent week (Fable): 0% used"
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Reset text has no year, so it is interpreted as the next occurrence in its
|
|
26
|
+
* named IANA time zone relative to when the command result is projected.
|
|
27
|
+
*/
|
|
28
|
+
export declare const claudeAccountUsage: AccountUsageReader;
|
|
29
|
+
//# sourceMappingURL=account-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-usage.d.ts","sourceRoot":"","sources":["../../../src/runtimes/claude/account-usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EAGrB,MAAM,kCAAkC,CAAC;AAgG1C,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,gBAAgB,GAAE,IAAiB,GAClC,oBAAoB,CA6BtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAyChC,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { runExecutable } from "../../shared/executable/index.js";
|
|
2
|
+
import { utcInstantFromDate } from "../../shared/instant.js";
|
|
3
|
+
import { asRecord, parseJson } from "../../shared/json.js";
|
|
4
|
+
const MONTHS = new Map([
|
|
5
|
+
["Jan", 0], ["Feb", 1], ["Mar", 2], ["Apr", 3], ["May", 4], ["Jun", 5],
|
|
6
|
+
["Jul", 6], ["Aug", 7], ["Sep", 8], ["Oct", 9], ["Nov", 10], ["Dec", 11],
|
|
7
|
+
]);
|
|
8
|
+
function zonedParts(instant, timeZone) {
|
|
9
|
+
try {
|
|
10
|
+
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
11
|
+
timeZone,
|
|
12
|
+
calendar: "gregory",
|
|
13
|
+
numberingSystem: "latn",
|
|
14
|
+
year: "numeric",
|
|
15
|
+
month: "2-digit",
|
|
16
|
+
day: "2-digit",
|
|
17
|
+
hour: "2-digit",
|
|
18
|
+
minute: "2-digit",
|
|
19
|
+
hourCycle: "h23",
|
|
20
|
+
}).formatToParts(instant);
|
|
21
|
+
const values = Object.fromEntries(parts.map((part) => [part.type, part.value]));
|
|
22
|
+
const result = {
|
|
23
|
+
year: Number(values.year),
|
|
24
|
+
month: Number(values.month) - 1,
|
|
25
|
+
day: Number(values.day),
|
|
26
|
+
hour: Number(values.hour),
|
|
27
|
+
minute: Number(values.minute),
|
|
28
|
+
};
|
|
29
|
+
return Object.values(result).every((value) => Number.isFinite(value)) ? result : null;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function localInstant(value, timeZone) {
|
|
36
|
+
const target = Date.UTC(value.year, value.month, value.day, value.hour, value.minute);
|
|
37
|
+
let instant = target;
|
|
38
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
39
|
+
const observed = zonedParts(instant, timeZone);
|
|
40
|
+
if (observed === null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const correction = target
|
|
44
|
+
- Date.UTC(observed.year, observed.month, observed.day, observed.hour, observed.minute);
|
|
45
|
+
if (correction === 0) {
|
|
46
|
+
return instant;
|
|
47
|
+
}
|
|
48
|
+
instant += correction;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
function resetInstant(resetText, referenceInstant) {
|
|
53
|
+
const match = /^(\w{3}) (\d{1,2}) at (\d{1,2}):(\d{2})(am|pm) \(([^)]+)\)$/u.exec(resetText);
|
|
54
|
+
const month = MONTHS.get(match?.[1] ?? "");
|
|
55
|
+
const day = Number(match?.[2]);
|
|
56
|
+
const twelveHour = Number(match?.[3]);
|
|
57
|
+
const minute = Number(match?.[4]);
|
|
58
|
+
const meridiem = match?.[5];
|
|
59
|
+
const timeZone = match?.[6];
|
|
60
|
+
if (month === undefined || timeZone === undefined || day < 1 || day > 31
|
|
61
|
+
|| twelveHour < 1 || twelveHour > 12 || minute < 0 || minute > 59
|
|
62
|
+
|| (meridiem !== "am" && meridiem !== "pm")) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const reference = zonedParts(referenceInstant.getTime(), timeZone);
|
|
66
|
+
if (reference === null) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const hour = twelveHour % 12 + (meridiem === "pm" ? 12 : 0);
|
|
70
|
+
const cutoff = referenceInstant.getTime() - 60_000;
|
|
71
|
+
for (const year of [reference.year, reference.year + 1]) {
|
|
72
|
+
const instant = localInstant({ year, month, day, hour, minute }, timeZone);
|
|
73
|
+
if (instant !== null && instant >= cutoff) {
|
|
74
|
+
return utcInstantFromDate(new Date(instant));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
function resultText(stdout) {
|
|
80
|
+
const result = asRecord(parseJson(stdout))?.result;
|
|
81
|
+
return typeof result === "string" && result.trim().length > 0 ? result : null;
|
|
82
|
+
}
|
|
83
|
+
export function projectClaudeUsage(content, referenceInstant = new Date()) {
|
|
84
|
+
const windows = [];
|
|
85
|
+
for (const line of content.split(/\r?\n/u)) {
|
|
86
|
+
const match = /^(.+?): (\d+(?:\.\d+)?)% used(?: · resets (.+))?$/u.exec(line.trim());
|
|
87
|
+
const label = match?.[1];
|
|
88
|
+
const percentage = match?.[2];
|
|
89
|
+
if (label === undefined || percentage === undefined) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const usedPercent = Number(percentage);
|
|
93
|
+
if (!Number.isFinite(usedPercent) || usedPercent < 0 || usedPercent > 100) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const resetText = match?.[3];
|
|
97
|
+
const resetsAt = resetText === undefined ? null : resetInstant(resetText, referenceInstant);
|
|
98
|
+
windows.push({
|
|
99
|
+
label,
|
|
100
|
+
usedRatio: Number((usedPercent / 100).toFixed(6)),
|
|
101
|
+
...(resetsAt === null ? {} : { resetsAt }),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (windows.length === 0) {
|
|
105
|
+
throw new Error("Claude returned no usable account usage windows");
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
kind: "available",
|
|
109
|
+
rateLimited: windows.some((window) => window.usedRatio >= 1),
|
|
110
|
+
windows,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* `claude -p /usage --output-format json` has two observed shapes.
|
|
115
|
+
* Without login, `result` is only an invocation summary:
|
|
116
|
+
*
|
|
117
|
+
* ```json
|
|
118
|
+
* {
|
|
119
|
+
* "type": "result",
|
|
120
|
+
* "total_cost_usd": 0,
|
|
121
|
+
* "usage": { "input_tokens": 0, "output_tokens": 0 },
|
|
122
|
+
* "result": "Total cost: $0.0000\nUsage: 0 input, 0 output, 0 cache read, 0 cache write"
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* With a subscription login, `result` contains account usage windows:
|
|
127
|
+
*
|
|
128
|
+
* ```json
|
|
129
|
+
* {
|
|
130
|
+
* "type": "result",
|
|
131
|
+
* "result": "You are currently using your subscription to power your Claude Code usage\n\nCurrent session: 7% used · resets Aug 21 at 7:39pm (Asia/Shanghai)\nCurrent week (all models): 0% used · resets Aug 28 at 2:59pm (Asia/Shanghai)\nCurrent week (Fable): 0% used"
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* Reset text has no year, so it is interpreted as the next occurrence in its
|
|
136
|
+
* named IANA time zone relative to when the command result is projected.
|
|
137
|
+
*/
|
|
138
|
+
export const claudeAccountUsage = async (installation, options = {}) => {
|
|
139
|
+
if (installation.via !== "executable") {
|
|
140
|
+
return { kind: "unsupported" };
|
|
141
|
+
}
|
|
142
|
+
const command = installation.command;
|
|
143
|
+
const timeoutMs = options.timeoutMs ?? 15_000;
|
|
144
|
+
const env = { ...process.env, CLAUDECODE: undefined };
|
|
145
|
+
const auth = await runExecutable(command, ["auth", "status", "--json"], { env, timeoutMs });
|
|
146
|
+
if (!auth.ok && auth.exitCode === null) {
|
|
147
|
+
throw new Error("Failed to read Claude authentication status");
|
|
148
|
+
}
|
|
149
|
+
const authStatus = asRecord(parseJson(auth.stdout));
|
|
150
|
+
if (!auth.ok || authStatus?.loggedIn === false) {
|
|
151
|
+
return { kind: "reauth_required" };
|
|
152
|
+
}
|
|
153
|
+
if (typeof authStatus?.apiKeySource === "string") {
|
|
154
|
+
// An API key takes precedence over any claude.ai login, and API-key
|
|
155
|
+
// billing has no subscription usage windows — /usage would return only a
|
|
156
|
+
// cost report (pinned by the claude vendor usage test).
|
|
157
|
+
return { kind: "unsupported" };
|
|
158
|
+
}
|
|
159
|
+
const usage = await runExecutable(command, ["-p", "/usage", "--output-format", "json"], {
|
|
160
|
+
env,
|
|
161
|
+
timeoutMs,
|
|
162
|
+
});
|
|
163
|
+
if (!usage.ok && usage.exitCode === null) {
|
|
164
|
+
throw new Error("Failed to execute Claude account usage");
|
|
165
|
+
}
|
|
166
|
+
if (!usage.ok) {
|
|
167
|
+
const output = `${usage.stdout}\n${usage.stderr}`;
|
|
168
|
+
if (/auth(?:entication)?\s*(?:missing|required)|log(?:ged)?\s*in/iu.test(output)) {
|
|
169
|
+
return { kind: "reauth_required" };
|
|
170
|
+
}
|
|
171
|
+
throw new Error("Claude account usage command failed");
|
|
172
|
+
}
|
|
173
|
+
const content = resultText(usage.stdout);
|
|
174
|
+
if (content === null) {
|
|
175
|
+
throw new Error("Claude returned no account usage result");
|
|
176
|
+
}
|
|
177
|
+
return projectClaudeUsage(content);
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=account-usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-usage.js","sourceRoot":"","sources":["../../../src/runtimes/claude/account-usage.ts"],"names":[],"m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,QAAQ,KAAK,IAAI,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QAClD,IAAI,+DAA+D,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACjF,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;QACrC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContextUsage } from "../../contracts/session.js";
|
|
2
|
+
import { type JsonRecord } from "../../shared/json.js";
|
|
3
|
+
/**
|
|
4
|
+
* Claude reports context usage in the result frame (structured — no need for
|
|
5
|
+
* the human-facing /context command): usage.{input,cache_read,cache_creation}
|
|
6
|
+
* tokens are the context sent, and modelUsage[model].contextWindow is the
|
|
7
|
+
* window. We cache the latest as the current snapshot (last-write-wins).
|
|
8
|
+
*/
|
|
9
|
+
export declare function claudeContextUsageFromResult(message: JsonRecord): ContextUsage | null;
|
|
10
|
+
//# sourceMappingURL=context-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-usage.d.ts","sourceRoot":"","sources":["../../../src/runtimes/claude/context-usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE3E;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,UAAU,GAAG,YAAY,GAAG,IAAI,CAcrF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { asNumber, asRecord } from "../../shared/json.js";
|
|
2
|
+
/**
|
|
3
|
+
* Claude reports context usage in the result frame (structured — no need for
|
|
4
|
+
* the human-facing /context command): usage.{input,cache_read,cache_creation}
|
|
5
|
+
* tokens are the context sent, and modelUsage[model].contextWindow is the
|
|
6
|
+
* window. We cache the latest as the current snapshot (last-write-wins).
|
|
7
|
+
*/
|
|
8
|
+
export function claudeContextUsageFromResult(message) {
|
|
9
|
+
const usage = asRecord(message.usage);
|
|
10
|
+
if (usage === null) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const input = asNumber(usage.input_tokens) ?? 0;
|
|
14
|
+
const cacheRead = asNumber(usage.cache_read_input_tokens) ?? 0;
|
|
15
|
+
const cacheCreate = asNumber(usage.cache_creation_input_tokens) ?? 0;
|
|
16
|
+
const tokens = input + cacheRead + cacheCreate;
|
|
17
|
+
const modelUsage = asRecord(message.modelUsage);
|
|
18
|
+
const firstModel = modelUsage === null ? null : asRecord(Object.values(modelUsage)[0]);
|
|
19
|
+
const contextWindow = firstModel === null ? null : asNumber(firstModel.contextWindow) ?? null;
|
|
20
|
+
const percent = contextWindow === null || contextWindow === 0 ? null : Math.round((tokens / contextWindow) * 100);
|
|
21
|
+
return { tokens, contextWindow, percent };
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=context-usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-usage.js","sourceRoot":"","sources":["../../../src/runtimes/claude/context-usage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,UAAU,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|
+
readonly accountUsage: import("../../index.js").AccountUsageReader;
|
|
5
|
+
readonly session: import("../../index.js").StartSession;
|
|
6
|
+
};
|
|
7
|
+
export { claudeAccountUsage } from "./account-usage.js";
|
|
8
|
+
export { claudeSession } from "./session.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtimes/claude/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa;;;;;CAKxB,CAAC;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineRuntime } from "../../contracts/runtime.js";
|
|
2
|
+
import { claudeAccountUsage } from "./account-usage.js";
|
|
3
|
+
import { claudeInstallation } from "./installation.js";
|
|
4
|
+
import { claudeSession } from "./session.js";
|
|
5
|
+
export const claudeRuntime = defineRuntime({
|
|
6
|
+
id: "claude",
|
|
7
|
+
installation: claudeInstallation,
|
|
8
|
+
accountUsage: claudeAccountUsage,
|
|
9
|
+
session: claudeSession,
|
|
10
|
+
});
|
|
11
|
+
export { claudeAccountUsage } from "./account-usage.js";
|
|
12
|
+
export { claudeSession } from "./session.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtimes/claude/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;IACzC,EAAE,EAAE,QAAQ;IACZ,YAAY,EAAE,kBAAkB;IAChC,YAAY,EAAE,kBAAkB;IAChC,OAAO,EAAE,aAAa;CACvB,CAAC,CAAC;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installation.d.ts","sourceRoot":"","sources":["../../../src/runtimes/claude/installation.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,4CAAqD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installation.js","sourceRoot":"","sources":["../../../src/runtimes/claude/installation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SessionEventBody, TurnOutcome } from "../../contracts/session.js";
|
|
2
|
+
import { type JsonRecord } from "../../shared/json.js";
|
|
3
|
+
/**
|
|
4
|
+
* The claude stdout → SessionEvent projection as a PURE FOLD. It is the same
|
|
5
|
+
* family as observe/reduceStatus, one layer earlier: a reducer over the raw
|
|
6
|
+
* provider stream that emits kernel COMMANDS (begin a turn, emit an event,
|
|
7
|
+
* settle an outcome) instead of touching the kernel itself. The live adapter
|
|
8
|
+
* applies the commands to a real kernel; tests apply them to nothing and
|
|
9
|
+
* snapshot the list. No transport, no side effects — so it is trivially
|
|
10
|
+
* unit-testable and shared verbatim between live and replay.
|
|
11
|
+
*
|
|
12
|
+
* Not generic: each runtime speaks a different wire vocabulary, so each has
|
|
13
|
+
* its own fold. What IS shared is the OUTPUT — SessionEventBody and this
|
|
14
|
+
* command algebra.
|
|
15
|
+
*/
|
|
16
|
+
export type ProjectionCommand = {
|
|
17
|
+
readonly kind: "begin";
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "emit";
|
|
20
|
+
readonly body: SessionEventBody;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "settle";
|
|
23
|
+
readonly outcome: TurnOutcome;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Fold state. `inTurn` is the projection's own view of turn framing (set true
|
|
27
|
+
* by the control plane on prompt, by the fold on a spontaneous init).
|
|
28
|
+
* `abortRequested` is the one input that is NOT in the provider stream — abort
|
|
29
|
+
* is a control-plane intent, and claude reports its result as an ordinary
|
|
30
|
+
* result frame, so the flag is how the fold tells aborted from completed. It
|
|
31
|
+
* makes explicit that projection folds over provider events ⊎ control intent.
|
|
32
|
+
*/
|
|
33
|
+
export interface ClaudeProjectionState {
|
|
34
|
+
readonly inTurn: boolean;
|
|
35
|
+
readonly abortRequested: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const initialClaudeProjection: ClaudeProjectionState;
|
|
38
|
+
/** Control plane → state: a prompt opens a turn; an abort arms the flag. */
|
|
39
|
+
export declare function claudePrompted(): ClaudeProjectionState;
|
|
40
|
+
export declare function claudeAbortRequested(state: ClaudeProjectionState): ClaudeProjectionState;
|
|
41
|
+
/** Fold one parsed claude stdout frame into the next state plus commands. */
|
|
42
|
+
export declare function foldClaudeStdout(state: ClaudeProjectionState, message: JsonRecord): {
|
|
43
|
+
readonly state: ClaudeProjectionState;
|
|
44
|
+
readonly commands: readonly ProjectionCommand[];
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/runtimes/claude/projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEhF,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;CAClC;AAED,eAAO,MAAM,uBAAuB,EAAE,qBAAgE,CAAC;AAEvG,4EAA4E;AAC5E,wBAAgB,cAAc,IAAI,qBAAqB,CAEtD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,qBAAqB,GAAG,qBAAqB,CAExF;AAiFD,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,qBAAqB,EAC5B,OAAO,EAAE,UAAU,GAClB;IAAE,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAAE,CAsB5F"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { classifyFailure } from "../../shared/failure-class.js";
|
|
2
|
+
import { asRecord } from "../../shared/json.js";
|
|
3
|
+
export const initialClaudeProjection = { inTurn: false, abortRequested: false };
|
|
4
|
+
/** Control plane → state: a prompt opens a turn; an abort arms the flag. */
|
|
5
|
+
export function claudePrompted() {
|
|
6
|
+
return { inTurn: true, abortRequested: false };
|
|
7
|
+
}
|
|
8
|
+
export function claudeAbortRequested(state) {
|
|
9
|
+
return { ...state, abortRequested: true };
|
|
10
|
+
}
|
|
11
|
+
function contentBlocks(message) {
|
|
12
|
+
const inner = asRecord(message.message);
|
|
13
|
+
const content = inner?.content;
|
|
14
|
+
if (!Array.isArray(content)) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return content.map((block) => asRecord(block)).filter((block) => block !== null);
|
|
18
|
+
}
|
|
19
|
+
function assistantEvents(message) {
|
|
20
|
+
const out = [];
|
|
21
|
+
for (const block of contentBlocks(message)) {
|
|
22
|
+
switch (String(block.type)) {
|
|
23
|
+
case "text": {
|
|
24
|
+
if (typeof block.text === "string") {
|
|
25
|
+
out.push({ kind: "text_delta", text: block.text });
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "thinking": {
|
|
30
|
+
const content = typeof block.thinking === "string" && block.thinking.length > 0
|
|
31
|
+
? { kind: "text", text: block.thinking }
|
|
32
|
+
: { kind: "empty" };
|
|
33
|
+
out.push({ kind: "reasoning", content });
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case "redacted_thinking": {
|
|
37
|
+
out.push({ kind: "reasoning", content: { kind: "redacted" } });
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case "tool_use": {
|
|
41
|
+
const started = {
|
|
42
|
+
kind: "tool_call_started",
|
|
43
|
+
callId: typeof block.id === "string" ? block.id : "unknown",
|
|
44
|
+
tool: typeof block.name === "string" ? block.name : "unknown",
|
|
45
|
+
};
|
|
46
|
+
const input = block.input === undefined ? undefined : JSON.stringify(block.input);
|
|
47
|
+
out.push(input === undefined ? started : { ...started, input });
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
function toolResultEvents(message) {
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const block of contentBlocks(message)) {
|
|
59
|
+
if (block.type === "tool_result" && typeof block.tool_use_id === "string") {
|
|
60
|
+
const output = block.content === undefined ? undefined : JSON.stringify(block.content);
|
|
61
|
+
out.push(output === undefined
|
|
62
|
+
? { kind: "tool_call_ended", callId: block.tool_use_id }
|
|
63
|
+
: { kind: "tool_call_ended", callId: block.tool_use_id, output });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function resultOutcome(state, message) {
|
|
69
|
+
if (state.abortRequested) {
|
|
70
|
+
return { kind: "aborted" };
|
|
71
|
+
}
|
|
72
|
+
if (message.is_error === true) {
|
|
73
|
+
// Vendor quirk (pinned 2026-08-22): claude can report is_error=true with
|
|
74
|
+
// subtype "success" and put the actual error text in result.
|
|
75
|
+
const text = typeof message.result === "string" && message.result.length > 0
|
|
76
|
+
? message.result
|
|
77
|
+
: undefined;
|
|
78
|
+
const subtype = typeof message.subtype === "string" && message.subtype !== "success"
|
|
79
|
+
? message.subtype
|
|
80
|
+
: undefined;
|
|
81
|
+
const reason = text ?? subtype ?? "error";
|
|
82
|
+
return { kind: "failed", reason, failure: classifyFailure(reason) };
|
|
83
|
+
}
|
|
84
|
+
return { kind: "completed" };
|
|
85
|
+
}
|
|
86
|
+
/** Fold one parsed claude stdout frame into the next state plus commands. */
|
|
87
|
+
export function foldClaudeStdout(state, message) {
|
|
88
|
+
// A system/init with no active turn is claude starting a run on its own (a
|
|
89
|
+
// steer that landed past the turn's end) — a spontaneous turn.
|
|
90
|
+
if (message.type === "system" && message.subtype === "init" && !state.inTurn) {
|
|
91
|
+
return { state: { ...state, inTurn: true }, commands: [{ kind: "begin" }] };
|
|
92
|
+
}
|
|
93
|
+
if (!state.inTurn) {
|
|
94
|
+
return { state, commands: [] };
|
|
95
|
+
}
|
|
96
|
+
switch (String(message.type)) {
|
|
97
|
+
case "assistant":
|
|
98
|
+
return { state, commands: assistantEvents(message).map((body) => ({ kind: "emit", body })) };
|
|
99
|
+
case "user":
|
|
100
|
+
return { state, commands: toolResultEvents(message).map((body) => ({ kind: "emit", body })) };
|
|
101
|
+
case "result":
|
|
102
|
+
return {
|
|
103
|
+
state: { inTurn: false, abortRequested: false },
|
|
104
|
+
commands: [{ kind: "settle", outcome: resultOutcome(state, message) }],
|
|
105
|
+
};
|
|
106
|
+
default:
|
|
107
|
+
return { state, commands: [] };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/runtimes/claude/projection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAkCjE,MAAM,CAAC,MAAM,uBAAuB,GAA0B,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AAEvG,4EAA4E;AAC5E,MAAM,UAAU,cAAc;IAC5B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAA4B;IAC/D,OAAO,EAAE,GAAG,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC;AAC5C,CAAC;AAED,SAAS,aAAa,CAAC,OAAmB;IACxC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,KAAK,EAAE,OAAO,CAAC;IAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,eAAe,CAAC,OAAmB;IAC1C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