@kriya-ai/harness 0.2.3 → 0.2.4

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.
@@ -4,10 +4,12 @@
4
4
  // −14 LUFS. Code does the editing; the model makes two small choices (the hook and
5
5
  // the lines to drop; the emphasis words), each with a default that needs no model.
6
6
 
7
+ import { isSceneBlock } from "../core/layout.js"
7
8
  import { apply } from "../core/ops.js"
8
9
  import { solve } from "../core/solver.js"
9
- import { LOOKS, pages } from "../engine/captions.js"
10
+ import { LOOKS, pages, readablePages } from "../engine/captions.js"
10
11
  import { paperEdit } from "../index/views.js"
12
+ import { sceneOps } from "./scene-clips.js"
11
13
 
12
14
  const FLICKS = 705_600_000
13
15
 
@@ -183,11 +185,20 @@ export async function planReel({ project, index: fullIndex, asset, ask, brief =
183
185
  // A hook the person approved in the Director's plan wins over the model's pick
184
186
  const planned = typeof brief.hook === "string" && lines.some((l) => l.id === brief.hook) ? brief.hook : null
185
187
  const hook = variant.noHook ? null : (planned ?? story.value.hook)
186
- let chosen = lines.filter((l) => !story.value.drop.includes(l.id) || mustKeep.includes(l.id))
188
+ // The lines under an approved scene stay: fitting the length mustn't take a scene the person approved (found on real footage)
189
+ const wordsById = new Map(index.words.map((w) => [w.id, w]))
190
+ const sceneLines = [...(brief.scenes ?? []), ...(brief.pictures ?? [])].flatMap((scene) => {
191
+ const from = wordsById.get(scene.from)
192
+ const to = wordsById.get(scene.to)
193
+ return from && to ? lines.filter((l) => l.start < to.end && from.start < l.end).map((l) => l.id) : []
194
+ })
195
+ let chosen = lines.filter((l) => !story.value.drop.includes(l.id) || mustKeep.includes(l.id) || sceneLines.includes(l.id))
187
196
 
188
197
  // Length: fit under the maximum, the hook and must-keeps always in
189
- const max = Math.round(recipe.target.max * (variant.tighter ?? 1))
190
- const required = new Set([...mustKeep, ...(hook ? [hook] : [])])
198
+ // With scenes, the length the person asked for is the limit, even past the reel's 60 s
199
+ const longest = brief.scenes?.length || brief.pictures?.length ? Math.max(recipe.target.max, brief.targetDuration ?? 0) : recipe.target.max
200
+ const max = Math.round(longest * (variant.tighter ?? 1))
201
+ const required = new Set([...mustKeep, ...sceneLines, ...(hook ? [hook] : [])])
191
202
  if (chosen.reduce((sum, l) => sum + lengthOf(l), 0) > max) chosen = fitLines(chosen, max, required)
192
203
  const total = chosen.reduce((sum, l) => sum + lengthOf(l), 0)
193
204
  // Short footage sets the length: a 29 s take makes a 29 s cut, not a cut that "needs you"
@@ -205,7 +216,8 @@ export async function planReel({ project, index: fullIndex, asset, ask, brief =
205
216
  // make left them all on screen twice (found in use, 2026-11-09)
206
217
  const rebuilt = new Set(sequence.tracks.filter((t) => ["base", "caption", "music"].includes(t.role)).map((t) => t.id))
207
218
  const ops = [
208
- ...sequence.clips.filter((c) => rebuilt.has(c.track)).map((c) => ({ op: "ripple_delete", clip: c.id })),
219
+ // Scenes too: an earlier make's scenes hang on the words of that cut
220
+ ...sequence.clips.filter((c) => rebuilt.has(c.track) || c.effects?.some((e) => isSceneBlock(e))).map((c) => ({ op: "ripple_delete", clip: c.id })),
209
221
  { op: "set_brief", format: recipe.id, targetDuration: target, mustKeep: brief.mustKeep ?? [], mustCut: brief.mustCut ?? [], effort: brief.effort ?? "best", ...(brief.language ? { language: brief.language } : {}) },
210
222
  { op: "set_format", width: recipe.canvas.width, height: recipe.canvas.height, fps: recipe.deliverable.fps },
211
223
  ...(project.deliverables.some((d) => d.preset === recipe.deliverable.preset) ? [] : [{ op: "add_deliverable", ...deliverableFor(brief) }]),
@@ -227,16 +239,20 @@ export async function planReel({ project, index: fullIndex, asset, ask, brief =
227
239
  // Emphasis: a few words worth a punch-in; a reference's pace can ask for more (EDD-23)
228
240
  const most = Number.isInteger(brief.punches) && brief.punches > 0 ? Math.min(brief.punches, 8) : recipe.punch.max
229
241
  const kept = chosen.flatMap((l) => runsOf(l).flat())
230
- const keptIds = new Set(kept.map((w) => w.id))
242
+ // The approved plan's scenes, on the cut as solved. A zoom or title under one would never be seen
243
+ const scenes = brief.scenes?.length || brief.pictures?.length || brief.terms?.length ? sceneOps({ scenes: brief.scenes ?? [], pictures: brief.pictures ?? [], terms: brief.terms ?? [], project: step.project, index, asset, kept, captions: !!LOOKS[brief.captions], sound: { scene: brief.sfx?.scene, reveal: brief.sfx?.reveal } }) : { ops: [], covered: new Set(), notes: [] }
244
+ notes.push(...scenes.notes)
245
+ const visible = kept.filter((w) => !scenes.covered.has(w.id))
246
+ const keptIds = new Set(visible.map((w) => w.id))
231
247
  const emphasis = await ask({
232
248
  task: "emphasis",
233
249
  schema: EMPHASIS_SCHEMA,
234
250
  recipe: recipe.notes,
235
- view: paperEdit({ ...scoped, sentences: chosen }, { assets: [asset] }),
251
+ view: paperEdit({ ...scoped, sentences: chosen.filter((l) => l.words.some((w) => keptIds.has(w.id))) }, { assets: [asset] }),
236
252
  request: `Pick up to ${most} single words to emphasise with a quick zoom: numbers, names, the point of a line. Word ids only.`,
237
253
  maxOutput: 200,
238
254
  check: ({ emphasis: picked }) => picked.filter((id) => !keptIds.has(id)).map((id) => `"${id}" isn't a kept word`),
239
- fallback: () => ({ emphasis: kept.filter((w) => /\d/.test(w.text)).slice(0, most).map((w) => w.id) }),
255
+ fallback: () => ({ emphasis: visible.filter((w) => /\d/.test(w.text)).slice(0, most).map((w) => w.id) }),
240
256
  signal,
241
257
  })
242
258
  calls += emphasis.calls
@@ -260,7 +276,9 @@ export async function planReel({ project, index: fullIndex, asset, ask, brief =
260
276
  // Sound design: an effect on every cut of the story, a riser into it after a cold open.
261
277
  // Each is placed by its peak, so the loudest moment lands on the cut
262
278
  const storyClips = clips.filter((c) => !c.echo)
263
- const cutSounds = brief.sfx?.cut ? storyClips.slice(1).map((c) => ({ op: "add_sfx", asset: brief.sfx.cut, peak_at: { clip: c.id, edge: "start" } })) : []
279
+ // A playbook's restraint: a sound on every nth cut, not on all of them
280
+ const every = Number.isInteger(brief.soundEvery) && brief.soundEvery > 1 ? brief.soundEvery : 1
281
+ const cutSounds = brief.sfx?.cut ? storyClips.slice(1).filter((_, i) => i % every === 0).map((c) => ({ op: "add_sfx", asset: brief.sfx.cut, peak_at: { clip: c.id, edge: "start" } })) : []
264
282
  const introSound = brief.sfx?.intro && cold && storyClips[0] ? [{ op: "add_sfx", asset: brief.sfx.intro, peak_at: { clip: storyClips[0].id, edge: "start" } }] : []
265
283
  const sounds = [...cutSounds, ...introSound]
266
284
 
@@ -300,12 +318,14 @@ export async function planReel({ project, index: fullIndex, asset, ask, brief =
300
318
  const cleaning = brief.cleanVoice ? clips.map((c) => ({ op: "clean_voice", clip: c.id, strength: 0.6 })) : []
301
319
 
302
320
  // Captions, when the brief asks for a look: pages of the kept words, timed to the speech
303
- const captions = LOOKS[brief.captions] ? chosen.flatMap((l) => runsOf(l)).flatMap((run) => pages(run)).map((ids) => ({ op: "caption_style", look: brief.captions, words: ids })) : []
321
+ const captions = LOOKS[brief.captions] ? chosen.flatMap((l) => runsOf(l)).flatMap((run) => readablePages(pages(run), run)).map((ids) => ({ op: "caption_style", look: brief.captions, words: ids })) : []
304
322
  // Music, when the brief names a sound in the project: fitted on its downbeats, ducked under the speech (ED9)
305
323
  const song = brief.music ? project.assets.find((a) => a.id === brief.music && a.kind === "audio") : null
306
324
  if (brief.music && !song) notes.push(`There is no sound "${brief.music}" in this project, so the reel has no music.`)
307
325
  const music = song ? [{ op: "set_music", asset: song.id }, { op: "music_shape", fit: true, fadeIn: Math.round(FLICKS * 0.3) }, { op: "duck" }] : []
308
- const all = [...ops, ...angles, ...punches, ...framing, ...grading, ...cleaning, ...broll, ...titles, ...captions, ...music, ...sounds, ...ramps]
326
+ const captionLook = { ...(brief.captionStyle ?? {}), ...(brief.holdCaptions ? { hold: true } : {}) }
327
+ const style = LOOKS[brief.captions] && Object.keys(captionLook).length ? [{ op: "set_look", caption: captionLook }] : []
328
+ const all = [...ops, ...style, ...angles, ...punches, ...framing, ...grading, ...cleaning, ...broll, ...titles, ...scenes.ops, ...captions, ...music, ...sounds, ...ramps]
309
329
  step = apply(project, all, { index, author: "agent" })
310
330
  if (!step.applied) throw new Error(`The reel was refused: ${step.diagnostics[0].message}`)
311
331
  return { ops: all, project: step.project, notes, calls, slots }
@@ -0,0 +1,127 @@
1
+ // Scene clips (VISUAL_SCENES.md §3.2): an approved plan's scenes as operations on the cut as
2
+ // solved. The words anchor them, so a scene moves with its speech; each label is timed to the
3
+ // word it's said on; code checks again what the plan checked, since a re-cut can drop a line.
4
+
5
+ import { arrangeScenes, MAX_SHARE, revealWords } from "../director/beats.js"
6
+ import { cleanScene, SCENE_BLOCK, SCENE_THEMES, SCENE_VERSION } from "../engine/scenes.js"
7
+ import { solve } from "../core/solver.js"
8
+
9
+ const FLICKS = 705_600_000
10
+ const OPENING = 2 * FLICKS // the speaker is seen first
11
+ // Removing pauses can tighten an approved gap: closer than this, the first scene holds until the next starts, so the speaker doesn't flash between them
12
+ const MIN_GAP = 1 * FLICKS
13
+ const MIN_LENGTH = 2 * FLICKS
14
+ const MAX_LENGTH = 15 * FLICKS
15
+ const REVEAL_GAP = 0.6 * FLICKS // pops closer than this blur together
16
+
17
+ /**
18
+ * pictures: approved licensed clips, resolved to assets; terms: quoted definitions to show on their words.
19
+ * @param {{ scenes: object[], pictures?: { asset: string, from: string, to: string }[], terms?: { at: string, term: string, quote: string, source: string }[], project: object, index: object, asset: string, kept: { id: string }[], captions?: boolean, sound?: { scene?: string, reveal?: string } }} input
20
+ * project: with the cut applied; kept: the words the cut keeps
21
+ * @returns {{ ops: object[], covered: Set<string>, notes: string[] }} covered: the words under a scene
22
+ */
23
+ export function sceneOps({ scenes, pictures = [], terms = [], project, index, asset, kept, captions = false, sound = {} }) {
24
+ const notes = []
25
+ const covered = new Set()
26
+ const ops = []
27
+ const { scenes: arranged, dropped } = arrangeScenes(scenes, { index, asset })
28
+ for (const { scene, reason } of dropped) notes.push(`Left out the ${scene.kind} scene: ${reason}.`)
29
+ const timeline = solve(project, index)
30
+ const story = timeline.picture.filter((p) => !p.echo && !p.hold)
31
+ const start = story[0]?.at ?? 0
32
+ const outputOf = (word, edge) => {
33
+ const t = edge === "start" ? word.start : word.end
34
+ const piece = story.find((p) => p.asset === asset && t >= p.in && t <= p.out)
35
+ return piece ? piece.at + (t - piece.in) : null
36
+ }
37
+ const keptIds = new Set(kept.map((w) => w.id))
38
+ const words = index.words.filter((w) => w.asset === asset)
39
+ const byId = new Map(words.map((w) => [w.id, w]))
40
+ let last = -Infinity
41
+ let previous = null
42
+ let used = 0
43
+ for (const raw of arranged) {
44
+ const scene = cleanScene(raw)
45
+ const from = byId.get(scene.from)
46
+ const to = byId.get(scene.to)
47
+ const name = `"${scene.title || scene.items[0].text}"`
48
+ const spoken = words.filter((w) => w.start >= from.start && w.end <= to.end && keptIds.has(w.id))
49
+ if (!spoken.length) {
50
+ notes.push(`Left out the scene ${name}: its lines aren't in this cut.`)
51
+ continue
52
+ }
53
+ const at = outputOf(spoken[0], "start")
54
+ const end = outputOf(spoken.at(-1), "end")
55
+ const length = end - at
56
+ const refuse = at === null || end === null || !(length > 0) ? "its lines aren't together in this cut" : at < start + OPENING ? "the speaker is seen first" : length < MIN_LENGTH ? "its lines are too short in this cut" : length > MAX_LENGTH ? "its lines are apart in this cut" : at < last ? "its lines come before the last scene in this cut" : used + length > timeline.duration * MAX_SHARE ? "the speaker would hardly be seen" : null
57
+ if (refuse) {
58
+ notes.push(`Left out the scene ${name}: ${refuse}.`)
59
+ continue
60
+ }
61
+ if (previous && at - last < MIN_GAP) previous.until = { word: spoken[0].id, edge: "start" }
62
+ const landing = revealWords(scene, spoken)
63
+ const items = scene.items.map((item, i) => {
64
+ const t = landing[i] && outputOf(landing[i], "start")
65
+ return { ...item, ...(t === null || t === undefined ? {} : { reveal: Math.round(((t - at) / FLICKS) * 1000) }) }
66
+ })
67
+ last = end
68
+ used += length
69
+ for (const word of spoken) covered.add(word.id)
70
+ previous = {
71
+ op: "add_motion",
72
+ block: SCENE_BLOCK,
73
+ version: SCENE_VERSION,
74
+ variables: { kind: scene.kind, theme: scene.theme, title: scene.title, text: scene.title || scene.items[0].text, items, ...(scene.mode ? { mode: scene.mode } : {}), ...(captions && SCENE_THEMES[scene.theme].band ? { band: true } : {}) },
75
+ at: { word: spoken[0].id, edge: "start" },
76
+ until: { word: spoken.at(-1).id, edge: "end" },
77
+ }
78
+ ops.push(previous)
79
+ if (sound.scene) ops.push({ op: "add_sfx", asset: sound.scene, peak_at: { word: spoken[0].id, edge: "start" } })
80
+ if (sound.reveal) {
81
+ let lastPop = at
82
+ for (const word of landing) {
83
+ const t = word && outputOf(word, "start")
84
+ if (t === null || t === undefined || t - lastPop < REVEAL_GAP) continue
85
+ lastPop = t
86
+ ops.push({ op: "add_sfx", asset: sound.reveal, peak_at: { word: word.id, edge: "start" } })
87
+ }
88
+ }
89
+ }
90
+ const taken = ops.filter((o) => o.op === "add_motion").map((o) => ({ at: outputOf(byId.get(o.at.word), "start"), end: outputOf(byId.get(o.until.word), "end") }))
91
+ for (const picture of pictures) {
92
+ const from = byId.get(picture.from)
93
+ const to = byId.get(picture.to)
94
+ const asset_ = project.assets.find((a) => a.id === picture.asset)
95
+ const spoken = from && to ? words.filter((w) => w.start >= from.start && w.end <= to.end && keptIds.has(w.id)) : []
96
+ if (!spoken.length || !asset_) {
97
+ notes.push("Left out a picture: its lines aren't in this cut.")
98
+ continue
99
+ }
100
+ const at = outputOf(spoken[0], "start")
101
+ const end = outputOf(spoken.at(-1), "end")
102
+ const length = end - at
103
+ const refuse = at === null || end === null || !(length > 0) ? "its lines aren't together in this cut" : at < start + OPENING ? "the speaker is seen first" : length < MIN_LENGTH || length > MAX_LENGTH ? "its lines don't fit it in this cut" : taken.some((t) => at < t.end && t.at < end) ? "a scene is already there" : length > (asset_.facts.duration ?? 0) ? "the clip is too short for its lines" : used + length > timeline.duration * MAX_SHARE ? "the speaker would hardly be seen" : null
104
+ if (refuse) {
105
+ notes.push(`Left out a picture: ${refuse}.`)
106
+ continue
107
+ }
108
+ used += length
109
+ taken.push({ at, end })
110
+ for (const word of spoken) covered.add(word.id)
111
+ ops.push({ op: "place_broll", asset: asset_.id, at: { word: spoken[0].id, edge: "start" }, until: { word: spoken.at(-1).id, edge: "end" } })
112
+ if (sound.scene) ops.push({ op: "add_sfx", asset: sound.scene, peak_at: { word: spoken[0].id, edge: "start" } })
113
+ }
114
+ for (const term of terms) {
115
+ const word = byId.get(term.at)
116
+ const at = word && keptIds.has(word.id) ? outputOf(word, "start") : null
117
+ if (at === null || taken.some((t) => at >= t.at && at < t.end)) {
118
+ notes.push(`Left out the definition of "${term.term}": something else is on screen there, or the line isn't in this cut.`)
119
+ continue
120
+ }
121
+ // Long enough to read: letters over 15 a second, plus a second and a half
122
+ const seconds = Math.min(7, (term.term.length + term.quote.length + term.source.length) / 15 + 1.5)
123
+ const duration = Math.round(Math.min(seconds * FLICKS, Math.max(FLICKS, timeline.duration - at)))
124
+ ops.push({ op: "add_motion", block: "term", version: 1, variables: { text: term.term, quote: term.quote, source: term.source, ...(term.page ? { page: term.page } : {}) }, at: { word: word.id, edge: "start" }, duration })
125
+ }
126
+ return { ops, covered, notes }
127
+ }
@@ -4,6 +4,38 @@
4
4
  import { call, KriyaError } from "../../api.js"
5
5
  import { openManifest, RuntimeError, TRUSTED_KEYS } from "./manifest.js"
6
6
 
7
+ /**
8
+ * What this Kriya has switched on for editing (EH-01). Any failure, a server with no such
9
+ * route among them, means off: the server ships first, and a client never assumes (track E rule 17).
10
+ * @returns {Promise<{ visuals: boolean, playbooks: boolean, mediaSearch: boolean }>}
11
+ */
12
+ export async function fetchFeatures(device) {
13
+ try {
14
+ const found = await call(device.url, "GET", "/editing/features", { token: device.token })
15
+ return { visuals: found?.visuals === true, playbooks: found?.playbooks === true, mediaSearch: found?.mediaSearch === true }
16
+ } catch {
17
+ return { visuals: false, playbooks: false, mediaSearch: false }
18
+ }
19
+ }
20
+
21
+ /** Licensed pictures for these words; nothing found on any failure, so a plan never fails on a search. */
22
+ export async function searchMedia(device, queries) {
23
+ try {
24
+ return (await call(device.url, "POST", "/editing/media", { token: device.token, body: { queries } }))?.results ?? []
25
+ } catch {
26
+ return []
27
+ }
28
+ }
29
+
30
+ /** Cited definitions for these terms; none on any failure. */
31
+ export async function defineTerms(device, terms) {
32
+ try {
33
+ return (await call(device.url, "POST", "/editing/define", { token: device.token, body: { terms } }))?.definitions ?? []
34
+ } catch {
35
+ return []
36
+ }
37
+ }
38
+
7
39
  /** The manifest for this device. A 404 is how a client learns this Kriya has no editing (EH-01). */
8
40
  export async function fetchManifest(device, trusted = TRUSTED_KEYS) {
9
41
  try {
@@ -227,6 +227,20 @@ a { color: var(--teal); }
227
227
  .send { display: grid; gap: 6px; }
228
228
  .extras { display: flex; flex-wrap: wrap; gap: 0 14px; }
229
229
  .plan .steps { margin: 4px 0; padding-left: 20px; display: grid; gap: 4px; }
230
+ .scenes { display: grid; gap: 8px; }
231
+ .scene-head { justify-content: space-between; align-items: center; }
232
+ .scene-head .field { width: auto; }
233
+ .scene-info .field { width: auto; flex: 1 1 140px; min-width: 0; }
234
+ .scene-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
235
+ .proposal .scene-row { display: flex; gap: 10px; align-items: flex-start; justify-content: flex-start; }
236
+ .found-thumb { flex: none; width: 120px; height: 90px; object-fit: cover; border-radius: 6px; background: #000; }
237
+ .scenes .row .field { width: auto; flex: 1 1 120px; min-width: 0; }
238
+ .scene-picture { flex: none; overflow: hidden; border-radius: 6px; background: #000; }
239
+ .scene-picture iframe { border: 0; display: block; transform-origin: 0 0; pointer-events: none; }
240
+ .scene-info { min-width: 0; display: grid; gap: 4px; }
241
+ .scene-info p { margin: 0; overflow-wrap: anywhere; }
242
+ .scene-info .row { flex-wrap: wrap; gap: 6px; }
243
+ .scene-time { font-family: ui-monospace, "JetBrains Mono", monospace; color: var(--teal); }
230
244
  .refs-direct { margin: 0; }
231
245
  .refs-direct:empty { display: none; }
232
246
  .ref .ref-lines { list-style: none; padding: 0; margin: 2px 0; font-size: 13px; color: var(--ink-2); display: grid; gap: 2px; }