@kriya-ai/harness 0.2.4 → 2.0.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/RELEASE_NOTES.md +121 -0
- package/SAFETY.md +181 -0
- package/THIRD_PARTY_NOTICES.md +113 -0
- package/bin/kriya.js +188 -2
- package/bundle/cordis.patch.yml +49 -0
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +504 -3
- package/contract/schemas/api.json +64 -0
- package/contract/schemas/auth_matrix.json +44 -0
- package/contract/schemas/component_states.json +33 -0
- package/contract/schemas/design_tokens.json +34 -0
- package/contract/schemas/scene_direction.json +82 -0
- package/contract/schemas/threat_model.json +44 -0
- package/package.json +2 -1
- package/plugins/changes/client.js +5 -3
- package/plugins/deploy/index.js +215 -0
- package/plugins/deploy/package.json +13 -0
- package/plugins/grounding/index.js +81 -0
- package/plugins/grounding/lookup.js +373 -0
- package/plugins/grounding/package.json +13 -0
- package/plugins/kriya-tools/index.js +2 -1
- package/plugins/loop/index.js +376 -10
- package/plugins/mcp/index.js +79 -0
- package/plugins/mcp/package.json +13 -0
- package/plugins/mirror/index.js +17 -0
- package/plugins/overview/client.js +5 -2
- package/plugins/preview/client.js +12 -6
- package/plugins/progress/client.js +7 -4
- package/plugins/repo/index.js +230 -0
- package/plugins/repo/package.json +13 -0
- package/plugins/repo/repo.js +348 -0
- package/plugins/runstrip/client.js +426 -0
- package/plugins/runstrip/index.js +301 -0
- package/plugins/runstrip/package.json +23 -0
- package/src/cartridges.js +133 -0
- package/src/contracts.js +130 -0
- package/src/critic.js +78 -0
- package/src/daemon.js +7 -1
- package/src/doctor.js +67 -0
- package/src/edit/core/effects.js +185 -0
- package/src/edit/core/ffmpeg.js +82 -5
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +175 -3
- package/src/edit/core/plan.js +95 -9
- package/src/edit/core/project.d.ts +24 -0
- package/src/edit/core/project.js +64 -0
- package/src/edit/core/solver.js +34 -6
- package/src/edit/core/style-brief.js +211 -0
- package/src/edit/core/style-packs.js +57 -0
- package/src/edit/core/transitions.js +17 -0
- package/src/edit/core/type-kit.js +173 -0
- package/src/edit/director/ask.js +37 -3
- package/src/edit/director/assembly.js +829 -0
- package/src/edit/director/continuity.js +137 -0
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +186 -0
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +89 -12
- package/src/edit/director/revise.js +172 -7
- package/src/edit/director/viewer.js +136 -0
- package/src/edit/director/watch-fix.js +119 -0
- package/src/edit/engine/captions.js +110 -5
- package/src/edit/engine/confine.js +81 -4
- package/src/edit/engine/custom.js +243 -0
- package/src/edit/engine/dna2.js +893 -0
- package/src/edit/engine/fonts.js +218 -0
- package/src/edit/engine/graphics.js +439 -0
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +153 -14
- package/src/edit/engine/music-bed.js +59 -1
- package/src/edit/engine/packs.js +11 -0
- package/src/edit/engine/reference2.js +26 -0
- package/src/edit/engine/sfx.js +56 -1
- package/src/edit/engine/tool.js +21 -5
- package/src/edit/gates/assembly.js +194 -0
- package/src/edit/gates/copy.js +7 -4
- package/src/edit/gates/index.js +76 -8
- package/src/edit/gates/picture.js +6 -3
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +4 -3
- package/src/edit/host/clips.js +33 -0
- package/src/edit/host/jobs.js +9 -3
- package/src/edit/host/layers.js +134 -0
- package/src/edit/host/main.js +17 -7
- package/src/edit/host/paths.js +34 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +494 -29
- package/src/edit/host/server.js +263 -19
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/loop/make.js +44 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +59 -0
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +138 -17
- package/src/edit/recipes/reference-look.js +29 -0
- package/src/edit/recipes/short-from-long.js +3 -3
- package/src/edit/recipes/sound.js +71 -0
- package/src/edit/runtime/cli.js +26 -5
- package/src/edit/runtime/fetch.js +4 -3
- package/src/edit/runtime/licences.js +7 -1
- package/src/explore.js +103 -0
- package/src/failure.js +1 -1
- package/src/gate-commands.js +114 -0
- package/src/gates/api.js +127 -0
- package/src/gates/commands.js +111 -0
- package/src/gates/detectors.js +370 -0
- package/src/gates/http.js +62 -0
- package/src/gates/index.js +196 -0
- package/src/gates/page.js +264 -0
- package/src/gates/sast.js +64 -0
- package/src/gates/stack.js +110 -0
- package/src/gates/tenant.js +162 -0
- package/src/gates/three.js +407 -0
- package/src/gates/ui.js +111 -0
- package/src/launch.js +15 -3
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +32 -0
- package/src/orchestra.js +43 -0
- package/src/outcomes.js +88 -0
- package/src/profiles.js +5 -0
- package/src/receipts.js +238 -0
- package/src/release.js +356 -0
- package/src/runstrip.js +122 -0
- package/src/stack.js +120 -0
- package/src/verify.js +67 -20
- package/studio/dist/fonts/fraunces.woff2 +0 -0
- package/studio/dist/fonts/geist.woff2 +0 -0
- package/studio/dist/fonts/jetbrains-mono.woff2 +0 -0
- package/studio/dist/studio.css +452 -3
- package/studio/dist/studio.js +3 -3
|
@@ -6,14 +6,18 @@
|
|
|
6
6
|
// engine renders, and a cold open must be a short stretch of one take.
|
|
7
7
|
|
|
8
8
|
import { FORMATS, GRADES } from "../recipes/reel.js"
|
|
9
|
-
import { MOODS } from "../engine/music-bed.js"
|
|
10
|
-
import { LOOKS } from "../engine/captions.js"
|
|
11
|
-
import {
|
|
9
|
+
import { ALL_MOODS, MOODS } from "../engine/music-bed.js"
|
|
10
|
+
import { ALL_LOOKS, LOOKS } from "../engine/captions.js"
|
|
11
|
+
import { STYLE_PACKS } from "../core/style-packs.js"
|
|
12
|
+
import { CUT_SOUNDS, INTRO_SOUNDS, SFX, SOUNDS } from "../engine/sfx.js"
|
|
12
13
|
import { paperEdit, shotDigest } from "../index/views.js"
|
|
13
14
|
import { planScenes, visualsIn } from "./beats.js"
|
|
15
|
+
import { graphicLine, graphicsIn, planGraphics } from "./graphics.js"
|
|
14
16
|
import { picturesRefused, planLookups } from "./lookups.js"
|
|
15
17
|
import { applyPlaybook, footageFacts, GENRES, PLAYBOOKS, playbookPrompt } from "./playbooks.js"
|
|
16
18
|
import { timesIn } from "./revise.js"
|
|
19
|
+
import { TRANSITIONS } from "../core/transitions.js"
|
|
20
|
+
import { fieldsOf, INTENT_PROMPT, intentSchema, readIntent, tidyIntent } from "./intent.js"
|
|
17
21
|
|
|
18
22
|
const FLICKS = 705_600_000
|
|
19
23
|
// The highlight colours a plan may choose; hex stays in code
|
|
@@ -51,6 +55,26 @@ export const PLAN_SCHEMA = {
|
|
|
51
55
|
additionalProperties: false,
|
|
52
56
|
}
|
|
53
57
|
|
|
58
|
+
// Transitions in the person's words: a kind, "no transitions", and whether every cut gets one
|
|
59
|
+
const TRANSITION_CUES = [
|
|
60
|
+
["slide", /\b(?:slide|push)\b/i],
|
|
61
|
+
["wipe", /\bwipe\b/i],
|
|
62
|
+
["zoom", /\bzoom\b/i],
|
|
63
|
+
["flash", /\bflash\b/i],
|
|
64
|
+
["dip", /\bdip\b|\bto black\b/i],
|
|
65
|
+
["fade", /\b(?:cross ?fade|dissolve|fade)\b/i],
|
|
66
|
+
]
|
|
67
|
+
/** @returns {{ transition?: string, transitionAll?: boolean }} empty when the words say nothing of transitions */
|
|
68
|
+
export function transitionIn(text) {
|
|
69
|
+
const said = String(text ?? "")
|
|
70
|
+
// The clause that speaks of transitions, so "zoom in on the price" elsewhere doesn't choose a zoom
|
|
71
|
+
const clause = said.split(/[.;!?\n]+/).find((part) => /\btransitions?\b|\bcross ?fade|\bdissolve/i.test(part))
|
|
72
|
+
if (!clause) return {}
|
|
73
|
+
if (/\b(?:no|without|skip|remove(?: the| all)?|drop the)\s+(?:any\s+)?transitions?\b/i.test(clause)) return { transition: "none" }
|
|
74
|
+
const kind = TRANSITION_CUES.find(([, cue]) => cue.test(clause))?.[0] ?? "fade"
|
|
75
|
+
return { transition: kind, ...(/\b(?:every|each|all)\s+(?:the\s+|of the\s+)?cuts?\b|\beverywhere\b/i.test(clause) ? { transitionAll: true } : {}) }
|
|
76
|
+
}
|
|
77
|
+
|
|
54
78
|
/** What the plan's settings ask of a make job, as the make route takes them. */
|
|
55
79
|
export function briefOf(settings = {}) {
|
|
56
80
|
return {
|
|
@@ -58,18 +82,25 @@ export function briefOf(settings = {}) {
|
|
|
58
82
|
...(settings.seconds ? { seconds: settings.seconds } : {}),
|
|
59
83
|
...(settings.captions && settings.captions !== "none" ? { captions: settings.captions } : {}),
|
|
60
84
|
...(settings.grade && settings.grade !== "natural" ? { grade: settings.grade } : {}),
|
|
61
|
-
...(settings.music && Object.hasOwn(
|
|
85
|
+
...(settings.music && Object.hasOwn(ALL_MOODS, settings.music) ? { music: `generated:${settings.music}` } : {}),
|
|
62
86
|
...(settings.cleanVoice ? { cleanVoice: true } : {}),
|
|
63
87
|
...(settings.hook ? { hook: settings.hook } : {}),
|
|
64
88
|
...(settings.coldOpen ? { coldOpen: settings.coldOpen } : {}),
|
|
65
|
-
...(settings.cutSound &&
|
|
66
|
-
...(settings.introSound &&
|
|
89
|
+
...(settings.cutSound && SOUNDS.includes(settings.cutSound) ? { cutSound: settings.cutSound } : {}),
|
|
90
|
+
...(settings.introSound && SOUNDS.includes(settings.introSound) ? { introSound: settings.introSound } : {}),
|
|
91
|
+
// TP10: the sound arranged to the cut, present only when a plan made with editing.craft set it
|
|
92
|
+
...(settings.arrange ? { arrange: true } : {}),
|
|
93
|
+
...(settings.ambience ? { ambience: true } : {}),
|
|
94
|
+
...(settings.splits ? { splits: true } : {}),
|
|
95
|
+
...(settings.beatJoins ? { beatJoins: true } : {}),
|
|
67
96
|
...(Number.isInteger(settings.punches) ? { punches: settings.punches } : {}),
|
|
68
97
|
...(settings.angles ? { angles: true } : {}),
|
|
69
98
|
...(settings.broll === "own" ? { broll: "own" } : {}),
|
|
70
99
|
...(settings.titles ? { titles: true } : {}),
|
|
71
100
|
...(settings.ramps ? { ramps: true } : {}),
|
|
72
101
|
...(Array.isArray(settings.cuts) && settings.cuts.length ? { cuts: mergeCuts(settings.cuts) } : {}),
|
|
102
|
+
// TP7: a style pack, present only when a plan made with editing.typeKit chose one
|
|
103
|
+
...(typeof settings.stylePack === "string" && Object.hasOwn(STYLE_PACKS, settings.stylePack) ? { stylePack: settings.stylePack } : {}),
|
|
73
104
|
...(typeof settings.song === "string" ? { music: settings.song } : {}),
|
|
74
105
|
...(settings.montage ? { montage: true } : {}),
|
|
75
106
|
...(settings.multicam ? { multicam: settings.multicam } : {}),
|
|
@@ -78,6 +109,10 @@ export function briefOf(settings = {}) {
|
|
|
78
109
|
...(settings.terms?.length ? { terms: settings.terms.map(({ at, id, term }) => ({ at, id, term })) } : {}),
|
|
79
110
|
...(Number.isInteger(settings.soundEvery) && settings.soundEvery > 1 ? { soundEvery: settings.soundEvery } : {}),
|
|
80
111
|
...(Array.isArray(settings.scenes) && settings.scenes.length ? { scenes: settings.scenes, sceneSound: settings.sceneSound !== false } : {}),
|
|
112
|
+
...(Array.isArray(settings.graphics) && settings.graphics.length ? { graphics: settings.graphics } : {}),
|
|
113
|
+
...(Object.hasOwn(TRANSITIONS, settings.transition ?? "") ? { transition: settings.transition, ...(settings.transitionAll ? { transitionAll: true } : {}) } : {}),
|
|
114
|
+
// The film's order (TP2), present only when one was decided
|
|
115
|
+
...(settings.assembly?.parts?.length ? { assembly: settings.assembly } : {}),
|
|
81
116
|
}
|
|
82
117
|
}
|
|
83
118
|
|
|
@@ -255,14 +290,17 @@ export function planProblems(settings, index) {
|
|
|
255
290
|
|
|
256
291
|
/**
|
|
257
292
|
* @param {{ ask: Function, project: object, index: object, text: string, history?: object[], previous?: object, references?: { name: string, lines: string[] }[], choices?: object, visuals?: boolean, playbooks?: boolean, signal?: AbortSignal }} input
|
|
258
|
-
* visuals, playbooks: the server's editing.visuals and editing.
|
|
293
|
+
* visuals, playbooks, motion: the server's editing.visuals, editing.playbooks and editing.motion; off, this plan is what it always was
|
|
259
294
|
* lookups: { search, define, keep } with editing.mediaSearch on; null, no search word leaves the computer
|
|
295
|
+
* intent: editing.intent (TP4): the same call also returns what the person asked for, each with its words,
|
|
296
|
+
* checked by code; off, the schema, the prompt and the plan are the objects they were (ET-NL-REG-01)
|
|
260
297
|
* @returns {Promise<{ say: string, steps: string[], settings: object, source: string, reason?: string }>}
|
|
261
298
|
*/
|
|
262
|
-
export async function planCut({ ask, project, index, text, history = [], previous = null, references = [], choices = {}, visuals = false, playbooks = false, lookups = null, signal }) {
|
|
299
|
+
export async function planCut({ ask, project, index, text, history = [], previous = null, references = [], choices = {}, visuals = false, playbooks = false, motion = false, lookups = null, pointed = "", intent = false, craft = false, typeKit = false, signal }) {
|
|
263
300
|
const assets = project.assets.filter((a) => a.kind === "video" || a.kind === "audio").map((a) => a.id)
|
|
264
301
|
const refs = references.length ? `References the person added, measured by code:\n${references.map((r) => `- ${r.name}: ${r.lines.join("; ")}`).join("\n")}` : "No references added."
|
|
265
|
-
|
|
302
|
+
// pointed: the clips the person mentioned (mentions.js), fenced as data; empty, the view is what it was
|
|
303
|
+
const view = [paperEdit(index, { assets }), shotDigest(index, { assets }), refs, `The person's current choices in the Studio: ${JSON.stringify(choices)}`, ...(pointed ? [pointed] : [])].join("\n\n")
|
|
266
304
|
const asked = formatAsked(text, history, previous)
|
|
267
305
|
// Trims are the person's, read by code from their words (this message and earlier ones) and kept through revisions
|
|
268
306
|
const take = project.assets.find((a) => a.kind === "video" && (index.words ?? []).some((w) => w.asset === a.id)) ?? project.assets.find((a) => a.kind === "video")
|
|
@@ -273,10 +311,11 @@ export async function planCut({ ask, project, index, text, history = [], previou
|
|
|
273
311
|
// The scenes first, so the pitch can speak for them; each is checked by code, and the person swaps them on the card
|
|
274
312
|
const planned = visuals && take ? await planScenes({ ask, index, asset: take.id, text, history, previous, cuts, signal }) : null
|
|
275
313
|
const scenes = planned?.scenes ?? []
|
|
276
|
-
const { scenes: _shownOnTheCard, ...previousSettings } = previous?.settings ?? {}
|
|
314
|
+
const { scenes: _shownOnTheCard, graphics: _alsoOnTheCard, ...previousSettings } = previous?.settings ?? {}
|
|
277
315
|
const earlier = history.length ? `Earlier in this chat:\n${history.map((h) => `${h.who === "you" ? "Person" : "Kriya"}: ${JSON.stringify(h.text)}`).join("\n")}\n\n` : ""
|
|
278
316
|
const request = [
|
|
279
317
|
`${earlier}The person says (their own words, trusted): ${JSON.stringify(String(text).slice(0, 2000))}`,
|
|
318
|
+
pointed ? "A place like ⟦1⟧ in their words is a clip they pointed at; the list above says which clip each is. Code puts the files in the order they asked, and shows it on the card: don't choose an order yourself." : "",
|
|
280
319
|
cuts.length ? `The person asked to trim ${cuts.map((c) => `${at(c.from)} to ${at(c.to)}`).join(", ")} of the take (${take.id}); code cuts exactly that, between words. Plan around it: no hook or cold open inside a trimmed stretch, and say the trim in your pitch.` : "",
|
|
281
320
|
asked ? `The person wants the ${asked} format: settings.format is "${asked}", and your pitch says ${asked}.` : "",
|
|
282
321
|
previous ? `Your previous plan, which they want changed: ${JSON.stringify(previous.settings ? { ...previous, settings: previousSettings } : previous).slice(0, 3000)}. Revise it by what they say now; keep what they didn't ask to change.` : "",
|
|
@@ -295,7 +334,20 @@ export async function planCut({ ask, project, index, text, history = [], previou
|
|
|
295
334
|
})
|
|
296
335
|
// With playbooks the answer also names the genre; off, the schema is the same object as before
|
|
297
336
|
const schema = playbooks ? { ...PLAN_SCHEMA, properties: { ...PLAN_SCHEMA.properties, genre: { type: "string", enum: GENRES }, settings: { ...PLAN_SCHEMA.properties.settings, properties: { ...PLAN_SCHEMA.properties.settings.properties, captions: { type: "string", enum: ["none", ...Object.keys(LOOKS)] }, accent: { type: "string", enum: Object.keys(ACCENTS) }, song: { type: "string", maxLength: 64 } } } }, required: [...PLAN_SCHEMA.required, "genre"] } : PLAN_SCHEMA
|
|
298
|
-
|
|
337
|
+
// With editing.motion the Director may also choose a transition; off, the schema is the object it was
|
|
338
|
+
const asked_ = motion ? { ...schema, properties: { ...schema.properties, settings: { ...schema.properties.settings, properties: { ...schema.properties.settings.properties, transition: { type: "string", enum: ["none", ...Object.keys(TRANSITIONS)] } } } } } : schema
|
|
339
|
+
// With editing.craft (TP10) the plan may also choose from more moods and sounds and arrange the sound to the cut
|
|
340
|
+
const crafted = craft ? { ...asked_, properties: { ...asked_.properties, settings: { ...asked_.properties.settings, properties: { ...asked_.properties.settings.properties, music: { type: "string", enum: ["none", "reference", ...Object.keys(ALL_MOODS)] }, cutSound: { type: "string", enum: ["none", ...CUT_SOUNDS] }, introSound: { type: "string", enum: ["none", ...INTRO_SOUNDS] }, arrange: { type: "boolean" }, ambience: { type: "boolean" }, splits: { type: "boolean" }, beatJoins: { type: "boolean" } } } } } : asked_
|
|
341
|
+
// With editing.typeKit (TP7) the plan may also choose one of the fourteen caption looks and a style pack; off, the object it was
|
|
342
|
+
const typed = typeKit ? { ...crafted, properties: { ...crafted.properties, settings: { ...crafted.properties.settings, properties: { ...crafted.properties.settings.properties, captions: { type: "string", enum: ["none", ...Object.keys(ALL_LOOKS)] }, stylePack: { type: "string", enum: ["none", ...Object.keys(STYLE_PACKS)] } } } } } : crafted
|
|
343
|
+
// With editing.intent the same call reads what was asked, field by field (no second call, EH-64); off, the objects they were
|
|
344
|
+
// The settings a person can ask for; a playbook's accent colour is the Director's, not a request
|
|
345
|
+
const fields = intent ? Object.fromEntries(Object.entries(fieldsOf(typed.properties.settings)).filter(([key]) => key !== "accent")) : null
|
|
346
|
+
const framed = intent ? { ...typed, properties: { ...typed.properties, intent: intentSchema(fields) }, required: [...typed.required, "intent"] } : typed
|
|
347
|
+
const told = motion ? `${request}\nYou may also set \`transition\` (${Object.keys(TRANSITIONS).join(", ")}): how the picture arrives where the story changes moment, such as out of a cold open or into a reordered line. Code puts it only at those joins, never on a filler cut. Choose none unless it suits the video.` : request
|
|
348
|
+
const sounded = craft ? `${told}\nYou may also arrange the sound to the cut: \`arrange\` (an accent in the bed's key on every join; with a music mood), \`ambience\` (a room tone from the take's own quiet), \`splits\` (J and L cuts at the talking joins) and \`beatJoins\` (B-roll on the music's beat). Use them when the person asks for better sound or sound design.` : told
|
|
349
|
+
const styled = typeKit ? `${sounded}\nYou may also set \`stylePack\`, one name for a whole look (${Object.entries(STYLE_PACKS).map(([id, pack]) => `${id}: ${pack.does}`).join("; ")}), and \`captions\` to any of ${Object.keys(ALL_LOOKS).join(", ")}. Choose a pack only when the person asks for a style or the video plainly wants one; none keeps the film's look.` : sounded
|
|
350
|
+
const answer = await ask({ task: "plan", tier: "budget", schema: framed, view, request: intent ? `${styled}\n${INTENT_PROMPT}` : styled, maxOutput: intent ? 3500 : 2500, check, fallback, signal, priority: 0, ...(intent ? { clean: (value) => (value && typeof value === "object" ? { ...value, intent: tidyIntent(value.intent, fields) } : value) } : {}) })
|
|
299
351
|
const clean = (value) => String(value ?? "").replace(/[\u0000-\u001f<>]/g, " ").trim()
|
|
300
352
|
// The frame is always set, and set by what the person said, never left to a default
|
|
301
353
|
// The fallback plan keeps the person's choices: no model read the speech, so no genre was found
|
|
@@ -314,6 +366,11 @@ export async function planCut({ ask, project, index, text, history = [], previou
|
|
|
314
366
|
if (key === "coldOpen") value ? (promised.coldOpen = true) : (settings.coldOpen = null)
|
|
315
367
|
else settings[key] = value
|
|
316
368
|
}
|
|
369
|
+
// The intent frame: kept fields where their words are in this message, code's reading over the model's, answers over both
|
|
370
|
+
const understood = intent
|
|
371
|
+
? readIntent(answer.source === "default" ? undefined : answer.value.intent, { message: text, fields, code: { ...Object.fromEntries(Object.entries(person).filter(([key]) => key !== "coldOpen" && key !== "format")), ...(asked ? { format: asked } : {}) }, answers: previous?.intent?.answers ?? {} })
|
|
372
|
+
: null
|
|
373
|
+
if (understood) for (const [key, value] of Object.entries(understood.apply)) settings[key] = value
|
|
317
374
|
if (cuts.length) settings.cuts = cuts
|
|
318
375
|
else delete settings.cuts
|
|
319
376
|
if (promised.coldOpen && !settings.coldOpen && take) settings.coldOpen = pickColdOpen(index, take.id, cuts)
|
|
@@ -361,5 +418,25 @@ export async function planCut({ ask, project, index, text, history = [], previou
|
|
|
361
418
|
if (visualsIn(text)) steps.push(`No animated scene this time${why ? `: ${why}` : ": nothing in the speech can be drawn from the speaker's own words"}.`)
|
|
362
419
|
delete settings.scenes
|
|
363
420
|
}
|
|
364
|
-
|
|
421
|
+
// Transitions: the person's words outrank the Director's choice; a revision that says nothing keeps what was approved
|
|
422
|
+
const transitionSaid = motion ? [...history.filter((h) => h.who === "you").map((h) => h.text), text].map(transitionIn).reduce((all, one) => ({ ...all, ...one }), {}) : {}
|
|
423
|
+
const kept_ = motion && previous?.settings?.transition && Object.hasOwn(TRANSITIONS, previous.settings.transition) ? { transition: previous.settings.transition, transitionAll: !!previous.settings.transitionAll } : {}
|
|
424
|
+
const chosen = { ...kept_, ...(Object.hasOwn(TRANSITIONS, settings.transition ?? "") ? { transition: settings.transition } : {}), ...transitionSaid }
|
|
425
|
+
delete settings.transition
|
|
426
|
+
delete settings.transitionAll
|
|
427
|
+
if (motion && Object.hasOwn(TRANSITIONS, chosen.transition ?? "")) {
|
|
428
|
+
settings.transition = chosen.transition
|
|
429
|
+
if (chosen.transitionAll) settings.transitionAll = true
|
|
430
|
+
}
|
|
431
|
+
// Motion graphics from the kit, after the scenes so none is planned under one; each is checked by code
|
|
432
|
+
delete settings.graphics
|
|
433
|
+
if (motion && take) {
|
|
434
|
+
const planned = await planGraphics({ ask, index, asset: take.id, text, history, previous, cuts, scenes: sceneList, ...(typeKit ? { typeKit } : {}), signal })
|
|
435
|
+
if (planned.graphics.length) {
|
|
436
|
+
settings.graphics = planned.graphics
|
|
437
|
+
steps.unshift(`Add ${planned.graphics.length} motion graphic${planned.graphics.length === 1 ? "" : "s"}: ${planned.graphics.map(graphicLine).join("; ")}. You can restyle or remove each below.`.slice(0, 240))
|
|
438
|
+
} else if (graphicsIn(text) === "on") steps.push(`No motion graphics this time${planned.dropped[0] ? `: ${planned.dropped[0].reason}` : ": the words for one must be the speaker's or yours, so say what a title or name strap should read"}.`.slice(0, 240))
|
|
439
|
+
}
|
|
440
|
+
const frame = understood ? { intent: { understood: understood.understood, cannot: understood.cannot, questions: understood.questions, defaulted: understood.defaulted, answers: { ...(previous?.intent?.answers ?? {}) } } } : {}
|
|
441
|
+
return { say: clean(answer.value.say).slice(0, 900), steps: steps.slice(0, 13), settings, source: answer.source, ...(genre ? { genreLabel: PLAYBOOKS[genre].label } : {}), ...(answer.reason ? { reason: answer.reason } : {}), ...frame }
|
|
365
442
|
}
|
|
@@ -5,7 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import { apply } from "../core/ops.js"
|
|
7
7
|
import { solve } from "../core/solver.js"
|
|
8
|
+
import { ALL_GRAPHIC_KINDS, cleanGraphic, GRAPHIC_BLOCK, GRAPHIC_KINDS, GRAPHIC_VERSION, graphicLength, STEP_MAX, STEPS_MAX, SUBTITLE_MAX, TEXT_MAX } from "../engine/graphics.js"
|
|
9
|
+
import { ALL_LOOKS } from "../engine/captions.js"
|
|
8
10
|
import { paperEdit, shotDigest } from "../index/views.js"
|
|
11
|
+
import { TRANSITION_LABELS, transitionLength, TRANSITIONS } from "../core/transitions.js"
|
|
12
|
+
import { brandIn, graphicProblems } from "./graphics.js"
|
|
13
|
+
import { withoutPlaces } from "./mentions.js"
|
|
14
|
+
import { grounded, tidyIntent } from "./intent.js"
|
|
15
|
+
import { EFFECTS as FX, MOVES } from "../core/effects.js"
|
|
9
16
|
|
|
10
17
|
const FLICKS = 705_600_000
|
|
11
18
|
|
|
@@ -97,6 +104,114 @@ export const OPS_SCHEMA = {
|
|
|
97
104
|
additionalProperties: false,
|
|
98
105
|
}
|
|
99
106
|
|
|
107
|
+
// With editing.motion on, chat can also put a kit graphic on screen (MOTION_GRAPHICS.md). Off,
|
|
108
|
+
// the console's schema is the same object as before
|
|
109
|
+
const ITEMS = OPS_SCHEMA.properties.ops.items
|
|
110
|
+
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 } } } } } }
|
|
111
|
+
export const consoleSchema = (motion) => (motion ? MOTION_SCHEMA : OPS_SCHEMA)
|
|
112
|
+
|
|
113
|
+
/** With editing.craft on (TP5), chat may also add a registry effect or a named move; off, `base` is returned as it is. */
|
|
114
|
+
export function craftSchema(base, craft) {
|
|
115
|
+
if (!craft) return base
|
|
116
|
+
const items = base.properties.ops.items
|
|
117
|
+
return { ...base, properties: { ...base.properties, ops: { ...base.properties.ops, items: { ...items, properties: { ...items.properties, op: { type: "string", enum: [...items.properties.op.enum, "add_effect", "add_adjustment", "remove_effect"] }, effect: { type: "string", enum: Object.keys(FX) }, params: { type: "object", additionalProperties: { type: "number" } }, move: { type: "string", enum: Object.keys(MOVES) } } } } } }
|
|
118
|
+
}
|
|
119
|
+
/** With editing.typeKit on (TP7), chat may also use the fourteen caption looks and motion kit 2; off, `base` is returned as it is. */
|
|
120
|
+
export function typeKitSchema(base, typeKit) {
|
|
121
|
+
if (!typeKit) return base
|
|
122
|
+
const items = base.properties.ops.items
|
|
123
|
+
const kinds = items.properties.kind ? { kind: { type: "string", enum: Object.keys(ALL_GRAPHIC_KINDS) }, steps: { type: "array", maxItems: STEPS_MAX, items: { type: "string", maxLength: STEP_MAX } } } : {}
|
|
124
|
+
return { ...base, properties: { ...base.properties, ops: { ...base.properties.ops, items: { ...items, properties: { ...items.properties, look: { type: "string", enum: Object.keys(ALL_LOOKS) }, ...kinds } } } } }
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* TP9 (CRAFT_UPGRADE §7): with editing.customMotion on, chat may ask for a custom animation
|
|
128
|
+
* (`custom_motion`, written afterwards by code's own slot, director/custom-motion.js); with a box drawn
|
|
129
|
+
* on the frame, it may act on it (`use_mark`). Neither, and `base` is returned as it is.
|
|
130
|
+
*/
|
|
131
|
+
export function pointingSchema(base, { customMotion = false, mark = false } = {}) {
|
|
132
|
+
if (!customMotion && !mark) return base
|
|
133
|
+
const items = base.properties.ops.items
|
|
134
|
+
const ops = [...items.properties.op.enum, ...(customMotion ? ["custom_motion"] : []), ...(mark ? ["use_mark"] : [])]
|
|
135
|
+
return { ...base, properties: { ...base.properties, ops: { ...base.properties.ops, items: { ...items, properties: { ...items.properties, op: { type: "string", enum: ops }, ...(customMotion ? { reuse: ID } : {}), ...(mark ? { use: { type: "string", enum: MARK_USES } } : {}) } } } } }
|
|
136
|
+
}
|
|
137
|
+
export const MARK_USES = ["callout", "blur", "zoom", "mask"]
|
|
138
|
+
export const CUSTOM_MOTION_PROMPT = "Only for an animation that no kit graphic and no operation above can make (a logo that spins, a shape that draws itself, an animated diagram), custom_motion with text: what to animate, in the person's words, at (a word anchor) and duration only if they said how long. Code has it written, checks it and shows it to the person to approve. To place a saved custom animation again, custom_motion with reuse: its clip id, and at. At most one custom_motion."
|
|
139
|
+
const MARK_KINDS = { box: "box", ring: "ring", arrow: "arrow" }
|
|
140
|
+
|
|
141
|
+
/** Where a drawn box is, in words a model reads (code alone knows its numbers). */
|
|
142
|
+
export function markView(mark) {
|
|
143
|
+
const across = mark.x + mark.w / 2 < 333 ? "left" : mark.x + mark.w / 2 > 667 ? "right" : "centre"
|
|
144
|
+
const down = mark.y + mark.h / 2 < 333 ? "top" : mark.y + mark.h / 2 > 667 ? "bottom" : "middle"
|
|
145
|
+
const share = Math.round((mark.w * mark.h) / 10_000)
|
|
146
|
+
return `The person drew a ${MARK_KINDS[mark.kind] ?? "box"} on the frame at ${clock(mark.at)}, in the ${down} ${across}, about ${share}% of the frame. "This", "here", "that" or "it" means what they drew. To act on it, use_mark with use: callout (mark it; an optional short label in text, the speaker's or the person's own words), blur (blur what is inside it), zoom (zoom in on it) or mask (darken everything else); duration in flicks only if they said how long. Code places it exactly where they drew: never give coordinates.`
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* `use_mark` as Edit Core operations, placed by code at the drawn box (TP9): a callout round it, a blur
|
|
151
|
+
* or a mask in it over the shot (from the moment drawn to the end of its piece), or a punch-in centred on
|
|
152
|
+
* it. The model chose what to do; the numbers are the person's drawing.
|
|
153
|
+
* @returns {{ ops: object[], problems: string[] }}
|
|
154
|
+
*/
|
|
155
|
+
export function expandMark(ops, { mark, project, index, person }) {
|
|
156
|
+
const problems = []
|
|
157
|
+
if (!ops.some((op) => op?.op === "use_mark")) return { ops, problems }
|
|
158
|
+
const { picture, duration: length } = solve(project, index)
|
|
159
|
+
const piece = picture.find((p) => mark.at >= p.at && mark.at < p.end)
|
|
160
|
+
const spoken = (index.words ?? []).map((w) => w.text).join(" ")
|
|
161
|
+
const region = { x: mark.x, y: mark.y, w: mark.w, h: mark.h }
|
|
162
|
+
// How long: what was asked, else the rest of the shot (capped), never past the cut's end; half a second at least
|
|
163
|
+
const span = (op, fallback) => Math.max(FLICKS / 2, Math.min(Number.isInteger(op.duration) ? op.duration : fallback, length - mark.at))
|
|
164
|
+
const rest = piece ? piece.end - mark.at : 3 * FLICKS
|
|
165
|
+
const out = ops.map((op, i) => {
|
|
166
|
+
if (op?.op !== "use_mark") return op
|
|
167
|
+
if (!MARK_USES.includes(op.use)) return problems.push(`operation ${i + 1}: use is one of ${MARK_USES.join(", ")}`), op
|
|
168
|
+
if (mark.at >= length) return problems.push(`operation ${i + 1}: the box was drawn past the end of the cut`), op
|
|
169
|
+
if (op.use === "callout") {
|
|
170
|
+
const graphic = cleanGraphic({ kind: "callout", style: MARK_KINDS[mark.kind] ?? "box", text: op.text ?? "", mark: region, ...brandIn(person) }, ALL_GRAPHIC_KINDS)
|
|
171
|
+
if (!graphic) return problems.push(`operation ${i + 1}: that label can't be a callout's`), op
|
|
172
|
+
const said = graphic.text ? graphicProblems(graphic, { spoken, near: spoken, person }) : []
|
|
173
|
+
if (said.length) return problems.push(`operation ${i + 1}: ${said[0]}; a callout's label is the speaker's or the person's own words`), op
|
|
174
|
+
return { op: "add_motion", block: GRAPHIC_BLOCK, version: GRAPHIC_VERSION, variables: graphic, at: mark.at, duration: span(op, 3 * FLICKS) }
|
|
175
|
+
}
|
|
176
|
+
if (op.use === "zoom") {
|
|
177
|
+
// Fit the drawn box in the frame, a little room round it, between 1.1× and 3×
|
|
178
|
+
const scale = Math.round(Math.min(3, Math.max(1.1, 0.9 * Math.min(1000 / mark.w, 1000 / mark.h))) * 100) / 100
|
|
179
|
+
return { op: "punch_in", at: mark.at, duration: span(op, Math.min(rest, 3 * FLICKS)), scale, ease: "smooth", x: Math.round(mark.x + mark.w / 2), y: Math.round(mark.y + mark.h / 2) }
|
|
180
|
+
}
|
|
181
|
+
const effect = op.use === "blur" ? { effect: "blur", params: { amount: 20 } } : { effect: "mask" }
|
|
182
|
+
return { op: "add_adjustment", at: mark.at, duration: span(op, Math.min(rest, 30 * FLICKS)), ...effect, region }
|
|
183
|
+
})
|
|
184
|
+
return { ops: out, problems }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export const TYPE_KIT_PROMPT = `Caption looks for caption_style: ${Object.keys(ALL_LOOKS).join(", ")}. With add_graphic you may also use ${Object.entries(ALL_GRAPHIC_KINDS).filter(([id]) => !GRAPHIC_KINDS[id]).map(([id, kind]) => `${id}: ${kind.label.toLowerCase()}`).join("; ")}; a list's lines go in \`steps\`, each the speaker's own words; a handle or call to action only in words the person typed.`
|
|
188
|
+
|
|
189
|
+
export const CRAFT_PROMPT = `To put an effect on a clip, add_effect with clip, effect (${Object.entries(FX).map(([id, row]) => `${id}: ${row.label.toLowerCase()}`).join("; ")}) and only the values the person asks for in params; over a stretch of the cut, add_adjustment with at (a word anchor), until or duration, and effect; remove_effect with clip and effect. For a change over time, pick a named move instead of numbers: ${Object.entries(MOVES).map(([id, m]) => `${id} (${m.effect}: ${m.label})`).join("; ")}. Add an effect only when the person asks for it.`
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* `add_graphic` as the engine's own operation: the graphic cleaned, its words held to the
|
|
193
|
+
* speaker's and the person's, its length set by code. Every other operation passes through.
|
|
194
|
+
* @param {object[]} ops
|
|
195
|
+
* @param {{ index: object, person: string }} context person: the person's own messages
|
|
196
|
+
* @returns {{ ops: object[], problems: string[] }}
|
|
197
|
+
*/
|
|
198
|
+
export function expandGraphics(ops, { index, person, kinds = GRAPHIC_KINDS }) {
|
|
199
|
+
const problems = []
|
|
200
|
+
const spoken = (index.words ?? []).map((w) => w.text).join(" ")
|
|
201
|
+
const out = ops.map((op, i) => {
|
|
202
|
+
// A transition's length is code's: the default, or what was asked, inside the allowed range
|
|
203
|
+
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)
|
|
204
|
+
if (op?.op !== "add_graphic") return op
|
|
205
|
+
const graphic = cleanGraphic({ ...op, ...brandIn(person), at: undefined }, kinds)
|
|
206
|
+
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
|
|
207
|
+
if (op.at === undefined) return problems.push(`operation ${i + 1}: add_graphic needs \`at\`, a word anchor or a clip edge`), op
|
|
208
|
+
const said = graphicProblems(graphic, { spoken, near: spoken, person })
|
|
209
|
+
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
|
|
210
|
+
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) }
|
|
211
|
+
})
|
|
212
|
+
return { ops: out, problems }
|
|
213
|
+
}
|
|
214
|
+
|
|
100
215
|
/**
|
|
101
216
|
* What models often send that means nothing: every optional field present as null,
|
|
102
217
|
* and empty lists or no `ops` at all. Tidied before the schema, never invented.
|
|
@@ -166,9 +281,14 @@ export function describe(op, index) {
|
|
|
166
281
|
return `Changed caption ${op.caption} to "${op.text}"`
|
|
167
282
|
case "caption_emphasis":
|
|
168
283
|
return `Emphasised "${words.get(op.word)?.text ?? op.word}" in caption ${op.caption}`
|
|
284
|
+
case "transition":
|
|
285
|
+
return `Added a ${(TRANSITION_LABELS[op.kind] ?? op.kind).toLowerCase()} transition into ${op.clip}`
|
|
169
286
|
case "add_title":
|
|
170
287
|
return `Added the title "${op.text}" at ${place(op.at)}`
|
|
171
288
|
case "add_motion":
|
|
289
|
+
if (op.block === "custom") return `Added a custom animation${op.variables?.name ? ` "${op.variables.name}"` : ""} at ${place(op.at)}`
|
|
290
|
+
if (op.block === GRAPHIC_BLOCK && op.variables?.mark) return `Marked what you drew with a ${op.variables.style ?? "box"} callout${op.variables.text ? `, "${op.variables.text}"` : ""}, at ${place(op.at)} for ${seconds(op.duration ?? 0)}`
|
|
291
|
+
if (op.block === GRAPHIC_BLOCK) return `Added ${/^[aeiou]/i.test(ALL_GRAPHIC_KINDS[op.variables?.kind]?.label ?? "g") ? "an" : "a"} ${(ALL_GRAPHIC_KINDS[op.variables?.kind]?.label ?? "graphic").toLowerCase()} "${op.variables?.text ?? ""}"${op.variables?.subtitle ? `, "${op.variables.subtitle}"` : ""} at ${place(op.at)}`
|
|
172
292
|
return op.block === "scene" ? `Added an animated ${op.variables?.kind ?? ""} scene, "${op.variables?.text ?? ""}", at ${place(op.at)}` : op.op
|
|
173
293
|
case "grade":
|
|
174
294
|
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}` : ""}`
|
|
@@ -184,6 +304,10 @@ export function describe(op, index) {
|
|
|
184
304
|
return `Cleaned the background noise out of ${op.clip}'s voice`
|
|
185
305
|
case "set_level":
|
|
186
306
|
return `Set ${op.clip} to ${op.db} dB`
|
|
307
|
+
case "add_adjustment":
|
|
308
|
+
// TP9: only a drawn region has words here; any other adjustment reads as it always did
|
|
309
|
+
if (op.region) return `${op.effect === "mask" ? "Darkened everything but" : "Blurred"} what you drew, from ${place(op.at)} for ${seconds(op.duration ?? 0)}`
|
|
310
|
+
return op.op
|
|
187
311
|
case "add_deliverable":
|
|
188
312
|
return `Set up the export: ${op.size?.width ?? "?"}×${op.size?.height ?? "?"}${op.loudness ? `, mastered to ${op.loudness.lufs} LUFS` : ""}${op.burnCaptions ? ", captions burned in" : ""}`
|
|
189
313
|
default:
|
|
@@ -255,7 +379,8 @@ const UNIT = "(?:s|sec\\w*|se?c?o?n?d?s?\\b)(?![a-z])"
|
|
|
255
379
|
* @returns {{ at: number, to?: number }[]} in flicks
|
|
256
380
|
*/
|
|
257
381
|
export function timesIn(text, { duration = null } = {}) {
|
|
258
|
-
|
|
382
|
+
// A mention's place (⟦1⟧, TP1) is never a time; without one this is the text as it was
|
|
383
|
+
const said = withoutPlaces(text)
|
|
259
384
|
// Relative stretches first: "the first 5 seconds", "the last 5 s" (needs the cut's length)
|
|
260
385
|
const relative = []
|
|
261
386
|
for (const m of said.matchAll(new RegExp(`\\b(first|last|final|opening)\\s+(\\d+(?:\\.\\d+)?)\\s*${UNIT}`, "gi"))) {
|
|
@@ -337,34 +462,70 @@ export function timesView(text, project, index) {
|
|
|
337
462
|
* @param {{ ask: ReturnType<import("./ask.js").createAsk>, project: object, index: object, text: string, selection?: object, signal?: AbortSignal }} input
|
|
338
463
|
* @returns {Promise<{ ops: object[], changes: string[], project: object | null, source: string, reason?: string, calls: number }>}
|
|
339
464
|
*/
|
|
340
|
-
export async function revise({ ask, project, index, text, selection, history = [], signal }) {
|
|
465
|
+
export async function revise({ ask, project, index, text, selection, history = [], motion = false, pointed = "", intent = false, craft = false, typeKit = false, customMotion = false, mark = null, customBlocks = [], signal }) {
|
|
341
466
|
const assets = project.assets.map((a) => a.id)
|
|
342
467
|
// A marked range reads like a typed one: code says what it points at
|
|
343
468
|
const marked = Number.isInteger(selection?.from) && Number.isInteger(selection?.to) ? ` from ${clock(selection.from)} to ${clock(selection.to)}` : ""
|
|
344
469
|
const times = timesView(`${text}${marked}`, project, index)
|
|
345
470
|
const bin = `Footage in the project: ${project.assets.filter((a) => ["video", "audio"].includes(a.kind)).map((a) => `${a.id} (${a.kind}, ${seconds(a.facts.duration ?? 0)})`).join(", ")}`
|
|
346
|
-
|
|
471
|
+
// pointed: the clips the person mentioned (mentions.js), fenced as data; empty, the view is what it was
|
|
472
|
+
// TP9: a drawn box and the saved custom animations, only when there are any; else the view is what it was
|
|
473
|
+
const saved = customMotion && customBlocks.length ? `Saved custom animations: ${customBlocks.map((b) => `${b.clip}${b.name ? ` ${JSON.stringify(b.name)}` : ""}`).join(", ")}` : ""
|
|
474
|
+
const view = [paperEdit(index, { assets }), shotDigest(index, { assets }), clipsView(project, index), bin, selectionText(selection, index), times, pointed, saved, mark ? markView(mark) : ""].filter(Boolean).join("\n\n")
|
|
347
475
|
// The last turns of this chat, so "shorter" or "no, the other one" mean something. The
|
|
348
476
|
// person's lines are theirs; Kriya's are what it said before, not instructions
|
|
349
477
|
const earlier = history.length ? `Earlier in this chat:\n${history.map((h) => `${h.who === "you" ? "Person" : "Kriya"}: ${JSON.stringify(h.text)}`).join("\n")}\n\n` : ""
|
|
350
478
|
const request = [
|
|
351
479
|
`${earlier}The person asks (their own words, trusted): ${JSON.stringify(String(text).slice(0, 2000))}`,
|
|
480
|
+
...(pointed ? ["A place like ⟦1⟧ in their words is a clip they pointed at; the list above says which asset each is. Use that asset id."] : []),
|
|
352
481
|
"Answer with JSON only. Put in `ops` the operations that do exactly what they ask, and nothing else.",
|
|
353
482
|
"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.",
|
|
483
|
+
...(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
484
|
"Put one plain sentence in `say`: what you changed, or the answer if they asked a question.",
|
|
355
485
|
"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
486
|
"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.",
|
|
357
487
|
'If none of these can do it, answer {"ops": []}.',
|
|
488
|
+
// editing.intent (TP4): nothing they asked is lost; off, the request is the text it was
|
|
489
|
+
...(craft ? [CRAFT_PROMPT] : []),
|
|
490
|
+
...(typeKit ? [TYPE_KIT_PROMPT] : []),
|
|
491
|
+
...(customMotion ? [CUSTOM_MOTION_PROMPT] : []),
|
|
492
|
+
...(intent ? ["Also put in `cannot` every piece of their request these operations can't do: their exact words as `evidence`, copied as written, and the nearest thing you can do as `nearest` if there is one. Empty when everything is done."] : []),
|
|
358
493
|
].join("\n")
|
|
359
494
|
const words = new Map((index.words ?? []).map((w) => [w.id, w]))
|
|
360
495
|
// Operations must apply; a correction on an unknown word is only dropped, never worth a second call
|
|
361
|
-
const
|
|
362
|
-
|
|
496
|
+
const person = [...history.filter((h) => h.who === "you").map((h) => h.text), text].join("\n")
|
|
497
|
+
// TP9: custom_motion is answered afterwards by its own slot, so it is set aside here, checked for shape only
|
|
498
|
+
const customClips = new Set(customBlocks.map((b) => b.clip))
|
|
499
|
+
const customProblems = (ops) =>
|
|
500
|
+
ops.flatMap((op, i) => {
|
|
501
|
+
if (op?.op !== "custom_motion") return []
|
|
502
|
+
if (!customMotion) return [`operation ${i + 1}: custom_motion isn't available`]
|
|
503
|
+
if (op.at === undefined) return [`operation ${i + 1}: custom_motion needs \`at\`, a word anchor or a clip edge`]
|
|
504
|
+
if (op.reuse !== undefined) return customClips.has(op.reuse) ? [] : [`operation ${i + 1}: ${op.reuse} isn't a saved custom animation`]
|
|
505
|
+
return typeof op.text === "string" && op.text.trim() ? [] : [`operation ${i + 1}: custom_motion needs text: what to animate`]
|
|
506
|
+
})
|
|
507
|
+
const expand = (asked) => {
|
|
508
|
+
const graphics = motion ? expandGraphics(asked, { index, person, ...(typeKit ? { kinds: ALL_GRAPHIC_KINDS } : {}) }) : { ops: asked, problems: [] }
|
|
509
|
+
const marked = mark ? expandMark(graphics.ops, { mark, project, index, person }) : { ops: graphics.ops, problems: [] }
|
|
510
|
+
const custom = customProblems(marked.ops)
|
|
511
|
+
if (marked.ops.filter((op) => op?.op === "custom_motion").length > 1) custom.push("only one custom_motion at a time")
|
|
512
|
+
return { ops: marked.ops.filter((op) => op?.op !== "custom_motion"), custom: marked.ops.filter((op) => op?.op === "custom_motion"), problems: [...graphics.problems, ...marked.problems, ...custom] }
|
|
513
|
+
}
|
|
514
|
+
const check = ({ ops: asked }) => {
|
|
515
|
+
if (!asked.length) return []
|
|
516
|
+
const { ops, problems } = expand(asked)
|
|
517
|
+
if (problems.length) return problems
|
|
363
518
|
const tried = apply(project, ops, { index, author: "agent" })
|
|
364
519
|
return tried.applied ? [] : tried.diagnostics.map((d) => `operation ${d.op + 1}: ${d.message}`)
|
|
365
520
|
}
|
|
366
|
-
const
|
|
367
|
-
const
|
|
521
|
+
const base = pointingSchema(typeKitSchema(craftSchema(consoleSchema(motion), craft), typeKit), { customMotion, mark: !!mark })
|
|
522
|
+
const schema = intent ? { ...base, properties: { ...base.properties, cannot: { type: "array", maxItems: 8, items: { type: "object", properties: { evidence: { type: "string", maxLength: 300 }, nearest: { type: "string", maxLength: 160 } }, required: ["evidence"], additionalProperties: false } } } } : base
|
|
523
|
+
// The `cannot` list is tidied before the schema sees it, so it never costs a repair call (EH-64)
|
|
524
|
+
const tidy = intent ? (value) => ({ ...tidyConsole(value), cannot: tidyIntent({ cannot: value?.cannot }, {}).cannot }) : tidyConsole
|
|
525
|
+
const answer = await ask({ task: "console", tier: "budget", schema, view, request, maxOutput: 2000, check, clean: tidy, fallback: () => ({ ops: [] }), signal, priority: 0 })
|
|
526
|
+
const expanded = expand(answer.value.ops)
|
|
527
|
+
const ops = expanded.problems.length ? [] : expanded.ops
|
|
528
|
+
const custom = expanded.problems.length ? [] : expanded.custom.map((op) => ({ at: op.at, ...(Number.isInteger(op.duration) ? { duration: op.duration } : {}), ...(op.reuse !== undefined ? { reuse: op.reuse } : { text: String(op.text).replace(/[\u0000-\u001f<>]/g, " ").trim().slice(0, 300) }) }))
|
|
368
529
|
const tried = ops.length ? apply(project, ops, { index, author: "agent" }) : null
|
|
369
530
|
// A correction that changes nothing, or isn't a known word, isn't offered
|
|
370
531
|
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)
|
|
@@ -379,5 +540,9 @@ export async function revise({ ask, project, index, text, selection, history = [
|
|
|
379
540
|
source: answer.source,
|
|
380
541
|
reason: answer.reason,
|
|
381
542
|
calls: answer.calls,
|
|
543
|
+
// TP9: a custom animation to write (or a saved one to place), for the Host's own slot; only with the switch on
|
|
544
|
+
...(custom.length ? { custom } : {}),
|
|
545
|
+
// What it couldn't do, in the person's own words: only words that are in their message
|
|
546
|
+
...(intent ? { cannot: (answer.value.cannot ?? []).filter((c) => grounded(c.evidence, text, "")).map((c) => ({ said: c.evidence.replace(/[\u0000-\u001f<>]/g, " ").trim(), ...(c.nearest ? { nearest: c.nearest.replace(/[\u0000-\u001f<>]/g, " ").trim() } : {}) })) } : {}),
|
|
382
547
|
}
|
|
383
548
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The Viewer's Report (TP8, CRAFT_UPGRADE §6.2, EDD-68): the Director watches its own draft
|
|
2
|
+
// by code, free and always, in five-second windows. Picture changes come from the timeline
|
|
3
|
+
// and from the rendered file's own cuts; loudness and pauses from the rendered sound; text on
|
|
4
|
+
// screen, cutaways and speech from the solved timeline. It names typed findings and one score,
|
|
5
|
+
// deterministic for the same draft. No model is asked: watching by model (§6.3) needs
|
|
6
|
+
// editing.frameVision and the project's frame consent (EDD-14), and even then sends nothing here.
|
|
7
|
+
|
|
8
|
+
import { solve } from "../core/solver.js"
|
|
9
|
+
import { metadataFrames, ptsFlicks } from "../index/layers/meta.js"
|
|
10
|
+
import { CUT_SCORE } from "../index/layers/shots.js"
|
|
11
|
+
import { readSound, soundArgs, STEP } from "../index/layers/sound.js"
|
|
12
|
+
|
|
13
|
+
const FLICKS = 705_600_000
|
|
14
|
+
export const WINDOW = 5 * FLICKS
|
|
15
|
+
// still: scdet's mean frame difference on the 160 px copy, under which a window with no change is dull.
|
|
16
|
+
// Measured 2026-11-11: still bars with light noise 0.10, testsrc 0.15, testsrc2 0.81, a mandelbrot zoom 1.03
|
|
17
|
+
export const LIMITS = { deadAir: Math.round(1.5 * FLICKS), levelJump: 6, crowded: 3, still: 1 }
|
|
18
|
+
// Picture changes a window needs for its playbook's pace: the slow genres are never dull
|
|
19
|
+
const SLOW = new Set(["documentary", "podcast", "montage"])
|
|
20
|
+
export const paceOf = (genre) => (SLOW.has(genre) ? 0 : 1)
|
|
21
|
+
// What each finding costs the score; a crowded frame or a dead pause is worse than a still one
|
|
22
|
+
export const WEIGHT = { dull: 4, crowded: 8, dead_air: 8, repeated_cutaway: 8, level_jump: 6 }
|
|
23
|
+
|
|
24
|
+
/** Whether the model may look at frames: only with the switch on and the project's own consent (EDD-14, ET-DL-06). */
|
|
25
|
+
export const mayWatchFrames = (features = {}, project = {}) => features.frameVision === true && project.consent?.frames === true
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What the draft shows, from its solved timeline: where the picture changes, the text on screen,
|
|
29
|
+
* the cutaways and the spoken words, all in timeline flicks, with the clip each came from.
|
|
30
|
+
*/
|
|
31
|
+
export function timelineOf(project, index = {}) {
|
|
32
|
+
const solved = solve(project, index)
|
|
33
|
+
const base = solved.picture.filter((p) => p.role !== "broll" && p.asset)
|
|
34
|
+
const cutaways = solved.overlays.filter((o) => o.role === "broll" && o.asset).map(({ clip, asset, at, end, in: from, out }) => ({ clip, asset, at, end, in: from, out }))
|
|
35
|
+
const blocks = solved.overlays.filter((o) => o.block).map(({ clip, at, end, block }) => ({ clip, at, end, kind: block.blockId === "scene" ? "scene" : "graphic", block }))
|
|
36
|
+
const texts = [...(solved.captions ?? []).map(({ clip, at, end }) => ({ clip, at, end, kind: "caption" })), ...blocks]
|
|
37
|
+
const zooms = (solved.zooms ?? []).map(({ clip, at, end }) => ({ clip, at, end }))
|
|
38
|
+
const changes = [...base.slice(1).map((p) => p.at), ...cutaways.flatMap((c) => [c.at, c.end]), ...zooms.flatMap((z) => [z.at, z.end])].filter((t) => t > 0 && t < solved.duration)
|
|
39
|
+
const words = []
|
|
40
|
+
for (const piece of base) for (const word of index.words ?? []) if (word.asset === piece.asset && word.start >= piece.in && word.end <= piece.out && !word.flags?.includes("trimmed")) words.push({ at: piece.at + (word.start - piece.in), end: piece.at + (word.end - piece.in) })
|
|
41
|
+
const faced = new Set(Object.entries(index.subjects ?? {}).filter(([, list]) => list?.length).map(([asset]) => asset))
|
|
42
|
+
return { duration: solved.duration, base: base.map(({ clip, asset, at, end, in: from, out }) => ({ clip, asset, at, end, in: from, out, face: faced.has(asset) })), cutaways, texts, zooms, changes, words }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const drawnArgs = (file) => ["-hide_banner", "-nostdin", "-loglevel", "error", "-i", file, "-an", "-sn", "-dn", "-vf", `scale=160:-2,settb=AVTB,scdet=threshold=${CUT_SCORE},metadata=mode=print:file=-`, "-f", "null", "-"]
|
|
46
|
+
|
|
47
|
+
/** Reads the rendered draft: its own cuts and motion per frame, and its sound every 100 ms. */
|
|
48
|
+
export async function measureDraft(file, { run, duration }) {
|
|
49
|
+
const frames = metadataFrames(await run("ffmpeg", drawnArgs(file), { timeoutMs: 600_000 })).map(({ pts, values }) => ({ t: ptsFlicks(pts, 1_000_000), mafd: Number(values["lavfi.scd.mafd"] ?? 0), score: Number(values["lavfi.scd.score"] ?? 0) }))
|
|
50
|
+
const sound = readSound(await run("ffmpeg", soundArgs(file), { timeoutMs: 600_000 }), duration)
|
|
51
|
+
return { frames, cuts: frames.filter((f) => f.score >= CUT_SCORE && f.t > 0).map((f) => f.t), loudness: sound.data.loudness, silences: sound.silences }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const energy = (values) => {
|
|
55
|
+
const live = values.filter((v) => v !== null && v !== undefined)
|
|
56
|
+
return live.length ? Math.round(10 * Math.log10(live.reduce((sum, v) => sum + 10 ** (v / 10), 0) / live.length) * 10) / 10 : null
|
|
57
|
+
}
|
|
58
|
+
const overlap = (a, b) => Math.max(0, Math.min(a.end, b.end) - Math.max(a.at, b.at))
|
|
59
|
+
const near = (list, t, within = FLICKS / 5) => list.some((x) => Math.abs(x - t) <= within)
|
|
60
|
+
|
|
61
|
+
/** The most text layers on screen at once inside [at, end), and the clips at that moment. */
|
|
62
|
+
function crowdIn(texts, at, end) {
|
|
63
|
+
let most = { count: 0, at, clips: [] }
|
|
64
|
+
for (const t of texts.filter((x) => x.at < end && x.end > at)) {
|
|
65
|
+
const moment = Math.max(t.at, at)
|
|
66
|
+
const on = texts.filter((x) => x.at <= moment && x.end > moment)
|
|
67
|
+
if (on.length > most.count) most = { count: on.length, at: moment, end: Math.min(...on.map((x) => x.end), end), clips: on.map((x) => x.clip) }
|
|
68
|
+
}
|
|
69
|
+
return most
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The report: per window its measures, the findings against the playbook's pace, and one score
|
|
74
|
+
* (100 with nothing found, lower for each finding, never below 0). Pure: the same input, the same report.
|
|
75
|
+
* @param {{ timeline: ReturnType<typeof timelineOf>, measured?: Awaited<ReturnType<typeof measureDraft>> | null, genre?: string }} input
|
|
76
|
+
*/
|
|
77
|
+
export function viewerReport({ timeline, measured = null, genre = "opinion" }) {
|
|
78
|
+
const { duration } = timeline
|
|
79
|
+
const pace = paceOf(genre)
|
|
80
|
+
const changes = [...timeline.changes]
|
|
81
|
+
for (const t of measured?.cuts ?? []) if (!near(changes, t)) changes.push(t)
|
|
82
|
+
const windows = []
|
|
83
|
+
for (let at = 0; at < duration; at += WINDOW) {
|
|
84
|
+
const end = Math.min(duration, at + WINDOW)
|
|
85
|
+
const span = { at, end }
|
|
86
|
+
const length = end - at
|
|
87
|
+
const shown = timeline.base.filter((p) => p.face).reduce((sum, p) => sum + overlap(p, span), 0) - timeline.cutaways.reduce((sum, c) => sum + overlap(c, span), 0)
|
|
88
|
+
const frames = measured?.frames?.filter((f) => f.t >= at && f.t < end) ?? []
|
|
89
|
+
windows.push({
|
|
90
|
+
at,
|
|
91
|
+
end,
|
|
92
|
+
changes: changes.filter((t) => t >= at && t < end).length,
|
|
93
|
+
face: Math.max(0, Math.round((shown / length) * 100) / 100),
|
|
94
|
+
text: crowdIn(timeline.texts, at, end).count,
|
|
95
|
+
loudness: measured ? energy(measured.loudness.slice(Math.floor(at / STEP), Math.ceil(end / STEP))) : null,
|
|
96
|
+
speech: Math.round((timeline.words.filter((w) => w.at >= at && w.at < end).length / (length / FLICKS)) * 10) / 10,
|
|
97
|
+
motion: frames.length ? Math.round((frames.reduce((sum, f) => sum + f.mafd, 0) / frames.length) * 100) / 100 : null,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
const findings = []
|
|
101
|
+
for (const w of windows) {
|
|
102
|
+
// Dull: a whole window where the picture never changes and barely moves, for a pace that wants change
|
|
103
|
+
if (pace && w.end - w.at >= WINDOW * 0.8 && w.changes < pace && (w.motion === null || w.motion < LIMITS.still)) findings.push({ kind: "dull", at: w.at, end: w.end })
|
|
104
|
+
const crowd = crowdIn(timeline.texts, w.at, w.end)
|
|
105
|
+
if (crowd.count >= LIMITS.crowded) findings.push({ kind: "crowded", at: crowd.at, end: crowd.end, clips: crowd.clips })
|
|
106
|
+
}
|
|
107
|
+
// Dead air: a pause in the rendered sound (or, unrendered, between spoken words) longer than a breath
|
|
108
|
+
const pauses = measured ? measured.silences : timeline.words.slice(1).map((w, i) => ({ start: timeline.words[i].end, end: w.at }))
|
|
109
|
+
for (const p of pauses) if (p.end - p.start >= LIMITS.deadAir && p.start > 0 && p.end < duration) findings.push({ kind: "dead_air", at: p.start, end: p.end })
|
|
110
|
+
// The same B-roll twice: the same file back to back, or the same stretch of it again anywhere
|
|
111
|
+
const shown = [...timeline.cutaways].sort((a, b) => a.at - b.at)
|
|
112
|
+
shown.forEach((c, i) => {
|
|
113
|
+
const again = shown.slice(0, i).some((d) => d.asset === c.asset && (d === shown[i - 1] || (c.in < d.out && d.in < c.out)))
|
|
114
|
+
if (again) findings.push({ kind: "repeated_cutaway", at: c.at, end: c.end, clip: c.clip, asset: c.asset })
|
|
115
|
+
})
|
|
116
|
+
// A level jump: two voiced windows side by side whose loudness steps by more than the limit
|
|
117
|
+
for (let i = 1; i < windows.length; i++) {
|
|
118
|
+
const [a, b] = [windows[i - 1], windows[i]]
|
|
119
|
+
if (a.loudness === null || b.loudness === null) continue
|
|
120
|
+
const step = Math.round((b.loudness - a.loudness) * 10) / 10
|
|
121
|
+
if (Math.abs(step) >= LIMITS.levelJump) findings.push({ kind: "level_jump", at: b.at, end: b.end, db: step, louder: step > 0 ? { at: b.at, end: b.end } : { at: a.at, end: a.end } })
|
|
122
|
+
}
|
|
123
|
+
findings.sort((a, b) => a.at - b.at || a.kind.localeCompare(b.kind))
|
|
124
|
+
const penalty = findings.reduce((sum, f) => sum + WEIGHT[f.kind], 0)
|
|
125
|
+
// Never saturates: a fix that removes any finding raises it, however long the film
|
|
126
|
+
const score = windows.length ? Math.round((100 * windows.length) / (windows.length + penalty / 10) * 10) / 10 : 0
|
|
127
|
+
return { windows, findings, score }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const clock = (t) => {
|
|
131
|
+
const s = Math.round(t / (FLICKS / 10)) / 10
|
|
132
|
+
return `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, "0")}`
|
|
133
|
+
}
|
|
134
|
+
const WORDS = { dull: "a still stretch", crowded: "too much text at once", dead_air: "a long pause", repeated_cutaway: "the same B-roll again", level_jump: "a jump in loudness" }
|
|
135
|
+
/** A finding in the person's words, with its time. */
|
|
136
|
+
export const sayFinding = (f) => `${WORDS[f.kind]} at ${clock(f.at)}`
|