@botiverse/oar 0.3.0 → 0.4.0

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.
Files changed (59) hide show
  1. package/README.md +31 -2
  2. package/dist/contracts/inventory.d.ts +65 -0
  3. package/dist/contracts/inventory.d.ts.map +1 -0
  4. package/dist/contracts/inventory.js +2 -0
  5. package/dist/contracts/inventory.js.map +1 -0
  6. package/dist/contracts/runtime.d.ts +3 -2
  7. package/dist/contracts/runtime.d.ts.map +1 -1
  8. package/dist/contracts/runtime.js +9 -1
  9. package/dist/contracts/runtime.js.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/runtimes/claude/account-usage.d.ts +5 -26
  14. package/dist/runtimes/claude/account-usage.d.ts.map +1 -1
  15. package/dist/runtimes/claude/account-usage.js +122 -178
  16. package/dist/runtimes/claude/account-usage.js.map +1 -1
  17. package/dist/runtimes/claude/index.d.ts +4 -1
  18. package/dist/runtimes/claude/index.d.ts.map +1 -1
  19. package/dist/runtimes/claude/index.js +4 -0
  20. package/dist/runtimes/claude/index.js.map +1 -1
  21. package/dist/runtimes/claude/inventory.d.ts +9 -0
  22. package/dist/runtimes/claude/inventory.d.ts.map +1 -0
  23. package/dist/runtimes/claude/inventory.js +120 -0
  24. package/dist/runtimes/claude/inventory.js.map +1 -0
  25. package/dist/runtimes/codex/app-server-client.d.ts +1 -1
  26. package/dist/runtimes/codex/app-server-client.d.ts.map +1 -1
  27. package/dist/runtimes/codex/app-server-client.js +2 -2
  28. package/dist/runtimes/codex/app-server-client.js.map +1 -1
  29. package/dist/runtimes/codex/index.d.ts +4 -1
  30. package/dist/runtimes/codex/index.d.ts.map +1 -1
  31. package/dist/runtimes/codex/index.js +4 -0
  32. package/dist/runtimes/codex/index.js.map +1 -1
  33. package/dist/runtimes/codex/inventory.d.ts +11 -0
  34. package/dist/runtimes/codex/inventory.d.ts.map +1 -0
  35. package/dist/runtimes/codex/inventory.js +88 -0
  36. package/dist/runtimes/codex/inventory.js.map +1 -0
  37. package/dist/runtimes/grok/index.d.ts +3 -1
  38. package/dist/runtimes/grok/index.d.ts.map +1 -1
  39. package/dist/runtimes/grok/index.js +3 -0
  40. package/dist/runtimes/grok/index.js.map +1 -1
  41. package/dist/runtimes/grok/inventory.d.ts +7 -0
  42. package/dist/runtimes/grok/inventory.d.ts.map +1 -0
  43. package/dist/runtimes/grok/inventory.js +47 -0
  44. package/dist/runtimes/grok/inventory.js.map +1 -0
  45. package/dist/runtimes/kimi/index.d.ts +1 -1
  46. package/dist/runtimes/kimi/index.d.ts.map +1 -1
  47. package/dist/runtimes/pi/index.d.ts +3 -1
  48. package/dist/runtimes/pi/index.d.ts.map +1 -1
  49. package/dist/runtimes/pi/index.js +3 -0
  50. package/dist/runtimes/pi/index.js.map +1 -1
  51. package/dist/runtimes/pi/inventory.d.ts +4 -0
  52. package/dist/runtimes/pi/inventory.d.ts.map +1 -0
  53. package/dist/runtimes/pi/inventory.js +51 -0
  54. package/dist/runtimes/pi/inventory.js.map +1 -0
  55. package/dist/shared/inventory.d.ts +22 -0
  56. package/dist/shared/inventory.d.ts.map +1 -0
  57. package/dist/shared/inventory.js +59 -0
  58. package/dist/shared/inventory.js.map +1 -0
  59. package/package.json +1 -1
