AI media harness for planning, generating, and editing locally
TypeScript
Extend project data for editor workspace
Bitti328efb2e3fe0
diff --git a/src/lib/persistence.ts b/src/lib/persistence.tsindex c83f39d..0e979de 100644--- a/src/lib/persistence.ts+++ b/src/lib/persistence.ts@@ -2,6 +2,7 @@ import { invoke } from "@tauri-apps/api/core";import {createProjectConfig,parseProjectConfig,+ seedProjectWorkspace,type CreateProjectInput,type ProjectConfig,type ProjectRecord,@@ -65,7 +66,7 @@ function webSeedProjects(): ProjectRecord[] {config.id = `sample-${index + 1}`;config.createdAt = new Date(now.getTime() - seed.offset * 86_400_000).toISOString();config.updatedAt = new Date(now.getTime() - (index * 22 + 3) * 3_600_000).toISOString();- return { folderPath: seed.path, config };+ return { folderPath: seed.path, config: seedProjectWorkspace(config, index) };});}@@ -74,7 +75,9 @@ function getWebProjects(): ProjectRecord[] {if (stored) {return stored.flatMap((record) => {try {- return [{ ...record, config: parseProjectConfig(record.config) }];+ const parsed = parseProjectConfig(record.config);+ const sampleIndex = /^sample-(\d+)$/.exec(parsed.id);+ return [{ ...record, config: sampleIndex ? seedProjectWorkspace(parsed, Number(sampleIndex[1]) - 1) : parsed }];} catch {return [];}diff --git a/src/lib/project.test.ts b/src/lib/project.test.tsindex 0ba8aaf..2e8b4c7 100644--- a/src/lib/project.test.ts+++ b/src/lib/project.test.ts@@ -5,6 +5,7 @@ import {normalizeProjectPath,parseProjectConfig,projectNameFromPrompt,+ seedProjectWorkspace,} from "./project";describe("project schema", () => {@@ -70,4 +71,19 @@ describe("project schema", () => {"Cinematic film about a midnight train through",);});++ it("seeds a portable, screenshot-ready editing workspace", () => {+ const project = seedProjectWorkspace(createProjectConfig({+ name: "Northern Light",+ prompt: "A brand film about humane architecture",+ aspectRatio: "16:9",+ resolution: "4k",+ targetDurationSeconds: 34,+ }));+ expect(project.timeline.tracks).toHaveLength(4);+ expect(project.generationJobs.some((job) => job.status === "generating")).toBe(true);+ expect(project.references.some((reference) => reference.kind === "image")).toBe(true);+ expect(project.assets.every((asset) => !asset.relativePath.match(/^([a-z]:|[/\\])/i))).toBe(true);+ expect(project.generationJobs.filter((job) => job.outputRelativePath).every((job) => !job.outputRelativePath!.match(/^([a-z]:|[/\\])/i))).toBe(true);+ });});diff --git a/src/lib/project.ts b/src/lib/project.tsindex 079cea6..6a8231f 100644--- a/src/lib/project.ts+++ b/src/lib/project.ts@@ -7,20 +7,14 @@ const idSchema = z.string().min(1);const isoDateSchema = z.string().datetime();export function normalizeProjectPath(value: string): string {- if (!value || value.includes("\0")) {- throw new Error("Project paths cannot be empty or contain null bytes.");- }+ if (!value || value.includes("\0")) throw new Error("Project paths cannot be empty or contain null bytes.");if (/^[\\/]/.test(value) || /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(value)) {throw new Error("Project paths must be relative to the project root.");}const parts = value.replace(/\\/g, "/").split("/");- if (parts.includes("..")) {- throw new Error("Project paths cannot traverse outside the project root.");- }+ if (parts.includes("..")) throw new Error("Project paths cannot traverse outside the project root.");const normalized = parts.filter((part) => part && part !== ".").join("/");- if (!normalized) {- throw new Error("Project paths must point to an item below the project root.");- }+ if (!normalized) throw new Error("Project paths must point to an item below the project root.");return normalized;}@@ -59,6 +53,8 @@ export const timelineClipSchema = z.object({durationMs: z.number().int().positive(),sourceStartMs: z.number().int().nonnegative().default(0),label: z.string().min(1),+ color: z.string().optional(),+ status: z.enum(["draft", "generated", "approved"]).default("approved"),});export const timelineTrackSchema = z.object({@@ -78,17 +74,16 @@ export const generationBriefSchema = z.object({resolution: resolutionSchema,});-export const reusableReferenceSchema = z.object({+export const projectReferenceSchema = z.object({id: idSchema,kind: z.enum(["text", "image"]),name: z.string().min(1),- content: z.string().min(1).nullable(),- relativePath: projectRelativePathSchema.nullable(),+ description: z.string().min(1),+ content: z.string().min(1).nullable().optional(),+ relativePath: projectRelativePathSchema.nullable().optional(),+ intendedUse: z.array(z.enum(["character", "product", "location", "style", "audio"])).default([]),createdAt: isoDateSchema,}).superRefine((reference, context) => {- if (reference.kind === "text" && !reference.content) {- context.addIssue({ code: z.ZodIssueCode.custom, path: ["content"], message: "Text references require content." });- }if (reference.kind === "image" && !reference.relativePath) {context.addIssue({ code: z.ZodIssueCode.custom, path: ["relativePath"], message: "Image references require a relative path." });}@@ -96,13 +91,18 @@ export const reusableReferenceSchema = z.object({export const generationJobSchema = z.object({id: idSchema,- status: z.enum(["draft", "queued", "generating", "ready", "failed", "cancelled"]),+ title: z.string().min(1),+ prompt: z.string().min(1),+ status: z.enum(["draft", "queued", "generating", "ready", "completed", "failed", "cancelled"]),+ stage: z.enum(["queued", "preparing", "generating", "encoding", "completed", "failed"]),+ progress: z.number().min(0).max(1),providerId: idSchema.nullable(),creativeBrief: z.string().min(1),compiledPrompt: z.string().min(1),referenceIds: z.array(idSchema).default([]),- outputRelativePath: projectRelativePathSchema.nullable(),- error: z.string().min(1).nullable(),+ clipId: idSchema.optional(),+ outputRelativePath: projectRelativePathSchema.nullable().optional(),+ error: z.string().min(1).nullable().optional(),createdAt: isoDateSchema,updatedAt: isoDateSchema,});@@ -114,17 +114,13 @@ export const agentMessageSchema = z.object({createdAt: isoDateSchema,});-export const agentConversationSchema = z.object({- messages: z.array(agentMessageSchema).default([]),-});-+export const agentConversationSchema = z.object({ messages: z.array(agentMessageSchema).default([]) });const providerOptionSchema = z.union([z.string(), z.number(), z.boolean()]);export const providerSettingSchema = z.object({enabled: z.boolean(),model: z.string().min(1).nullable(),options: z.record(providerOptionSchema).default({}),});-export const providerSettingsSchema = z.record(idSchema, providerSettingSchema);export const projectConfigSchema = z.object({@@ -143,7 +139,7 @@ export const projectConfigSchema = z.object({brief: generationBriefSchema,assets: z.array(projectAssetSchema),timeline: z.object({ tracks: z.array(timelineTrackSchema) }),- references: z.array(reusableReferenceSchema).default([]),+ references: z.array(projectReferenceSchema).default([]),generationJobs: z.array(generationJobSchema).default([]),agentConversation: agentConversationSchema.default({ messages: [] }),providerSettings: providerSettingsSchema.default({}),@@ -155,18 +151,14 @@ export type ProjectAsset = z.infer<typeof projectAssetSchema>;export type TimelineClip = z.infer<typeof timelineClipSchema>;export type TimelineTrack = z.infer<typeof timelineTrackSchema>;export type GenerationBrief = z.infer<typeof generationBriefSchema>;-export type ReusableReference = z.infer<typeof reusableReferenceSchema>;+export type ProjectReference = z.infer<typeof projectReferenceSchema>;export type GenerationJob = z.infer<typeof generationJobSchema>;export type AgentMessage = z.infer<typeof agentMessageSchema>;export type AgentConversation = z.infer<typeof agentConversationSchema>;export type ProviderSetting = z.infer<typeof providerSettingSchema>;export type ProjectConfig = z.infer<typeof projectConfigSchema>;-export interface ProjectRecord {- folderPath: string;- config: ProjectConfig;-}-+export interface ProjectRecord { folderPath: string; config: ProjectConfig }export interface CreateProjectInput {name: string;prompt: string;@@ -185,39 +177,72 @@ export function createProjectConfig(input: CreateProjectInput): ProjectConfig {createdAt: now,updatedAt: now,thumbnail: null,- settings: {- aspectRatio: input.aspectRatio,- resolution: input.resolution,- frameRate: 30,- backgroundColor: "#10131a",- },+ settings: { aspectRatio: input.aspectRatio, resolution: input.resolution, frameRate: 30, backgroundColor: "#10131a" },brief: {- prompt: input.prompt.trim(),- status: "draft",- targetDurationSeconds: input.targetDurationSeconds,- aspectRatio: input.aspectRatio,- resolution: input.resolution,+ prompt: input.prompt.trim(), status: "draft", targetDurationSeconds: input.targetDurationSeconds,+ aspectRatio: input.aspectRatio, resolution: input.resolution,},- assets: [],- timeline: { tracks: [] },- references: [],- generationJobs: [],- agentConversation: { messages: [] },- providerSettings: {},+ assets: [], timeline: { tracks: [] }, references: [], generationJobs: [],+ agentConversation: { messages: [] }, providerSettings: {},});}-export function parseProjectConfig(value: unknown): ProjectConfig {- return projectConfigSchema.parse(value);+const h3Prompt = (description: string, sound = "Quiet room tone.") =>+ `integrated_multimodal_description: [Shot 1] ${description}\n\noverall_soundscape: ${sound}\n\nnon_diegetic_music: N/A`;++export function seedProjectWorkspace(config: ProjectConfig, seed = 0): ProjectConfig {+ if (config.timeline.tracks.length > 0) return config;+ const createdAt = config.createdAt;+ const hues = seed % 2 === 0 ? ["#516fba", "#8b5d74", "#90734e"] : ["#4f7a72", "#8a654a", "#665b91"];+ const assets: ProjectAsset[] = [+ { id: "asset-establishing", kind: "generated", name: "City at blue hour", relativePath: "media/generated/scene-01.mp4", mimeType: "video/mp4", durationMs: 7200, width: 3840, height: 2160, createdAt },+ { id: "asset-studio", kind: "generated", name: "Studio details", relativePath: "media/generated/scene-02.mp4", mimeType: "video/mp4", durationMs: 8600, width: 3840, height: 2160, createdAt },+ { id: "asset-portrait", kind: "generated", name: "Architect portrait", relativePath: "media/generated/scene-03.mp4", mimeType: "video/mp4", durationMs: 7600, width: 3840, height: 2160, createdAt },+ { id: "asset-rooftop", kind: "generated", name: "Rooftop resolve", relativePath: "media/generated/scene-04.mp4", mimeType: "video/mp4", durationMs: 8400, width: 3840, height: 2160, createdAt },+ { id: "asset-score", kind: "audio", name: "Glass & concrete score", relativePath: "media/imported/score.wav", mimeType: "audio/wav", durationMs: 36000, createdAt },+ { id: "asset-voice", kind: "audio", name: "Mara voice-over", relativePath: "media/generated/voice-over.wav", mimeType: "audio/wav", durationMs: 32000, createdAt },+ ];+ const videoClips: TimelineClip[] = [+ { id: "clip-01", assetId: "asset-establishing", trackId: "track-v1", startMs: 0, durationMs: 7200, sourceStartMs: 0, label: "01 · A city still becoming", color: hues[0], status: "approved" },+ { id: "clip-02", assetId: "asset-studio", trackId: "track-v1", startMs: 7200, durationMs: 8600, sourceStartMs: 0, label: "02 · From line to light", color: hues[1], status: "approved" },+ { id: "clip-03", assetId: "asset-portrait", trackId: "track-v1", startMs: 15800, durationMs: 7600, sourceStartMs: 0, label: "03 · Designed for people", color: hues[2], status: "generated" },+ { id: "clip-04", assetId: "asset-rooftop", trackId: "track-v1", startMs: 23400, durationMs: 8400, sourceStartMs: 0, label: "04 · Northern light", color: hues[0], status: "approved" },+ ];+ const references: ProjectReference[] = [+ { id: "ref-mara", kind: "text", name: "Mara · lead architect", description: "Calm, observant woman in her late 30s. Charcoal wool, precise gestures, quiet confidence. Keep facial features and wardrobe consistent.", content: "Calm, observant woman in her late 30s. Charcoal wool, precise gestures, quiet confidence.", intendedUse: ["character"], createdAt },+ { id: "ref-building", kind: "image", name: "Harbor facade", description: "Primary material and geometry reference. Retain pale stone fins, deep window reveals, and cool northern daylight.", relativePath: "references/harbor-facade.jpg", intendedUse: ["location", "style"], createdAt },+ { id: "ref-grade", kind: "text", name: "Blue-hour grade", description: "Slate shadows, warm practicals, restrained saturation, subtle 35 mm texture. Skin tones remain natural and luminous.", content: "Slate shadows, warm practicals, restrained saturation, subtle 35 mm texture.", intendedUse: ["style"], createdAt },+ ];+ const job = (value: Omit<GenerationJob, "providerId" | "creativeBrief" | "compiledPrompt" | "updatedAt">): GenerationJob => ({+ ...value, providerId: "minimax-h3", creativeBrief: value.prompt,+ compiledPrompt: h3Prompt(value.prompt), updatedAt: value.createdAt,+ });+ const generationJobs: GenerationJob[] = [+ job({ id: "job-active", title: "Macro model details", prompt: "Slow controlled push across the scale model as morning light catches its edges.", status: "generating", stage: "generating", progress: 0.68, clipId: "clip-03", referenceIds: ["ref-building", "ref-grade"], createdAt }),+ job({ id: "job-queued", title: "Hands sketching elevation", prompt: "Overhead close shot of Mara drafting a final elevation in graphite.", status: "queued", stage: "queued", progress: 0, referenceIds: ["ref-mara", "ref-grade"], createdAt }),+ job({ id: "job-complete-1", title: "Harbor establishing shot", prompt: "Wide harbor architecture at blue hour, slow aerial drift.", status: "completed", stage: "completed", progress: 1, clipId: "clip-01", outputRelativePath: "media/generated/scene-01.mp4", referenceIds: ["ref-building", "ref-grade"], createdAt }),+ job({ id: "job-complete-2", title: "Architect at studio window", prompt: "Mara studies the skyline beside a studio window, subtle handheld movement.", status: "completed", stage: "completed", progress: 1, clipId: "clip-02", outputRelativePath: "media/generated/scene-02.mp4", referenceIds: ["ref-mara", "ref-grade"], createdAt }),+ ];+ return projectConfigSchema.parse({+ ...config,+ brief: { ...config.brief, status: "generating" },+ assets,+ timeline: { tracks: [+ { id: "track-v2", kind: "video", name: "Overlays", locked: false, muted: false, clips: [] },+ { id: "track-v1", kind: "video", name: "Story", locked: false, muted: false, clips: videoClips },+ { id: "track-a1", kind: "audio", name: "Voice-over", locked: false, muted: false, clips: [{ id: "clip-voice", assetId: "asset-voice", trackId: "track-a1", startMs: 1800, durationMs: 28000, sourceStartMs: 0, label: "Mara · narration", color: "#3d817c", status: "approved" }] },+ { id: "track-a2", kind: "audio", name: "Music", locked: false, muted: false, clips: [{ id: "clip-score", assetId: "asset-score", trackId: "track-a2", startMs: 0, durationMs: 34000, sourceStartMs: 0, label: "Glass & concrete", color: "#6b5790", status: "approved" }] },+ ] },+ references,+ generationJobs,+ });}+export function parseProjectConfig(value: unknown): ProjectConfig { return projectConfigSchema.parse(value); }+export function projectNameFromPrompt(prompt: string): string {- const cleaned = prompt- .replace(/^(create|make|generate|build|produce)\s+(me\s+)?(a|an|the)?\s*/i, "")- .replace(/[.!?]+$/g, "")- .trim();+ const cleaned = prompt.replace(/^(create|make|generate|build|produce)\s+(me\s+)?(a|an|the)?\s*/i, "").replace(/[.!?]+$/g, "").trim();if (!cleaned) return "Untitled video";const short = cleaned.split(/\s+/).slice(0, 7).join(" ");return short.charAt(0).toUpperCase() + short.slice(1);}-