@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.217
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/CHANGELOG.md +206 -1
- package/README.md +45 -0
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
- package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
- package/dist/command-catalog.generated.d.ts +105 -10
- package/dist/command-catalog.generated.js +127 -10
- package/dist/command-help.js +3 -1
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/auth.js +11 -52
- package/dist/commands/bot.js +75 -10
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud-demote.d.ts +19 -4
- package/dist/commands/cloud-demote.js +85 -12
- package/dist/commands/cloud-provision.d.ts +5 -1
- package/dist/commands/cloud-provision.js +6 -2
- package/dist/commands/cloud.d.ts +36 -0
- package/dist/commands/cloud.js +110 -27
- package/dist/commands/core-delegate-w1b.js +15 -1
- package/dist/commands/core-policy.js +67 -8
- package/dist/commands/core.js +1 -0
- package/dist/commands/daemon.js +9 -1
- package/dist/commands/dm.js +7 -0
- package/dist/commands/doctor-usage.d.ts +8 -0
- package/dist/commands/doctor-usage.js +20 -0
- package/dist/commands/doctor.js +7 -1
- package/dist/commands/env.d.ts +18 -0
- package/dist/commands/env.js +82 -0
- package/dist/commands/files-browse.d.ts +11 -4
- package/dist/commands/files-browse.js +21 -4
- package/dist/commands/files.d.ts +1 -1
- package/dist/commands/files.js +25 -11
- package/dist/commands/install-global.js +2 -2
- package/dist/commands/integrations-auth-rules.d.ts +27 -0
- package/dist/commands/integrations-auth-rules.js +79 -0
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +102 -26
- package/dist/commands/logout.d.ts +7 -0
- package/dist/commands/logout.js +41 -34
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sources.d.ts +8 -2
- package/dist/commands/sources.js +65 -9
- package/dist/commands/sync-held.js +5 -2
- package/dist/commands/whoami.js +26 -1
- package/dist/data/command-states.json +15 -0
- package/dist/index.js +52 -4
- package/dist/lazy-commands.js +5 -6
- package/dist/lib/anywhere-person-setting.d.ts +2 -0
- package/dist/lib/anywhere-person-setting.js +6 -3
- package/dist/lib/billing/usage-card.d.ts +25 -4
- package/dist/lib/billing/usage-card.js +76 -9
- package/dist/lib/billing/usage-cost.d.ts +3 -3
- package/dist/lib/billing/usage-cost.js +35 -13
- package/dist/lib/billing/usage-only.js +4 -2
- package/dist/lib/billing/usage-rate-card.d.ts +2 -2
- package/dist/lib/billing/usage-rate-card.js +3 -0
- package/dist/lib/bot/fleet-cron.d.ts +8 -0
- package/dist/lib/bot/fleet-cron.js +126 -7
- package/dist/lib/bot/fleet-daemon.d.ts +46 -0
- package/dist/lib/bot/fleet-daemon.js +99 -1
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/inflight.js +10 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
- package/dist/lib/bot/probe.js +7 -1
- package/dist/lib/bot/run.js +20 -1
- package/dist/lib/bot/runtime/codex.js +1 -1
- package/dist/lib/bot/runtime/grok-acp.d.ts +6 -1
- package/dist/lib/bot/runtime/grok-acp.js +32 -14
- package/dist/lib/bot/runtime/grok.js +1 -1
- package/dist/lib/bot/runtime/index.js +19 -9
- package/dist/lib/bot/runtime/messages-stream.js +2 -2
- package/dist/lib/bot/runtime/types.d.ts +15 -0
- package/dist/lib/bot/runtime/types.js +9 -0
- package/dist/lib/bot/runtime-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- package/dist/lib/capacity/accounts.d.ts +8 -0
- package/dist/lib/capacity/accounts.js +19 -0
- package/dist/lib/capacity/available.d.ts +154 -0
- package/dist/lib/capacity/available.js +905 -0
- package/dist/lib/capacity/codex-availability.d.ts +14 -1
- package/dist/lib/capacity/codex-availability.js +26 -1
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
- package/dist/lib/capacity/collectors/codex.js +10 -7
- package/dist/lib/capacity/ledger.d.ts +37 -1
- package/dist/lib/capacity/ledger.js +207 -30
- package/dist/lib/capacity/project.d.ts +26 -0
- package/dist/lib/capacity/project.js +137 -8
- package/dist/lib/capacity/refusal-rows.d.ts +31 -0
- package/dist/lib/capacity/refusal-rows.js +61 -0
- package/dist/lib/capacity/refusal.d.ts +53 -2
- package/dist/lib/capacity/refusal.js +284 -65
- package/dist/lib/capacity/route.js +46 -11
- package/dist/lib/capacity/widget.d.ts +12 -1
- package/dist/lib/capacity/widget.js +91 -3
- package/dist/lib/daemon/flag-monitor.d.ts +8 -0
- package/dist/lib/daemon/flag-monitor.js +17 -6
- package/dist/lib/daemon/flag.d.ts +65 -1
- package/dist/lib/daemon/flag.js +190 -40
- package/dist/lib/daemon/ops/policy.js +62 -5
- package/dist/lib/daemon/paths.d.ts +72 -2
- package/dist/lib/daemon/paths.js +154 -3
- package/dist/lib/daemon/resolver.d.ts +2 -0
- package/dist/lib/daemon/resolver.js +3 -0
- package/dist/lib/daemon/run.d.ts +9 -0
- package/dist/lib/daemon/run.js +79 -21
- package/dist/lib/daemon/selfcheck.d.ts +22 -0
- package/dist/lib/daemon/selfcheck.js +40 -1
- package/dist/lib/daemon/server.d.ts +5 -1
- package/dist/lib/daemon/server.js +17 -23
- package/dist/lib/daemon/state-file-switch.d.ts +57 -0
- package/dist/lib/daemon/state-file-switch.js +88 -0
- package/dist/lib/daemon/state-file.d.ts +198 -0
- package/dist/lib/daemon/state-file.js +419 -0
- package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
- package/dist/lib/daemon/tcc-eperm.js +310 -0
- package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
- package/dist/lib/daemon/timed-flag-monitors.js +75 -0
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +7 -1
- package/dist/lib/delivery/artifacts.js +29 -10
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -0
- package/dist/lib/delivery/disposable-target.d.ts +42 -0
- package/dist/lib/delivery/disposable-target.js +111 -0
- package/dist/lib/delivery/effects.d.ts +136 -0
- package/dist/lib/delivery/effects.js +541 -0
- package/dist/lib/delivery/enrollment.d.ts +21 -17
- package/dist/lib/delivery/enrollment.js +83 -5
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -0
- package/dist/lib/delivery/lease.d.ts +80 -0
- package/dist/lib/delivery/lease.js +134 -0
- package/dist/lib/delivery/migrations.d.ts +120 -4
- package/dist/lib/delivery/migrations.js +215 -15
- package/dist/lib/delivery/mqtt.d.ts +2 -0
- package/dist/lib/delivery/mqtt.js +7 -0
- package/dist/lib/delivery/reconciler.d.ts +65 -1
- package/dist/lib/delivery/reconciler.js +224 -13
- package/dist/lib/delivery/rpc/client.d.ts +22 -0
- package/dist/lib/delivery/rpc/client.js +159 -0
- package/dist/lib/delivery/rpc/port.d.ts +40 -0
- package/dist/lib/delivery/rpc/port.js +16 -0
- package/dist/lib/delivery/rpc/server.d.ts +30 -0
- package/dist/lib/delivery/rpc/server.js +205 -0
- package/dist/lib/delivery/rpc/wire.d.ts +85 -0
- package/dist/lib/delivery/rpc/wire.js +143 -0
- package/dist/lib/delivery/store.d.ts +2 -0
- package/dist/lib/delivery/store.js +4 -0
- package/dist/lib/delivery/windows-service-install.d.ts +262 -0
- package/dist/lib/delivery/windows-service-install.js +892 -0
- package/dist/lib/delivery/workers/macos.d.ts +16 -1
- package/dist/lib/delivery/workers/macos.js +54 -12
- package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
- package/dist/lib/delivery/workers/windows-service-live.js +711 -0
- package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
- package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
- package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
- package/dist/lib/delivery/workers/windows-service.js +584 -0
- package/dist/lib/delivery/workers/windows.d.ts +32 -22
- package/dist/lib/delivery/workers/windows.js +50 -64
- package/dist/lib/doctor/checks/host-core.d.ts +50 -0
- package/dist/lib/doctor/checks/host-core.js +269 -0
- package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
- package/dist/lib/doctor/checks/replay-recorder.js +261 -0
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/environment/profile.d.ts +239 -0
- package/dist/lib/environment/profile.js +251 -0
- package/dist/lib/hook-engine/reconcile.js +39 -13
- package/dist/lib/hook-engine/registration.d.ts +9 -0
- package/dist/lib/hook-engine/registration.js +19 -0
- package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
- package/dist/lib/hot-channels/adapters/meetings.js +36 -3
- package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
- package/dist/lib/hot-channels/adapters/slack.js +64 -21
- package/dist/lib/hot-channels/alert.d.ts +2 -0
- package/dist/lib/hot-channels/alert.js +8 -1
- package/dist/lib/hot-channels/contract.d.ts +12 -0
- package/dist/lib/hot-channels/contract.js +7 -0
- package/dist/lib/hot-channels/loop.js +1 -0
- package/dist/lib/hot-channels/run.d.ts +6 -0
- package/dist/lib/hot-channels/run.js +4 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +74 -1
- package/dist/lib/hot-channels/signals-pass.js +82 -41
- package/dist/lib/hot-channels/signals-redo.js +10 -2
- package/dist/lib/install/claude-targets.d.ts +12 -1
- package/dist/lib/install/claude-targets.js +57 -5
- package/dist/lib/install/codex-targets.d.ts +2 -2
- package/dist/lib/install/codex-targets.js +36 -6
- package/dist/lib/install/hook-target.d.ts +3 -0
- package/dist/lib/install/hook-target.js +11 -0
- package/dist/lib/lanes/canonical-host.d.ts +35 -0
- package/dist/lib/lanes/canonical-host.js +65 -0
- package/dist/lib/lanes/host-capacity.d.ts +30 -0
- package/dist/lib/lanes/host-capacity.js +29 -3
- package/dist/lib/lanes/watcher.js +35 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +5 -2
- package/dist/lib/mesh/live/flush.d.ts +5 -1
- package/dist/lib/mesh/live/flush.js +12 -6
- package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
- package/dist/lib/mesh/live/reporting-privacy.js +56 -1
- package/dist/lib/mesh/live/spool.d.ts +7 -0
- package/dist/lib/mesh/live/spool.js +25 -0
- package/dist/lib/person-setting-cache.d.ts +38 -0
- package/dist/lib/person-setting-cache.js +98 -0
- package/dist/lib/safe-store.d.ts +245 -0
- package/dist/lib/safe-store.js +777 -0
- package/dist/lib/signals/engine.d.ts +29 -2
- package/dist/lib/signals/engine.js +103 -4
- package/dist/lib/signals/reply.js +73 -18
- package/dist/lib/signals/steps/adapters.js +7 -2
- package/dist/lib/signals/steps/extract.d.ts +13 -0
- package/dist/lib/signals/steps/extract.js +122 -6
- package/dist/main.js +46 -3
- package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
- package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
- package/dist/utils/auth-expiry.d.ts +8 -0
- package/dist/utils/auth-expiry.js +53 -0
- package/dist/utils/catalog-runtime-paths.d.ts +34 -0
- package/dist/utils/catalog-runtime-paths.js +53 -0
- package/dist/utils/cli-telemetry.d.ts +21 -0
- package/dist/utils/cli-telemetry.js +34 -0
- package/dist/utils/command-usage.d.ts +275 -0
- package/dist/utils/command-usage.js +797 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/dist/utils/hook-trust.d.ts +7 -0
- package/dist/utils/hook-trust.js +31 -4
- package/dist/utils/host-registration.d.ts +126 -0
- package/dist/utils/host-registration.js +378 -0
- package/dist/utils/resident-package-preload.js +2 -0
- package/package.json +10 -8
- package/scripts/bench-core.mjs +1096 -0
- package/scripts/check-function-manifest.mjs +702 -0
- package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
- package/dist/lib/delivery/workers/windows-boundary.js +0 -693
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { NowLimit } from "./ledger.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The raw account string for a Codex home, before hashing. win32 paths are
|
|
4
|
+
* case-insensitive, so the same home reached with different casing folds to one
|
|
5
|
+
* id; on other platforms the resolved path is used as-is. Every id built from a
|
|
6
|
+
* home must go through here so both Codex collectors agree on the account.
|
|
7
|
+
*/
|
|
8
|
+
export declare function codexHomeAccountRaw(home: string): string;
|
|
9
|
+
/** The one account id for a Codex home. Same value the collectors hash for that home. */
|
|
10
|
+
export declare function canonicalCodexAccountId(home: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* A newer snapshot supersedes omitted windows within the same account. The
|
|
13
|
+
* rebuild has already moved every reading of a home to its canonical id, so
|
|
14
|
+
* this compares one login's readings across both Codex collectors.
|
|
15
|
+
*/
|
|
3
16
|
export declare function codexSnapshotStale(limit: NowLimit, limits: readonly NowLimit[]): boolean;
|
|
4
17
|
/** Credits can keep Codex serving after a plan window runs out. */
|
|
5
18
|
export declare function hasCodexCreditRoom(limits: readonly NowLimit[], nowMs: number): boolean;
|
|
@@ -1,6 +1,31 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { isRefusalHold } from "./refusal-rows.js";
|
|
1
4
|
const MAX_CREDIT_AGE_MS = 24 * 36e5;
|
|
2
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* The raw account string for a Codex home, before hashing. win32 paths are
|
|
7
|
+
* case-insensitive, so the same home reached with different casing folds to one
|
|
8
|
+
* id; on other platforms the resolved path is used as-is. Every id built from a
|
|
9
|
+
* home must go through here so both Codex collectors agree on the account.
|
|
10
|
+
*/
|
|
11
|
+
export function codexHomeAccountRaw(home) {
|
|
12
|
+
const resolved = path.resolve(home);
|
|
13
|
+
return `home:${process.platform === "win32" ? resolved.toLowerCase() : resolved}`;
|
|
14
|
+
}
|
|
15
|
+
/** The one account id for a Codex home. Same value the collectors hash for that home. */
|
|
16
|
+
export function canonicalCodexAccountId(home) {
|
|
17
|
+
const digest = crypto.createHash("sha256").update(codexHomeAccountRaw(home), "utf8").digest("hex").slice(0, 16);
|
|
18
|
+
return `acct_${digest}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A newer snapshot supersedes omitted windows within the same account. The
|
|
22
|
+
* rebuild has already moved every reading of a home to its canonical id, so
|
|
23
|
+
* this compares one login's readings across both Codex collectors.
|
|
24
|
+
*/
|
|
3
25
|
export function codexSnapshotStale(limit, limits) {
|
|
26
|
+
// A refusal hold has its own end: holdsInForce and its reset.
|
|
27
|
+
if (isRefusalHold(limit))
|
|
28
|
+
return false;
|
|
4
29
|
if (limit.source !== "codex-jsonl" && limit.source !== "codex-app-server" && limit.source !== "refusal")
|
|
5
30
|
return false;
|
|
6
31
|
const at = Date.parse(limit.observedAt);
|
|
@@ -29,11 +29,17 @@
|
|
|
29
29
|
* observedAt is the response time. One collect appends every account's
|
|
30
30
|
* readings and failures in one rebuild.
|
|
31
31
|
*/
|
|
32
|
-
import { type LedgerOptions, type NowView, type ParserFailureEvent, type ReadingInput } from "../ledger.js";
|
|
32
|
+
import { type LedgerOptions, type RateLimitResetCredits, type NowView, type ParserFailureEvent, type ReadingInput } from "../ledger.js";
|
|
33
33
|
export declare const CLAUDE_OAUTH_PARSER_VERSION = "claude-oauth-usage.1";
|
|
34
34
|
export declare const CLAUDE_OAUTH_PROVIDER = "claude";
|
|
35
35
|
export declare const CLAUDE_OAUTH_SOURCE: "oauth-usage";
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* `cedar_ember=1` adds the account's banked limit resets (a `cedar_ember` block with
|
|
38
|
+
* `grants[]`) to the usual usage body. Claude Code reads the same block to offer a
|
|
39
|
+
* reset at the limit wall. Without it an account that is at 100% but holds a reset
|
|
40
|
+
* looks used up for the week.
|
|
41
|
+
*/
|
|
42
|
+
export declare const CLAUDE_OAUTH_URL = "https://api.anthropic.com/api/oauth/usage?cedar_ember=1";
|
|
37
43
|
export declare const CLAUDE_OAUTH_PROFILE_URL = "https://api.anthropic.com/api/oauth/profile";
|
|
38
44
|
export declare const CLAUDE_OAUTH_BETA = "oauth-2025-04-20";
|
|
39
45
|
export declare const CLAUDE_ORG_CACHE_MS: number;
|
|
@@ -251,6 +257,20 @@ export declare function parseClaudeCliVersion(text: string): string | null;
|
|
|
251
257
|
export declare function mapClaudeOAuthUsage(body: unknown, options: MapOptions): {
|
|
252
258
|
readings: ReadingInput[];
|
|
253
259
|
failures: ParserFailureEvent[];
|
|
260
|
+
/** Undefined when the body has no reset block (older server or flag off): leave the last count alone. */
|
|
261
|
+
resetCredits?: RateLimitResetCredits | null;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Map the `cedar_ember` block to banked reset credits. `null` means the server
|
|
265
|
+
* answered with no reset block for this account. One credit row per grant;
|
|
266
|
+
* `remaining` carries how many resets that grant still holds, and
|
|
267
|
+
* `availableCount` sums them. A grant can be scoped: `clears` names the limits it
|
|
268
|
+
* resets (a Fable-only grant clears only that model's weekly limit).
|
|
269
|
+
*/
|
|
270
|
+
export declare function mapClaudeResetGrants(value: unknown): {
|
|
271
|
+
value: RateLimitResetCredits | null;
|
|
272
|
+
} | {
|
|
273
|
+
error: string;
|
|
254
274
|
};
|
|
255
275
|
export declare function collectClaudeOAuth(inputOptions?: CollectClaudeOAuthOptions): Promise<ClaudeOAuthCollectResult>;
|
|
256
276
|
/**
|
|
@@ -266,6 +286,13 @@ export declare function claudeIdentityKeys(root: string): ReadonlyMap<string, st
|
|
|
266
286
|
*/
|
|
267
287
|
export declare function displayOrganization(name: string): string | null;
|
|
268
288
|
export declare function claudeSeatAccountId(seat: string, orgId: string | null): string;
|
|
289
|
+
/**
|
|
290
|
+
* The usage endpoint fills the `cedar_ember` reset block only for a Claude Code
|
|
291
|
+
* client: any other user agent gets `eligible: false, ineligible_reason: "surface"`
|
|
292
|
+
* and no grants. The token is a Claude Code sign-in, so name the installed CLI
|
|
293
|
+
* version the way Claude Code does.
|
|
294
|
+
*/
|
|
295
|
+
export declare function claudeUsageUserAgent(cliVersion: string | undefined): string;
|
|
269
296
|
export declare function readInstalledClaudeVersion(readVersion?: () => string): string;
|
|
270
297
|
/** Async `claude --version` for the daemon. The sync reader stays for one-shot callers. */
|
|
271
298
|
export declare function readInstalledClaudeVersionAsync(): Promise<string>;
|
|
@@ -40,7 +40,13 @@ import { REMOTE_LANE_READ_ENV } from "../../lanes/outpost-dispatch.js";
|
|
|
40
40
|
export const CLAUDE_OAUTH_PARSER_VERSION = "claude-oauth-usage.1";
|
|
41
41
|
export const CLAUDE_OAUTH_PROVIDER = "claude";
|
|
42
42
|
export const CLAUDE_OAUTH_SOURCE = "oauth-usage";
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* `cedar_ember=1` adds the account's banked limit resets (a `cedar_ember` block with
|
|
45
|
+
* `grants[]`) to the usual usage body. Claude Code reads the same block to offer a
|
|
46
|
+
* reset at the limit wall. Without it an account that is at 100% but holds a reset
|
|
47
|
+
* looks used up for the week.
|
|
48
|
+
*/
|
|
49
|
+
export const CLAUDE_OAUTH_URL = "https://api.anthropic.com/api/oauth/usage?cedar_ember=1";
|
|
44
50
|
export const CLAUDE_OAUTH_PROFILE_URL = "https://api.anthropic.com/api/oauth/profile";
|
|
45
51
|
export const CLAUDE_OAUTH_BETA = "oauth-2025-04-20";
|
|
46
52
|
export const CLAUDE_ORG_CACHE_MS = 24 * 60 * 60 * 1000;
|
|
@@ -135,7 +141,81 @@ export function mapClaudeOAuthUsage(body, options) {
|
|
|
135
141
|
else
|
|
136
142
|
readings.push(spend.reading);
|
|
137
143
|
}
|
|
138
|
-
|
|
144
|
+
if (!("cedar_ember" in root))
|
|
145
|
+
return { readings, failures };
|
|
146
|
+
const resets = mapClaudeResetGrants(root.cedar_ember);
|
|
147
|
+
if ("error" in resets) {
|
|
148
|
+
failures.push(failure(options, resets.error));
|
|
149
|
+
return { readings, failures };
|
|
150
|
+
}
|
|
151
|
+
return { readings, failures, resetCredits: resets.value };
|
|
152
|
+
}
|
|
153
|
+
const CLAUDE_RESET_DRIFT = "claude oauth usage field drift: cedar_ember";
|
|
154
|
+
/**
|
|
155
|
+
* Map the `cedar_ember` block to banked reset credits. `null` means the server
|
|
156
|
+
* answered with no reset block for this account. One credit row per grant;
|
|
157
|
+
* `remaining` carries how many resets that grant still holds, and
|
|
158
|
+
* `availableCount` sums them. A grant can be scoped: `clears` names the limits it
|
|
159
|
+
* resets (a Fable-only grant clears only that model's weekly limit).
|
|
160
|
+
*/
|
|
161
|
+
export function mapClaudeResetGrants(value) {
|
|
162
|
+
if (value === null)
|
|
163
|
+
return { value: null };
|
|
164
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
165
|
+
return { error: CLAUDE_RESET_DRIFT };
|
|
166
|
+
const block = value;
|
|
167
|
+
if (block.grants === undefined || block.grants === null)
|
|
168
|
+
return { value: { availableCount: 0, credits: [] } };
|
|
169
|
+
if (!Array.isArray(block.grants))
|
|
170
|
+
return { error: CLAUDE_RESET_DRIFT };
|
|
171
|
+
const credits = [];
|
|
172
|
+
let available = 0;
|
|
173
|
+
for (const raw of block.grants) {
|
|
174
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
175
|
+
return { error: CLAUDE_RESET_DRIFT };
|
|
176
|
+
const grant = raw;
|
|
177
|
+
if (typeof grant.id !== "string" || !grant.id.trim())
|
|
178
|
+
return { error: CLAUDE_RESET_DRIFT };
|
|
179
|
+
const left = grant.resets_left;
|
|
180
|
+
if (typeof left !== "number" || !Number.isInteger(left) || left < 0)
|
|
181
|
+
return { error: CLAUDE_RESET_DRIFT };
|
|
182
|
+
const paused = grant.paused === true;
|
|
183
|
+
const reason = typeof grant.unavailable_reason === "string" && grant.unavailable_reason ? grant.unavailable_reason : null;
|
|
184
|
+
const clears = Array.isArray(grant.clears) ? grant.clears.filter((id) => typeof id === "string") : [];
|
|
185
|
+
available += left;
|
|
186
|
+
credits.push({
|
|
187
|
+
id: grant.id,
|
|
188
|
+
resetType: typeof grant.type === "string" ? grant.type : null,
|
|
189
|
+
status: paused ? "paused" : reason ?? (left > 0 ? "available" : "used"),
|
|
190
|
+
grantedAt: isoToMs(grant.starts_at),
|
|
191
|
+
expiresAt: isoToMs(grant.ends_at),
|
|
192
|
+
title: typeof grant.label === "string" && grant.label.trim() ? grant.label.trim() : null,
|
|
193
|
+
description: null,
|
|
194
|
+
remaining: left,
|
|
195
|
+
usableNow: typeof grant.usable_now === "boolean" ? grant.usable_now : null,
|
|
196
|
+
clears,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return { value: { availableCount: available, credits } };
|
|
200
|
+
}
|
|
201
|
+
function isoToMs(value) {
|
|
202
|
+
if (typeof value !== "string" || !value.trim())
|
|
203
|
+
return null;
|
|
204
|
+
const ms = Date.parse(value);
|
|
205
|
+
return Number.isNaN(ms) ? null : ms;
|
|
206
|
+
}
|
|
207
|
+
function resetMeta(context, credits) {
|
|
208
|
+
const event = {
|
|
209
|
+
event: "provider_meta",
|
|
210
|
+
observedAt: context.observedAt,
|
|
211
|
+
provider: CLAUDE_OAUTH_PROVIDER,
|
|
212
|
+
source: "oauth-usage",
|
|
213
|
+
ordinaryUsageAllowed: null,
|
|
214
|
+
rateLimitResetCredits: credits,
|
|
215
|
+
accountId: context.accountId,
|
|
216
|
+
cliVersion: context.cliVersion,
|
|
217
|
+
};
|
|
218
|
+
return event;
|
|
139
219
|
}
|
|
140
220
|
export async function collectClaudeOAuth(inputOptions = {}) {
|
|
141
221
|
const options = {
|
|
@@ -206,6 +286,7 @@ export async function collectClaudeOAuth(inputOptions = {}) {
|
|
|
206
286
|
const endpoint = options.endpoint ?? CLAUDE_OAUTH_URL;
|
|
207
287
|
const fetchImpl = options.fetchImpl ?? defaultClaudeFetch;
|
|
208
288
|
const readings = [];
|
|
289
|
+
const metas = [];
|
|
209
290
|
const failures = [...loaded.failures];
|
|
210
291
|
const accountIds = [];
|
|
211
292
|
let httpStatus = null;
|
|
@@ -279,7 +360,7 @@ export async function collectClaudeOAuth(inputOptions = {}) {
|
|
|
279
360
|
let text;
|
|
280
361
|
let retryAfter;
|
|
281
362
|
try {
|
|
282
|
-
const response = await fetchImpl(endpoint, usageInit(currentToken));
|
|
363
|
+
const response = await fetchImpl(endpoint, usageInit(currentToken, cliVersion));
|
|
283
364
|
status = response.status;
|
|
284
365
|
retryAfter = response.headers?.get("retry-after") ?? null;
|
|
285
366
|
text = status === 200 ? await response.text() : "";
|
|
@@ -318,6 +399,8 @@ export async function collectClaudeOAuth(inputOptions = {}) {
|
|
|
318
399
|
const mapped = mapClaudeOAuthUsage(parsed, mapContext);
|
|
319
400
|
readings.push(...mapped.readings);
|
|
320
401
|
failures.push(...mapped.failures);
|
|
402
|
+
if (mapped.resetCredits !== undefined)
|
|
403
|
+
metas.push(resetMeta(mapContext, mapped.resetCredits));
|
|
321
404
|
}
|
|
322
405
|
if (!fetched && failures.length === 0) {
|
|
323
406
|
return empty({
|
|
@@ -336,7 +419,7 @@ export async function collectClaudeOAuth(inputOptions = {}) {
|
|
|
336
419
|
accountIds,
|
|
337
420
|
};
|
|
338
421
|
}
|
|
339
|
-
const view = appendReadings(readings, failures,
|
|
422
|
+
const view = appendReadings(readings, failures, metas, scoped);
|
|
340
423
|
return { readings, failures, view, keychain: loaded.keychain, httpStatus, accountIds };
|
|
341
424
|
}
|
|
342
425
|
async function collectEnumeratedClaude(options, scoped, root, clock, cliVersion) {
|
|
@@ -360,6 +443,7 @@ async function collectEnumeratedClaude(options, scoped, root, clock, cliVersion)
|
|
|
360
443
|
const endpoint = options.endpoint ?? CLAUDE_OAUTH_URL;
|
|
361
444
|
const fetchImpl = options.fetchImpl ?? defaultClaudeFetch;
|
|
362
445
|
const readings = [];
|
|
446
|
+
const metas = [];
|
|
363
447
|
const failures = [];
|
|
364
448
|
const accountIds = [];
|
|
365
449
|
let httpStatus = null;
|
|
@@ -455,7 +539,7 @@ async function collectEnumeratedClaude(options, scoped, root, clock, cliVersion)
|
|
|
455
539
|
let text;
|
|
456
540
|
let retryAfter;
|
|
457
541
|
try {
|
|
458
|
-
const response = await fetchImpl(endpoint, usageInit(token));
|
|
542
|
+
const response = await fetchImpl(endpoint, usageInit(token, cliVersion));
|
|
459
543
|
status = response.status;
|
|
460
544
|
retryAfter = response.headers?.get("retry-after") ?? null;
|
|
461
545
|
text = status === 200 ? await response.text() : "";
|
|
@@ -494,6 +578,8 @@ async function collectEnumeratedClaude(options, scoped, root, clock, cliVersion)
|
|
|
494
578
|
const mapped = mapClaudeOAuthUsage(parsed, mapContext);
|
|
495
579
|
readings.push(...mapped.readings);
|
|
496
580
|
failures.push(...mapped.failures);
|
|
581
|
+
if (mapped.resetCredits !== undefined)
|
|
582
|
+
metas.push(resetMeta(mapContext, mapped.resetCredits));
|
|
497
583
|
}
|
|
498
584
|
if (!fetched && failures.length === 0) {
|
|
499
585
|
return {
|
|
@@ -509,7 +595,7 @@ async function collectEnumeratedClaude(options, scoped, root, clock, cliVersion)
|
|
|
509
595
|
if (readings.length === 0 && failures.length === 0) {
|
|
510
596
|
return { readings, failures, view: null, keychain, httpStatus, accountIds };
|
|
511
597
|
}
|
|
512
|
-
const view = appendReadings(readings, failures,
|
|
598
|
+
const view = appendReadings(readings, failures, metas, scoped);
|
|
513
599
|
return { readings, failures, view, keychain, httpStatus, accountIds };
|
|
514
600
|
}
|
|
515
601
|
function groupHomes(accounts) {
|
|
@@ -1066,10 +1152,21 @@ function classifySecurity(result) {
|
|
|
1066
1152
|
return "error";
|
|
1067
1153
|
return "no-prompt";
|
|
1068
1154
|
}
|
|
1069
|
-
|
|
1155
|
+
/**
|
|
1156
|
+
* The usage endpoint fills the `cedar_ember` reset block only for a Claude Code
|
|
1157
|
+
* client: any other user agent gets `eligible: false, ineligible_reason: "surface"`
|
|
1158
|
+
* and no grants. The token is a Claude Code sign-in, so name the installed CLI
|
|
1159
|
+
* version the way Claude Code does.
|
|
1160
|
+
*/
|
|
1161
|
+
export function claudeUsageUserAgent(cliVersion) {
|
|
1162
|
+
const version = cliVersion && /^[0-9][0-9A-Za-z.+-]*$/.test(cliVersion) ? cliVersion : "unknown";
|
|
1163
|
+
return `claude-cli/${version} (external, cli)`;
|
|
1164
|
+
}
|
|
1165
|
+
function usageInit(token, cliVersion) {
|
|
1070
1166
|
return {
|
|
1071
1167
|
method: "GET",
|
|
1072
1168
|
headers: {
|
|
1169
|
+
"User-Agent": claudeUsageUserAgent(cliVersion),
|
|
1073
1170
|
Authorization: `Bearer ${token}`,
|
|
1074
1171
|
"anthropic-beta": CLAUDE_OAUTH_BETA,
|
|
1075
1172
|
Accept: "application/json",
|
|
@@ -15,6 +15,7 @@ import { spawn } from "node:child_process";
|
|
|
15
15
|
import * as fs from "node:fs";
|
|
16
16
|
import * as path from "node:path";
|
|
17
17
|
import { appendReadings, BURN_WINDOW_MS, redactProviderTokens, } from "../ledger.js";
|
|
18
|
+
import { codexHomeAccountRaw } from "../codex-availability.js";
|
|
18
19
|
export const CODEX_PARSER_VERSION = "codex.1";
|
|
19
20
|
export const CODEX_IDLE_MS = 30 * 60 * 1000;
|
|
20
21
|
export const CODEX_APP_SERVER_TIMEOUT_MS = 20_000;
|
|
@@ -123,7 +124,7 @@ export function tailCodexSessions(options) {
|
|
|
123
124
|
const latest = new Map();
|
|
124
125
|
const emittedAt = new Map();
|
|
125
126
|
let bestEventMs = Number.NEGATIVE_INFINITY;
|
|
126
|
-
const accountId = hashAccountId(options.accountId ?? (options.accountHome ?
|
|
127
|
+
const accountId = hashAccountId(options.accountId ?? (options.accountHome ? codexHomeAccountRaw(options.accountHome) : LOCAL_ACCOUNT));
|
|
127
128
|
const consider = (parsed, emit) => {
|
|
128
129
|
if (emit) {
|
|
129
130
|
readings.push(...parsed.readings);
|
|
@@ -208,6 +209,7 @@ export function tailCodexSessions(options) {
|
|
|
208
209
|
export function mapCodexAppServerBody(body, options) {
|
|
209
210
|
const now = options.now ?? new Date();
|
|
210
211
|
const observedAt = now.toISOString();
|
|
212
|
+
const homeAccount = options.accountId ?? (options.accountHome ? codexHomeAccountRaw(options.accountHome) : null);
|
|
211
213
|
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
212
214
|
return {
|
|
213
215
|
readings: [],
|
|
@@ -215,16 +217,17 @@ export function mapCodexAppServerBody(body, options) {
|
|
|
215
217
|
observedAt,
|
|
216
218
|
source: "codex-app-server",
|
|
217
219
|
cliVersion: options.cliVersion,
|
|
218
|
-
accountId: hashAccountId(
|
|
220
|
+
accountId: hashAccountId(homeAccount ?? LOCAL_ACCOUNT),
|
|
219
221
|
error: "codex app-server rate limit payload drifted",
|
|
220
222
|
})],
|
|
221
223
|
providerMeta: null,
|
|
222
224
|
};
|
|
223
225
|
}
|
|
224
226
|
const record = body;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
// One home is one account id on every Codex path. The provider's own id is
|
|
228
|
+
// used only when no home is known, as on the JSONL path.
|
|
229
|
+
const rawAccount = homeAccount
|
|
230
|
+
?? (typeof record.accountId === "string" && record.accountId.trim() ? record.accountId : LOCAL_ACCOUNT);
|
|
228
231
|
const accountId = hashAccountId(rawAccount);
|
|
229
232
|
const mapped = mapRateLimitCarrier(record, {
|
|
230
233
|
source: "codex-app-server",
|
|
@@ -271,7 +274,7 @@ export function mapCodexAppServerBody(body, options) {
|
|
|
271
274
|
}
|
|
272
275
|
export async function readCodexAppServer(options) {
|
|
273
276
|
const timeoutMs = options.timeoutMs ?? CODEX_APP_SERVER_TIMEOUT_MS;
|
|
274
|
-
const accountId = options.accountId ?? (options.home ?
|
|
277
|
+
const accountId = options.accountId ?? (options.home ? codexHomeAccountRaw(options.home) : undefined);
|
|
275
278
|
const spawnImpl = options.spawn ?? defaultCodexSpawn;
|
|
276
279
|
const command = options.command ?? "codex";
|
|
277
280
|
let child = null;
|
|
@@ -320,7 +323,7 @@ export function ingestCodexResult(result, options) {
|
|
|
320
323
|
return appendReadings(result.readings, result.failures, meta, options);
|
|
321
324
|
}
|
|
322
325
|
function transportFailure(reason, options) {
|
|
323
|
-
const raw = options?.accountId ?? (options?.home ?
|
|
326
|
+
const raw = options?.accountId ?? (options?.home ? codexHomeAccountRaw(options.home) : undefined);
|
|
324
327
|
const failures = [];
|
|
325
328
|
if (raw && options?.cliVersion) {
|
|
326
329
|
failures.push(failureEvent({
|
|
@@ -104,6 +104,12 @@ export interface RateLimitResetCredit {
|
|
|
104
104
|
expiresAt: number | null;
|
|
105
105
|
title: string | null;
|
|
106
106
|
description: string | null;
|
|
107
|
+
/** Resets left on this grant. Absent on Codex credits, which count one each. */
|
|
108
|
+
remaining?: number | null;
|
|
109
|
+
/** False when the grant is paused or blocked right now. */
|
|
110
|
+
usableNow?: boolean | null;
|
|
111
|
+
/** Provider limit ids the reset clears (Claude: five_hour, seven_day, seven_day_<model>). */
|
|
112
|
+
clears?: string[];
|
|
107
113
|
}
|
|
108
114
|
export interface RateLimitResetCredits {
|
|
109
115
|
availableCount: number | null;
|
|
@@ -175,6 +181,8 @@ export interface NowAccount {
|
|
|
175
181
|
* drift, HTTP error), absent once a later reading from the account lands.
|
|
176
182
|
*/
|
|
177
183
|
lastError?: string;
|
|
184
|
+
/** Banked resets this account can spend to clear a limit early. Absent when never read. */
|
|
185
|
+
rateLimitResetCredits?: RateLimitResetCredits | null;
|
|
178
186
|
limits: NowLimit[];
|
|
179
187
|
}
|
|
180
188
|
export interface NowProvider {
|
|
@@ -188,10 +196,16 @@ export interface NowProvider {
|
|
|
188
196
|
/** Present when a reading or signed-out failure named an account. */
|
|
189
197
|
accounts?: NowAccount[];
|
|
190
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Set by a rebuild that writes one reading per login. A view without it came
|
|
201
|
+
* from an older hq process, which restores the two-id split.
|
|
202
|
+
*/
|
|
203
|
+
export declare const CAPACITY_VIEW_REVISION = 2;
|
|
191
204
|
export interface NowView {
|
|
192
205
|
machineId: string;
|
|
193
206
|
hqCliVersion: string;
|
|
194
207
|
generatedAt: string;
|
|
208
|
+
viewRevision?: number;
|
|
195
209
|
providers: NowProvider[];
|
|
196
210
|
}
|
|
197
211
|
/** On/off mark for the resident collector. The directory alone is not the mark. */
|
|
@@ -326,6 +340,9 @@ export declare const nowViewJsonSchema: {
|
|
|
326
340
|
readonly generatedAt: {
|
|
327
341
|
readonly type: "string";
|
|
328
342
|
};
|
|
343
|
+
readonly viewRevision: {
|
|
344
|
+
readonly type: "number";
|
|
345
|
+
};
|
|
329
346
|
readonly providers: {
|
|
330
347
|
readonly type: "array";
|
|
331
348
|
readonly items: {
|
|
@@ -399,14 +416,33 @@ export declare function appendReading(input: ReadingInput, options?: LedgerOptio
|
|
|
399
416
|
* Write every reading, parser failure, and optional provider meta, then
|
|
400
417
|
* rebuild now.json once. appendReading stays the single-reading path.
|
|
401
418
|
*/
|
|
402
|
-
export declare function appendReadings(readings: readonly ReadingInput[], failures?: readonly ParserFailureEvent[], meta?: ProviderMetaEvent | null, options?: LedgerOptions): NowView;
|
|
419
|
+
export declare function appendReadings(readings: readonly ReadingInput[], failures?: readonly ParserFailureEvent[], meta?: ProviderMetaEvent | readonly ProviderMetaEvent[] | null, options?: LedgerOptions): NowView;
|
|
403
420
|
export declare function appendParserFailure(input: ParserFailureEvent, options?: LedgerOptions): NowView;
|
|
404
421
|
export declare function appendProviderMeta(input: ProviderMetaEvent, options?: LedgerOptions): NowView;
|
|
405
422
|
export declare function readNow(options?: LedgerOptions): NowView;
|
|
423
|
+
/**
|
|
424
|
+
* readNow for anything that routes. A view an older hq process wrote is rebuilt
|
|
425
|
+
* from the events first. With no events, or a busy lock, the view is returned as
|
|
426
|
+
* it stands.
|
|
427
|
+
*/
|
|
428
|
+
export declare function readCurrentNow(options?: LedgerOptions): NowView;
|
|
406
429
|
export declare function readLedgerEvents(options?: LedgerOptions): LedgerEvent[];
|
|
407
430
|
export declare function readCollectorMark(options?: LedgerOptions): CollectorMark | null;
|
|
408
431
|
export declare function setCollectorEnabled(enabled: boolean, options?: LedgerOptions): CollectorMark;
|
|
409
432
|
export declare function rebuildNow(options?: LedgerOptions): NowView;
|
|
433
|
+
/**
|
|
434
|
+
* The newest refusal already on file for a limit, under any of a login's ids,
|
|
435
|
+
* from the last two event files. A hold that has ended is gone from now.json, so
|
|
436
|
+
* this is how a repeat refusal is told from a first one.
|
|
437
|
+
*/
|
|
438
|
+
export declare function latestRefusalOnFile(input: {
|
|
439
|
+
provider: string;
|
|
440
|
+
accountIds: readonly string[];
|
|
441
|
+
limitId: string;
|
|
442
|
+
}, options?: LedgerOptions): {
|
|
443
|
+
observedAt: string;
|
|
444
|
+
resetsAt: string | null;
|
|
445
|
+
} | null;
|
|
410
446
|
/** Newest uncleared parse or HTTP error among these accounts. */
|
|
411
447
|
export declare function newestAccountError(accounts: readonly NowAccount[]): string | null;
|
|
412
448
|
//# sourceMappingURL=ledger.d.ts.map
|