package/README.md CHANGED
@@ -72,5 +72,34 @@ reasons must be presented as unknown rather than guessed.
72
72
 
73
73
  Operational failures (network errors, timeouts, malformed responses) still reject
74
74
  the promise. Reasons do not include tokens, credential values, or raw provider
75
- responses. This change does not alter authentication precedence, refresh tokens,
76
- or probe endpoints that were previously skipped.
75
+ responses.
76
+
77
+ Claude account usage delegates to its native stream-json `get_usage` request
78
+ (with `skip_behaviors: true`). OAR does not read Claude credentials or call its
79
+ HTTP quota endpoint. A native `rate_limits_available: false` becomes
80
+ `quota_unavailable`; it does not prove invalid credentials. Older CLIs that
81
+ reject the control request return `endpoint_unavailable`. Query-process session
82
+ totals are not returned as account usage.
83
+
84
+ ## Native inventories
85
+
86
+ Every runtime exposes `skills(installation, options?)`,
87
+ `mcpServers(installation, options?)`, and `tools(installation, options?)`.
88
+ Options are `{ cwd?: string, timeoutMs?: number }`; cwd defaults to
89
+ `process.cwd()`. Queries independently discover native information and do not
90
+ inspect an existing Session or submit a model prompt.
91
+
92
+ Results distinguish `ok`, `unsupported`, and `unavailable`. Successful results
93
+ contain `items`, `scope.cwd`, `observedAt`, `view`, and `partial`. A
94
+ `mcp-only` view excludes built-in tools. Unknown schema or state fields stay
95
+ absent, and an unsupported query never pretends to be an empty catalog.
96
+
97
+ Codex and Claude expose skills and MCP discovery (tools are MCP-only); Grok
98
+ exposes independent skills/MCP configuration discovery; Pi exposes skills and
99
+ registered tools with active membership. Kimi inventory is unsupported on the
100
+ selected transport. Native startup can load extensions and connect configured
101
+ MCP servers.
102
+
103
+ Custom runtimes should use `defineRuntime`, which fills unavailable inventory
104
+ methods with explicit unsupported results. A manually constructed `Runtime`
105
+ must implement the three methods.
@@ -0,0 +1,65 @@
1
+ import type { AvailableInstallation } from "./installation.js";
2
+ /** Independent native discovery in a working directory. */
3
+ export interface InventoryScope {
4
+ readonly kind: "workspace";
5
+ readonly cwd: string;
6
+ }
7
+ export interface InventoryOptions {
8
+ /** Defaults to process.cwd(); hosts should pass their project directory explicitly. */
9
+ readonly cwd?: string;
10
+ readonly timeoutMs?: number;
11
+ }
12
+ export interface SkillEntry {
13
+ readonly name: string;
14
+ readonly description?: string;
15
+ readonly path?: string;
16
+ readonly source?: string;
17
+ readonly enabled?: boolean;
18
+ readonly disableModelInvocation?: boolean;
19
+ }
20
+ export interface McpServerEntry {
21
+ readonly id: string;
22
+ readonly name: string;
23
+ /** Native state, not normalized into a guessed connected boolean. */
24
+ readonly status?: string;
25
+ readonly authStatus?: string;
26
+ readonly enabled?: boolean;
27
+ readonly source?: string;
28
+ readonly toolCount?: number;
29
+ readonly error?: string;
30
+ }
31
+ export interface ToolEntry {
32
+ readonly name: string;
33
+ readonly description?: string;
34
+ readonly mcpServerId?: string;
35
+ readonly source?: string;
36
+ readonly enabled?: boolean;
37
+ readonly active?: boolean;
38
+ readonly loaded?: boolean;
39
+ readonly inputSchema?: Readonly<Record<string, unknown>>;
40
+ }
41
+ export type InventoryResult<T> = {
42
+ readonly kind: "ok";
43
+ readonly scope: InventoryScope;
44
+ readonly observedAt: string;
45
+ /** Which native view was read; mcp-only must never be displayed as all tools. */
46
+ readonly view: "discovered" | "context" | "registered" | "mcp-only";
47
+ readonly items: readonly T[];
48
+ /** Native discovery errors / startup gaps, without credentials or raw configs. */
49
+ readonly partial: boolean;
50
+ } | {
51
+ readonly kind: "unsupported";
52
+ readonly code: "native_query_unavailable" | "transport_unavailable" | "scope_unavailable" | "installation_unsupported";
53
+ readonly reason: string;
54
+ } | {
55
+ readonly kind: "unavailable";
56
+ readonly code: "timeout" | "query_failed";
57
+ readonly reason: string;
58
+ };
59
+ export type InventoryReader<T> = (installation: AvailableInstallation, options?: InventoryOptions) => Promise<InventoryResult<T>>;
60
+ export interface RuntimeInventories {
61
+ readonly skills: InventoryReader<SkillEntry>;
62
+ readonly mcpServers: InventoryReader<McpServerEntry>;
63
+ readonly tools: InventoryReader<ToolEntry>;
64
+ }
65
+ //# sourceMappingURL=inventory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../src/contracts/inventory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE/D,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAAG,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE;AAEpF,MAAM,WAAW,gBAAgB;IAC/B,uFAAuF;IACvF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC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ts/inventory.ts"],"names":[],"mappings":""}
@@ -1,14 +1,15 @@
1
+ import type { RuntimeInventories } from "./inventory.js";
1
2
  import type { AccountUsageReader } from "./account-usage.js";
