This file defines the operating rules, architecture boundaries, and verification steps for AI coding agents working in this repository. Read GEMINI.md alongside this file before making changes.
We are extending Timeline Studio (MartinDelophy/ai-video-editor) into a 1-click Indic Short-Form Video Auto-Editor powered by Sarvam AI.
Do NOT rebuild the video editor. Timeline Studio already handles multi-track rendering, canvas preview, WebCodecs MP4 export, and timeline scrubbing. Your job as a coding agent is to:
- Build and maintain the Python FastAPI backend (
backend/) that orchestrates Sarvam AI + dynamic sticker generation. - Add the "⚡ Auto-Cut" trigger and JSON-to-Timeline dispatcher in the React/TypeScript frontend (
src/). - Keep the edit experience 100% human-in-the-loop (all AI edits land as editable tracks on the timeline).
npm install
npm run dev # Starts Next.js dev server (preserves COOP/COEP headers)
npm run build # Production bundle checkcd backend
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload --port 8000SARVAM_API_KEY=your_sarvam_api_subscription_key # Required: the auto-edit endpoint returns 503 without it
FALLBACK_PROVIDER=none # Optional: "groq" | "gemini" if Sarvam times out
GROQ_API_KEY= # Optional fallback- DO NOT refactor Timeline Studio's core WebCodecs encoder, WebGPU shaders, color wheels, or depth-map pipelines.
- DO inspect the existing timeline store (
src/storeorsrc/features/timeline) and.agent/skills/edit-timeline-studioto reuse existing track-mutation actions (splitting clips, adding text/caption tracks, adding overlay/PiP images, adding audio tracks). - DO keep all new UI additions minimal and cohesive (one "⚡ Auto-Cut" button, loading state indicator, and optional language/caption-style toggle: Romanized Hinglish vs Dual Hinglish + English).
- Unit tests and frontend integration tests MUST NOT hit the live Sarvam API. Stub the network boundary instead: patch
sarvam_client._stt_requestandsarvam_client._call_sarvam(seeTestLivePipelineStubbedinbackend/test_suite.py) and set a dummySARVAM_API_KEYin the test environment. - There is no mock mode or cached sample plan. Live Sarvam calls happen only on manual runs (e.g. clicking Auto-Cut in the UI).
- Never write an automated test loop that calls
https://api.sarvam.ai/speech-to-textor/v2/chat/completionsrepeatedly.
- All timestamps across the backend and frontend must be floating-point seconds (e.g.,
1.25, not"00:01:25"). - When
cutsare applied via ripple-delete, ensure downstreamcaptions,stickers,sfx, andzoomstimestamps are either:- Applied before ripple-cutting (so Timeline Studio's ripple-delete shifts them automatically), OR
- Offset mathematically in the dispatcher to match the post-cut timeline clock. (Verify which behavior Timeline Studio's split/delete action uses before wiring the dispatcher!)
- Because Timeline Studio runs with
Cross-Origin-Embedder-Policy: require-corp, any sticker PNG or SFX MP3 served fromhttp://localhost:8000will be blocked by the browser unless FastAPI sets:response.headers["Cross-Origin-Resource-Policy"] = "cross-origin"
- Alternatively, configure a Next.js rewrite proxy (
/apiand/dynamic_stickers->http://localhost:8000) innext.config.mjsso all assets appear same-origin to the browser. Prefer the Next.js rewrite proxy approach.
- NEVER use emojis anywhere in the React/TypeScript UI — not in button labels, status text, tooltips, track headers, panel titles, toasts, or any other interface element.
- ALWAYS use icons from
lucide-reactfor all iconography in the UI. Import named exports only (e.g.import { Zap, ChevronRight, Scissors } from 'lucide-react'). - Use
strokeWidth={1.25}for all Lucide icons to match the premium ultra-light aesthetic. Adjust tostrokeWidth={1.5}only for small icons under 14px. - Exception: Emojis are permitted exclusively inside the actual video content output — e.g. text overlays, karaoke captions, or sticker labels that get burned into the exported MP4. Never in any UI chrome.
- Sticker Scraping:
duckduckgo_searchcan fail or return irrelevant images. Wrapfetch_and_make_sticker()in atry/exceptwith a 4-second timeout. If it fails, fall back to a matching icon inpublic/assets/stickers/or skip that sticker cleanly without crashing the pipeline. - LLM Output: Always request
response_format={"type": "json_object"}fromsarvam-105band validate the response with Pydantic before returning it to the frontend.
| File | Responsibility |
|---|---|
backend/main.py |
FastAPI app, CORS, /api/sarvam-auto-edit endpoint, /api/health. Accepts uploaded video/audio, coordinates pipeline, returns validated EditPlan JSON. |
backend/sarvam_client.py |
Calls saaras:v4 (mode="translit") for phrase-level timestamps and sarvam-105b for the director JSON. Implements FALLBACK_PROVIDER (Groq / Gemini) with an offline heuristic director as the last resort. |
backend/sticker_engine.py |
Searches web images via duckduckgo_search, strips background with rembg, saves RGBA PNGs to public/assets/dynamic_stickers/, and enforces disk caching. |
backend/silence_detector.py |
Uses pydub.silence.detect_silence() to detect dead-air intervals locally at zero API cost and merges them with LLM-identified filler cuts. |
backend/schemas.py |
Pydantic models for WordTimestamp, CutSegment, StickerOverlay, SfxEvent, ZoomKeyframe, and EditPlan. |
Before marking a feature or PR complete, agents must verify:
- Type Check & Build:
npm run buildsucceeds with zero TypeScript errors. - Backend Schema Check:
python -m pytest backend/test_suite.pypasses (Sarvam HTTP stubbed); a manualPOST /api/sarvam-auto-editwith a real key returns valid JSON matchingEditPlanschema. - Asset Loading: Dynamic sticker PNGs load in the browser canvas without
ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoepconsole errors. - Timeline Sync: Captions, stickers, and SFX appear on separate draggable tracks in Timeline Studio and align with the spoken words in preview playback.
- Export Smoke Test: Clicking Export produces a playable
.mp4containing the cuts, burned karaoke captions, stickers, and SFX audio.