@litfamily/litcodex 1.0.28 → 1.0.30

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 (170) hide show
  1. package/README-Ko-KR.md +10 -10
  2. package/README.md +10 -10
  3. package/dist/cli.js +1 -1
  4. package/dist/config-migration/cli.js +11 -3
  5. package/dist/install/generated-skill-payload-hashes.d.ts +59 -31
  6. package/dist/install/generated-skill-payload-hashes.js +59 -31
  7. package/dist/install/index.js +1 -1
  8. package/dist/install/marketplace.js +10 -1
  9. package/dist/install/motion-runtime.d.ts +4 -1
  10. package/dist/install/motion-runtime.js +15 -4
  11. package/dist/install/office-runtime.d.ts +10 -11
  12. package/dist/install/office-runtime.js +8 -3
  13. package/dist/install/skill-catalog.d.ts +1 -1
  14. package/dist/install/skill-catalog.js +1 -0
  15. package/dist/postinstall.js +4 -2
  16. package/marketplace/.agents/plugins/marketplace.json +4 -1
  17. package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +14 -2
  18. package/marketplace/plugins/litcodex/assets/screenshot-lit-ignited.png +0 -0
  19. package/marketplace/plugins/litcodex/components/auto-update/dist/auto-update.d.ts +12 -0
  20. package/marketplace/plugins/litcodex/components/auto-update/dist/auto-update.js +31 -2
  21. package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
  22. package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
  23. package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
  24. package/marketplace/plugins/litcodex/components/lit-loop/directive.md +2 -1
  25. package/marketplace/plugins/litcodex/components/lit-loop/directives/deep-interview.md +2 -0
  26. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-brainstorm.md +216 -0
  27. package/marketplace/plugins/litcodex/components/lit-loop/directives/litgoal.md +8 -1
  28. package/marketplace/plugins/litcodex/components/lit-loop/directives/review-work.md +12 -4
  29. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.d.ts +6 -1
  30. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.js +16 -5
  31. package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.d.ts +3 -1
  32. package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.js +5 -2
  33. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.d.ts +2 -0
  34. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +26 -8
  35. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.d.ts +2 -0
  36. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.js +2 -0
  37. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.d.ts +1 -1
  38. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.js +9 -1
  39. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-route.js +2 -0
  40. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.d.ts +2 -0
  41. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.js +8 -0
  42. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.d.ts +56 -0
  43. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.js +171 -0
  44. package/marketplace/plugins/litcodex/components/lit-loop/dist/route-context.js +5 -2
  45. package/marketplace/plugins/litcodex/components/lit-loop/dist/route-heads.js +35 -15
  46. package/marketplace/plugins/litcodex/components/lit-loop/dist/skill-mention-scope.js +2 -0
  47. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.d.ts +2 -2
  48. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.js +17 -6
  49. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.js +1 -0
  50. package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
  51. package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
  52. package/marketplace/plugins/litcodex/components/rules/dist/model-metadata.d.ts +16 -0
  53. package/marketplace/plugins/litcodex/components/rules/dist/model-metadata.js +37 -1
  54. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/README.md +15 -21
  55. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/lib/parse.js +49 -10
  56. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/lib/picomatch.js +14 -2
  57. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/lib/scan.js +30 -18
  58. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/package.json +3 -2
  59. package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
  60. package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
  61. package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
  62. package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
  63. package/marketplace/plugins/litcodex/skills/browser-drive/scripts/capability-probe.mjs +24 -4
  64. package/marketplace/plugins/litcodex/skills/deep-interview/SKILL.md +3 -1
  65. package/marketplace/plugins/litcodex/skills/lit-brainstorm/SKILL.md +271 -0
  66. package/marketplace/plugins/litcodex/skills/lit-brainstorm/agents/openai.yaml +6 -0
  67. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/doctor.mjs +4 -3
  68. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/export.mjs +6 -5
  69. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/runtime-probes.mjs +25 -0
  70. package/marketplace/plugins/litcodex/skills/lit-docx/scripts/convert_md_to_pdf.py +31 -1
  71. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/acs/template.tex +2 -0
  72. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/elsevier/template.tex +2 -0
  73. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/ieee/template.tex +2 -0
  74. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/korean-generic/template.tex +2 -0
  75. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/nature/template.tex +2 -0
  76. package/marketplace/plugins/litcodex/skills/lit-loop/SKILL.md +8 -1
  77. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +42 -10
  78. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/SKILL.md +11 -9
  79. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/agents/openai.yaml +3 -0
  80. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +4 -0
  81. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/constants.mjs +38 -0
  82. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-assets.mjs +113 -0
  83. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-capture.mjs +161 -0
  84. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-gate.mjs +327 -0
  85. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-image.mjs +136 -0
  86. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-init.js +43 -0
  87. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-sheet.mjs +69 -0
  88. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-treatment.mjs +102 -0
  89. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-worker.mjs +21 -0
  90. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover.mjs +352 -0
  91. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/driver.mjs +19 -1
  92. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/fonts.mjs +11 -0
  93. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/look.mjs +128 -2
  94. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/loop-kit.js +104 -0
  95. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/runtime.mjs +92 -18
  96. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage.mjs +2 -0
  97. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/treatment.mjs +3 -2
  98. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/webp.mjs +140 -0
  99. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/JetBrainsMono-wght-latin.woff2 +0 -0
  100. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/OFL.txt +93 -0
  101. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/expected.json +16 -0
  102. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/index.html +42 -0
  103. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/expected.json +16 -0
  104. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/index.html +27 -0
  105. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/expected.json +17 -0
  106. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/index.html +29 -0
  107. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/expected.json +17 -0
  108. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/index.html +44 -0
  109. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +67 -0
  110. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/index.html +182 -0
  111. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/expected.json +95 -0
  112. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/index.html +231 -0
  113. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/expected.json +67 -0
  114. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/index.html +103 -0
  115. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/cover.md +389 -0
  116. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/quality-gate.md +4 -0
  117. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +7 -6
  118. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +3 -1
  119. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +2 -0
  120. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/runtime/requirements-audio.txt +3 -3
  121. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/render.mjs +37 -5
  122. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/runtime.mjs +1 -1
  123. package/marketplace/plugins/litcodex/skills/litgoal/SKILL.md +8 -3
  124. package/marketplace/plugins/litcodex/skills/lsp-setup/SKILL.md +2 -1
  125. package/marketplace/plugins/litcodex/skills/lsp-setup/scripts/verify-lsp.ts +43 -7
  126. package/marketplace/plugins/litcodex/skills/readme-studio/templates/hyperframes-cover/package-lock.json +3 -3
  127. package/marketplace/plugins/litcodex/skills/readme-studio/templates/remotion-cover/package-lock.json +3 -3
  128. package/marketplace/plugins/litcodex/skills/review-work/SKILL.md +21 -4
  129. package/node_modules/@litcodex/lit-loop/CHANGELOG.md +7 -0
  130. package/node_modules/@litcodex/lit-loop/README.md +6 -0
  131. package/node_modules/@litcodex/lit-loop/directive.md +2 -1
  132. package/node_modules/@litcodex/lit-loop/directives/deep-interview.md +2 -0
  133. package/node_modules/@litcodex/lit-loop/directives/lit-brainstorm.md +216 -0
  134. package/node_modules/@litcodex/lit-loop/directives/litgoal.md +8 -1
  135. package/node_modules/@litcodex/lit-loop/directives/review-work.md +12 -4
  136. package/node_modules/@litcodex/lit-loop/dist/codex-hook.d.ts +6 -1
  137. package/node_modules/@litcodex/lit-loop/dist/codex-hook.js +16 -5
  138. package/node_modules/@litcodex/lit-loop/dist/guards.d.ts +3 -1
  139. package/node_modules/@litcodex/lit-loop/dist/guards.js +5 -2
  140. package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +2 -0
  141. package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +26 -8
  142. package/node_modules/@litcodex/lit-loop/dist/markers.d.ts +2 -0
  143. package/node_modules/@litcodex/lit-loop/dist/markers.js +2 -0
  144. package/node_modules/@litcodex/lit-loop/dist/modes.d.ts +1 -1
  145. package/node_modules/@litcodex/lit-loop/dist/modes.js +9 -1
  146. package/node_modules/@litcodex/lit-loop/dist/motion-route.js +2 -0
  147. package/node_modules/@litcodex/lit-loop/dist/plan-persistence.d.ts +2 -0
  148. package/node_modules/@litcodex/lit-loop/dist/plan-persistence.js +8 -0
  149. package/node_modules/@litcodex/lit-loop/dist/reentry.d.ts +56 -0
  150. package/node_modules/@litcodex/lit-loop/dist/reentry.js +171 -0
  151. package/node_modules/@litcodex/lit-loop/dist/route-context.js +5 -2
  152. package/node_modules/@litcodex/lit-loop/dist/route-heads.js +35 -15
  153. package/node_modules/@litcodex/lit-loop/dist/skill-mention-scope.js +2 -0
  154. package/node_modules/@litcodex/lit-loop/dist/trigger.d.ts +2 -2
  155. package/node_modules/@litcodex/lit-loop/dist/trigger.js +17 -6
  156. package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +1 -0
  157. package/node_modules/@litcodex/lit-loop/package.json +1 -1
  158. package/node_modules/@litcodex/lit-loop/skills/browser-drive/scripts/capability-probe.mjs +24 -4
  159. package/node_modules/@litcodex/lit-loop/skills/deep-interview/SKILL.md +3 -1
  160. package/node_modules/@litcodex/lit-loop/skills/lit-brainstorm/SKILL.md +271 -0
  161. package/node_modules/@litcodex/lit-loop/skills/lit-loop/SKILL.md +8 -1
  162. package/node_modules/@litcodex/lit-loop/skills/litgoal/SKILL.md +8 -3
  163. package/node_modules/@litcodex/lit-loop/skills/review-work/SKILL.md +21 -4
  164. package/package.json +2 -2
  165. package/readme-assets/badge-version.svg +1 -1
  166. package/readme-assets/cover-motion-still.webp +0 -0
  167. package/readme-assets/cover-motion.webp +0 -0
  168. package/readme-assets/cover.webp +0 -0
  169. package/readme-assets/litfamily-machines.png +0 -0
  170. package/readme-assets/skills/lit-brainstorm.webp +0 -0
