@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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A refusal is a hold of its own, on its own limit row. It never replaces the
|
|
3
|
+
* reading of a real limit, so when it ends the account is back on its last real
|
|
4
|
+
* reading, with that reading's percent and reset.
|
|
5
|
+
*
|
|
6
|
+
* Holds carry `limitId` `refusal:<window>`. The window says only what the
|
|
7
|
+
* provider's refusal said: a session limit, the weekly limit, one model, a usage
|
|
8
|
+
* limit that named no window, or a short rate limit.
|
|
9
|
+
*/
|
|
10
|
+
import type { NowLimit } from "./ledger.js";
|
|
11
|
+
export declare const REFUSAL_LIMIT_PREFIX = "refusal:";
|
|
12
|
+
/** Scope of a hold whose window the refusal did not name. */
|
|
13
|
+
export declare const REFUSAL_SCOPE_USAGE = "usage";
|
|
14
|
+
/** Scope of a hold for a short rate limit, which says nothing about the plan. */
|
|
15
|
+
export declare const REFUSAL_SCOPE_RATE_LIMIT = "rate_limit";
|
|
16
|
+
export declare function isRefusalHold(limit: Pick<NowLimit, "limitId" | "source">): boolean;
|
|
17
|
+
export declare function isRateLimitHold(limit: Pick<NowLimit, "limitId" | "source" | "scope">): boolean;
|
|
18
|
+
/** The hold's time is up. A row with no reset never counts as ended here. */
|
|
19
|
+
export declare function refusalEnded(limit: Pick<NowLimit, "limitId" | "source" | "resetsAt">, nowMs: number): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Holds still in force, for rows that all belong to one login, under any of its
|
|
22
|
+
* ids: after a login change a hold can sit on the old id while the live id reads.
|
|
23
|
+
*
|
|
24
|
+
* A newer real reading below 100% of the limit the hold is about ends it. A
|
|
25
|
+
* reading stamped ahead of now is clock skew and proves nothing yet. A rate limit
|
|
26
|
+
* is not about the plan, so a usage reading cannot end it: only its short time does.
|
|
27
|
+
*/
|
|
28
|
+
export declare function holdsInForce(limits: readonly NowLimit[], nowMs: number): NowLimit[];
|
|
29
|
+
/** The same check before ids are clustered into logins: each id on its own. */
|
|
30
|
+
export declare function holdsInForceById(limits: readonly NowLimit[], nowMs: number): NowLimit[];
|
|
31
|
+
//# sourceMappingURL=refusal-rows.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const REFUSAL_LIMIT_PREFIX = "refusal:";
|
|
2
|
+
/** Scope of a hold whose window the refusal did not name. */
|
|
3
|
+
export const REFUSAL_SCOPE_USAGE = "usage";
|
|
4
|
+
/** Scope of a hold for a short rate limit, which says nothing about the plan. */
|
|
5
|
+
export const REFUSAL_SCOPE_RATE_LIMIT = "rate_limit";
|
|
6
|
+
export function isRefusalHold(limit) {
|
|
7
|
+
return limit.source === "refusal" && limit.limitId.startsWith(REFUSAL_LIMIT_PREFIX);
|
|
8
|
+
}
|
|
9
|
+
export function isRateLimitHold(limit) {
|
|
10
|
+
return isRefusalHold(limit) && limit.scope === REFUSAL_SCOPE_RATE_LIMIT;
|
|
11
|
+
}
|
|
12
|
+
/** The hold's time is up. A row with no reset never counts as ended here. */
|
|
13
|
+
export function refusalEnded(limit, nowMs) {
|
|
14
|
+
if (!isRefusalHold(limit) || !limit.resetsAt)
|
|
15
|
+
return false;
|
|
16
|
+
const at = Date.parse(limit.resetsAt);
|
|
17
|
+
return Number.isFinite(at) && at <= nowMs;
|
|
18
|
+
}
|
|
19
|
+
function readingAnswers(hold, reading) {
|
|
20
|
+
if (hold.kind === "session")
|
|
21
|
+
return reading.kind === "session";
|
|
22
|
+
if (hold.kind === "weekly_all")
|
|
23
|
+
return reading.kind === "weekly_all";
|
|
24
|
+
if (hold.kind === "weekly_scoped") {
|
|
25
|
+
return reading.kind === "weekly_scoped"
|
|
26
|
+
&& (reading.scope ?? "").toLowerCase() === (hold.scope ?? "").toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
return reading.kind === "session" || reading.kind === "weekly_all";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Holds still in force, for rows that all belong to one login, under any of its
|
|
32
|
+
* ids: after a login change a hold can sit on the old id while the live id reads.
|
|
33
|
+
*
|
|
34
|
+
* A newer real reading below 100% of the limit the hold is about ends it. A
|
|
35
|
+
* reading stamped ahead of now is clock skew and proves nothing yet. A rate limit
|
|
36
|
+
* is not about the plan, so a usage reading cannot end it: only its short time does.
|
|
37
|
+
*/
|
|
38
|
+
export function holdsInForce(limits, nowMs) {
|
|
39
|
+
return limits.filter((hold) => {
|
|
40
|
+
if (!isRefusalHold(hold) || isRateLimitHold(hold))
|
|
41
|
+
return true;
|
|
42
|
+
const at = Date.parse(hold.observedAt);
|
|
43
|
+
return !limits.some((reading) => {
|
|
44
|
+
if (isRefusalHold(reading) || !readingAnswers(hold, reading))
|
|
45
|
+
return false;
|
|
46
|
+
if (typeof reading.usedPercent !== "number" || reading.usedPercent >= 100)
|
|
47
|
+
return false;
|
|
48
|
+
const readAt = Date.parse(reading.observedAt);
|
|
49
|
+
return readAt > at && !(readAt > nowMs);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** The same check before ids are clustered into logins: each id on its own. */
|
|
54
|
+
export function holdsInForceById(limits, nowMs) {
|
|
55
|
+
const byId = new Map();
|
|
56
|
+
for (const limit of limits)
|
|
57
|
+
byId.set(limit.accountId, [...(byId.get(limit.accountId) ?? []), limit]);
|
|
58
|
+
const kept = new Set([...byId.values()].flatMap((rows) => holdsInForce(rows, nowMs)));
|
|
59
|
+
return limits.filter((limit) => kept.has(limit));
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=refusal-rows.js.map
|
|
@@ -2,17 +2,41 @@ import { type LedgerOptions, type NowLimit } from "./ledger.js";
|
|
|
2
2
|
export declare const REFUSAL_PROVIDERS: readonly ["claude", "codex", "grok"];
|
|
3
3
|
export type RefusalProvider = (typeof REFUSAL_PROVIDERS)[number];
|
|
4
4
|
export declare const REFUSAL_PARSER_VERSION = "capacity-refusal.1";
|
|
5
|
-
export declare const REFUSAL_DEFAULT_LIMIT_ID = "weekly";
|
|
6
5
|
export declare const REFUSAL_HELP: string;
|
|
7
6
|
export declare class CapacityUsageError extends Error {
|
|
8
7
|
readonly exitCode: 2;
|
|
9
8
|
constructor(message: string);
|
|
10
9
|
}
|
|
10
|
+
/** What a refusal says it is about, and nothing more. */
|
|
11
|
+
export type RefusalWindow = {
|
|
12
|
+
kind: "session";
|
|
13
|
+
} | {
|
|
14
|
+
kind: "weekly";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "model";
|
|
17
|
+
model: string;
|
|
18
|
+
}
|
|
19
|
+
/** A usage limit that named no window. It must not claim to be weekly. */
|
|
20
|
+
| {
|
|
21
|
+
kind: "usage";
|
|
22
|
+
} | {
|
|
23
|
+
kind: "rate_limit";
|
|
24
|
+
};
|
|
11
25
|
export interface IngestRefusalInput {
|
|
12
26
|
provider?: string;
|
|
13
27
|
limitId?: string;
|
|
14
28
|
resetsAt?: string;
|
|
15
29
|
accountId?: string;
|
|
30
|
+
window?: RefusalWindow;
|
|
31
|
+
/** How long a hold lasts when nothing says when it ends. */
|
|
32
|
+
holdMs?: number;
|
|
33
|
+
/** Copied onto the reading, so the account keeps its row with no other reading. */
|
|
34
|
+
account?: {
|
|
35
|
+
labels: readonly string[];
|
|
36
|
+
home: string | null;
|
|
37
|
+
};
|
|
38
|
+
/** Wait this long and rebuild once more when a rebuild in progress holds the lock. */
|
|
39
|
+
busyRetryMs?: number;
|
|
16
40
|
}
|
|
17
41
|
export interface RefusalRecord {
|
|
18
42
|
provider: RefusalProvider;
|
|
@@ -21,10 +45,37 @@ export interface RefusalRecord {
|
|
|
21
45
|
source: "refusal";
|
|
22
46
|
confidence: "inferred";
|
|
23
47
|
observedAt: string;
|
|
24
|
-
|
|
48
|
+
/** False when the hold ended as it was recorded: its reset is past, or a reading already answers it. */
|
|
49
|
+
inForce: boolean;
|
|
50
|
+
/** The hold's state, or null when it is not in force. */
|
|
51
|
+
state: NowLimit["state"] | null;
|
|
25
52
|
resetsAt: string | null;
|
|
26
53
|
readingId: string;
|
|
27
54
|
usedPercent: number | null;
|
|
28
55
|
}
|
|
29
56
|
export declare function ingestRefusal(input: IngestRefusalInput, options?: LedgerOptions): RefusalRecord;
|
|
57
|
+
export type RefusalLog = (level: "info" | "warn" | "error", message: string) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Record a real refusal against the account on a provider home. For callers in
|
|
60
|
+
* the middle of other work, so it never throws. It writes nothing unless exactly
|
|
61
|
+
* one account in the ledger uses that home: a bot's own login, or a home the
|
|
62
|
+
* ledger has not read, is not some other account's refusal. A failed write is
|
|
63
|
+
* logged and returns null.
|
|
64
|
+
*/
|
|
65
|
+
export declare function recordRefusalForHome(input: {
|
|
66
|
+
provider: string;
|
|
67
|
+
home: string;
|
|
68
|
+
window: RefusalWindow;
|
|
69
|
+
/** Used only when it parses to a time ahead of now. */
|
|
70
|
+
resetsAt?: string | null;
|
|
71
|
+
holdMs?: number;
|
|
72
|
+
log?: RefusalLog;
|
|
73
|
+
}, env?: NodeJS.ProcessEnv): RefusalRecord | null;
|
|
74
|
+
export declare function recordUsageLimitRefusal(input: {
|
|
75
|
+
provider: string;
|
|
76
|
+
turnEnv: NodeJS.ProcessEnv;
|
|
77
|
+
text: string;
|
|
78
|
+
hqRoot?: string;
|
|
79
|
+
log?: RefusalLog;
|
|
80
|
+
}, env?: NodeJS.ProcessEnv): RefusalRecord | null;
|
|
30
81
|
//# sourceMappingURL=refusal.d.ts.map
|
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `hq capacity ingest refusal` — one inferred
|
|
3
|
-
* now.json rebuild. No network and no provider call.
|
|
2
|
+
* `hq capacity ingest refusal` — one inferred hold, on a limit row of its own
|
|
3
|
+
* (refusal-rows.ts), then one now.json rebuild. No network and no provider call.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* reading below 100% replaces the inference before that reset.
|
|
5
|
+
* The hold never replaces a real reading. It ends at its reset, or sooner when a
|
|
6
|
+
* newer reading of the limit it is about is below 100%.
|
|
8
7
|
*/
|
|
9
8
|
import { createHash } from "node:crypto";
|
|
10
|
-
import
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as os from "node:os";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import { usageLimitWindow } from "../bot/runtime-failure.js";
|
|
13
|
+
import { PROVIDER_HOME_ENV } from "../lanes/provider-home.js";
|
|
14
|
+
import { loadLanesConfig, providerQuotaDefaultHoldMs } from "../lanes/config.js";
|
|
15
|
+
import { resolveLanesHqRoot } from "../lanes/hq-root.js";
|
|
16
|
+
import { parseProviderResetTime } from "../lanes/quota.js";
|
|
17
|
+
import { REFUSAL_LIMIT_PREFIX, REFUSAL_SCOPE_RATE_LIMIT, REFUSAL_SCOPE_USAGE, isRefusalHold } from "./refusal-rows.js";
|
|
18
|
+
import { defaultProviderHome } from "./accounts.js";
|
|
19
|
+
import { LedgerCorrupt, LedgerMissing, PROVIDER_TOKEN_LEAK, latestRefusalOnFile, appendReading, readNow, rebuildNow, } from "./ledger.js";
|
|
20
|
+
import { LedgerBusy, capacityOptionsFromEnv, redactProviderTokens } from "./ledger.js";
|
|
11
21
|
export const REFUSAL_PROVIDERS = ["claude", "codex", "grok"];
|
|
12
22
|
export const REFUSAL_PARSER_VERSION = "capacity-refusal.1";
|
|
13
|
-
export const REFUSAL_DEFAULT_LIMIT_ID = "weekly";
|
|
14
23
|
export const REFUSAL_HELP = [
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
24
|
+
"A model-CLI bot's turn, hq bot probe and the lane failure path record their",
|
|
25
|
+
"own refusals. Run this by hand only for a provider failure that was classified",
|
|
26
|
+
"as a rate-limit refusal (policy",
|
|
27
|
+
"indigo-provider-failures-classified-not-masked-as-timeout), never for a",
|
|
28
|
+
"timeout that was not:",
|
|
19
29
|
"",
|
|
20
|
-
" hq capacity ingest refusal --provider <claude|codex|grok> [--limit-id <id>] [--resets-at <iso|epoch>]
|
|
30
|
+
" hq capacity ingest refusal --provider <claude|codex|grok> --account <hash> [--limit-id <id>] [--resets-at <iso|epoch>]",
|
|
21
31
|
"",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
32
|
+
"--account is required unless --limit-id names a limit that exactly one account",
|
|
33
|
+
"has. A limit id that several accounts share, or neither flag, is a usage error:",
|
|
34
|
+
"nothing is recorded against a guess, even when the provider has one account.",
|
|
35
|
+
"The refusal is a hold beside the account's readings, and never replaces one.",
|
|
36
|
+
"--limit-id names the limit it is about; without it the refusal claims no",
|
|
37
|
+
"window. The hold ends at --resets-at, at that limit's own reset, or after a",
|
|
38
|
+
"short default, or sooner when a newer reading of that limit is below 100%.",
|
|
25
39
|
].join("\n");
|
|
26
40
|
export class CapacityUsageError extends Error {
|
|
27
41
|
exitCode = 2;
|
|
@@ -36,42 +50,217 @@ export function ingestRefusal(input, options) {
|
|
|
36
50
|
const resetArg = input.resetsAt === undefined ? undefined : parseReset(input.resetsAt);
|
|
37
51
|
const limitArg = optionalTokenFree(input.limitId, "--limit-id must be a non-empty id");
|
|
38
52
|
const view = loadView(options);
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
53
|
+
const accountId = accountArg ?? resolveRefusalAccount(view, provider, limitArg);
|
|
54
|
+
const limits = (view?.providers.find((entry) => entry.provider === provider)?.limits ?? [])
|
|
55
|
+
.filter((limit) => limit.accountId === accountId && !isRefusalHold(limit));
|
|
56
|
+
const named = limitArg ? limits.find((limit) => limit.limitId === limitArg) : undefined;
|
|
57
|
+
const window = input.window ?? (named ? windowOfLimit(named) : { kind: "usage" });
|
|
42
58
|
const now = options?.now ? options.now() : new Date();
|
|
43
59
|
const observedAt = now.toISOString();
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
limitId,
|
|
49
|
-
observedAt,
|
|
50
|
-
resetsAt,
|
|
51
|
-
matched,
|
|
52
|
-
});
|
|
53
|
-
const rebuilt = appendReading(reading, options);
|
|
60
|
+
const real = limits.find((limit) => limitMatchesWindow(limit, window));
|
|
61
|
+
const resetsAt = resolveRefusalReset(resetArg, real?.resetsAt, now, input.holdMs);
|
|
62
|
+
const reading = buildReading({ provider, accountId, window, observedAt, resetsAt, real, account: input.account });
|
|
63
|
+
const rebuilt = appendThenRebuild(reading, input.busyRetryMs, options);
|
|
54
64
|
const row = rebuilt.providers
|
|
55
65
|
.find((entry) => entry.provider === provider)
|
|
56
|
-
?.limits.find((limit) => limit.
|
|
57
|
-
if (!row)
|
|
58
|
-
throw new Error("refusal reading was not materialized");
|
|
66
|
+
?.limits.find((limit) => limit.readingId === reading.readingId);
|
|
59
67
|
return {
|
|
60
68
|
provider,
|
|
61
69
|
accountId,
|
|
62
|
-
limitId,
|
|
70
|
+
limitId: reading.limit.limitId,
|
|
63
71
|
source: "refusal",
|
|
64
72
|
confidence: "inferred",
|
|
65
73
|
observedAt,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
inForce: row !== undefined,
|
|
75
|
+
state: row?.state ?? null,
|
|
76
|
+
resetsAt: row?.resetsAt ?? resetsAt,
|
|
77
|
+
readingId: reading.readingId,
|
|
78
|
+
usedPercent: null,
|
|
70
79
|
};
|
|
71
80
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
/** Busy is only ever the rebuild: the event line is on disk by then, so a retry rebuilds and does not append again. */
|
|
82
|
+
function appendThenRebuild(reading, busyRetryMs, options) {
|
|
83
|
+
try {
|
|
84
|
+
return appendReading(reading, options);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (!(err instanceof LedgerBusy) || !busyRetryMs)
|
|
88
|
+
throw err;
|
|
89
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, busyRetryMs);
|
|
90
|
+
return rebuildNow(options);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function windowOfLimit(limit) {
|
|
94
|
+
if (limit.kind === "session")
|
|
95
|
+
return { kind: "session" };
|
|
96
|
+
if (limit.kind === "weekly_all")
|
|
97
|
+
return { kind: "weekly" };
|
|
98
|
+
if (limit.kind === "weekly_scoped" && limit.scope)
|
|
99
|
+
return { kind: "model", model: limit.scope };
|
|
100
|
+
return { kind: "usage" };
|
|
101
|
+
}
|
|
102
|
+
function limitMatchesWindow(limit, window) {
|
|
103
|
+
if (window.kind === "session")
|
|
104
|
+
return limit.kind === "session";
|
|
105
|
+
if (window.kind === "weekly")
|
|
106
|
+
return limit.kind === "weekly_all";
|
|
107
|
+
if (window.kind === "model") {
|
|
108
|
+
return limit.kind === "weekly_scoped" && (limit.scope ?? "").toLowerCase() === window.model.toLowerCase();
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const defaultRefusalLog = (level, message) => {
|
|
113
|
+
if (level === "info")
|
|
114
|
+
return;
|
|
115
|
+
process.stderr.write(`hq capacity: ${message}\n`);
|
|
116
|
+
};
|
|
117
|
+
const BUSY_RETRY_MS = 250;
|
|
118
|
+
const REPEAT_REFUSAL_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
119
|
+
/**
|
|
120
|
+
* Record a real refusal against the account on a provider home. For callers in
|
|
121
|
+
* the middle of other work, so it never throws. It writes nothing unless exactly
|
|
122
|
+
* one account in the ledger uses that home: a bot's own login, or a home the
|
|
123
|
+
* ledger has not read, is not some other account's refusal. A failed write is
|
|
124
|
+
* logged and returns null.
|
|
125
|
+
*/
|
|
126
|
+
export function recordRefusalForHome(input, env = process.env) {
|
|
127
|
+
// A test that did not point at a fixture ledger must not write the real one.
|
|
128
|
+
if (env.VITEST && !env.HQ_CAPACITY_ROOT?.trim())
|
|
129
|
+
return null;
|
|
130
|
+
const log = input.log ?? defaultRefusalLog;
|
|
131
|
+
try {
|
|
132
|
+
const provider = requireProvider(input.provider);
|
|
133
|
+
const options = capacityOptionsFromEnv(env);
|
|
134
|
+
let view;
|
|
135
|
+
try {
|
|
136
|
+
view = readNow(options);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
if (!(err instanceof LedgerMissing))
|
|
140
|
+
throw err;
|
|
141
|
+
log("info", `refusal not recorded for ${provider}: no capacity ledger on this computer`);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const wanted = realHome(input.home);
|
|
145
|
+
const accounts = (view.providers.find((entry) => entry.provider === provider)?.accounts ?? [])
|
|
146
|
+
.filter((account) => account.homes.some((home) => realHome(home) === wanted));
|
|
147
|
+
if (accounts.length !== 1) {
|
|
148
|
+
log("info", `refusal not recorded for ${provider}: ${accounts.length} ledger accounts use this login's home`);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const account = accounts[0];
|
|
152
|
+
const now = options.now ? options.now() : new Date();
|
|
153
|
+
const parsed = input.resetsAt ? Date.parse(input.resetsAt) : Number.NaN;
|
|
154
|
+
const named = Number.isFinite(parsed) && parsed > now.getTime() ? parsed : null;
|
|
155
|
+
const until = input.window.kind === "usage"
|
|
156
|
+
? unnamedRefusalEnd({ provider, account, named, holdMs: input.holdMs, now, options })
|
|
157
|
+
: named;
|
|
158
|
+
return ingestRefusal({
|
|
159
|
+
provider,
|
|
160
|
+
accountId: account.accountId,
|
|
161
|
+
window: input.window,
|
|
162
|
+
...(until !== null ? { resetsAt: new Date(until).toISOString() } : {}),
|
|
163
|
+
...(input.holdMs !== undefined ? { holdMs: input.holdMs } : {}),
|
|
164
|
+
account: { labels: account.labels, home: input.home },
|
|
165
|
+
busyRetryMs: BUSY_RETRY_MS,
|
|
166
|
+
}, options);
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
if (err instanceof LedgerBusy) {
|
|
170
|
+
log("warn", `refusal for ${input.provider} saved, but capacity is behind until its next rebuild: the ledger stayed busy`);
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
log("error", `refusal not recorded for ${input.provider}: ${redactProviderTokens(err instanceof Error ? err.message : String(err))}`);
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Record a usage-limit refusal from the tool's own words, for the login its turn
|
|
179
|
+
* really ran on: the turn's home variable, or the provider's default home.
|
|
180
|
+
*/
|
|
181
|
+
/**
|
|
182
|
+
* One refusal that names no window may be about the wrong subscription (incident
|
|
183
|
+
* 2026-10-13, held the only account for three days), so it gets the short hold
|
|
184
|
+
* even when the tool quotes a far reset. The same rule as applyDefaultQuotaHold
|
|
185
|
+
* and recordAccountQuota: a repeat after that hold lapsed goes to the provider's
|
|
186
|
+
* reset. A second refusal while the hold is live is the same strike, and neither
|
|
187
|
+
* promotes the hold nor shortens it.
|
|
188
|
+
*/
|
|
189
|
+
function unnamedRefusalEnd(input) {
|
|
190
|
+
const { account, named, now } = input;
|
|
191
|
+
const nowMs = now.getTime();
|
|
192
|
+
const limitId = `${REFUSAL_LIMIT_PREFIX}${REFUSAL_SCOPE_USAGE}`;
|
|
193
|
+
const shortEnd = nowMs + (input.holdMs ?? REFUSAL_DEFAULT_TTL_MS);
|
|
194
|
+
const live = account.limits.find((limit) => limit.limitId === limitId && isRefusalHold(limit));
|
|
195
|
+
const liveEnd = live?.resetsAt ? Date.parse(live.resetsAt) : Number.NaN;
|
|
196
|
+
if (Number.isFinite(liveEnd) && liveEnd > nowMs) {
|
|
197
|
+
return Math.max(liveEnd, named !== null && named <= shortEnd ? named : shortEnd);
|
|
198
|
+
}
|
|
199
|
+
if (named === null)
|
|
200
|
+
return null;
|
|
201
|
+
if (named <= shortEnd)
|
|
202
|
+
return named;
|
|
203
|
+
const prior = latestRefusalOnFile({
|
|
204
|
+
provider: input.provider,
|
|
205
|
+
accountIds: [...new Set([account.accountId, ...account.limits.map((limit) => limit.accountId)])],
|
|
206
|
+
limitId,
|
|
207
|
+
}, input.options);
|
|
208
|
+
const priorEnd = prior?.resetsAt ? Date.parse(prior.resetsAt) : Number.NaN;
|
|
209
|
+
const lapsedLately = prior !== null
|
|
210
|
+
&& nowMs - Date.parse(prior.observedAt) <= REPEAT_REFUSAL_WINDOW_MS
|
|
211
|
+
&& Number.isFinite(priorEnd) && priorEnd <= nowMs;
|
|
212
|
+
return lapsedLately ? named : null;
|
|
213
|
+
}
|
|
214
|
+
/** The provider's configured hold, so a bot or probe holds as long as a lane does. */
|
|
215
|
+
function configuredHoldMs(provider, hqRoot, env, log) {
|
|
216
|
+
try {
|
|
217
|
+
const config = loadLanesConfig(hqRoot ?? resolveLanesHqRoot({ env })).providers[provider];
|
|
218
|
+
return config ? providerQuotaDefaultHoldMs(config) : undefined;
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
log("warn", `using the default refusal hold for ${provider}: ${redactProviderTokens(err instanceof Error ? err.message : String(err))}`);
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export function recordUsageLimitRefusal(input, env = process.env) {
|
|
226
|
+
const log = input.log ?? defaultRefusalLog;
|
|
227
|
+
try {
|
|
228
|
+
if (!REFUSAL_PROVIDERS.includes(input.provider))
|
|
229
|
+
return null;
|
|
230
|
+
const provider = input.provider;
|
|
231
|
+
const home = input.turnEnv[PROVIDER_HOME_ENV[provider]]?.trim()
|
|
232
|
+
|| defaultProviderHome(provider, input.turnEnv.HOME?.trim() || os.homedir());
|
|
233
|
+
const now = capacityOptionsFromEnv(env).now?.() ?? new Date();
|
|
234
|
+
return recordRefusalForHome({
|
|
235
|
+
provider,
|
|
236
|
+
home,
|
|
237
|
+
window: usageLimitWindow(input.text),
|
|
238
|
+
resetsAt: parseProviderResetTime(input.text, now),
|
|
239
|
+
holdMs: configuredHoldMs(provider, input.hqRoot, env, log),
|
|
240
|
+
log,
|
|
241
|
+
}, env);
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
log("error", `refusal not recorded for ${input.provider}: ${redactProviderTokens(err instanceof Error ? err.message : String(err))}`);
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function realHome(home) {
|
|
249
|
+
const resolved = path.resolve(home);
|
|
250
|
+
try {
|
|
251
|
+
return fs.realpathSync(resolved);
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
return resolved;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/** Fifteen minutes, the same default a lane's own hold uses. */
|
|
258
|
+
const REFUSAL_DEFAULT_TTL_MS = 15 * 60 * 1000;
|
|
259
|
+
/**
|
|
260
|
+
* An explicit reset wins. Otherwise the hold ends at the reset of the real limit
|
|
261
|
+
* the refusal named, when that is ahead. With neither, it is short.
|
|
262
|
+
*/
|
|
263
|
+
function resolveRefusalReset(explicit, inherited, now, holdMs) {
|
|
75
264
|
if (explicit !== undefined)
|
|
76
265
|
return explicit;
|
|
77
266
|
if (inherited) {
|
|
@@ -79,7 +268,7 @@ function resolveRefusalReset(explicit, inherited, now) {
|
|
|
79
268
|
if (!Number.isNaN(at) && at > now.getTime())
|
|
80
269
|
return inherited;
|
|
81
270
|
}
|
|
82
|
-
return new Date(now.getTime() + REFUSAL_DEFAULT_TTL_MS).toISOString();
|
|
271
|
+
return new Date(now.getTime() + (holdMs ?? REFUSAL_DEFAULT_TTL_MS)).toISOString();
|
|
83
272
|
}
|
|
84
273
|
function requireProvider(value) {
|
|
85
274
|
const provider = value?.trim() ?? "";
|
|
@@ -134,44 +323,74 @@ function loadView(options) {
|
|
|
134
323
|
throw err;
|
|
135
324
|
}
|
|
136
325
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
326
|
+
/**
|
|
327
|
+
* The account a refusal lands on when `--account` is omitted. Only a
|
|
328
|
+
* `--limit-id` that exactly one account has names it. The provider having one
|
|
329
|
+
* account is not enough: the refusal may come from a login the ledger has never
|
|
330
|
+
* read, such as a bot's own. Limit ids like `weekly` are shared across accounts,
|
|
331
|
+
* so one that several accounts have is ambiguous. Every case that does not name
|
|
332
|
+
* exactly one account is a usage error, never a guess.
|
|
333
|
+
*/
|
|
334
|
+
function resolveRefusalAccount(view, provider, limitArg) {
|
|
335
|
+
const providerView = view?.providers.find((entry) => entry.provider === provider);
|
|
336
|
+
const accounts = providerView?.accounts ?? [];
|
|
337
|
+
if (accounts.length === 0) {
|
|
338
|
+
throw new CapacityUsageError(`no account for ${provider} on this computer: name the account that refused with --account`);
|
|
339
|
+
}
|
|
340
|
+
if (!limitArg) {
|
|
341
|
+
throw new CapacityUsageError(`--account is required: name the ${provider} account that refused`);
|
|
342
|
+
}
|
|
343
|
+
const owners = [...new Set((providerView?.limits ?? [])
|
|
344
|
+
.filter((limit) => limit.limitId === limitArg && !isRefusalHold(limit))
|
|
345
|
+
.map((limit) => limit.accountId))];
|
|
346
|
+
if (owners.length === 1)
|
|
347
|
+
return owners[0];
|
|
348
|
+
if (owners.length === 0) {
|
|
349
|
+
throw new CapacityUsageError(`no ${provider} account has the limit '${limitArg}': name the account that refused with --account`);
|
|
350
|
+
}
|
|
351
|
+
throw new CapacityUsageError(`${owners.length} ${provider} accounts have the limit '${limitArg}': name the one that refused with --account`);
|
|
352
|
+
}
|
|
353
|
+
function holdShape(window) {
|
|
354
|
+
switch (window.kind) {
|
|
355
|
+
case "session":
|
|
356
|
+
return { limitId: `${REFUSAL_LIMIT_PREFIX}session`, kind: "session", scope: null };
|
|
357
|
+
case "weekly":
|
|
358
|
+
return { limitId: `${REFUSAL_LIMIT_PREFIX}weekly`, kind: "weekly_all", scope: null };
|
|
359
|
+
case "model": {
|
|
360
|
+
const model = window.model.toLowerCase();
|
|
361
|
+
return { limitId: `${REFUSAL_LIMIT_PREFIX}model:${model}`, kind: "weekly_scoped", scope: model };
|
|
362
|
+
}
|
|
363
|
+
case "rate_limit":
|
|
364
|
+
return { limitId: `${REFUSAL_LIMIT_PREFIX}${REFUSAL_SCOPE_RATE_LIMIT}`, kind: "unknown", scope: REFUSAL_SCOPE_RATE_LIMIT };
|
|
365
|
+
default:
|
|
366
|
+
return { limitId: `${REFUSAL_LIMIT_PREFIX}${REFUSAL_SCOPE_USAGE}`, kind: "unknown", scope: REFUSAL_SCOPE_USAGE };
|
|
367
|
+
}
|
|
143
368
|
}
|
|
144
369
|
function buildReading(input) {
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
readingId: readingId(input.provider, input.accountId,
|
|
370
|
+
const shape = holdShape(input.window);
|
|
371
|
+
const labels = input.account?.labels ?? [];
|
|
372
|
+
return {
|
|
373
|
+
readingId: readingId(input.provider, input.accountId, shape.limitId, input.observedAt, input.resetsAt),
|
|
149
374
|
observedAt: input.observedAt,
|
|
150
375
|
provider: input.provider,
|
|
151
376
|
accountId: input.accountId,
|
|
152
377
|
source: "refusal",
|
|
153
|
-
cliVersion:
|
|
378
|
+
cliVersion: input.real?.cliVersion ?? "unknown",
|
|
154
379
|
confidence: "inferred",
|
|
155
380
|
parserVersion: REFUSAL_PARSER_VERSION,
|
|
381
|
+
...(labels[0] ? { accountLabel: labels[0], accountLabels: [...labels] } : {}),
|
|
382
|
+
...(input.account?.home ? { accountHome: input.account.home } : {}),
|
|
156
383
|
limit: {
|
|
157
|
-
limitId:
|
|
158
|
-
kind,
|
|
159
|
-
scope:
|
|
384
|
+
limitId: shape.limitId,
|
|
385
|
+
kind: shape.kind,
|
|
386
|
+
scope: shape.scope,
|
|
160
387
|
usedPercent: null,
|
|
161
|
-
windowMinutes:
|
|
388
|
+
windowMinutes: input.real?.windowMinutes ?? null,
|
|
162
389
|
resetsAt: input.resetsAt,
|
|
163
|
-
balance:
|
|
164
|
-
planType:
|
|
390
|
+
balance: null,
|
|
391
|
+
planType: input.real?.planType ?? null,
|
|
165
392
|
},
|
|
166
393
|
};
|
|
167
|
-
if (matched?.hasCredits !== undefined)
|
|
168
|
-
reading.limit.hasCredits = matched.hasCredits;
|
|
169
|
-
if (matched?.unlimited !== undefined)
|
|
170
|
-
reading.limit.unlimited = matched.unlimited;
|
|
171
|
-
if (matched?.allowancePercentOfWeekly !== undefined) {
|
|
172
|
-
reading.limit.allowancePercentOfWeekly = matched.allowancePercentOfWeekly;
|
|
173
|
-
}
|
|
174
|
-
return reading;
|
|
175
394
|
}
|
|
176
395
|
function readingId(provider, accountId, limitId, observedAt, resetsAt) {
|
|
177
396
|
const digest = createHash("sha256")
|