Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

feat: emit the markup that reuses an accepted Record

rponedf5091331a05
diff --git a/packages/cli/src/archive.ts b/packages/cli/src/archive.ts
index 1db9c5e7..590c3ce6 100644
--- a/packages/cli/src/archive.ts
+++ b/packages/cli/src/archive.ts
@@ -269,3 +269,41 @@ export function summarizeBuildCatalog(catalog: BuildCatalogEntry, state?: BuildS
.map((alias) => alias.name),
};
}
+
+export type PinnedRecord = {
+ readonly output: string;
+ readonly build: string;
+ readonly candidate: string;
+ readonly markup: readonly string[];
+};
+
+/**
+ * The Run Source markup that selects an already accepted Record.
+ *
+ * Reuse is authored, never implied, so these pairs have to exist before a rerun will use what a
+ * previous Build produced. Written by eye from a Build id and an output name, the transcription is
+ * where an accepted Record quietly becomes a second paid generation.
+ *
+ * Entries are expected newest first; the first appearance of each output name wins.
+ */
+export function pinnedRecords(
+ entries: readonly { readonly build: string; readonly output: { readonly name: string } }[],
+): readonly PinnedRecord[] {
+ const seen = new Set<string>();
+ const pinned: PinnedRecord[] = [];
+ for (const entry of entries) {
+ if (seen.has(entry.output.name)) continue;
+ seen.add(entry.output.name);
+ const candidate = `record-${entry.output.name.replace(/[^a-zA-Z0-9]+/gu, "-").replace(/^-|-$/gu, "")}`;
+ pinned.push({
+ output: entry.output.name,
+ build: entry.build,
+ candidate,
+ markup: [
+ `<build-record id="${candidate}" build="${entry.build}" output="${entry.output.name}"/>`,
+ `<satisfy output="${entry.output.name}" candidate="${candidate}"/>`,
+ ],
+ });
+ }
+ return pinned;
+}
diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts
index ecd1f7fc..ac3e2297 100644
--- a/packages/cli/src/index.ts
+++ b/packages/cli/src/index.ts
@@ -1,4 +1,5 @@
-export { materializeArtifact, materializeRecord } from "./archive.js";
+export { materializeArtifact, materializeRecord, pinnedRecords } from "./archive.js";
+export type { PinnedRecord } from "./archive.js";
export { runCli } from "./main.js";
export { discoverSourcePackages } from "./source-discovery.js";
export { hypitHostStateRoot, hypitProjectStateRoot } from "./paths.js";
diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts
index e40c1325..88767f6a 100644
--- a/packages/cli/src/main.ts
+++ b/packages/cli/src/main.ts
@@ -16,6 +16,7 @@ import {
inspectBuild,
materializeArtifact,
materializeRecord,
+ pinnedRecords,
selectArchivedRecord,
summarizeBuildCatalog,
} from "./archive.js";
@@ -52,6 +53,8 @@ type ParsedArgs = {
readonly packageRoot: string | undefined;
readonly runtime: string | undefined;
readonly follow: boolean;
+ /** Emit the Run Source markup that reuses these Records instead of listing them. */
+ readonly pin: boolean;
readonly maxWaitMs: number | undefined;
readonly record: string | undefined;
readonly output: string | undefined;
@@ -118,6 +121,7 @@ function parseArgs(argv: readonly string[]): ParsedArgs {
let packageRoot: string | undefined;
let runtime: string | undefined;
let follow = false;
+ let pin = false;
let maxWaitMs: number | undefined;
let record: string | undefined;
let output: string | undefined;
@@ -280,6 +284,10 @@ function parseArgs(argv: readonly string[]): ParsedArgs {
follow = true;
continue;
}
+ if (item === "--pin") {
+ pin = true;
+ continue;
+ }
if (item === "--no-programs") {
noPrograms = true;
continue;
@@ -340,6 +348,7 @@ function parseArgs(argv: readonly string[]): ParsedArgs {
packageRoot,
runtime,
follow,
+ pin,
maxWaitMs,
record,
output,
@@ -407,7 +416,7 @@ function assertCommandOptions(args: ParsedArgs): void {
case "history":
case "inspect":
add("--runtime");
- if (args.command === "history") add("--source");
+ if (args.command === "history") add("--source", "--pin");
break;
case "check":
case "plan":
@@ -445,7 +454,7 @@ function usage(): string {
" hypit build <run-source> [--runtime profile.json] [--workspace workspace] [--asset-root directory] [--follow] [--no-programs]",
" hypit status <build-id> [--runtime profile.json] [--watch]",
" hypit builds [--runtime profile.json]",
- " hypit history [source-output-name] [--runtime profile.json] [--source author.svml]",
+ " hypit history [source-output-name] [--runtime profile.json] [--source author.svml] [--pin]",
" hypit inspect <build-id> [--runtime profile.json]",
" hypit get <build-id> [--runtime profile.json] [--name source-name|--record record-id|--output logical-output-id|--artifact digest] [--to path]",
" hypit cancel <build-id> [--runtime profile.json] [--reason text]",
@@ -1338,16 +1347,24 @@ export async function runCli(
...(args.file === undefined ? {} : { output: args.file }),
...(args.source === undefined ? {} : { source: args.source }),
};
+ const pins = args.pin ? pinnedRecords(entries) : [];
const shown = entries.slice(0, args.verbose ? undefined : 20);
- writeOperational({ query, entries }, entries.length === 0 ? "No accepted output history" : "Output history",
+ writeOperational({ query, entries, ...(args.pin ? { pins } : {}) },
+ entries.length === 0 ? "No accepted output history" : args.pin ? "Reuse these Records" : "Output history",
entries.length === 0 ? "warning" : "info", [
...(args.file === undefined ? [] : [["Output", args.file] as const]),
...(args.source === undefined ? [] : [["Source", args.source] as const]),
["Records", String(entries.length)],
- ], shown.map((item) => {
- const created = new Date(item.createdAt).toISOString();
- return `${item.build}: ${item.output.name} · ${created} · ${item.output.record.id}`;
- }));
+ ...(args.pin ? [["Outputs pinned", String(pins.length)] as const] : []),
+ ], args.pin
+ ? [
+ "Paste into a Run Source; the newest accepted Record of each output is selected.",
+ ...pins.flatMap((item) => item.markup),
+ ]
+ : shown.map((item) => {
+ const created = new Date(item.createdAt).toISOString();
+ return `${item.build}: ${item.output.name} · ${created} · ${item.output.record.id}`;
+ }));
} else if (args.command === "status") {
let status = await runtime.status(args.file!);
if (args.watch && status.build !== undefined && status.dispatch !== undefined) {
diff --git a/packages/cli/test/pin.test.ts b/packages/cli/test/pin.test.ts
new file mode 100644
index 00000000..1ae68909
--- /dev/null
+++ b/packages/cli/test/pin.test.ts
@@ -0,0 +1,28 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { parseRunDocument } from "@hypit/run-markup";
+
+import { pinnedRecords } from "../src/archive.js";
+
+test("pinned Records emit Run Source markup that parses, one per output", () => {
+ const pins = pinnedRecords([
+ { build: "bld_newest", output: { name: "paper.image" } },
+ { build: "bld_older", output: { name: "paper.image" } },
+ { build: "bld_other", output: { name: "apple-plate.image" } },
+ ]);
+ assert.deepEqual(pins.map((item) => item.output), ["paper.image", "apple-plate.image"]);
+ assert.equal(pins[0]!.build, "bld_newest", "the newest accepted Record of an output is the one selected");
+
+ const document = [
+ `<svrun version="1">`,
+ ` <author source="./main.svml"/>`,
+ ` <target output="final.video"/>`,
+ ...pins.flatMap((item) => item.markup).map((line) => ` ${line}`),
+ `</svrun>`,
+ ].join("\n");
+ // Emitting markup nobody can parse would be worse than emitting nothing, because it reads as done.
+ const parsed = parseRunDocument("pin.svrun", document);
+ assert.equal(parsed.candidates.length, 2);
+ assert.equal(parsed.satisfactions.length, 2);
+});