Files
hyperframes/packages/cli/src/commands/reverse/start.ts
T
Michael WangandClaude Opus 5.5 a6e6717f2a feat(cli): checkout links name the CLI and the skill that sent them (#7177)
* feat(skills): every published skill reports its own run

`hyperframes events --skill=<name>` exists so a skill can say it ran, but
only reverse-any-video and figma asked the agent to call it, so the other
skills' use was invisible. Each of the nine published skills now opens with
a one-line usage beacon naming itself. The line says what it sends (the
skill's name only) and that the telemetry opt-out applies. The router's
`init` line also passes `--skill=hyperframes`, so renders of new projects
carry the skill.

check-core-skills fails a core skill that lacks its own beacon; each core
skill's size budget grows by 192 B for the line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(cli): checkout links name the CLI and the skill that sent them

Only `billing subscribe` marked its pricing link `from=cli`, and the
terminal's Press-Enter Pro checkout sent no return page, so a purchase made
from the terminal looked like one made on the site. Now:

- `pageUrl` adds `utm_source=cli` and `skill`: the one named, else the
  project's own `authoringSkill` from hyperframes.json.
- `billing` takes `--skill`. The terminal Pro checkout returns to the plans
  page marked `from=cli&skill=...`, and retries without the return page if
  the server does not allow it.
- Pricing links the server hands back (reverse's upgrade link, a refused
  media call's link) gain `from=cli` and the skill when they lack them.
- The Pro gates name their skill: reverse -> reverse-any-video, templates ->
  style-sampling, paid media calls -> media-use, in the CLI's printed fix and
  in those skills' billing commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): report a refused checkout return page, and say where --skill goes

When the server refuses the terminal checkout's return page, the CLI still
sells Pro without it, but that purchase loses its CLI origin. A
cli_billing_checkout_return_refused event now makes that visible.

The --skill help said the skill is recorded with the purchase. It is sent
with the pricing link; the purchase itself does not store it yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 00:23:20 +00:00

114 lines
3.8 KiB
TypeScript

import { existsSync } from "node:fs";
import { defineCommand } from "../../utils/defineCommand.js";
import type { Example } from "../_examples.js";
import { jsonArg, runMeasure, videoArg } from "../../measure/command.js";
import { Fix } from "../../measure/media.js";
import {
reverseUpgradeUrl,
startReverseSession,
type ReverseSession,
type ReverseStart,
} from "../../heygen/reverse.js";
import {
projectConfigPath,
readProjectConfig,
recordProjectReverseSession,
} from "../../utils/projectConfig.js";
import { probeReport } from "../measure/probe.js";
export const examples: Example[] = [
[
"Note the run with HeyGen, save its session in the project, and probe the video",
"hyperframes reverse start ref.mp4 --dir my-rebuild",
],
["Resume inside an existing project", "hyperframes reverse start original.mp4"],
];
const SKILL = "reverse-any-video";
export function subscribeCommand(sessionId?: string): string {
return `npx hyperframes billing subscribe --feature reverse --skill ${SKILL}${sessionId ? ` --session ${sessionId}` : ""}`;
}
async function freeFields(session: ReverseSession) {
const link = await reverseUpgradeUrl(session);
return {
upgrade_url: link,
subscribe_command: link === null ? null : subscribeCommand(session.sessionId),
};
}
async function summary(started: ReverseStart, savedTo: string | undefined) {
if (!started.recorded) {
return {
signed_in: started.reason !== "not_signed_in",
plan: started.plan ?? null,
recorded: false,
...(started.plan === "free"
? { upgrade_url: await reverseUpgradeUrl(), subscribe_command: subscribeCommand() }
: {}),
};
}
const { session } = started;
return {
signed_in: true,
plan: session.plan === "unknown" ? null : session.plan,
recorded: true,
session_id: session.sessionId,
gate: session.gate,
saved_to: savedTo ?? null,
...(session.plan === "free" ? await freeFields(session) : {}),
};
}
async function refusalWhenServerBlocksFree(session: ReverseSession): Promise<Fix | undefined> {
if (session.gate !== "block" || session.plan !== "free") return undefined;
if ((await reverseUpgradeUrl(session)) === null) {
return new Fix(
"Reverse is part of HyperFrames Pro, and a plan can't be purchased right now.",
"Run reverse start again once this account is on Pro.",
);
}
const command = subscribeCommand(session.sessionId);
return new Fix(
`Reverse is part of HyperFrames Pro. Run \`${command}\`, then run reverse start again.`,
command,
);
}
export default defineCommand({
meta: {
name: "start",
description:
"Note a reverse run with HeyGen (signed in: saves its session in the project), then print the video's probe; stops only when HeyGen blocks a Free account",
},
args: {
video: videoArg,
dir: {
type: "string",
description:
"Project folder that keeps the session in hyperframes.json (created when absent; init keeps it). Default: the current folder, when it is a project",
},
json: jsonArg,
},
async run({ args }) {
await runMeasure(async () => {
const probe = probeReport(String(args.video));
const dir = args.dir === undefined ? undefined : String(args.dir);
const projectDir = dir ?? ".";
const started = await startReverseSession({
resumeSessionId: readProjectConfig(projectDir)?.reverseSessionId,
});
const save = started.recorded && (dir !== undefined || existsSync(projectConfigPath(".")));
const savedTo = save
? recordProjectReverseSession(projectDir, started.session.sessionId, SKILL)
: undefined;
const refused = started.recorded
? await refusalWhenServerBlocksFree(started.session)
: undefined;
if (refused) throw refused;
return { reverse: await summary(started, savedTo), ...probe };
});
},
});