@kriya-ai/harness 0.2.4 → 0.2.5
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/contract/SOURCE.md +3 -3
- package/contract/contract.json +7 -1
- package/package.json +1 -1
- package/src/edit/core/ffmpeg.js +19 -1
- package/src/edit/core/ops.js +6 -1
- package/src/edit/core/plan.js +34 -4
- package/src/edit/core/transitions.js +17 -0
- package/src/edit/director/continuity.js +129 -0
- package/src/edit/director/graphics.js +152 -0
- package/src/edit/director/plan.js +49 -4
- package/src/edit/director/revise.js +47 -5
- package/src/edit/engine/graphics.js +178 -0
- package/src/edit/engine/motion.js +5 -1
- package/src/edit/gates/index.js +4 -1
- package/src/edit/gates/picture.js +6 -3
- package/src/edit/host/main.js +8 -5
- package/src/edit/host/paths.js +15 -2
- package/src/edit/host/projects.js +63 -7
- package/src/edit/host/server.js +32 -3
- package/src/edit/loop/make.js +18 -2
- package/src/edit/recipes/graphic-clips.js +57 -0
- package/src/edit/recipes/reel.js +36 -5
- package/src/edit/runtime/fetch.js +4 -3
- package/studio/dist/studio.css +3 -2
- package/studio/dist/studio.js +3 -3
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import { apply } from "../core/ops.js"
|
|
7
7
|
import { solve } from "../core/solver.js"
|
|
8
|
+
import { cleanGraphic, GRAPHIC_BLOCK, GRAPHIC_KINDS, GRAPHIC_VERSION, graphicLength, SUBTITLE_MAX, TEXT_MAX } from "../engine/graphics.js"
|
|
8
9
|
import { paperEdit, shotDigest } from "../index/views.js"
|
|
10
|
+
import { TRANSITION_LABELS, transitionLength, TRANSITIONS } from "../core/transitions.js"
|
|
11
|
+
import { brandIn, graphicProblems } from "./graphics.js"
|
|
9
12
|
|
|
10
13
|
const FLICKS = 705_600_000
|
|
11
14
|
|
|
@@ -97,6 +100,36 @@ export const OPS_SCHEMA = {
|
|
|
97
100
|
additionalProperties: false,
|
|
98
101
|
}
|
|
99
102
|
|
|
103
|
+
// With editing.motion on, chat can also put a kit graphic on screen (MOTION_GRAPHICS.md). Off,
|
|
104
|
+
// the console's schema is the same object as before
|
|
105
|
+
const ITEMS = OPS_SCHEMA.properties.ops.items
|
|
106
|
+
const MOTION_SCHEMA = { ...OPS_SCHEMA, properties: { ...OPS_SCHEMA.properties, ops: { ...OPS_SCHEMA.properties.ops, items: { ...ITEMS, properties: { ...ITEMS.properties, op: { type: "string", enum: [...CONSOLE_OPS, "add_graphic", "transition"] }, kind: { type: "string", enum: [...Object.keys(GRAPHIC_KINDS), ...Object.keys(TRANSITIONS)] }, style: { type: "string", maxLength: 16 }, subtitle: { type: "string", maxLength: SUBTITLE_MAX } } } } } }
|
|
107
|
+
export const consoleSchema = (motion) => (motion ? MOTION_SCHEMA : OPS_SCHEMA)
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* `add_graphic` as the engine's own operation: the graphic cleaned, its words held to the
|
|
111
|
+
* speaker's and the person's, its length set by code. Every other operation passes through.
|
|
112
|
+
* @param {object[]} ops
|
|
113
|
+
* @param {{ index: object, person: string }} context person: the person's own messages
|
|
114
|
+
* @returns {{ ops: object[], problems: string[] }}
|
|
115
|
+
*/
|
|
116
|
+
export function expandGraphics(ops, { index, person }) {
|
|
117
|
+
const problems = []
|
|
118
|
+
const spoken = (index.words ?? []).map((w) => w.text).join(" ")
|
|
119
|
+
const out = ops.map((op, i) => {
|
|
120
|
+
// A transition's length is code's: the default, or what was asked, inside the allowed range
|
|
121
|
+
if (op?.op === "transition") return Object.hasOwn(TRANSITIONS, op.kind ?? "") ? { op: "transition", clip: op.clip, kind: op.kind, duration: transitionLength(op.duration) } : (problems.push(`operation ${i + 1}: a transition's kind is one of ${Object.keys(TRANSITIONS).join(", ")}`), op)
|
|
122
|
+
if (op?.op !== "add_graphic") return op
|
|
123
|
+
const graphic = cleanGraphic({ ...op, ...brandIn(person), at: undefined })
|
|
124
|
+
if (!graphic) return problems.push(`operation ${i + 1}: that isn't a graphic the kit draws (a "stat" is digits; text is up to ${TEXT_MAX} characters)`), op
|
|
125
|
+
if (op.at === undefined) return problems.push(`operation ${i + 1}: add_graphic needs \`at\`, a word anchor or a clip edge`), op
|
|
126
|
+
const said = graphicProblems(graphic, { spoken, near: spoken, person })
|
|
127
|
+
if (said.length) return problems.push(`operation ${i + 1}: ${said[0]}; a graphic's words are the speaker's or the person's own`), op
|
|
128
|
+
return { op: "add_motion", block: GRAPHIC_BLOCK, version: GRAPHIC_VERSION, variables: graphic, at: op.at, duration: Number.isInteger(op.duration) ? Math.min(op.duration, 8 * FLICKS) : graphicLength(graphic) }
|
|
129
|
+
})
|
|
130
|
+
return { ops: out, problems }
|
|
131
|
+
}
|
|
132
|
+
|
|
100
133
|
/**
|
|
101
134
|
* What models often send that means nothing: every optional field present as null,
|
|
102
135
|
* and empty lists or no `ops` at all. Tidied before the schema, never invented.
|
|
@@ -166,9 +199,12 @@ export function describe(op, index) {
|
|
|
166
199
|
return `Changed caption ${op.caption} to "${op.text}"`
|
|
167
200
|
case "caption_emphasis":
|
|
168
201
|
return `Emphasised "${words.get(op.word)?.text ?? op.word}" in caption ${op.caption}`
|
|
202
|
+
case "transition":
|
|
203
|
+
return `Added a ${(TRANSITION_LABELS[op.kind] ?? op.kind).toLowerCase()} transition into ${op.clip}`
|
|
169
204
|
case "add_title":
|
|
170
205
|
return `Added the title "${op.text}" at ${place(op.at)}`
|
|
171
206
|
case "add_motion":
|
|
207
|
+
if (op.block === GRAPHIC_BLOCK) return `Added ${/^[aeiou]/i.test(GRAPHIC_KINDS[op.variables?.kind]?.label ?? "g") ? "an" : "a"} ${(GRAPHIC_KINDS[op.variables?.kind]?.label ?? "graphic").toLowerCase()} "${op.variables?.text ?? ""}"${op.variables?.subtitle ? `, "${op.variables.subtitle}"` : ""} at ${place(op.at)}`
|
|
172
208
|
return op.block === "scene" ? `Added an animated ${op.variables?.kind ?? ""} scene, "${op.variables?.text ?? ""}", at ${place(op.at)}` : op.op
|
|
173
209
|
case "grade":
|
|
174
210
|
return `Graded ${op.clip}${op.saturation !== undefined ? `, saturation ${op.saturation}` : ""}${op.gain !== undefined ? `, contrast ${op.gain}` : ""}${op.gamma !== undefined ? `, gamma ${op.gamma}` : ""}${op.lift !== undefined ? `, lift ${op.lift}` : ""}`
|
|
@@ -337,7 +373,7 @@ export function timesView(text, project, index) {
|
|
|
337
373
|
* @param {{ ask: ReturnType<import("./ask.js").createAsk>, project: object, index: object, text: string, selection?: object, signal?: AbortSignal }} input
|
|
338
374
|
* @returns {Promise<{ ops: object[], changes: string[], project: object | null, source: string, reason?: string, calls: number }>}
|
|
339
375
|
*/
|
|
340
|
-
export async function revise({ ask, project, index, text, selection, history = [], signal }) {
|
|
376
|
+
export async function revise({ ask, project, index, text, selection, history = [], motion = false, signal }) {
|
|
341
377
|
const assets = project.assets.map((a) => a.id)
|
|
342
378
|
// A marked range reads like a typed one: code says what it points at
|
|
343
379
|
const marked = Number.isInteger(selection?.from) && Number.isInteger(selection?.to) ? ` from ${clock(selection.from)} to ${clock(selection.to)}` : ""
|
|
@@ -351,6 +387,7 @@ export async function revise({ ask, project, index, text, selection, history = [
|
|
|
351
387
|
`${earlier}The person asks (their own words, trusted): ${JSON.stringify(String(text).slice(0, 2000))}`,
|
|
352
388
|
"Answer with JSON only. Put in `ops` the operations that do exactly what they ask, and nothing else.",
|
|
353
389
|
"Times like 0:05 are on the cut's timeline; the lines above say which clip, words and captions each time points at. Use those ids, never compute flicks yourself. To take out a stretch the person names by time, use the exact remove_range given for it above, unchanged; for a stretch named by words, remove_range from its first word (edge start) to its last word (edge end). To change what a caption says, caption_edit with its caption id; to remove a caption, ripple_delete its caption id; to caption words, caption_style with their word ids and a look; to put a title on screen, add_title with text and a word anchor; to take background noise out of the voice, clean_voice on each picture clip; to warm or cool the picture, grade with temperature (lower is warmer, 6500 neutral), vibrance or vignette; for a speed ramp or slow motion, speed_ramp on the clip with from and to (source flicks from the lines above, or word anchors) and peak {n, d} (2/1 speeds up and back, 1/2 is eased slow motion); for a constant speed, speed; to lay other footage over a moment, place_broll with a video asset id from the project, at a word anchor or clip edge, and duration in flicks.",
|
|
390
|
+
...(motion ? [`To put a motion graphic on screen, add_graphic with kind (${Object.entries(GRAPHIC_KINDS).map(([id, kind]) => `${id}: ${kind.label.toLowerCase()}`).join("; ")}), text, subtitle where the kind has a second line, and at (a word anchor). Its words must be the speaker's or the person's own from their request, never yours; a stat's text is digits the speaker says.`, `To dress a cut, transition with the clip the picture arrives in (never the first clip) and kind (${Object.keys(TRANSITIONS).join(", ")}); the cut itself doesn't move.`] : []),
|
|
354
391
|
"Put one plain sentence in `say`: what you changed, or the answer if they asked a question.",
|
|
355
392
|
"If they ask to fix or correct the transcript (names, misheard words), put each wrong word in `corrections` as {word: its id, text: the right word}, only where you are confident from the context.",
|
|
356
393
|
"If they ask for the whole video to be made, directed, edited or improved (not one part of it), set `direct` to an object (with `seconds` and a caption look if they say so) and leave `ops` empty: the Director makes the whole cut.",
|
|
@@ -358,13 +395,18 @@ export async function revise({ ask, project, index, text, selection, history = [
|
|
|
358
395
|
].join("\n")
|
|
359
396
|
const words = new Map((index.words ?? []).map((w) => [w.id, w]))
|
|
360
397
|
// Operations must apply; a correction on an unknown word is only dropped, never worth a second call
|
|
361
|
-
const
|
|
362
|
-
|
|
398
|
+
const person = [...history.filter((h) => h.who === "you").map((h) => h.text), text].join("\n")
|
|
399
|
+
const expand = (ops) => (motion ? expandGraphics(ops, { index, person }) : { ops, problems: [] })
|
|
400
|
+
const check = ({ ops: asked }) => {
|
|
401
|
+
if (!asked.length) return []
|
|
402
|
+
const { ops, problems } = expand(asked)
|
|
403
|
+
if (problems.length) return problems
|
|
363
404
|
const tried = apply(project, ops, { index, author: "agent" })
|
|
364
405
|
return tried.applied ? [] : tried.diagnostics.map((d) => `operation ${d.op + 1}: ${d.message}`)
|
|
365
406
|
}
|
|
366
|
-
const answer = await ask({ task: "console", tier: "budget", schema:
|
|
367
|
-
const
|
|
407
|
+
const answer = await ask({ task: "console", tier: "budget", schema: consoleSchema(motion), view, request, maxOutput: 2000, check, clean: tidyConsole, fallback: () => ({ ops: [] }), signal, priority: 0 })
|
|
408
|
+
const expanded = expand(answer.value.ops)
|
|
409
|
+
const ops = expanded.problems.length ? [] : expanded.ops
|
|
368
410
|
const tried = ops.length ? apply(project, ops, { index, author: "agent" }) : null
|
|
369
411
|
// A correction that changes nothing, or isn't a known word, isn't offered
|
|
370
412
|
const corrections = (answer.value.corrections ?? []).map((c) => ({ word: c.word, text: cleanWord(c.text) })).filter((c) => words.has(c.word) && c.text && c.text !== words.get(c.word).text)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// The motion kit (MOTION_GRAPHICS.md, EDD-58): titles, name straps, opening and end cards,
|
|
2
|
+
// quotes and numbers over the footage, drawn by Kriya's own code from typed variables. No
|
|
3
|
+
// model writes code here. Web Animations only, so a graphic seeks and renders like every
|
|
4
|
+
// other tile: no clock, no randomness, no network. Each sits in the box the layout solver
|
|
5
|
+
// gives it, clear of the speaker's face and the captions, and its words are `text` and
|
|
6
|
+
// `subtitle`, so the copy and contrast gates read it as they read a title.
|
|
7
|
+
|
|
8
|
+
import { EngineFailure } from "./tool.js"
|
|
9
|
+
|
|
10
|
+
const FLICKS = 705_600_000
|
|
11
|
+
|
|
12
|
+
export const GRAPHIC_BLOCK = "graphic"
|
|
13
|
+
export const GRAPHIC_VERSION = 1
|
|
14
|
+
|
|
15
|
+
/** The kinds: what each is for (the Director's prompt and the Plan Card read this), and its styles, the first the default. */
|
|
16
|
+
export const GRAPHIC_KINDS = {
|
|
17
|
+
title: { label: "Title", styles: ["rise", "slam", "words"], subtitle: false, when: "a few strong words of the line being said, to land its point" },
|
|
18
|
+
chapter: { label: "Chapter card", styles: ["wipe"], subtitle: false, when: "the name of a new part of the video, as the speaker starts it" },
|
|
19
|
+
quote: { label: "Quote", styles: ["line"], subtitle: false, when: "a short sentence the speaker says that is worth reading as well as hearing" },
|
|
20
|
+
lower: { label: "Name strap", styles: ["bar", "pill"], subtitle: true, when: "who is speaking: the name in `text`, the role in `subtitle`; only when the person gave them" },
|
|
21
|
+
intro: { label: "Opening title", styles: ["sweep"], subtitle: true, when: "the video's title over its first seconds, with an optional second line" },
|
|
22
|
+
end: { label: "End card", styles: ["sweep"], subtitle: true, when: "the closing call to action over the last seconds, with an optional handle or second line" },
|
|
23
|
+
stat: { label: "Number", styles: ["pop"], subtitle: true, number: true, when: "one number the speaker says, as digits in `text` (with its unit if said), and what it counts in `subtitle`" },
|
|
24
|
+
}
|
|
25
|
+
export const STYLE_LABELS = { rise: "Rise", slam: "Slam", words: "Word by word", wipe: "Wipe", line: "Accent line", bar: "Bar", pill: "Pill", sweep: "Line sweep", pop: "Pop" }
|
|
26
|
+
|
|
27
|
+
/** The brand kit a project may choose from; hex and font stacks stay in code. Ink on plate holds WCAG 4.5:1 (tested). */
|
|
28
|
+
export const GRAPHIC_ACCENTS = { teal: "#4fd1c5", yellow: "#ffd23f", amber: "#ffb347", pink: "#ff7ab6", white: "#ffffff" }
|
|
29
|
+
export const GRAPHIC_TONES = { dark: { plate: "#13292b", ink: "#f2eadf", chip: "#13292b" }, light: { plate: "#f6f1e7", ink: "#1c2530", chip: "#1c2530" } }
|
|
30
|
+
// System fonts only: nothing is downloaded, and every stack ends in a family each platform has
|
|
31
|
+
export const GRAPHIC_FONTS = {
|
|
32
|
+
sans: "'Helvetica Neue',Helvetica,Arial,sans-serif",
|
|
33
|
+
serif: "Georgia,'Times New Roman',serif",
|
|
34
|
+
condensed: "'Avenir Next Condensed','Arial Narrow','Helvetica Neue',Arial,sans-serif",
|
|
35
|
+
mono: "'SF Mono',Menlo,Consolas,'Courier New',monospace",
|
|
36
|
+
}
|
|
37
|
+
export const TEXT_MAX = 48
|
|
38
|
+
export const SUBTITLE_MAX = 32 // one line under the main one, in the narrowest frame at the smallest readable size
|
|
39
|
+
const NUMBER = /^[₹$€£]?\d{1,7}(?:[.,]\d{1,3})*\s?(?:%|[A-Za-z₹$€£]{1,8})?$/
|
|
40
|
+
|
|
41
|
+
// Too long is cut at a word, never through one
|
|
42
|
+
const cleanText = (value, max = TEXT_MAX) => {
|
|
43
|
+
if (typeof value !== "string") return ""
|
|
44
|
+
const text = value.replace(/[\u0000-\u001f\u007f<>]/g, " ").replace(/\s+/g, " ").trim()
|
|
45
|
+
if (text.length <= max) return text
|
|
46
|
+
const cut = text.slice(0, max + 1)
|
|
47
|
+
return (cut.includes(" ") ? cut.slice(0, cut.lastIndexOf(" ")) : cut.slice(0, max)).trim()
|
|
48
|
+
}
|
|
49
|
+
const pick = (table, value, fallback) => (Object.hasOwn(table, value ?? "") ? value : fallback)
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A graphic's shape, at every trust boundary (a model's answer, a browser's request, a saved
|
|
53
|
+
* project). Unknown fields go; text is cleaned. Whether its words may be shown is `graphicProblems`' job.
|
|
54
|
+
* @returns {object | null} null when it can't be a graphic
|
|
55
|
+
*/
|
|
56
|
+
export function cleanGraphic(raw) {
|
|
57
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null
|
|
58
|
+
const kind = pick(GRAPHIC_KINDS, raw.kind, null)
|
|
59
|
+
if (!kind) return null
|
|
60
|
+
const shape = GRAPHIC_KINDS[kind]
|
|
61
|
+
const text = cleanText(raw.text)
|
|
62
|
+
if (!text || (shape.number && !NUMBER.test(text))) return null
|
|
63
|
+
const subtitle = shape.subtitle ? cleanText(raw.subtitle, SUBTITLE_MAX) : ""
|
|
64
|
+
const id = typeof raw.at === "string" && /^[A-Za-z0-9:_-]{1,64}$/.test(raw.at) ? raw.at : null
|
|
65
|
+
return {
|
|
66
|
+
kind,
|
|
67
|
+
style: shape.styles.includes(raw.style) ? raw.style : shape.styles[0],
|
|
68
|
+
text,
|
|
69
|
+
...(subtitle ? { subtitle } : {}),
|
|
70
|
+
accent: pick(GRAPHIC_ACCENTS, raw.accent, "teal"),
|
|
71
|
+
tone: pick(GRAPHIC_TONES, raw.tone, "dark"),
|
|
72
|
+
font: pick(GRAPHIC_FONTS, raw.font, "sans"),
|
|
73
|
+
...(id ? { at: id } : {}),
|
|
74
|
+
// Set by the recipe on a graphic an approved plan asked for, so a remake replaces it
|
|
75
|
+
...(raw.plan === true ? { plan: true } : {}),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** How long a graphic stays up: long enough to read, never long enough to bore. In flicks. */
|
|
80
|
+
export function graphicLength(graphic) {
|
|
81
|
+
const letters = graphic.text.length + (graphic.subtitle?.length ?? 0)
|
|
82
|
+
const seconds = graphic.kind === "intro" || graphic.kind === "end" ? 3.2 : graphic.kind === "lower" ? 4 : Math.min(5, Math.max(1.8, letters / 15 + 1.2))
|
|
83
|
+
return Math.round(seconds * FLICKS)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const escape = (text) => String(text).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c])
|
|
87
|
+
const round = (n) => Math.round(n * 10000) / 10000
|
|
88
|
+
const EASE = "cubic-bezier(.2,.8,.2,1)"
|
|
89
|
+
const SPRING = { damping: 0.6, frequency: 12, ms: 620 }
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {{ variables: object, area: { x: number, y: number, w: number, h: number }, output: { width: number, height: number }, duration: number }} input
|
|
93
|
+
* @param {(spring: object) => object[]} springKeyframes motion.js's, handed in so the two files don't import each other
|
|
94
|
+
* @returns {{ css: string, body: string, animations: object[], fit: object }}
|
|
95
|
+
*/
|
|
96
|
+
export function buildGraphic({ variables, area, output, duration }, springKeyframes) {
|
|
97
|
+
const graphic = cleanGraphic(variables)
|
|
98
|
+
if (!graphic) throw new EngineFailure("plan", "bad_graphic", "This graphic's variables don't describe a graphic.")
|
|
99
|
+
const { kind, style, text, subtitle } = graphic
|
|
100
|
+
const tone = GRAPHIC_TONES[graphic.tone]
|
|
101
|
+
const accent = GRAPHIC_ACCENTS[graphic.accent]
|
|
102
|
+
const font = GRAPHIC_FONTS[graphic.font]
|
|
103
|
+
const ms = (duration / FLICKS) * 1000
|
|
104
|
+
const floor = Math.ceil(output.height * 0.0205) // QG-09's smallest readable size
|
|
105
|
+
const two = !!subtitle
|
|
106
|
+
const pad = Math.round(area.h * 0.08)
|
|
107
|
+
const big = kind === "stat" || kind === "intro"
|
|
108
|
+
const main = Math.max(floor, Math.round(area.h * (two ? (big ? 0.4 : 0.34) : big ? 0.5 : 0.42)))
|
|
109
|
+
const small = Math.max(floor, Math.round(area.h * 0.19))
|
|
110
|
+
const left = kind === "lower" || kind === "chapter" || kind === "quote"
|
|
111
|
+
const radius = style === "pill" ? Math.round(area.h / 2) : Math.round(area.h * 0.1)
|
|
112
|
+
const bar = Math.max(4, Math.round(area.h * 0.05))
|
|
113
|
+
|
|
114
|
+
const animations = []
|
|
115
|
+
const animate = (id, keyframes, options) => animations.push({ id, keyframes, options: { fill: "both", ...options } })
|
|
116
|
+
// In and out with the whole graphic, so it never pops off on a cut
|
|
117
|
+
const out = Math.min(220, ms * 0.12)
|
|
118
|
+
animate("a", [{ opacity: 1, offset: 0 }, { opacity: 1, offset: round(1 - out / ms) }, { opacity: 0, offset: 1 }], { duration: ms })
|
|
119
|
+
const spring = (id, from, delay = 0) => animate(id, springKeyframes({ ...SPRING, from, to: { y: 0, scale: 1, opacity: 1 } }), { duration: SPRING.ms, delay })
|
|
120
|
+
const grow = (id, axis, delay = 0, length = 380) => animate(id, [{ transform: `scale${axis}(0)` }, { transform: `scale${axis}(1)` }], { duration: length, delay, easing: EASE })
|
|
121
|
+
const fade = (id, delay, length = 300) => animate(id, [{ opacity: 0 }, { opacity: 1 }], { duration: length, delay, easing: "ease-out" })
|
|
122
|
+
|
|
123
|
+
// Room on the left for what leads the text in: the bar or the dot
|
|
124
|
+
const lead = Math.round(pad * 2.2) + (kind === "lower" || kind === "chapter" || kind === "quote" ? bar * 4 : 0)
|
|
125
|
+
let words = escape(text)
|
|
126
|
+
let rule = ""
|
|
127
|
+
if (kind === "title" && style === "slam") {
|
|
128
|
+
spring("t", { scale: 1.6, opacity: 0 })
|
|
129
|
+
rule = "under"
|
|
130
|
+
grow("k", "X", 260)
|
|
131
|
+
} else if (kind === "title" && style === "words") {
|
|
132
|
+
// Each word lands in turn, all in within half a second so the line reads at once
|
|
133
|
+
const parts = text.split(" ")
|
|
134
|
+
const step = Math.min(90, 480 / parts.length)
|
|
135
|
+
words = parts.map((word, i) => `<span id="w${i}" class="w">${escape(word)}</span>`).join(" ")
|
|
136
|
+
fade("t", 0, 120)
|
|
137
|
+
parts.forEach((_, i) => spring(`w${i}`, { y: Math.round(main * 0.6), opacity: 0 }, Math.round(i * step)))
|
|
138
|
+
} else if (kind === "chapter") {
|
|
139
|
+
rule = "side"
|
|
140
|
+
grow("k", "Y", 0, 320)
|
|
141
|
+
animate("t", [{ clipPath: "inset(0 100% 0 0)" }, { clipPath: "inset(0 0 0 0)" }], { duration: 460, delay: 120, easing: EASE })
|
|
142
|
+
} else if (kind === "quote") {
|
|
143
|
+
// No quote-mark glyph: a reader takes one for "66" and the copy gate rightly fails it (found on a real make)
|
|
144
|
+
rule = "side"
|
|
145
|
+
grow("k", "Y", 0, 320)
|
|
146
|
+
spring("t", { y: Math.round(main * 0.5), opacity: 0 }, 90)
|
|
147
|
+
} else if (kind === "lower") {
|
|
148
|
+
rule = style === "pill" ? "dot" : "side"
|
|
149
|
+
animate("t", [{ transform: `translateX(-${Math.round(area.w * 0.12)}px)`, opacity: 0 }, { transform: "translateX(0)", opacity: 1 }], { duration: 480, easing: EASE })
|
|
150
|
+
grow("k", style === "pill" ? "" : "Y", 180, 320)
|
|
151
|
+
} else if (kind === "intro" || kind === "end") {
|
|
152
|
+
rule = "under"
|
|
153
|
+
spring("t", { y: Math.round(main * 0.8), scale: 0.92, opacity: 0 })
|
|
154
|
+
grow("k", "X", 220, 520)
|
|
155
|
+
} else if (kind === "stat") {
|
|
156
|
+
rule = "under"
|
|
157
|
+
spring("t", { scale: 0.5, opacity: 0 })
|
|
158
|
+
grow("k", "X", 200)
|
|
159
|
+
} else spring("t", { y: Math.round(main * 1.2), scale: 0.85, opacity: 0 })
|
|
160
|
+
if (two) fade("u", 320)
|
|
161
|
+
|
|
162
|
+
// The end card's second line is a chip in the accent colour, with the plate's dark ink on it
|
|
163
|
+
const chip = kind === "end" && two
|
|
164
|
+
// QG-09 reads a text's plate from the text's own element, so each line carries the plate's colour
|
|
165
|
+
const css = [
|
|
166
|
+
`#a{position:absolute;left:${area.x}px;top:${area.y}px;width:${area.w}px;height:${area.h}px;display:flex;align-items:center;justify-content:${left ? "flex-start" : "center"}}`,
|
|
167
|
+
`#t{position:relative;box-sizing:border-box;max-width:100%;display:flex;flex-direction:column;align-items:${left ? "flex-start" : "center"};justify-content:center;gap:${Math.round(pad * 0.3)}px;padding:${pad}px ${Math.round(pad * 2.2)}px ${pad}px ${lead}px;background:${tone.plate};border-radius:${radius}px;font-family:${font};color:${tone.ink};text-align:${left ? "left" : "center"};text-wrap:balance;box-shadow:0 ${Math.round(pad * 0.3)}px ${pad * 2}px #00000040}`,
|
|
168
|
+
`#m{display:block;padding:0 .08em;background:${tone.plate};font-size:${main}px;line-height:1.2;font-weight:800;${kind === "quote" ? "font-style:italic;font-weight:600;" : ""}${kind === "stat" ? "font-variant-numeric:tabular-nums;" : ""}}`,
|
|
169
|
+
`.w{display:inline-block}`,
|
|
170
|
+
`#u{display:block;white-space:nowrap;font-size:${small}px;line-height:1.25;font-weight:600;${chip ? `background:${accent};color:${GRAPHIC_TONES.dark.chip};padding:${Math.round(small * 0.18)}px ${Math.round(small * 0.5)}px;border-radius:${Math.round(small * 0.3)}px` : `background:${tone.plate}`}}`,
|
|
171
|
+
rule === "under" ? `#k{height:${bar}px;width:100%;background:${accent};border-radius:${bar}px;transform-origin:${left ? "left" : "center"}}` : "",
|
|
172
|
+
rule === "side" ? `#k{position:absolute;left:0;top:0;bottom:0;width:${bar * 2}px;background:${accent};border-radius:${radius}px 0 0 ${radius}px;transform-origin:top}` : "",
|
|
173
|
+
rule === "dot" ? `#k{position:absolute;left:${Math.round(pad * 1.6)}px;top:50%;width:${bar * 2}px;height:${bar * 2}px;margin-top:-${bar}px;background:${accent};border-radius:50%}` : "",
|
|
174
|
+
].join("")
|
|
175
|
+
const body = `<div id="a"><div id="t"><span id="m" data-text>${words}</span>${rule === "under" ? `<span id="k"></span>` : ""}${two ? `<span id="u" data-text>${escape(subtitle)}</span>` : ""}${rule === "side" || rule === "dot" ? `<span id="k"></span>` : ""}</div></div>`
|
|
176
|
+
// The main line wraps, then steps down until the plate fits its box, never under the readable floor
|
|
177
|
+
return { css, body, animations, fit: { id: "m", within: "a", min: floor, box: "t" } }
|
|
178
|
+
}
|
|
@@ -10,6 +10,7 @@ import { join } from "node:path"
|
|
|
10
10
|
import { childEnv } from "../runtime/setup.js"
|
|
11
11
|
import { confine, confinement, installOf } from "./confine.js"
|
|
12
12
|
import { buildScene, SCENE_VERSION } from "./scenes.js"
|
|
13
|
+
import { buildGraphic, GRAPHIC_VERSION } from "./graphics.js"
|
|
13
14
|
import { EngineFailure, runTool } from "./tool.js"
|
|
14
15
|
|
|
15
16
|
const FLICKS = 705_600_000
|
|
@@ -66,9 +67,10 @@ export function tileSeconds(flicks, fps) {
|
|
|
66
67
|
* tile, Kriya's own animations. Non-GSAP, so `data-no-timeline` (EX-01).
|
|
67
68
|
* @param {{ width: number, height: number, duration: number, css: string, body: string, animations: { id: string, keyframes: object[], options: object }[], fit?: { id: string, within: string, min: number } }} parts duration in flicks;
|
|
68
69
|
* fit: shrink an element's font, a pixel at a time, until it fits its box (no clock, so every render agrees)
|
|
70
|
+
* fit.box: the element measured against the box, when it isn't the one whose font shrinks (a plate around the text)
|
|
69
71
|
*/
|
|
70
72
|
export function tileDocument({ width, height, duration, css, body, animations, fit }) {
|
|
71
|
-
const fitting = fit ? `{const t=document.getElementById(${scriptJson(fit.id)}),a=document.getElementById(${scriptJson(fit.within)});let s=parseFloat(getComputedStyle(t).fontSize);while((
|
|
73
|
+
const fitting = fit ? `{const t=document.getElementById(${scriptJson(fit.id)}),a=document.getElementById(${scriptJson(fit.within)}),b=document.getElementById(${scriptJson(fit.box ?? fit.id)});let s=parseFloat(getComputedStyle(t).fontSize);while((b.offsetHeight>a.clientHeight||b.scrollWidth>a.clientWidth)&&s>${Number(fit.min)}){s-=1;t.style.fontSize=s+"px"}}` : ""
|
|
72
74
|
const seconds = (duration / FLICKS).toFixed(6)
|
|
73
75
|
return [
|
|
74
76
|
"<!doctype html>",
|
|
@@ -135,6 +137,8 @@ export const BLOCKS = {
|
|
|
135
137
|
},
|
|
136
138
|
// An explainer scene (VISUAL_SCENES.md): an opaque cutaway; `placement` is its content box
|
|
137
139
|
scene: { version: SCENE_VERSION, build: (parts) => buildScene(parts, springKeyframes) },
|
|
140
|
+
// The motion kit (MOTION_GRAPHICS.md): a title, strap or card in the box the layout gives it
|
|
141
|
+
graphic: { version: GRAPHIC_VERSION, build: (parts) => buildGraphic(parts, springKeyframes) },
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
/** A block tile's composition. An unknown block or version is refused, never drawn as something else. */
|
package/src/edit/gates/index.js
CHANGED
|
@@ -309,8 +309,11 @@ async function qg07({ file, plan, run, thresholds }) {
|
|
|
309
309
|
const picture = wholeSegment(plan).node.picture.sort((a, b) => a.at - b.at)
|
|
310
310
|
// A freeze the plan asks for; and a scene may rest on a finished diagram while the voice explains it
|
|
311
311
|
const holds = [...picture.filter((p) => p.hold), ...plan.tiles.filter((tile) => isSceneBlock(tile.node))].map(({ at, end }) => ({ at, end }))
|
|
312
|
+
// A transition the plan asks for holds the last frame under the next clip, and a dip passes through black
|
|
313
|
+
const transitions = picture.filter((p) => p.enter).map((p) => ({ at: p.at, end: p.at + p.enter.duration }))
|
|
314
|
+
holds.push(...transitions)
|
|
312
315
|
const cuts = picture.slice(1).map((p, i) => ({ t: p.at, same: p.asset === picture[i].asset && !p.hold && !picture[i].hold }))
|
|
313
|
-
return outcome("QG-07", judgeHealth(health, { duration: plan.duration, fps: plan.output.fps, holds, cuts }, thresholds))
|
|
316
|
+
return outcome("QG-07", judgeHealth(health, { duration: plan.duration, fps: plan.output.fps, holds, cuts, transitions }, thresholds))
|
|
314
317
|
}
|
|
315
318
|
|
|
316
319
|
const textTiles = (plan) => plan.tiles.filter((t) => t.kind === "caption" || t.kind === "block")
|
|
@@ -69,16 +69,19 @@ export function readHealth(text) {
|
|
|
69
69
|
* @param {{ black: object[], frozen: object[], luma: number[] }} health
|
|
70
70
|
* @param {{ duration: number, fps: { n: number, d: number }, holds: { at: number, end: number }[], cuts: { t: number, same: boolean }[] }} plan holds: freezes the plan asks for; cuts: where pieces of one source meet
|
|
71
71
|
*/
|
|
72
|
-
export function judgeHealth({ black, frozen, luma }, { duration, fps, holds, cuts }, { exposureJump }) {
|
|
72
|
+
export function judgeHealth({ black, frozen, luma }, { duration, fps, holds, cuts, transitions = [] }, { exposureJump }) {
|
|
73
73
|
const failures = []
|
|
74
74
|
const close = (span) => ({ ...span, end: span.end ?? duration })
|
|
75
75
|
const planned = (span) => holds.some((h) => h.at <= span.start + FLICKS / 10 && span.end - FLICKS / 10 <= h.end)
|
|
76
|
-
|
|
76
|
+
// Black is a fault except inside a transition the plan asked for (a dip to black)
|
|
77
|
+
const dipped = (span) => transitions.some((t) => t.at <= span.start + FLICKS / 10 && span.end - FLICKS / 10 <= t.end)
|
|
78
|
+
for (const span of black.map(close).filter((span) => !dipped(span))) failures.push({ kind: "black", severity: "block", t: span.start, seconds: round((span.end - span.start) / FLICKS, 2) })
|
|
77
79
|
for (const span of frozen.map(close)) if (!planned(span)) failures.push({ kind: "frozen", severity: "block", t: span.start, seconds: round((span.end - span.start) / FLICKS, 2) })
|
|
78
80
|
const frameAt = (t) => Math.min(luma.length - 1, Math.max(0, Math.floor((t * fps.n) / (FLICKS * fps.d))))
|
|
79
81
|
let worst = 0
|
|
80
82
|
for (const cut of cuts) {
|
|
81
|
-
|
|
83
|
+
// A cut dressed with a transition isn't a hard cut: its brightness is meant to move
|
|
84
|
+
if (!cut.same || transitions.some((t) => t.at === cut.t)) continue
|
|
82
85
|
const before = luma[frameAt(cut.t) - 1]
|
|
83
86
|
const after = luma[frameAt(cut.t)]
|
|
84
87
|
if (!Number.isFinite(before) || !Number.isFinite(after)) continue
|
package/src/edit/host/main.js
CHANGED
|
@@ -12,7 +12,7 @@ import { createScheduler, DEFAULT_SLOTS } from "../graph/scheduler.js"
|
|
|
12
12
|
import { createGovernor } from "../loop/governor.js"
|
|
13
13
|
import { kriyaHome } from "../../paths.js"
|
|
14
14
|
import { createJobs } from "./jobs.js"
|
|
15
|
-
import { codeStamp, editHome, lockPath, portPath, socketPath } from "./paths.js"
|
|
15
|
+
import { codeStamp, editHome, isPipe, lockPath, portPath, socketPath } from "./paths.js"
|
|
16
16
|
import { createProjects } from "./projects.js"
|
|
17
17
|
import { createHandler } from "./server.js"
|
|
18
18
|
import { createTavi } from "./tavi.js"
|
|
@@ -91,7 +91,7 @@ function shutdown() {
|
|
|
91
91
|
server.close()
|
|
92
92
|
server.closeAllConnections()
|
|
93
93
|
}
|
|
94
|
-
rmSync(socketPath(home), { force: true })
|
|
94
|
+
if (!isPipe(socketPath(home))) rmSync(socketPath(home), { force: true })
|
|
95
95
|
tavi.close()
|
|
96
96
|
watcher.close()
|
|
97
97
|
projects.close()
|
|
@@ -123,9 +123,12 @@ function storedPort() {
|
|
|
123
123
|
|
|
124
124
|
port = await listen(storedPort())
|
|
125
125
|
writeFileSync(portPath(home), String(port))
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
// A Unix socket is a file: a stale one is cleared first, and only its owner may open it.
|
|
127
|
+
// A Windows named pipe is neither (paths.js): it goes when the Host does, and has no mode
|
|
128
|
+
const socket = socketPath(home)
|
|
129
|
+
if (!isPipe(socket)) rmSync(socket, { force: true })
|
|
130
|
+
await new Promise((done) => local.listen(socket, done))
|
|
131
|
+
if (!isPipe(socket)) chmodSync(socket, 0o600)
|
|
129
132
|
log(`listening on 127.0.0.1:${port}`)
|
|
130
133
|
|
|
131
134
|
void readTools()
|
package/src/edit/host/paths.js
CHANGED
|
@@ -2,12 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
import { createHash } from "node:crypto"
|
|
4
4
|
import { readdirSync, statSync } from "node:fs"
|
|
5
|
-
import { join } from "node:path"
|
|
5
|
+
import { join, resolve } from "node:path"
|
|
6
6
|
|
|
7
7
|
import { kriyaHome } from "../../paths.js"
|
|
8
8
|
|
|
9
9
|
export const editHome = (home = kriyaHome()) => join(home, "edit")
|
|
10
|
-
|
|
10
|
+
const PIPE = "\\\\.\\pipe\\"
|
|
11
|
+
/** True for a Windows named pipe: it isn't a file, so it has no mode to set and nothing to remove. */
|
|
12
|
+
export const isPipe = (path) => path.startsWith(PIPE)
|
|
13
|
+
/**
|
|
14
|
+
* Where the Host listens for this computer's own commands. A Unix socket in the Host's folder;
|
|
15
|
+
* on Windows, which has none there, a named pipe, one per Kriya home (a hash of its path,
|
|
16
|
+
* which Windows compares without case).
|
|
17
|
+
* shortcut: a pipe gets Windows' default access rules, not the socket's owner-only mode; a pipe
|
|
18
|
+
* limited to the signed-in person needs a native call Node doesn't offer. Not yet run on Windows.
|
|
19
|
+
*/
|
|
20
|
+
export function socketPath(home = kriyaHome(), platform = process.platform) {
|
|
21
|
+
if (platform !== "win32") return join(editHome(home), "host.sock")
|
|
22
|
+
return `${PIPE}kriya-edit-host-${createHash("sha256").update(resolve(home).toLowerCase()).digest("hex").slice(0, 16)}`
|
|
23
|
+
}
|
|
11
24
|
export const lockPath = (home) => join(editHome(home), "host.lock")
|
|
12
25
|
export const portPath = (home) => join(editHome(home), "port")
|
|
13
26
|
export const logPath = (home) => join(editHome(home), "host.log")
|
|
@@ -40,9 +40,14 @@ import { editHome } from "./paths.js"
|
|
|
40
40
|
import { createTaste } from "./taste.js"
|
|
41
41
|
import { ASPECTS, analyseReference, cleanRefs, takeFrom } from "../engine/reference.js"
|
|
42
42
|
import { briefOf, planCut } from "../director/plan.js"
|
|
43
|
+
import { editsSince, planDiff, storyFor } from "../director/continuity.js"
|
|
44
|
+
import { cleanGraphic, GRAPHIC_ACCENTS, GRAPHIC_BLOCK, GRAPHIC_FONTS, GRAPHIC_KINDS, GRAPHIC_TONES, GRAPHIC_VERSION, graphicLength, STYLE_LABELS } from "../engine/graphics.js"
|
|
43
45
|
import { MOODS, writeMusicBed } from "../engine/music-bed.js"
|
|
44
46
|
import { SFX, writeSfx } from "../engine/sfx.js"
|
|
45
47
|
|
|
48
|
+
// "start over", "from scratch": the one way a request after a make isn't a change to that cut
|
|
49
|
+
const STARTS_OVER = /\b(?:start (?:over|again|afresh)|from scratch|fresh (?:cut|edit|start)|brand[- ]new (?:cut|edit))\b/i
|
|
50
|
+
|
|
46
51
|
function atomicWrite(file, text) {
|
|
47
52
|
const part = `${file}.${process.pid}.tmp`
|
|
48
53
|
const handle = openSync(part, "w")
|
|
@@ -289,7 +294,8 @@ export function createProjects({ home, roots, scheduler, tools, governor = null,
|
|
|
289
294
|
/** The console: words → a proposal, applied to a copy, nothing landing yet (UX_SPEC §4, §5). */
|
|
290
295
|
async ask(state, { text, selection, history = [], job = 0 }) {
|
|
291
296
|
const chosen = cleanSelection(selection, state.log.current, state.index)
|
|
292
|
-
const
|
|
297
|
+
const { motion } = await this.features()
|
|
298
|
+
const result = await revise({ ask: this.askFor(state, job), project: state.log.current, index: state.index, text, selection: chosen, history, motion: motion && !state.engine.motion().missing })
|
|
293
299
|
// A request about the whole video goes to the Director's make job; the Studio offers it
|
|
294
300
|
const direct = result.direct ? { brief: { ...(result.direct.seconds ? { seconds: result.direct.seconds } : {}), ...(result.direct.captions ? { captions: result.direct.captions } : {}) } } : null
|
|
295
301
|
if (!result.ops.length && !result.corrections.length) return { proposal: null, direct, say: result.say, source: result.source, reason: direct || result.say ? null : (result.reason ?? "Kriya couldn't turn that into an edit. Try saying it another way.") }
|
|
@@ -322,7 +328,21 @@ export function createProjects({ home, roots, scheduler, tools, governor = null,
|
|
|
322
328
|
/** What this Kriya allows now. A failed question means off. */
|
|
323
329
|
async features() {
|
|
324
330
|
if (!known || Date.now() - known.at > FEATURES_MS) known = { at: Date.now(), value: await features().catch(() => ({ visuals: false, playbooks: false, mediaSearch: false })) }
|
|
325
|
-
|
|
331
|
+
// A server from before editing.motion says nothing of it: off
|
|
332
|
+
return { motion: false, customMotion: false, ...known.value }
|
|
333
|
+
},
|
|
334
|
+
|
|
335
|
+
/** One motion graphic as the render will draw it, for the Plan Card. @returns {string} a complete document */
|
|
336
|
+
graphicPreview(state, raw, format) {
|
|
337
|
+
const graphic = cleanGraphic(raw)
|
|
338
|
+
if (!graphic) throw new EngineFailure("input", "bad_graphic", "That isn't a graphic from this project's plan.")
|
|
339
|
+
const shape = FORMATS[format] ?? FORMATS["9:16"]
|
|
340
|
+
const canvas = { width: shape.width, height: shape.height }
|
|
341
|
+
// Where a strap or a title usually lands; the make places each clear of the face and the captions
|
|
342
|
+
const low = graphic.kind === "lower" || graphic.kind === "end"
|
|
343
|
+
const placement = { x: Math.round(canvas.width * 0.1), y: Math.round(canvas.height * (low ? 0.66 : 0.42)), w: Math.floor((canvas.width * DEFAULT_RULES.boxWidth) / 100), h: Math.floor((canvas.height * DEFAULT_RULES.boxHeight) / 100) }
|
|
344
|
+
// A graphic sits over footage; the card shows it on a plain backdrop so a light or dark plate both read
|
|
345
|
+
return blockComposition({ blockId: GRAPHIC_BLOCK, version: GRAPHIC_VERSION, variables: graphic, placement, duration: graphicLength(graphic) }, { output: canvas, canvas }).replace("html,body{margin:0;background:transparent", "html,body{margin:0;background:linear-gradient(160deg,#6b7b80,#2a3437)")
|
|
326
346
|
},
|
|
327
347
|
|
|
328
348
|
/**
|
|
@@ -417,8 +437,31 @@ export function createProjects({ home, roots, scheduler, tools, governor = null,
|
|
|
417
437
|
return { pictures, terms }
|
|
418
438
|
},
|
|
419
439
|
|
|
440
|
+
/**
|
|
441
|
+
* The last make this cut still descends from: its brief, story, approved plan and the
|
|
442
|
+
* person's edits it carried (continuity.js). Null once that make is undone or none was run.
|
|
443
|
+
*/
|
|
444
|
+
lastMake(state) {
|
|
445
|
+
try {
|
|
446
|
+
const last = JSON.parse(readFileSync(join(dirOf(state.id), "last-make.json"), "utf8"))
|
|
447
|
+
const since = editsSince(state.log, last.head)
|
|
448
|
+
return since ? { ...last, edits: [...(Array.isArray(last.carried) ? last.carried : []), ...since] } : null
|
|
449
|
+
} catch {
|
|
450
|
+
return null
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
/** The story a make of this brief keeps from the last one; null when it's chosen again. */
|
|
455
|
+
keptStory(state, brief) {
|
|
456
|
+
return brief.fresh ? null : storyFor(this.lastMake(state), brief)
|
|
457
|
+
},
|
|
458
|
+
|
|
420
459
|
/** The Director's plan for the whole cut: proposed, never made until the person approves it. */
|
|
421
460
|
async plan(state, { text, history = [], previous = null, choices = {}, job = 0, signal } = {}) {
|
|
461
|
+
// With a cut already made, a request changes that cut: the plan it was made from is the one revised
|
|
462
|
+
const fresh = STARTS_OVER.test(text)
|
|
463
|
+
const last = fresh ? null : this.lastMake(state)
|
|
464
|
+
previous ??= last?.plan ?? null
|
|
422
465
|
// The references in use, each only for what the person took it for; with none named, every reference, whole
|
|
423
466
|
const named = cleanRefs(choices.references)
|
|
424
467
|
const chosen = named.length ? named : state.log.current.assets.filter((a) => a.kind === "reference").map((a) => ({ id: a.id, aspect: "all" }))
|
|
@@ -431,16 +474,22 @@ export function createProjects({ home, roots, scheduler, tools, governor = null,
|
|
|
431
474
|
const name = `${ref.path.split(/[\\/]/).at(-1)}${aspect === "all" ? "" : ` (only for: ${ASPECTS[aspect]})`}`
|
|
432
475
|
references.push({ name, lines: taken.lines.length ? taken.lines : [`nothing measured for ${ASPECTS[aspect].toLowerCase()}`] })
|
|
433
476
|
}
|
|
434
|
-
const { visuals, playbooks, mediaSearch } = await this.features()
|
|
477
|
+
const { visuals, playbooks, mediaSearch, motion } = await this.features()
|
|
435
478
|
const device = mediaSearch ? readDevice() : null
|
|
436
479
|
// What was found is kept here, so an approval names an id and never carries a URL or a licence from the browser
|
|
437
480
|
const lookups = device ? { search: (queries) => searchMedia(device, queries), define: (terms) => defineTerms(device, terms), keep: (found) => this.keepFound(state, found) } : null
|
|
438
|
-
const plan = await planCut({ ask: this.askFor(state, job), project: state.log.current, index: state.index, text, history, previous, references, choices, visuals: visuals && !state.engine.motion().missing, playbooks, lookups, signal })
|
|
481
|
+
const plan = await planCut({ ask: this.askFor(state, job), project: state.log.current, index: state.index, text, history, previous, references, choices, motion: motion && !state.engine.motion().missing, visuals: visuals && !state.engine.motion().missing, playbooks, lookups, signal })
|
|
439
482
|
const scenes = plan.settings.scenes ?? []
|
|
483
|
+
const brief = briefOf(plan.settings)
|
|
440
484
|
// The exact brief an approval makes, so the Studio sends back what was shown
|
|
441
485
|
return {
|
|
442
486
|
...plan,
|
|
443
|
-
brief:
|
|
487
|
+
brief: { ...brief, ...(fresh ? { fresh: true } : {}) },
|
|
488
|
+
// Said by code from the two briefs, so the card shows what an approval changes in the cut that's there,
|
|
489
|
+
// and whether its story stays (the same test the make route applies, in the make's own units)
|
|
490
|
+
...(last ? { revises: true, differs: last.plan ? planDiff(briefOf(last.plan.settings ?? {}), brief) : [], keepsStory: !!storyFor(last, { ...(brief.seconds ? { targetDuration: Math.round(brief.seconds * FLICKS) } : {}), ...(brief.cuts ? { cuts: brief.cuts.map((c) => ({ from: Math.round(c.from * FLICKS), to: Math.round(c.to * FLICKS) })) } : {}) }) } : {}),
|
|
491
|
+
// What the card may restyle each graphic to: labels only, the colours and fonts stay in code
|
|
492
|
+
...(plan.settings.graphics?.length ? { graphicChoices: { kinds: Object.fromEntries(Object.entries(GRAPHIC_KINDS).map(([id, kind]) => [id, { label: kind.label, styles: kind.styles }])), styles: STYLE_LABELS, accents: Object.keys(GRAPHIC_ACCENTS), tones: Object.keys(GRAPHIC_TONES), fonts: Object.keys(GRAPHIC_FONTS) } } : {}),
|
|
444
493
|
// What the card may swap each scene to; code says, so it can't offer what won't draw
|
|
445
494
|
...(scenes.length ? { sceneChoices: { kinds: Object.fromEntries(Object.entries(SCENE_KINDS).map(([id, kind]) => [id, kind.label])), themes: Object.fromEntries(Object.entries(SCENE_THEMES).map(([id, theme]) => [id, theme.label])), swaps: scenes.map(swapsFor) } } : {}),
|
|
446
495
|
}
|
|
@@ -621,7 +670,10 @@ export function createProjects({ home, roots, scheduler, tools, governor = null,
|
|
|
621
670
|
const runtime = activeRuntime(home)
|
|
622
671
|
const ask = replay ? replayAsk(replay.answers) : this.askFor(state, job)
|
|
623
672
|
const parent = state.log.head
|
|
673
|
+
// The person's edits to the last cut go onto this one, unless they asked to start over
|
|
674
|
+
const last = replay || request.brief?.fresh ? null : this.lastMake(state)
|
|
624
675
|
const result = await makeReel({
|
|
676
|
+
edits: last?.edits ?? [],
|
|
625
677
|
project: state.log.current,
|
|
626
678
|
head: state.log.head,
|
|
627
679
|
index: state.index,
|
|
@@ -651,11 +703,15 @@ export function createProjects({ home, roots, scheduler, tools, governor = null,
|
|
|
651
703
|
const planHash = result.best.plan ? sha256(canonical(result.best.plan)) : null
|
|
652
704
|
const repairs = result.best.repairs ?? []
|
|
653
705
|
const person = result.best.person ?? []
|
|
654
|
-
const
|
|
706
|
+
const carried = result.best.carried ?? []
|
|
707
|
+
const lost = result.best.dropped ?? []
|
|
708
|
+
const notes = [...result.notes, ...(carried.length ? [`Kept ${carried.length} of your own edit${carried.length === 1 ? "" : "s"} to the last cut.`] : []), ...(lost.length ? [`${lost.length} of your edits no longer fit this cut and ${lost.length === 1 ? "was" : "were"} left out: ${lost.map((d) => describe(d.op, state.index)).join("; ")}.`] : []), ...person.map((p) => `${p.gate}: ${p.message} This is yours to decide.`)]
|
|
655
709
|
if (replay) return { replayOf: replay.of, verdict: gates?.verdict ?? "not_checked", gates: gates?.gates ?? [], planHash, notes, repairs, calls: result.calls, stop: result.outcome.stop }
|
|
656
710
|
const { ops, dropped } = state.log.head === result.head ? { ops: result.best.ops, dropped: [] } : rebase(state.log.current, result.best.ops, state.index)
|
|
657
711
|
const landed = change(state, { ops, author: "agent" })
|
|
658
712
|
if (!landed.ok) throw new EngineFailure("plan", "refused", landed.diagnostics[0].message)
|
|
713
|
+
// What the next change to this cut starts from
|
|
714
|
+
atomicWrite(join(dirOf(state.id), "last-make.json"), JSON.stringify({ head: state.log.head, brief: request.brief ?? {}, story: result.best.story ?? null, carried, plan: request.plan ?? (request.brief?.fresh ? null : (last?.plan ?? null)) }))
|
|
659
715
|
// A caption per spoken line is one change to a person: said once, with the count
|
|
660
716
|
const captioned = ops.filter((op) => op.op === "caption_style" && op.words?.length)
|
|
661
717
|
const changes = [...usedRules, ...ops.filter((op) => !["ripple_delete", "reframe", "caption_style"].includes(op.op) || (op.op === "caption_style" && !op.words?.length)).map((op) => describe(op, state.index)), ...(captioned.length ? [`Captioned ${captioned.length} line${captioned.length === 1 ? "" : "s"} (${captioned[0].look})`] : [])]
|
|
@@ -680,7 +736,7 @@ export function createProjects({ home, roots, scheduler, tools, governor = null,
|
|
|
680
736
|
slots: result.slots,
|
|
681
737
|
stop: result.outcome.stop,
|
|
682
738
|
attempts,
|
|
683
|
-
dropped: dropped.map((d) => ({ change: describe(d.op, state.index), reason: d.reason })),
|
|
739
|
+
dropped: [...dropped, ...lost].map((d) => ({ change: describe(d.op, state.index), reason: d.reason })),
|
|
684
740
|
}
|
|
685
741
|
},
|
|
686
742
|
|