@indigoai-us/hq-cli 5.62.2 → 5.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@
22
22
  * the caller's single active membership (same as `members.ts`).
23
23
  */
24
24
  import { Command } from "commander";
25
+ import { type BillingErrorPayload } from "../utils/billing-gate.js";
25
26
  /** Reasoning-effort values hq-pro accepts on `runtime-config`. */
26
27
  export declare const VALID_EFFORTS: Set<string>;
27
28
  /** Service-tier (speed) values hq-pro accepts on `runtime-config`. */
@@ -35,7 +36,9 @@ export declare const VALID_TIERS: Set<string>;
35
36
  export declare class AgentsHttpError extends Error {
36
37
  status: number;
37
38
  code?: string;
38
- constructor(status: number, message: string, code?: string);
39
+ /** hq-pro's billing envelope on a `402 billing_required` provision block. */
40
+ billing?: BillingErrorPayload;
41
+ constructor(status: number, message: string, code?: string, billing?: BillingErrorPayload);
39
42
  }
40
43
  /** Roster row from `GET /v1/agents` — a superset is returned; we keep what we render. */
41
44
  export interface CompanyAgentView {
@@ -79,6 +82,24 @@ export declare function agentsRequest<T>(opts: {
79
82
  body?: Record<string, unknown>;
80
83
  query?: Record<string, string>;
81
84
  }): Promise<T>;
85
+ /** Slugify an agent name into a lowercase, hyphen-separated slug. */
86
+ export declare function slugifyAgentName(name: string): string;
87
+ export interface ProvisionAgentInput {
88
+ companyUid: string;
89
+ name: string;
90
+ slug: string;
91
+ codexAuthMode: "subscription" | "apiKey";
92
+ provider?: "codex" | "grok";
93
+ codexApiKey?: string;
94
+ idempotencyKey: string;
95
+ title?: string;
96
+ description?: string;
97
+ }
98
+ export declare function provisionAgent(token: string, input: ProvisionAgentInput): Promise<{
99
+ uid?: string;
100
+ slug?: string;
101
+ [key: string]: unknown;
102
+ }>;
82
103
  export declare function listAgents(token: string, companyUid: string): Promise<CompanyAgentView[]>;
83
104
  export declare function getAgentStatus(token: string, agentUid: string): Promise<Record<string, unknown>>;
84
105
  export declare function patchAgentProfile(token: string, agentUid: string, patch: ProfilePatch): Promise<{
@@ -22,10 +22,12 @@
22
22
  * the caller's single active membership (same as `members.ts`).
23
23
  */
24
24
 
25
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8a374059-a137-5cce-94ad-9e2647fc37c5")}catch(e){}}();
25
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="581b1950-a9bc-50a4-b16b-6e6649e9db30")}catch(e){}}();
26
26
  import chalk from "chalk";
27
+ import { randomUUID } from "node:crypto";
27
28
  import { ensureCognitoToken } from "../utils/cognito-session.js";
28
29
  import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
30
+ import { AGENT_PRICE_CENTS, confirmChargeOrExit, parseBillingPayload, surfaceBillingRequired, } from "../utils/billing-gate.js";
29
31
  /** Reasoning-effort values hq-pro accepts on `runtime-config`. */
