@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
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Watch and fix (TP8, CRAFT_UPGRADE §6.1, EDD-68): each finding of the Viewer's Report maps to
|
|
2
|
+
// one typed fix, made by code: a punch-in on a still stretch, a graphic moved off a crowded
|
|
3
|
+
// moment, a pause trimmed, a repeated cutaway swapped or removed, a jump in level evened. The
|
|
4
|
+
// draft is rendered and gated again, and a fix is kept only when the score rises and the gates
|
|
5
|
+
// are no worse; a cut that passes its gates is never replaced by one that doesn't (EH-74). The
|
|
6
|
+
// rounds are the repair ladder's own, not more on top of them.
|
|
7
|
+
|
|
8
|
+
import { apply } from "../core/ops.js"
|
|
9
|
+
import { better, rankOf, ROUNDS } from "../loop/repair.js"
|
|
10
|
+
import { sayFinding } from "./viewer.js"
|
|
11
|
+
|
|
12
|
+
const FLICKS = 705_600_000
|
|
13
|
+
const PUNCH = 1.12
|
|
14
|
+
const PAD = Math.round(0.25 * FLICKS)
|
|
15
|
+
export const FIX_ROUNDS = 2
|
|
16
|
+
|
|
17
|
+
/** The fix rounds a candidate has left: two at most, out of what its repair ladder didn't use. */
|
|
18
|
+
export const roundsLeft = (repairs = []) => Math.max(0, Math.min(FIX_ROUNDS, ROUNDS - repairs.length))
|
|
19
|
+
|
|
20
|
+
const levelOf = (clip) => clip?.effects.find((e) => e.type === "level")?.db ?? 0
|
|
21
|
+
const clipOf = (project, id) => project.sequences.find((q) => q.id === project.active).clips.find((c) => c.id === id)
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The typed operations for a report's findings. A finding with no safe fix is left for the person.
|
|
25
|
+
* @param {{ findings: object[] }} report
|
|
26
|
+
* @param {ReturnType<import("./viewer.js").timelineOf>} timeline
|
|
27
|
+
* @returns {{ fixes: { kind: string, at: number, ops: object[], why: string }[], left: object[] }}
|
|
28
|
+
*/
|
|
29
|
+
export function fixesFor(report, project, index, timeline) {
|
|
30
|
+
const fixes = []
|
|
31
|
+
const left = []
|
|
32
|
+
const indexWords = index.words ?? []
|
|
33
|
+
const pictures = project.assets.filter((a) => a.kind === "video" && a.facts?.width && (a.facts.duration ?? 0) > FLICKS)
|
|
34
|
+
for (const f of report.findings) {
|
|
35
|
+
if (f.kind === "dull") {
|
|
36
|
+
const at = f.at + Math.round((f.end - f.at) / 3)
|
|
37
|
+
const duration = Math.min(Math.round(1.5 * FLICKS), f.end - at)
|
|
38
|
+
if (duration > FLICKS / 2 && !timeline.zooms.some((z) => z.at < at + duration && z.end > at)) fixes.push({ kind: f.kind, at: f.at, ops: [{ op: "punch_in", at, duration, scale: PUNCH }], why: `Punched in on ${sayFinding(f)}.` })
|
|
39
|
+
else left.push(f)
|
|
40
|
+
} else if (f.kind === "crowded") {
|
|
41
|
+
// The latest graphic of the moment moves to where nothing else is on screen; a scene stays on its words
|
|
42
|
+
const graphic = timeline.texts.filter((t) => f.clips.includes(t.clip) && t.kind === "graphic").sort((a, b) => b.at - a.at)[0]
|
|
43
|
+
const length = graphic ? graphic.end - graphic.at : 0
|
|
44
|
+
const clear = graphic && [f.end, ...timeline.texts.map((t) => t.end)].sort((a, b) => a - b).find((t) => t >= f.end && t + length <= timeline.duration && timeline.texts.filter((x) => x.clip !== graphic.clip && x.at < t + length && x.end > t).length < 2)
|
|
45
|
+
if (graphic && clear !== undefined) fixes.push({ kind: f.kind, at: f.at, ops: [{ op: "ripple_delete", clip: graphic.clip }, { op: "add_motion", block: graphic.block.blockId, version: graphic.block.version, variables: graphic.block.variables, at: clear, duration: length }], why: `Moved a graphic off ${sayFinding(f)}.` })
|
|
46
|
+
else left.push(f)
|
|
47
|
+
} else if (f.kind === "dead_air") {
|
|
48
|
+
// Trimmed inside its own clip, a quarter second kept each side, never through a word
|
|
49
|
+
const piece = timeline.base.find((p) => p.at <= f.at && p.end >= f.end)
|
|
50
|
+
const from = piece && piece.in + (f.at - piece.at) + PAD
|
|
51
|
+
const to = piece && piece.in + (f.end - piece.at) - PAD
|
|
52
|
+
if (piece && to - from > FLICKS / 4 && !indexWords.some((w) => w.asset === piece.asset && w.start < to && w.end > from)) fixes.push({ kind: f.kind, at: f.at, ops: [{ op: "remove_range", asset: piece.asset, from, to }], why: `Trimmed ${sayFinding(f)}.` })
|
|
53
|
+
else left.push(f)
|
|
54
|
+
} else if (f.kind === "repeated_cutaway") {
|
|
55
|
+
// Another of the person's clips not already on screen nearby, from its start; else the repeat goes
|
|
56
|
+
const near = new Set(timeline.cutaways.filter((c) => Math.abs(c.at - f.at) < 10 * FLICKS).map((c) => c.asset))
|
|
57
|
+
const base = new Set(timeline.base.map((p) => p.asset))
|
|
58
|
+
const other = pictures.find((a) => !near.has(a.id) && !base.has(a.id) && a.facts.duration >= f.end - f.at)
|
|
59
|
+
fixes.push({ kind: f.kind, at: f.at, ops: [{ op: "ripple_delete", clip: f.clip }, ...(other ? [{ op: "place_broll", asset: other.id, at: f.at, in: 0, duration: f.end - f.at }] : [])], why: other ? `Swapped ${sayFinding(f)} for another of your clips.` : `Took out ${sayFinding(f)}.` })
|
|
60
|
+
} else if (f.kind === "level_jump") {
|
|
61
|
+
// The louder side's own clips come down toward the quieter, never past it
|
|
62
|
+
const louder = timeline.base.filter((p) => p.at < f.louder.end && p.end > f.louder.at)
|
|
63
|
+
const quieter = new Set(timeline.base.filter((p) => !louder.includes(p)).map((p) => p.clip))
|
|
64
|
+
const clips = [...new Set(louder.map((p) => p.clip))].filter((id) => !quieter.has(id))
|
|
65
|
+
const down = Math.round((Math.abs(f.db) - 2) * 10) / 10
|
|
66
|
+
if (clips.length) fixes.push({ kind: f.kind, at: f.at, ops: clips.map((id) => ({ op: "set_level", clip: id, db: Math.round((levelOf(clipOf(project, id)) - down) * 10) / 10 })), why: `Evened ${sayFinding(f)} (${down} dB).` })
|
|
67
|
+
else left.push(f)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { fixes, left }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const passing = (checked) => checked.blocking === 0 && checked.briefMisses === 0
|
|
74
|
+
|
|
75
|
+
/** The keep rule (ET-DL-03, EH-74): a higher score, gates no worse, and never a passing cut swapped for a failing one. */
|
|
76
|
+
export function keepFix(before, after) {
|
|
77
|
+
if (passing(before.checked) && !passing(after.checked)) return { kept: false, reason: "it would fail a gate the cut passed" }
|
|
78
|
+
if (better(rankOf(before.checked), rankOf(after.checked))) return { kept: false, reason: "the gates were worse" }
|
|
79
|
+
if (!(after.report.score > before.report.score)) return { kept: false, reason: `the score didn't rise (${before.report.score} → ${after.report.score})` }
|
|
80
|
+
return { kept: true }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The loop over one checked attempt.
|
|
85
|
+
* @param {{ project: object, ops: object[], file: string, plan: object, checked: object }} start
|
|
86
|
+
* @param {{ index: object, view: (attempt: object) => Promise<{ report: object, timeline: object }>, render: (project: object) => Promise<{ file: string, plan: object }>, check: (file: string, plan: object, project: object) => Promise<object>, rounds?: number, fixes?: typeof fixesFor, signal?: AbortSignal }} io
|
|
87
|
+
* @returns {Promise<{ best: object, rounds: object[], left: object[] }>}
|
|
88
|
+
*/
|
|
89
|
+
export async function watchAndFix(start, { index, view, render, check, rounds = FIX_ROUNDS, fixes = fixesFor, signal }) {
|
|
90
|
+
let best = { ...start, ...(await view(start)) }
|
|
91
|
+
const log = []
|
|
92
|
+
const tried = new Set()
|
|
93
|
+
for (let round = 1; round <= Math.min(rounds, FIX_ROUNDS); round++) {
|
|
94
|
+
if (signal?.aborted || !best.report.findings.length) break
|
|
95
|
+
const proposed = fixes(best.report, best.project, index, best.timeline).fixes.filter((fix) => !tried.has(JSON.stringify(fix.ops)))
|
|
96
|
+
if (!proposed.length) break
|
|
97
|
+
proposed.forEach((fix) => tried.add(JSON.stringify(fix.ops)))
|
|
98
|
+
const ops = proposed.flatMap((fix) => fix.ops)
|
|
99
|
+
const step = apply(best.project, ops, { index, author: "code" })
|
|
100
|
+
const said = proposed.map(({ ops: _, ...fix }) => fix)
|
|
101
|
+
if (!step.applied) {
|
|
102
|
+
log.push({ round, fixes: said, kept: false, reason: step.diagnostics[0].message })
|
|
103
|
+
continue
|
|
104
|
+
}
|
|
105
|
+
const { file, plan } = await render(step.project)
|
|
106
|
+
const checked = await check(file, plan, step.project)
|
|
107
|
+
const attempt = { project: step.project, ops: [...best.ops, ...ops], file, plan, checked }
|
|
108
|
+
Object.assign(attempt, await view(attempt))
|
|
109
|
+
const verdict = keepFix(best, attempt)
|
|
110
|
+
log.push({ round, fixes: said, was: best.report.score, score: attempt.report.score, ...verdict })
|
|
111
|
+
if (verdict.kept) best = attempt
|
|
112
|
+
}
|
|
113
|
+
return { best, rounds: log, left: best.report.findings }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** What the loop did, in the person's words: each kept fix, and each dropped round with its reason. */
|
|
117
|
+
export function sayWatch(rounds) {
|
|
118
|
+
return rounds.map((r) => (r.kept ? `Director: ${r.fixes.map((f) => f.why).join(" ")} Score ${r.was} → ${r.score}.` : `Director: tried ${r.fixes.map((f) => f.why.replace(/\.$/, "").toLowerCase()).join("; ")}, and kept the cut as it was: ${r.reason}.`))
|
|
119
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// looks written as Kriya's own CSS and WAAPI (no GSAP, no Remotion: EDD-08, EDD-09),
|
|
3
3
|
// and each caption a HyperFrames tile, so preview and final match (EDIT_ENGINE §6).
|
|
4
4
|
|
|
5
|
+
import { boxFor, readableColors } from "../core/type-kit.js"
|
|
6
|
+
import { fontFaces, fontsFor, fontStackFor, lineFor } from "./fonts.js"
|
|
5
7
|
import { springKeyframes, tileDocument } from "./motion.js"
|
|
6
8
|
|
|
7
9
|
const FLICKS = 705_600_000
|
|
@@ -27,11 +29,40 @@ export const LOOKS = {
|
|
|
27
29
|
minimal: { font: "sans", weight: 700, size: 0.034, color: "#ffffff", accent: "#ffffff", box: { color: "#000000", alpha: 0.72 }, stroke: null, highlight: false },
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
* TP7 (CRAFT_UPGRADE §5.3, EDD-67): eight more looks, offered only with editing.typeKit on.
|
|
34
|
+
* Data like the six: words per page (1 to 5), lines, how a word arrives (pop, rise, fade, type
|
|
35
|
+
* on), how the spoken word is marked (colour, box, underline, size), how an emphasised word
|
|
36
|
+
* differs, where the page sits. Web Animations only; QG-08 and QG-09 judge each as before.
|
|
37
|
+
*/
|
|
38
|
+
export const MORE_CAPTION_LOOKS = {
|
|
39
|
+
single: { font: "sans", weight: 900, size: 0.07, color: "#ffffff", accent: "#ffd23f", box: null, stroke: "#000000", highlight: false, words: 1, lines: 1, arrive: "pop", mark: "none", emphasis: "color", place: "middle" },
|
|
40
|
+
duo: { font: "sans", weight: 900, size: 0.06, color: "#ffffff", accent: "#4fd1c5", box: null, stroke: "#000000", highlight: false, words: 2, lines: 1, arrive: "pop", mark: "color", emphasis: "size", place: "middle" },
|
|
41
|
+
marker: { font: "sans", weight: 800, size: 0.05, color: "#ffffff", accent: "#ffd23f", box: null, stroke: "#000000", highlight: false, words: 3, lines: 2, arrive: "rise", mark: "box", emphasis: "box", place: "bottom" },
|
|
42
|
+
underline: { font: "sans", weight: 800, size: 0.046, color: "#ffffff", accent: "#ff7ab6", box: { color: "#0a0a0a", alpha: 0.72 }, stroke: null, highlight: false, words: 4, lines: 2, arrive: "fade", mark: "underline", emphasis: "underline", place: "bottom" },
|
|
43
|
+
grow: { font: "sans", weight: 800, size: 0.05, color: "#ffffff", accent: "#ffb347", box: null, stroke: "#000000", highlight: false, words: 3, lines: 2, arrive: "pop", mark: "size", emphasis: "color", place: "bottom" },
|
|
44
|
+
typewriter: { font: "sans", weight: 700, size: 0.04, color: "#f2eadf", accent: "#ffb347", box: { color: "#13292b", alpha: 0.92 }, stroke: null, highlight: false, words: 5, lines: 2, arrive: "type", mark: "none", emphasis: "color", place: "bottom" },
|
|
45
|
+
headline: { font: "sans", weight: 900, size: 0.052, color: "#ffffff", accent: "#ffd23f", box: { color: "#0a0a0a", alpha: 0.8 }, stroke: null, highlight: false, words: 3, lines: 2, arrive: "rise", mark: "color", emphasis: "box", place: "top", case: "upper" },
|
|
46
|
+
subtle: { font: "sans", weight: 600, size: 0.034, color: "#ffffff", accent: "#cfe8ff", box: { color: "#000000", alpha: 0.6 }, stroke: null, highlight: false, words: 5, lines: 2, arrive: "fade", mark: "color", emphasis: "underline", place: "bottom" },
|
|
47
|
+
}
|
|
48
|
+
export const ALL_LOOKS = { ...LOOKS, ...MORE_CAPTION_LOOKS }
|
|
49
|
+
export const ARRIVALS = ["pop", "rise", "fade", "type"]
|
|
50
|
+
export const MARKS = ["none", "color", "box", "underline", "size"]
|
|
51
|
+
|
|
52
|
+
/** Words per page a look asks for: the six keep 2 to 5, as before. */
|
|
53
|
+
export function pageLimits(id) {
|
|
54
|
+
const words = MORE_CAPTION_LOOKS[id]?.words
|
|
55
|
+
return words ? { min: Math.min(2, words), max: words } : { min: 2, max: 5 }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Where a look's page sits when it isn't the recipe's row (TP7): "middle" or "top", else nothing. */
|
|
59
|
+
export const placeOf = (id) => (["middle", "top"].includes(MORE_CAPTION_LOOKS[id]?.place) ? MORE_CAPTION_LOOKS[id].place : undefined)
|
|
60
|
+
|
|
30
61
|
const HEX = /^#[0-9a-f]{6}$/i
|
|
31
62
|
|
|
32
63
|
/** A look with the project's typed overrides; anything else in the style is ignored, never passed on. */
|
|
33
64
|
export function lookOf(id, style = {}) {
|
|
34
|
-
const base =
|
|
65
|
+
const base = ALL_LOOKS[id] ?? ALL_LOOKS[style.style] ?? LOOKS.clean
|
|
35
66
|
const look = { ...base }
|
|
36
67
|
if (HEX.test(style.color ?? "")) look.color = style.color
|
|
37
68
|
if (HEX.test(style.accent ?? "")) look.accent = style.accent
|
|
@@ -143,6 +174,15 @@ const ENTRANCE = { damping: 0.7, frequency: 14, ms: 320 }
|
|
|
143
174
|
*/
|
|
144
175
|
export function captionComposition(node, { output, canvas }) {
|
|
145
176
|
const look = lookOf(node.look, node.style)
|
|
177
|
+
// TP7: a project with a type kit draws in its faces and colours; one without draws as it did
|
|
178
|
+
const kit = node.type
|
|
179
|
+
if (kit?.colors) {
|
|
180
|
+
const colors = readableColors({ text: kit.colors.text ?? look.color, accent: kit.colors.accent ?? look.accent, plate: kit.colors.plate }, { plate: !!look.box })
|
|
181
|
+
look.color = colors.text
|
|
182
|
+
look.accent = colors.accent
|
|
183
|
+
look.stroke = colors.stroke
|
|
184
|
+
look.box = colors.plate ? { color: colors.plate, alpha: look.box ? Math.max(look.box.alpha, 0.92) : 0.92 } : null
|
|
185
|
+
}
|
|
146
186
|
const sx = output.width / canvas.width
|
|
147
187
|
const sy = output.height / canvas.height
|
|
148
188
|
const box = node.placement ?? { x: Math.round(canvas.width * 0.1), y: Math.round(canvas.height * 0.7), w: Math.round(canvas.width * 0.8), h: Math.round(canvas.height * 0.12) }
|
|
@@ -150,13 +190,21 @@ export function captionComposition(node, { output, canvas }) {
|
|
|
150
190
|
const area = { x: Math.round(box.x * sx), y: Math.round(box.y * sy), w: Math.round(box.w * sx), h: Math.round(box.h * sy) }
|
|
151
191
|
const plate = look.box ? `background:${look.box.color}${Math.round(look.box.alpha * 255).toString(16).padStart(2, "0")};border-radius:${Math.round(size * 0.35)}px;padding:${Math.round(size * 0.22)}px ${Math.round(size * 0.45)}px;` : ""
|
|
152
192
|
const stroke = look.stroke ? `-webkit-text-stroke:${Math.max(2, Math.round(size * 0.08))}px ${look.stroke};paint-order:stroke fill;` : ""
|
|
193
|
+
const duration = node.duration
|
|
194
|
+
const pageText = node.text ?? node.words.map((w) => w.text).join(" ")
|
|
195
|
+
const face = kit ? (look.weight >= 900 || look.case === "upper" ? kit.heading : kit.body) : null
|
|
196
|
+
// Not shipped here: the kit's own system stacks, no font asked for, so the tile is the same with or without the pack
|
|
197
|
+
const family = face ? fontStackFor(pageText, face.font, kit.shipped ? null : new Set()) : FONTS[look.font]
|
|
198
|
+
const typeCss = face ? `${face.case === "upper" || look.case === "upper" ? "text-transform:uppercase;" : ""}${face.tracking ? `letter-spacing:${face.tracking}em;` : ""}` : look.case === "upper" ? "text-transform:uppercase;" : ""
|
|
153
199
|
const css = [
|
|
200
|
+
face && kit.shipped ? fontFaces(fontsFor(pageText, face.font)) : "",
|
|
154
201
|
`#area{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:center}`,
|
|
155
|
-
|
|
202
|
+
// A look that marks the spoken word by size wraps narrower, so the word can grow inside the box
|
|
203
|
+
`#t{max-width:${look.mark === "size" ? Math.floor(area.w / 1.2) : area.w}px;box-sizing:border-box;text-align:center;font-family:${family};font-weight:${look.weight};font-size:${size}px;line-height:${face ? lineFor(pageText, face.font, 1.18) : 1.18};color:${look.color};${plate}${stroke}${typeCss}${look.lines === 1 ? "white-space:nowrap;" : ""}}`,
|
|
156
204
|
`#t span{display:inline-block;white-space:pre}`,
|
|
157
205
|
`#t .e{color:${look.accent}}`,
|
|
206
|
+
look.arrive ? emphasisCss(look, size) : "",
|
|
158
207
|
].join("")
|
|
159
|
-
const duration = node.duration
|
|
160
208
|
// The person's corrected text is what shows (caption_edit): word by word when it has as many
|
|
161
209
|
// words as were said, else as one block (found in ED10: the edit wasn't drawn at all)
|
|
162
210
|
const said = node.words.map((w) => w.text).join(" ")
|
|
@@ -164,7 +212,7 @@ export function captionComposition(node, { output, canvas }) {
|
|
|
164
212
|
const shown = !edited ? node.words : edited.length === node.words.length ? node.words.map((w, i) => ({ ...w, text: edited[i] })) : [{ text: node.text, at: 0, end: duration, emphasis: false }]
|
|
165
213
|
const words = shown.map((word, i) => ({ ...word, id: `w${i}` }))
|
|
166
214
|
const body = `<div id="area"><div id="t" data-text>${words.map((w, i) => `<span id="${w.id}"${w.emphasis ? ' class="e"' : ""} data-at="${ms(w.at)}" data-end="${ms(w.end)}">${i ? " " : ""}${escapeText(w.text)}</span>`).join("")}</div></div>`
|
|
167
|
-
const animations = [{ id: "t", keyframes: springKeyframes({ ...ENTRANCE, from: { y: Math.round(size * 0.6), opacity: 0 }, to: { y: 0, opacity: 1 } }), options: { duration: ENTRANCE.ms, fill: "both" } }]
|
|
215
|
+
const animations = look.arrive ? arrivals(look, words, size, duration) : [{ id: "t", keyframes: springKeyframes({ ...ENTRANCE, from: { y: Math.round(size * 0.6), opacity: 0 }, to: { y: 0, opacity: 1 } }), options: { duration: ENTRANCE.ms, fill: "both" } }]
|
|
168
216
|
if (look.highlight) {
|
|
169
217
|
const total = Math.max(1, ms(duration))
|
|
170
218
|
for (const word of words) {
|
|
@@ -177,7 +225,64 @@ export function captionComposition(node, { output, canvas }) {
|
|
|
177
225
|
}
|
|
178
226
|
}
|
|
179
227
|
// A page fits its placement: the font steps down, never under QG-09's smallest size
|
|
180
|
-
|
|
228
|
+
// A kit page with a script font may step down to QG-09's own floor, not the Latin one (TP7)
|
|
229
|
+
const floor = face && fontsFor(pageText, face.font).length > 1 ? 0.0205 : 0.025
|
|
230
|
+
return tileDocument({ width: output.width, height: output.height, duration, css, body, animations, fit: { id: "t", within: "area", min: Math.ceil(output.height * floor) } })
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* ─────────────────────────────── TP7's looks ─────────────────────────────── */
|
|
234
|
+
|
|
235
|
+
// An emphasised word: in the accent, boxed, underlined or larger. A box keeps the page's ink and outline, on the accent moved until that ink holds 4.5:1
|
|
236
|
+
function emphasisCss(look, size) {
|
|
237
|
+
const pad = Math.round(size * 0.12)
|
|
238
|
+
const rules = {
|
|
239
|
+
color: `#t .e{color:${look.accent}}`,
|
|
240
|
+
box: `#t .e{color:${look.color};background:${boxFor(look.accent, look.color)};border-radius:${pad}px;padding:0 ${pad}px}`,
|
|
241
|
+
underline: `#t .e{box-shadow:inset 0 -${Math.max(3, Math.round(size * 0.12))}px 0 ${look.accent}}`,
|
|
242
|
+
size: `#t .e{color:${look.accent};font-size:1.15em}`,
|
|
243
|
+
}
|
|
244
|
+
return rules[look.emphasis] ?? ""
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Each word arrives as it is said, and the spoken word is marked while it is said. Timed on
|
|
249
|
+
* the tile's whole length, so a seek to any frame draws the same.
|
|
250
|
+
*/
|
|
251
|
+
function arrivals(look, words, size, duration) {
|
|
252
|
+
const total = Math.max(1, ms(duration))
|
|
253
|
+
const at = (t) => Math.min(1, Math.max(0, t / total))
|
|
254
|
+
const out = []
|
|
255
|
+
for (const word of words) {
|
|
256
|
+
// A word is fully in by the moment it is said, so a gate reading at a word's start sees it whole
|
|
257
|
+
const on = ms(word.at)
|
|
258
|
+
const arrive = look.arrive === "type" ? 260 : 220
|
|
259
|
+
const a = at(Math.max(0, on - arrive))
|
|
260
|
+
const b = Math.max(a, at(on))
|
|
261
|
+
const from = {
|
|
262
|
+
pop: { transform: "scale(0.6)", opacity: 0 },
|
|
263
|
+
rise: { transform: "scaleY(0.2)", transformOrigin: "50% 100%", opacity: 0 },
|
|
264
|
+
fade: { opacity: 0 },
|
|
265
|
+
type: { clipPath: "inset(0 100% 0 0)" },
|
|
266
|
+
}[look.arrive]
|
|
267
|
+
const to = { pop: { transform: "scale(1)", opacity: 1 }, rise: { transform: "scaleY(1)", transformOrigin: "50% 100%", opacity: 1 }, fade: { opacity: 1 }, type: { clipPath: "inset(0 0% 0 0)" } }[look.arrive]
|
|
268
|
+
out.push({ id: word.id, keyframes: [{ ...from, offset: 0 }, { ...from, offset: a }, { ...to, offset: b }, { ...to, offset: 1 }], options: { duration: total, fill: "both", easing: "linear" } })
|
|
269
|
+
if (look.mark === "none" || word.emphasis) continue
|
|
270
|
+
const lit = Math.max(b, at(ms(word.end)))
|
|
271
|
+
// A mark that doesn't touch what the arrival moves: colour, background, a shadow line, or the size (a second animation on font-size)
|
|
272
|
+
// The size mark is in em, so it follows the page the fit shrank
|
|
273
|
+
const mark = { color: ["color", look.color, look.accent], box: ["backgroundColor", `${boxFor(look.accent, look.color)}00`, boxFor(look.accent, look.color)], underline: ["boxShadow", `inset 0 0 0 ${look.accent}00`, `inset 0 -${Math.max(3, Math.round(size * 0.12))}px 0 ${look.accent}`], size: ["fontSize", "1em", "1.18em"] }[look.mark]
|
|
274
|
+
const [prop, base, on2] = mark
|
|
275
|
+
const frames = [{ [prop]: base, offset: 0 }, { [prop]: base, offset: b }, { [prop]: on2, offset: b }, { [prop]: on2, offset: lit }, { [prop]: base, offset: lit }, { [prop]: base, offset: 1 }]
|
|
276
|
+
out.push({ id: word.id, keyframes: frames, options: { duration: total, fill: "both", easing: "linear" } })
|
|
277
|
+
}
|
|
278
|
+
return out
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** When a page with arriving words is all in: QG-10 reads it then (ms into the tile). */
|
|
282
|
+
export function captionAtRest(node) {
|
|
283
|
+
const look = lookOf(node.look, node.style)
|
|
284
|
+
if (!look.arrive) return null
|
|
285
|
+
return Math.max(0, ...node.words.map((w) => ms(w.at))) + 320
|
|
181
286
|
}
|
|
182
287
|
|
|
183
288
|
/** Text for an element's content: markup can't get in (ES-05, ET-SEC-02). */
|
|
@@ -4,11 +4,18 @@
|
|
|
4
4
|
// loopback, no reading people's files, writing only to its own work folder.
|
|
5
5
|
|
|
6
6
|
import { existsSync, realpathSync } from "node:fs"
|
|
7
|
-
import { dirname } from "node:path"
|
|
7
|
+
import { dirname, join } from "node:path"
|
|
8
8
|
|
|
9
|
+
import { activeRuntime } from "../runtime/setup.js"
|
|
9
10
|
import { EngineFailure } from "./tool.js"
|
|
10
11
|
|
|
11
12
|
const SANDBOX_EXEC = "/usr/bin/sandbox-exec"
|
|
13
|
+
// TP11 (EQ-11): Linux's bubblewrap where the distribution puts it; never a PATH lookup a folder could shadow
|
|
14
|
+
export const BWRAP_PATHS = ["/usr/bin/bwrap", "/bin/bwrap", "/usr/local/bin/bwrap"]
|
|
15
|
+
// The system's own read-only parts a confined Chrome needs on Linux (libraries, fonts, certificates); never /home
|
|
16
|
+
const LINUX_SYSTEM = ["/usr", "/lib", "/lib64", "/lib32", "/bin", "/sbin", "/etc/fonts", "/etc/ssl", "/etc/ld.so.cache", "/etc/alternatives"]
|
|
17
|
+
// Windows: an AppContainer runner the Media Runtime ships and verifies by hash (manifest artifact), or nothing
|
|
18
|
+
export const WINDOWS_RUNNER = "appcontainer-runner"
|
|
12
19
|
// Where people's files and other programs' temporary files live
|
|
13
20
|
const PRIVATE = ["/Users", "/Volumes", "/private/tmp", "/private/var/folders", "/private/var/tmp"]
|
|
14
21
|
|
|
@@ -19,13 +26,80 @@ function quoted(path) {
|
|
|
19
26
|
return `"${path}"`
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The Windows runner the active Media Runtime installed, verified by hash at install: the manifest's
|
|
31
|
+
* `appcontainer-runner` artifact for win32-x64, present on disk. No signed manifest carries one yet (EQ-11).
|
|
32
|
+
* @returns {string | null}
|
|
33
|
+
*/
|
|
34
|
+
export function windowsRunner(runtime = activeRuntime(), exists = existsSync) {
|
|
35
|
+
const artifact = runtime?.manifest?.platforms?.["win32-x64"]?.artifacts?.find((a) => a.id === WINDOWS_RUNNER)
|
|
36
|
+
if (!artifact || typeof artifact.entry !== "string") return null
|
|
37
|
+
const path = join(runtime.dir, artifact.id, artifact.entry)
|
|
38
|
+
return exists(path) ? path : null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What this computer can confine with, or why it can't. Never an open process called confined (ES-05):
|
|
43
|
+
* macOS's sandbox-exec, Linux's bubblewrap, or the Windows runner the Media Runtime ships; else none.
|
|
44
|
+
* @returns {{ kind: "sandbox-exec" } | { kind: "bwrap", path: string } | { kind: "appcontainer", path: string } | { kind: null, missing: string }}
|
|
45
|
+
*/
|
|
46
|
+
export function confinement(platform = process.platform, exists = existsSync, { runner = () => windowsRunner(undefined, exists) } = {}) {
|
|
24
47
|
if (platform === "darwin" && exists(SANDBOX_EXEC)) return { kind: "sandbox-exec" }
|
|
25
|
-
|
|
48
|
+
if (platform === "linux") {
|
|
49
|
+
const path = BWRAP_PATHS.find((candidate) => exists(candidate))
|
|
50
|
+
if (path) return { kind: "bwrap", path }
|
|
51
|
+
return { kind: null, missing: "The motion layer runs Chrome inside bubblewrap on Linux, and it isn't installed. Install the bubblewrap package (bwrap), then try again." }
|
|
52
|
+
}
|
|
53
|
+
if (platform === "win32") {
|
|
54
|
+
const path = runner()
|
|
55
|
+
if (path) return { kind: "appcontainer", path }
|
|
56
|
+
return { kind: null, missing: "The motion layer runs Chrome inside an AppContainer on Windows, and this Media Runtime has no runner for it yet." }
|
|
57
|
+
}
|
|
26
58
|
return { kind: null, missing: "The motion layer runs Chrome inside the operating system's sandbox, and this system's sandbox isn't supported yet." }
|
|
27
59
|
}
|
|
28
60
|
|
|
61
|
+
// A path handed to a sandbox: absolute, and nothing that could end an argument or a line
|
|
62
|
+
function plain(path) {
|
|
63
|
+
if (!(path.startsWith("/") || /^[A-Za-z]:\\/.test(path)) || /["\n\r\0]/.test(path)) throw new RangeError(`a confinement path must be a plain absolute path, got "${path}"`)
|
|
64
|
+
return path
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Linux (TP11): bubblewrap's arguments. Every namespace unshared, the network too, so only a loopback of its
|
|
69
|
+
* own exists (Chrome and HyperFrames talk over it; nothing reaches another computer or this one's services);
|
|
70
|
+
* the system's libraries read-only; the runtime read-only; the tile's folder read-write; a private /tmp; it
|
|
71
|
+
* dies with its parent. No /home and no /Users unless a folder asked for sits there, and then only that folder.
|
|
72
|
+
* @param {{ read: string[], write: string[] }} paths absolute; made real here
|
|
73
|
+
*/
|
|
74
|
+
export function bwrapArgs({ read, write }, exists = existsSync) {
|
|
75
|
+
const r = [...new Set(read.map(real).map(plain))]
|
|
76
|
+
const w = [...new Set(write.map(real).map(plain))]
|
|
77
|
+
return [
|
|
78
|
+
"--die-with-parent",
|
|
79
|
+
"--new-session",
|
|
80
|
+
"--unshare-all",
|
|
81
|
+
"--cap-drop",
|
|
82
|
+
"ALL",
|
|
83
|
+
...LINUX_SYSTEM.filter((p) => exists(p)).flatMap((p) => ["--ro-bind", p, p]),
|
|
84
|
+
"--proc",
|
|
85
|
+
"/proc",
|
|
86
|
+
"--dev",
|
|
87
|
+
"/dev",
|
|
88
|
+
"--tmpfs",
|
|
89
|
+
"/tmp",
|
|
90
|
+
...r.flatMap((p) => ["--ro-bind", p, p]),
|
|
91
|
+
...w.flatMap((p) => ["--bind", p, p]),
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Windows (TP11): the runner's arguments, a seam for the runner the Media Runtime will ship. The folders it
|
|
97
|
+
* may read and write, loopback only, then the command. Nothing here runs until a verified runner exists.
|
|
98
|
+
*/
|
|
99
|
+
export function appContainerArgs({ read, write }) {
|
|
100
|
+
return [...read.map(plain).flatMap((p) => ["--read", p]), ...write.map(plain).flatMap((p) => ["--write", p]), "--network", "loopback", "--"]
|
|
101
|
+
}
|
|
102
|
+
|
|
29
103
|
/**
|
|
30
104
|
* The macOS profile. Later rules win in SBPL, so the denials come first and the few
|
|
31
105
|
* folders a render needs are let back in.
|
|
@@ -60,6 +134,9 @@ export function sandboxProfile({ read, write }) {
|
|
|
60
134
|
*/
|
|
61
135
|
export function confine(command, args, paths, which = confinement()) {
|
|
62
136
|
if (!which.kind) throw new EngineFailure("environment", "no_confinement", which.missing)
|
|
137
|
+
if (which.kind === "bwrap") return { command: which.path, args: [...bwrapArgs(paths), "--", command, ...args] }
|
|
138
|
+
if (which.kind === "appcontainer") return { command: which.path, args: [...appContainerArgs(paths), command, ...args] }
|
|
139
|
+
if (which.kind !== "sandbox-exec") throw new EngineFailure("environment", "no_confinement", "This sandbox isn't one Kriya knows.")
|
|
63
140
|
return { command: SANDBOX_EXEC, args: ["-p", sandboxProfile(paths), command, ...args] }
|
|
64
141
|
}
|
|
65
142
|
|