@indigoai-us/hq-cli 5.345.215 → 5.345.218
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 +168 -0
- package/README.md +46 -1
- package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
- package/assets/scaffold/core/scripts/hq-session.sh +4 -0
- 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 +59 -4
- package/dist/command-catalog.generated.js +74 -4
- 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 +11 -4
- 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 +37 -1
- package/dist/commands/cloud.js +110 -27
- package/dist/commands/core-hq-session-native.js +3 -0
- package/dist/commands/core.js +1 -0
- package/dist/commands/daemon.js +4 -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/install-global.js +3 -3
- package/dist/commands/lanes.js +100 -24
- package/dist/commands/logout.d.ts +7 -0
- package/dist/commands/logout.js +41 -34
- package/dist/commands/members.js +1 -1
- package/dist/commands/pack-start-bot.d.ts +1 -1
- package/dist/commands/pack-start-bot.js +2 -2
- package/dist/commands/pkg-update.js +1 -1
- package/dist/commands/sources.d.ts +8 -2
- package/dist/commands/sources.js +65 -9
- package/dist/commands/sync-narrow.js +1 -1
- package/dist/commands/team-sync.js +1 -1
- package/dist/commands/whoami.js +26 -1
- package/dist/data/command-states.json +22 -0
- package/dist/index.js +52 -4
- package/dist/lazy-commands.js +2 -1
- 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 +40 -15
- 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.js +93 -6
- 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/pack-link.d.ts +2 -2
- package/dist/lib/bot/pack-link.js +2 -2
- package/dist/lib/bot/runtime/grok-acp.d.ts +1 -0
- package/dist/lib/bot/runtime/grok-acp.js +26 -11
- package/dist/lib/bot/runtime/grok.js +1 -1
- 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/hook-env.d.ts +32 -0
- package/dist/lib/daemon/hook-env.js +51 -0
- package/dist/lib/daemon/ops/policy.js +67 -8
- package/dist/lib/daemon/paths.d.ts +72 -2
- package/dist/lib/daemon/paths.js +154 -3
- package/dist/lib/daemon/run.js +32 -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 +3 -1
- package/dist/lib/daemon/server.js +7 -22
- 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/timed-flag-monitors.d.ts +47 -0
- package/dist/lib/daemon/timed-flag-monitors.js +75 -0
- package/dist/lib/doctor/checks/host-core.d.ts +52 -0
- package/dist/lib/doctor/checks/host-core.js +337 -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/checks/sync-runtime.js +3 -3
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/environment/credential-shapes.d.ts +61 -0
- package/dist/lib/environment/credential-shapes.js +333 -0
- package/dist/lib/environment/profile.d.ts +239 -0
- package/dist/lib/environment/profile.js +239 -0
- package/dist/lib/hook-engine/coverage.d.ts +13 -0
- package/dist/lib/hook-engine/coverage.js +124 -0
- package/dist/lib/hook-engine/reconcile.js +300 -94
- package/dist/lib/hook-engine/registration.d.ts +17 -1
- package/dist/lib/hook-engine/registration.js +62 -7
- 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 +64 -1
- package/dist/lib/hot-channels/signals-pass.js +21 -49
- package/dist/lib/install/claude-targets.d.ts +12 -1
- package/dist/lib/install/claude-targets.js +70 -5
- package/dist/lib/install/codex-pack-contributions.js +1 -1
- package/dist/lib/install/codex-targets.d.ts +2 -2
- package/dist/lib/install/codex-targets.js +48 -5
- package/dist/lib/install/hook-target.d.ts +4 -1
- package/dist/lib/install/hook-target.js +14 -1
- 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/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/packages/setup-block.d.ts +2 -2
- package/dist/lib/packages/setup-block.js +2 -2
- package/dist/lib/packages/start-bot.d.ts +1 -1
- package/dist/lib/packages/start-bot.js +1 -1
- 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 +84 -4
- package/dist/main.js +47 -4
- package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
- package/dist/types.d.ts +1 -1
- package/dist/utils/auth-expiry.d.ts +8 -0
- package/dist/utils/auth-expiry.js +53 -0
- package/dist/utils/callback-port-busy.d.ts +1 -1
- package/dist/utils/callback-port-busy.js +4 -4
- 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/hook-trust.d.ts +7 -0
- package/dist/utils/hook-trust.js +34 -4
- package/dist/utils/host-registration.d.ts +179 -0
- package/dist/utils/host-registration.js +505 -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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"commands": {
|
|
4
|
+
"crm entity get": { "state": "retiring" },
|
|
5
|
+
"crm entity list": { "state": "retiring" },
|
|
6
|
+
"packages packs list": { "state": "retiring", "replacedBy": "hq packs list" },
|
|
7
|
+
"packages packs uninstall": { "state": "retiring", "replacedBy": "hq packs uninstall" },
|
|
8
|
+
"packages packs update": { "state": "retiring", "replacedBy": "hq packs update" },
|
|
9
|
+
"packages remove": { "state": "retiring", "replacedBy": "hq remove" },
|
|
10
|
+
"report access": { "state": "retiring" },
|
|
11
|
+
"report discard-draft": { "state": "retiring" },
|
|
12
|
+
"report promote": { "state": "retiring" },
|
|
13
|
+
"report templates": { "state": "retiring" },
|
|
14
|
+
"staff listings approve": { "state": "retiring", "replacedBy": "the staff-only hq-staff script outside the public CLI" },
|
|
15
|
+
"staff listings queue": { "state": "retiring", "replacedBy": "the staff-only hq-staff script outside the public CLI" },
|
|
16
|
+
"staff listings reject": { "state": "retiring", "replacedBy": "the staff-only hq-staff script outside the public CLI" },
|
|
17
|
+
"staff reset-test-account": { "state": "retiring", "replacedBy": "the staff-only hq-staff script outside the public CLI" },
|
|
18
|
+
"staff test-account add": { "state": "retiring", "replacedBy": "the staff-only hq-staff script outside the public CLI" },
|
|
19
|
+
"staff test-account list": { "state": "retiring", "replacedBy": "the staff-only hq-staff script outside the public CLI" },
|
|
20
|
+
"staff test-account remove": { "state": "retiring", "replacedBy": "the staff-only hq-staff script outside the public CLI" }
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,27 @@ import { isLaneSessionStartFastRequest } from "./lanes-session-start-argv.js";
|
|
|
20
20
|
import { writeLanesAliasDeprecationForArgv } from "./runners-alias.js";
|
|
21
21
|
import { createRequire } from "node:module";
|
|
22
22
|
import { hookEnginePathArgs, runHookEnginePath } from "./hook-engine-path.js";
|
|
23
|
+
// Builtins only: the local command count and the retiring gate run on every
|
|
24
|
+
// route, including the hook fast routes. The gate ships switched off
|
|
25
|
+
// (RETIRING_GATE_ENABLED in utils/command-usage.ts), so it refuses nothing.
|
|
26
|
+
import { admitCommandRun, hasStillUseFlag } from "./utils/command-usage.js";
|
|
27
|
+
/**
|
|
28
|
+
* Count one run of a command that a fast route is about to handle. With the
|
|
29
|
+
* retiring gate switched on, a command being retired would be refused and this
|
|
30
|
+
* would return false (the command must not run); while the gate is off it
|
|
31
|
+
* always returns true.
|
|
32
|
+
* `commandPath` is built from command names only, never from an argument;
|
|
33
|
+
* `canonical` is the same path by declared names when an alias was typed.
|
|
34
|
+
* Commands that reach the full command graph are counted there (main.ts).
|
|
35
|
+
*/
|
|
36
|
+
function admitFastRoute(commandPath, canonical) {
|
|
37
|
+
const refusal = admitCommandRun({ typed: commandPath, canonical, stillUse: false });
|
|
38
|
+
if (refusal === null)
|
|
39
|
+
return true;
|
|
40
|
+
process.stderr.write(`hq: ${refusal}\n`);
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
23
44
|
function cygpathMixedPath(value) {
|
|
24
45
|
// Require only a Node builtin: the package supports Node releases before
|
|
25
46
|
// require(ESM) became available, and this runs in the synchronous dispatcher.
|
|
@@ -205,9 +226,14 @@ function dispatchCliEntry() {
|
|
|
205
226
|
// Before anything spawns: a background hq on Windows (no terminal) hides the
|
|
206
227
|
// console window of every child it starts (feedback_351a40d5).
|
|
207
228
|
installWindowsHideDefault();
|
|
208
|
-
|
|
229
|
+
// A run that mentions --i-still-use-this takes the full command graph, which
|
|
230
|
+
// knows the command names and reads the flag only where it is hq's (before
|
|
231
|
+
// the command's own arguments). The fast routes pass their arguments on
|
|
232
|
+
// untouched and would hand a flag meant for hq to the command itself.
|
|
233
|
+
const engineArgs = hasStillUseFlag(process.argv) ? null : hookEnginePathArgs(process.argv);
|
|
209
234
|
if (engineArgs !== null) {
|
|
210
|
-
|
|
235
|
+
if (admitFastRoute("core hook-engine-path"))
|
|
236
|
+
void runHookEnginePath(engineArgs);
|
|
211
237
|
return;
|
|
212
238
|
}
|
|
213
239
|
// cmd.exe code page 437 prints em dashes as mojibake. Pipes stay UTF-8.
|
|
@@ -237,10 +263,13 @@ function dispatchCliRoutes() {
|
|
|
237
263
|
if (!versionRequest)
|
|
238
264
|
writeLanesAliasDeprecationForArgv(process.argv);
|
|
239
265
|
const helpRequest = !versionRequest && isCommandHelpRequest(process.argv);
|
|
240
|
-
const parsedFastCore = versionRequest || helpRequest ? null : parseFastCore(process.argv);
|
|
266
|
+
const parsedFastCore = versionRequest || helpRequest || hasStillUseFlag(process.argv) ? null : parseFastCore(process.argv);
|
|
241
267
|
const monitorRequest = versionRequest || helpRequest ? null : parseMonitorCheckFastRequest(process.argv);
|
|
242
268
|
if (!versionRequest && !helpRequest && !monitorRequest && isLaneSessionStartFastRequest(process.argv)) {
|
|
243
|
-
|
|
269
|
+
// argv[2] is `runners` or its alias `lanes`; the matcher accepts nothing else.
|
|
270
|
+
if (admitFastRoute(`${process.argv[2]} session-start`, "runners session-start")) {
|
|
271
|
+
void runLaneSessionStartFastWithRecovery();
|
|
272
|
+
}
|
|
244
273
|
return;
|
|
245
274
|
}
|
|
246
275
|
const secretsRequest = versionRequest || helpRequest || monitorRequest || parsedFastCore
|
|
@@ -273,6 +302,25 @@ function dispatchCliRoutes() {
|
|
|
273
302
|
dispatchCliCommand(versionRequest, helpRequest, parsedFastCore, monitorRequest, secretsRequest, mcpRequest);
|
|
274
303
|
}
|
|
275
304
|
function dispatchCliCommand(versionRequest, helpRequest, parsedFastCore, monitorRequest, secretsRequest, mcpRequest) {
|
|
305
|
+
// Same order as the branches below. `hq --version` and help are not command
|
|
306
|
+
// runs; the last branch (the full command graph) counts in main.ts.
|
|
307
|
+
const fastCommand = versionRequest
|
|
308
|
+
? (process.argv.slice(2).includes("version") ? "version" : null)
|
|
309
|
+
: helpRequest
|
|
310
|
+
? null
|
|
311
|
+
: monitorRequest
|
|
312
|
+
? `${process.argv[2]} monitor-check`
|
|
313
|
+
: parsedFastCore
|
|
314
|
+
? `core ${parsedFastCore.entry.name}`
|
|
315
|
+
: secretsRequest
|
|
316
|
+
? "secrets env"
|
|
317
|
+
: mcpRequest
|
|
318
|
+
? "mcp serve"
|
|
319
|
+
: null;
|
|
320
|
+
// `lanes monitor-check` is the alias spelling of `runners monitor-check`.
|
|
321
|
+
const fastCanonical = monitorRequest ? "runners monitor-check" : undefined;
|
|
322
|
+
if (fastCommand !== null && !admitFastRoute(fastCommand, fastCanonical))
|
|
323
|
+
return;
|
|
276
324
|
if (versionRequest) {
|
|
277
325
|
// Bare `--version` is the CLI semver only (the contract field updaters
|
|
278
326
|
// compare). `hq version` and `--json` print the labelled HQ/CLI report.
|
package/dist/lazy-commands.js
CHANGED
|
@@ -5,6 +5,7 @@ import { dirname, join, resolve, sep } from "node:path";
|
|
|
5
5
|
import { COMMAND_CATALOG } from "./command-catalog.generated.js";
|
|
6
6
|
import { installUnknownCommandSuggestions } from "./unknown-command.js";
|
|
7
7
|
import { restoreRuntimeText } from "./utils/catalog-runtime-paths.js";
|
|
8
|
+
import { STILL_USE_FLAG } from "./utils/command-usage.js";
|
|
8
9
|
import { MissingRegistrationPlanError } from "./utils/registration-plan-error.js";
|
|
9
10
|
const commandCatalog = COMMAND_CATALOG;
|
|
10
11
|
/**
|
|
@@ -121,7 +122,7 @@ function commandForToken(token) {
|
|
|
121
122
|
*/
|
|
122
123
|
export function findLazyCommand(argv) {
|
|
123
124
|
let commandIndex = 2;
|
|
124
|
-
while (argv[commandIndex] === "--verbose")
|
|
125
|
+
while (argv[commandIndex] === "--verbose" || argv[commandIndex] === STILL_USE_FLAG)
|
|
125
126
|
commandIndex += 1;
|
|
126
127
|
const first = argv[commandIndex];
|
|
127
128
|
const token = first === "help" ? argv[commandIndex + 1] : first;
|
|
@@ -9,6 +9,8 @@ export interface ReadHqAnywherePersonSettingOptions {
|
|
|
9
9
|
home?: string;
|
|
10
10
|
onError?: (errorName: string) => void;
|
|
11
11
|
}
|
|
12
|
+
/** Mirrors personTokenCacheFile() in utils/cognito-session.ts; duplicated so this path does not load that module. */
|
|
13
|
+
export declare function personTokenCachePath(env: NodeJS.ProcessEnv, home: string): string;
|
|
12
14
|
/** Returns null when the person preference cannot be read; callers must fail closed. */
|
|
13
15
|
export declare function readHqAnywherePersonSetting(options?: ReadHqAnywherePersonSettingOptions): Promise<boolean | null>;
|
|
14
16
|
/**
|
|
@@ -2,10 +2,13 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { anywhereRuntimeEnabledFromSnapshot } from "./anywhere-runtime-fast-flag.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/** Mirrors personTokenCacheFile() in utils/cognito-session.ts; duplicated so this path does not load that module. */
|
|
6
|
+
export function personTokenCachePath(env, home) {
|
|
7
7
|
const stateDir = env.HQ_STATE_DIR?.trim() || path.join(home, ".hq");
|
|
8
|
-
return
|
|
8
|
+
return path.join(stateDir, "cognito-tokens.json");
|
|
9
|
+
}
|
|
10
|
+
function hasPersonTokenCache(env, home) {
|
|
11
|
+
return fs.existsSync(personTokenCachePath(env, home));
|
|
9
12
|
}
|
|
10
13
|
const HQ_ANYWHERE_OPT_OUT_KEY = "hq-anywhere-opt-out";
|
|
11
14
|
const HQ_ANYWHERE_OPT_IN_KEY = "hq-anywhere";
|
|
@@ -8,15 +8,25 @@
|
|
|
8
8
|
*
|
|
9
9
|
* - {@link fetchUsageCard} reads the feed and falls back to the bundled card
|
|
10
10
|
* when the feed is offline, slow, or has no `usage` block yet.
|
|
11
|
-
* - {@link BUNDLED_USAGE_CARD} is the fallback. It equals the
|
|
12
|
-
*
|
|
11
|
+
* - {@link BUNDLED_USAGE_CARD} is the fallback. It equals the live
|
|
12
|
+
* `GET /v1/pricing` `usage` block, display fields included.
|
|
13
13
|
*
|
|
14
14
|
* Field-level fallback: a feed that sends a `usage` block with one malformed
|
|
15
15
|
* field keeps the feed's other fields and takes the bundled value for that one
|
|
16
16
|
* field. Unknown meter ids are kept (they render with their own label and
|
|
17
17
|
* price); malformed meter or box rows are dropped.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Optional quote for a meter priced per N units (`displayPer` of those units
|
|
21
|
+
* cost `displayUsd`). `displayText` is the phrase to show. A field of the
|
|
22
|
+
* wrong type is dropped; it never rejects the meter.
|
|
23
|
+
*/
|
|
24
|
+
export interface MeterDisplayFields {
|
|
25
|
+
readonly displayPer?: number;
|
|
26
|
+
readonly displayUsd?: number;
|
|
27
|
+
readonly displayText?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface UsageCardMeter extends MeterDisplayFields {
|
|
20
30
|
readonly id: string;
|
|
21
31
|
readonly label: string;
|
|
22
32
|
readonly unit: string;
|
|
@@ -54,6 +64,8 @@ export interface ResolvedUsageCard {
|
|
|
54
64
|
export declare const BUNDLED_USAGE_CARD: UsageCard;
|
|
55
65
|
/** The self-hosted / on-prem guide the card links for teams that want no cloud bill. */
|
|
56
66
|
export declare const SELF_HOSTED_GUIDE_URL = "https://docs.hq.computer/hq/guide/use-hq-for-free/";
|
|
67
|
+
/** Display fields from a meter or a usage-statement line. Wrong types are omitted. */
|
|
68
|
+
export declare function readMeterDisplayFields(raw: unknown): MeterDisplayFields;
|
|
57
69
|
/**
|
|
58
70
|
* Parse the `usage` block of a `GET /v1/pricing` body. Returns null when the
|
|
59
71
|
* body has no `usage` object at all (the feed before hq-pro ships it).
|
|
@@ -71,8 +83,17 @@ export interface FetchUsageCardDeps {
|
|
|
71
83
|
* body without `usage` all resolve to the bundled card.
|
|
72
84
|
*/
|
|
73
85
|
export declare function fetchUsageCard(deps?: FetchUsageCardDeps): Promise<ResolvedUsageCard>;
|
|
74
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* `$10`, `$2.00`, `$0.10`. An amount under half a cent keeps the digits that
|
|
88
|
+
* `toFixed(2)` would turn into `$0.00` (so `0.001` is `$0.001`).
|
|
89
|
+
*/
|
|
75
90
|
export declare function formatCardUsd(amount: number): string;
|
|
91
|
+
/** The phrase shown for one meter's price: `displayText` when the feed sent it. */
|
|
92
|
+
export declare function meterRateText(meter: {
|
|
93
|
+
readonly unitUsd: number;
|
|
94
|
+
readonly unit: string;
|
|
95
|
+
readonly displayText?: string;
|
|
96
|
+
}): string;
|
|
76
97
|
/** "small (t3.small) $100/month, medium (t3.medium) $200/month, ..." */
|
|
77
98
|
export declare function formatBoxQuotes(card?: UsageCard): string;
|
|
78
99
|
/** "deploys, DMs and background AI" */
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*
|
|
9
9
|
* - {@link fetchUsageCard} reads the feed and falls back to the bundled card
|
|
10
10
|
* when the feed is offline, slow, or has no `usage` block yet.
|
|
11
|
-
* - {@link BUNDLED_USAGE_CARD} is the fallback. It equals the
|
|
12
|
-
*
|
|
11
|
+
* - {@link BUNDLED_USAGE_CARD} is the fallback. It equals the live
|
|
12
|
+
* `GET /v1/pricing` `usage` block, display fields included.
|
|
13
13
|
*
|
|
14
14
|
* Field-level fallback: a feed that sends a `usage` block with one malformed
|
|
15
15
|
* field keeps the feed's other fields and takes the bundled value for that one
|
|
@@ -19,14 +19,30 @@
|
|
|
19
19
|
import { vaultApiFetchPublic } from "../../utils/vault-api.js";
|
|
20
20
|
/** The feed contract, verbatim. Used whenever the feed has no usable `usage` block. */
|
|
21
21
|
export const BUNDLED_USAGE_CARD = {
|
|
22
|
-
version: "2026-
|
|
22
|
+
version: "2026-11-13",
|
|
23
23
|
newSignupsFrom: "2026-10-16T18:00:00Z",
|
|
24
24
|
includedUsd: 10,
|
|
25
25
|
trial: { days: 30, capUsd: 500 },
|
|
26
26
|
meters: [
|
|
27
27
|
{ id: "member-sync", label: "Sync", unit: "sync", unitUsd: 0.1 },
|
|
28
|
-
{
|
|
29
|
-
|
|
28
|
+
{
|
|
29
|
+
id: "integration-call",
|
|
30
|
+
label: "Gateway call",
|
|
31
|
+
unit: "call",
|
|
32
|
+
unitUsd: 0.001,
|
|
33
|
+
displayPer: 100,
|
|
34
|
+
displayUsd: 0.1,
|
|
35
|
+
displayText: "$0.10 per 100 calls",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "hq-mcp-call",
|
|
39
|
+
label: "HQ MCP call",
|
|
40
|
+
unit: "call",
|
|
41
|
+
unitUsd: 0.001,
|
|
42
|
+
displayPer: 100,
|
|
43
|
+
displayUsd: 0.1,
|
|
44
|
+
displayText: "$0.10 per 100 calls",
|
|
45
|
+
},
|
|
30
46
|
{ id: "agent-run", label: "Agent run", unit: "run", unitUsd: 0.05 },
|
|
31
47
|
{ id: "storage", label: "Storage", unit: "GB-month", unitUsd: 2 },
|
|
32
48
|
{ id: "secret", label: "Secret", unit: "secret-month", unitUsd: 0.5 },
|
|
@@ -54,6 +70,23 @@ function nonNegative(value) {
|
|
|
54
70
|
function nonEmpty(value) {
|
|
55
71
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
56
72
|
}
|
|
73
|
+
function finiteNumber(value) {
|
|
74
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
75
|
+
}
|
|
76
|
+
/** Display fields from a meter or a usage-statement line. Wrong types are omitted. */
|
|
77
|
+
export function readMeterDisplayFields(raw) {
|
|
78
|
+
const rec = asRecord(raw);
|
|
79
|
+
if (!rec)
|
|
80
|
+
return {};
|
|
81
|
+
const displayPer = finiteNumber(rec.displayPer);
|
|
82
|
+
const displayUsd = finiteNumber(rec.displayUsd);
|
|
83
|
+
const displayText = nonEmpty(rec.displayText);
|
|
84
|
+
return {
|
|
85
|
+
...(displayPer !== undefined && displayPer > 0 ? { displayPer } : {}),
|
|
86
|
+
...(displayUsd !== undefined && displayUsd >= 0 ? { displayUsd } : {}),
|
|
87
|
+
...(displayText ? { displayText } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
57
90
|
function parseMeter(raw) {
|
|
58
91
|
const rec = asRecord(raw);
|
|
59
92
|
if (!rec)
|
|
@@ -64,7 +97,14 @@ function parseMeter(raw) {
|
|
|
64
97
|
const unitUsd = nonNegative(rec.unitUsd);
|
|
65
98
|
if (!id || !label || !unit || unitUsd === null)
|
|
66
99
|
return null;
|
|
67
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
id,
|
|
102
|
+
label,
|
|
103
|
+
unit,
|
|
104
|
+
unitUsd,
|
|
105
|
+
...(rec.waivedInTrial === true ? { waivedInTrial: true } : {}),
|
|
106
|
+
...readMeterDisplayFields(rec),
|
|
107
|
+
};
|
|
68
108
|
}
|
|
69
109
|
function parseBox(raw) {
|
|
70
110
|
const rec = asRecord(raw);
|
|
@@ -158,9 +198,36 @@ export async function fetchUsageCard(deps = {}) {
|
|
|
158
198
|
}
|
|
159
199
|
}
|
|
160
200
|
// ── Rendering ────────────────────────────────────────────────────────────────
|
|
161
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* `$10`, `$2.00`, `$0.10`. An amount under half a cent keeps the digits that
|
|
203
|
+
* `toFixed(2)` would turn into `$0.00` (so `0.001` is `$0.001`).
|
|
204
|
+
*/
|
|
162
205
|
export function formatCardUsd(amount) {
|
|
163
|
-
|
|
206
|
+
if (!Number.isFinite(amount))
|
|
207
|
+
return "$0.00";
|
|
208
|
+
const sign = amount < 0 ? "-" : "";
|
|
209
|
+
const abs = Math.abs(amount);
|
|
210
|
+
if (Number.isInteger(abs) && abs >= 10)
|
|
211
|
+
return `${sign}$${abs}`;
|
|
212
|
+
if (abs === 0)
|
|
213
|
+
return "$0.00";
|
|
214
|
+
const cents = abs.toFixed(2);
|
|
215
|
+
if (cents !== "0.00")
|
|
216
|
+
return `${sign}$${cents}`;
|
|
217
|
+
for (let places = 3; places <= 12; places++) {
|
|
218
|
+
const fixed = abs.toFixed(places);
|
|
219
|
+
if (fixed !== `0.${"0".repeat(places)}`) {
|
|
220
|
+
return `${sign}$${fixed.replace(/0+$/, "")}`;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return `${sign}$${abs.toExponential(2)}`;
|
|
224
|
+
}
|
|
225
|
+
/** The phrase shown for one meter's price: `displayText` when the feed sent it. */
|
|
226
|
+
export function meterRateText(meter) {
|
|
227
|
+
const text = typeof meter.displayText === "string" ? meter.displayText.trim() : "";
|
|
228
|
+
if (text.length > 0)
|
|
229
|
+
return text;
|
|
230
|
+
return `${formatCardUsd(meter.unitUsd)} per ${meter.unit}`;
|
|
164
231
|
}
|
|
165
232
|
/** "small (t3.small) $100/month, medium (t3.medium) $200/month, ..." */
|
|
166
233
|
export function formatBoxQuotes(card = BUNDLED_USAGE_CARD) {
|
|
@@ -186,7 +253,7 @@ export function formatUsageCardLines(card = BUNDLED_USAGE_CARD) {
|
|
|
186
253
|
const nameW = Math.max(...card.meters.map((m) => m.label.length));
|
|
187
254
|
for (const m of card.meters) {
|
|
188
255
|
const waived = m.waivedInTrial ? " (waived during the trial)" : "";
|
|
189
|
-
lines.push(` ${m.label.padEnd(nameW)} ${
|
|
256
|
+
lines.push(` ${m.label.padEnd(nameW)} ${meterRateText(m)}${waived}`);
|
|
190
257
|
}
|
|
191
258
|
lines.push(`Included usage: ${formatCardUsd(card.includedUsd)} per month.`);
|
|
192
259
|
lines.push(`Trial: ${card.trial.days} days, capped at ${formatCardUsd(card.trial.capUsd)} of usage.`);
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* Fixes are returned as commands for the caller to preview and run with the
|
|
30
30
|
* user's yes (the /hq-cost skill does that).
|
|
31
31
|
*/
|
|
32
|
-
import { type UsageCard } from "./usage-card.js";
|
|
32
|
+
import { type MeterDisplayFields, type UsageCard } from "./usage-card.js";
|
|
33
33
|
import { type UsageMeterKey, type UsageMeterRate } from "./usage-rate-card.js";
|
|
34
34
|
/** Bytes per billed GB. Storage is billed like S3: 1 GB = 2^30 bytes. */
|
|
35
35
|
export declare const BYTES_PER_GB: number;
|
|
@@ -42,7 +42,7 @@ export type UsageScope = {
|
|
|
42
42
|
kind: "person";
|
|
43
43
|
};
|
|
44
44
|
export type MeterState = "measured" | "unknown" | "not-available";
|
|
45
|
-
export interface MeterReading {
|
|
45
|
+
export interface MeterReading extends MeterDisplayFields {
|
|
46
46
|
key: UsageMeterKey;
|
|
47
47
|
/** In billed units (GB for storage). Null unless measured. */
|
|
48
48
|
value: number | null;
|
|
@@ -146,7 +146,7 @@ export declare function usageStatementSource(fetchStatement: (scope: UsageScope)
|
|
|
146
146
|
* default source here when the US-005 rollup has a read route.
|
|
147
147
|
*/
|
|
148
148
|
export declare function readMonthUsage(scope: UsageScope, deps: ReadMonthUsageDeps, source?: MonthUsageSource): Promise<MonthUsage>;
|
|
149
|
-
export interface MeterCost {
|
|
149
|
+
export interface MeterCost extends MeterDisplayFields {
|
|
150
150
|
key: UsageMeterKey;
|
|
151
151
|
displayName: string;
|
|
152
152
|
unit: string;
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* Fixes are returned as commands for the caller to preview and run with the
|
|
30
30
|
* user's yes (the /hq-cost skill does that).
|
|
31
31
|
*/
|
|
32
|
-
import { BUNDLED_USAGE_CARD, SELF_HOSTED_GUIDE_URL, formatFreeItems } from "./usage-card.js";
|
|
32
|
+
import { BUNDLED_USAGE_CARD, SELF_HOSTED_GUIDE_URL, formatCardUsd, formatFreeItems, meterRateText, readMeterDisplayFields, } from "./usage-card.js";
|
|
33
33
|
import { BUNDLED_USAGE_METER_RATES, USAGE_MONTHLY_ALLOWANCE_USD, } from "./usage-rate-card.js";
|
|
34
34
|
/** Bytes per billed GB. Storage is billed like S3: 1 GB = 2^30 bytes. */
|
|
35
35
|
export const BYTES_PER_GB = 1024 ** 3;
|
|
@@ -177,13 +177,19 @@ export function meterReadingsFromStatement(body) {
|
|
|
177
177
|
if (typeof line.key !== "string" || !STATEMENT_KEYS.has(line.key))
|
|
178
178
|
continue;
|
|
179
179
|
const key = line.key;
|
|
180
|
+
const quote = readMeterDisplayFields(line);
|
|
180
181
|
const measured = line.status === "measured" || line.status === "partial";
|
|
181
182
|
const usage = line.usage;
|
|
182
183
|
if (!measured || typeof usage !== "number" || !Number.isFinite(usage) || usage < 0) {
|
|
183
|
-
byKey.set(key, { key, value: null, state: "not-available" });
|
|
184
|
+
byKey.set(key, { key, value: null, state: "not-available", ...quote });
|
|
184
185
|
continue;
|
|
185
186
|
}
|
|
186
|
-
const reading = {
|
|
187
|
+
const reading = {
|
|
188
|
+
key,
|
|
189
|
+
value: key === "storage" ? usage / bytesPerGb : usage,
|
|
190
|
+
state: "measured",
|
|
191
|
+
...quote,
|
|
192
|
+
};
|
|
187
193
|
const cost = centsField(line.costCents);
|
|
188
194
|
const projected = centsField(line.projectedCostCents);
|
|
189
195
|
if (cost !== null && projected !== null) {
|
|
@@ -270,32 +276,38 @@ export function computeBill(usage, rates = BUNDLED_USAGE_METER_RATES, cardAllowa
|
|
|
270
276
|
let incomplete = false;
|
|
271
277
|
const meters = rates.map((rate) => {
|
|
272
278
|
const reading = byKey.get(rate.key) ?? { key: rate.key, value: null, state: "not-available" };
|
|
279
|
+
const quoted = (cost) => ({
|
|
280
|
+
...cost,
|
|
281
|
+
...(reading.displayPer !== undefined ? { displayPer: reading.displayPer } : {}),
|
|
282
|
+
...(reading.displayUsd !== undefined ? { displayUsd: reading.displayUsd } : {}),
|
|
283
|
+
...(reading.displayText !== undefined ? { displayText: reading.displayText } : {}),
|
|
284
|
+
});
|
|
273
285
|
if (reading.state !== "measured" || reading.value === null) {
|
|
274
286
|
incomplete = true;
|
|
275
|
-
return { ...pick(rate), value: null, state: reading.state, monthToDateUsd: null, projectedUsd: null };
|
|
287
|
+
return quoted({ ...pick(rate), value: null, state: reading.state, monthToDateUsd: null, projectedUsd: null });
|
|
276
288
|
}
|
|
277
289
|
if (reading.accrued) {
|
|
278
290
|
const { monthToDateUsd: m, projectedUsd: p, waived } = reading.accrued;
|
|
279
291
|
mtd += m;
|
|
280
292
|
projected += p;
|
|
281
|
-
return {
|
|
293
|
+
return quoted({
|
|
282
294
|
...pick(rate),
|
|
283
295
|
value: reading.value,
|
|
284
296
|
state: "measured",
|
|
285
297
|
monthToDateUsd: round2(m),
|
|
286
298
|
projectedUsd: round2(p),
|
|
287
299
|
...(waived ? { waivedInTrial: true } : {}),
|
|
288
|
-
};
|
|
300
|
+
});
|
|
289
301
|
}
|
|
290
302
|
if (rate.waivedInTrial && usage.trialActive === true) {
|
|
291
|
-
return { ...pick(rate), value: reading.value, state: "measured", monthToDateUsd: 0, projectedUsd: 0, waivedInTrial: true };
|
|
303
|
+
return quoted({ ...pick(rate), value: reading.value, state: "measured", monthToDateUsd: 0, projectedUsd: 0, waivedInTrial: true });
|
|
292
304
|
}
|
|
293
305
|
const full = reading.value * rate.unitUsd;
|
|
294
306
|
const m = rate.kind === "gauge" ? full * (daysElapsed / daysInMonth) : full;
|
|
295
307
|
const p = rate.kind === "gauge" ? full : full * (daysInMonth / daysElapsed);
|
|
296
308
|
mtd += m;
|
|
297
309
|
projected += p;
|
|
298
|
-
return { ...pick(rate), value: reading.value, state: "measured", monthToDateUsd: round2(m), projectedUsd: round2(p) };
|
|
310
|
+
return quoted({ ...pick(rate), value: reading.value, state: "measured", monthToDateUsd: round2(m), projectedUsd: round2(p) });
|
|
299
311
|
});
|
|
300
312
|
return {
|
|
301
313
|
meters,
|
|
@@ -310,7 +322,15 @@ export function computeBill(usage, rates = BUNDLED_USAGE_METER_RATES, cardAllowa
|
|
|
310
322
|
};
|
|
311
323
|
}
|
|
312
324
|
function pick(rate) {
|
|
313
|
-
return {
|
|
325
|
+
return {
|
|
326
|
+
key: rate.key,
|
|
327
|
+
displayName: rate.displayName,
|
|
328
|
+
unit: rate.unit,
|
|
329
|
+
unitUsd: rate.unitUsd,
|
|
330
|
+
...(rate.displayPer !== undefined ? { displayPer: rate.displayPer } : {}),
|
|
331
|
+
...(rate.displayUsd !== undefined ? { displayUsd: rate.displayUsd } : {}),
|
|
332
|
+
...(rate.displayText !== undefined ? { displayText: rate.displayText } : {}),
|
|
333
|
+
};
|
|
314
334
|
}
|
|
315
335
|
function gb(n) {
|
|
316
336
|
return n >= 10 ? n.toFixed(0) : n >= 1 ? n.toFixed(1) : n.toFixed(2);
|
|
@@ -333,8 +353,11 @@ export function excludeFoldersFix(scope) {
|
|
|
333
353
|
id: "exclude-folders",
|
|
334
354
|
title: "Stop syncing folders you do not need in the cloud",
|
|
335
355
|
detail: "Add the folders to .hqignore in your HQ folder so sync skips them, or limit what this company downloads with " +
|
|
336
|
-
"
|
|
337
|
-
|
|
356
|
+
(scope.kind === "company" ? `\`hq daemon sync mode set ${scope.companySlug} shared\`.` : "the company's sync settings.") +
|
|
357
|
+
" Files already in the cloud stay until you remove them; nothing is deleted.",
|
|
358
|
+
preview: scope.kind === "company"
|
|
359
|
+
? [`hq daemon sync mode get ${scope.companySlug}`, `hq storage status${companyFlag(scope)} --json`]
|
|
360
|
+
: ["hq daemon sync status"],
|
|
338
361
|
apply: ["(edit <HQ folder>/.hqignore: add one line per folder, for example `bigfolder/`)"],
|
|
339
362
|
savesUsdPerMonth: null,
|
|
340
363
|
};
|
|
@@ -405,13 +428,13 @@ export function findDrivers(usage, bill) {
|
|
|
405
428
|
if (secrets?.projectedUsd && secrets.value) {
|
|
406
429
|
drivers.push({
|
|
407
430
|
meter: "secret",
|
|
408
|
-
summary: `Secrets: ${secrets.value} stored at ${
|
|
431
|
+
summary: `Secrets: ${secrets.value} stored at ${formatCardUsd(secrets.unitUsd)} each a month (${usd(secrets.projectedUsd)}).`,
|
|
409
432
|
projectedUsd: secrets.projectedUsd,
|
|
410
433
|
fixes: [
|
|
411
434
|
{
|
|
412
435
|
id: "remove-unused-secrets",
|
|
413
436
|
title: "Remove secrets nothing uses any more",
|
|
414
|
-
detail: `Each secret you delete saves ${
|
|
437
|
+
detail: `Each secret you delete saves ${formatCardUsd(secrets.unitUsd)} a month. HQ does not record when a secret was last read, ` +
|
|
415
438
|
"so the list shows when each was last changed; you pick which to delete, one at a time. This cannot be undone.",
|
|
416
439
|
preview: [`hq secrets${companyFlag(scope)}${personalFlag(scope)} list`],
|
|
417
440
|
// --force skips the CLI's own TTY prompt. Run it only for a name the
|
|
@@ -511,9 +534,11 @@ export function buildReport(usage, rates) {
|
|
|
511
534
|
};
|
|
512
535
|
}
|
|
513
536
|
function rateText(m) {
|
|
514
|
-
const price =
|
|
537
|
+
const price = meterRateText(m);
|
|
538
|
+
if (m.displayText)
|
|
539
|
+
return price;
|
|
515
540
|
const trial = m.key === "vault" && !m.waivedInTrial ? ", waived during the trial" : "";
|
|
516
|
-
return `${price}
|
|
541
|
+
return `${price}${trial}`;
|
|
517
542
|
}
|
|
518
543
|
function valueText(m) {
|
|
519
544
|
if (m.state === "not-available")
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* they saw before, and an account is only told about usage pricing when the
|
|
23
23
|
* server said so.
|
|
24
24
|
*/
|
|
25
|
-
import { BUNDLED_USAGE_CARD, formatBoxQuotes, formatCardUsd, } from "./usage-card.js";
|
|
25
|
+
import { BUNDLED_USAGE_CARD, formatBoxQuotes, formatCardUsd, meterRateText, } from "./usage-card.js";
|
|
26
26
|
// Static imports on purpose: resident command paths (agents, daemon, ...) may
|
|
27
27
|
// not lazy-load packages (src/utils/resident-package-preload.test.ts).
|
|
28
28
|
// vault-api loads plan-limit-nag with a dynamic import, so there is no
|
|
@@ -337,7 +337,9 @@ export function usageOnlyPlanLine(card = BUNDLED_USAGE_CARD) {
|
|
|
337
337
|
*/
|
|
338
338
|
export function usageOnlyBoxSentence(card = BUNDLED_USAGE_CARD) {
|
|
339
339
|
const run = card.meters.find((m) => m.id === "agent-run");
|
|
340
|
-
const perRun = run
|
|
340
|
+
const perRun = run
|
|
341
|
+
? `, plus ${run.displayText ? meterRateText(run) : `${formatCardUsd(run.unitUsd)} per agent run`}`
|
|
342
|
+
: "";
|
|
341
343
|
return `Agent boxes on usage pricing are billed by size: ${formatBoxQuotes(card)}${perRun}.`;
|
|
342
344
|
}
|
|
343
345
|
/**
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* or counter) are priced here; an unknown feed meter is left out of the bill
|
|
12
12
|
* rather than billed with a guessed shape.
|
|
13
13
|
*/
|
|
14
|
-
import { type UsageCard } from "./usage-card.js";
|
|
14
|
+
import { type MeterDisplayFields, type UsageCard } from "./usage-card.js";
|
|
15
15
|
export type UsageMeterKey = "member-sync" | "integration-call" | "hq-mcp-call" | "agent-run" | "storage" | "secret" | "vault";
|
|
16
16
|
/**
|
|
17
17
|
* Gauges are billed on the amount held (GB, secrets, vaults) for the month.
|
|
@@ -19,7 +19,7 @@ export type UsageMeterKey = "member-sync" | "integration-call" | "hq-mcp-call" |
|
|
|
19
19
|
* month end.
|
|
20
20
|
*/
|
|
21
21
|
export type UsageMeterKind = "gauge" | "counter";
|
|
22
|
-
export interface UsageMeterRate {
|
|
22
|
+
export interface UsageMeterRate extends MeterDisplayFields {
|
|
23
23
|
readonly key: UsageMeterKey;
|
|
24
24
|
readonly displayName: string;
|
|
25
25
|
/** What one billed unit is, in words. */
|
|
@@ -37,6 +37,9 @@ export function ratesFromCard(card) {
|
|
|
37
37
|
unitUsd: m.unitUsd,
|
|
38
38
|
kind: METER_KINDS[m.id],
|
|
39
39
|
...(m.waivedInTrial ? { waivedInTrial: true } : {}),
|
|
40
|
+
...(m.displayPer !== undefined ? { displayPer: m.displayPer } : {}),
|
|
41
|
+
...(m.displayUsd !== undefined ? { displayUsd: m.displayUsd } : {}),
|
|
42
|
+
...(m.displayText !== undefined ? { displayText: m.displayText } : {}),
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
45
|
return out;
|