@kriya-ai/harness 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +379 -2
  2. package/SAFETY.md +162 -0
  3. package/THIRD_PARTY_NOTICES.md +7911 -0
  4. package/bin/kriya.js +577 -0
  5. package/bundle/cordis.patch.yml +397 -0
  6. package/contract/SOURCE.md +15 -0
  7. package/contract/contract.json +1355 -0
  8. package/package.json +57 -4
  9. package/plugins/anchor/index.js +56 -0
  10. package/plugins/anchor/package.json +13 -0
  11. package/plugins/approvals/index.js +183 -0
  12. package/plugins/approvals/package.json +13 -0
  13. package/plugins/brand/DESIGN.md +112 -0
  14. package/plugins/brand/client.js +826 -0
  15. package/plugins/brand/index.js +15 -0
  16. package/plugins/brand/package.json +25 -0
  17. package/plugins/brand/src/client.js +823 -0
  18. package/plugins/browser/index.js +218 -0
  19. package/plugins/browser/package.json +13 -0
  20. package/plugins/budget/index.js +108 -0
  21. package/plugins/budget/package.json +13 -0
  22. package/plugins/changes/client.js +245 -0
  23. package/plugins/changes/index.js +75 -0
  24. package/plugins/changes/package.json +22 -0
  25. package/plugins/edit/client.js +113 -0
  26. package/plugins/edit/index.js +58 -0
  27. package/plugins/edit/package.json +23 -0
  28. package/plugins/fs-freshness/index.js +28 -0
  29. package/plugins/fs-freshness/package.json +13 -0
  30. package/plugins/graph/client.js +178 -0
  31. package/plugins/graph/index.js +4 -0
  32. package/plugins/graph/package.json +22 -0
  33. package/plugins/kriya-handoff/index.js +194 -0
  34. package/plugins/kriya-handoff/package.json +13 -0
  35. package/plugins/kriya-tools/index.js +189 -0
  36. package/plugins/kriya-tools/package.json +13 -0
  37. package/plugins/loop/index.js +743 -0
  38. package/plugins/loop/package.json +13 -0
  39. package/plugins/mirror/index.js +235 -0
  40. package/plugins/mirror/package.json +13 -0
  41. package/plugins/overview/client.js +276 -0
  42. package/plugins/overview/index.js +95 -0
  43. package/plugins/overview/package.json +22 -0
  44. package/plugins/preview/client.js +337 -0
  45. package/plugins/preview/index.js +4 -0
  46. package/plugins/preview/package.json +22 -0
  47. package/plugins/progress/client.js +290 -0
  48. package/plugins/progress/index.js +100 -0
  49. package/plugins/progress/package.json +22 -0
  50. package/plugins/projects/client.js +249 -0
  51. package/plugins/projects/index.js +30 -0
  52. package/plugins/projects/package.json +24 -0
  53. package/plugins/rea/index.js +256 -0
  54. package/plugins/rea/package.json +10 -0
  55. package/plugins/rea/skill/LICENSE +21 -0
  56. package/plugins/rea/skill/SKILL.md +360 -0
  57. package/plugins/rea/skill/references/android-applications.md +36 -0
  58. package/plugins/rea/skill/references/connection-and-recovery.md +127 -0
  59. package/plugins/rea/skill/references/evidence-workflows.md +71 -0
  60. package/plugins/rea/skill/references/javascript-applications.md +218 -0
  61. package/plugins/rea/skill/references/native-and-artifacts.md +297 -0
  62. package/plugins/rea/skill/references/runtime-observation.md +78 -0
  63. package/plugins/remote/index.js +297 -0
  64. package/plugins/remote/package.json +10 -0
  65. package/plugins/router/index.js +84 -0
  66. package/plugins/router/package.json +13 -0
  67. package/plugins/sessions/client.js +68 -0
  68. package/plugins/sessions/index.js +79 -0
  69. package/plugins/sessions/package.json +20 -0
  70. package/plugins/skills/client.js +504 -0
  71. package/plugins/skills/index.js +166 -0
  72. package/plugins/skills/package.json +23 -0
  73. package/src/api.js +97 -0
  74. package/src/browser.js +286 -0
  75. package/src/changes.js +191 -0
  76. package/src/checkpoints.js +313 -0
  77. package/src/daemon.js +503 -0
  78. package/src/doctor.js +137 -0
  79. package/src/edit/core/anchors.js +102 -0
  80. package/src/edit/core/audio.js +158 -0
  81. package/src/edit/core/faces.js +99 -0
  82. package/src/edit/core/ffmpeg.js +258 -0
  83. package/src/edit/core/handoff.js +220 -0
  84. package/src/edit/core/history.js +90 -0
  85. package/src/edit/core/layout.js +92 -0
  86. package/src/edit/core/mix.js +115 -0
  87. package/src/edit/core/ops.js +602 -0
  88. package/src/edit/core/plan.js +266 -0
  89. package/src/edit/core/project.d.ts +134 -0
  90. package/src/edit/core/project.js +307 -0
  91. package/src/edit/core/reframe.js +125 -0
  92. package/src/edit/core/solver.js +416 -0
  93. package/src/edit/core/time.js +110 -0
  94. package/src/edit/core/tonemap.js +57 -0
  95. package/src/edit/director/ask.js +120 -0
  96. package/src/edit/director/gateway.js +16 -0
  97. package/src/edit/director/revise.js +186 -0
  98. package/src/edit/engine/capabilities.js +33 -0
  99. package/src/edit/engine/captions.js +154 -0
  100. package/src/edit/engine/color.js +269 -0
  101. package/src/edit/engine/confine.js +67 -0
  102. package/src/edit/engine/dna.js +148 -0
  103. package/src/edit/engine/index.js +473 -0
  104. package/src/edit/engine/loudness.js +43 -0
  105. package/src/edit/engine/media.js +57 -0
  106. package/src/edit/engine/motion.js +281 -0
  107. package/src/edit/engine/packs.js +87 -0
  108. package/src/edit/engine/probe.js +101 -0
  109. package/src/edit/engine/receipt.js +123 -0
  110. package/src/edit/engine/tool.js +101 -0
  111. package/src/edit/gates/copy.js +113 -0
  112. package/src/edit/gates/index.js +430 -0
  113. package/src/edit/gates/picture.js +130 -0
  114. package/src/edit/gates/sound.js +58 -0
  115. package/src/edit/gates/speech.js +127 -0
  116. package/src/edit/gates/text.js +196 -0
  117. package/src/edit/gates/text.swift +22 -0
  118. package/src/edit/graph/index.js +139 -0
  119. package/src/edit/graph/journal.js +69 -0
  120. package/src/edit/graph/scheduler.js +79 -0
  121. package/src/edit/host/client.js +58 -0
  122. package/src/edit/host/deliver.js +119 -0
  123. package/src/edit/host/jobs.js +84 -0
  124. package/src/edit/host/main.js +135 -0
  125. package/src/edit/host/paths.js +11 -0
  126. package/src/edit/host/projects.js +415 -0
  127. package/src/edit/host/server.js +391 -0
  128. package/src/edit/host/taste.js +135 -0
  129. package/src/edit/host/tavi.js +417 -0
  130. package/src/edit/host/watch.js +141 -0
  131. package/src/edit/index/db.js +109 -0
  132. package/src/edit/index/index.js +236 -0
  133. package/src/edit/index/layers/faces.js +78 -0
  134. package/src/edit/index/layers/faces.swift +18 -0
  135. package/src/edit/index/layers/meta.js +35 -0
  136. package/src/edit/index/layers/music.js +146 -0
  137. package/src/edit/index/layers/quality.js +120 -0
  138. package/src/edit/index/layers/retakes.js +132 -0
  139. package/src/edit/index/layers/screen.js +99 -0
  140. package/src/edit/index/layers/shots.js +29 -0
  141. package/src/edit/index/layers/sound.js +42 -0
  142. package/src/edit/index/layers/words.js +64 -0
  143. package/src/edit/index/story.js +248 -0
  144. package/src/edit/index/views.js +71 -0
  145. package/src/edit/loop/governor.js +112 -0
  146. package/src/edit/loop/loop.js +69 -0
  147. package/src/edit/loop/make.js +115 -0
  148. package/src/edit/loop/repair.js +97 -0
  149. package/src/edit/loop/replay.js +32 -0
  150. package/src/edit/recipes/multicam.js +461 -0
  151. package/src/edit/recipes/reel.js +202 -0
  152. package/src/edit/recipes/short-from-long.js +237 -0
  153. package/src/edit/recipes/tutorial.js +137 -0
  154. package/src/edit/recipes/youtube.js +155 -0
  155. package/src/edit/runtime/cli.js +126 -0
  156. package/src/edit/runtime/doctor.js +122 -0
  157. package/src/edit/runtime/fetch.js +15 -0
  158. package/src/edit/runtime/licences.js +88 -0
  159. package/src/edit/runtime/manifest.js +73 -0
  160. package/src/edit/runtime/setup.js +252 -0
  161. package/src/failure.js +69 -0
  162. package/src/gateway-proxy.js +213 -0
  163. package/src/intent.js +130 -0
  164. package/src/launch.js +315 -0
  165. package/src/live.js +81 -0
  166. package/src/local-skills.js +284 -0
  167. package/src/login.js +82 -0
  168. package/src/loop.js +428 -0
  169. package/src/modes.js +128 -0
  170. package/src/overview.js +71 -0
  171. package/src/paths.js +30 -0
  172. package/src/profiles.js +92 -0
  173. package/src/projects.js +104 -0
  174. package/src/recon.js +244 -0
  175. package/src/rules.js +139 -0
  176. package/src/runner.bundle.js +21172 -0
  177. package/src/sentinel.js +248 -0
  178. package/src/skill-switches.js +130 -0
  179. package/src/store.js +58 -0
  180. package/src/strict.js +124 -0
  181. package/src/verify.js +659 -0
  182. package/src/world.js +268 -0
  183. package/studio/dist/index.html +14 -0
  184. package/studio/dist/studio.css +163 -0
  185. package/studio/dist/studio.js +1 -0
