@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
package/dist/commands/sources.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { randomUUID } from "node:crypto";
|
|
24
24
|
import * as fs from "node:fs";
|
|
25
25
|
import * as path from "node:path";
|
|
26
|
-
import { InvalidArgumentError } from "commander";
|
|
26
|
+
import { InvalidArgumentError, Option } from "commander";
|
|
27
27
|
import chalk from "chalk";
|
|
28
28
|
import { printDeletedCompanyNotices } from "../utils/deleted-company-notice.js";
|
|
29
29
|
import { SOURCE_CHANNELS, assertSourceChannel, resolveEntity, listAvailableEntities, listSources, getSource, VaultClient, } from "@indigoai-us/hq-cloud";
|
|
@@ -35,7 +35,7 @@ import { Sentry } from "../sentry.js";
|
|
|
35
35
|
import { resolveUploadAuthor } from "../utils/upload-author.js";
|
|
36
36
|
import { createSignalsAlertChannelPoster, raiseSignalsFailureAlerts } from "../lib/hot-channels/alert.js";
|
|
37
37
|
import { audienceKey } from "../lib/hot-channels/audience.js";
|
|
38
|
-
import { appendRunLedgerEntry, ledgerDay, readRunLedger, summarizeRunLedger, } from "../lib/hot-channels/ledger.js";
|
|
38
|
+
import { appendRunLedgerEntry, ledgerDay, readRunLedger, RUN_TRIGGERS, summarizeRunLedger, } from "../lib/hot-channels/ledger.js";
|
|
39
39
|
import { createClaudeSignalsPass, DEFAULT_MAX_SIGNAL_DOCS, readPendingSignals, SignalsPassError, } from "../lib/hot-channels/signals-pass.js";
|
|
40
40
|
import { backlogRunResult, parseSince, queueSignalsRedo, selectSignalsRedo, SignalsRedoUsageError, } from "../lib/hot-channels/signals-redo.js";
|
|
41
41
|
import { assertSafeSegment } from "../lib/hot-channels/landing.js";
|
|
@@ -47,6 +47,8 @@ import { createPersonVaultReader } from "../lib/hot-channels/person-vault-reader
|
|
|
47
47
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
48
48
|
import { resolveCanonicalPersonUid } from "./cloud.js";
|
|
49
49
|
import { botsRoot as defaultBotsRoot } from "../lib/bot/paths.js";
|
|
50
|
+
// The same main-bot runtime the signals engine's extract step uses.
|
|
51
|
+
import { defaultResolveBotRuntime } from "../lib/signals/steps/extract.js";
|
|
50
52
|
import { ensureHotSignalSyncJob } from "../lib/bot/jobs/hot-signal-sync.js";
|
|
51
53
|
import { resolveExecutiveBot } from "../lib/bot/executive.js";
|
|
52
54
|
import { companyOfHotSignalSyncJob, fleetCronOps } from "../lib/bot/fleet-cron.js";
|
|
@@ -589,8 +591,8 @@ async function runLockedCompanySync(input, vaultRoot, personKey, author, session
|
|
|
589
591
|
}
|
|
590
592
|
/**
|
|
591
593
|
* Run every hot channel for the signed-in person now: each adapter once per
|
|
592
|
-
* usable connection. Writes cursors, landed sources and
|
|
593
|
-
*
|
|
594
|
+
* usable connection. Writes cursors, landed sources and a ledger line (trigger
|
|
595
|
+
* `on-demand` unless `--trigger` says `scheduled`) under `companies/{company}/sources/`, and nothing else.
|
|
594
596
|
*/
|
|
595
597
|
export async function runSync(options, overrides = {}) {
|
|
596
598
|
const company = options.company ?? readActiveCompanySlug(options.hqRoot);
|
|
@@ -601,10 +603,11 @@ export async function runSync(options, overrides = {}) {
|
|
|
601
603
|
hqRoot: options.hqRoot,
|
|
602
604
|
company,
|
|
603
605
|
...(options.adapter !== undefined ? { adapter: options.adapter } : {}),
|
|
606
|
+
...(options.trigger !== undefined ? { trigger: options.trigger } : {}),
|
|
604
607
|
...(overrides.registry ? { registry: overrides.registry } : {}),
|
|
605
608
|
...(overrides.now ? { now: overrides.now } : {}),
|
|
606
609
|
...(overrides.createSelections ? { createSelections: overrides.createSelections } : {}),
|
|
607
|
-
signalsGenerated: overrides.signalsGenerated ?? createClaudeSignalsPass({ hqRoot: options.hqRoot, company }),
|
|
610
|
+
signalsGenerated: overrides.signalsGenerated ?? createClaudeSignalsPass({ hqRoot: options.hqRoot, company, botRuntime: defaultResolveBotRuntime }),
|
|
608
611
|
// The CLI has no owner-DM sender: the terminal is the primary alert here.
|
|
609
612
|
signalsAlert: {
|
|
610
613
|
sendOwnerDm: async (text) => {
|
|
@@ -697,6 +700,7 @@ export async function runSignalsRedo(options, overrides = {}) {
|
|
|
697
700
|
pendingLeft: {},
|
|
698
701
|
notices: [...selection.notices],
|
|
699
702
|
error: null,
|
|
703
|
+
failedChannels: {},
|
|
700
704
|
exitCode: 0,
|
|
701
705
|
};
|
|
702
706
|
const channels = [...new Set([...selection.pending.keys(), ...selection.worklist.keys()])];
|
|
@@ -719,9 +723,23 @@ export async function runSignalsRedo(options, overrides = {}) {
|
|
|
719
723
|
});
|
|
720
724
|
const pass = overrides.createPass
|
|
721
725
|
? overrides.createPass(maxDocs)
|
|
722
|
-
: createClaudeSignalsPass({ hqRoot: options.hqRoot, company, maxDocs });
|
|
726
|
+
: createClaudeSignalsPass({ hqRoot: options.hqRoot, company, maxDocs, botRuntime: defaultResolveBotRuntime });
|
|
723
727
|
for (const channel of channels) {
|
|
724
|
-
|
|
728
|
+
try {
|
|
729
|
+
report.signalsWritten += await pass(backlogRunResult(channel), { beforeWrite: lock.assertHeld });
|
|
730
|
+
}
|
|
731
|
+
catch (err) {
|
|
732
|
+
// A pass failure on one channel does not skip the others, the way
|
|
733
|
+
// `hq sources sync` goes on to the next adapter. The signals this
|
|
734
|
+
// channel wrote before it failed still count. Any other error (a
|
|
735
|
+
// lost lock, a crash) stops the run below.
|
|
736
|
+
if (!(err instanceof SignalsPassError))
|
|
737
|
+
throw err;
|
|
738
|
+
report.signalsWritten += err.written;
|
|
739
|
+
report.failedChannels[channel] = err.code;
|
|
740
|
+
report.error ??= err.code;
|
|
741
|
+
report.exitCode = 1;
|
|
742
|
+
}
|
|
725
743
|
}
|
|
726
744
|
}
|
|
727
745
|
catch (err) {
|
|
@@ -774,8 +792,13 @@ function renderSignalsRedo(report) {
|
|
|
774
792
|
if (left > 0)
|
|
775
793
|
lines.push(`${left} document(s) still queued in sources/${channel}; the next run picks them up.`);
|
|
776
794
|
}
|
|
777
|
-
|
|
795
|
+
const failed = Object.entries(report.failedChannels);
|
|
796
|
+
for (const [channel, code] of failed) {
|
|
797
|
+
lines.push(chalk.red(`The signals pass for sources/${channel} failed: ${code}. Its queued documents stay queued.`));
|
|
798
|
+
}
|
|
799
|
+
if (report.error && !failed.some(([, code]) => code === report.error)) {
|
|
778
800
|
lines.push(chalk.red(`The signals pass stopped: ${report.error}. Queued documents stay queued.`));
|
|
801
|
+
}
|
|
779
802
|
}
|
|
780
803
|
return lines.join("\n");
|
|
781
804
|
}
|
|
@@ -912,6 +935,36 @@ async function finishScheduleReport(options, overrides, company, job, extraBots,
|
|
|
912
935
|
// ---------------------------------------------------------------------------
|
|
913
936
|
// Registration
|
|
914
937
|
// ---------------------------------------------------------------------------
|
|
938
|
+
function innerErrorText(value) {
|
|
939
|
+
if (value instanceof Error)
|
|
940
|
+
return typeof value.message === "string" ? value.message : "";
|
|
941
|
+
return typeof value === "string" ? value : "";
|
|
942
|
+
}
|
|
943
|
+
function describeThrownErrorUnguarded(err) {
|
|
944
|
+
if (!(err instanceof Error))
|
|
945
|
+
return String(err) || "an empty error";
|
|
946
|
+
const name = typeof err.name === "string" && err.name ? err.name : "Error";
|
|
947
|
+
if (typeof err.message !== "string")
|
|
948
|
+
return `${name} with an unreadable message`;
|
|
949
|
+
if (err.message.trim())
|
|
950
|
+
return err.message;
|
|
951
|
+
const label = [name];
|
|
952
|
+
const code = err.code;
|
|
953
|
+
if (typeof code === "string" && code)
|
|
954
|
+
label.push(code);
|
|
955
|
+
const members = err instanceof AggregateError ? err.errors : [err.cause];
|
|
956
|
+
const inner = Array.isArray(members) ? members : [];
|
|
957
|
+
const details = [...new Set(inner.map(innerErrorText).filter((m) => m.trim()))].slice(0, 3);
|
|
958
|
+
return `${label.join(" ")} with no message${details.length > 0 ? `: ${details.join("; ")}` : ""}`;
|
|
959
|
+
}
|
|
960
|
+
export function describeThrownError(err) {
|
|
961
|
+
try {
|
|
962
|
+
return describeThrownErrorUnguarded(err);
|
|
963
|
+
}
|
|
964
|
+
catch {
|
|
965
|
+
return "an error that could not be described";
|
|
966
|
+
}
|
|
967
|
+
}
|
|
915
968
|
/** Wrap an action so caught errors print red + capture to Sentry + exit 1. */
|
|
916
969
|
function withErrorHandling(fn) {
|
|
917
970
|
return async (...args) => {
|
|
@@ -919,7 +972,7 @@ function withErrorHandling(fn) {
|
|
|
919
972
|
await fn(...args);
|
|
920
973
|
}
|
|
921
974
|
catch (err) {
|
|
922
|
-
const message =
|
|
975
|
+
const message = describeThrownError(err);
|
|
923
976
|
process.stderr.write(chalk.red(`✗ ${message}\n`));
|
|
924
977
|
Sentry.captureException(err);
|
|
925
978
|
process.exit(1);
|
|
@@ -1009,6 +1062,9 @@ export function registerSourcesCommand(program) {
|
|
|
1009
1062
|
.option("--adapter <id>", "Run one adapter only (a catalog provider or adapter id)")
|
|
1010
1063
|
.option("--company <slug>", "Company slug (defaults to .hq/config.json activeCompany)")
|
|
1011
1064
|
.option("--json", "Print the run report as JSON")
|
|
1065
|
+
.addOption(new Option("--trigger <trigger>", "What the run ledger records as the trigger; the bot's daily job passes scheduled")
|
|
1066
|
+
.choices([...RUN_TRIGGERS])
|
|
1067
|
+
.default("on-demand"))
|
|
1012
1068
|
.option("--hq-root <path>", `Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`, DEFAULT_HQ_ROOT)
|
|
1013
1069
|
.action(withErrorHandling(async (options) => {
|
|
1014
1070
|
await runSync(options);
|
|
@@ -60,7 +60,10 @@ export async function runSyncHeld(deps, json = false) {
|
|
|
60
60
|
deps.log("No uploads are held on this computer.");
|
|
61
61
|
return 0;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
// First install also writes this hold (feedback_baa82c96). Do not say
|
|
64
|
+
// another account was signed in; that is often false and reads as a
|
|
65
|
+
// security scare. The hold is still a confirmation before upload.
|
|
66
|
+
deps.log("These uploads are held until you confirm they belong to the signed-in account on this computer:");
|
|
64
67
|
for (const scope of scopes)
|
|
65
68
|
for (const line of describe(scope))
|
|
66
69
|
deps.log(line);
|
|
@@ -172,7 +175,7 @@ export function createDefaultSyncHeldDeps() {
|
|
|
172
175
|
export function registerSyncHeldCommands(syncCmd) {
|
|
173
176
|
syncCmd
|
|
174
177
|
.command("held")
|
|
175
|
-
.description("Show uploads held
|
|
178
|
+
.description("Show uploads held until you confirm they belong to the signed-in account")
|
|
176
179
|
.option("--json", "Print the held scopes as JSON")
|
|
177
180
|
.action(async (options) => {
|
|
178
181
|
process.exitCode = await runSyncHeld(createDefaultSyncHeldDeps(), options.json === true);
|
package/dist/commands/whoami.js
CHANGED
|
@@ -10,6 +10,7 @@ import { resolveCompanyFlagGate, } from "../lib/flag-registry.js";
|
|
|
10
10
|
import { queuePlanLimitInviteTeammateExposure } from "../utils/cli-telemetry.js";
|
|
11
11
|
import { resolveCallerPersonUid } from "../utils/vault-api.js";
|
|
12
12
|
import { printDeletedCompanyNotices } from "../utils/deleted-company-notice.js";
|
|
13
|
+
import { authExpiryIso, formatAuthExpiry } from "../utils/auth-expiry.js";
|
|
13
14
|
export const CLI_LIMIT_INVITE_TEAMMATE_FLAG = "cli.limit-invite-teammate-v1";
|
|
14
15
|
/**
|
|
15
16
|
* Resolves the person represented by an ID token without pairing a delegated
|
|
@@ -151,10 +152,21 @@ async function printPlanBlock(company) {
|
|
|
151
152
|
queuePlanLimitInviteTeammateExposure(status.companyUid);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether the cached session is valid and when it expires: the line
|
|
157
|
+
* `hq auth status` printed, so one command answers "who am I and is my
|
|
158
|
+
* session good". Reads the expiry only; no token is printed.
|
|
159
|
+
*/
|
|
160
|
+
function sessionStatusLine(cached) {
|
|
161
|
+
const expiry = formatAuthExpiry(cached.expiresAt);
|
|
162
|
+
return isExpiring(cached)
|
|
163
|
+
? chalk.yellow(`HQ session cached but expiring (expiresAt=${expiry})`)
|
|
164
|
+
: chalk.green(`HQ session valid (expiresAt=${expiry})`);
|
|
165
|
+
}
|
|
154
166
|
export function registerWhoamiCommand(program) {
|
|
155
167
|
program
|
|
156
168
|
.command('whoami')
|
|
157
|
-
.description('Show
|
|
169
|
+
.description('Show signed-in user and session expiry')
|
|
158
170
|
.option('--json', 'Output identity metadata as JSON (never tokens)')
|
|
159
171
|
.option('--company <slug>', 'Also report this company\'s billing and usage notice')
|
|
160
172
|
.action(async (opts) => {
|
|
@@ -200,6 +212,11 @@ export function registerWhoamiCommand(program) {
|
|
|
200
212
|
personUid,
|
|
201
213
|
agentUid,
|
|
202
214
|
username: machineCreds?.username ?? null,
|
|
215
|
+
// Additive (what `hq auth status` reported): when the cached
|
|
216
|
+
// session expires, and whether it is inside the refresh window.
|
|
217
|
+
// Both are null when no session is cached.
|
|
218
|
+
sessionExpiresAt: identityCache ? authExpiryIso(identityCache.expiresAt) : null,
|
|
219
|
+
sessionExpiring: identityCache ? isExpiring(identityCache) : null,
|
|
203
220
|
planLimits,
|
|
204
221
|
}, null, 2));
|
|
205
222
|
return;
|
|
@@ -213,21 +230,29 @@ export function registerWhoamiCommand(program) {
|
|
|
213
230
|
? peekIdToken(cached.idToken).entityUid
|
|
214
231
|
: undefined;
|
|
215
232
|
console.log(`Machine identity ${username}${entityUid ? ` (agent ${entityUid})` : ''} — sessions mint automatically`);
|
|
233
|
+
// Machine tokens live in the daemon state dir, never ~/.hq.
|
|
234
|
+
const machineSession = loadMachineCachedTokens();
|
|
235
|
+
if (machineSession)
|
|
236
|
+
console.log(sessionStatusLine(machineSession));
|
|
216
237
|
console.log(`token source: machine`);
|
|
217
238
|
await printPlanBlock(opts.company);
|
|
218
239
|
return;
|
|
219
240
|
}
|
|
220
241
|
if (!cached) {
|
|
242
|
+
// No session, so no session status or token source to report.
|
|
221
243
|
console.log("Not logged in. Run 'hq login' to authenticate.");
|
|
222
244
|
return;
|
|
223
245
|
}
|
|
224
246
|
if (isExpiring(cached, 0)) {
|
|
225
247
|
const who = resolveWhoamiIdentity(peekIdToken(cached.idToken)).email ?? 'unknown';
|
|
226
248
|
console.log(chalk.yellow(`Session expired for ${who}. Run 'hq login' to re-authenticate.`));
|
|
249
|
+
console.log(chalk.dim('token source: person'));
|
|
227
250
|
return;
|
|
228
251
|
}
|
|
229
252
|
const { email, sub } = resolveWhoamiIdentity(peekIdToken(cached.idToken));
|
|
230
253
|
console.log(`Logged in as ${email ?? 'unknown'}${sub ? ` (${sub})` : ''}`);
|
|
254
|
+
console.log(sessionStatusLine(cached));
|
|
255
|
+
console.log(chalk.dim('token source: person'));
|
|
231
256
|
await printPlanBlock(opts.company);
|
|
232
257
|
// Person sessions only: a deleted company is otherwise invisible here.
|
|
233
258
|
// Bounded like the person-uid lookup, on stderr, and never a failure.
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
15
|
+
}
|
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
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Argument, Command, Option } from "commander";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
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
|
+
import { restoreRuntimeText } from "./utils/catalog-runtime-paths.js";
|
|
8
|
+
import { STILL_USE_FLAG } from "./utils/command-usage.js";
|
|
7
9
|
import { MissingRegistrationPlanError } from "./utils/registration-plan-error.js";
|
|
8
10
|
const commandCatalog = COMMAND_CATALOG;
|
|
9
11
|
/**
|
|
@@ -71,10 +73,7 @@ function commandDefinition(command) {
|
|
|
71
73
|
}
|
|
72
74
|
function restoreRuntimePath(value) {
|
|
73
75
|
if (typeof value === "string") {
|
|
74
|
-
|
|
75
|
-
if (restored.includes("<runtime-path>"))
|
|
76
|
-
restored = restored.replaceAll("<runtime-path>", runtimeHqRoot());
|
|
77
|
-
return restored;
|
|
76
|
+
return restoreRuntimeText(value, { home: homedir(), hqRoot: runtimeHqRoot }, sep);
|
|
78
77
|
}
|
|
79
78
|
if (Array.isArray(value))
|
|
80
79
|
return value.map(restoreRuntimePath);
|
|
@@ -123,7 +122,7 @@ function commandForToken(token) {
|
|
|
123
122
|
*/
|
|
124
123
|
export function findLazyCommand(argv) {
|
|
125
124
|
let commandIndex = 2;
|
|
126
|
-
while (argv[commandIndex] === "--verbose")
|
|
125
|
+
while (argv[commandIndex] === "--verbose" || argv[commandIndex] === STILL_USE_FLAG)
|
|
127
126
|
commandIndex += 1;
|
|
128
127
|
const first = argv[commandIndex];
|
|
129
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;
|