@kriya-ai/harness 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +379 -2
- package/SAFETY.md +162 -0
- package/THIRD_PARTY_NOTICES.md +7911 -0
- package/bin/kriya.js +577 -0
- package/bundle/cordis.patch.yml +397 -0
- package/contract/SOURCE.md +15 -0
- package/contract/contract.json +1355 -0
- package/package.json +57 -4
- package/plugins/anchor/index.js +56 -0
- package/plugins/anchor/package.json +13 -0
- package/plugins/approvals/index.js +183 -0
- package/plugins/approvals/package.json +13 -0
- package/plugins/brand/DESIGN.md +112 -0
- package/plugins/brand/client.js +826 -0
- package/plugins/brand/index.js +15 -0
- package/plugins/brand/package.json +25 -0
- package/plugins/brand/src/client.js +823 -0
- package/plugins/browser/index.js +218 -0
- package/plugins/browser/package.json +13 -0
- package/plugins/budget/index.js +108 -0
- package/plugins/budget/package.json +13 -0
- package/plugins/changes/client.js +245 -0
- package/plugins/changes/index.js +75 -0
- package/plugins/changes/package.json +22 -0
- package/plugins/edit/client.js +113 -0
- package/plugins/edit/index.js +58 -0
- package/plugins/edit/package.json +23 -0
- package/plugins/fs-freshness/index.js +28 -0
- package/plugins/fs-freshness/package.json +13 -0
- package/plugins/graph/client.js +178 -0
- package/plugins/graph/index.js +4 -0
- package/plugins/graph/package.json +22 -0
- package/plugins/kriya-handoff/index.js +194 -0
- package/plugins/kriya-handoff/package.json +13 -0
- package/plugins/kriya-tools/index.js +189 -0
- package/plugins/kriya-tools/package.json +13 -0
- package/plugins/loop/index.js +743 -0
- package/plugins/loop/package.json +13 -0
- package/plugins/mirror/index.js +235 -0
- package/plugins/mirror/package.json +13 -0
- package/plugins/overview/client.js +276 -0
- package/plugins/overview/index.js +95 -0
- package/plugins/overview/package.json +22 -0
- package/plugins/preview/client.js +337 -0
- package/plugins/preview/index.js +4 -0
- package/plugins/preview/package.json +22 -0
- package/plugins/progress/client.js +290 -0
- package/plugins/progress/index.js +100 -0
- package/plugins/progress/package.json +22 -0
- package/plugins/projects/client.js +249 -0
- package/plugins/projects/index.js +30 -0
- package/plugins/projects/package.json +24 -0
- package/plugins/rea/index.js +256 -0
- package/plugins/rea/package.json +10 -0
- package/plugins/rea/skill/LICENSE +21 -0
- package/plugins/rea/skill/SKILL.md +360 -0
- package/plugins/rea/skill/references/android-applications.md +36 -0
- package/plugins/rea/skill/references/connection-and-recovery.md +127 -0
- package/plugins/rea/skill/references/evidence-workflows.md +71 -0
- package/plugins/rea/skill/references/javascript-applications.md +218 -0
- package/plugins/rea/skill/references/native-and-artifacts.md +297 -0
- package/plugins/rea/skill/references/runtime-observation.md +78 -0
- package/plugins/remote/index.js +297 -0
- package/plugins/remote/package.json +10 -0
- package/plugins/router/index.js +84 -0
- package/plugins/router/package.json +13 -0
- package/plugins/sessions/client.js +68 -0
- package/plugins/sessions/index.js +79 -0
- package/plugins/sessions/package.json +20 -0
- package/plugins/skills/client.js +504 -0
- package/plugins/skills/index.js +166 -0
- package/plugins/skills/package.json +23 -0
- package/src/api.js +97 -0
- package/src/browser.js +286 -0
- package/src/changes.js +191 -0
- package/src/checkpoints.js +313 -0
- package/src/daemon.js +503 -0
- package/src/doctor.js +137 -0
- package/src/edit/core/anchors.js +102 -0
- package/src/edit/core/audio.js +158 -0
- package/src/edit/core/faces.js +99 -0
- package/src/edit/core/ffmpeg.js +258 -0
- package/src/edit/core/handoff.js +220 -0
- package/src/edit/core/history.js +90 -0
- package/src/edit/core/layout.js +92 -0
- package/src/edit/core/mix.js +115 -0
- package/src/edit/core/ops.js +602 -0
- package/src/edit/core/plan.js +266 -0
- package/src/edit/core/project.d.ts +134 -0
- package/src/edit/core/project.js +307 -0
- package/src/edit/core/reframe.js +125 -0
- package/src/edit/core/solver.js +416 -0
- package/src/edit/core/time.js +110 -0
- package/src/edit/core/tonemap.js +57 -0
- package/src/edit/director/ask.js +120 -0
- package/src/edit/director/gateway.js +16 -0
- package/src/edit/director/revise.js +186 -0
- package/src/edit/engine/capabilities.js +33 -0
- package/src/edit/engine/captions.js +154 -0
- package/src/edit/engine/color.js +269 -0
- package/src/edit/engine/confine.js +67 -0
- package/src/edit/engine/dna.js +148 -0
- package/src/edit/engine/index.js +473 -0
- package/src/edit/engine/loudness.js +43 -0
- package/src/edit/engine/media.js +57 -0
- package/src/edit/engine/motion.js +281 -0
- package/src/edit/engine/packs.js +87 -0
- package/src/edit/engine/probe.js +101 -0
- package/src/edit/engine/receipt.js +123 -0
- package/src/edit/engine/tool.js +101 -0
- package/src/edit/gates/copy.js +113 -0
- package/src/edit/gates/index.js +430 -0
- package/src/edit/gates/picture.js +130 -0
- package/src/edit/gates/sound.js +58 -0
- package/src/edit/gates/speech.js +127 -0
- package/src/edit/gates/text.js +196 -0
- package/src/edit/gates/text.swift +22 -0
- package/src/edit/graph/index.js +139 -0
- package/src/edit/graph/journal.js +69 -0
- package/src/edit/graph/scheduler.js +79 -0
- package/src/edit/host/client.js +58 -0
- package/src/edit/host/deliver.js +119 -0
- package/src/edit/host/jobs.js +84 -0
- package/src/edit/host/main.js +135 -0
- package/src/edit/host/paths.js +11 -0
- package/src/edit/host/projects.js +415 -0
- package/src/edit/host/server.js +391 -0
- package/src/edit/host/taste.js +135 -0
- package/src/edit/host/tavi.js +417 -0
- package/src/edit/host/watch.js +141 -0
- package/src/edit/index/db.js +109 -0
- package/src/edit/index/index.js +236 -0
- package/src/edit/index/layers/faces.js +78 -0
- package/src/edit/index/layers/faces.swift +18 -0
- package/src/edit/index/layers/meta.js +35 -0
- package/src/edit/index/layers/music.js +146 -0
- package/src/edit/index/layers/quality.js +120 -0
- package/src/edit/index/layers/retakes.js +132 -0
- package/src/edit/index/layers/screen.js +99 -0
- package/src/edit/index/layers/shots.js +29 -0
- package/src/edit/index/layers/sound.js +42 -0
- package/src/edit/index/layers/words.js +64 -0
- package/src/edit/index/story.js +248 -0
- package/src/edit/index/views.js +71 -0
- package/src/edit/loop/governor.js +112 -0
- package/src/edit/loop/loop.js +69 -0
- package/src/edit/loop/make.js +115 -0
- package/src/edit/loop/repair.js +97 -0
- package/src/edit/loop/replay.js +32 -0
- package/src/edit/recipes/multicam.js +461 -0
- package/src/edit/recipes/reel.js +202 -0
- package/src/edit/recipes/short-from-long.js +237 -0
- package/src/edit/recipes/tutorial.js +137 -0
- package/src/edit/recipes/youtube.js +155 -0
- package/src/edit/runtime/cli.js +126 -0
- package/src/edit/runtime/doctor.js +122 -0
- package/src/edit/runtime/fetch.js +15 -0
- package/src/edit/runtime/licences.js +88 -0
- package/src/edit/runtime/manifest.js +73 -0
- package/src/edit/runtime/setup.js +252 -0
- package/src/failure.js +69 -0
- package/src/gateway-proxy.js +213 -0
- package/src/intent.js +130 -0
- package/src/launch.js +315 -0
- package/src/live.js +81 -0
- package/src/local-skills.js +284 -0
- package/src/login.js +82 -0
- package/src/loop.js +428 -0
- package/src/modes.js +128 -0
- package/src/overview.js +71 -0
- package/src/paths.js +30 -0
- package/src/profiles.js +92 -0
- package/src/projects.js +104 -0
- package/src/recon.js +244 -0
- package/src/rules.js +139 -0
- package/src/runner.bundle.js +21172 -0
- package/src/sentinel.js +248 -0
- package/src/skill-switches.js +130 -0
- package/src/store.js +58 -0
- package/src/strict.js +124 -0
- package/src/verify.js +659 -0
- package/src/world.js +268 -0
- package/studio/dist/index.html +14 -0
- package/studio/dist/studio.css +163 -0
- package/studio/dist/studio.js +1 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// The Kriya Edit Project (EDIT_ENGINE §3, DATA_MODEL §2): one JSON document,
|
|
2
|
+
// validated on every load. It holds decisions, never derived data.
|
|
3
|
+
|
|
4
|
+
import { createHash } from "node:crypto"
|
|
5
|
+
|
|
6
|
+
import { isFlicks, isRate } from "./time.js"
|
|
7
|
+
|
|
8
|
+
export const SCHEMA = 1
|
|
9
|
+
|
|
10
|
+
const EDGE = { enum: ["start", "end"] }
|
|
11
|
+
const ROLES = ["base", "broll", "matte", "overlay", "caption", "dialogue", "sfx", "music", "ambience"]
|
|
12
|
+
const AUTHOR = { enum: ["person", "agent", "code"] }
|
|
13
|
+
|
|
14
|
+
export const ANCHORS = {
|
|
15
|
+
word: { word: "id", edge: EDGE, "exact?": "bool" },
|
|
16
|
+
shot: { shot: "id", "edge?": EDGE },
|
|
17
|
+
beat: { beat: "id" },
|
|
18
|
+
marker: { marker: "id" },
|
|
19
|
+
clip: { clip: "id", edge: EDGE, "offset?": "signed" },
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const BOX = { x: "int", y: "int", w: "pos", h: "pos" }
|
|
23
|
+
|
|
24
|
+
export const EFFECTS = {
|
|
25
|
+
reframe: { mode: { enum: ["subject", "fixed"] }, "x?": "int", "y?": "int" },
|
|
26
|
+
zoom: { scale: "num", "ease?": "str", "x?": "int", "y?": "int" },
|
|
27
|
+
matte: { "model?": "str" },
|
|
28
|
+
grade: { "lift?": "num", "gamma?": "num", "gain?": "num", "saturation?": "num", "ev?": "num", "match?": "id" },
|
|
29
|
+
lut: { asset: "id" },
|
|
30
|
+
stabilize: { "strength?": "num" },
|
|
31
|
+
fade: { "in?": "flicks", "out?": "flicks" },
|
|
32
|
+
transition: { kind: "str", duration: "flicks" },
|
|
33
|
+
caption: { words: { list: "id" }, "text?": "str", look: "str", "placement?": BOX, emphasis: { list: "id" } },
|
|
34
|
+
block: { blockId: "id", version: "pos", variables: "plain" },
|
|
35
|
+
level: { db: "num" },
|
|
36
|
+
eq: { preset: "str", "strength?": "num" },
|
|
37
|
+
duck: { "depth?": "num", "attack?": "flicks", "release?": "flicks" },
|
|
38
|
+
fit: {},
|
|
39
|
+
freeze: { at: "ref", duration: "flicks" },
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const SHAPES = {
|
|
43
|
+
project: {
|
|
44
|
+
schema: "pos",
|
|
45
|
+
id: "id",
|
|
46
|
+
name: "str",
|
|
47
|
+
canvas: {
|
|
48
|
+
width: "pos",
|
|
49
|
+
height: "pos",
|
|
50
|
+
fps: "rate",
|
|
51
|
+
color: { primaries: "str", transfer: "str", range: "str" },
|
|
52
|
+
workingBitDepth: "pos",
|
|
53
|
+
},
|
|
54
|
+
assets: {
|
|
55
|
+
list: {
|
|
56
|
+
id: "id",
|
|
57
|
+
kind: { enum: ["video", "audio", "image", "document", "data", "font", "lut", "reference"] },
|
|
58
|
+
fingerprint: "id",
|
|
59
|
+
"sha256?": "str",
|
|
60
|
+
path: "str",
|
|
61
|
+
linked: "bool",
|
|
62
|
+
rights: { enum: ["own", "licensed", "public_domain", "unknown"] },
|
|
63
|
+
"rightsNote?": "str",
|
|
64
|
+
"role?": { enum: ["aroll", "broll", "screen", "music", "sfx", "logo"] },
|
|
65
|
+
facts: {
|
|
66
|
+
"duration?": "flicks",
|
|
67
|
+
"fps?": { nullable: "rate" },
|
|
68
|
+
"vfr?": "bool",
|
|
69
|
+
"width?": "pos",
|
|
70
|
+
"height?": "pos",
|
|
71
|
+
"hasAudio?": "bool",
|
|
72
|
+
"sampleRate?": "pos",
|
|
73
|
+
"channels?": "pos",
|
|
74
|
+
"rotation?": "int",
|
|
75
|
+
"color?": { primaries: "str", transfer: "str", range: "str", tagged: "bool", hdr: "bool" },
|
|
76
|
+
"peak?": "flicks",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
sequences: {
|
|
81
|
+
list: {
|
|
82
|
+
id: "id",
|
|
83
|
+
name: "str",
|
|
84
|
+
tracks: { list: { id: "id", role: { enum: ROLES }, order: "int", muted: "bool", locked: "bool" } },
|
|
85
|
+
markers: { list: { id: "id", name: "str", at: "ref" } },
|
|
86
|
+
clips: {
|
|
87
|
+
list: {
|
|
88
|
+
id: "id",
|
|
89
|
+
track: "id",
|
|
90
|
+
source: { nullable: { asset: "id", in: "ref", out: "ref" } },
|
|
91
|
+
at: { nullable: "ref" },
|
|
92
|
+
"until?": "ref",
|
|
93
|
+
"duration?": "flicks",
|
|
94
|
+
"peak?": "flicks",
|
|
95
|
+
"loop?": "bool",
|
|
96
|
+
effects: { list: "effect" },
|
|
97
|
+
speed: "rate",
|
|
98
|
+
"linkGroup?": "str",
|
|
99
|
+
"audioLead?": "flicks",
|
|
100
|
+
"audioLag?": "flicks",
|
|
101
|
+
createdBy: AUTHOR,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
"parent?": "id",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
active: "id",
|
|
108
|
+
look: { id: "id", caption: "plain", color: "plain", motion: "plain", sound: "plain", brand: "plain" },
|
|
109
|
+
deliverables: {
|
|
110
|
+
list: {
|
|
111
|
+
id: "id",
|
|
112
|
+
preset: "str",
|
|
113
|
+
size: { width: "pos", height: "pos" },
|
|
114
|
+
fps: "rate",
|
|
115
|
+
codec: "str",
|
|
116
|
+
audio: "str",
|
|
117
|
+
loudness: { lufs: "num", tp: "num" },
|
|
118
|
+
burnCaptions: "bool",
|
|
119
|
+
gates: { list: "str" },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
"brief?": {
|
|
123
|
+
format: "str",
|
|
124
|
+
targetDuration: "flicks",
|
|
125
|
+
"audience?": "str",
|
|
126
|
+
"tone?": "str",
|
|
127
|
+
mustKeep: { list: "str" },
|
|
128
|
+
mustCut: { list: "str" },
|
|
129
|
+
"language?": "str",
|
|
130
|
+
effort: { enum: ["fast", "best"] },
|
|
131
|
+
},
|
|
132
|
+
nextId: "pos",
|
|
133
|
+
head: { nullable: "id" },
|
|
134
|
+
history: {
|
|
135
|
+
list: { id: "id", parent: { nullable: "id" }, "name?": "str", author: AUTHOR, opsRange: { list: "int" }, hash: "str", at: "str" },
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
...EFFECTS,
|
|
139
|
+
...ANCHORS,
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value)
|
|
143
|
+
|
|
144
|
+
const PRIMITIVES = {
|
|
145
|
+
str: (v) => (typeof v === "string" ? null : "must be text"),
|
|
146
|
+
// Ids and fingerprints name cache files (ES-01): letters, digits and :_.@+- only, never ".." or a slash
|
|
147
|
+
id: (v) => (typeof v === "string" && /^(?!.*\.\.)[\p{L}\p{N}_][\p{L}\p{N}:_.@+-]{0,127}$/u.test(v) ? null : "must be a short id of letters, digits and :_.@+-"),
|
|
148
|
+
name: (v) => (typeof v === "string" && v.length > 0 ? null : "must be a non-empty name"),
|
|
149
|
+
int: (v) => (Number.isSafeInteger(v) ? null : "must be a whole number"),
|
|
150
|
+
pos: (v) => (Number.isSafeInteger(v) && v > 0 ? null : "must be a positive whole number"),
|
|
151
|
+
num: (v) => (Number.isFinite(v) ? null : "must be a number"),
|
|
152
|
+
bool: (v) => (typeof v === "boolean" ? null : "must be true or false"),
|
|
153
|
+
flicks: (v) => (isFlicks(v) && v >= 0 ? null : "must be whole flicks, zero or more"),
|
|
154
|
+
signed: (v) => (isFlicks(v) ? null : "must be whole flicks"),
|
|
155
|
+
rate: (v) => (isRate(v) && Object.keys(v).length === 2 ? null : "must be a rational { n, d } of positive whole numbers"),
|
|
156
|
+
plain: (v) => (isObject(v) ? null : "must be an object"),
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Adds { path, reason } for everything wrong with value against spec. */
|
|
160
|
+
export function check(value, spec, path, errors) {
|
|
161
|
+
if (typeof spec === "string") {
|
|
162
|
+
if (spec === "ref") return checkRef(value, path, errors)
|
|
163
|
+
if (spec === "anchor") return checkAnchor(value, path, errors)
|
|
164
|
+
if (spec === "effect") return checkEffect(value, path, errors)
|
|
165
|
+
const reason = PRIMITIVES[spec](value)
|
|
166
|
+
if (reason) errors.push({ path, reason })
|
|
167
|
+
} else if (spec.enum) {
|
|
168
|
+
if (!spec.enum.includes(value)) errors.push({ path, reason: `must be one of ${spec.enum.join(", ")}` })
|
|
169
|
+
} else if (spec.nullable) {
|
|
170
|
+
if (value !== null) check(value, spec.nullable, path, errors)
|
|
171
|
+
} else if (spec.list) {
|
|
172
|
+
if (!Array.isArray(value)) errors.push({ path, reason: "must be a list" })
|
|
173
|
+
else value.forEach((item, i) => check(item, spec.list, `${path}[${i}]`, errors))
|
|
174
|
+
} else checkShape(value, spec, path, errors)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function checkShape(value, shape, path, errors) {
|
|
178
|
+
if (!isObject(value)) {
|
|
179
|
+
errors.push({ path, reason: "must be an object" })
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
const at = (key) => (path ? `${path}.${key}` : key)
|
|
183
|
+
const known = new Set()
|
|
184
|
+
for (const [field, spec] of Object.entries(shape)) {
|
|
185
|
+
const optional = field.endsWith("?")
|
|
186
|
+
const key = optional ? field.slice(0, -1) : field
|
|
187
|
+
known.add(key)
|
|
188
|
+
if (value[key] !== undefined) check(value[key], spec, at(key), errors)
|
|
189
|
+
else if (!optional) errors.push({ path: at(key), reason: "is required" })
|
|
190
|
+
}
|
|
191
|
+
for (const key of Object.keys(value)) if (!known.has(key)) errors.push({ path: at(key), reason: "is not a field here" })
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function checkAnchor(value, path, errors) {
|
|
195
|
+
const kind = isObject(value) ? Object.keys(ANCHORS).find((key) => key in value) : undefined
|
|
196
|
+
if (kind) checkShape(value, ANCHORS[kind], path, errors)
|
|
197
|
+
else errors.push({ path, reason: "must be an anchor: word, shot, beat, marker or clip" })
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function checkRef(value, path, errors) {
|
|
201
|
+
if (typeof value === "number") check(value, "flicks", path, errors)
|
|
202
|
+
else checkAnchor(value, path, errors)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function checkEffect(value, path, errors) {
|
|
206
|
+
const { type, ...fields } = isObject(value) ? value : {}
|
|
207
|
+
if (!Object.hasOwn(EFFECTS, type)) errors.push({ path, reason: `is not a known effect: ${type}` })
|
|
208
|
+
else checkShape(fields, EFFECTS[type], path, errors)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function checkMeaning(project, errors) {
|
|
212
|
+
const unique = (items, path) => {
|
|
213
|
+
const seen = new Set()
|
|
214
|
+
for (const { id } of items) {
|
|
215
|
+
if (seen.has(id)) errors.push({ path, reason: `duplicate id "${id}"` })
|
|
216
|
+
seen.add(id)
|
|
217
|
+
}
|
|
218
|
+
return seen
|
|
219
|
+
}
|
|
220
|
+
const assets = unique(project.assets, "assets")
|
|
221
|
+
unique(project.deliverables, "deliverables")
|
|
222
|
+
const sequences = unique(project.sequences, "sequences")
|
|
223
|
+
if (!sequences.has(project.active)) errors.push({ path: "active", reason: `no sequence "${project.active}"` })
|
|
224
|
+
project.sequences.forEach((sequence, s) => {
|
|
225
|
+
const path = `sequences[${s}]`
|
|
226
|
+
const tracks = unique(sequence.tracks, `${path}.tracks`)
|
|
227
|
+
unique(sequence.markers, `${path}.markers`)
|
|
228
|
+
unique(sequence.clips, `${path}.clips`)
|
|
229
|
+
sequence.clips.forEach((clip, c) => {
|
|
230
|
+
if (!tracks.has(clip.track)) errors.push({ path: `${path}.clips[${c}].track`, reason: `no track "${clip.track}"` })
|
|
231
|
+
if (clip.source && !assets.has(clip.source.asset)) errors.push({ path: `${path}.clips[${c}].source.asset`, reason: `no asset "${clip.source.asset}"` })
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** @returns {{ path: string, reason: string }[]} empty when the project is valid */
|
|
237
|
+
export function validateProject(project) {
|
|
238
|
+
const errors = []
|
|
239
|
+
check(project, SHAPES.project, "", errors)
|
|
240
|
+
if (project?.schema !== undefined && project.schema !== SCHEMA) errors.push({ path: "schema", reason: `must be ${SCHEMA}` })
|
|
241
|
+
if (errors.length === 0) checkMeaning(project, errors)
|
|
242
|
+
return errors
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Pure v(n) → v(n+1) steps. Schema 1 is the first, so there are none yet
|
|
246
|
+
const MIGRATIONS = {}
|
|
247
|
+
|
|
248
|
+
export function migrate(doc, steps = MIGRATIONS) {
|
|
249
|
+
let current = doc
|
|
250
|
+
while (current.schema < SCHEMA) {
|
|
251
|
+
const step = steps[current.schema]
|
|
252
|
+
if (!step) throw new RangeError(`no migration from schema ${current.schema}`)
|
|
253
|
+
current = step(current)
|
|
254
|
+
}
|
|
255
|
+
return current
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Parses project text. A newer or invalid document is refused whole, never partly read. */
|
|
259
|
+
export function parseProject(text) {
|
|
260
|
+
let doc
|
|
261
|
+
try {
|
|
262
|
+
doc = JSON.parse(text)
|
|
263
|
+
} catch {
|
|
264
|
+
return { ok: false, errors: [{ path: "", reason: "this isn't a Kriya project file: it isn't valid JSON" }] }
|
|
265
|
+
}
|
|
266
|
+
if (!isObject(doc) || !Number.isSafeInteger(doc.schema)) return { ok: false, errors: [{ path: "schema", reason: "this isn't a Kriya project file" }] }
|
|
267
|
+
if (doc.schema > SCHEMA) return { ok: false, errors: [{ path: "schema", reason: `this project was saved by a newer version of Kriya (schema ${doc.schema}). Update Kriya to open it` }] }
|
|
268
|
+
try {
|
|
269
|
+
const project = migrate(doc)
|
|
270
|
+
const errors = validateProject(project)
|
|
271
|
+
return errors.length ? { ok: false, errors } : { ok: true, project, errors }
|
|
272
|
+
} catch (error) {
|
|
273
|
+
return { ok: false, errors: [{ path: "schema", reason: error.message }] }
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** A new, empty project: one sequence, a base track, and a caption track. */
|
|
278
|
+
export function newProject({ id, name, width = 1080, height = 1920, fps = { n: 30, d: 1 } }) {
|
|
279
|
+
const track = (role, order) => ({ id: `t-${role}`, role, order, muted: false, locked: false })
|
|
280
|
+
return {
|
|
281
|
+
schema: SCHEMA,
|
|
282
|
+
id,
|
|
283
|
+
name,
|
|
284
|
+
canvas: { width, height, fps, color: { primaries: "bt709", transfer: "bt709", range: "tv" }, workingBitDepth: 10 },
|
|
285
|
+
assets: [],
|
|
286
|
+
sequences: [{ id: "q1", name: "Main", tracks: [track("base", 0), track("caption", 4)], markers: [], clips: [] }],
|
|
287
|
+
active: "q1",
|
|
288
|
+
look: { id: "default", caption: {}, color: {}, motion: {}, sound: {}, brand: {} },
|
|
289
|
+
deliverables: [],
|
|
290
|
+
nextId: 1,
|
|
291
|
+
head: null,
|
|
292
|
+
history: [],
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** JSON with sorted keys: the same value always gives the same bytes. */
|
|
297
|
+
export function canonical(value) {
|
|
298
|
+
return JSON.stringify(value, (_, v) => (isObject(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) : v))
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export const serialize = (project) => `${canonical(project)}\n`
|
|
302
|
+
export const sha256 = (text) => createHash("sha256").update(text).digest("hex")
|
|
303
|
+
|
|
304
|
+
/** Hash of the decisions; where HEAD sits and the mirrored log aren't part of them. */
|
|
305
|
+
export function hashProject({ head, history, ...decisions }) {
|
|
306
|
+
return sha256(canonical(decisions))
|
|
307
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Reframe solver (EDIT_ENGINE §5.2): a crop path that moves like a camera operator.
|
|
2
|
+
// L1 trend filtering, min ½‖x−y‖² + hold‖D₁x‖₁ + smooth‖D₂x‖₁, gives long holds and
|
|
3
|
+
// decisive moves. One small ADMM serves both penalties, so no separate taut-string
|
|
4
|
+
// pass is needed. Pixels here are floats; they are rounded before they leave.
|
|
5
|
+
|
|
6
|
+
const soft = (value, limit) => Math.sign(value) * Math.max(Math.abs(value) - limit, 0)
|
|
7
|
+
|
|
8
|
+
// LDLᵀ of the symmetric pentadiagonal I + ρ(D₁ᵀD₁ + D₂ᵀD₂), factored once per shot
|
|
9
|
+
function factor(n, rho) {
|
|
10
|
+
const d = new Float64Array(n).fill(1)
|
|
11
|
+
const e = new Float64Array(n)
|
|
12
|
+
const f = new Float64Array(n)
|
|
13
|
+
const add = (row) => {
|
|
14
|
+
row.forEach(([i, a]) => {
|
|
15
|
+
row.forEach(([j, b]) => {
|
|
16
|
+
if (i === j) d[i] += rho * a * b
|
|
17
|
+
else if (j === i + 1) e[i] += rho * a * b
|
|
18
|
+
else if (j === i + 2) f[i] += rho * a * b
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
for (let i = 0; i + 1 < n; i++) add([[i, -1], [i + 1, 1]])
|
|
23
|
+
for (let i = 0; i + 2 < n; i++) add([[i, 1], [i + 1, -2], [i + 2, 1]])
|
|
24
|
+
const l1 = new Float64Array(n)
|
|
25
|
+
const l2 = new Float64Array(n)
|
|
26
|
+
for (let i = 0; i < n; i++) {
|
|
27
|
+
if (i > 0) d[i] -= l1[i - 1] ** 2 * d[i - 1]
|
|
28
|
+
if (i > 1) d[i] -= l2[i - 2] ** 2 * d[i - 2]
|
|
29
|
+
if (i + 1 < n) l1[i] = (e[i] - (i > 0 ? l1[i - 1] * l2[i - 1] * d[i - 1] : 0)) / d[i]
|
|
30
|
+
if (i + 2 < n) l2[i] = f[i] / d[i]
|
|
31
|
+
}
|
|
32
|
+
return { d, l1, l2 }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function solveFactored({ d, l1, l2 }, rhs) {
|
|
36
|
+
const n = rhs.length
|
|
37
|
+
const x = Float64Array.from(rhs)
|
|
38
|
+
for (let i = 1; i < n; i++) x[i] -= l1[i - 1] * x[i - 1] + (i > 1 ? l2[i - 2] * x[i - 2] : 0)
|
|
39
|
+
for (let i = 0; i < n; i++) x[i] /= d[i]
|
|
40
|
+
for (let i = n - 2; i >= 0; i--) x[i] -= l1[i] * x[i + 1] + (i + 2 < n ? l2[i] * x[i + 2] : 0)
|
|
41
|
+
return x
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function trendFilter(y, hold, smooth, iterations) {
|
|
45
|
+
const n = y.length
|
|
46
|
+
if (n < 3) return y
|
|
47
|
+
const rho = Math.max((hold + smooth) / 8, 1)
|
|
48
|
+
const factored = factor(n, rho)
|
|
49
|
+
const z1 = new Float64Array(n - 1)
|
|
50
|
+
const u1 = new Float64Array(n - 1)
|
|
51
|
+
const z2 = new Float64Array(n - 2)
|
|
52
|
+
const u2 = new Float64Array(n - 2)
|
|
53
|
+
let x = Float64Array.from(y)
|
|
54
|
+
for (let k = 0; k < iterations; k++) {
|
|
55
|
+
const rhs = Float64Array.from(y)
|
|
56
|
+
for (let i = 0; i + 1 < n; i++) {
|
|
57
|
+
const v = rho * (z1[i] - u1[i])
|
|
58
|
+
rhs[i] -= v
|
|
59
|
+
rhs[i + 1] += v
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i + 2 < n; i++) {
|
|
62
|
+
const v = rho * (z2[i] - u2[i])
|
|
63
|
+
rhs[i] += v
|
|
64
|
+
rhs[i + 1] -= 2 * v
|
|
65
|
+
rhs[i + 2] += v
|
|
66
|
+
}
|
|
67
|
+
x = solveFactored(factored, rhs)
|
|
68
|
+
for (let i = 0; i + 1 < n; i++) {
|
|
69
|
+
const dx = x[i + 1] - x[i]
|
|
70
|
+
z1[i] = soft(dx + u1[i], hold / rho)
|
|
71
|
+
u1[i] += dx - z1[i]
|
|
72
|
+
}
|
|
73
|
+
for (let i = 0; i + 2 < n; i++) {
|
|
74
|
+
const dx = x[i] - 2 * x[i + 1] + x[i + 2]
|
|
75
|
+
z2[i] = soft(dx + u2[i], smooth / rho)
|
|
76
|
+
u2[i] += dx - z2[i]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Array.from(x)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const FLICKS = 705_600_000
|
|
83
|
+
|
|
84
|
+
// ET-SOL-03: no whip. One pass each way caps every move at maxSpeed px a second; their
|
|
85
|
+
// mean is just as capped and centres the ramp on the subject's move
|
|
86
|
+
function limitSpeed(path, samples, maxSpeed) {
|
|
87
|
+
const reach = (i, j) => (maxSpeed * Math.abs(samples[j].t - samples[i].t)) / FLICKS
|
|
88
|
+
const ahead = [...path]
|
|
89
|
+
for (let i = 1; i < ahead.length; i++) ahead[i] = Math.min(Math.max(ahead[i], ahead[i - 1] - reach(i, i - 1)), ahead[i - 1] + reach(i, i - 1))
|
|
90
|
+
const behind = [...path]
|
|
91
|
+
for (let i = behind.length - 2; i >= 0; i--) behind[i] = Math.min(Math.max(behind[i], behind[i + 1] - reach(i, i + 1)), behind[i + 1] + reach(i, i + 1))
|
|
92
|
+
return path.map((_, i) => (ahead[i] + behind[i]) / 2)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function solveShot(samples, { sourceWidth, cropWidth, deadzone = 0, hold = 40, smooth = 20, margin = 0, maxSpeed, iterations = 400 }) {
|
|
96
|
+
if (samples.length === 0) return []
|
|
97
|
+
const target = []
|
|
98
|
+
for (const { x } of samples) {
|
|
99
|
+
const held = target.at(-1)
|
|
100
|
+
target.push(held !== undefined && Math.abs(x - held) <= deadzone ? held : x)
|
|
101
|
+
}
|
|
102
|
+
const half = cropWidth / 2
|
|
103
|
+
const filtered = trendFilter(target, hold, smooth, iterations)
|
|
104
|
+
const path = (maxSpeed ? limitSpeed(filtered, samples, maxSpeed) : filtered).map((center, i) => {
|
|
105
|
+
// The subject's whole box stays in (w from L8), not just its centre; a box wider than the crop keeps its centre
|
|
106
|
+
const { x: subject, w = 0 } = samples[i]
|
|
107
|
+
const inset = Math.min(half, margin + w / 2)
|
|
108
|
+
const inFrame = Math.min(Math.max(center, subject - half + inset), subject + half - inset)
|
|
109
|
+
return Math.round(Math.min(Math.max(inFrame, half), sourceWidth - half) - half)
|
|
110
|
+
})
|
|
111
|
+
// Rounding leaves one-pixel ripple on a hold: a camera doesn't move a pixel
|
|
112
|
+
for (let i = 1; i < path.length; i++) if (Math.abs(path[i] - path[i - 1]) <= 1) path[i] = path[i - 1]
|
|
113
|
+
return path.map((x, i) => ({ t: samples[i].t, x }))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Solves each shot alone, because a shot change resets the path.
|
|
118
|
+
* @param {{ id: string, samples: { t: number, x: number, w?: number }[] }[]} shots w: the subject's box width
|
|
119
|
+
* @param {{ sourceWidth: number, cropWidth: number, deadzone?: number, hold?: number, smooth?: number, margin?: number, maxSpeed?: number, iterations?: number }} options
|
|
120
|
+
* maxSpeed: px a second the crop may move (ET-SOL-03: no whips); keeping the subject in frame comes first
|
|
121
|
+
* @returns {{ shot: string, path: { t: number, x: number }[] }[]} x is the crop's left edge
|
|
122
|
+
*/
|
|
123
|
+
export function solveReframe(shots, options) {
|
|
124
|
+
return shots.map((shot) => ({ shot: shot.id, path: solveShot(shot.samples, options) }))
|
|
125
|
+
}
|