@@ -0,0 +1,126 @@
1
+ // `kriya edit setup` and `kriya edit doctor`, loaded only with the switch on.
2
+
3
+ import { KriyaError } from "../../api.js"
4
+ import { kriyaHome } from "../../paths.js"
5
+ import { readDevice } from "../../store.js"
6
+ import { checkRuntime } from "./doctor.js"
7
+ import { fetchManifest } from "./fetch.js"
8
+ import { RuntimeError } from "./manifest.js"
9
+ import { install, installPack, removePack, rollback } from "./setup.js"
10
+
11
+ const USAGE = `Usage:
12
+ kriya edit start the Edit Host and print the Studio's link
13
+ kriya edit setup [--rollback] install the Media Runtime, or go back to the last one
14
+ kriya edit setup --pack <name> add a capability pack (color, voice-clean, depth)
15
+ kriya edit setup --remove-pack <name>
16
+ remove one; the rest of the runtime stays
17
+ kriya edit doctor what this computer has for editing
18
+ kriya edit verify <file> [--receipt <file>]
19
+ re-measure an export against its receipt
20
+ kriya edit replay <job> re-run a make job from its recording, with no model call
21
+ kriya edit watch [<folder>] tell Kriya about new recordings there (name and duration only);
22
+ with no folder, list them. Nothing runs until you tap the card
23
+ kriya edit unwatch <folder> stop`
24
+
25
+ export async function editCommand([action, ...rest], { say = (line) => process.stdout.write(`${line}\n`) } = {}) {
26
+ try {
27
+ if (action === undefined) {
28
+ const { ensureHost, hostCall } = await import("../host/client.js")
29
+ await ensureHost()
30
+ say((await hostCall(kriyaHome(), "POST", "/internal/launch")).url)
31
+ return 0
32
+ }
33
+ if ((action === "watch" && rest.length <= 1) || (action === "unwatch" && rest.length === 1)) {
34
+ const { unwatchFolder, watchedFolders, watchFolder } = await import("../host/watch.js")
35
+ const { ensureHost } = await import("../host/client.js")
36
+ const home = kriyaHome()
37
+ if (action === "unwatch") {
38
+ say(unwatchFolder(rest[0], { home }) ? `Stopped watching ${rest[0]}.` : "That folder wasn't being watched.")
39
+ return 0
40
+ }
41
+ if (!rest.length) {
42
+ const folders = watchedFolders({ home })
43
+ say(folders.length ? folders.join("\n") : "No folder is being watched.")
44
+ return 0
45
+ }
46
+ try {
47
+ const folder = watchFolder(rest[0], { home })
48
+ await ensureHost()
49
+ say(`Watching ${folder}. What's there now counts as old. It needs to be a folder \`kriya daemon\` offers.`)
50
+ return 0
51
+ } catch (error) {
52
+ say(error.code === "ENOENT" ? "There's no such folder." : error.message)
53
+ return 1
54
+ }
55
+ }
56
+ if (action === "doctor" && rest.length === 0) return (await checkRuntime({ say })).ok ? 0 : 1
57
+ if (action === "verify" && (rest.length === 1 || (rest.length === 3 && rest[1] === "--receipt"))) return await verifyCommand(rest[0], rest[2], say)
58
+ if (action === "replay" && rest.length === 1) return await replayCommand(rest[0], say)
59
+ if (action === "setup" && rest.length === 1 && rest[0] === "--rollback") {
60
+ say(`Back on Media Runtime ${rollback().version}.`)
61
+ return 0
62
+ }
63
+ if (action === "setup" && rest.length === 2 && rest[0] === "--remove-pack") {
64
+ removePack(`pack-${rest[1]}`)
65
+ say(`Removed the ${rest[1]} pack.`)
66
+ return 0
67
+ }
68
+ if (action === "setup" && rest.length === 2 && rest[0] === "--pack") {
69
+ const { PACKS } = await import("../engine/packs.js")
70
+ const pack = PACKS[`pack-${rest[1]}`]
71
+ if (!pack) return say(`There is no ${rest[1]} pack. Packs: ${Object.keys(PACKS).map((id) => id.slice(5)).join(", ")}.`), 1
72
+ if (!pack.artifacts.length) return say(`The ${pack.title} pack comes with FFmpeg; there is nothing to download. kriya edit doctor says whether this FFmpeg has what it needs.`), 0
73
+ const device = readDevice()
74
+ if (!device) {
75
+ say("Run `kriya login` to connect your Kriya account.")
76
+ return 1
77
+ }
78
+ await installPack(await fetchManifest(device), `pack-${rest[1]}`, { say })
79
+ return 0
80
+ }
81
+ if (action === "setup" && rest.length === 0) {
82
+ const device = readDevice()
83
+ if (!device) {
84
+ say("Run `kriya login` to connect your Kriya account.")
85
+ return 1
86
+ }
87
+ await install(await fetchManifest(device), { say })
88
+ return 0
89
+ }
90
+ say(USAGE)
91
+ return 1
92
+ } catch (error) {
93
+ if (!(error instanceof RuntimeError || error instanceof KriyaError)) throw error
94
+ say(error.message)
95
+ return 1
96
+ }
97
+ }
98
+
99
+ async function verifyCommand(file, receiptFile, say) {
100
+ const { existsSync } = await import("node:fs")
101
+ const { readReceipt, receiptPath, verifyFile } = await import("../engine/receipt.js")
102
+ const receipt = receiptFile ?? receiptPath(file)
103
+ if (!existsSync(file)) return say(`There is no file ${file}.`), 1
104
+ if (!existsSync(receipt)) return say(`There is no receipt at ${receipt}.`), 1
105
+ const result = await verifyFile(file, readReceipt(receipt))
106
+ if (result.ok) say(`${file} is the file its receipt describes, byte for byte.`)
107
+ else for (const line of [`${file} doesn't match its receipt:`, ...result.differences.map((d) => ` ${d}`)]) say(line)
108
+ return result.ok ? 0 : 1
109
+ }
110
+
111
+ async function replayCommand(job, say) {
112
+ const { ensureHost, hostCall } = await import("../host/client.js")
113
+ await ensureHost()
114
+ const started = await hostCall(kriyaHome(), "POST", `/jobs/${job}/replay`)
115
+ for (;;) {
116
+ const row = (await hostCall(kriyaHome(), "GET", "/jobs")).jobs.find((j) => j.id === started.id)
117
+ if (row && ["done", "failed", "canceled"].includes(row.status)) {
118
+ if (row.status !== "done") return say(`The replay ${row.status}: ${row.error ?? ""}`.trim()), 1
119
+ const result = JSON.parse(row.output)
120
+ say(`Replayed ${result.replayOf} with no model call: verdict ${result.verdict}.`)
121
+ for (const line of result.same ? ["Same verdict, plan and gates as the first run."] : ["It differs from the first run:", ...result.differences.map((d) => ` ${d}`)]) say(line)
122
+ return result.same ? 0 : 1
123
+ }
124
+ await new Promise((done) => setTimeout(done, 500))
125
+ }
126
+ }
@@ -0,0 +1,122 @@
1
+ // `kriya edit doctor`: what this computer has for editing, each with a plain fix.
2
+ // Exit code 0 only when every check passes, as `kriya doctor`.
3
+
4
+ import { accessSync, constants, existsSync, statfsSync } from "node:fs"
5
+ import { cpus, totalmem } from "node:os"
6
+ import { dirname, join } from "node:path"
7
+
8
+ import { syncedFolder } from "../../doctor.js"
9
+ import { kriyaHome } from "../../paths.js"
10
+ import { activeRuntime, platformId, runChild } from "./setup.js"
11
+
12
+ const SUPPORTED = ["darwin-arm64"]
13
+ // EX-09 measured about 4.8 GB for everything on a Mac
14
+ const MIN_FREE = 5e9
15
+ // Used until a runtime is installed; after that its manifest decides
16
+ const SYSTEM = [
17
+ { id: "ffmpeg", minVersion: "6.0", fix: "brew install ffmpeg" },
18
+ { id: "uv", minVersion: "0.13.0", fix: "brew install uv" },
19
+ ]
20
+ const HARDWARE_ENCODERS = ["h264_videotoolbox", "hevc_videotoolbox"]
21
+
22
+ const older = (version, minimum) => {
23
+ if (!/^\d/.test(version)) return false // a development build names no number to compare
24
+ const [a, b] = [version, minimum].map((v) => v.split(".").map((part) => Number.parseInt(part, 10) || 0))
25
+ for (let i = 0; i < Math.max(a.length, b.length); i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) < (b[i] ?? 0)
26
+ return false
27
+ }
28
+
29
+ const attempt = async (run, command, args) => {
30
+ try {
31
+ return await run(command, args)
32
+ } catch {
33
+ return null
34
+ }
35
+ }
36
+
37
+ const versionOf = (output) => /version (\S+)/.exec(output ?? "")?.[1] ?? null
38
+
39
+ // shortcut: 16 GB is a judgement, not a measurement, EX runs on a slower laptop (SPIKES §3) should settle it
40
+ export const hardwareTier = ({ memory, metal }) => (metal && memory >= 16 * 2 ** 30 ? "standard" : "core")
41
+
42
+ function nearestFolder(path) {
43
+ let dir = path
44
+ while (!existsSync(dir)) dir = dirname(dir)
45
+ return dir
46
+ }
47
+
48
+ const freeBytes = (dir) => {
49
+ const { bavail, bsize } = statfsSync(nearestFolder(dir))
50
+ return Number(bavail) * Number(bsize)
51
+ }
52
+
53
+ const executable = (path) => {
54
+ try {
55
+ accessSync(path, constants.X_OK)
56
+ return true
57
+ } catch {
58
+ return false
59
+ }
60
+ }
61
+
62
+ /** @returns {Promise<{ ok: boolean, ffmpeg: string | null, encoders: string[], metal: boolean, tier: string, runtime: string | null }>} */
63
+ export async function checkRuntime({ home = kriyaHome(), platform = platformId(), run = runChild(home), free = freeBytes, memory = totalmem(), cpu = cpus()[0]?.model ?? "unknown", cwd = process.cwd(), say = (line) => process.stdout.write(`${line}\n`) } = {}) {
64
+ let ok = true
65
+ const check = (pass, label, fix) => {
66
+ ok &&= pass
67
+ say(`${pass ? "ok " : "FAIL"} ${label}${pass || !fix ? "" : ` — ${fix}`}`)
68
+ }
69
+
70
+ check(SUPPORTED.includes(platform), `computer: ${platform}`, "macOS on Apple silicon comes first; this one isn't supported yet")
71
+
72
+ const runtime = activeRuntime(home)
73
+ const spec = runtime?.manifest.platforms[platform]
74
+ const system = spec?.system ?? SYSTEM
75
+ const need = (id) => system.find((tool) => tool.id === id)
76
+
77
+ const ffmpeg = versionOf(await attempt(run, "ffmpeg", ["-version"]))
78
+ const ffprobe = versionOf(await attempt(run, "ffprobe", ["-version"]))
79
+ const { minVersion, fix } = need("ffmpeg")
80
+ if (!ffmpeg) check(false, "FFmpeg", fix)
81
+ else if (older(ffmpeg, minVersion)) check(false, `FFmpeg ${ffmpeg} is older than ${minVersion}`, fix)
82
+ else if (ffprobe !== ffmpeg) check(false, `ffprobe ${ffprobe ?? "is missing and"} doesn't match FFmpeg ${ffmpeg}`, fix)
83
+ else check(true, `FFmpeg ${ffmpeg}`)
84
+
85
+ const list = ffmpeg ? ((await attempt(run, "ffmpeg", ["-hide_banner", "-encoders"])) ?? "") : ""
86
+ const encoders = HARDWARE_ENCODERS.filter((name) => new RegExp(`\\b${name}\\b`).test(list))
87
+ if (encoders.length) check(true, `hardware encoders: ${encoders.join(", ")}`)
88
+ else if (ffmpeg) say("note no hardware encoder in this FFmpeg, so drafts render on the CPU")
89
+
90
+ // Homebrew's plain ffmpeg has neither (EF-37): captions go through tiles, and HDR through a LUT
91
+ const filters = ffmpeg ? await attempt(run, "ffmpeg", ["-hide_banner", "-filters"]) : null
92
+ if (filters && !/\bdrawtext\b/.test(filters)) say("note this FFmpeg has no drawtext, so captions render as tiles (ED8), not burned in directly")
93
+
94
+ const uv = /^uv (\S+)/.exec((await attempt(run, "uv", ["--version"])) ?? "")?.[1]
95
+ const needUv = need("uv")
96
+ check(!!uv && !older(uv, needUv.minVersion), uv ? `uv ${uv}` : "uv", needUv.fix)
97
+
98
+ const display = platform.startsWith("darwin") ? await attempt(run, "system_profiler", ["SPDisplaysDataType"]) : null
99
+ const metal = /Metal/.test(display ?? "")
100
+ if (metal) check(true, "Metal")
101
+ else say("note no Metal GPU found; heavy layers stay off")
102
+
103
+ const tier = hardwareTier({ memory, metal })
104
+ say(`ok machine: ${cpu}, ${Math.round(memory / 2 ** 30)} GB memory`)
105
+ say(`ok hardware tier: ${tier}`)
106
+
107
+ const available = free(home)
108
+ check(available >= MIN_FREE, `disk: ${(available / 1e9).toFixed(0)} GB free`, `the runtime and its cache need about ${(MIN_FREE / 1e9).toFixed(0)} GB`)
109
+
110
+ if (!runtime || !spec) check(false, "Media Runtime", "run kriya edit setup")
111
+ else {
112
+ check(true, `Media Runtime ${runtime.version}`)
113
+ for (const artifact of spec.artifacts) check(executable(join(runtime.dir, artifact.id, artifact.entry)), `${artifact.id} ${artifact.version}`, "run kriya edit setup")
114
+ const { id, check: module } = spec.python
115
+ const imported = await attempt(run, join(runtime.dir, "python", "bin", "python"), ["-c", `import ${module}`])
116
+ check(imported !== null, `${id}: ${module}`, "run kriya edit setup")
117
+ }
118
+
119
+ const synced = syncedFolder(cwd)
120
+ if (synced) say(`note ${synced}`)
121
+ return { ok, ffmpeg, encoders, metal, tier, runtime: runtime?.version ?? null }
122
+ }
@@ -0,0 +1,15 @@
1
+ // The one place the runtime talks to Kriya, kept apart from manifest.js so the
2
+ // Engine can use the rest with no path to the API client (ARCHITECTURE §6).
3
+
4
+ import { call, KriyaError } from "../../api.js"
5
+ import { openManifest, RuntimeError, TRUSTED_KEYS } from "./manifest.js"
6
+
7
+ /** The manifest for this device. A 404 is how a client learns this Kriya has no editing (EH-01). */
8
+ export async function fetchManifest(device, trusted = TRUSTED_KEYS) {
9
+ try {
10
+ return openManifest(await call(device.url, "GET", "/editing/manifest", { token: device.token }), trusted)
11
+ } catch (error) {
12
+ if (error instanceof KriyaError && error.status === 404) throw new RuntimeError("Editing isn't available on your Kriya yet.")
13
+ throw error
14
+ }
15
+ }
@@ -0,0 +1,88 @@
1
+ // The licence gate (SKILLS_AND_OPEN_SOURCE §2, ET-LIC-01), per item: every package,
2
+ // runtime artifact, Python package, pack weight and bundled file has a licence in the
3
+ // table, or nothing ships. Checked in the test suite against the lockfile, the Studio
4
+ // bundle's metafile and the runtime manifest, and again when a runtime or a pack is
5
+ // installed. Remotion (EDD-08) and GSAP (EDD-09) are refused by name, wherever they appear.
6
+
7
+ /** Allowed outright, with notices. */
8
+ export const ALLOWED = ["MIT", "BSD-2-Clause", "BSD-3-Clause", "ISC", "Apache-2.0", "Unlicense", "CC0-1.0", "0BSD", "BlueOak-1.0.0", "Python-2.0"]
9
+ /** Allowed only where the table says. */
10
+ export const CONDITIONAL = {
11
+ "OFL-1.1": "fonts only",
12
+ "MPL-2.0": "unmodified, as a dependency",
13
+ "LGPL-2.1-or-later": "a separate process or library (FFmpeg, EQ-02)",
14
+ "LGPL-3.0-or-later": "a separate process or library",
15
+ }
16
+ /** The owner's alpha exception (2026-11-07, EQ-15): the Media Runtime only, pending counsel. */
17
+ export const RUNTIME_ONLY = ["PSF-2.0", "CNRI-Python", "Zlib"]
18
+ /** Never, whatever the item. */
19
+ export const REFUSED_LICENCES = /\b(CC-BY-NC|PolyForm-Noncommercial|AGPL|GPL-[23]\.0(?!-or-later.*LGPL)|SSPL|BUSL|Commons-Clause)\b/i
20
+ /** Refused by owner decision, by name. */
21
+ export const REFUSED_NAMES = /(^|[/@])(remotion|gsap)([/@-]|$)/i
22
+
23
+ // SPDX ids start with a capital or a digit (0BSD); lower-case words are prose; the word after WITH is an exception, not a licence
24
+ function ids(text) {
25
+ const out = []
26
+ const words = text.replace(/[()]/g, " ").split(/\s+/)
27
+ for (let i = 0; i < words.length; i++) {
28
+ if (words[i] === "WITH") i++
29
+ else if (!/^(AND|OR)$/.test(words[i]) && /^[A-Z0-9][A-Za-z0-9.+-]*$/.test(words[i])) out.push(words[i])
30
+ }
31
+ return out
32
+ }
33
+
34
+ /**
35
+ * Whether a licence expression may ship `where`: "client" (the npm release and
36
+ * the Studio), "runtime" (Media Runtime artifacts and Python packages) or "weight".
37
+ * SPDX ids decide; a choice (OR) passes when one side does; prose after the ids
38
+ * ("and third-party notices") is a note, not a licence.
39
+ * @returns {{ ok: boolean, why: string }}
40
+ */
41
+ export function licenceVerdict(expression, where = "client") {
42
+ const text = String(expression ?? "").trim()
43
+ if (!text) return { ok: false, why: "no licence is recorded, which means all rights reserved" }
44
+ const fits = (id) => ALLOWED.includes(id) || id in CONDITIONAL || (where === "runtime" && RUNTIME_ONLY.includes(id))
45
+ const sides = text.split(/\s+OR\s+/).map((side) => ({ side, ids: ids(side) }))
46
+ const good = sides.find(({ side, ids: list }) => list.length && !REFUSED_LICENCES.test(side) && list.every(fits))
47
+ if (good) return { ok: true, why: good.ids.filter((id) => id in CONDITIONAL).map((id) => `${id}: ${CONDITIONAL[id]}`).join("; ") }
48
+ if (sides.every(({ ids: list }) => !list.length)) return { ok: false, why: `"${text}" names no licence the table knows` }
49
+ if (REFUSED_LICENCES.test(text)) return { ok: false, why: `${text} is outside the licence table` }
50
+ const unfit = [...new Set(sides.flatMap(({ ids: list }) => list.filter((id) => !fits(id))))]
51
+ return { ok: false, why: `${unfit.join(", ")} isn't allowed for the ${where}` }
52
+ }
53
+
54
+ /**
55
+ * Every licence in a runtime manifest: artifacts, Python packages and pack weights.
56
+ * @returns {{ item: string, problem: string }[]}
57
+ */
58
+ export function manifestLicenceProblems(data) {
59
+ const problems = []
60
+ const check = (item, licence, where) => {
61
+ if (REFUSED_NAMES.test(item)) problems.push({ item, problem: "refused by the owner (Remotion, EDD-08; GSAP, EDD-09)" })
62
+ const verdict = licenceVerdict(licence, where)
63
+ if (!verdict.ok) problems.push({ item, problem: verdict.why })
64
+ }
65
+ for (const [platform, spec] of Object.entries(data?.platforms ?? {})) {
66
+ for (const artifact of spec.artifacts ?? []) check(`${platform}/${artifact.id}`, artifact.licence, "runtime")
67
+ for (const pkg of spec.python?.packages ?? []) check(`${platform}/python/${pkg.name}`, pkg.licence, "runtime")
68
+ for (const [pack, offered] of Object.entries(spec.packs ?? {})) for (const artifact of offered.artifacts ?? []) check(`${platform}/${pack}/${artifact.id}`, artifact.licence, "weight")
69
+ }
70
+ return problems
71
+ }
72
+
73
+ /**
74
+ * The npm side: refused names anywhere in the lockfile (dev tools included), and the
75
+ * Studio bundle taking in nothing but its own code (esbuild's metafile).
76
+ * @param {{ lock: object, metafile?: { inputs: Record<string, unknown> }, sources?: { file: string, text: string }[] }} input
77
+ * @returns {{ item: string, problem: string }[]}
78
+ */
79
+ export function bundleLicenceProblems({ lock, metafile, sources = [] }) {
80
+ const problems = []
81
+ for (const path of Object.keys(lock?.packages ?? {})) {
82
+ const name = path.replace(/^.*node_modules\//, "")
83
+ if (name && REFUSED_NAMES.test(name)) problems.push({ item: name, problem: "refused by the owner (Remotion, EDD-08; GSAP, EDD-09)" })
84
+ }
85
+ for (const input of Object.keys(metafile?.inputs ?? {})) if (!/(^|\/)studio\/src\//.test(input)) problems.push({ item: input, problem: "the Studio bundle took in code from outside studio/src, with no licence recorded" })
86
+ for (const { file, text } of sources) if (/\b(?:from|import\(|require\()\s*["'](?:@?remotion|gsap)(?:["'/])/.test(text)) problems.push({ item: file, problem: "imports Remotion or GSAP" })
87
+ return problems
88
+ }
@@ -0,0 +1,73 @@
1
+ // The Media Runtime manifest (DECISIONS EDD-05, ES-08): fetched from Kriya, and
2
+ // trusted only when a key pinned here signed those exact bytes. The private key
3
+ // stays offline with the owner, so a compromised web service can't sign one.
4
+
5
+ import { createHash, createPublicKey, verify } from "node:crypto"
6
+ import { createReadStream } from "node:fs"
7
+
8
+ /** Ed25519 public keys, base64 SPKI DER, from `npx tsx lib/editing/sign.ts keygen` in Kriya. */
9
+ export const TRUSTED_KEYS = []
10
+
11
+ export class RuntimeError extends Error {}
12
+
13
+ const signedBy = (text, signature, key) => {
14
+ try {
15
+ return verify(null, Buffer.from(text), createPublicKey({ key: Buffer.from(key, "base64"), format: "der", type: "spki" }), Buffer.from(signature, "base64"))
16
+ } catch {
17
+ return false
18
+ }
19
+ }
20
+
21
+ const bad = (what) => {
22
+ throw new RuntimeError(`The runtime manifest is invalid: ${what}.`)
23
+ }
24
+
25
+ const isLoopback = (url) => url.protocol === "http:" && url.hostname === "127.0.0.1"
26
+
27
+ function checkArtifact(artifact) {
28
+ if (!/^[a-z0-9][a-z0-9-]*$/.test(artifact.id)) bad("an artifact id isn't safe")
29
+ if (!/^[0-9a-f]{64}$/.test(artifact.sha256)) bad(`${artifact.id} has no sha256`)
30
+ if (!Number.isSafeInteger(artifact.bytes) || artifact.bytes <= 0) bad(`${artifact.id} has no size`)
31
+ if (!["none", "zip"].includes(artifact.unpack)) bad(`${artifact.id} can't be unpacked that way`)
32
+ if (artifact.entry.startsWith("/") || artifact.entry.split("/").includes("..")) bad(`${artifact.id} points outside the runtime`)
33
+ const url = new URL(artifact.url)
34
+ if (url.protocol !== "https:" && !isLoopback(url)) bad(`${artifact.id} isn't on https`)
35
+ }
36
+
37
+ function checkManifest(data) {
38
+ if (data?.schema !== 1) bad("this client doesn't know its schema")
39
+ if (!/^\d+\.\d+\.\d+$/.test(data.version)) bad("its version isn't safe")
40
+ for (const platform of Object.values(data.platforms ?? {})) {
41
+ platform.artifacts.forEach(checkArtifact)
42
+ // Capability packs (ED13): each artifact pinned by hash, with its licence recorded (ET-PK-03)
43
+ for (const [id, pack] of Object.entries(platform.packs ?? {})) {
44
+ if (!/^pack-[a-z0-9-]+$/.test(id)) bad("a pack's name isn't safe")
45
+ if (!Array.isArray(pack.artifacts) || !pack.artifacts.length) bad(`${id} has nothing to install`)
46
+ for (const artifact of pack.artifacts) {
47
+ checkArtifact(artifact)
48
+ if (typeof artifact.licence !== "string" || !artifact.licence.trim()) bad(`${artifact.id} has no licence recorded`)
49
+ }
50
+ }
51
+ if (!/^\d+\.\d+$/.test(platform.python.version)) bad("its Python version isn't exact")
52
+ if (!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(platform.python.check)) bad("its Python check isn't a module name")
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Verifies the signature over the exact text, then reads it.
58
+ * @param {{ manifest: string, signature: string | null }} body
59
+ * @param {string[]} trusted
60
+ * @returns {{ text: string, data: object }}
61
+ */
62
+ export function openManifest({ manifest, signature }, trusted = TRUSTED_KEYS) {
63
+ if (!signature || !trusted.some((key) => signedBy(manifest, signature, key))) throw new RuntimeError("This runtime isn't signed by a key this client trusts, so it won't be installed.")
64
+ const data = JSON.parse(manifest)
65
+ checkManifest(data)
66
+ return { text: manifest, data }
67
+ }
68
+
69
+ export async function fileSha256(path) {
70
+ const hash = createHash("sha256")
71
+ for await (const chunk of createReadStream(path)) hash.update(chunk)
72
+ return hash.digest("hex")
73
+ }