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: forbid playground registries and production influence
kashorin929396fe6327
diff --git a/docs/guide/playground.md b/docs/guide/playground.mdindex 7b6b52ba..0905640a 100644--- a/docs/guide/playground.md+++ b/docs/guide/playground.md@@ -33,15 +33,23 @@ that declares a Producer emitting a `VisualTrack` appears on its own.## Hard boundary-The Playground is a consumer of the system, never an author of system-semantics. Production Protocol, Core and domain packages contain no Playground-defaults, UI hints, fixtures or preview helpers.+Two rules are permanent:++1. The Playground is a consumer of the system, never an author of system+ semantics. Production Protocol, Core and domain packages contain no+ Playground defaults, UI hints, fixtures, facets or preview helpers.+2. The Playground maintains no component, Recipe, Story, Scenario or example+ registry and defines no parallel source format. A startup command may select+ packages and ordinary SVML/SVS/Run sources for that session; selection is not+ a central catalog.The generic form uses only facts the production contract already needs:schema kinds, enums and numeric bounds. Canvas size, duration, frame rate,background and blank form values are local session state owned by this tool.If the Playground later needs richer controls or fixtures, they must be addedinside `tools/playground`; a production package must not change for that reason.+Likewise, examples remain normal project sources rather than entries in a+Playground-owned registry.## Mediadiff --git a/docs/zh/guide/playground.md b/docs/zh/guide/playground.mdindex 002db428..27953d8e 100644--- a/docs/zh/guide/playground.md+++ b/docs/zh/guide/playground.md@@ -29,12 +29,17 @@ pnpm playground## 硬边界-Playground 只能消费系统,不能定义系统语义。生产 Protocol、Core 与领域包中不得出现任何-Playground 默认值、UI 提示、fixture 或预览辅助函数。+两条规则永久成立:++1. Playground 只能消费系统,不能定义系统语义。生产 Protocol、Core 与领域包中不得出现任何+ Playground 默认值、UI 提示、fixture、facet 或预览辅助函数。+2. Playground 不维护组件、Recipe、Story、Scenario 或示例注册表,也不定义一套平行的源码格式。+ 启动命令可以为本次会话选择包和普通 SVML/SVS/Run 源码;这种局部选择不是中央目录。通用表单只消费生产合同本来就需要的事实:schema 类型、枚举和数值边界。画布大小、时长、帧率、背景色和空白表单值都只是本工具内部的会话状态。如果以后需要更丰富的控件或 fixture,必须在 `tools/playground` 内部实现,不能要求生产包为预览便利而改变。+示例同样必须是普通项目源码,不能成为 Playground 自有注册表中的条目。## 媒体diff --git a/test/playground-discovery.test.ts b/test/playground-discovery.test.tsindex e73bfe0a..0b8ece7d 100644--- a/test/playground-discovery.test.ts+++ b/test/playground-discovery.test.ts@@ -30,21 +30,44 @@ function workspace(): PreviewSources {return { manifests: entries, components };}-test("previewable modules are the ones declaring a VisualTrack Producer", async () => {- const found = await discoverPreviewProducers(workspace());- assert.deepEqual(- [...new Set(found.map((producer) => producer.moduleName))].sort(),- [- "@narratage/caption-fine",- "@narratage/comment-sticker",- "@narratage/deck-track",- "@narratage/media-track",- "@narratage/ranking",- "@narratage/screen-overlay",- "@narratage/speech-basis",- "@narratage/typography-track",- ],- );+test("an arbitrary supplied visual module is discovered without registration", async () => {+ const module = { name: "@example/visual", version: "1" } as const;+ const input = { module, name: "Input" } as const;+ const track = {+ module: { name: "@narratage/composition", version: "1" },+ name: "VisualTrack",+ } as const;+ const implementation = {+ kind: "registered", locator: "@example/visual/render",+ digest: `sha256:${"0".repeat(64)}`,+ } as const;++ const found = await discoverPreviewProducers({+ manifests: {+ arbitrary: async () => ({ manifest: {+ format: "svml.module@1", name: module.name, version: module.version,+ dependencies: [], capabilities: [], surfaces: [],+ types: [{ name: input.name, schema: { kind: "string" } }],+ producers: [{+ name: "render", inputs: [{ name: "input", type: input }],+ outputs: [{ name: "track", type: track }], needs: [], implementation,+ }],+ } }),+ },+ components: {+ arbitrary: async () => ({ component: {+ name: module.name,+ producers: [{+ producer: { module, name: "render" },+ handler: () => ({ outputs: { track: { value: "arbitrary-output" } } }),+ }],+ } }),+ },+ });++ assert.equal(found.length, 1);+ assert.equal(found[0]?.id, "@example/visual#render");+ assert.deepEqual(found[0]?.inputs.map((entry) => entry.name), ["input"]);});test("each producer carries its inputs' declared schemas", async () => {diff --git a/tools/package-boundaries.test.mjs b/tools/package-boundaries.test.mjsindex 247fe211..d56a58b0 100644--- a/tools/package-boundaries.test.mjs+++ b/tools/package-boundaries.test.mjs@@ -108,11 +108,13 @@ test("official production packages have no dependency cycle", async () => {});test("Playground cannot add semantics or metadata to production packages", async () => {+ let productionSource = "";for (const entry of await readdir(packageRoot, { withFileTypes: true })) {if (!entry.isDirectory()) continue;const sourceRoot = new URL(`./${entry.name}/src/`, packageRoot);for (const file of await sourceFiles(sourceRoot)) {const source = await readFile(file, "utf8");+ productionSource += source;assert.ok(!/\bplayground\b/iu.test(source),`${file.pathname} mentions Playground; the dependency must point from the tool to production only`);}@@ -125,6 +127,36 @@ test("Playground cannot add semantics or metadata to production packages", asyncconst valueSchemas = await readFile(new URL("./protocol/src/value.ts", packageRoot), "utf8");assert.ok(!/readonly\s+format\??\s*:/u.test(valueSchemas),"ValueSchema must not carry presentation hints for a tool");++ const componentKit = await readFile(new URL("./component-kit/src/index.ts", packageRoot), "utf8");+ assert.ok(!/\bRecipeFacet\b|readonly\s+recipes\??\s*:/u.test(componentKit),+ "ComponentPackage must not grow an editor or Playground Recipe facet");++ for (const helper of [+ "defaultProgramSpace", "defaultCanvasSpace", "defaultFilmProgram", "defaultScreenOverlayProgram",+ ]) {+ assert.ok(!productionSource.includes(helper),+ `${helper} is a preview starting value and must stay outside production packages`);+ }+});++test("Playground has no hard-coded component registry", async () => {+ const root = new URL("../tools/playground/src/", import.meta.url);+ const allowedWaists = new Set([+ "@narratage/composition",+ "@narratage/core",+ "@narratage/program-space",+ "@narratage/protocol",+ ]);+ for (const file of await sourceFiles(root)) {+ const source = await readFile(file, "utf8");+ for (const match of source.matchAll(/["'](@narratage\/[a-z0-9-]+)["']/gu)) {+ assert.ok(allowedWaists.has(match[1]),+ `${file.pathname} names ${match[1]}; components must be selected or discovered, never registered here`);+ }+ assert.ok(!/\b(?:Story|Scenario|Recipe)Registry\b/u.test(source),+ `${file.pathname} introduces a parallel Playground registry`);+ }});test("Markup syntax, graph Text and video Typography keep distinct package identities", async () => {diff --git a/tools/playground-source-bytes.test.mjs b/tools/playground-source-bytes.test.mjsindex 6b09f1d9..e9bae2bb 100644--- a/tools/playground-source-bytes.test.mjs+++ b/tools/playground-source-bytes.test.mjs@@ -1,6 +1,6 @@import assert from "node:assert/strict";import { execFileSync } from "node:child_process";-import { readFileSync } from "node:fs";+import { existsSync, readFileSync } from "node:fs";import test from "node:test";import { fileURLToPath } from "node:url";@@ -26,7 +26,12 @@ function tracked() {test("no playground source carries a raw control byte", () => {const offenders = [];for (const path of tracked()) {- const bytes = readFileSync(new URL(path, new URL("..", import.meta.url)));+ const url = new URL(path, new URL("..", import.meta.url));+ // `git ls-files -c` includes a tracked deletion until it is staged. A+ // deleted source cannot contain a control byte and must not make this+ // source-content check depend on Git's index timing.+ if (!existsSync(url)) continue;+ const bytes = readFileSync(url);for (const [index, byte] of bytes.entries()) {// Tab, newline and carriage return are the only control bytes text needs.if (byte < 0x20 && byte !== 0x09 && byte !== 0x0a && byte !== 0x0d) {diff --git a/tools/playground/README.md b/tools/playground/README.mdindex 4ee64bd0..66f902ce 100644--- a/tools/playground/README.md+++ b/tools/playground/README.md@@ -48,9 +48,15 @@ self-sufficient — a real render supplies a producer for the rest. The shim in## Dependency boundary-The dependency is one-way: the Playground may consume public production-contracts, but production contracts and packages contain no Playground-defaults, form hints, fixtures or preview helpers.+Two rules are non-negotiable:++1. The dependency is one-way. The Playground may consume public production+ contracts; Protocol, Core and every other package contain no Playground+ defaults, form hints, fixtures, facets or preview helpers.+2. The Playground owns no component, Recipe, Story, Scenario or example+ registry. It discovers what a selected environment actually exposes and may+ read ordinary SVML/SVS/Run sources; it does not maintain a second data format+ describing the system.To become discoverable, a module only declares its real Producer, ports andstructural input schemas. The Playground creates blank form state and its own@@ -61,6 +67,12 @@ The generic form uses only schema kinds, enums and numeric bounds. A richereditor or fixture system must be implemented inside this tool; it must not makea production package change merely to improve a preview.+The current workspace scan is discovery, not registration: it enumerates the+selected workspace at startup and derives eligibility from an ordinary+`VisualTrack` output. There is no checked-in list of package names. In a+project-oriented Playground, the startup command and the imported source/lock+closure will select the environment instead; no central catalog is introduced.+## Known divergences from a real render- Fonts lower to a plain CSS `font-family` string. The productiondiff --git a/tools/playground/src/preview/artifacts.ts b/tools/playground/src/preview/artifacts.tsdeleted file mode 100644index 1bc31e06..00000000--- a/tools/playground/src/preview/artifacts.ts+++ /dev/null@@ -1,85 +0,0 @@-import type { MediaArtifactRef } from "../svml.js";--/**- * Media the playground has been given, addressed the way the Runtime addresses- * it.- *- * `assertHyperframesDocument` cross-checks every `svml-artifact://` placeholder- * against the document's declared Artifacts and runs `isDigest` on each, so a- * stub digest would be rejected. These are real SHA-256 digests of the actual- * bytes, computed with Web Crypto — which is asynchronous, hence registering a- * file is too.- */--const refs = new Map<string, MediaArtifactRef>();-const urls = new Map<string, string>();--function hex(buffer: ArrayBuffer): string {- return [...new Uint8Array(buffer)].map((byte) => byte.toString(16).padStart(2, "0")).join("");-}--/** Reads a media file's own duration, which MediaArtifactRef requires. */-async function durationOf(file: File, url: string): Promise<number> {- if (file.type.startsWith("image/")) return 0;- const kind = file.type.startsWith("audio/") ? "audio" : "video";- return await new Promise<number>((resolve) => {- const probe = document.createElement(kind);- probe.preload = "metadata";- const done = (value: number): void => { probe.removeAttribute("src"); resolve(value); };- probe.addEventListener("loadedmetadata", () => {- done(Number.isFinite(probe.duration) ? probe.duration : 0);- }, { once: true });- // A file the browser cannot decode still has to produce a legal Artifact,- // so the preview can show the failure rather than refusing to build.- probe.addEventListener("error", () => done(0), { once: true });- probe.src = url;- });-}--/**- * Records an Artifact the playground can name but has no bytes for.- *- * A component only needs the reference to build a legal Composition; the bytes- * are needed to draw it. Keeping the two separable is what lets an adapter be- * exercised outside a browser, and it is also the honest model for a digest- * that arrives from somewhere other than a file picker.- */-export function registerArtifact(ref: MediaArtifactRef, objectUrl?: string): MediaArtifactRef {- refs.set(ref.digest, ref);- if (objectUrl !== undefined) urls.set(ref.digest, objectUrl);- return ref;-}--export async function registerFile(file: File): Promise<MediaArtifactRef> {- const bytes = await file.arrayBuffer();- const digest = `sha256:${hex(await crypto.subtle.digest("SHA-256", bytes))}`;- const existing = refs.get(digest);- if (existing !== undefined) return existing;-- const mediaType = file.type || "application/octet-stream";- const url = URL.createObjectURL(new Blob([bytes], { type: mediaType }));- return registerArtifact({- digest,- size: bytes.byteLength,- mediaType,- durationSec: await durationOf(file, url),- } as MediaArtifactRef, url);-}--export function artifactRef(digest: string | undefined): MediaArtifactRef | undefined {- return digest === undefined ? undefined : refs.get(digest);-}--export function artifactUrl(digest: string): string | undefined {- return urls.get(digest);-}--export function artifactLabel(digest: string | undefined): string {- if (digest === undefined) return "no media";- const ref = refs.get(digest);- if (ref === undefined) return `${digest.slice(0, 15)}… (missing)`;- const size = ref.size < 1024 * 1024- ? `${Math.round(ref.size / 1024)} KB`- : `${(ref.size / 1024 / 1024).toFixed(1)} MB`;- return `${ref.mediaType}, ${size}`;-}diff --git a/tools/playground/src/preview/render.ts b/tools/playground/src/preview/render.tsindex d75ae4d3..96e13279 100644--- a/tools/playground/src/preview/render.ts+++ b/tools/playground/src/preview/render.ts@@ -5,7 +5,6 @@ import {sealComposition,} from "../svml.js";import type { Composition, ProgramSpace, Track } from "../svml.js";-import { artifactUrl } from "./artifacts.js";import { injectRuntimeShim } from "./runtime-shim.js";/** A grey card standing in for an Artifact the playground has not been given. */@@ -50,10 +49,8 @@ export function renderPreview(input: PreviewInput): PreviewOutput {const warnings: string[] = [];const html = materializeHyperframesHtml(document, (artifact) => {- const resolved = artifactUrl(artifact.digest);- if (resolved !== undefined) return resolved;- // A missing Artifact must not blank the frame: a playground where one- // unset image hides everything else teaches nothing.+ // Artifact fulfillment belongs to a normal author/run graph. The low-level+ // component inspector owns no parallel registry of files or fixtures.warnings.push(`No media registered for ${artifact.digest.slice(0, 19)}…`);return MISSING_MEDIA;});diff --git a/tools/playground/src/svml.ts b/tools/playground/src/svml.tsindex 90cf9c7a..d864c9d3 100644--- a/tools/playground/src/svml.ts+++ b/tools/playground/src/svml.ts@@ -35,5 +35,3 @@ export type {TypeRef,ValueSchema,} from "@narratage/protocol";--export type { MediaArtifactRef } from "@narratage/media";diff --git a/tools/playground/vite.config.ts b/tools/playground/vite.config.tsindex ad71126f..f1e46264 100644--- a/tools/playground/vite.config.ts+++ b/tools/playground/vite.config.ts@@ -28,8 +28,8 @@ function workspaceAliases(): Array<{ find: string; replacement: string }> {}const entryPoint = (manifest.exports as Record<string, unknown> | undefined)?.["."];if (typeof manifest.name !== "string" || typeof entryPoint !== "string") return [];- // Exact-or-followed-by-slash matching keeps "@narratage/speech" from- // swallowing "@narratage/speech-basis".+ // Exact-or-followed-by-slash matching keeps one package prefix from+ // swallowing another package whose name happens to extend it.return [{ find: manifest.name, replacement: join(packages, entry.name, entryPoint) }];});}