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
refactor(studio): make preview an ordinary run
kashorin7bab59726f7a
diff --git a/examples/minimal-author-package/packages/example-component/preview/preview.svml b/examples/minimal-author-package/packages/example-component/preview/preview.svmlindex 5e4a87f6..684a51ea 100644--- a/examples/minimal-author-package/packages/example-component/preview/preview.svml+++ b/examples/minimal-author-package/packages/example-component/preview/preview.svml@@ -1,7 +1,7 @@<?svml using="@hypit/markup@1"?>-<!-- A complete, self-contained catalogue Source. The generated take is preview-mocked; the- remaining deterministic graph is compiled and rendered through the normal Studio path. -->+<!-- A complete catalogue Source. Its Run is ordinary: Studio can open it once the required media+ Candidates are supplied, and a normal Build of the same Run can regenerate the catalogue frame. --><svml><import from="@hypit/script@1"/><import as="wording" from="@hypit/text@1"/>diff --git a/package.json b/package.jsonindex da0cfc4f..938f0911 100644--- a/package.json+++ b/package.json@@ -86,7 +86,6 @@"@hypit/interview-emoji-reveal": "workspace:*","@hypit/media": "workspace:*","@hypit/media-pipeline": "workspace:*",- "@hypit/mock-media": "workspace:*","@hypit/media-track": "workspace:*","@hypit/media-track-studio": "workspace:*","@hypit/mimo-tts": "workspace:*",@@ -102,7 +101,6 @@"@hypit/provider-kie": "workspace:*","@hypit/provider-vertex": "workspace:*","@hypit/provider-media-local": "workspace:*",- "@hypit/preview-mock": "workspace:*","@hypit/provider-whisperx-local": "workspace:*","@hypit/provider-xiaomi-mimo": "workspace:*","@hypit/ranking": "workspace:*",diff --git a/packages/media-execution/src/execute.ts b/packages/media-execution/src/execute.tsindex 63a8e614..267e7204 100644--- a/packages/media-execution/src/execute.ts+++ b/packages/media-execution/src/execute.ts@@ -4,7 +4,6 @@ import { createReadStream } from "node:fs";import { mkdtemp, open, readFile, rm, stat, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";-import { deflateSync } from "node:zlib";import { mediaTypes, sealMediaInspection, sealMuxedMedia, sealSynchronizedMedia, sealTimelineAudio, verifyMediaInspection, verifyMediaStreamSelection, verifyRenderedVisual, verifySynchronizedMedia, verifyTimelineAudio } from "@hypit/media";import type { MediaAudioStream, MediaInspection, MediaRational, MediaStream, MediaStreamSelection, MediaTimestamp, MediaVideoStream, MuxedMedia, RenderedVisual, SynchronizedMedia, TimelineAudio } from "@hypit/media";import type { ProgramSpace } from "@hypit/program-space";@@ -72,27 +71,6 @@ export type MediaOperationResult = {readonly value: StoredValue;};-export type RenderMockImageRequest = {- readonly width: number;- readonly height: number;- readonly color: string;-};--export type RenderMockVideoRequest = {- readonly width: number;- readonly height: number;- readonly frameRate: MediaRational;- readonly frameCount: number;- readonly color: string;- readonly audio: "silence" | "none";-};--export type RenderMockSilenceRequest = {- readonly sampleRate: 48_000;- readonly channels: 2;- readonly sampleFrames: number;-};-function assert(condition: unknown, message: string): asserts condition {if (!condition) throw new Error(message);}@@ -448,143 +426,6 @@ function artifactResult(value: BlobRef): MediaOperationResult {return { value };}-function mockColor(value: string): [number, number, number] {- assert(/^#[0-9a-f]{6}$/iu.test(value), "Mock color must be a six-digit hex color");- return [parseInt(value.slice(1, 3), 16), parseInt(value.slice(3, 5), 16), parseInt(value.slice(5, 7), 16)];-}--// Keep preview media visibly identifiable without changing the requested mock fill. The bright-// outline survives both still-image and video materialization, so an agent can distinguish mock-// media from authored assets at a glance.-const MOCK_BORDER_COLOR = "#d946ef";-// The border occupies pixels inside the mock bounds; it never expands or clips the media.-const MOCK_BORDER_WIDTH = 8;--function crc32(bytes: Uint8Array): number {- let crc = 0xFFFFFFFF;- for (const byte of bytes) {- crc ^= byte;- for (let bit = 0; bit < 8; bit += 1) crc = (crc >>> 1) ^ (crc & 1 ? 0xEDB88320 : 0);- }- return (crc ^ 0xFFFFFFFF) >>> 0;-}--function pngChunk(type: string, data: Uint8Array): Uint8Array {- const body = new Uint8Array(type.length + data.length);- for (let index = 0; index < type.length; index += 1) body[index] = type.charCodeAt(index);- body.set(data, type.length);- const result = new Uint8Array(12 + data.length);- const view = new DataView(result.buffer);- view.setUint32(0, data.length);- result.set(body, 4);- view.setUint32(8 + data.length, crc32(body));- return result;-}--function mockPng(width: number, height: number, color: string): Uint8Array {- positiveInteger(width, "Mock image width");- positiveInteger(height, "Mock image height");- const [red, green, blue] = mockColor(color);- const [borderRed, borderGreen, borderBlue] = mockColor(MOCK_BORDER_COLOR);- const scanlines = Buffer.alloc(height * (1 + width * 3));- for (let row = 0; row < height; row += 1) {- const offset = row * (1 + width * 3);- scanlines[offset] = 0;- for (let column = 0; column < width; column += 1) {- const pixel = offset + 1 + column * 3;- const border = row < MOCK_BORDER_WIDTH || row >= height - MOCK_BORDER_WIDTH- || column < MOCK_BORDER_WIDTH || column >= width - MOCK_BORDER_WIDTH;- scanlines[pixel] = border ? borderRed : red;- scanlines[pixel + 1] = border ? borderGreen : green;- scanlines[pixel + 2] = border ? borderBlue : blue;- }- }- const header = Buffer.alloc(13);- header.writeUInt32BE(width, 0); header.writeUInt32BE(height, 4);- header[8] = 8; header[9] = 2;- return Uint8Array.from(Buffer.concat([- Buffer.from("\x89PNG\r\n\x1a\n", "binary"),- Buffer.from(pngChunk("IHDR", header)),- Buffer.from(pngChunk("IDAT", deflateSync(scanlines))),- Buffer.from(pngChunk("IEND", new Uint8Array())),- ]));-}--function mockSilenceWav(sampleFrames: number): Uint8Array {- positiveInteger(sampleFrames, "Mock silence sampleFrames");- const dataBytes = sampleFrames * 2 * 2;- const wav = Buffer.alloc(44 + dataBytes);- wav.write("RIFF", 0); wav.writeUInt32LE(36 + dataBytes, 4); wav.write("WAVE", 8);- wav.write("fmt ", 12); wav.writeUInt32LE(16, 16); wav.writeUInt16LE(1, 20);- wav.writeUInt16LE(2, 22); wav.writeUInt32LE(48_000, 24); wav.writeUInt32LE(48_000 * 4, 28);- wav.writeUInt16LE(4, 32); wav.writeUInt16LE(16, 34); wav.write("data", 36); wav.writeUInt32LE(dataBytes, 40);- return Uint8Array.from(wav);-}--function mockImageNeed(value: CanonicalValue): RenderMockImageRequest {- const item = object(value, "RenderMockImageRequest") as unknown as RenderMockImageRequest;- positiveInteger(item.width, "Mock image width"); positiveInteger(item.height, "Mock image height"); mockColor(item.color);- return item;-}--function mockVideoNeed(value: CanonicalValue): RenderMockVideoRequest {- const item = object(value, "RenderMockVideoRequest") as unknown as RenderMockVideoRequest;- positiveInteger(item.width, "Mock video width"); positiveInteger(item.height, "Mock video height");- positiveInteger(item.frameCount, "Mock video frameCount"); mockColor(item.color);- assert(item.audio === "silence" || item.audio === "none", "Mock video audio mode is invalid");- assert(Number.isSafeInteger(item.frameRate?.numerator) && item.frameRate.numerator > 0- && Number.isSafeInteger(item.frameRate?.denominator) && item.frameRate.denominator > 0,- "Mock video frameRate is invalid");- return item;-}--function mockSilenceNeed(value: CanonicalValue): RenderMockSilenceRequest {- const item = object(value, "RenderMockSilenceRequest") as unknown as RenderMockSilenceRequest;- assert(item.sampleRate === 48_000 && item.channels === 2, "Mock silence format must be 48kHz stereo");- positiveInteger(item.sampleFrames, "Mock silence sampleFrames");- return item;-}--export async function executeRenderMockImage(- env: MediaExecutionEnvironment,- constraints: CanonicalValue,-): Promise<MediaOperationResult> {- return artifactResult(await env.artifacts.put(mockPng(mockImageNeed(constraints).width, mockImageNeed(constraints).height, mockImageNeed(constraints).color), "image/png"));-}--export async function executeRenderMockSilence(- env: MediaExecutionEnvironment,- constraints: CanonicalValue,-): Promise<MediaOperationResult> {- const request = mockSilenceNeed(constraints);- return artifactResult(await env.artifacts.put(mockSilenceWav(request.sampleFrames), "audio/wav"));-}--export async function executeRenderMockVideo(- env: MediaExecutionEnvironment,- constraints: CanonicalValue,-): Promise<MediaOperationResult> {- const request = mockVideoNeed(constraints);- const work = await mkdtemp(join(tmpdir(), "hypit-media-mock-video-"));- try {- const output = join(work, "mock.mp4");- const rate = `${request.frameRate.numerator}/${request.frameRate.denominator}`;- const duration = request.frameCount * request.frameRate.denominator / request.frameRate.numerator;- const filter = `color=c=${request.color.slice(1)}:s=${request.width}x${request.height}:r=${rate}:d=${duration},drawbox=x=0:y=0:w=iw:h=ih:color=0x${MOCK_BORDER_COLOR.slice(1)}:t=${MOCK_BORDER_WIDTH}`;- const argv = ["-y", "-v", "error", "-f", "lavfi", "-i", filter,- ...(request.audio === "silence" ? ["-f", "lavfi", "-i", `anullsrc=r=48000:cl=stereo`] : []),- "-frames:v", String(request.frameCount), ...(request.audio === "silence"- ? ["-map", "0:v:0", "-map", "1:a:0", "-c:a", "pcm_s16le", "-shortest"]- : ["-an"]), "-c:v", "libx264", "-pix_fmt", "yuv420p", "-r", rate,- "-movflags", "+faststart", output];- await runProcess({ executable: env.ffmpegPath, argv, timeoutMs: env.processTimeoutMs, maxStdoutBytes: 64 * 1024,- ...(env.sharedLibraryPath === undefined ? {} : { sharedLibraryPath: env.sharedLibraryPath }) });- return artifactResult(await env.artifacts.putFile(output, "video/mp4"));- } finally {- await rm(work, { recursive: true, force: true }).catch(() => {});- }-}-function inspectNeed(value: CanonicalValue): InspectMediaNeed {const item = object(value, "InspectMediaNeed") as unknown as InspectMediaNeed;assert(item.source?.kind === "blob", "InspectMediaNeed is invalid");diff --git a/packages/media-execution/src/index.ts b/packages/media-execution/src/index.tsindex 4206ee57..fcc10457 100644--- a/packages/media-execution/src/index.ts+++ b/packages/media-execution/src/index.ts@@ -7,9 +7,6 @@ export {executeProjectSpeechEvidenceAudio,executeRenderTimelineAudio,executeRenderStillVideo,- executeRenderMockImage,- executeRenderMockVideo,- executeRenderMockSilence,executeTransformMedia,} from "./execute.js";export { parseMediaInspection } from "./probe.js";diff --git a/packages/media-track/preview/preview.svml b/packages/media-track/preview/preview.svmlindex 56622195..a13af8bb 100644--- a/packages/media-track/preview/preview.svml+++ b/packages/media-track/preview/preview.svml@@ -6,8 +6,8 @@about a project reaches this file, and nothing in it reaches a project. It exists so a readercan see the Surface's range in one picture, and so that picture can be made again.- The generations it declares are never performed. `render_previews` mocks each one- and draws the rest, so this stays free to run and free to re-run.+ The checked-in Track.png is the package catalogue asset. This Source and its ordinary Run+ preserve how it was authored; regenerating the encoded frame is a normal Build.A placeholder shows the Frame treatment and nothing inside it. To show the component holding apicture, commit a sample beside this file and satisfy the media output in `build.svrun`:@@ -15,7 +15,7 @@<file id="sample-a" type="@hypit/artifact@1#BlobArtifact" from="./sample-a.png" media-type="image/png"/><satisfy output="motion-a-media.media" candidate="sample-a"/>- Anything the Run satisfies is carried through untouched and never mocked over. -->+ Candidate selection is explicit in the Run; Studio never replaces missing media itself. --><svml><import from="@hypit/script@1"/><import as="wording" from="@hypit/text@1"/>diff --git a/packages/mock-media/README.md b/packages/mock-media/README.mddeleted file mode 100644index ad857792..00000000--- a/packages/mock-media/README.md+++ /dev/null@@ -1,5 +0,0 @@-# `@hypit/mock-media`--Preview-only mock media Fragments and their `render-mock-image`, `render-mock-video`, and-`render-mock-silence` capability contracts. The local Provider executes these capabilities into-ordinary Resource-backed `BlobArtifact` values; no mock type or user Source is introduced.diff --git a/packages/mock-media/package.json b/packages/mock-media/package.jsondeleted file mode 100644index 9c512ac4..00000000--- a/packages/mock-media/package.json+++ /dev/null@@ -1,19 +0,0 @@-{- "name": "@hypit/mock-media",- "version": "0.0.0-dev",- "license": "SEE LICENSE IN LICENSE",- "private": true,- "type": "module",- "exports": { ".": "./src/index.ts" },- "hypit": { "activation": "./src/activation.ts" },- "dependencies": {- "@hypit/artifact": "workspace:*",- "@hypit/elaborator": "workspace:*",- "@hypit/media": "workspace:*",- "@hypit/program-space": "workspace:*",- "@hypit/protocol": "workspace:*",- "@hypit/run": "workspace:*",- "@hypit/spatial": "workspace:*",- "@hypit/speech": "workspace:*"- }-}diff --git a/packages/mock-media/src/activation.ts b/packages/mock-media/src/activation.tsdeleted file mode 100644index b1c2f507..00000000--- a/packages/mock-media/src/activation.ts+++ /dev/null@@ -1,14 +0,0 @@-import { createRunFragmentHostFacet } from "@hypit/run";-import { mockImageFragment, mockMediaManifest, mockMediaModuleRef, mockSilenceFragment, mockVideoFragment } from "./index.js";-import { mockMediaComponent } from "./component.js";--export const hypitPackage = {- format: "hypit.node-package@1" as const,- modules: [{ manifest: mockMediaManifest }],- components: [mockMediaComponent],- hostFacets: [createRunFragmentHostFacet({- name: "@hypit/mock-media@1",- fragments: { image: mockImageFragment, video: mockVideoFragment, silence: mockSilenceFragment },- })],-};-export default hypitPackage;diff --git a/packages/mock-media/src/component.ts b/packages/mock-media/src/component.tsdeleted file mode 100644index e654e97d..00000000--- a/packages/mock-media/src/component.ts+++ /dev/null@@ -1,56 +0,0 @@-import { canonicalize } from "@hypit/protocol";-import type { StoredValue } from "@hypit/protocol";-import type { CanvasSpace } from "@hypit/spatial";-import type { ProgramClock } from "@hypit/program-space";-import type { SpeechDuration } from "@hypit/speech";-import { assertProgramClockIdentity } from "@hypit/program-space";-import { assertSpeechDurationIdentity } from "@hypit/speech";-import { mockMediaProducers } from "./manifest.js";--function inline<T>(value: StoredValue, subject: string): T {- if (value.kind !== "inline") throw new Error(`${subject} must be inline`);- return value.value as T;-}--function canvas(value: StoredValue): CanvasSpace {- const item = inline<CanvasSpace>(value, "Mock Canvas");- if (!Number.isSafeInteger(item.widthPx) || item.widthPx <= 0 || !Number.isSafeInteger(item.heightPx) || item.heightPx <= 0) {- throw new Error("Mock Canvas dimensions are invalid");- }- return item;-}--function color(): string { return "#9AA0A6"; }--export const mockMediaComponent = {- producers: [- {- producer: mockMediaProducers.image,- handler: ({ inputs }: { readonly inputs: Readonly<Record<string, { readonly value: StoredValue }>> }) => {- const size = canvas(inputs.canvas!.value);- return { outputs: {}, needs: { image: canonicalize({ width: size.widthPx, height: size.heightPx, color: color() }) } };- },- },- {- producer: mockMediaProducers.video,- handler: ({ inputs }: { readonly inputs: Readonly<Record<string, { readonly value: StoredValue }>> }) => {- const size = canvas(inputs.canvas!.value);- const duration = inline<SpeechDuration>(inputs.duration!.value, "Mock video duration");- const clock = inline<ProgramClock>(inputs.clock!.value, "Mock video clock");- assertSpeechDurationIdentity(duration); assertProgramClockIdentity(clock);- const frameCount = Math.max(1, Math.round(duration * clock.frameRate.numerator / clock.frameRate.denominator));- return { outputs: {}, needs: { video: canonicalize({ width: size.widthPx, height: size.heightPx,- frameRate: clock.frameRate, frameCount, color: color(), audio: "silence" }) } };- },- },- {- producer: mockMediaProducers.silence,- handler: ({ inputs }: { readonly inputs: Readonly<Record<string, { readonly value: StoredValue }>> }) => {- const duration = inline<SpeechDuration>(inputs.duration!.value, "Mock silence duration");- assertSpeechDurationIdentity(duration);- return { outputs: {}, needs: { audio: canonicalize({ sampleRate: 48_000, channels: 2,- sampleFrames: Math.max(1, Math.round(duration * 48_000)) }) } };- },- },- ],-};diff --git a/packages/mock-media/src/fragment.ts b/packages/mock-media/src/fragment.tsdeleted file mode 100644index 700a0943..00000000--- a/packages/mock-media/src/fragment.ts+++ /dev/null@@ -1,31 +0,0 @@-import { artifactTypes } from "@hypit/artifact";-import { sealGraphFragment } from "@hypit/elaborator";-import { programSpaceTypes } from "@hypit/program-space";-import { spatialTypes } from "@hypit/spatial";-import { speechTypes } from "@hypit/speech";-import { mockMediaProducers } from "./manifest.js";--const input = (name: string) => ({ kind: "fragment-input" as const, name });-const operation = (name: string) => ({ kind: "fragment-operation" as const, operation: name });--export const mockImageFragment = sealGraphFragment({- inputs: [{ name: "canvas", type: spatialTypes.canvas }],- operations: [{ id: "image", producer: mockMediaProducers.image, inputs: { canvas: input("canvas") }, result: { kind: "need", name: "image" } }],- exports: [{ name: "image", type: artifactTypes.blob, root: operation("image") }],-});--export const mockVideoFragment = sealGraphFragment({- inputs: [- { name: "canvas", type: spatialTypes.canvas },- { name: "duration", type: speechTypes.duration },- { name: "clock", type: programSpaceTypes.clock },- ],- operations: [{ id: "video", producer: mockMediaProducers.video, inputs: { canvas: input("canvas"), duration: input("duration"), clock: input("clock") }, result: { kind: "need", name: "video" } }],- exports: [{ name: "video", type: artifactTypes.blob, root: operation("video") }],-});--export const mockSilenceFragment = sealGraphFragment({- inputs: [{ name: "duration", type: speechTypes.duration }],- operations: [{ id: "silence", producer: mockMediaProducers.silence, inputs: { duration: input("duration") }, result: { kind: "need", name: "audio" } }],- exports: [{ name: "audio", type: artifactTypes.blob, root: operation("silence") }],-});diff --git a/packages/mock-media/src/index.ts b/packages/mock-media/src/index.tsdeleted file mode 100644index 8c7e4a70..00000000--- a/packages/mock-media/src/index.ts+++ /dev/null@@ -1,6 +0,0 @@-export { mockMediaManifest, mockMediaModuleRef, mockMediaTypes, mockMediaCapabilities, mockMediaProducers } from "./manifest.js";-export { mockImageFragment, mockVideoFragment, mockSilenceFragment } from "./fragment.js";-export { mockMediaComponent } from "./component.js";-export type MockImageRequest = { readonly width: number; readonly height: number; readonly color: string };-export type MockVideoRequest = { readonly width: number; readonly height: number; readonly frameRate: import("@hypit/media").MediaRational; readonly frameCount: number; readonly color: string; readonly audio: "silence" | "none" };-export type MockSilenceRequest = { readonly sampleRate: 48_000; readonly channels: 2; readonly sampleFrames: number };diff --git a/packages/mock-media/src/manifest.ts b/packages/mock-media/src/manifest.tsdeleted file mode 100644index 3c878997..00000000--- a/packages/mock-media/src/manifest.ts+++ /dev/null@@ -1,42 +0,0 @@-import { artifactTypes } from "@hypit/artifact";-import { programSpaceTypes } from "@hypit/program-space";-import type { CapabilityRef, ModuleManifest, ProducerRef, TypeRef } from "@hypit/protocol";-import { spatialTypes } from "@hypit/spatial";-import { speechTypes } from "@hypit/speech";--export const mockMediaModuleRef = { name: "@hypit/mock-media", version: "1" } as const;-export const mockMediaTypes = {- imageRequest: { module: mockMediaModuleRef, name: "MockImageRequest" },- videoRequest: { module: mockMediaModuleRef, name: "MockVideoRequest" },- silenceRequest: { module: mockMediaModuleRef, name: "MockSilenceRequest" },-} satisfies Record<string, TypeRef>;-export const mockMediaCapabilities = {- image: { module: mockMediaModuleRef, name: "render-mock-image" },- video: { module: mockMediaModuleRef, name: "render-mock-video" },- silence: { module: mockMediaModuleRef, name: "render-mock-silence" },-} satisfies Record<string, CapabilityRef>;-export const mockMediaProducers = {- image: { module: mockMediaModuleRef, name: "request-mock-image" },- video: { module: mockMediaModuleRef, name: "request-mock-video" },- silence: { module: mockMediaModuleRef, name: "request-mock-silence" },-} satisfies Record<string, ProducerRef>;--const canvas = { module: spatialTypes.canvas.module, name: spatialTypes.canvas.name } as const;-export const mockMediaManifest: ModuleManifest = {- format: "hypit.module@1",- name: mockMediaModuleRef.name,- version: mockMediaModuleRef.version,- dependencies: [- { module: { name: "@hypit/artifact", version: "1" } },- { module: { name: "@hypit/program-space", version: "1" } },- { module: { name: "@hypit/spatial", version: "1" } },- { module: { name: "@hypit/speech", version: "1" } },- ],- types: Object.values(mockMediaTypes).map((item) => ({ name: item.name })),- capabilities: Object.values(mockMediaCapabilities).map((item) => ({ name: item.name, returns: artifactTypes.blob })),- producers: [- { name: mockMediaProducers.image.name, inputs: [{ name: "canvas", type: canvas }], outputs: [], needs: [{ name: "image", capability: mockMediaCapabilities.image, returns: artifactTypes.blob }] },- { name: mockMediaProducers.video.name, inputs: [{ name: "canvas", type: canvas }, { name: "duration", type: speechTypes.duration }, { name: "clock", type: programSpaceTypes.clock }], outputs: [], needs: [{ name: "video", capability: mockMediaCapabilities.video, returns: artifactTypes.blob }] },- { name: mockMediaProducers.silence.name, inputs: [{ name: "duration", type: speechTypes.duration }], outputs: [], needs: [{ name: "audio", capability: mockMediaCapabilities.silence, returns: artifactTypes.blob }] },- ],-};diff --git a/packages/preview-mock/README.md b/packages/preview-mock/README.mddeleted file mode 100644index 397604c1..00000000--- a/packages/preview-mock/README.md+++ /dev/null@@ -1,4 +0,0 @@-# `@hypit/preview-mock`--The preview Mock Realizer. It maps compiled Graph outputs to mock Fragments, writes an isolated-temporary `preview.svrun`, and returns preview attachments and provenance with `estimate` timing.diff --git a/packages/preview-mock/package.json b/packages/preview-mock/package.jsondeleted file mode 100644index e026eb48..00000000--- a/packages/preview-mock/package.json+++ /dev/null@@ -1,29 +0,0 @@-{- "name": "@hypit/preview-mock",- "version": "0.0.0-dev",- "license": "SEE LICENSE IN LICENSE",- "private": true,- "type": "module",- "exports": {- ".": "./src/index.ts"- },- "hypit": {- "activation": "./src/activation.ts"- },- "dependencies": {- "@hypit/artifact": "workspace:*",- "@hypit/resource-store-fs": "workspace:*",- "@hypit/compiler-node": "workspace:*",- "@hypit/driver-node": "workspace:*",- "@hypit/mock-media": "workspace:*",- "@hypit/provider-media-local": "workspace:*",- "@hypit/protocol": "workspace:*",- "@hypit/spatial": "workspace:*",- "@hypit/media": "workspace:*",- "@hypit/program-space": "workspace:*",- "@hypit/speech": "workspace:*",- "@hypit/text": "workspace:*",- "@hypit/semantic-take-estimate": "workspace:*",- "@hypit/workspace": "workspace:*"- }-}diff --git a/packages/preview-mock/src/activation.ts b/packages/preview-mock/src/activation.tsdeleted file mode 100644index c63f5283..00000000--- a/packages/preview-mock/src/activation.ts+++ /dev/null@@ -1,2 +0,0 @@-export const hypitPackage = { format: "hypit.node-package@1" as const };-export default hypitPackage;diff --git a/packages/preview-mock/src/geometry.ts b/packages/preview-mock/src/geometry.tsdeleted file mode 100644index 195c8cb0..00000000--- a/packages/preview-mock/src/geometry.ts+++ /dev/null@@ -1,39 +0,0 @@-import type { CompiledGraph, StoredValue } from "@hypit/protocol";-import { findLogicalOutput, findCandidate } from "@hypit/compiler-node";-import { spatialTypes } from "@hypit/spatial";--function inline(value: StoredValue | undefined): unknown {- return value?.kind === "inline" ? value.value : undefined;-}--export type MockGeometry = { readonly width: number; readonly height: number };--/** Geometry is a graph fact; resolution labels are intentionally not interpreted as pixels. */-export function deriveGeometry(graph: CompiledGraph, outputs: readonly string[]): MockGeometry {- const candidates = outputs.flatMap((id) => {- const output = findLogicalOutput(graph, id);- return output === undefined ? [] : [findCandidate(graph, output.primary)];- }).filter((item): item is NonNullable<typeof item> => item !== undefined);- const canvas = graph.outputs- .filter((output) => output.type.module.name === spatialTypes.canvas.module.name && output.type.name === spatialTypes.canvas.name)- .map((output) => findCandidate(graph, output.primary))- .find((candidate) => candidate?.root.kind === "value");- const value = canvas?.root.kind === "value" ? inline(canvas.root.value.value) as { widthPx?: unknown; heightPx?: unknown } : undefined;- if (value !== undefined && Number.isSafeInteger(value.widthPx) && Number.isSafeInteger(value.heightPx)- && (value.widthPx as number) > 0 && (value.heightPx as number) > 0) {- return { width: value.widthPx as number, height: value.heightPx as number };- }- const ratios = candidates.flatMap((candidate) => {- if (candidate.root.kind !== "value") return [];- const item = inline(candidate.root.value.value) as { aspectRatio?: unknown; width?: unknown; height?: unknown };- if (typeof item.aspectRatio === "number" && item.aspectRatio > 0) return [item.aspectRatio];- if (typeof item.width === "number" && typeof item.height === "number" && item.width > 0 && item.height > 0) return [item.width / item.height];- return [];- });- if (ratios.length > 0 && ratios.every((ratio) => Math.abs(ratio - ratios[0]!) < 1e-9)) {- const width = 1920;- return { width, height: Math.max(1, Math.round(width / ratios[0]!)) };- }- if (ratios.length > 1) throw new Error("Preview mock geometry has conflicting aspect-ratio declarations");- return { width: 1920, height: 1080 };-}diff --git a/packages/preview-mock/src/graph.ts b/packages/preview-mock/src/graph.tsdeleted file mode 100644index 57512467..00000000--- a/packages/preview-mock/src/graph.ts+++ /dev/null@@ -1,271 +0,0 @@-import type { CompiledGraph, Candidate, TypedRecord } from "@hypit/protocol";-import { findLogicalOutput, findCandidate, findOperation } from "@hypit/compiler-node";-import type { GraphValueRef, TypeRef } from "@hypit/protocol";--export type MockKind = "image" | "video" | "audio" | "semantic-take";-export type MockTarget = { readonly output: string; readonly candidate: Candidate; readonly kind: MockKind; readonly inputs: Readonly<Record<string, string>>; readonly durationSeconds?: number };--/**- * The longest duration the author wrote anywhere in the graph: a SpeechDuration literal (a still's- * length) or the `duration` port of a generation request (a Seedance take). Durations are author- * literals, so the preview clock is known before anything runs.- */-export function estimatedProgramDurationSeconds(graph: CompiledGraph, records: readonly TypedRecord[] = []): number | undefined {- const values: unknown[] = [- ...records.filter((item) => sameType(item.type, "@hypit/speech", "SpeechDuration")).map((item) => item.value),- ...graph.candidates.filter((item) => sameType(item.type, "@hypit/speech", "SpeechDuration") && item.root.kind === "value")- .map((item) => item.root.kind === "value" ? item.root.value.value : undefined),- ];- const durations = values.map(inlineNumber).filter((value): value is number => value !== undefined);- for (const record of records) {- const duration = requestDuration(record.value.kind === "inline" ? record.value.value : undefined);- if (duration !== undefined) durations.push(duration);- }- return durations.length === 0 ? undefined : Math.max(...durations);-}--/** The `duration` port of a sealed generation request or draft; nothing else is read as a duration. */-function requestDuration(value: unknown): number | undefined {- if (value === null || typeof value !== "object") return undefined;- const ports = (value as { readonly ports?: unknown }).ports;- if (ports === null || typeof ports !== "object") return undefined;- return inlineDuration((ports as Record<string, unknown>).duration);-}--function sameType(left: TypeRef | undefined, module: string, name: string): boolean {- return left?.module.name === module && left.name === name;-}--function refType(graph: CompiledGraph, ref: GraphValueRef, records: readonly TypedRecord[] = []): TypeRef | undefined {- if (ref.kind === "logical-output") return findLogicalOutput(graph, ref.id)?.type;- if (ref.kind === "record") return records.find((item) => item.id === ref.id)?.type- ?? graph.candidates.find((item) => item.root.kind === "value" && item.root.value.id === ref.id)?.type;- const operation = findOperation(graph, ref.operation);- if (operation === undefined) return undefined;- return graph.candidates.find((item) => item.root.kind === "operation" && item.root.result.operation === ref.operation)?.type;-}--function firstRefOfType(graph: CompiledGraph, type: { module: string; name: string }, records: readonly TypedRecord[] = []): string | undefined {- for (const output of graph.outputs) if (sameType(output.type, type.module, type.name)) return output.id;- const record = records.find((item) => sameType(item.type, type.module, type.name));- if (record !== undefined) return record.id;- for (const operation of graph.operations) {- for (const ref of Object.values(operation.inputs)) {- if (sameType(refType(graph, ref), type.module, type.name)) {- const id = logicalId(graph, ref);- if (id !== undefined) return id;- }- }- }- return undefined;-}--function logicalId(graph: CompiledGraph, ref: GraphValueRef | undefined): string | undefined {- if (ref === undefined) return undefined;- if (ref.kind === "logical-output") return ref.id;- if (ref.kind === "record") return ref.id;- if (ref.kind !== "operation-result") return undefined;- const candidate = graph.candidates.find((item) => item.root.kind === "operation" && item.root.result.operation === ref.operation);- return candidate === undefined ? undefined : graph.outputs.find((output) => output.primary === candidate.id)?.id;-}--function inlineNumber(value: unknown): number | undefined {- if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;- if (value !== null && typeof value === "object" && "value" in value) return inlineNumber((value as { value?: unknown }).value);- return undefined;-}--function recordValue(records: readonly TypedRecord[], id: string): unknown {- const record = records.find((item) => item.id === id);- return record?.value.kind === "inline" ? record.value.value : undefined;-}--function inlineDuration(value: unknown): number | undefined {- const direct = inlineNumber(value);- if (direct !== undefined) return direct;- if (Array.isArray(value)) {- for (const item of value) {- const candidate = inlineDuration(item);- if (candidate !== undefined) return candidate;- }- return undefined;- }- if (value === null || typeof value !== "object") return undefined;- const object = value as Record<string, unknown>;- for (const key of ["duration", "durationSec", "durationSeconds"]) {- const candidate = inlineNumber(object[key]);- if (candidate !== undefined) return candidate;- }- const ports = object.ports;- if (ports !== null && typeof ports === "object") {- const candidate = inlineDuration((ports as Record<string, unknown>).duration);- if (candidate !== undefined) return candidate;- }- return undefined;-}--function operationForRef(graph: CompiledGraph, ref: GraphValueRef): ReturnType<typeof findOperation> {- if (ref.kind === "operation-result") return findOperation(graph, ref.operation);- if (ref.kind !== "logical-output") return undefined;- const output = findLogicalOutput(graph, ref.id);- const candidate = output === undefined ? undefined : findCandidate(graph, output.primary);- return candidate?.root.kind === "operation" ? findOperation(graph, candidate.root.result.operation) : undefined;-}--/** Find a typed input reachable from one operation, without consulting unrelated graph branches. */-function refOfTypeInOperation(- graph: CompiledGraph,- operation: ReturnType<typeof findOperation>,- type: { readonly module: string; readonly name: string },- records: readonly TypedRecord[],- seen = new Set<string>(),-): GraphValueRef | undefined {- if (operation === undefined || seen.has(operation.id)) return undefined;- seen.add(operation.id);- const refs = Object.entries(operation.inputs).sort(([left], [right]) => {- const priority = (name: string) => name === "duration" ? 0 : name === "policy" ? 1 : name === "program" ? 2 : 3;- return priority(left) - priority(right);- });- for (const [, ref] of refs) {- if (sameType(refType(graph, ref, records), type.module, type.name)) return ref;- const nested = refOfTypeInOperation(graph, operationForRef(graph, ref), type, records, seen);- if (nested !== undefined) return nested;- }- return undefined;-}--/** Resolve the duration belonging to one generation operation, without falling back to the first- * duration in the graph: a SpeechDuration record, or the literal `duration` port of the request. */-function durationFromRef(- graph: CompiledGraph,- ref: GraphValueRef | undefined,- records: readonly TypedRecord[],- seen = new Set<string>(),-): number | undefined {- if (ref === undefined) return undefined;- if (ref.kind === "record") return inlineDuration(recordValue(records, ref.id));- if (ref.kind === "logical-output") {- const candidate = findLogicalOutput(graph, ref.id);- if (candidate === undefined) return undefined;- const primary = findCandidate(graph, candidate.primary);- if (primary?.root.kind === "value") return inlineDuration(primary.root.value.value);- if (primary?.root.kind === "operation") return durationFromRef(graph, primary.root.result, records, seen);- return undefined;- }- if (seen.has(ref.operation)) return undefined;- seen.add(ref.operation);- const operation = findOperation(graph, ref.operation);- if (operation === undefined) return undefined;- for (const name of ["duration", "request", "draft"]) {- const value = durationFromRef(graph, operation.inputs[name], records, seen);- if (value !== undefined) return value;- }- for (const ref of Object.values(operation.inputs)) {- const value = durationFromRef(graph, ref, records, seen);- if (value !== undefined) return value;- }- return undefined;-}--function durationForTarget(graph: CompiledGraph, operation: ReturnType<typeof findOperation>, inputs: Readonly<Record<string, string>>, records: readonly TypedRecord[]): number | undefined {- const direct = durationFromRef(graph, refOfTypeInOperation(graph, operation, { module: "@hypit/speech", name: "SpeechDuration" }, records) ?? operation?.inputs.duration, records);- if (direct !== undefined) return direct;- const durationId = inputs.duration;- if (durationId !== undefined) {- const candidate = graph.candidates.find((item) => item.root.kind === "value" && item.root.value.id === durationId)- ?? graph.candidates.find((item) => graph.outputs.some((output) => output.id === durationId && output.primary === item.id));- if (candidate?.root.kind === "value") return inlineDuration(candidate.root.value.value);- }- return undefined;-}--function mockInputs(graph: CompiledGraph, kind: MockKind, operation: ReturnType<typeof findOperation>, records: readonly TypedRecord[] = []): Readonly<Record<string, string>> {- const refs = operation?.inputs ?? {};- const byName = (name: string): string | undefined => logicalId(graph, refs[name]!);- const byType = (module: string, name: string): string | undefined => {- for (const ref of Object.values(refs)) {- const id = logicalId(graph, ref);- if (id !== undefined && sameType(refType(graph, ref, records), module, name)) return id;- }- return firstRefOfType(graph, { module, name }, records);- };- if (kind === "image") {- const canvas = byName("canvas") ?? byType("@hypit/spatial", "CanvasSpace");- return canvas === undefined ? {} : { canvas };- }- if (kind === "video") {- const canvas = byName("canvas") ?? byType("@hypit/spatial", "CanvasSpace");- const duration = byName("duration")- ?? logicalId(graph, refOfTypeInOperation(graph, operation, { module: "@hypit/speech", name: "SpeechDuration" }, records));- const clock = byName("clock") ?? byType("@hypit/program-space", "ProgramClock");- return Object.fromEntries([["canvas", canvas], ["duration", duration], ["clock", clock]].filter((item): item is [string, string] => item[1] !== undefined));- }- if (kind === "audio") {- const duration = byName("duration") ?? byType("@hypit/speech", "SpeechDuration");- return duration === undefined ? {} : { duration };- }- const result: Record<string, string | undefined> = {};- for (const name of ["narrative", "segment", "media", "policy"]) {- const direct = byName(name);- if (direct !== undefined) result[name] = direct;- }- result.policy ??= logicalId(graph, refOfTypeInOperation(graph, operation, { module: "@hypit/estimate", name: "SpeechEstimatePolicy" }, records));- result.narrative ??= byType("@hypit/narrative", "Narrative");- result.segment ??= byType("@hypit/narrative", "NarrativeExcerpt");- result.media ??= byType("@hypit/media", "SynchronizedMedia");- result.policy ??= byType("@hypit/estimate", "SpeechEstimatePolicy");- return Object.fromEntries(Object.entries(result).filter(([, value]) => value !== undefined && value.length > 0)) as Readonly<Record<string, string>>;-}--export function findMockTargets(graph: CompiledGraph, targets?: readonly string[], records: readonly TypedRecord[] = []): readonly MockTarget[] {- const selected = targets ?? graph.outputs.map((item) => item.id);- const closure = new Set<string>();- const visitOperation = (operationId: string): void => {- const operation = findOperation(graph, operationId);- if (operation === undefined) return;- for (const ref of Object.values(operation.inputs)) {- if (ref.kind === "logical-output") visitOutput(ref.id);- else if (ref.kind === "operation-result") {- const candidate = graph.candidates.find((item) => item.root.kind === "operation" && item.root.result.operation === ref.operation);- const output = candidate === undefined ? undefined : graph.outputs.find((item) => item.primary === candidate.id);- if (output !== undefined) visitOutput(output.id);- else visitOperation(ref.operation);- }- }- };- const visitOutput = (id: string): void => {- if (closure.has(id)) return;- closure.add(id);- const output = findLogicalOutput(graph, id);- if (output === undefined) return;- const candidate = findCandidate(graph, output.primary);- if (candidate?.root.kind !== "operation") return;- visitOperation(candidate.root.result.operation);- };- for (const id of selected) visitOutput(id);- const result: MockTarget[] = [];- for (const id of closure) {- const output = findLogicalOutput(graph, id);- if (output === undefined) continue;- const candidate = findCandidate(graph, output.primary);- if (candidate === undefined) continue;- let resolved: MockKind | undefined;- if (output.type.module.name === "@hypit/speech" && output.type.name === "SemanticTake") resolved = "semantic-take";- else if (output.type.module.name === "@hypit/artifact" && output.type.name === "BlobArtifact" && candidate.root.kind === "operation") {- const operation = findOperation(graph, candidate.root.result.operation);- if (operation?.producer.module.name === "@hypit/media-pipeline") continue;- const name = operation?.producer.name.toLowerCase() ?? "";- if (name.includes("project-mux") || name === "mux" || name.includes("render-composition")) continue;- resolved = operation?.producer.module.name === "@hypit/gpt-image" || name.includes("image") || name.includes("picture") ? "image"- : name.includes("video") || name.includes("visual") || name.includes("media") ? "video"- : name.includes("audio") || name.includes("speech") || name.includes("tts") || name.includes("wav") ? "audio" : undefined;- }- const operation = candidate.root.kind === "operation" ? findOperation(graph, candidate.root.result.operation) : undefined;- if (resolved !== undefined) {- const inputs = mockInputs(graph, resolved, operation, records);- const durationSeconds = resolved === "video" ? durationForTarget(graph, operation, inputs, records) : undefined;- result.push({ output: id, candidate, kind: resolved, inputs, ...(durationSeconds === undefined ? {} : { durationSeconds }) });- }- }- return result;-}diff --git a/packages/preview-mock/src/index.ts b/packages/preview-mock/src/index.tsdeleted file mode 100644index 70dd8d8a..00000000--- a/packages/preview-mock/src/index.ts+++ /dev/null@@ -1,4 +0,0 @@-export { realizePreviewMock } from "./realizer.js";-export type { PreviewMockRequest, PreviewMockResult, PreviewMockTiming } from "./realizer.js";-export { findMockTargets } from "./graph.js";-export { deriveGeometry } from "./geometry.js";diff --git a/packages/preview-mock/src/materialize.ts b/packages/preview-mock/src/materialize.tsdeleted file mode 100644index 785a78d3..00000000--- a/packages/preview-mock/src/materialize.ts+++ /dev/null@@ -1,42 +0,0 @@-import type { ArtifactAttachment } from "@hypit/workspace";-import type { BlobRef } from "@hypit/protocol";-import { MemoryResourceStore, EndpointRegistry } from "@hypit/driver-node";-import { createLocalMediaProvider } from "@hypit/provider-media-local";-import { mockMediaCapabilities } from "@hypit/mock-media";-type ResourceStore = {- readonly get: (resource: BlobRef["resource"]) => Promise<Uint8Array | undefined>;- readonly put: (bytes: Uint8Array, mediaType: string) => Promise<BlobRef>;- readonly write: (resource: BlobRef, bytes: Uint8Array) => Promise<void>;- readonly has: (resource: BlobRef["resource"]) => Promise<boolean>;-};--/**- * Execute one mock Need with the local Provider. Callers may provide the- * project preview ResourceStore so the resulting bytes survive the process- * which created the temporary Run (Studio is deliberately a separate- * process). The in-memory default is retained for small library callers.- */-export async function materializeMockNeed(input: {- readonly capability: typeof mockMediaCapabilities[keyof typeof mockMediaCapabilities];- readonly constraints: unknown;- readonly resources?: ResourceStore;-}): Promise<{ readonly artifact: BlobRef; readonly attachment: ArtifactAttachment }> {- const resources = input.resources ?? new MemoryResourceStore();- const registry = new EndpointRegistry();- await createLocalMediaProvider({}).install(registry);- const registration = registry.resolve({ id: "mock", capability: input.capability, returns: { module: { name: "@hypit/artifact", version: "1" }, name: "BlobArtifact" }, constraints: input.constraints as never, result: "mock" });- if (registration.status !== "resolved" || registration.registration.kind !== "immediate") throw new Error(`No local mock capability configured for ${input.capability.name}`);- const result = await registration.registration.handler({ command: { kind: "fulfill-need", id: "mock", need: { id: "mock", capability: input.capability, returns: registration.registration.returns, constraints: input.constraints as never, result: "mock" } }, need: { id: "mock", capability: input.capability, returns: registration.registration.returns, constraints: input.constraints as never, result: "mock" }, resources, credentials: {} });- if (result.value.kind !== "blob") throw new Error("Mock Provider returned a non-Artifact value");- const artifact = result.value;- return {- artifact,- attachment: {- artifact,- open: async () => (async function* () {- const bytes = await resources.get(artifact.resource);- if (bytes !== undefined) yield bytes;- })(),- },- };-}diff --git a/packages/preview-mock/src/realizer.ts b/packages/preview-mock/src/realizer.tsdeleted file mode 100644index 3d5ce3b2..00000000--- a/packages/preview-mock/src/realizer.ts+++ /dev/null@@ -1,133 +0,0 @@-import { mkdir, readFile, writeFile } from "node:fs/promises";-import { basename, dirname, join, relative, resolve } from "node:path";-import type { ArtifactAttachment } from "@hypit/workspace";-import type { CompiledGraph, TypedRecord } from "@hypit/protocol";-import { estimatedProgramDurationSeconds, findMockTargets } from "./graph.js";-import { deriveGeometry } from "./geometry.js";-import { previewRunSource } from "./run-source.js";-import { materializeMockNeed } from "./materialize.js";-import { mockMediaCapabilities } from "@hypit/mock-media";-import { FileResourceStore } from "@hypit/resource-store-fs";--export type PreviewMockTiming = "estimate";-export type PreviewMockRequest = { readonly run: string; readonly targets?: readonly string[]; readonly timing?: PreviewMockTiming; readonly cacheRoot?: string; readonly graph?: CompiledGraph; readonly records?: readonly TypedRecord[]; readonly author?: string; readonly aliases?: ReadonlyMap<string, string> };-export type PreviewMockResult = {- readonly run: string;- readonly root: string;- /** The persisted Run containing the native mock fragments. */- readonly mockRun: string;- /** The persisted Run consumed by Studio; its mock outputs are file Candidates. */- readonly previewRun: string;- readonly attachments: readonly ArtifactAttachment[];- readonly mocked: readonly { output: string; candidate: string; kind: "image" | "video" | "audio" | "semantic-take" }[];- readonly timingBasis: "estimate";-};--function artifactRelativePath(root: string, resource: string): string {- return `./artifacts/resources/${resource}`;-}--function previewDirectoryName(run: string): string {- const name = basename(run).replace(/[^a-zA-Z0-9._-]+/gu, "-");- return name.length === 0 ? "run" : name;-}--export async function realizePreviewMock(input: PreviewMockRequest): Promise<PreviewMockResult> {- const run = resolve(input.run);- const source = await readFile(run, "utf8");- const author = input.author ?? /<author\s+source="([^"]+)"/u.exec(source)?.[1];- if (author === undefined) throw new Error(`${input.run} declares no author source`);- if (input.graph === undefined) {- const root = input.cacheRoot ?? join(dirname(run), ".hypit", "preview", previewDirectoryName(run));- await mkdir(root, { recursive: true });- const previewRun = join(root, "preview.svrun");- const mockRun = join(root, "mock.svrun");- await writeFile(previewRun, source, "utf8");- await writeFile(mockRun, source, "utf8");- return { run, root, mockRun, previewRun, attachments: [], mocked: [], timingBasis: "estimate" };- }- const alias = (ref: string): string => input.aliases?.get(ref) ?? ref;- const rawTargets = findMockTargets(input.graph, input.targets, input.records);- const fallbackDurationSeconds = estimatedProgramDurationSeconds(input.graph, input.records);- const targets = rawTargets.map((target) => ({- ...target,- output: alias(target.output),- inputs: Object.fromEntries(Object.entries(target.inputs).map(([name, ref]) => [name, alias(ref)])),- }));- const selectedTargets = (input.targets ?? input.graph.outputs.map((item) => item.id)).map(alias);- const geometry = deriveGeometry(input.graph, rawTargets.map((item) => item.output));- const authorPath = resolve(dirname(run), author);- await readFile(authorPath, "utf8");- const root = input.cacheRoot ?? join(dirname(run), ".hypit", "preview", previewDirectoryName(run));- await mkdir(root, { recursive: true });- const previewRun = join(root, "preview.svrun");- const mockRun = join(root, "mock.svrun");- const resourceStore = new FileResourceStore(join(root, "artifacts"));- const preserved = [...source.matchAll(/^\s*<(?:file|value|build-record)\b[^>]*\/?>(?:\s*)$/gmu)]- .map((match) => (match[0] ?? "").trim())- .map((line) => line.replace(/\bfrom="([^"]+)"/u, (_whole, from: string) => {- // Rebase carried Run assets against the temporary Run directory. The- // generated source never contains an absolute Candidate path, even when- // the original Run used one.- const absolute = resolve(dirname(run), from);- const relativePath = relative(root, absolute).replaceAll("\\", "/");- return `from="${relativePath.startsWith(".") ? relativePath : `./${relativePath}`}"`;- }));- // Keep the native mock Run as a durable audit/debug artifact. Its Needs are- // fulfilled by the local mock Provider below; Studio then opens the second- // Run, whose relative file Candidates point at those persisted- // results and therefore require no Provider endpoint.- const generatedMock = previewRunSource(resolve(dirname(run), author), mockRun, selectedTargets, geometry, targets);- await writeFile(mockRun, generatedMock, "utf8");- const mockedOutputs = new Set(targets.map((item) => item.output));- const carriedSatisfactions = [...source.matchAll(/^\s*<satisfy\s+output="([^"]+)"[^>]*\/?>\s*$/gmu)]- .filter((match) => !mockedOutputs.has(match[1] ?? ""))- .map((match) => ` ${(match[0] ?? "").trim()}`);- const attachments: ArtifactAttachment[] = [];- const attached = new Set<string>();- const files = new Map<string, { readonly id: string; readonly from: string; readonly mediaType: string }>();- for (const target of targets) {- if (target.kind === "semantic-take") continue;- const capability = target.kind === "image" ? mockMediaCapabilities.image- : target.kind === "video" ? mockMediaCapabilities.video : mockMediaCapabilities.silence;- const constraints = target.kind === "image"- ? { width: geometry.width, height: geometry.height, color: "#9AA0A6" }- : target.kind === "video"- // The mock video domain follows the deterministic SpeechDuration carried by this target.- // It must not invent a ten-second clock per Segment: SemanticTake owns the estimate timing- // and the generated preview material only needs enough frames for that estimate.- ? {- width: geometry.width,- height: geometry.height,- frameRate: { numerator: 30, denominator: 1 },- frameCount: Math.max(1, Math.ceil((target.durationSeconds ?? fallbackDurationSeconds ?? 1) * 30)),- color: "#9AA0A6",- audio: "silence",- }- : { sampleRate: 48_000, channels: 2, sampleFrames: 48_000 };- const materialized = await materializeMockNeed({ capability, constraints, resources: resourceStore });- if (!attached.has(materialized.artifact.resource)) {- attached.add(materialized.artifact.resource);- attachments.push(materialized.attachment);- }- const candidateId = `mock-file-${files.size}`;- files.set(target.output, {- id: candidateId,- from: artifactRelativePath(root, materialized.artifact.resource),- mediaType: materialized.artifact.mediaType,- });- }- const generated = previewRunSource(resolve(dirname(run), author), previewRun, selectedTargets, geometry, targets, files);- const withCarried = generated.replace("</svrun>", `${carriedSatisfactions.join("\n")}\n</svrun>`);- const carried = preserved.map((line) => ` ${line}`).join("\n");- await writeFile(previewRun, withCarried.replace(" <target", `${carried}${carried.length === 0 ? "" : "\n"} <target`), "utf8");- return {- run, root, mockRun, previewRun, attachments,- mocked: targets.map((item, index) => ({- output: item.output,- candidate: files.get(item.output)?.id ?? `mock-${index}.${item.kind === "audio" ? "audio" : item.kind}`,- kind: item.kind,- })),- timingBasis: "estimate",- };-}diff --git a/packages/preview-mock/src/run-source.ts b/packages/preview-mock/src/run-source.tsdeleted file mode 100644index c4648031..00000000--- a/packages/preview-mock/src/run-source.ts+++ /dev/null@@ -1,41 +0,0 @@-import { relative, dirname } from "node:path";-import type { MockTarget } from "./graph.js";--export type PreviewMockFile = {- readonly id: string;- readonly from: string;- readonly mediaType: string;-};--export function previewRunSource(- author: string,- runFile: string,- targets: readonly string[],- geometry: { width: number; height: number },- mocks: readonly MockTarget[],- files: ReadonlyMap<string, PreviewMockFile> = new Map(),-): string {- const authorRef = relative(dirname(runFile), author).replaceAll("\\", "/");- const declarations: string[] = [];- const satisfactions: string[] = [];- const needsEstimate = mocks.some((mock) => mock.kind === "semantic-take");- const importLine = needsEstimate- ? ` <import from="@hypit/semantic-take-estimate@1" as="estimate"/>\n`- : "";- for (const [index, mock] of mocks.entries()) {- const file = files.get(mock.output);- if (file !== undefined) {- declarations.push(` <file id="${file.id}" type="@hypit/artifact@1#BlobArtifact" from="${file.from}" media-type="${file.mediaType}"/>`);- satisfactions.push(` <satisfy output="${mock.output}" candidate="${file.id}"/>`);- continue;- }- const fragment = mock.kind === "semantic-take" ? "estimate:semantic-take"- : mock.kind === "image" ? "mock:image" : mock.kind === "video" ? "mock:video" : "mock:silence";- const id = `mock-${index}`;- const inputs = Object.entries(mock.inputs).map(([name, from]) => `<input name="${name}" from="${from}"/>`).join("");- declarations.push(` <fragment id="${id}" using="${fragment}">${inputs}</fragment>`);- const exportName = mock.kind === "semantic-take" ? "take" : mock.kind === "audio" ? "audio" : mock.kind;- satisfactions.push(` <satisfy output="${mock.output}" candidate="${id}.${exportName}"/>`);- }- return `<?svml using="@hypit/run-markup@1"?>\n<svrun version="1">\n <author source="${authorRef}"/>\n <import from="@hypit/mock-media@1" as="mock"/>\n${importLine}${targets.map((target) => ` <target output="${target}"/>`).join("\n")}\n${declarations.join("\n")}\n${satisfactions.join("\n")}\n</svrun>\n`;-}diff --git a/packages/provider-media-local/package.json b/packages/provider-media-local/package.jsonindex 981ab558..a7d6fe7f 100644--- a/packages/provider-media-local/package.json+++ b/packages/provider-media-local/package.json@@ -16,7 +16,6 @@"@hypit/media": "workspace:*","@hypit/media-execution": "workspace:*","@hypit/media-pipeline": "workspace:*",- "@hypit/mock-media": "workspace:*","@hypit/protocol": "workspace:*","@hypit/runtime": "workspace:*","@hypit/runtime-kit": "workspace:*",diff --git a/packages/provider-media-local/src/provider.ts b/packages/provider-media-local/src/provider.tsindex 2d18de0a..f85e8b57 100644--- a/packages/provider-media-local/src/provider.ts+++ b/packages/provider-media-local/src/provider.ts@@ -9,14 +9,10 @@ import {executeProjectSpeechEvidenceAudio,executeRenderTimelineAudio,executeRenderStillVideo,- executeRenderMockImage,- executeRenderMockVideo,- executeRenderMockSilence,executeTransformMedia,} from "@hypit/media-execution";import type { MediaExecutionEnvironment, MediaOperationResult } from "@hypit/media-execution";import { mediaPipelineCapabilities } from "@hypit/media-pipeline";-import { mockMediaCapabilities } from "@hypit/mock-media";import { isStreamingResourceStore } from "@hypit/runtime";import { speechTypes } from "@hypit/speech";import { defineEndpointPackage } from "@hypit/endpoint-kit";@@ -123,24 +119,6 @@ export function createLocalMediaProvider(config: CreateLocalMediaProviderOptionsreturns: artifactTypes.blob,handler: operation(executeRenderStillVideo),},- {- lifecycle: "immediate" as const,- capability: mockMediaCapabilities.image,- returns: artifactTypes.blob,- handler: operation(executeRenderMockImage),- },- {- lifecycle: "immediate" as const,- capability: mockMediaCapabilities.video,- returns: artifactTypes.blob,- handler: operation(executeRenderMockVideo),- },- {- lifecycle: "immediate" as const,- capability: mockMediaCapabilities.silence,- returns: artifactTypes.blob,- handler: operation(executeRenderMockSilence),- },{lifecycle: "immediate" as const,capability: mediaPipelineCapabilities.projectSpeechEvidenceAudio,diff --git a/packages/studio/README.md b/packages/studio/README.mdindex e8f1c2f5..818e60aa 100644--- a/packages/studio/README.md+++ b/packages/studio/README.md@@ -79,3 +79,10 @@ attribute names, runtime id prefixes or coincident frame spans.Opening Studio never invokes a Provider and never creates a Build. Everyprojection needed for display must already be supplied by the Run or bedeterministically derivable from those supplied Candidates.++Studio and an encoded review use the same ordinary Run. Studio evaluates its+deterministic display closure in the browser; building that Run evaluates the+full target closure and sends the resulting HyperFrames document to the chosen+render Endpoint. A separate review Run is useful only when the author wants a+different Candidate selection. Its path and filename carry no execution+semantics.diff --git a/packages/studio/package.json b/packages/studio/package.jsonindex a713a7c0..e8ac2142 100644--- a/packages/studio/package.json+++ b/packages/studio/package.json@@ -46,7 +46,6 @@"@hypit/video-cli": "workspace:*","@hypit/workspace": "workspace:*","@hypit/workspace-fs-node": "workspace:*",- "@hypit/provider-media-local": "workspace:*","vite": "5.4.21"}}diff --git a/packages/studio/src/execute.ts b/packages/studio/src/execute.tsindex 3962e9a0..cbab10c8 100644--- a/packages/studio/src/execute.ts+++ b/packages/studio/src/execute.ts@@ -16,8 +16,8 @@ export async function executeDeterministic(domain: StudioDomain,planned: BuildState,resources: ResourceStore,- endpoints: EndpointRegistry = new EndpointRegistry(),): Promise<Executed> {+ const endpoints = new EndpointRegistry();const result = await new NodeDriver({producers: domain.producers,validators: domain.validators,diff --git a/packages/studio/src/programme.ts b/packages/studio/src/programme.tsindex 26c5cf39..e863bbac 100644--- a/packages/studio/src/programme.ts+++ b/packages/studio/src/programme.ts@@ -16,7 +16,6 @@ import type { StudioResolvedTrack, StudioTemporalBinding } from "@hypit/studio-aimport type { CompiledSource, ServedFile } from "./compile.js";import type { StudioDomain } from "./domain.js";import { executeDeterministic, MemoryResourceStore } from "./execute.js";-import type { EndpointRegistry } from "@hypit/driver-node";import type { RunPlan } from "./run.js";import type { StudioViewRequirement } from "./studio-preflight.js";import { studioSurfacePreview } from "./surface-preview.js";@@ -110,8 +109,6 @@ export async function preview(input: {readonly outputRefs: readonly string[];readonly compositionRef: string;readonly projections: readonly StudioViewRequirement[];- /** Preview-only endpoint set. Production Studio passes none; preview-mock may pass only local mock media. */- readonly endpoints?: EndpointRegistry;}): Promise<Preview> {const exportsByRef = new Map(input.source.exports.map((item) => [item.ref, item] as const));const targets = input.outputRefs.flatMap((ref) => {@@ -149,7 +146,7 @@ export async function preview(input: {},};const planned = input.run.plan(input.run.run, targets.map((target) => target.ref));- const executed = await executeDeterministic(input.domain, planned.state, resources, input.endpoints);+ const executed = await executeDeterministic(input.domain, planned.state, resources);if (executed.unserved.length > 0) {throw new Error(`Studio projection is unresolved: ${executed.unserved.map((item) => item.capability).join(", ")}`,diff --git a/packages/studio/src/server.ts b/packages/studio/src/server.tsindex 136b30de..fe05ae95 100644--- a/packages/studio/src/server.ts+++ b/packages/studio/src/server.ts@@ -9,7 +9,6 @@ import { pipeline } from "node:stream/promises";import type { Plugin, ViteDevServer } from "vite";import type { BuildResultFileRange } from "@hypit/build-result";import type { StudioTemporalInstantProjection } from "@hypit/studio-adapter";-import type { EndpointRegistry } from "@hypit/driver-node";import type { StudioBuildLibrary } from "./build-library.js";import type { ServedFile } from "./compile.js";@@ -31,7 +30,6 @@ export type StudioPluginOptions = {readonly registry: StudioCompanionRegistry;readonly workspaceRoot: string;readonly buildLibrary?: StudioBuildLibrary;- readonly endpoints?: EndpointRegistry;};function json(response: import("node:http").ServerResponse, status: number, value: unknown): void {@@ -138,7 +136,6 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {domain: options.domain,registry: options.registry,...(options.buildLibrary === undefined ? {} : { buildLibrary: options.buildLibrary }),- ...(options.endpoints === undefined ? {} : { endpoints: options.endpoints }),});currentSource = run.authorSource;watchSource(options.runPath);@@ -153,7 +150,6 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {registry: options.registry,run,...(options.buildLibrary === undefined ? {} : { buildLibrary: options.buildLibrary }),- ...(options.endpoints === undefined ? {} : { endpoints: options.endpoints }),revision: attempt,sourcePath: relative(options.workspaceRoot, run.authorSource),workspaceRoot: options.workspaceRoot,diff --git a/packages/studio/src/session.ts b/packages/studio/src/session.tsindex 2a250084..a7f7ba2e 100644--- a/packages/studio/src/session.ts+++ b/packages/studio/src/session.ts@@ -1,6 +1,5 @@import { existsSync, readFileSync } from "node:fs";import { relative } from "node:path";-import type { EndpointRegistry } from "@hypit/driver-node";import { markupAuthorFrontendId } from "@hypit/markup";import { svsFrontendId } from "@hypit/svs";@@ -14,7 +13,7 @@ import type { RunPlan } from "./run.js";import type { StudioSnapshot } from "./shared.js";import type { StudioCompanionRegistry } from "./studio-registry.js";import { snapshot } from "./snapshot.js";-import { PREVIEW_LOCAL_MEDIA_CAPABILITIES, inspectStudioRun } from "./studio-preflight.js";+import { inspectStudioRun } from "./studio-preflight.js";import type { StudioViewRequirement } from "./studio-preflight.js";import type { StudioSourceFile } from "./parameters.js";@@ -59,14 +58,9 @@ export async function readStudioSession(input: {readonly revision: number;readonly sourcePath?: string;readonly workspaceRoot: string;- /** Preview-only local deterministic media endpoints (never paid/external Providers). */- readonly endpoints?: EndpointRegistry;}): Promise<StudioSession> {const source = input.run.source;- // The endpoints a preview Run carries are the local deterministic media ones, so the capabilities- // they serve are resolved for this session exactly as they are for the startup preflight.- const inspection = inspectStudioRun(input.registry, source, input.run,- input.endpoints === undefined ? undefined : PREVIEW_LOCAL_MEDIA_CAPABILITIES);+ const inspection = inspectStudioRun(input.registry, source, input.run);const outputRefs = [inspection.filmComposition,...inspection.projections.map((projection) => projection.ref),@@ -78,7 +72,6 @@ export async function readStudioSession(input: {outputRefs,compositionRef: inspection.filmComposition,projections: inspection.projections,- ...(input.endpoints === undefined ? {} : { endpoints: input.endpoints }),});const rendered = renderPreview({composition: built.composition,diff --git a/packages/studio/src/studio-preflight.ts b/packages/studio/src/studio-preflight.tsindex 1a1f1bee..db4b8a7e 100644--- a/packages/studio/src/studio-preflight.ts+++ b/packages/studio/src/studio-preflight.ts@@ -49,11 +49,11 @@ function candidateIsMaterialized(candidate: Candidate | undefined): boolean {&& candidate.root.value.value.kind === "inline";}-function plannedExternalNeeds(base: RunPlan, refs: readonly string[], resolved: ReadonlySet<string> = new Set()): readonly string[] {+function plannedExternalNeeds(base: RunPlan, refs: readonly string[]): readonly string[] {const planned = base.plan(base.run, refs);return unique(plannedNeeds(planned.state).map((need) =>`${need.capability.module.name}@${need.capability.module.version}#${need.capability.name}`,- ).filter((name) => !resolved.has(name)));+ ));}function localName(value: string): string {@@ -85,19 +85,6 @@ function filmForTarget(registry: StudioCompanionRegistry, source: CompiledSourcereturn found === undefined ? { renderTarget: false } : { renderTarget: true, ...found };}-/**- * The deterministic media capabilities a preview Run still reaches after its mock media is- * persisted. They are served by the local FFmpeg endpoint Studio installs for a preview Run, never- * by a paid or external Provider, so a projection that needs one of them is not unresolved.- */-export const PREVIEW_LOCAL_MEDIA_CAPABILITIES: ReadonlySet<string> = new Set([- "@hypit/media-pipeline@1#inspect-media",- "@hypit/media-pipeline@1#normalize-media",- "@hypit/media-pipeline@1#extract-audio",- "@hypit/media-pipeline@1#render-audio",- "@hypit/media-pipeline@1#mux",-]);-/*** Video-domain policy is centralized here, inside Studio. Core still only* supplies the compiled graph and its exact BuildPlan/Need closure.@@ -106,7 +93,6 @@ export function inspectStudioRun(registry: StudioCompanionRegistry,source: CompiledSource,base: RunPlan,- resolvedCapabilities: ReadonlySet<string> = new Set(),): StudioInspection {const issues: string[] = [];if (base.targets.length === 0) issues.push("the Run Source has no target; Studio requires Film or Render");@@ -201,7 +187,7 @@ export function inspectStudioRun(}if (derived.length > 0) {- const needs = plannedExternalNeeds(base, derived.map((projection) => projection.ref), resolvedCapabilities);+ const needs = plannedExternalNeeds(base, derived.map((projection) => projection.ref));if (needs.length > 0) {issues.push(`the Studio projection closure requires unresolved capabilities: ${needs.join(", ")}`);} else {diff --git a/packages/studio/start.ts b/packages/studio/start.tsindex b275fff1..af17a3d7 100644--- a/packages/studio/start.ts+++ b/packages/studio/start.ts@@ -4,15 +4,13 @@ import { fileURLToPath } from "node:url";import { createServer } from "vite";import { findRuntimeProfile } from "@hypit/cli";import { videoCliDistribution } from "@hypit/video-cli";-import { EndpointRegistry } from "@hypit/driver-node";-import { createLocalMediaProvider } from "@hypit/provider-media-local";import { openStudioBuildLibrary } from "./src/build-library.js";import { loadStudioCompanionRegistry } from "./src/companion-profile.js";import { loadStudioDomain } from "./src/domain.js";import { loadStudioRun } from "./src/run.js";import { studioPlugin } from "./src/server.js";-import { PREVIEW_LOCAL_MEDIA_CAPABILITIES, inspectStudioRun } from "./src/studio-preflight.js";+import { inspectStudioRun } from "./src/studio-preflight.js";const here = dirname(fileURLToPath(import.meta.url));@@ -49,7 +47,6 @@ const invokedFrom = process.env.INIT_CWD ?? process.cwd();const runArgument = values.get("run");if (runArgument === undefined || runArgument.trim().length === 0) usage("Missing --run");const runPath = resolve(invokedFrom, runArgument);-const previewOnly = /[\\/]\.hypit[\\/]preview[\\/]/u.test(runPath);const packageRootArgument = values.get("package-root");const workspaceArgument = values.get("workspace");const requestedWorkspaceRoot = workspaceArgument === undefined@@ -93,14 +90,8 @@ try {throw error;}const source = run.authorSource;-// A preview Run has already persisted all mock media as relative file-// Candidates, but deterministic inspect/normalize/render-media Producers still-// need the local FFmpeg endpoint. This is not a paid or external Provider and-// is never installed for ordinary production Runs.-const endpoints = previewOnly ? new EndpointRegistry() : undefined;-if (endpoints !== undefined) await createLocalMediaProvider({}).install(endpoints);try {- inspectStudioRun(registry, run.source, run, previewOnly ? PREVIEW_LOCAL_MEDIA_CAPABILITIES : undefined);+ inspectStudioRun(registry, run.source, run);} catch (error) {await buildLibrary?.close();throw error;@@ -123,7 +114,6 @@ const server = await createServer({domain,registry,...(buildLibrary === undefined ? {} : { buildLibrary }),- ...(endpoints === undefined ? {} : { endpoints }),})],});await server.listen();diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 6f67fe2b..865d8c13 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -120,18 +120,12 @@ importers:'@hypit/minimax-h3':specifier: workspace:*version: link:packages/minimax-h3- '@hypit/mock-media':- specifier: workspace:*- version: link:packages/mock-media'@hypit/nano-banana':specifier: workspace:*version: link:packages/nano-banana'@hypit/narrative':specifier: workspace:*version: link:packages/narrative- '@hypit/preview-mock':- specifier: workspace:*- version: link:packages/preview-mock'@hypit/program-space':specifier: workspace:*version: link:packages/program-space@@ -1817,33 +1811,6 @@ importers:specifier: workspace:*version: link:../text- packages/mock-media:- dependencies:- '@hypit/artifact':- specifier: workspace:*- version: link:../artifact- '@hypit/elaborator':- specifier: workspace:*- version: link:../elaborator- '@hypit/media':- specifier: workspace:*- version: link:../media- '@hypit/program-space':- specifier: workspace:*- version: link:../program-space- '@hypit/protocol':- specifier: workspace:*- version: link:../protocol- '@hypit/run':- specifier: workspace:*- version: link:../run- '@hypit/spatial':- specifier: workspace:*- version: link:../spatial- '@hypit/speech':- specifier: workspace:*- version: link:../speech-packages/model-kit:dependencies:'@hypit/artifact':@@ -1910,51 +1877,6 @@ importers:specifier: workspace:*version: link:../protocol- packages/preview-mock:- dependencies:- '@hypit/artifact':- specifier: workspace:*- version: link:../artifact- '@hypit/compiler-node':- specifier: workspace:*- version: link:../compiler-node- '@hypit/driver-node':- specifier: workspace:*- version: link:../driver-node- '@hypit/media':- specifier: workspace:*- version: link:../media- '@hypit/mock-media':- specifier: workspace:*- version: link:../mock-media- '@hypit/program-space':- specifier: workspace:*- version: link:../program-space- '@hypit/protocol':- specifier: workspace:*- version: link:../protocol- '@hypit/provider-media-local':- specifier: workspace:*- version: link:../provider-media-local- '@hypit/resource-store-fs':- specifier: workspace:*- version: link:../resource-store-fs- '@hypit/semantic-take-estimate':- specifier: workspace:*- version: link:../semantic-take-estimate- '@hypit/spatial':- specifier: workspace:*- version: link:../spatial- '@hypit/speech':- specifier: workspace:*- version: link:../speech- '@hypit/text':- specifier: workspace:*- version: link:../text- '@hypit/workspace':- specifier: workspace:*- version: link:../workspace-packages/program-space:dependencies:'@hypit/markup':@@ -2231,9 +2153,6 @@ importers:'@hypit/media-pipeline':specifier: workspace:*version: link:../media-pipeline- '@hypit/mock-media':- specifier: workspace:*- version: link:../mock-media'@hypit/protocol':specifier: workspace:*version: link:../protocol@@ -3067,9 +2986,6 @@ importers:'@hypit/protocol':specifier: workspace:*version: link:../protocol- '@hypit/provider-media-local':- specifier: workspace:*- version: link:../provider-media-local'@hypit/ranking-studio':specifier: workspace:*version: link:../ranking-studio