Author: Gang Qiao
Live demo: https://casr.niren.life
Code repository: https://github.com/TwoOxygenH2O/casr-core
CASR Core is a reusable Java implementation of Continuity-Aware Self-Repair for AI short-drama and AI video production pipelines. It turns post-generation failures into a measurable repair-planning problem: diagnose failures, quantify structural quality and narrative continuity, compare repair strategies under cost and time constraints, and return explainable recommendations.
CASR Core(连续性感知自修复算法库) 是一个面向 AI 短剧与 AI 视频生产线的可复用 Java 算法实现。它把“生成后失败修复”建模为可计算的策略规划问题:诊断失败、量化结构质量与叙事连续性、在成本和时间约束下比较修复策略,并输出可解释的推荐路径。
Search keywords: CASR, Continuity-Aware Self-Repair, AI video generation, short-drama production pipeline, post-generation repair, failure attribution, continuity scoring, cost-aware policy search, explainable repair planning, benchmark evaluation.
检索关键词:CASR、连续性感知自修复、AI 视频生成、短剧生产线、生成后修复、失败归因、连续性评分、成本敏感策略搜索、可解释修复规划、可复现实验评估。
Most AI video tools focus on generating content. CASR focuses on what happens after generation: a production pipeline receives missing first frames, failed video tasks, black frames, frozen motion, aspect-ratio drift, identity drift, wardrobe drift, scene drift, stale tasks, and duration anomalies. CASR provides a lightweight reliability layer that can decide whether to regenerate a first frame, retry a video, switch to a high-continuity workflow, switch to a fast preview workflow, or compose a fallback preview.
许多 AI 视频工具主要关注“生成内容”。CASR 关注生成之后的问题:生产线会遇到缺首帧、视频任务失败、黑屏、冻结、画幅漂移、身份漂移、服装漂移、场景漂移、陈旧任务和时长异常。CASR 提供一个轻量可靠性层,用来决定是否重生成首帧、重跑视频、切换高连续性工作流、切换快速预览工作流,或合成兜底预览。
This repository is the algorithm library and standalone technical demo. A separate demo repository is not necessary at this stage because the demo server and demo web UI are intentionally small and live next to the engine they visualize.
niren-drama is the production integration. It maps project, storyboard, issue, consistency, and task entities into CasrInput, persists CASR runs in its own database, and uses this repository as a Maven dependency.
本仓库负责算法库与轻量独立 Demo。当前阶段不需要再拆出第三个 Demo 仓库,因为 Demo server 和 Demo web UI 都很小,并且直接服务于算法可视化。
niren-drama 是生产系统集成案例。它把项目、分镜、问题、一致性条目和任务记录转换为 CasrInput,在自己的数据库中持久化 CASR 运行记录,并通过 Maven 依赖引用本仓库。
casr-domain: stable DTOs for shot graphs, quality issues, consistency anchors, task state, analysis output, and repair plans.casr-engine: pure Java policy engine for diagnosis, scoring, failure attribution, cost-aware repair planning, and benchmark evaluation.casr-demo-server: standalone Spring Boot demo API with no database, Redis, login, or paid AI dependency.casr-demo-web: Vue demo workbench for showing shot-level diagnosis, policy search alternatives, reward components, and simulated execution.datasets: deterministic demo case data for reproducible evaluation.docs/research-roadmap.md: bilingual research roadmap, benchmark design, ablation plan, and limitations.
Input:
- Shot metadata: storyboard order, descriptions, duration, aspect ratio, first-frame URL, video URL, prompts, and task status.
- Consistency anchors: character, wardrobe, scene, and locked prompt hints.
- Quality issues: black frame, frozen frame, duration anomaly, aspect-ratio drift, and other production defects.
- Task records: failed, running, pending, successful, and stale generation tasks.
Output:
qualityScore: structural quality score.continuityScore: continuity score.failureTypes: actionable failure labels.shotDiagnoses: shot-level diagnosis, severity, recommendation, cost, time, and explanation.metrics: dynamic research metrics including blocking ratio, anchor coverage, continuity transition risk, and repair urgency.repairPlan: ranked repair options with reward, cost, time, risk, success probability, affected shots, and policy trace.
Reward function:
reward = scoreGain - costPenalty - timePenalty - riskPenalty
The policy search is state-sensitive. It converts the current diagnosis into a compact state vector containing risky shot count, blocking issue count, continuity-risk count, missing-media count, motion-risk count, and stale-task count. Candidate repair paths then estimate score gain, cost, time, risk, and success probability from that state instead of using fixed workflow labels.
CASR now includes a deterministic benchmark runner that compares four strategies:
casr-policy-search: CASR diagnosis and cost-aware repair planning.blind-retry-risky-shots: retry every risky shot without explicit failure attribution.rerun-all-shots: rerun the whole shot list.low-cost-preview: choose a cheap preview path with weaker continuity guarantees.
Metrics:
- estimated cost
- estimated minutes
- success probability proxy
- detected-failure recall
- explanation coverage
- continuity-priority score
- expected utility
Run the benchmark through Java:
import com.twooxygen.casr.engine.eval.CasrBenchmarkReport;
import com.twooxygen.casr.engine.eval.CasrBenchmarkRunner;
CasrBenchmarkReport report = new CasrBenchmarkRunner().runDefaultBenchmark();
System.out.println(report.getAggregates());Run the benchmark through HTTP:
mvn -pl casr-demo-server -am spring-boot:run
curl http://localhost:8090/api/benchmarkThis benchmark is not a replacement for large-scale visual evaluation. It is a reproducible research scaffold that makes the current claims measurable and gives the paper a concrete baseline comparison.
Install locally while the artifact is not published to a package registry:
mvn clean installReference the engine from another Java project:
<dependency>
<groupId>com.twooxygen.casr</groupId>
<artifactId>casr-engine</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>Java usage:
import com.twooxygen.casr.domain.CasrInput;
import com.twooxygen.casr.domain.CasrRunResult;
import com.twooxygen.casr.engine.CasrDemoFixtures;
import com.twooxygen.casr.engine.CasrEngine;
CasrEngine engine = new CasrEngine();
CasrInput input = CasrDemoFixtures.shortDramaCase();
CasrRunResult result = engine.run(input);
System.out.println(result.getAnalysis().getQualityScore());
System.out.println(result.getPlan().getRecommendedOption().getId());Start the standalone demo API:
mvn -pl casr-demo-server -am spring-boot:runDefault base URL:
http://localhost:8090/api
Available endpoints:
GET /demo-case
GET /benchmark
POST /analyze
POST /plan
POST /execute/simulate
Python usage:
import requests
base_url = "http://localhost:8090/api"
case = requests.get(f"{base_url}/demo-case", timeout=10).json()
analysis = requests.post(f"{base_url}/analyze", json=case, timeout=10).json()
plan = requests.post(f"{base_url}/plan", json=case, timeout=10).json()
benchmark = requests.get(f"{base_url}/benchmark", timeout=10).json()
print(analysis["qualityScore"], analysis["continuityScore"])
print(plan["recommendedOption"]["id"])
print(benchmark["aggregates"]["bestStrategyByExpectedUtility"])Go usage:
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
baseURL := "http://localhost:8090/api"
resp, err := http.Get(baseURL + "/demo-case")
if err != nil {
panic(err)
}
defer resp.Body.Close()
var input map[string]any
if err := json.NewDecoder(resp.Body).Decode(&input); err != nil {
panic(err)
}
body, _ := json.Marshal(input)
planResp, err := http.Post(baseURL+"/plan", "application/json", bytes.NewReader(body))
if err != nil {
panic(err)
}
defer planResp.Body.Close()
var plan map[string]any
if err := json.NewDecoder(planResp.Body).Decode(&plan); err != nil {
panic(err)
}
benchmarkResp, err := http.Get(baseURL + "/benchmark")
if err != nil {
panic(err)
}
defer benchmarkResp.Body.Close()
var benchmark map[string]any
if err := json.NewDecoder(benchmarkResp.Body).Decode(&benchmark); err != nil {
panic(err)
}
fmt.Println(plan["recommendedOption"])
fmt.Println(benchmark["aggregates"])
}For production systems, prefer embedding casr-engine directly when running on the JVM and exposing a narrow service boundary for non-JVM callers.
Run tests:
mvn clean testBuild the demo web UI:
cd casr-demo-web
npm install
npm run buildStart the demo server:
mvn -pl casr-demo-server -am spring-boot:runStart the demo web UI:
cd casr-demo-web
npm run devOpen http://localhost:5174.
Hosted demo:
https://casr.niren.life
The strongest next research direction is to combine CASR with visual evaluators and learned outcome models:
- Optional visual metrics: CLIP/DINO similarity, face embedding consistency, optical flow, frame-difference signals, aspect-ratio verification.
- Learned priors: estimate repair success, cost, and time from production logs.
- Stronger planning: budgeted MCTS, beam search, contextual bandits, and constrained optimization.
- Dataset expansion: synthetic and real production traces with expected failure labels and repair outcomes.
- Human-in-the-loop evaluation: measure whether explanations reduce decision time and improve repair action selection.
See docs/research-roadmap.md for the bilingual roadmap and publication-oriented experiment design.
Manuscript drafts, DOCX/PDF exports, arXiv packaging outputs, and submission helper notes are maintained as local-only materials until a formal preprint or publication link is available. The public repository keeps reusable code, deterministic demo, datasets, tests, licensing, citation metadata, and usage documentation cleanly separated from unpublished manuscript drafts.
This repository includes CITATION.cff. If you use CASR Core in research or engineering work, cite the software entry and, after a preprint is available, cite the arXiv paper as well.
CASR Core is released under the Apache License 2.0.