🎥 Make videos programmatically with React
`@remotion/skills-evals`: Add skills playground (#9096)
Jonny Burgerc5d26eee5309
diff --git a/.gitignore b/.gitignoreindex 5917954623..a5bdabb04f 100644--- a/.gitignore+++ b/.gitignore@@ -40,3 +40,4 @@ packages/docs/outpackages/cloudrun/container/ensure-browser.mjspackages/skills-evals/.runspackages/skills-evals/.site+packages/skills-evals/.playgrounddiff --git a/package.json b/package.jsonindex 4fda149adb..43283fdbd7 100644--- a/package.json+++ b/package.json@@ -44,6 +44,7 @@"watchthree": "turbo watch make --experimental-write-cache --filter='@remotion/three'","release": "bun publish.ts && turbo run publishprivate --concurrency=1 && git push --tags && git push","publishtemplates": "cd packages/it-tests && bun src/templates/publish.ts",+ "playground": "bun packages/skills-evals/src/playground.ts","checkskills": "bun packages/skills/scripts/sync-best-practices.ts --check && bun run validateskills","syncskills": "bun packages/skills/scripts/sync-best-practices.ts","validateskills": "bun packages/skills/scripts/validate-links.ts",@@ -97,6 +98,7 @@"!packages/template-vercel/**","!packages/skills-evals/.runs/**","!packages/skills-evals/.site/**",+ "!packages/skills-evals/.playground/**","!packages/bugs"],"catalog": {diff --git a/packages/skills-evals/README.md b/packages/skills-evals/README.mdindex 4510034e8b..8650af99b2 100644--- a/packages/skills-evals/README.md+++ b/packages/skills-evals/README.md@@ -1,5 +1,13 @@# @remotion/skills-evals-## Usage+## Playground-This is an internal package and has no documentation.+Run this command from the repository root to create a clean Remotion project+with the local skills from `packages/skills/skills` linked into it:++```sh+bun playground+```++The generated project is written to `packages/skills-evals/.playground` and is+recreated each time the command runs.diff --git a/packages/skills-evals/src/playground.ts b/packages/skills-evals/src/playground.tsnew file mode 100644index 0000000000..9b3801ce67--- /dev/null+++ b/packages/skills-evals/src/playground.ts@@ -0,0 +1,68 @@+import {mkdir, rm, symlink} from 'node:fs/promises';+import {dirname, join, relative, resolve} from 'node:path';+import {runCommand} from './command';+import {+ copyBlankTemplate,+ getSkillNames,+ packageRoot,+ skillsSource,+} from './skill-project';++const playgroundRoot = resolve(packageRoot, '.playground');++const linkSkills = async () => {+ const projectSkillsRoot = join(playgroundRoot, '.agents', 'skills');+ const skillNames = await getSkillNames();++ await rm(projectSkillsRoot, {force: true, recursive: true});+ await mkdir(projectSkillsRoot, {recursive: true});++ for (const skillName of skillNames) {+ const source = join(skillsSource, skillName);+ const destination = join(projectSkillsRoot, skillName);+ const target =+ process.platform === 'win32'+ ? source+ : relative(dirname(destination), source);++ await symlink(+ target,+ destination,+ process.platform === 'win32' ? 'junction' : 'dir',+ );+ }++ return skillNames.length;+};++const main = async () => {+ const args = process.argv.slice(2);+ if (args.length > 0) {+ throw new Error(`Unknown option "${args[0]}".`);+ }++ await rm(playgroundRoot, {force: true, recursive: true});+ await copyBlankTemplate({+ projectName: 'remotion-skills-playground',+ projectRoot: playgroundRoot,+ });+ const skillCount = await linkSkills();++ process.stdout.write('Installing the playground dependencies...\n');+ const install = await runCommand({+ command: ['bun', 'install'],+ cwd: playgroundRoot,+ onOutput: ({chunk}) => process.stdout.write(chunk),+ });++ if (install.exitCode !== 0) {+ throw new Error(`bun install failed (${install.exitCode}).`);+ }++ process.stdout.write(+ `\nPlayground ready with ${skillCount} linked skills.\n\n` ++ `Start Codex in:\n${playgroundRoot}\n`,+ );+};++main();diff --git a/packages/skills-evals/src/run-skill-eval.ts b/packages/skills-evals/src/run-skill-eval.tsindex 4c036b15ed..bc56cf3fa1 100644--- a/packages/skills-evals/src/run-skill-eval.ts+++ b/packages/skills-evals/src/run-skill-eval.ts@@ -1,7 +1,6 @@import {createHash} from 'node:crypto';import {mkdir, readFile, rm, stat, writeFile} from 'node:fs/promises';import {dirname, extname, join, relative, resolve} from 'node:path';-import {fileURLToPath} from 'node:url';import type {SkillEvalScenario} from '../scenarios';import type {CommandResult} from './command';import {runCommand, type CommandOutput} from './command';@@ -9,7 +8,6 @@ import {copyDirectory,createTimestamp,listFilesRecursively,- readJson,sanitizePathPart,writeJson,} from './files';@@ -21,6 +19,13 @@ import type {VisualArtifact,} from './manifest';import {exportPiSession, runPi} from './pi';+import {+ copyBlankTemplate,+ getSkillNames,+ packageRoot,+ repoRoot,+ skillsSource,+} from './skill-project';export type SkillEvalPhase = 'install' | 'pi' | 'pi-render' | 'pi-export';@@ -47,23 +52,7 @@ type SkillEvalScenarioInput = SkillEvalScenario & {>;};-type PackageJson = {- name?: string;- dependencies?: Record<string, string>;- devDependencies?: Record<string, string>;- [key: string]: unknown;-};--const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');-const repoRoot = resolve(packageRoot, '..', '..');const runsRoot = resolve(packageRoot, '.runs');-const templateBlank = resolve(packageRoot, '..', 'template-blank');-const skillsSource = resolve(packageRoot, '..', 'skills', 'skills');-const remotionPackagesInBlankTemplate = [- '@remotion/cli',- '@remotion/eslint-config-flat',- 'remotion',-];const visualArtifactExtensions = new Set(['.gif','.jpeg',@@ -105,78 +94,6 @@ const hashDirectory = async (dir: string) => {return hash.digest('hex').slice(0, 12);};-let publishedRemotionVersionPromise: Promise<string> | null = null;--const getPublishedRemotionVersion = () => {- publishedRemotionVersionPromise ??= (async () => {- const override = process.env.REMOTION_SKILLS_EVALS_REMOTION_VERSION;-- if (override) {- return override;- }-- const result = await runCommand({- command: ['bun', 'pm', 'view', 'remotion', 'version'],- cwd: repoRoot,- timeoutMs: 30_000,- });-- if (result.exitCode !== 0) {- throw new Error(- `Could not resolve the latest published Remotion version: ${result.stderr}`,- );- }-- return result.stdout.trim();- })();-- return publishedRemotionVersionPromise;-};--const patchDependencyMap = (- dependencies: Record<string, string> | undefined,- version: string,-) => {- if (!dependencies) {- return dependencies;- }-- return Object.fromEntries(- Object.entries(dependencies).map(([name, dependencyVersion]) => [- name,- remotionPackagesInBlankTemplate.includes(name)- ? version- : dependencyVersion,- ]),- );-};--const copyBlankTemplate = async ({- projectRoot,- projectName,-}: {- projectRoot: string;- projectName: string;-}) => {- await copyDirectory(templateBlank, projectRoot);-- const packageJsonFile = join(projectRoot, 'package.json');- const packageJson = await readJson<PackageJson>(packageJsonFile);- const version = await getPublishedRemotionVersion();-- await writeJson(packageJsonFile, {- ...packageJson,- name: projectName,- dependencies: patchDependencyMap(packageJson.dependencies, version),- devDependencies: patchDependencyMap(packageJson.devDependencies, version),- });-- await writeFile(- join(projectRoot, 'README.md'),- `# ${projectName}\n\nGenerated by @remotion/skills-evals.\n`,- );-};-const copySkillsForPiDiscovery = async ({projectRoot,skillSnapshot,@@ -187,17 +104,23 @@ const copySkillsForPiDiscovery = async ({skillsSourcePath?: string;}): Promise<SkillSnapshot> => {const projectSkillsRoot = join(projectRoot, '.pi', 'skills');- const sandboxPath = join(projectSkillsRoot, 'remotion');const sourcePath = skillsSourcePath ?? skillsSource;+ const skillNames = await getSkillNames(sourcePath);+ await rm(projectSkillsRoot, {force: true, recursive: true});await mkdir(projectSkillsRoot, {recursive: true});- await copyDirectory(join(sourcePath, 'remotion'), sandboxPath);+ for (const skillName of skillNames) {+ await copyDirectory(+ join(sourcePath, skillName),+ join(projectSkillsRoot, skillName),+ );+ }return {...skillSnapshot,sourcePath,- sandboxPath,- hash: await hashDirectory(sandboxPath),+ sandboxPath: projectSkillsRoot,+ hash: await hashDirectory(projectSkillsRoot),};};diff --git a/packages/skills-evals/src/skill-project.ts b/packages/skills-evals/src/skill-project.tsnew file mode 100644index 0000000000..182fd45c84--- /dev/null+++ b/packages/skills-evals/src/skill-project.ts@@ -0,0 +1,107 @@+import {readdir, writeFile} from 'node:fs/promises';+import {dirname, join, resolve} from 'node:path';+import {fileURLToPath} from 'node:url';+import {runCommand} from './command';+import {copyDirectory, readJson, writeJson} from './files';++type PackageJson = {+ name?: string;+ dependencies?: Record<string, string>;+ devDependencies?: Record<string, string>;+ [key: string]: unknown;+};++export const packageRoot = resolve(+ dirname(fileURLToPath(import.meta.url)),+ '..',+);+export const repoRoot = resolve(packageRoot, '..', '..');+export const templateBlank = resolve(packageRoot, '..', 'template-blank');+export const skillsSource = resolve(packageRoot, '..', 'skills', 'skills');++const remotionPackagesInBlankTemplate = [+ '@remotion/cli',+ '@remotion/eslint-config-flat',+ 'remotion',+];++let publishedRemotionVersionPromise: Promise<string> | null = null;++const getPublishedRemotionVersion = () => {+ publishedRemotionVersionPromise ??= (async () => {+ const override = process.env.REMOTION_SKILLS_EVALS_REMOTION_VERSION;++ if (override) {+ return override;+ }++ const result = await runCommand({+ command: ['bun', 'pm', 'view', 'remotion', 'version'],+ cwd: repoRoot,+ timeoutMs: 30_000,+ });++ if (result.exitCode !== 0) {+ throw new Error(+ `Could not resolve the latest published Remotion version: ${result.stderr}`,+ );+ }++ return result.stdout.trim();+ })();++ return publishedRemotionVersionPromise;+};++const patchDependencyMap = (+ dependencies: Record<string, string> | undefined,+ version: string,+) => {+ if (!dependencies) {+ return dependencies;+ }++ return Object.fromEntries(+ Object.entries(dependencies).map(([name, dependencyVersion]) => [+ name,+ remotionPackagesInBlankTemplate.includes(name)+ ? version+ : dependencyVersion,+ ]),+ );+};++export const copyBlankTemplate = async ({+ projectRoot,+ projectName,+}: {+ projectRoot: string;+ projectName: string;+}) => {+ await copyDirectory(templateBlank, projectRoot);++ const packageJsonFile = join(projectRoot, 'package.json');+ const packageJson = await readJson<PackageJson>(packageJsonFile);+ const version = await getPublishedRemotionVersion();++ await writeJson(packageJsonFile, {+ ...packageJson,+ name: projectName,+ dependencies: patchDependencyMap(packageJson.dependencies, version),+ devDependencies: patchDependencyMap(packageJson.devDependencies, version),+ });++ await writeFile(+ join(projectRoot, 'README.md'),+ `# ${projectName}\n\nGenerated by @remotion/skills-evals.\n`,+ );+};++export const getSkillNames = async (sourcePath = skillsSource) => {+ const entries = await readdir(sourcePath, {withFileTypes: true});++ return entries+ .filter((entry) => entry.isDirectory())+ .map((entry) => entry.name)+ .sort();+};