@@ -5,7 +5,7 @@ import { spawnSync } from 'node:child_process';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { buildBlockRegistry } from './block-registry.mjs';
7
7
  import { decodeXmlCharacterReferences, officeCssUrlsAreSafe, officeHrefRefsAreSafe } from './office-safety.mjs';
8
- import { supportsAgentBrowserVersion } from './runtime-probes.mjs';
8
+ import { agentBrowser, supportsAgentBrowserVersion } from './runtime-probes.mjs';
9
9
 
10
10
  const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
11
11
  const args=process.argv.slice(2);
@@ -22,9 +22,10 @@ const output=path.resolve(outputValue);
22
22
  if(path.basename(input)==='index.html'){console.error('EXPORT_SOURCE_REJECTED gallery pages are not diagram sources');process.exit(2);}
23
23
  const resolved=path.resolve(input);
24
24
  if(!fs.existsSync(resolved)){console.error('INPUT_MISSING '+resolved);process.exit(2);}
25
- const browserVersion=spawnSync('agent-browser',['--version'],{encoding:'utf8'});
25
+ const browserSpawn=(args,options)=>{try{const run=agentBrowser(args);return spawnSync(run.command,run.args,options);}catch(e){return {status:null,stdout:'',stderr:e.message};}};
26
+ const browserVersion=browserSpawn(['--version'],{encoding:'utf8'});
26
27
  if(browserVersion.status!==0||!supportsAgentBrowserVersion(browserVersion.stdout)){console.error('RENDERER_REQUIRED agent-browser >= 0.38.1 is required; install or update it yourself with: npm install -g agent-browser');process.exit(2);}