2
3
  import type { InstallationProbe } from "./installation.js";
3
4
  import type { ModelLister } from "./list-models.js";
4
5
  import type { StartSession } from "./session.js";
5
6
  /** One provider-independent runtime adoption unit. */
6
- export interface Runtime {
7
+ export interface Runtime extends RuntimeInventories {
7
8
  readonly id: string;
8
9
  readonly session: StartSession;
9
10
  readonly installation?: InstallationProbe;
10
11
  readonly accountUsage?: AccountUsageReader;
11
12
  readonly listModels?: ModelLister;
12
13
  }
13
- export declare function defineRuntime<const T extends Runtime>(runtime: T): T;
14
+ export declare function defineRuntime<const T extends Omit<Runtime, keyof RuntimeInventories> & Partial<RuntimeInventories>>(runtime: T): T & RuntimeInventories;
14
15
  //# sourceMappingURL=runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/contracts/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,sDAAsD;AACtD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC;CACnC;AAED,wBAAgB,aAAa,CAAC,KAAK,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAEpE"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/contracts/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,sDAAsD;AACtD,MAAM,WAAW,OAAQ,SAAQ,kBAAkB;IACjD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC;CACnC;AAWD,wBAAgB,aAAa,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,OAAO,EAAE,MAAM,kBAAkB,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAEvJ"}
@@ -1,4 +1,12 @@
1
+ async function unsupported() {
2
+ await Promise.resolve();
3
+ return {
4
+ kind: "unsupported",
5
+ code: "transport_unavailable",
6
+ reason: "The selected runtime interface does not expose this inventory",
7
+ };
8
+ }
1
9
  export function defineRuntime(runtime) {
2
- return runtime;
10
+ return { skills: unsupported, mcpServers: unsupported, tools: unsupported, ...runtime };
3
11
  }
4
12
  //# sourceMappingURL=runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/contracts/runtime.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,aAAa,CAA0B,OAAU;IAC/D,OAAO,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/contracts/runtime.ts"],"names":[],"mappings":"AAeA,KAAK,UAAU,WAAW;IACxB,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;IACxB,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,uBAAuB;QAC7B,MAAM,EAAE,+DAA+D;KACxE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAwF,OAAU;IAC7H,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,OAAO,EAAE,CAAC;AAC1F,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RuntimeRegistry } from "./registry.js";
2
+ export type { InventoryScope, InventoryOptions, SkillEntry, McpServerEntry, ToolEntry, InventoryResult, InventoryReader, RuntimeInventories } from "./contracts/inventory.js";
2
3
  export type { AccountUsageUnsupportedReason, AccountUsageReauthReason, AccountUsageReader, AccountUsageReadOptions, AccountUsageSnapshot, AccountUsageWindow, UtcInstant, } from "./contracts/account-usage.js";
3
4
  export type { AvailableInstallation, BundledInstallation, ExecutableInstallation, InstallationProbe, InstallationSnapshot, } from "./contracts/installation.js";
4
5
  export type { ProviderAuthFacade, ProviderAuthStatus, ProviderLoginEvent, ProviderLoginInteraction, ProviderLoginMethod, ProviderLoginPrompt, } from "./contracts/provider-auth.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAOhD,YAAY,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,GACX,MAA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../contracts/account-usage.js";
2
+ /** Native get_usage reply, not the HTTP endpoint's unrelated limits[] shape. */
3
+ export declare function projectClaudeUsage(payload: unknown, email?: string): AccountUsageSnapshot;
2
4
  /**
3
- * Project the `/api/oauth/usage` payload. The authoritative shape is its
4
- * `limits` array; a representative (subscription) response is:
5
- *
6
- * ```json
7
- * {
8
- * "limits": [
9
- * { "kind": "session", "group": "session", "percent": 17, "severity": "normal",
10
- * "resets_at": "2026-08-26T13:49:59.725522+00:00", "scope": null, "is_active": false },
11
- * { "kind": "weekly_all", "group": "weekly", "percent": 72, "severity": "normal",
12
- * "resets_at": "2026-08-28T06:59:59.725547+00:00", "scope": null, "is_active": false },
13
- * { "kind": "weekly_scoped", "group": "weekly", "percent": 100, "severity": "critical",
14
- * "resets_at": "2026-08-28T06:59:59.725963+00:00",
15
- * "scope": { "model": { "display_name": "Fable" } }, "is_active": true }
16
- * ]
17
- * }
18
- * ```
19
- */
20
- export declare function projectClaudeUsage(payload: unknown, email?: string, plan?: string): AccountUsageSnapshot;
21
- /** Extract Claude Code's explicit subscription tier from a confirmed login. */
22
- export declare function claudeAccountPlan(payload: unknown): string | undefined;
23
- /**
24
- * Reads Claude account usage in two steps: `claude auth status --json` for the
25
- * login gate and account email, then a single read-only request to Anthropic's
26
- * structured usage endpoint using the persisted `/login` OAuth token. This
27
- * replaces the older `claude -p /usage` subprocess, which was slower and only
28
- * returned pre-rendered text.
5
+ * Only native control queries; no prompt, credential reads or direct HTTP.
6
+ * Fresh-process session totals are deliberately not exposed as account usage.
7
+ * initialize provides optional account identity; get_usage owns quota access.
29
8
  */
30
9
  export declare const claudeAccountUsage: AccountUsageReader;
31
10
  //# sourceMappingURL=account-usage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account-usage.d.ts","sourceRoot":"","sources":["../../../src/runtimes/claude/account-usage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EAGrB,MAAM,kCAAkC,CAAC;AAqG1C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,oBAAoB,CA8BtB;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOtE;AAaD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBA+ChC,CAAC"}
1
+ {"version":3,"file":"account-usage.d.ts","sourceRoot":"","sources":["../../../src/runtimes/claude/account-usage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAsB,MAAM,kCAAkC,CAAC;AAmBrH,gFAAgF;AAChF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAmDzF;AAaD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAiEhC,CAAC"}
@@ -1,210 +1,154 @@
1
- import { readFileSync } from "node:fs";
2
- import { homedir, platform } from "node:os";
3
- import { join } from "node:path";
4
- import { runExecutable } from "../../shared/executable/index.js";
1
+ import { randomUUID } from "node:crypto";
2
+ import { spawnLineProcess } from "../../shared/executable/index.js";
5
3
  import { utcInstantFromDate } from "../../shared/instant.js";
6
- import { asNumber, asRecord, parseJson } from "../../shared/json.js";
7
- const USAGE_ENDPOINT = "https://api.anthropic.com/api/oauth/usage";
8
- // The structured usage endpoint is gated behind the OAuth beta and requires a
9
- // full `/login` token carrying the `user:profile` scope. Inference-only tokens
10
- // (env CLAUDE_CODE_OAUTH_TOKEN / injected FDs) lack that scope, so this reader
11
- // only consults the persisted login credential.
12
- const OAUTH_BETA = "oauth-2025-04-20";
13
- const PROFILE_SCOPE = "user:profile";
14
- function parseStoredOAuth(raw) {
15
- const oauth = asRecord(asRecord(parseJson(raw))?.claudeAiOauth);
16
- const accessToken = oauth?.accessToken;
17
- if (typeof accessToken !== "string" || accessToken.length === 0) {
4
+ import { asNumber, asRecord, asRecordList, parseJson } from "../../shared/json.js";
5
+ function windowOf(label, value) {
6
+ const entry = asRecord(value);
7
+ const percent = asNumber(entry?.utilization);
8
+ if (percent === null || percent < 0) {
18
9
  return null;
19
10
  }
20
- const scopes = oauth?.scopes;
21
- const hasProfileScope = Array.isArray(scopes) && scopes.includes(PROFILE_SCOPE);
22
- return { accessToken, hasProfileScope };
23
- }
24
- function credentialsFilePath() {
25
- const base = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude");
26
- return join(base, ".credentials.json");
27
- }
28
- /**
29
- * Read Claude Code's persisted `/login` OAuth credential, mirroring the
30
- * `getClaudeAIOAuthTokens()` fallback: the plaintext credentials file (Linux,
31
- * and the macOS/Windows fallback), then the macOS Keychain, which stores the
32
- * same JSON blob. Any failure degrades to `null`; never throws.
33
- */
34
- async function readStoredOAuth(timeoutMs) {
35
- try {
36
- return parseStoredOAuth(readFileSync(credentialsFilePath(), "utf8"));
37
- }
38
- catch {
39
- // No file (or unreadable): fall through to the platform keystore.
40
- }
41
- if (platform() === "darwin") {
42
- const keychain = await runExecutable("security", ["find-generic-password", "-w", "-s", "Claude Code-credentials"], { timeoutMs });
43
- if (keychain.ok) {
44
- try {
45
- return parseStoredOAuth(keychain.stdout);
46
- }
47
- catch {
48
- return null;
49
- }
50
- }
51
- }
52
- return null;
53
- }
54
- function usageWindowLabel(kind, scope) {
55
- const modelName = asRecord(scope?.model)?.display_name;
56
- switch (kind) {
57
- case "session":
58
- return "Current session";
59
- case "weekly_all":
60
- return "Current week (all models)";
61
- case "weekly_scoped":
62
- return typeof modelName === "string" ? `Current week (${modelName})` : "Current week";
63
- default:
64
- return typeof kind === "string" && kind.length > 0 ? kind : "Usage limit";
65
- }
11
+ const reset = typeof entry?.resets_at === "string" ? utcInstantFromDate(new Date(entry.resets_at)) : null;
12
+ return {
13
+ label,
14
+ usedRatio: Math.min(1, Number((percent / 100).toFixed(6))),
15
+ ...(reset === null ? {} : { resetsAt: reset }),
16
+ };
66
17
  }
67
- async function fetchUsage(accessToken, version, timeoutMs) {
68
- try {
69
- return await fetch(USAGE_ENDPOINT, {
70
- headers: {
71
- "Authorization": `Bearer ${accessToken}`,
72
- "anthropic-beta": OAUTH_BETA,
73
- "Content-Type": "application/json",
74
- "User-Agent": `claude-code/${version}`,
75
- },
76
- signal: AbortSignal.timeout(Math.min(timeoutMs, 5000)),
77
- });
18
+ /** Native get_usage reply, not the HTTP endpoint's unrelated limits[] shape. */
19
+ export function projectClaudeUsage(payload, email) {
20
+ const root = asRecord(payload);
21
+ if (root?.rate_limits_available === false) {
22
+ // The CLI does not distinguish auth mode, missing scope, etc. here.
23
+ return { kind: "unsupported", reason: "quota_unavailable" };
78
24
  }
79
- catch (error) {
80
- throw new Error("Failed to reach Claude usage endpoint", { cause: error });
25
+ if (root?.rate_limits_available !== true) {
26
+ throw new Error("Claude get_usage returned an invalid availability flag");
81
27
  }
82
- }
83
- function resetInstant(value) {
84
- if (typeof value !== "string") {
85
- return null;
28
+ const limits = asRecord(root.rate_limits);
29
+ if (limits === null) {
30
+ // Available in principle, but the runtime could not supply a snapshot.
31
+ throw new Error("Claude get_usage did not return account rate limits");
86
32
  }
87
- const date = new Date(value);
88
- return Number.isNaN(date.getTime()) ? null : utcInstantFromDate(date);
89
- }
90
- /**
91
- * Project the `/api/oauth/usage` payload. The authoritative shape is its
92
- * `limits` array; a representative (subscription) response is:
93
- *
94
- * ```json
95
- * {
96
- * "limits": [
97
- * { "kind": "session", "group": "session", "percent": 17, "severity": "normal",
98
- * "resets_at": "2026-08-26T13:49:59.725522+00:00", "scope": null, "is_active": false },
99
- * { "kind": "weekly_all", "group": "weekly", "percent": 72, "severity": "normal",
100
- * "resets_at": "2026-08-28T06:59:59.725547+00:00", "scope": null, "is_active": false },
101
- * { "kind": "weekly_scoped", "group": "weekly", "percent": 100, "severity": "critical",
102
- * "resets_at": "2026-08-28T06:59:59.725963+00:00",
103
- * "scope": { "model": { "display_name": "Fable" } }, "is_active": true }
104
- * ]
105
- * }
106
- * ```
107
- */
108
- export function projectClaudeUsage(payload, email, plan) {
109
- const limits = asRecord(payload)?.limits;
110
33
  const windows = [];
111
- let rateLimited = false;
112
- if (Array.isArray(limits)) {
113
- for (const entry of limits) {
114
- const limit = asRecord(entry);
115
- const percent = asNumber(limit?.percent);
116
- if (limit === null || percent === null || percent < 0) {
117
- continue;
34
+ const add = (label, value) => {
35
+ const window = windowOf(label, value);
36
+ if (window !== null) {
37
+ windows.push(window);
38
+ }
39
+ };
40
+ add("Current session", limits.five_hour);
41
+ add("Current week (all models)", limits.seven_day);
42
+ add("Current week (OAuth apps)", limits.seven_day_oauth_apps);
43
+ if (Array.isArray(limits.model_scoped)) {
44
+ for (const entry of asRecordList(limits.model_scoped)) {
45
+ if (typeof entry.display_name === "string" && entry.display_name.trim().length > 0) {
46
+ add(`Current week (${entry.display_name})`, entry);
118
47
  }
119
- const resetsAt = resetInstant(limit.resets_at);
120
- windows.push({
121
- label: usageWindowLabel(limit.kind, asRecord(limit.scope)),
122
- usedRatio: Number((percent / 100).toFixed(6)),
123
- ...(resetsAt === null ? {} : { resetsAt }),
124
- });
125
- rateLimited ||= limit.severity === "critical" || percent >= 100;
126
48
  }
127
49
  }
50
+ else {
51
+ add("Current week (Opus)", limits.seven_day_opus);
52
+ add("Current week (Sonnet)", limits.seven_day_sonnet);
53
+ }
54
+ const includedExhausted = windows.some((window) => window.usedRatio >= 1);
55
+ const extra = asRecord(limits.extra_usage);
56
+ const extraWindow = extra?.is_enabled === true ? windowOf("Extra usage", extra) : null;
57
+ if (extraWindow !== null) {
58
+ windows.push(extraWindow);
59
+ }
128
60
  if (windows.length === 0) {
129
- throw new Error("Claude usage endpoint returned no usable windows");
61
+ throw new Error("Claude get_usage returned no usable windows");
130
62
  }
63
+ const plan = typeof root.subscription_type === "string" ? root.subscription_type.trim() : "";
131
64
  return {
132
65
  kind: "available",
133
- ...(plan === undefined ? {} : { plan }),
66
+ ...(plan.length === 0 ? {} : { plan }),
134
67
  ...(email === undefined ? {} : { email }),
135
- rateLimited,
68
+ rateLimited: includedExhausted && !(extraWindow !== null && extraWindow.usedRatio < 1),
136
69
  windows,
137
70
  };
138
71
  }
139
- /** Extract Claude Code's explicit subscription tier from a confirmed login. */
140
- export function claudeAccountPlan(payload) {
141
- const authStatus = asRecord(payload);
142
- if (authStatus?.loggedIn !== true || typeof authStatus.subscriptionType !== "string") {
143
- return undefined;
72
+ function controlFailure(reply) {
73
+ const detail = typeof reply.error === "string" ? reply.error : "Malformed control response";
74
+ if (/unsupported control request subtype|unknown control request|not supported in this context|not available on this connection/iu.test(detail)) {
75
+ return { kind: "unsupported", reason: "endpoint_unavailable" };
144
76
  }
145
- const plan = authStatus.subscriptionType.trim();
146
- return plan.length > 0 ? plan : undefined;
147
- }
148
- function isConfirmedNonSubscriptionLogin(authStatus) {
149
- if (typeof authStatus.apiKeySource === "string") {
150
- return true;
77
+ if (/not logged in|authentication required|please (?:run )?\/login/iu.test(detail)) {
78
+ return { kind: "reauth_required", reason: "not_authenticated" };
151
79
  }
152
- // Claude Code reports externally supplied auth tokens (including custom API
153
- // endpoints) as `oauth_token`. They authenticate inference, not a claude.ai
154
- // subscription, so the profile-scoped usage endpoint is inapplicable.
155
- return typeof authStatus.authMethod === "string"
156
- && authStatus.authMethod !== "claude.ai";
80
+ throw new Error(`Claude usage control request failed: ${detail}`);
157
81
  }
158
82
  /**
159
- * Reads Claude account usage in two steps: `claude auth status --json` for the
160
- * login gate and account email, then a single read-only request to Anthropic's
161
- * structured usage endpoint using the persisted `/login` OAuth token. This
162
- * replaces the older `claude -p /usage` subprocess, which was slower and only
163
- * returned pre-rendered text.
83
+ * Only native control queries; no prompt, credential reads or direct HTTP.
84
+ * Fresh-process session totals are deliberately not exposed as account usage.
85
+ * initialize provides optional account identity; get_usage owns quota access.
164
86
  */
165
87
  export const claudeAccountUsage = async (installation, options = {}) => {
166
88
  if (installation.via !== "executable") {
167
89
  return { kind: "unsupported", reason: "unsupported_installation" };
168
90
  }
169
- const command = installation.command;
170
- const timeoutMs = options.timeoutMs ?? 15_000;
171
- const env = { ...process.env, CLAUDECODE: undefined };
172
- const auth = await runExecutable(command, ["auth", "status", "--json"], { env, timeoutMs });
173
- if (!auth.ok && auth.exitCode === null) {
174
- throw new Error("Failed to read Claude authentication status");
175
- }
176
- const authStatus = asRecord(parseJson(auth.stdout));
177
- if (!auth.ok || authStatus?.loggedIn === false) {
178
- return { kind: "reauth_required", reason: "not_authenticated" };
179
- }
180
- // Only a confirmed login exposes an account email (pinned by the owner's
181
- // `loggedIn === true` requirement); an absent or non-string email is dropped.
182
- const email = authStatus?.loggedIn === true && typeof authStatus.email === "string"
183
- ? authStatus.email
184
- : undefined;
185
- const plan = claudeAccountPlan(authStatus);
186
- if (authStatus?.loggedIn === true && isConfirmedNonSubscriptionLogin(authStatus)) {
187
- // Inference credentials take precedence over any claude.ai login, and
188
- // non-subscription billing has no profile usage windows.
189
- return { kind: "unsupported", reason: "unsupported_auth_mode" };
190
- }
191
- const stored = await readStoredOAuth(timeoutMs);
192
- if (stored === null) {
193
- // No persisted profile-scoped login token means the usage endpoint would
194
- // reject the request; treat it as needing a fresh `/login`.
195
- return { kind: "reauth_required", reason: "credentials_missing" };
196
- }
197
- if (!stored.hasProfileScope) {
198
- return { kind: "reauth_required", reason: "scope_missing" };
199
- }
200
- const response = await fetchUsage(stored.accessToken, installation.version ?? "0.0.0", timeoutMs);
201
- if (response.status === 401 || response.status === 403) {
202
- return { kind: "reauth_required", reason: "credentials_rejected" };
91
+ const child = spawnLineProcess(installation.command, [
92
+ "-p", "--input-format", "stream-json", "--output-format", "stream-json",
93
+ "--verbose", "--no-session-persistence",
94
+ ], { env: { ...process.env, CLAUDECODE: undefined } });
95
+ let pending = null;
96
+ let ended = false;
97
+ let timedOut = false;
98
+ child.onLine((line) => {
99
+ const message = asRecord(parseJson(line));
100
+ const inner = asRecord(message?.response);
101
+ if (message?.type === "control_response" && pending !== null && inner?.request_id === pending.id) {
102
+ pending.resolve(inner);
103
+ }
104
+ });
105
+ child.onExit(() => {
106
+ ended = true;
107
+ pending?.resolve(null);
108
+ });
109
+ child.stdin.on("error", () => {
110
+ ended = true;
111
+ pending?.resolve(null);
112
+ });
113
+ const timer = setTimeout(() => {
114
+ timedOut = true;
115
+ pending?.resolve(null);
116
+ child.kill();
117
+ }, options.timeoutMs ?? 15_000);
118
+ const query = async (request) => {
119
+ if (ended || timedOut) {
120
+ throw new Error("Claude exited or timed out before answering usage queries");
121
+ }
122
+ const id = `oar-usage-${randomUUID()}`;
123
+ const { promise, resolve } = Promise.withResolvers();
124
+ pending = { id, resolve };
125
+ child.write(`${JSON.stringify({ type: "control_request", request_id: id, request })}\n`);
126
+ const reply = await promise;
127
+ pending = null;
128
+ if (reply === null) {
129
+ throw new Error("Claude exited or timed out before answering usage query");
130
+ }
131
+ return reply;
132
+ };
133
+ try {
134
+ await child.spawned;
135
+ const initialized = await query({ subtype: "initialize" });
136
+ if (initialized.subtype !== "success") {
137
+ return controlFailure(initialized);
138
+ }
139
+ const account = asRecord(asRecord(initialized.response)?.account);
140
+ const email = typeof account?.email === "string" && account.email.trim().length > 0
141
+ ? account.email.trim() : undefined;
142
+ const reply = await query({ subtype: "get_usage", skip_behaviors: true });
143
+ if (reply.subtype !== "success") {
144
+ return controlFailure(reply);
145
+ }
146
+ return projectClaudeUsage(reply.response, email);
203
147
  }
204
- if (!response.ok) {
205
- throw new Error(`Claude usage endpoint returned HTTP ${response.status}`);
148
+ finally {
149
+ clearTimeout(timer);
150
+ child.kill();
151
+ await child.exited;
206
152
  }
207
- const payload = parseJson(await response.text());
208
- return projectClaudeUsage(payload, email, plan);
209
153
  };
210
154
  //# sourceMappingURL=account-usage.js.map