30
32
  export const VALID_EFFORTS = new Set([
31
33
  "minimal",
@@ -45,11 +47,14 @@ export const VALID_TIERS = new Set(["default", "priority"]);
45
47
  export class AgentsHttpError extends Error {
46
48
  status;
47
49
  code;
48
- constructor(status, message, code) {
50
+ /** hq-pro's billing envelope on a `402 billing_required` provision block. */
51
+ billing;
52
+ constructor(status, message, code, billing) {
49
53
  super(message);
50
54
  this.name = "AgentsHttpError";
51
55
  this.status = status;
52
56
  this.code = code;
57
+ this.billing = billing;
53
58
  }
54
59
  }
55
60
  /**
@@ -61,10 +66,26 @@ export async function agentsRequest(opts) {
61
66
  const res = await vaultApiFetch(opts);
62
67
  if (!res.ok) {
63
68
  const body = (await res.json().catch(() => ({})));
64
- throw new AgentsHttpError(res.status, body.error ?? body.message ?? res.statusText, body.code);
69
+ throw new AgentsHttpError(res.status, body.error ?? body.message ?? res.statusText, body.code, parseBillingPayload(body));
65
70
  }
66
71
  return (await res.json());
67
72
  }
73
+ /** Slugify an agent name into a lowercase, hyphen-separated slug. */
74
+ export function slugifyAgentName(name) {
75
+ return name
76
+ .toLowerCase()
77
+ .trim()
78
+ .replace(/[^a-z0-9]+/g, "-")
79
+ .replace(/^-+|-+$/g, "");
80
+ }
81
+ export async function provisionAgent(token, input) {
82
+ return agentsRequest({
83
+ token,
84
+ path: "/v1/agents",
85
+ method: "POST",
86
+ body: input,
87
+ });
88
+ }
68
89
  export async function listAgents(token, companyUid) {
69
90
  const data = await agentsRequest({
70
91
  token,
@@ -144,6 +165,79 @@ export function registerAgentsCommand(program) {
144
165
  // `hq agents --company acme list`.
145
166
  const companyOf = (sub) => sub.opts().company ??
146
167
  agents.opts().company;
168
+ agents
169
+ .command("provision <name>")
170
+ .alias("new")
171
+ .description("Provision a new cloud agent ($100/month — requires --yes)")
172
+ .option("--company <slug>", "Company slug (resolves to companyUid)")
173
+ .option("--slug <slug>", "Agent slug (defaults to a slug of <name>)")
174
+ .option("--provider <provider>", "Runtime: codex | grok (default codex)")
175
+ .option("--auth-mode <mode>", "Codex auth: subscription | apiKey (default subscription)", "subscription")
176
+ .option("--api-key-env <VAR>", "Env var holding the API key for --auth-mode apiKey (never pass the key as a flag)")
177
+ .option("--title <title>", "Org-chart job title")
178
+ .option("--description <text>", "Short description / bio")
179
+ .option("--yes", "Confirm the $100/month charge (required to provision)")
180
+ .action(async function (name, opts) {
181
+ try {
182
+ const authMode = opts.authMode === "apiKey" ? "apiKey" : "subscription";
183
+ const provider = opts.provider === "grok" ? "grok" : opts.provider ? "codex" : undefined;
184
+ // Resolve the API key from the environment (never from a flag value) when
185
+ // apiKey mode is requested — validated BEFORE the paid gate so we don't
186
+ // charge and then fail.
187
+ let codexApiKey;
188
+ if (authMode === "apiKey") {
189
+ const envVar = opts.apiKeyEnv;
190
+ if (!envVar) {
191
+ console.error(chalk.red("--auth-mode apiKey requires --api-key-env <VAR> naming the env var that holds the key."));
192
+ process.exit(1);
193
+ }
194
+ codexApiKey = process.env[envVar];
195
+ if (!codexApiKey) {
196
+ console.error(chalk.red(`Env var ${envVar} is empty or unset — no API key to use.`));
197
+ process.exit(1);
198
+ }
199
+ }
200
+ const token = await ensureCognitoToken();
201
+ const companyUid = await getCompanyUid(token, companyOf(this));
202
+ // Paid gate: print the monthly cost and require --yes before any call.
203
+ confirmChargeOrExit({
204
+ resource: "agent",
205
+ unitCents: AGENT_PRICE_CENTS,
206
+ yes: opts.yes,
207
+ });
208
+ const slug = opts.slug ?? slugifyAgentName(name);
209
+ try {
210
+ const result = await provisionAgent(token, {
211
+ companyUid,
212
+ name,
213
+ slug,
214
+ codexAuthMode: authMode,
215
+ ...(provider ? { provider } : {}),
216
+ ...(codexApiKey ? { codexApiKey } : {}),
217
+ idempotencyKey: `hq-cli-${randomUUID()}`,
218
+ ...(opts.title ? { title: opts.title } : {}),
219
+ ...(opts.description ? { description: opts.description } : {}),
220
+ });
221
+ const uid = typeof result.uid === "string" ? result.uid : slug;
222
+ console.log(chalk.green(`Provisioning started for agent "${name}".`));
223
+ console.log(chalk.dim(`Track setup: hq agents status ${uid} --company <slug>`));
224
+ }
225
+ catch (err) {
226
+ // No card on file → surface the shareable payment link instead of an
227
+ // opaque 402, then exit non-zero so scripts can react.
228
+ if (err instanceof AgentsHttpError &&
229
+ err.status === 402 &&
230
+ err.billing) {
231
+ await surfaceBillingRequired(token, err.billing);
232
+ process.exit(1);
233
+ }
234
+ throw err;
235
+ }
236
+ }
237
+ catch (err) {
238
+ fail(err);
239
+ }
240
+ });
147
241
  agents
148
242
  .command("list")
149
243
  .description("List the company's agents")
@@ -382,4 +476,4 @@ export function registerAgentsCommand(program) {
382
476
  });
383
477
  }
384
478
  //# sourceMappingURL=agents.js.map
385
- //# debugId=8a374059-a137-5cce-94ad-9e2647fc37c5
479
+ //# debugId=581b1950-a9bc-50a4-b16b-6e6649e9db30
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `hq billing` — inspect billing state and mint a card-capture link from the
3
+ * terminal. Backs the paid-provisioning gate (agents & Outposts): a user can
4
+ * check whether a card is on file, and proactively hand out the same Stripe
5
+ * hosted card-capture link that a `402 billing_required` would surface.
6
+ *
7
+ * Targets the hq-pro billing control plane on `DEFAULT_VAULT_API_URL` via the
8
+ * shared `vaultApiFetch` helper — the same routes the console billing surfaces
9
+ * call.
10
+ *
11
+ * Subcommands:
12
+ * hq billing status [--company <slug>] — subscription + card on file
13
+ * hq billing checkout [--company <slug>] [--personal] — mint a card-capture link
14
+ */
15
+ import { Command } from "commander";
16
+ export declare function registerBillingCommand(program: Command): void;
17
+ //# sourceMappingURL=billing.d.ts.map
@@ -0,0 +1,114 @@
1
+ /**
2
+ * `hq billing` — inspect billing state and mint a card-capture link from the
3
+ * terminal. Backs the paid-provisioning gate (agents & Outposts): a user can
4
+ * check whether a card is on file, and proactively hand out the same Stripe
5
+ * hosted card-capture link that a `402 billing_required` would surface.
6
+ *
7
+ * Targets the hq-pro billing control plane on `DEFAULT_VAULT_API_URL` via the
8
+ * shared `vaultApiFetch` helper — the same routes the console billing surfaces
9
+ * call.
10
+ *
11
+ * Subcommands:
12
+ * hq billing status [--company <slug>] — subscription + card on file
13
+ * hq billing checkout [--company <slug>] [--personal] — mint a card-capture link
14
+ */
15
+
16
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9a5d87b5-94d2-5893-8c48-af8db719fa05")}catch(e){}}();
17
+ import chalk from "chalk";
18
+ import { ensureCognitoToken } from "../utils/cognito-session.js";
19
+ import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
20
+ import { mintPaymentLink } from "../utils/billing-gate.js";
21
+ function fail(err) {
22
+ console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
23
+ process.exit(1);
24
+ }
25
+ async function getBillingSummary(token, companyUid) {
26
+ const res = await vaultApiFetch({
27
+ token,
28
+ path: "/v1/billing/summary",
29
+ query: { companyUid },
30
+ });
31
+ if (!res.ok) {
32
+ const body = (await res.json().catch(() => ({})));
33
+ throw new Error(body.error ?? body.message ?? res.statusText);
34
+ }
35
+ return (await res.json());
36
+ }
37
+ export function registerBillingCommand(program) {
38
+ const billing = program
39
+ .command("billing")
40
+ .description("Inspect billing and mint a card-capture link")
41
+ .option("--company <slug>", "Company slug (resolves to companyUid)");
42
+ const companyOf = (sub) => sub.opts().company ??
43
+ billing.opts().company;
44
+ billing
45
+ .command("status")
46
+ .description("Show subscription status and whether a card is on file")
47
+ .option("--company <slug>", "Company slug (resolves to companyUid)")
48
+ .option("--json", "Emit raw JSON")
49
+ .action(async function (opts) {
50
+ try {
51
+ const token = await ensureCognitoToken();
52
+ const companyUid = await getCompanyUid(token, companyOf(this));
53
+ const summary = await getBillingSummary(token, companyUid);
54
+ if (opts.json) {
55
+ process.stdout.write(JSON.stringify(summary, null, 2) + "\n");
56
+ return;
57
+ }
58
+ const sub = summary.subscriptionStatus ?? "none";
59
+ console.log(`${chalk.bold("Subscription")}: ${sub}`);
60
+ const pm = summary.defaultPaymentMethod;
61
+ if (pm?.present) {
62
+ const detail = pm.brand && pm.last4 ? `${pm.brand} ••••${pm.last4}` : "on file";
63
+ console.log(`${chalk.bold("Card")}: ${detail}`);
64
+ }
65
+ else {
66
+ console.log(`${chalk.bold("Card")}: ${chalk.yellow("no card on file")} — ` +
67
+ `run \`hq billing checkout\` to add one before provisioning paid resources.`);
68
+ }
69
+ }
70
+ catch (err) {
71
+ fail(err);
72
+ }
73
+ });
74
+ billing
75
+ .command("checkout")
76
+ .description("Mint a Stripe card-capture link (shareable) to add a card")
77
+ .option("--company <slug>", "Company slug (resolves to companyUid)")
78
+ .option("--personal", "Mint the link for your personal payer (Outposts) instead of a company")
79
+ .option("--json", "Emit raw JSON")
80
+ .action(async function (opts) {
81
+ try {
82
+ const token = await ensureCognitoToken();
83
+ let setup;
84
+ if (opts.personal) {
85
+ setup = {
86
+ payerType: "person",
87
+ path: "/v1/billing/checkout/person",
88
+ method: "POST",
89
+ };
90
+ }
91
+ else {
92
+ const companyUid = await getCompanyUid(token, companyOf(this));
93
+ setup = {
94
+ payerType: "company",
95
+ path: "/v1/billing/checkout/org",
96
+ method: "POST",
97
+ body: { companyUid },
98
+ };
99
+ }
100
+ const url = await mintPaymentLink(token, setup);
101
+ if (opts.json) {
102
+ process.stdout.write(JSON.stringify({ url }, null, 2) + "\n");
103
+ return;
104
+ }
105
+ console.log("Add a card here (safe to share with whoever owns billing):\n " +
106
+ chalk.cyan(url));
107
+ }
108
+ catch (err) {
109
+ fail(err);
110
+ }
111
+ });
112
+ }
113
+ //# sourceMappingURL=billing.js.map
114
+ //# debugId=9a5d87b5-94d2-5893-8c48-af8db719fa05
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9dbfcbea-adf6-5852-b0de-aa6ee4391615")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="09a00ce0-be62-5739-9816-042dda515518")}catch(e){}}();
3
3
  import chalk from "chalk";
4
4
  import { ensureCognitoToken } from "../utils/cognito-session.js";
5
5
  import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
@@ -267,9 +267,17 @@ export function resolveRevokeTargetToMembershipKey(arg, companyUid) {
267
267
  return arg;
268
268
  const detected = detectTarget(arg);
269
269
  if (detected?.type === "email") {
270
+ // Active agent guest memberships are personUid-keyed (agt_…#cmp_…), not
271
+ // email-keyed. Map machine emails to that key so revoke works after invite.
272
+ if (detected.isAgent) {
273
+ const local = detected.value.split("@")[0] ?? "";
274
+ const m = local.match(/^agt-(.+)$/i);
275
+ if (m)
276
+ return `agt_${m[1].toUpperCase()}#${companyUid}`;
277
+ }
270
278
  return `email:${detected.value}#${companyUid}`;
271
279
  }
272
- if (detected?.type === "person") {
280
+ if (detected?.type === "person" || detected?.type === "agent") {
273
281
  return `${detected.value}#${companyUid}`;
274
282
  }
275
283
  return arg;
@@ -623,4 +631,4 @@ export function registerMembersCommand(program) {
623
631
  });
624
632
  }
625
633
  //# sourceMappingURL=members.js.map
626
- //# debugId=9dbfcbea-adf6-5852-b0de-aa6ee4391615
634
+ //# debugId=09a00ce0-be62-5739-9816-042dda515518
@@ -21,11 +21,14 @@
21
21
  * and status routes that exist. Renaming an Outpost is not a backend capability.
22
22
  */
23
23
  import { Command } from "commander";
24
+ import { type BillingErrorPayload } from "../utils/billing-gate.js";
24
25
  /** A non-2xx from the `/outpost/*` control plane. Carries status + `step`. */
25
26
  export declare class OutpostHttpError extends Error {
26
27
  status: number;
27
28
  step?: string;
28
- constructor(status: number, message: string, step?: string);
29
+ /** hq-pro's billing envelope on a `402 billing_required` provision block. */
30
+ billing?: BillingErrorPayload;
31
+ constructor(status: number, message: string, step?: string, billing?: BillingErrorPayload);
29
32
  }
30
33
  /** Row summary from `GET /outpost/list`. */
31
34
  export interface OutpostSummary {
@@ -49,8 +52,22 @@ export declare function outpostRequest<T>(opts: {
49
52
  token: string;
50
53
  path: string;
51
54
  method?: string;
55
+ body?: Record<string, unknown>;
52
56
  query?: Record<string, string>;
53
57
  }): Promise<T>;
58
+ /**
59
+ * Provision the caller's Outpost. Sends the cached Cognito refresh token so the
60
+ * box can authenticate AS the caller (the same body the console's
61
+ * `provisionMyOutpost` sends). Idempotent server-side: a caller already at their
62
+ * per-person cap gets their existing box back rather than a duplicate. The
63
+ * refresh token is sent over HTTPS and NEVER printed.
64
+ */
65
+ export declare function provisionOutpost(token: string, input: {
66
+ refreshToken: string;
67
+ clientIp?: string;
68
+ diskSizeGb?: number;
69
+ agentRuntime?: "claude" | "codex";
70
+ }): Promise<Record<string, unknown>>;
54
71
  export declare function listOutposts(token: string): Promise<OutpostSummary[]>;
55
72
  export declare function getOutpostStatus(token: string, outpostId?: string): Promise<Record<string, unknown>>;
56
73
  export declare function enableCodex(token: string, outpostId?: string): Promise<Record<string, unknown>>;
@@ -21,19 +21,24 @@
21
21
  * and status routes that exist. Renaming an Outpost is not a backend capability.
22
22
  */
23
23
 
24
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b01c6828-502e-5f7a-b15c-acafef4fa143")}catch(e){}}();
24
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d99c091a-e57f-55a6-a666-fdc339c83aab")}catch(e){}}();
25
25
  import chalk from "chalk";
26
+ import { loadCachedTokens } from "@indigoai-us/hq-cloud";
26
27
  import { ensureCognitoToken } from "../utils/cognito-session.js";
27
28
  import { vaultApiFetch } from "../utils/vault-api.js";
29
+ import { OUTPOST_PRICE_CENTS, confirmChargeOrExit, parseBillingPayload, surfaceBillingRequired, } from "../utils/billing-gate.js";
28
30
  /** A non-2xx from the `/outpost/*` control plane. Carries status + `step`. */
29
31
  export class OutpostHttpError extends Error {
30
32
  status;
31
33
  step;
32
- constructor(status, message, step) {
34
+ /** hq-pro's billing envelope on a `402 billing_required` provision block. */
35
+ billing;
36
+ constructor(status, message, step, billing) {
33
37
  super(message);
34
38
  this.name = "OutpostHttpError";
35
39
  this.status = status;
36
40
  this.step = step;
41
+ this.billing = billing;
37
42
  }
38
43
  }
39
44
  /**
@@ -52,10 +57,30 @@ export async function outpostRequest(opts) {
52
57
  : typeof body.error === "string"
53
58
  ? body.error
54
59
  : res.statusText;
55
- throw new OutpostHttpError(res.status, message, body.step);
60
+ throw new OutpostHttpError(res.status, message, body.step, parseBillingPayload(body));
56
61
  }
57
62
  return (await res.json());
58
63
  }
64
+ /**
65
+ * Provision the caller's Outpost. Sends the cached Cognito refresh token so the
66
+ * box can authenticate AS the caller (the same body the console's
67
+ * `provisionMyOutpost` sends). Idempotent server-side: a caller already at their
68
+ * per-person cap gets their existing box back rather than a duplicate. The
69
+ * refresh token is sent over HTTPS and NEVER printed.
70
+ */
71
+ export async function provisionOutpost(token, input) {
72
+ return outpostRequest({
73
+ token,
74
+ path: "/outpost/provision",
75
+ method: "POST",
76
+ body: {
77
+ refreshToken: input.refreshToken,
78
+ ...(input.clientIp ? { clientIp: input.clientIp } : {}),
79
+ ...(input.diskSizeGb ? { diskSizeGb: input.diskSizeGb } : {}),
80
+ ...(input.agentRuntime ? { agentRuntime: input.agentRuntime } : {}),
81
+ },
82
+ });
83
+ }
59
84
  export async function listOutposts(token) {
60
85
  const data = await outpostRequest({
61
86
  token,
@@ -117,6 +142,68 @@ export function registerOutpostsCommand(program) {
117
142
  const outposts = program
118
143
  .command("outposts")
119
144
  .description("Manage your personal HQ Outposts (EC2 boxes)");
145
+ outposts
146
+ .command("provision")
147
+ .alias("create")
148
+ .description("Provision a new Outpost ($80/month — requires --yes)")
149
+ .option("--runtime <runtime>", "Agent runtime: claude | codex (default claude)")
150
+ .option("--disk <gb>", "Root disk size in GB (EC2 only)")
151
+ .option("--client-ip <ip>", "Your public IP for the box's SSH ingress (optional; server derives it otherwise)")
152
+ .option("--yes", "Confirm the $80/month charge (required to provision)")
153
+ .action(async function (opts) {
154
+ try {
155
+ const agentRuntime = opts.runtime === "codex"
156
+ ? "codex"
157
+ : opts.runtime
158
+ ? "claude"
159
+ : undefined;
160
+ let diskSizeGb;
161
+ if (opts.disk !== undefined) {
162
+ diskSizeGb = Number(opts.disk);
163
+ if (!Number.isFinite(diskSizeGb) || diskSizeGb <= 0) {
164
+ console.error(chalk.red(`Invalid --disk '${opts.disk}': must be a positive number of GB.`));
165
+ process.exit(1);
166
+ }
167
+ }
168
+ // Paid gate: print the monthly cost and require --yes before any call.
169
+ confirmChargeOrExit({
170
+ resource: "Outpost",
171
+ unitCents: OUTPOST_PRICE_CENTS,
172
+ yes: opts.yes,
173
+ });
174
+ // The box authenticates AS the caller using the cached refresh token —
175
+ // the same body the console sends. Never printed.
176
+ const refreshToken = loadCachedTokens()?.refreshToken;
177
+ if (!refreshToken) {
178
+ console.error(chalk.red("No cached session found — run `hq login` first, then re-run."));
179
+ process.exit(1);
180
+ }
181
+ const token = await ensureCognitoToken();
182
+ try {
183
+ await provisionOutpost(token, {
184
+ refreshToken,
185
+ ...(opts.clientIp ? { clientIp: opts.clientIp } : {}),
186
+ ...(diskSizeGb ? { diskSizeGb } : {}),
187
+ ...(agentRuntime ? { agentRuntime } : {}),
188
+ });
189
+ console.log(chalk.green("Provisioning started for your Outpost."));
190
+ console.log(chalk.dim("Track it: hq outposts status"));
191
+ }
192
+ catch (err) {
193
+ // No card on file → surface the shareable payment link, not an opaque 402.
194
+ if (err instanceof OutpostHttpError &&
195
+ err.status === 402 &&
196
+ err.billing) {
197
+ await surfaceBillingRequired(token, err.billing);
198
+ process.exit(1);
199
+ }
200
+ throw err;
201
+ }
202
+ }
203
+ catch (err) {
204
+ fail(err);
205
+ }
206
+ });
120
207
  outposts
121
208
  .command("list")
122
209
  .description("List every Outpost you own")
@@ -252,4 +339,4 @@ export function registerOutpostsCommand(program) {
252
339
  });
253
340
  }
254
341
  //# sourceMappingURL=outposts.js.map
255
- //# debugId=b01c6828-502e-5f7a-b15c-acafef4fa143
342
+ //# debugId=d99c091a-e57f-55a6-a666-fdc339c83aab
package/dist/main.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // MUST be first: guard the Node version before any dependency that needs a
6
6
  // Node 20+ API (e.g. util.styleText) or a newer native ABI is evaluated.
7
7
 
8
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d089113e-52b9-5313-a256-63f054d8e72a")}catch(e){}}();
8
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1cc9f0b6-d8a8-54ea-a85f-44437f67b856")}catch(e){}}();
9
9
  import "./node-preflight.js";
10
10
  import { Command } from "commander";
11
11
  import { initSentry, Sentry } from "./sentry.js";
@@ -56,6 +56,7 @@ import { registerCrmCommand } from "./commands/crm.js";
56
56
  import { registerCompanyCommand } from "./commands/company.js";
57
57
  import { registerAgentsCommand } from "./commands/agents.js";
58
58
  import { registerOutpostsCommand } from "./commands/outposts.js";
59
+ import { registerBillingCommand } from "./commands/billing.js";
59
60
  import { registerDbCommand } from "./commands/db.js";
60
61
  import { sanitizeArgv } from "./utils/feedback-diagnostics.js";
61
62
  import { environmentalFsErrorMessage } from "./utils/environmental-error.js";
@@ -209,6 +210,10 @@ registerAgentsCommand(program);
209
210
  // enable Codex on, refresh login for, and destroy your EC2 boxes via the hq-pro
210
211
  // /outpost/* control plane.
211
212
  registerOutpostsCommand(program);
213
+ // Billing (subcommand group — `hq billing …`). Check subscription/card state and
214
+ // mint a shareable Stripe card-capture link — the client side of the paid-
215
+ // provisioning gate for agents & Outposts.
216
+ registerBillingCommand(program);
212
217
  export async function runCli() {
213
218
  try {
214
219
  Sentry.addBreadcrumb({
@@ -269,4 +274,4 @@ export async function runCli() {
269
274
  }
270
275
  }
271
276
  //# sourceMappingURL=main.js.map
272
- //# debugId=d089113e-52b9-5313-a256-63f054d8e72a
277
+ //# debugId=1cc9f0b6-d8a8-54ea-a85f-44437f67b856
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Billing gate for paid provisioning (agents & Outposts).
3
+ *
4
+ * hq-pro enforces billing server-side: a provision call for a resource whose
5
+ * payer has no card on file returns `402` with a `billing` payload carrying a
6
+ * `setup` action that names EXACTLY which checkout endpoint to hit. That
7
+ * endpoint returns `{ url }` — a Stripe-hosted card-capture link.
8
+ *
9
+ * This module wires the client-side experience around that contract:
10
+ * 1. `confirmChargeOrExit` — print the monthly cost and require `--yes`
11
+ * BEFORE any paid provisioning call is made.
12
+ * 2. `surfaceBillingRequired` — when the backend answers `402 billing_required`,
13
+ * mint the card-capture link and print a plain, shareable message instead
14
+ * of an opaque failure.
15
+ * 3. `hq billing checkout` (see commands/billing.ts) reuses `mintPaymentLink`
16
+ * to hand out the same link proactively.
17
+ *
18
+ * Prices mirror the console's authoritative constants
19
+ * (hq-console `src/lib/billing-pricing.ts`): amounts are in the smallest
20
+ * currency unit (US cents) to match Stripe's wire shape.
21
+ */
22
+ /** Per-Agent monthly list price, in cents ($100.00 / agent / month). */
23
+ export declare const AGENT_PRICE_CENTS = 10000;
24
+ /** Per-Outpost monthly list price, in cents ($80.00 / Outpost / month). */
25
+ export declare const OUTPOST_PRICE_CENTS = 8000;
26
+ /** Render a cents amount as a `$X.YZ` USD string. */
27
+ export declare function formatUsd(cents: number): string;
28
+ /**
29
+ * The server-supplied "how to add a card" action on a `402 billing_required`.
30
+ * Mirrors hq-pro `src/billing/activation-billing.ts` `BillingSetupAction` and
31
+ * the console's `src/lib/billing-setup.ts`.
32
+ */
33
+ export interface BillingSetupAction {
34
+ payerType: "company" | "person";
35
+ path: "/v1/billing/checkout/org" | "/v1/billing/checkout/person";
36
+ method: "POST";
37
+ body?: {
38
+ companyUid?: string;
39
+ };
40
+ }
41
+ /** The `billing` envelope hq-pro attaches to a billing-blocked provision. */
42
+ export interface BillingErrorPayload {
43
+ status: string;
44
+ setup?: BillingSetupAction;
45
+ }
46
+ /** Narrow an unknown value to a usable `BillingSetupAction`. */
47
+ export declare function isBillingSetupAction(value: unknown): value is BillingSetupAction;
48
+ /** Pull a `BillingErrorPayload` out of a decoded hq-pro error body, if present. */
49
+ export declare function parseBillingPayload(body: unknown): BillingErrorPayload | undefined;
50
+ export type PaidResource = "agent" | "Outpost";
51
+ /**
52
+ * Gate a paid provisioning call behind an explicit, informed `--yes`. Prints the
53
+ * monthly charge in full prose (this is a paid, outward action — Auto-Clarity)
54
+ * and exits non-zero when the caller has not passed `--yes`. Returns normally
55
+ * once approved so the caller proceeds to provision.
56
+ */
57
+ export declare function confirmChargeOrExit(opts: {
58
+ resource: PaidResource;
59
+ unitCents: number;
60
+ quantity?: number;
61
+ yes?: boolean;
62
+ }): void;
63
+ /**
64
+ * Mint a Stripe-hosted card-capture link for a `BillingSetupAction`. Returns the
65
+ * hosted URL the payer opens to add a card. Throws on a non-2xx (the caller
66
+ * decides how to surface it) — never swallows.
67
+ */
68
+ export declare function mintPaymentLink(token: string, setup: BillingSetupAction): Promise<string>;
69
+ /**
70
+ * The provision was blocked because the payer has no card on file. Mint the
71
+ * card-capture link the backend pointed us at and print a plain, shareable
72
+ * message so the user can add a card (or hand the link to whoever owns billing)
73
+ * and re-run. Returns the URL, or `null` when the server gave no `setup` action
74
+ * to act on. Never prints tokens or secrets.
75
+ */
76
+ export declare function surfaceBillingRequired(token: string, billing: BillingErrorPayload): Promise<string | null>;
77
+ //# sourceMappingURL=billing-gate.d.ts.map