27
- const doctor=spawnSync('agent-browser',['doctor','--json'],{encoding:'utf8'});
28
+ const doctor=browserSpawn(['doctor','--json'],{encoding:'utf8'});
28
29
  let doctorJson;
29
30
  try{doctorJson=JSON.parse(doctor.stdout);}catch{doctorJson=null;}
30
31
  const chrome=doctorJson?.checks?.find((x)=>x.id==='chrome.installed')?.message||'';
@@ -72,7 +73,7 @@ if(office){
72
73
  officeSvg=officeSvg.replace(/(<svg\b[^>]*>)/i,'$1'+style);
73
74
  }
74
75
  function run(commandArgs, env={}) {
75
- const r=spawnSync('agent-browser',commandArgs,{encoding:'utf8',env:{...process.env,AGENT_BROWSER_ALLOW_FILE_ACCESS:'true',...env},maxBuffer:2*1024*1024});
76
+ const r=browserSpawn(commandArgs,{encoding:'utf8',env:{...process.env,AGENT_BROWSER_ALLOW_FILE_ACCESS:'true',...env},maxBuffer:2*1024*1024});
76
77
  if(r.status!==0) throw new Error((r.stderr||r.stdout||'agent-browser failed').trim());
77
78
  return (r.stdout||'').trim();
78
79
  }
@@ -107,7 +108,7 @@ try{
107
108
  process.exitCode=1;
108
109
  } finally {
109
110
  if(opened) {
110
- const close=spawnSync('agent-browser',['--session',session,'close'],{encoding:'utf8'});
111
+ const close=browserSpawn(['--session',session,'close'],{encoding:'utf8'});
111
112
  if(close.status!==0) console.error('BROWSER_CLOSE_WARNING '+(close.stderr||''));
112
113
  }
113
114
  }
@@ -1,3 +1,6 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { win32 } from 'node:path';
3
+
1
4
  export function supportsAgentBrowserVersion(output) {
2
5
  const match = /(?:^|\s)v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?(?:\s|$)/u.exec(output.trim());
3
6
  if (!match || match[4] !== undefined) return false;
@@ -9,3 +12,25 @@ export function supportsAgentBrowserVersion(output) {
9
12
  }
10
13
  return true;
11
14
  }
15
+
16
+ /**
17
+ * How to spawn a user-installed CLI without a shell. On Windows npm installs agent-browser as a
18
+ * .cmd shim, which Node refuses to spawn without a shell (CVE-2024-27980), so the shim is unwrapped
19
+ * to the script or binary it launches; no argument ever passes through cmd.exe.
20
+ */
21
+ export function shellFreeCommand(name, args, { env = process.env, platform = process.platform, exists = existsSync, read = (file) => readFileSync(file, 'utf8') } = {}) {
22
+ if (platform !== 'win32') return { command: name, args };
23
+ const extensions = (env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean);
24
+ const found = (env.PATH ?? env.Path ?? '').split(';').filter(Boolean).flatMap((dir) => extensions.map((ext) => win32.join(dir, name + ext))).find((file) => exists(file));
25
+ if (!found) return { command: name, args };
26
+ if (!/\.(?:cmd|bat)$/iu.test(found)) return { command: found, args };
27
+ const target = [...read(found).matchAll(/"%~?dp0%?\\([^"\r\n]+)"\s+%\*/gu)].at(-1)?.[1];
28
+ if (!target) throw new Error(`${found} is not an npm shim; it cannot be run without a shell`);
29
+ const resolved = win32.join(win32.dirname(found), target);
30
+ return /\.[cm]?js$/iu.test(resolved) ? { command: process.execPath, args: [resolved, ...args] } : { command: resolved, args };
31
+ }
32
+
33
+ /** The shell-free command that runs agent-browser with these arguments. */
34
+ export function agentBrowser(args) {
35
+ return shellFreeCommand('agent-browser', args);
36
+ }
@@ -127,7 +127,8 @@ def template_variables(frontmatter: dict, publisher_name: str, publisher: dict,
127
127
  "publisher-name": publisher_name,
128
128
  "detected-locale": detected_locale,
129
129
  "mode": mode,
130
- "has-cjk": "true" if detected_locale in {"ko", "mixed"} else "false",
130
+ # Pandoc treats any non-empty value as true, so an English document leaves the variable unset.
131
+ "has-cjk": "true" if detected_locale in {"ko", "mixed"} else "",
131
132
  }
132
133
 
133
134
 
@@ -183,6 +184,29 @@ def kpsewhich_has(target: str) -> bool:
183
184
  return result.returncode == 0 and bool(result.stdout.strip())
184
185
 
185
186
 
187
+ FONT_INSTALL_HINTS = {
188
+ "Pretendard": "install Pretendard from https://github.com/orioncactus/pretendard/releases",
189
+ "Pretendard SemiBold": "install Pretendard from https://github.com/orioncactus/pretendard/releases",
190
+ "Times New Roman": "install the Microsoft core fonts (Debian/Ubuntu: ttf-mscorefonts-installer)",
191
+ "Arial": "install the Microsoft core fonts (Debian/Ubuntu: ttf-mscorefonts-installer)",
192
+ }
193
+
194
+
195
+ def required_fonts(publisher: dict, detected_locale: str) -> list[str]:
196
+ body_font = ((publisher.get("docx") or {}).get("font") or {}).get("body") or {}
197
+ fonts = [str(body_font.get("family") or "Times New Roman")]
198
+ if detected_locale in {"ko", "mixed"}:
199
+ fonts.append(str((publisher["latex"].get("cjk") or {}).get("main_font") or "Pretendard"))
200
+ return list(dict.fromkeys(fonts))
201
+
202
+
203
+ def missing_fonts(fonts: list[str], fc_list: str | None) -> list[str]:
204
+ """Fonts fontconfig cannot find; XeLaTeX resolves fontspec names through the same lookup."""
205
+ if not fc_list:
206
+ return []
207
+ return [font for font in fonts if not run_checked([fc_list, f":family={font}", "family"]).stdout.strip()]
208
+
209
+
186
210
  def preflight_pdf_compile(publisher_name: str, publisher: dict, detected_locale: str) -> None:
