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.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
fix(results): keep forwards on finished owners
kashorinb834d45a09c8
diff --git a/docs/quickstart/run.md b/docs/quickstart/run.mdindex ca5b1c2e..30023591 100644--- a/docs/quickstart/run.md+++ b/docs/quickstart/run.md@@ -156,7 +156,8 @@ on `<build-record>` and use the current name on `<satisfy>`:Hypit never infers that two names mean the same author intent. Every `build` invocation receives afresh Build id and its own Result directory, even when nothing changed. A later Run reuses an Outputonly by naming the earlier Build id and Output here. If that earlier Output already forwards to an-older one, resolution follows the explicit chain; no bytes are copied into the new Result.+older one, Result storage resolves that explicit path once and records the new Forward directly to+the finished Result that owns the value; no bytes are copied and no reverse index is maintained.Forwarding applies only to a complete public Output. Structured JSON cannot recursively point atanother Output; a historical value consumed inside a new Fragment is an ordinary input and the newFragment's Output belongs to the current Result.diff --git a/packages/build-result-s3/README.md b/packages/build-result-s3/README.mdindex b5b3169b..4d93a94d 100644--- a/packages/build-result-s3/README.md+++ b/packages/build-result-s3/README.md@@ -37,8 +37,9 @@ domain data separate from the paths of nested Resources.Physical object prefixes use a reversible descending-time form derived from the ordered Build id, soS3 can return a newest-first delimiter page directly. This is only adapter key layout: callers stilladdress `build + output`, and no index object or global Build table exists. A reused historical Output is a-small forward reference to its producing Build and Output; following several such references still-reads the original file and does not upload another copy. While a Build is running, a private writer+small forward reference to the finished Result that owns its value. New references are reduced to that+terminal address as they are written, so repeated reuse still reads the original file without uploading+another copy or maintaining a reverse dependency index. While a Build is running, a private writerfile records only the state needed to continue publishing completed public Outputs and is removed whenthe Result receives its outcome.diff --git a/packages/build-result-s3/src/repository.ts b/packages/build-result-s3/src/repository.tsindex 6d47ccae..9e6d5bde 100644--- a/packages/build-result-s3/src/repository.ts+++ b/packages/build-result-s3/src/repository.ts@@ -20,6 +20,7 @@ import {decodeBuildResultValueDocument,decodeBuildResultWriterState,encodeBuildResultManifest,+ normalizeBuildResultForwards,syncBuildResultOutputs,} from "@hypit/build-result";import { assertOrderedBuildId, buildIdCreatedAt } from "@hypit/protocol";@@ -177,10 +178,7 @@ export class S3BuildResultRepository implements BuildResultRepository {assertOrderedBuildId(seed.id);assertBuildResultSeed(seed);assert((await this.read(seed.id)) === undefined, `Build Result ${seed.id} already exists`);- for (const forward of seed.forwards ?? []) {- assert(await this.resolve(forward.build, forward.sourceOutput) !== undefined,- `Build ${forward.build} has no Output ${forward.sourceOutput}`);- }+ const forwards = await normalizeBuildResultForwards(this, seed.forwards ?? []);const manifest: BuildResultManifest = {format: "hypit.build-result@2",id: seed.id,@@ -195,7 +193,7 @@ export class S3BuildResultRepository implements BuildResultRepository {resources: {},values: {},publishedOutputs: seed.publishedOutputs,- forwards: seed.forwards ?? [],+ forwards,});await this.writeManifest(seed.id, manifest);} catch (error) {@@ -210,7 +208,10 @@ export class S3BuildResultRepository implements BuildResultRepository {return (await this.read(build)) === undefined ? undefined : new S3BuildResultWriter(this, build);}- async remove(build: string): Promise<void> {+ async removeIncomplete(build: string): Promise<void> {+ const manifest = await this.read(build);+ if (manifest === undefined) return;+ assert(manifest.outcome === undefined, `Finished Build Result ${build} cannot be removed`);const prefix = this.#key(build, "result.json").slice(0, -"result.json".length);const keys = await this.#client.list(prefix);await Promise.all(keys.filter((key) => key.startsWith(prefix)).map(async (key) => await this.#client.delete(key)));diff --git a/packages/build-result-s3/test/repository.test.ts b/packages/build-result-s3/test/repository.test.tsindex 401022da..00cc7744 100644--- a/packages/build-result-s3/test/repository.test.ts+++ b/packages/build-result-s3/test/repository.test.ts@@ -282,7 +282,7 @@ test("S3 browses ordered Build ids newest first with a public cursor", async ()assert.equal(client.listRequests.at(-1)?.after?.endsWith(`-${ids[1]}/`), true);});-test("S3 forwarding can cross several Builds without copying the historical file", async () => {+test("S3 reduces repeated reuse to its finished content owner without copying bytes", async () => {const client = new MemoryS3();const repository = new S3BuildResultRepository({ bucket: "fixture", client });const bytes = new TextEncoder().encode("historical video");@@ -322,6 +322,25 @@ test("S3 forwarding can cross several Builds without copying the historical file},},});+ await assert.rejects(+ repository.create({+ id: "bld_20260902T100000002Z_0000000001",+ source: { path: "/project/main.svml" },+ targets: ["video"],+ publishedOutputs: [{ name: "video", output: "logical:video" }],+ forwards: [{+ output: "logical:video",+ build: "bld_20260902T100000001Z_0000000001",+ sourceOutput: "video",+ }],+ }),+ /is not a finished Result/u,+ );+ await original.finish({ outcome: "complete" });+ await assert.rejects(+ repository.removeIncomplete("bld_20260902T100000001Z_0000000001"),+ /cannot be removed/u,+ );const forward = async (id: string, fromBuild: string) => {const writer = await repository.create({@@ -331,7 +350,7 @@ test("S3 forwarding can cross several Builds without copying the historical filepublishedOutputs: [{ name: "video", output: "logical:video" }],forwards: [{ output: "logical:video", build: fromBuild, sourceOutput: "video" }],});- await writer.sync({+ const manifest = await writer.sync({state: state({status: "complete",records: [@@ -359,9 +378,19 @@ test("S3 forwarding can cross several Builds without copying the historical file},},});+ await writer.finish({ outcome: "complete" });+ return manifest;};await forward("bld_20260902T100000002Z_0000000001", "bld_20260902T100000001Z_0000000001");- await forward("bld_20260902T100000003Z_0000000001", "bld_20260902T100000002Z_0000000001");+ const forwardedAgain = await forward(+ "bld_20260902T100000003Z_0000000001",+ "bld_20260902T100000002Z_0000000001",+ );+ assert.deepEqual(forwardedAgain.outputs.video?.value, {+ kind: "build-output",+ build: "bld_20260902T100000001Z_0000000001",+ output: "video",+ });const described = await repository.describeOutput("bld_20260902T100000003Z_0000000001", "video");assert.equal(described?.kind, "resource");diff --git a/packages/build-result/src/index.ts b/packages/build-result/src/index.tsindex 1418bca1..4ad0dad6 100644--- a/packages/build-result/src/index.ts+++ b/packages/build-result/src/index.ts@@ -17,6 +17,7 @@ export {browseBuildResults,buildResultDirectory,describeBuildResultOutput,+ normalizeBuildResultForwards,readBuildResult,resolveBuildResultOutput,} from "./store.js";diff --git a/packages/build-result/src/store.ts b/packages/build-result/src/store.tsindex 112dc480..58064908 100644--- a/packages/build-result/src/store.ts+++ b/packages/build-result/src/store.ts@@ -20,6 +20,7 @@ import type {BuildResultFileRef,BuildResultFileRange,BuildResultFinish,+ BuildResultForward,BuildResultManifest,BuildResultPresentationUpdate,BuildResultSeed,@@ -269,6 +270,39 @@ export async function describeBuildResultOutput(}}+/**+ * Accept only finished historical Results and reduce every new Forward to the Result that owns its+ * terminal value. This follows only the addresses named by the caller; it needs no reverse index or+ * global Result scan.+ */+export async function normalizeBuildResultForwards(+ repository: {+ read(build: string): Promise<BuildResultManifest | undefined>;+ resolve(build: string, output: string): Promise<{+ readonly build: string;+ readonly output: string;+ } | undefined>;+ },+ forwards: readonly BuildResultForward[],+): Promise<readonly BuildResultForward[]> {+ return await Promise.all(forwards.map(async (forward) => {+ const source = await repository.read(forward.build);+ assert(source?.outcome !== undefined,+ `Build ${forward.build} is not a finished Result`);+ const resolved = await repository.resolve(forward.build, forward.sourceOutput);+ assert(resolved !== undefined,+ `Build ${forward.build} has no Output ${forward.sourceOutput}`);+ const owner = resolved.build === source.id ? source : await repository.read(resolved.build);+ assert(owner?.outcome !== undefined,+ `Build ${resolved.build} is not a finished Result`);+ return {+ output: forward.output,+ build: resolved.build,+ sourceOutput: resolved.output,+ };+ }));+}+export class FileBuildResult {readonly directory: string;@@ -279,10 +313,10 @@ export class FileBuildResult {static async create(root: string, seed: BuildResultSeed): Promise<FileBuildResult> {assertOrderedBuildId(seed.id);assertBuildResultSeed(seed);- for (const forward of seed.forwards ?? []) {- assert(await resolveBuildResultOutput(root, forward.build, forward.sourceOutput) !== undefined,- `Build ${forward.build} has no Output ${forward.sourceOutput}`);- }+ const forwards = await normalizeBuildResultForwards({+ read: async (build) => await readBuildResult(buildResultDirectory(root, build)),+ resolve: async (build, output) => await resolveBuildResultOutput(root, build, output),+ }, seed.forwards ?? []);const directory = buildResultDirectory(root, seed.id);await mkdir(resolve(root), { recursive: true });const temporary = join(resolve(root), `.preparing-${seed.id}-${randomUUID()}`);@@ -302,7 +336,7 @@ export class FileBuildResult {resources: {},values: {},publishedOutputs: seed.publishedOutputs,- forwards: seed.forwards ?? [],+ forwards,});await rename(temporary, directory);} catch (error) {@@ -391,7 +425,10 @@ export class FileBuildResultRepository implements BuildResultRepository {return await readBuildResult(directory) === undefined ? undefined : await FileBuildResult.open(directory);}- async remove(build: string): Promise<void> {+ async removeIncomplete(build: string): Promise<void> {+ const manifest = await this.read(build);+ if (manifest === undefined) return;+ assert(manifest.outcome === undefined, `Finished Build Result ${build} cannot be removed`);await rm(buildResultDirectory(this.root, build), { recursive: true, force: true });}diff --git a/packages/build-result/src/types.ts b/packages/build-result/src/types.tsindex 94332f0e..ba7544a6 100644--- a/packages/build-result/src/types.ts+++ b/packages/build-result/src/types.ts@@ -316,8 +316,8 @@ export type BuildResultWriter = {export type BuildResultRepository = {create(seed: BuildResultSeed): Promise<BuildResultWriter>;openWriter(build: string): Promise<BuildResultWriter | undefined>;- /** Remove one exact Result created by a submission that never became claimable. */- remove(build: string): Promise<void>;+ /** Remove one exact unfinished Result created by a submission that never became claimable. */+ removeIncomplete(build: string): Promise<void>;read(build: string): Promise<BuildResultManifest | undefined>;/** Edit only human presentation stored inside this exact finished Result. */updatePresentation(build: string, update: BuildResultPresentationUpdate): Promise<BuildResultManifest>;diff --git a/packages/build-result/test/result.test.ts b/packages/build-result/test/result.test.tsindex ad6f3095..87e88b9c 100644--- a/packages/build-result/test/result.test.ts+++ b/packages/build-result/test/result.test.ts@@ -282,13 +282,20 @@ test("an explicitly reused public output is a forward reference and copies no by}),resources: { async open() { return (async function* () { yield new Uint8Array(10); })(); } },});- const result = await FileBuildResult.create(root, {+ const reused = {id: "bld_20260902T100000002Z_0000000002",source: { path: "/project/main.svml" },targets: ["shot.video"],publishedOutputs: [{ name: "shot.video", output: "logical:shot-video" }],forwards: [{ output: "logical:shot-video", build: "bld_20260902T100000001Z_0000000001", sourceOutput: "opening.video" }],- });+ } as const;+ await assert.rejects(FileBuildResult.create(root, reused), /is not a finished Result/u);+ await prior.finish({ outcome: "complete" });+ await assert.rejects(+ new FileBuildResultRepository(root).removeIncomplete("bld_20260902T100000001Z_0000000001"),+ /cannot be removed/u,+ );+ const result = await FileBuildResult.create(root, reused);const manifest = await result.sync({state: state({records: [{diff --git a/packages/cli/src/run-file.ts b/packages/cli/src/run-file.tsindex dedd1ec4..53286f14 100644--- a/packages/cli/src/run-file.ts+++ b/packages/cli/src/run-file.ts@@ -85,6 +85,8 @@ export async function resolveBuildResultValue(readonly value: StoredValue;readonly attachments?: readonly ArtifactAttachment[];} | undefined> {+ const manifest = await repository.read(build);+ if (manifest?.outcome === undefined) return undefined;const resultAttachment = async (owner: string, file: BuildResultFileRef): Promise<ArtifactAttachment> => {const address = `${owner}\u0000${file.path}`;const existing = session.files.get(address);@@ -115,6 +117,8 @@ export async function resolveBuildResultValue(}const resolved = await pending;if (resolved === undefined) return undefined;+ const owner = resolved.build === build ? manifest : await repository.read(resolved.build);+ if (owner?.outcome === undefined) return undefined;let value: StoredValue;if (resolved.value.kind === "build-file") {const attachment = await resultAttachment(resolved.build, resolved.value);diff --git a/packages/cli/test/build-results.test.ts b/packages/cli/test/build-results.test.tsindex fcdcd639..fa01e854 100644--- a/packages/cli/test/build-results.test.ts+++ b/packages/cli/test/build-results.test.ts@@ -416,6 +416,7 @@ test("build-record selects one exact Result Output without leaking its storage a},},});+ await result.finish({ outcome: "complete" });const authorFile = join(root, "main.svml");const runFile = join(root, "reuse.svrun");diff --git a/packages/runtime-local/src/result-writer.ts b/packages/runtime-local/src/result-writer.tsindex 51f68a6d..0ecae893 100644--- a/packages/runtime-local/src/result-writer.ts+++ b/packages/runtime-local/src/result-writer.ts@@ -193,7 +193,7 @@ export function createLocalResultWriter(if (submission === undefined) return false;const opened = await options.openBuildResultRepository(submission.result);try {- await opened.repository.remove(build);+ await opened.repository.removeIncomplete(build);} finally {await opened.close?.();}diff --git a/packages/runtime-local/test/local.test.ts b/packages/runtime-local/test/local.test.tsindex ee378b60..99e78821 100644--- a/packages/runtime-local/test/local.test.ts+++ b/packages/runtime-local/test/local.test.ts@@ -493,7 +493,7 @@ test("an interrupted Result write finishes explicitly without rerunning the Builfinish: async (input) => await writer.finish(input),};},- remove: async (build) => await base.remove(build),+ removeIncomplete: async (build) => await base.removeIncomplete(build),read: async (build) => await base.read(build),updatePresentation: async (build, update) => await base.updatePresentation(build, update),browse: async (request) => await base.browse(request),@@ -542,7 +542,7 @@ test("a failed Result creation leaves no active Build", async () => {const unavailable: BuildResultRepository = {async create() { throw new Error("result repository refused creation"); },async openWriter() { return undefined; },- async remove() {},+ async removeIncomplete() {},async read() { return undefined; },async updatePresentation() { throw new Error("result repository refused update"); },async browse() { return { results: [] }; },diff --git a/packages/studio/test/build-library.test.ts b/packages/studio/test/build-library.test.tsindex e8396784..8173b449 100644--- a/packages/studio/test/build-library.test.ts+++ b/packages/studio/test/build-library.test.ts@@ -46,7 +46,7 @@ test("Studio library joins this environment's Builds with project Build Result fconst results: BuildResultRepository = {async create() { throw new Error("not used"); },async openWriter() { return undefined; },- async remove() {},+ async removeIncomplete() {},async updatePresentation() { throw new Error("read-only fixture"); },async read(build) { return manifests.find((item) => item.id === build); },async browse() { return { results: manifests }; },