From b2e6076b7e7f73debadd1ac91a5b64ea2c4d3ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 16 Nov 2026 06:50:49 +0000 Subject: [PATCH] feat(cli): show and open the page to manage or cancel a paid plan (#7784) * feat(cli): show and open the page to manage or cancel a paid plan * chore(cli): drop two comments the names already carry --- docs/packages/cli.mdx | 7 ++++ .../cli/src/commands/auth/status-user.test.ts | 1 + packages/cli/src/commands/auth/status.ts | 9 ++--- packages/cli/src/commands/billing.test.ts | 35 +++++++++++++++++++ packages/cli/src/commands/billing.ts | 20 +++++++++-- packages/cli/src/help.ts | 2 +- packages/cli/src/heygen/plan.test.ts | 10 ++++++ packages/cli/src/heygen/plan.ts | 10 ++++-- 8 files changed, 84 insertions(+), 10 deletions(-) diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index 7d3b55e0ea..9d6e35b0b0 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -2547,13 +2547,20 @@ account shows the change, so an agent's run carries on by itself. The page is on the web app at hyperframes.studio. `HYPERFRAMES_PLANS_URL` and `HYPERFRAMES_CREDITS_URL` point it at another page. +With no action it shows your plan and, on a paid plan, the page where you manage or cancel it +(hyperframes.studio/billing, `HYPERFRAMES_BILLING_URL` points it elsewhere). `--manage` opens that page; +when no one is at the terminal it prints the link instead. + ```bash +npx hyperframes billing +npx hyperframes billing --manage npx hyperframes billing subscribe npx hyperframes billing add-credits --needed 180 ``` | Flag | Description | | ----------- | -------------------------------------------------------------------------- | +| `--manage` | Open the page to manage or cancel your plan | | `--needed` | Credits the waiting step needs; `add-credits` waits until the balance covers it | | `--feature` | The feature that sent the person here, so a purchase is credited to it | | `--session` | The run to credit the purchase to, with `--feature` | diff --git a/packages/cli/src/commands/auth/status-user.test.ts b/packages/cli/src/commands/auth/status-user.test.ts index ad861d339c..cd1265aca3 100644 --- a/packages/cli/src/commands/auth/status-user.test.ts +++ b/packages/cli/src/commands/auth/status-user.test.ts @@ -168,6 +168,7 @@ describe("auth status — persisted user block surface", () => { const text = stdout.join("\n"); expect(text).toContain("pro plan, 25,000 credits"); expect(text).not.toContain("balance unavailable"); + expect(text).toMatch(/^Manage or cancel your plan: https:\/\/hyperframes\.studio\/billing\?/m); }); it("surfaces the persisted user block (with resolved display_name) for a file credential", async () => { diff --git a/packages/cli/src/commands/auth/status.ts b/packages/cli/src/commands/auth/status.ts index 74bbb6aed2..bc45bbdbb9 100644 --- a/packages/cli/src/commands/auth/status.ts +++ b/packages/cli/src/commands/auth/status.ts @@ -32,7 +32,7 @@ import { import { refreshIfNeeded } from "../../cloud/auth.js"; import { getSystemMeta } from "../../telemetry/system.js"; import { c } from "../../ui/colors.js"; -import { pageUrl, readPlan, type Plan } from "../../heygen/plan.js"; +import { MANAGE_LABEL, pageUrl, readPlan, type Plan } from "../../heygen/plan.js"; import { resolveMusic, resolveVoice } from "../../audio/providers.js"; import { buildUnconfiguredJson, @@ -66,7 +66,7 @@ interface VerifiedStatus { apiError: string | null; /** The HyperFrames plan and credits, when the server (or the mock) answers. */ plan?: Plan | null; - upgradeUrl?: string; + planUrl?: string; } /** True for credentials resolved from the HyperFrames store (not env). */ @@ -284,7 +284,7 @@ function persistedUserJson(u: StoredUserInfo | null): Record | async function printHumanStatus(s: VerifiedStatus): Promise { const rows = collectStatusRows({ ...s, - ...(s.plan?.plan === "none" ? { upgradeUrl: await pageUrl("plans") } : {}), + ...(s.plan ? { planUrl: await pageUrl(s.plan.plan === "none" ? "plans" : "manage") } : {}), }); for (const [label, value] of rows) console.log(`${c.bold(label)} ${value}`); } @@ -311,9 +311,10 @@ function collectStatusRows(s: VerifiedStatus): [string, string][] { rows.push([ "HyperFrames:", plan.plan === "none" - ? `Free · Upgrade to Pro: ${s.upgradeUrl}${tag}` + ? `Free · Upgrade to Pro: ${s.planUrl}${tag}` : `${plan.plan} plan, ${plan.credits.toLocaleString("en-US")} credits${tag}`, ]); + if (plan.plan !== "none" && s.planUrl) rows.push([MANAGE_LABEL, s.planUrl]); } return rows; } diff --git a/packages/cli/src/commands/billing.test.ts b/packages/cli/src/commands/billing.test.ts index 8cc56a6306..cdffb98825 100644 --- a/packages/cli/src/commands/billing.test.ts +++ b/packages/cli/src/commands/billing.test.ts @@ -177,6 +177,41 @@ describe("billing add-credits", () => { }); }); +describe("billing with no action", () => { + const printed = async (rawArgs: string[], read: { plan: string; credits: number } | null) => { + held.reads = [read]; + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + await runCommand(billing, { rawArgs }); + return log.mock.calls.flat().join("\n"); + }; + const MANAGE = + /^Manage or cancel your plan: https:\/\/hyperframes\.studio\/billing\?from=cli&utm_source=cli&workspace_hint=sp-1$/m; + + it("shows a paid plan and the page that manages or cancels it, opening nothing", async () => { + const out = await printed([], { plan: "pro", credits: 500 }); + expect(out).toContain("HyperFrames: pro plan, 500 credits"); + expect(out).toMatch(MANAGE); + expect(opened).toEqual([]); + }); + + it("shows Free with no manage line", async () => { + const out = await printed([], { plan: "none", credits: 0 }); + expect(out).toContain("HyperFrames: Free"); + expect(out).not.toContain("Manage or cancel"); + }); + + it("--manage opens that page at a terminal", async () => { + terminal.attended = true; + expect(await printed(["--manage"], { plan: "pro", credits: 500 })).toMatch(MANAGE); + expect(new URL(opened[0] ?? "").pathname).toBe("/billing"); + }); + + it("--manage only prints the link when no one is at the terminal", async () => { + expect(await printed(["--manage"], null)).toMatch(MANAGE); + expect(opened).toEqual([]); + }); +}); + describe("billing without a terminal", () => { it("prints Stripe's checkout link instead of waiting for Enter, and opens only the pricing page", async () => { const log = vi.spyOn(console, "log").mockImplementation(() => undefined); diff --git a/packages/cli/src/commands/billing.ts b/packages/cli/src/commands/billing.ts index 30bde60bcb..1a42736ad1 100644 --- a/packages/cli/src/commands/billing.ts +++ b/packages/cli/src/commands/billing.ts @@ -4,6 +4,7 @@ import { addonBlocks, checkoutSkill, createCheckout, + MANAGE_LABEL, money, pageUrl, readOffer, @@ -128,15 +129,29 @@ function reportCheckoutFailure(error: unknown): CheckoutError | null { return error; } +async function showPlan(open: boolean): Promise { + const plan = await readPlan(); + console.log(`HyperFrames: ${plan ? describe(plan) : "plan unavailable"}`); + if (plan?.plan === "none" && !open) return; + const url = await pageUrl("manage"); + console.log(`${MANAGE_LABEL} ${c.accent(url)}`); + if (open && !isUnattended()) await openBrowser(url); +} + /** Opens the plans or credits page, then waits until the account shows the change, so the run continues on its own. */ export default defineCommand({ meta: { name: "billing", description: - "Open the HyperFrames plans page (subscribe) or buy add-on credits, used separately from your plan's monthly credits (add-credits), and wait until the person is done", + "Show your HyperFrames plan and where to manage or cancel it (--manage opens that page), open the plans page (subscribe) or buy add-on credits, used separately from your plan's monthly credits (add-credits), and wait until the person is done", }, args: { - action: { type: "positional", description: "subscribe | add-credits", required: true }, + action: { type: "positional", description: "subscribe | add-credits", required: false }, + manage: { + type: "boolean", + description: + "Open the page to manage or cancel your plan (prints the link when no one is at the terminal)", + }, needed: { type: "string", description: "Credits the waiting step needs (add-credits waits until the balance covers it)", @@ -156,6 +171,7 @@ export default defineCommand({ }, // fallow-ignore-next-line complexity async run({ args }) { + if (args.action === undefined) return showPlan(args.manage === true); const action = String(args.action); if (action !== "subscribe" && action !== "add-credits") { console.error(c.error("Use `billing subscribe` or `billing add-credits`.")); diff --git a/packages/cli/src/help.ts b/packages/cli/src/help.ts index 971fddbb47..547c64d191 100644 --- a/packages/cli/src/help.ts +++ b/packages/cli/src/help.ts @@ -66,7 +66,7 @@ const GROUPS: Group[] = [ "Measure a video file: clock, cuts, events, frames, motion, crops, boxes, eases, look", ], ["reverse", "Open a reverse-any-video run: note it with HeyGen, then probe the video"], - ["billing", "Open the HyperFrames plans or credits page and wait until it is done"], + ["billing", "Show your plan and where to manage or cancel it, or buy a plan or credits"], ["templates", "Pull a style template into this project (HyperFrames Pro)"], ["info", "Print project metadata"], ["compositions", "List all compositions in a project"], diff --git a/packages/cli/src/heygen/plan.test.ts b/packages/cli/src/heygen/plan.test.ts index 8ccf455030..b0d7b83933 100644 --- a/packages/cli/src/heygen/plan.test.ts +++ b/packages/cli/src/heygen/plan.test.ts @@ -81,6 +81,16 @@ describe("pageUrl", () => { expect(await pageUrl("plans")).toBe("https://example.test/plans?from=cli&utm_source=cli"); }); + it("links the page that manages or cancels the plan, outside the app", async () => { + signedOut(); + vi.stubEnv("HYPERFRAMES_BILLING_URL", ""); + expect(await pageUrl("manage")).toBe( + "https://hyperframes.studio/billing?from=cli&utm_source=cli", + ); + vi.stubEnv("HYPERFRAMES_BILLING_URL", "https://example.test/billing"); + expect(await pageUrl("manage")).toBe("https://example.test/billing?from=cli&utm_source=cli"); + }); + it("carries the workspace the sign-in is bound to on every link, read from account.get", async () => { signedInAs(SPACE); vi.stubEnv("HYPERFRAMES_PLANS_URL", ""); diff --git a/packages/cli/src/heygen/plan.ts b/packages/cli/src/heygen/plan.ts index 9e06e55d52..09617e8fa9 100644 --- a/packages/cli/src/heygen/plan.ts +++ b/packages/cli/src/heygen/plan.ts @@ -74,6 +74,10 @@ export async function readPlan(stop?: AbortSignal): Promise { const webBase = () => "https://hyperframes.studio"; const plansUrl = () => process.env["HYPERFRAMES_PLANS_URL"] || `${webBase()}/pricing`; const creditsUrl = () => process.env["HYPERFRAMES_CREDITS_URL"] || `${webBase()}/pricing`; +const manageUrl = () => process.env["HYPERFRAMES_BILLING_URL"] || `${webBase()}/billing`; +const PAGES = { plans: plansUrl, credits: creditsUrl, manage: manageUrl }; + +export const MANAGE_LABEL = "Manage or cancel your plan:"; async function signedInSpace(): Promise { try { @@ -104,9 +108,9 @@ export function cliCheckoutLink(link: string, skill = checkoutSkill()): string { return url.toString(); } -/** A plans or credits page link with what the web side reads, incl. the signed-in `workspace_hint`. */ +/** A plans, credits or plan-management page link with what the web side reads, incl. the signed-in `workspace_hint`. */ export async function pageUrl( - kind: "plans" | "credits", + kind: keyof typeof PAGES, fields: { needed?: number; tool?: string; @@ -116,7 +120,7 @@ export async function pageUrl( base?: string; } = {}, ): Promise { - const url = new URL(fields.base ?? (kind === "plans" ? plansUrl() : creditsUrl())); + const url = new URL(fields.base ?? PAGES[kind]()); url.searchParams.set("from", "cli"); url.searchParams.set("utm_source", "cli"); const skill = checkoutSkill(fields.skill);