187
211
  ensure_pandoc()
188
212
  if not command_path("xelatex"):
@@ -204,6 +228,12 @@ def preflight_pdf_compile(publisher_name: str, publisher: dict, detected_locale:
204
228
  raise SystemExit(
205
229
  "Error: xeCJK.sty not found. Korean/CJK PDF output requires xeCJK from TeX Live."
206
230
  )
231
+ for font in missing_fonts(required_fonts(publisher, detected_locale), command_path("fc-list")):
232
+ hint = FONT_INSTALL_HINTS.get(font, f"install the font family '{font}'")
233
+ raise SystemExit(
234
+ f"BLOCKED: publisher '{publisher_name}' needs the font '{font}', which is not installed; "
235
+ f"{hint}, then rerun. XeLaTeX would stop on it."
236
+ )
207
237
 
208
238
 
209
239
  def compile_latex_to_pdf(tex_path: Path, pdf_path: Path) -> str:
@@ -3,6 +3,8 @@
3
3
  \usepackage{graphicx}
4
4
  \usepackage{hyperref}
5
5
  \usepackage{booktabs}
6
+ \usepackage{longtable}
7
+ \providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
6
8
  \usepackage{microtype}
7
9
  \usepackage{siunitx}
8
10
  \usepackage{csquotes}
@@ -4,6 +4,8 @@
4
4
  \usepackage{hyperref}
5
5
  \usepackage{natbib}
6
6
  \usepackage{booktabs}
7
+ \usepackage{longtable}
8
+ \providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
7
9
  \usepackage{microtype}
8
10
  \usepackage{siunitx}
9
11
  \usepackage{csquotes}
@@ -3,6 +3,8 @@
3
3
  \usepackage{graphicx}
4
4
  \usepackage{hyperref}
5
5
  \usepackage{booktabs}
6
+ \usepackage{longtable}
7
+ \providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
6
8
  \usepackage{microtype}
7
9
  \usepackage{siunitx}
8
10
  \usepackage{csquotes}
@@ -3,6 +3,8 @@
3
3
  \usepackage{graphicx}
4
4
  \usepackage{hyperref}
5
5
  \usepackage{booktabs}
6
+ \usepackage{longtable}
7
+ \providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
6
8
  \usepackage{microtype}
7
9
  \usepackage{siunitx}
8
10
  \usepackage{csquotes}
@@ -3,6 +3,8 @@
3
3
  \usepackage{graphicx}
4
4
  \usepackage{hyperref}
5
5
  \usepackage{booktabs}
6
+ \usepackage{longtable}
7
+ \providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
6
8
  \usepackage{microtype}
7
9
  \usepackage{siunitx}
8
10
  \usepackage{csquotes}
@@ -199,7 +199,8 @@ inserting a video into slides, a deck or a report; a script, transcript, summary
199
199
  thumbnail about a video; and UI motion such as button or hover motion, motion tokens or reduced
200
200
  motion. Bare motion or intro alone, including a motion put to a vote, never selects it. On a film
201
201
  request the hook names the installed `../lit-typographic-motion/scripts/render.mjs` by absolute
202
- path and lists its subcommands. Hand-encoded films are not the deliverable.
202
+ path and lists its subcommands. Hand-encoded films are not the deliverable. A README, hero or
203
+ banner loop is the same skill's cover mode: a silent, seamless loop gated on the decoded file.
203
204
 
204
205
  When this task creates or changes a user-facing web interface, put its UI behavior and probe in the
205
206
  plan or bounded acceptance checks. Load the installed sibling `../frontend-ui-ux/SKILL.md` as a
@@ -268,6 +269,12 @@ the operational expansion of that directive: once you see `<lit-loop-mode>`, app
268
269
  above, then follow the selected path. A user who wants to watch the run from a terminal can keep the LIT card
269
270
  live in a second window with `litcodex hud`, which only reads the records these hooks already write.
270
271
 
272
+ A later prompt in the same session that names the same mode arrives as a short `<lit-loop-continue>` note
273
+ instead of this directive. Keep working under the contract you already hold: do not re-read this file or
274
+ restart the workflow. A different mode, `lit new …`, `lit restart …` and the first `lit` after a compaction
275
+ send the full activation again. A bare `lit` or `lit continue` carries on whichever mode is active, and over an active start-work plan, a published
276
+ plan or open goals arrives as a resume note: pick that work up and create no new plan.
277
+
271
278
  ## Codex tool mapping
272
279
 
273
280
  Delegation uses the `multi_agent_v1` subagent tool namespace:
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from "node:child_process";
3
3
  import { createHash } from "node:crypto";
4
- import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
5
5
  import { homedir } from "node:os";
6
6
  import { dirname, join, resolve } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
@@ -33,15 +33,45 @@ const commands = {
33
33
 
34
34
  function run(program, args, options = {}) {
35
35
  const result = spawnSync(program, args, { stdio: "inherit", ...options });
36
- if (result.error) throw result.error;
37
- if (result.status !== 0) process.exit(result.status ?? 1);
36
+ // Name the failed step: a bare stack or exit code is all the installer could show otherwise.
37
+ if (result.error) {
38
+ process.stderr.write(`[lit-office] ${options.shell ? program : [program, ...args].join(" ")} could not start: ${result.error.message}\n`);
39
+ process.exit(1);
40
+ }
41
+ if (result.status !== 0) {
42
+ process.stderr.write(`[lit-office] ${options.shell ? program : [program, ...args].join(" ")} exited with ${result.status ?? result.signal}\n`);
43
+ process.exit(result.status ?? 1);
44
+ }
45
+ }
46
+
47
+ // Node refuses to spawn a .cmd/.bat shim without a shell (CVE-2024-27980), so on Windows npm runs as
48
+ // node + npm's own entry script; only when neither entry exists does cmd.exe get a quoted command line.
49
+ export function npmInvocation(args, env = process.env, platform = process.platform, exists = existsSync) {
50
+ const entry = env.npm_execpath;
51
+ if (entry && exists(entry)) return { command: process.execPath, args: [entry, ...args] };
52
+ if (platform !== "win32") return { command: "npm", args };
53
+ const bundled = join(dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js");
54
+ if (exists(bundled)) return { command: process.execPath, args: [bundled, ...args] };
55
+ return { command: ["npm.cmd", ...args].map(cmdArgument).join(" "), args: [], shell: true };
38
56
  }
39
57
 
40
- function npmInvocation(args) {
41
- const entry = process.env.npm_execpath;
42
- return entry
43
- ? { command: process.execPath, args: [entry, ...args] }
44
- : { command: process.platform === "win32" ? "npm.cmd" : "npm", args };
58
+ /** One argument for a cmd.exe line: quoted when it holds spaces; refused when cmd would interpret it. */
59
+ export function cmdArgument(value) {
60
+ if (/["%^&|<>!\r\n]/u.test(value)) throw new Error(`refusing to pass ${JSON.stringify(value)} through cmd.exe`);
61
+ return /[\s()]/u.test(value) ? `"${value}"` : value;
62
+ }
63
+
64
+ /** A PATH lookup that also tries PATHEXT on Windows, where `which` does not exist. */
65
+ export function onPath(name, env = process.env, platform = process.platform, exists = existsSync) {
66
+ const extensions = platform === "win32" ? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
67
+ for (const dir of (env.PATH ?? env.Path ?? "").split(platform === "win32" ? ";" : ":")) {
68
+ if (!dir) continue;
69
+ for (const extension of extensions) {
70
+ const candidate = join(dir, `${name}${extension}`);
71
+ if (exists(candidate)) return candidate;
72
+ }
73
+ }
74
+ return null;
45
75
  }
46
76
 
47
77
  // npm config an enclosing `npm install -g` or `--dry-run` exports; each one turns the child `npm ci` into a different command.
@@ -93,6 +123,7 @@ function ensureNode(cache) {
93
123
  const npm = npmInvocation(["ci", "--ignore-scripts", "--omit=dev", "--prefix", cache]);
94
124
  run(npm.command, npm.args, {
95
125
  env: { ...npmChildEnv(), PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" },
126
+ ...(npm.shell ? { shell: true } : {}),
96
127
  });
97
128
  writeFileSync(join(cache, "node.ready"), "ready\n");
98
129
  }
@@ -109,7 +140,7 @@ function main() {
109
140
  return;
110
141
  }
111
142
  if (skill === "doctor") {
112
- const which = (name) => spawnSync("which", [name], { encoding: "utf8" }).status === 0;
143
+ const which = (name) => onPath(name) !== null;
113
144
  process.stdout.write(`${JSON.stringify({
114
145
  pptx: { ready: ready("pptx"), cache: cacheFor("pptx") },
115
146
  docx: { ready: ready("docx"), cache: cacheFor("docx") },
@@ -141,4 +172,5 @@ function main() {
141
172
  });
142
173
  }
143
174
 
144
- main();
175
+ const invoked = process.argv[1] && existsSync(process.argv[1]) ? realpathSync(process.argv[1]) : "";
176
+ if (invoked === realpathSync(fileURLToPath(import.meta.url))) main();
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: lit-typographic-motion
3
- description: Direct a film (MP4, stills, sound): treatment first, then an authored stage page or the typography engine, gated and viewed. Use for 영상, 모션그래픽, video, lyric video.
3
+ description: Direct a film (MP4) or a seamless README cover loop: treatment first, stage page or typography engine, gated and viewed. Use for 영상, 모션그래픽, video, lyric video.
4
4
  ---
5
5
 
6
6
  ## #contract.activation
@@ -31,16 +31,18 @@ The request, optional audio and optional explicit style. Under `lit`, ask no que
31
31
  | Treatment | Always first | Load only `references/treatment.md`; write `treatment.json` in the output dir |
32
32
  | Stage | `path: stage` | `references/stage.md`: author the page (`index.html` in the output's `stage` folder), then `stage` |
33
33
  | Type | `path: type` | `references/style-bibles.md`, `references/type-and-timing.md`, `references/scene-author.md`, then `film` |
34
+ | Cover | README, hero, banner or cover loop | `references/cover.md`; a `recipes/` page, then `cover` |
34
35
  | Look | Every stills set | View the PNGs, then `look` (`references/quality-gate.md`) |
35
- | Blocked | Exit 10-12, 14-20 | Name the state and its fix |
36
+ | Blocked | Exit 10-12, 14-22 | Name the state and its fix |
36
37
 
37
38
  ## #contract.procedure
38
39
 
39
40
  1. `R` = absolute path of `scripts/render.mjs` beside this SKILL.md; `O` = the output dir.
40
41
  2. Write `treatment.json` in `O`; the path reference loads only after `path` is set.
41
- 3. Round 1: `node "$R" stage --out O --stills-only --round 1` (type path: `film`). Open every PNG listed in the stills `manifest.json` with `view_image`; write answers; `node "$R" look --out O --round 1 --answers <file>` names the weakest beat and the change you made.
42
- 4. Full render: `node "$R" stage --out O --round 2`. Give the call a timeout of at least 600 s; never shorten the film to save time. View the new stills, record `look --round 2`; revise until the look is clean, at most round 3.
42
+ 3. Round 1: `node "$R" stage --out O --stills-only --round 1` (type path: `film`). Open every PNG in the stills `manifest.json` with `view_image`; write answers; `node "$R" look --out O --round 1 --answers <file>` names the weakest beat and the change you made.
43
+ 4. Full render: `node "$R" stage --out O --round 2`. Give the call a timeout of at least 600 s; never shorten the film to save time. View the new stills, record `look --round 2`; at most round 3.
43
44
  5. Sound: the generated bed is the default; `sound --out O` previews it.
45
+ 6. Cover: `node "$R" cover --out O --round N`; view sheet, poster and seam, then `look`.
44
46
 
45
47
  Hand-encoded films are not the deliverable; every frame and track goes through `$R`.
46
48
 
@@ -51,8 +53,8 @@ Hand-encoded films are not the deliverable; every frame and track goes through `
51
53
  "contract_schema_version": 1,
52
54
  "output_schema": {
53
55
  "film": "film.mp4, or withheld after a flash FAIL",
54
- "stills": "stills/ with manifest.json, beat midpoints, transition strips, contact sheet",
55
- "poster": "poster.png",
56
+ "cover": "cover.webp, gated on the decoded file",
57
+ "stills": "stills/ with manifest.json",
56
58
  "treatment": "treatment.json with every invention listed",
57
59
  "report": "gate-report.txt and look.json",
58
60
  "limitations": ["blocked state, failed rule, open look item or downgrade"]
@@ -62,12 +64,12 @@ Hand-encoded films are not the deliverable; every frame and track goes through `
62
64
 
63
65
  ## #contract.evidence
64
66
 
65
- `node "$R" completion --out O` must print `complete` (or `DONE_UNVIEWED`, said plainly) before you call the film finished. Reply in plain words, below the activation line: one line on the defaults chosen; label every invention and generated sound; one line on what was checked (flash safety, legibility, frames looked at); where the copy lives and the one command that re-renders; any downgrade or open look item.
67
+ `node "$R" completion --out O` must print `complete` (or `DONE_UNVIEWED`, said plainly) before you call the work finished. Reply in plain words: the defaults chosen; every invention, generated sound and `label:` asset, labelled; what was checked; where the copy lives and the command that re-renders; any downgrade or open look item.
66
68
 
67
69
  ## #contract.hard_stops
68
70
 
69
- Exit 10 no Chrome, 11 no WebGL2, 12 no ffmpeg (stills still written), 13 gate FAIL, 14 runtime not pre-warmed, 15 font pin fault, 16 treatment invalid (field named), 17 stage contract, 18 nondeterministic stage, 19 network request, 20 sound invalid. For 14 or 15 run `litcodex motion-runtime install` outside the sandbox. A flash FAIL withholds the film. Details: `references/runtime.md`.
71
+ Exit 10 no Chrome, 11 no WebGL2, 12 no ffmpeg, 13 gate FAIL, 14 not pre-warmed, 15 font pin, 16 treatment, 17 stage contract, 18 nondeterministic, 19 network, 20 sound, 21 no cover encoder, 22 asset missing. For 14 or 15 run `litcodex motion-runtime install` outside the sandbox. A flash FAIL withholds the output. Details: `references/runtime.md`.
70
72
 
71
73
  ## #contract.anti_patterns
72
74
 
73
- Never answer a failure by shortening the film, dropping a beat or the subject device, muting the sound or switching to the type path; fix the cause or state the failure. No network, installs or third-party libraries in a render.
75
+ Never answer a failure by shortening, dropping a beat, layer or subject, muting, switching path, raising a gate number or drawing a stand-in asset; fix the cause or state the failure. No network, installs or third-party libraries in a render.
@@ -10,6 +10,9 @@ interface:
10
10
  - "title sequence"
11
11
  - "모션그래픽"
12
12
  - "타이포그래피 영상"
13
+ - "README cover loop"
14
+ - "motion cover"
15
+ - "모션 커버"
13
16
  default_prompt: "Use $litcodex:lit-typographic-motion to direct, render and verify a film."
14
17
  policy:
15
18
  allow_implicit_invocation: true
@@ -12,6 +12,10 @@ Fonts bundled in this skill (paths relative to the skill directory)
12
12
  variable font; recipe and hashes in fonts/archivo/SHA256SUMS.
13
13
  - VT323 Regular: fonts/vt323/VT323-Regular.ttf; licence fonts/vt323/OFL.txt (SIL Open Font
14
14
  License 1.1, The VT323 Project Authors).
15
+ - JetBrains Mono, variable wght 100-800, latin subset: fonts/jetbrains-mono/JetBrainsMono-wght-latin.woff2;
16
+ licence fonts/jetbrains-mono/OFL.txt (SIL Open Font License 1.1, Copyright 2020 The JetBrains Mono
17
+ Project Authors; no Reserved Font Name). The unmodified file
18
+ files/jetbrains-mono-latin-wght-normal.woff2 of @fontsource-variable/jetbrains-mono 5.3.0.
15
19
  - EMS Allure, EMS Felix, EMS Osmotron, EMS Readability, EMS Tech single-stroke SVG fonts:
16
20
  fonts/stroke/*.svg; licence fonts/stroke/OFL.txt (SIL Open Font License 1.1) and
17
21
  fonts/stroke/CREDITS (per-font creator, converter and base font).
@@ -243,6 +243,8 @@ export const EXIT = Object.freeze({
243
243
  STAGE_NONDETERMINISTIC: 18,
244
244
  STAGE_NETWORK_REQUEST: 19,
245
245
  SOUND_INVALID: 20,
246
+ BLOCKED_NO_COVER_ENCODER: 21,
247
+ BLOCKED_ASSET_MISSING: 22,
246
248
  USAGE: 2,
247
249
  });
248
250
 
@@ -262,3 +264,39 @@ export const STAGE_FORMATS = Object.freeze({ "16:9": Object.freeze({ width: 1920
262
264
  // Generated sound bed: the documented timbre palettes a treatment's sound.palette selects.
263
265
  export const SOUND_PALETTES = Object.freeze(["air", "felt", "glass", "pulse"]);
264
266
  export const MAX_ROUNDS = 3;
267
+
268
+ // Cover mode (references/cover.md): a silent, seamless README loop gated on the DECODED file.
269
+ // Calibrated on eight earlier painted covers (all pass FLOOR, all miss TARGET: a 1.9 s hold and a
270
+ // flash at the seam), four slide-like negatives (all fail FLOOR) and three pilot loops (all reach
271
+ // TARGET). A threshold moves only with a new calibration table, never to let a cover pass.
272
+ export const COVER = Object.freeze({
273
+ maxBytes: 3 * 1024 * 1024,
274
+ targetBytes: 2 * 1024 * 1024,
275
+ minSec: 6,
276
+ maxSec: 12,
277
+ gridMs: 50, // metrics sample a fixed grid of max(gridMs, shortest decoded frame)
278
+ stillEps: 0.0005, // a grid step whose mean |dY| (0..1, luma about 300 px wide) is below this is still
279
+ lumaWidth: 300,
280
+ floor: Object.freeze({ medianD: 0.0004, movingFrac: 0.45, stillSec: 2.0, seamLocal: 8 }),
281
+ target: Object.freeze({ medianD: 0.0015, movingFrac: 0.95, stillSec: 0.5, spike: 6, seamLow: 0.25, seamHigh: 2.0 }),
282
+ minContrast: 4.5,
283
+ // G6: the title's cap height at the width a README column shows a full-width image (about 830 px).
284
+ minCapPx: 24,
285
+ displayWidth: 830,
286
+ // ART: frame 0 shows the base art (SSIM of its check box against the source scaled into the box).
287
+ artSsim: 0.9,
288
+ artMinShare: 0.1,
289
+ seekFrames: 16, // re-rendered in a fresh page in a seeded shuffled order
290
+ seekLevels: 1, // the software rasterizer's own rounding when opacity and transform change together
291
+ windowPadSec: 0.5,
292
+ maxDefects: 3,
293
+ captureScale: 2,
294
+ sheetTiles: 12,
295
+ fps: Object.freeze([16, 20, 25]),
296
+ // The page is laid out at `page` CSS px, captured at captureScale and Lanczos-downsampled to `size`.
297
+ aspects: Object.freeze({
298
+ "2:1": Object.freeze({ page: Object.freeze([1200, 600]), size: Object.freeze([1000, 500]) }),
299
+ "3:2": Object.freeze({ page: Object.freeze([1200, 800]), size: Object.freeze([960, 640]) }),
300
+ }),
301
+ encode: Object.freeze({ q: 86, edgeQ: 97, edgeFrames: 15, method: 4 }),
302
+ });
@@ -0,0 +1,113 @@
1
+ // Cover assets. Every raster a cover page can load (base art, logo, wordmark, texture) is listed in
2
+ // `<out>/assets.json` with its path, role, source (user or generated) and SHA-256, and the renderer
3
+ // checks the list before the first capture. A listed file that is missing stops the run as
4
+ // BLOCKED_ASSET_MISSING (exit 22): the art is supplied or generated, never replaced by a drawn
5
+ // stand-in, and the painted-light recipe cannot run without its base art. After the render, frame 0
6
+ // must show that art: the SSIM of its check box in decoded frame 0 against the source scaled into
7
+ // the art's box.
8
+ import { spawnSync } from "node:child_process";
9
+ import { createHash } from "node:crypto";
10
+ import { existsSync, readFileSync } from "node:fs";
11
+ import { extname, join, sep } from "node:path";
12
+ import { COVER, EXIT, Exit } from "./constants.mjs";
13
+ import { readPngRgba } from "./cover-gate.mjs";
14
+ import { crop, lanczosResize, ssim } from "./cover-image.mjs";
15
+ import { which } from "./runtime.mjs";
16
+ import { rasterInfo } from "./stage.mjs";
17
+
18
+ export const ASSETS_FILE = "assets.json";
19
+ export const ASSET_ROLES = Object.freeze(["base-art", "logo", "wordmark", "texture"]);
20
+ const RASTERS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);
21
+
22
+ const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
23
+ const invalid = (field, message) => new Exit(EXIT.BLOCKED_TREATMENT_INVALID, `BLOCKED_TREATMENT_INVALID: assets.json ${field}: ${message}`);
24
+ const isBox = (b) => Array.isArray(b) && b.length === 4 && b.every((v) => typeof v === "number" && v >= 0 && v <= 1) && b[2] > 0 && b[3] > 0 && b[0] + b[2] <= 1 + 1e-9 && b[1] + b[3] <= 1 + 1e-9;
25
+ const inside = (inner, outer) => inner[0] >= outer[0] - 1e-9 && inner[1] >= outer[1] - 1e-9 && inner[0] + inner[2] <= outer[0] + outer[2] + 1e-9 && inner[1] + inner[3] <= outer[1] + outer[3] + 1e-9;
26
+
27
+ function entry(raw, i, coverDir) {
28
+ const at = `assets[${i}]`;
29
+ if (!raw || typeof raw !== "object") throw invalid(at, "must be an object");
30
+ if (typeof raw.path !== "string" || !raw.path.startsWith(`${coverDir}/`) || raw.path.split("/").includes("..")) throw invalid(`${at}.path`, `must be a path inside ${coverDir}/, relative to the output directory`);
31
+ if (!ASSET_ROLES.includes(raw.role)) throw invalid(`${at}.role`, `must be one of ${ASSET_ROLES.join(", ")}`);
32
+ if (!["user", "generated"].includes(raw.source)) throw invalid(`${at}.source`, "must be user (supplied) or generated (made for this cover)");
33
+ if (!/^[0-9a-f]{64}$/u.test(raw.sha256 ?? "")) throw invalid(`${at}.sha256`, "must be the file's SHA-256 (64 hex digits)");
34
+ if ("box" in raw && !isBox(raw.box)) throw invalid(`${at}.box`, "must be [x, y, w, h] as fractions of the cover, inside it");
35
+ if (raw.role === "base-art" && !raw.box) throw invalid(`${at}.box`, "base art needs the box it fills on the cover");
36
+ if ("checkBox" in raw) {
37
+ if (!isBox(raw.checkBox)) throw invalid(`${at}.checkBox`, "must be [x, y, w, h] as fractions of the cover, inside it");
38
+ if (!raw.box) throw invalid(`${at}.checkBox`, "needs the art's box");
39
+ if (!inside(raw.checkBox, raw.box)) throw invalid(`${at}.checkBox`, "must lie inside the art's box");
40
+ if (raw.checkBox[2] * raw.checkBox[3] < COVER.artMinShare * raw.box[2] * raw.box[3]) throw invalid(`${at}.checkBox`, `must cover at least ${COVER.artMinShare * 100} % of the art's box`);
41
+ }
42
+ return { path: raw.path, role: raw.role, source: raw.source, sha256: raw.sha256, box: raw.box ?? null, checkBox: raw.checkBox ?? null, title: raw.title === true };
43
+ }
44
+
45
+ /**
46
+ * Check `<outDir>/assets.json` against the cover folder before any capture. `files` is the static
47
+ * scan's file list (paths relative to the cover folder). Exit 22 for a missing listed file or a
48
+ * painted recipe with no base art; exit 17 for a raster the list does not name or a file whose hash
49
+ * changed; exit 16 for a malformed entry. Returns { assets } (empty when there is no list).
50
+ */
51
+ export function checkAssets({ outDir, treatment, files, coverDir = "cover" }) {
52
+ const file = join(outDir, ASSETS_FILE);
53
+ let assets = [];
54
+ if (existsSync(file)) {
55
+ let doc;
56
+ try {
57
+ doc = JSON.parse(readFileSync(file, "utf8"));
58
+ } catch (error) {
59
+ throw invalid("", `not valid JSON (${error.message})`);
60
+ }
61
+ if (!doc || !Array.isArray(doc.assets)) throw invalid("assets", "must be an array of { path, role, source, sha256 }");
62
+ assets = doc.assets.map((raw, i) => entry(raw, i, coverDir));
63
+ for (const asset of assets) {
64
+ const path = join(outDir, asset.path);
65
+ if (!existsSync(path)) throw new Exit(EXIT.BLOCKED_ASSET_MISSING, `BLOCKED_ASSET_MISSING: ${asset.path} is listed in assets.json and missing; supply it or generate it, never draw a stand-in`);
66
+ if (sha256(readFileSync(path)) !== asset.sha256) throw new Exit(EXIT.STAGE_CONTRACT_ERROR, `STAGE_CONTRACT_ERROR: ${asset.path} no longer matches its sha256 in assets.json; list it again after changing it`);
67
+ }
68
+ }
69
+ if (treatment.recipe === "painted-light" && !assets.some((a) => a.role === "base-art")) throw new Exit(EXIT.BLOCKED_ASSET_MISSING, "BLOCKED_ASSET_MISSING: the painted-light recipe needs its base art listed in assets.json ({ path, role: base-art, source, sha256, box }); supply or generate the painting, never draw a stand-in");
70
+ const listed = new Set(assets.map((a) => a.path));
71
+ for (const f of files.filter((f) => RASTERS.has(extname(f.rel).toLowerCase()))) {
72
+ const rel = `${coverDir}/${f.rel.split(sep).join("/")}`;
73
+ if (!listed.has(rel)) throw new Exit(EXIT.STAGE_CONTRACT_ERROR, `STAGE_CONTRACT_ERROR: ${rel} is a raster the page can load but assets.json does not list; add it with its role, source and sha256`);
74
+ }
75
+ return { assets };
76
+ }
77
+
78
+ /** A raster's pixels: PNG decoded here, any other format (or a PNG this decoder cannot read) through ffmpeg. */
79
+ export function readRaster(file, env = process.env) {
80
+ try {
81
+ return readPngRgba(file);
82
+ } catch {
83
+ const info = rasterInfo(readFileSync(file), extname(file).toLowerCase());
84
+ const ffmpeg = which("ffmpeg", env);
85
+ if (!info || !ffmpeg) return null;
86
+ const raw = spawnSync(ffmpeg, ["-v", "error", "-i", file, "-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "rgba", "pipe:1"], { maxBuffer: 2 ** 30, env });
87
+ return raw.status === 0 ? { width: info.width, height: info.height, rgba: raw.stdout } : null;
88
+ }
89
+ }
90
+
91
+ const toPx = (box, width, height) => box.map((v, k) => Math.round(v * (k % 2 ? height : width)));
92
+
93
+ /**
94
+ * ART: crop the check box (default: the art's whole box) out of decoded frame 0 and compare it with
95
+ * the same region of the source scaled into the art's box. Boxes are fractions of the cover.
96
+ */
97
+ export function artCheck({ frame0, width, height, art, box, checkBox = null }) {
98
+ const [bx, by, bw, bh] = toPx(box, width, height);
99
+ const scaled = lanczosResize(art.rgba, art.width, art.height, bw, bh);
100
+ const [cx, cy, cw, ch] = toPx(checkBox ?? box, width, height);
101
+ const value = ssim(crop(frame0, width, [cx, cy, cw, ch]), crop(scaled, bw, [cx - bx, cy - by, cw, ch]), cw, ch);
102
+ return { ssim: value, pass: value >= COVER.artSsim, box: [bx, by, bw, bh], checked: [cx, cy, cw, ch] };
103
+ }
104
+
105
+ /** The reply labels a generated asset needs; `completion` prints them for the finished cover. */
106
+ export function generatedLabels(outDir) {
107
+ try {
108
+ const doc = JSON.parse(readFileSync(join(outDir, ASSETS_FILE), "utf8"));
109
+ return (doc.assets ?? []).filter((a) => a?.source === "generated" && typeof a.path === "string").map((a) => `the ${String(a.role ?? "asset").replace("-", " ")} ${a.path} is generated, not supplied: label it as generated in the reply`);
110
+ } catch {
111
+ return [];
112
+ }
113
+ }