The human approved the full implementation plan in docs/IMPLEMENTATION-PLAN.md. Implement ONLY domain.py and tests/test_domain_generated.py for this application. Other files are being written concurrently; do not edit/revert them, spawn agents, make network requests, or invoke another Codex process. Use Python standard library only. Run your meaningful domain tests.

Required stable interface:
class DomainError(ValueError): has status:int default422.
validate_limits(value)->dict with budget numeric nonnegative, attempts integer1..100, minutes integer1..1440, stall integer1..20. Defaults budget100,attempts3,minutes60,stall2. Reject booleans, NaN, infinity and negative values.
validate_rules(value)->dict: threshold default90 and must90..100; weights dict default {'visual':25,'structure':20,'motion':20,'timing':15,'audio':10,'correctness':10}, nonnegative sum100, exactly these6keys; mandatory list nonempty unique nonblank strings default ['required-scenes','technical-quality','continuity']. Return canonical keys threshold,weights,mandatory.
quality_result(evaluation,rules)->dict score numeric weighted6scores, passed bool if score>=threshold and every mandatory true; findings preserved. evaluation has scores mapping6keys, mandatory mapping configurednames->bool, findings list of {criterion,timestamp,description,repair}. A missing score/gate must never pass. Reject malformed numeric data; missing numeric criteria should produce score=None,passed=False,unassessed list; no inferred/automatic gate success.
new_template(payload,reference_asset)->dict. Required name,instructions and nonempty reference_asset identifier; language defaultEnglish, duration integer1..1200, ratio oneof9:16/16:9/1:1. Generate uuid id/family, version1,statusDraft, reference=reference_asset, images=[], constraints frompayload, rules=validate_rules(payload.rules), limits and productionLimits validated; history=[],attempts=[],samples=[],cost=0,score=None,best=0,gatePass=False,approachAccepted=False,approach=None,fixed='',variables='',conditional=''. Reject missing reference/name/instructions/unsupported ratios.
new_version(template,changes)->dict deep-copy asnew uuid samefamily version+1,statusDraft; reset approvals/output/evaluation/score/best/attempts/samples/history,cost,approachAccepted; preserveprior immutable input and original version; accept allowedchanges excludingid/family/version/status/approval. Runtime will choosemaxexistingversion ifneeded.
check_topics(candidates,existing_titles,template)->list of normalized dicts. Accept eachcandidate{title,brief,fit,findings,exceptions}; duplicate/near-duplicate using Unicode normalization/casefold/punctuation and high word overlap must havefitFalse and explicitfinding. Missingbrief/title rejected. exceptions nonempty =>fitFalse. Newtopicuuid,template=template.id,status='Pending approval',history=[],approvedInstructions=None. Don't blindly approveAIflags.
approve_topics(topics)->list copies; onlypendingorNeedschanges andfitTrue canbeQueued; sets approvedInstructions=brief; never createsvideo/jobs. Illegal topicapproval raisesDomainError.
start_videos(topics,templates,existing_videos,idempotency_key)->list newvideo records forselectedtopics. Require nonemptyidempotencykey, topicstatusQueued, associatedtemplatestatusReady, approvedInstructions present; rejectmixedinvalidselection atomically. Existingactivevideo forsametopic returns itsrecord ratherthan duplicate (includingallnonRejected statuses). Newvideo fields:id,topic,template,revision1,statusQueued,instructions=approvedInstructions,templateVersion=tpl.version,limits=copytpl.productionLimits,history=[],attempts=[],cost0,scoreNone,best0,gatePassFalse,output=None,evaluation=None,requestKey. Doesnot mutateinputs. Later revisionscreatedbyrevision_video.
revision_video(video,feedback,scope='video')->dict newuuid withrevision+1,priorRevision=video.id, originaltopic/template unchanged, sameinstructionsplusfeedback, resetoutput/evaluation/attempts/cost/score/approval/history, status='Queued'; validate nonblankfeedback andscopevideo/batch. Preserve oldrecord including Approveddecision. No approvalinheritance.
can_approve_video(video,template)->bool require statusHumanreview, actualoutput nonempty, evaluation mapping, video.gatePassTrue, numerical score>=template.rules.threshold. This helper is necessary but runtime will additionally validate storedasset exists and checker binds exactoutputsha.
can_activate_template(template)->bool require statusValidation, referenceApprovedTrue, output nonempty, gatePassTrue, 2or3samples withdistinctnonblanktopics; everysamplestatusApproved,outputnonempty,gatePassTrue andscore>=threshold. A planorAIpass nevercountsashumanapproval.

Test threshold/gates/missingdata/invalidlimits,immutableversions,duplicate topics, approvalnotautoproduction, selectionidempotency, pervideorevision reset, no finalapprovalwithmissingoutput and sampleactivationrequires2–3explicitapprovals. At finish listfiles/tests, no implementation elsewhere.
