@lalalic/markcut 3.2.60 → 3.2.62

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 (54) hide show
  1. package/README.md +48 -5
  2. package/bin/markcut +15 -0
  3. package/docs/developer-reference.md +41 -1
  4. package/package.json +8 -2
  5. package/recipes/markcut/map-cinematic-follow.json +17 -0
  6. package/recipes/markcut/map-location-reveal.json +17 -0
  7. package/recipes/markcut/map-route-journey.json +18 -0
  8. package/recipes/markcut/map-streetview-explore.json +17 -0
  9. package/skills/markcut/SKILL.md +8 -3
  10. package/skills/markcut/docs/markdown-descriptive.md +68 -1
  11. package/skills/markcut/docs/recipes.md +45 -0
  12. package/skills/markcut/references/mobile-event-preview-cli.md +9 -5
  13. package/src/descriptive/compiler.ts +38 -2
  14. package/src/descriptive/markdown.ts +30 -0
  15. package/src/descriptive/model3d.test.ts +38 -0
  16. package/src/editor-decision/cli.mjs +21 -0
  17. package/src/editor-decision/editor-decision.schema.json +41 -0
  18. package/src/editor-decision/index.mjs +115 -0
  19. package/src/editor-decision/index.test.mjs +63 -0
  20. package/src/mcp/bridge.mjs +92 -12
  21. package/src/mcp/compile-worker.mjs +2 -2
  22. package/src/mcp/design-cli.mjs +126 -0
  23. package/src/mcp/mobile-review-cli.mjs +40 -33
  24. package/src/mcp/preview-mobile.css +21 -8
  25. package/src/mcp/preview.mjs +97 -57
  26. package/src/mcp/remote-assets.mjs +85 -7
  27. package/src/mcp/remotion-app.bundle.js +5013 -1117
  28. package/src/mcp/remotion-app.tsx +132 -10
  29. package/src/mcp/server.mjs +4 -2
  30. package/src/player/browser.tsx +1 -3
  31. package/src/player/bundle/player.js +73054 -17357
  32. package/src/player/components/HeaderBar.tsx +3 -1
  33. package/src/player/components/VariantBar.tsx +20 -21
  34. package/src/player/pipeline.mjs +133 -77
  35. package/src/player/server.mjs +43 -23
  36. package/src/recipes/catalog.mjs +115 -0
  37. package/src/recipes/cli.mjs +87 -0
  38. package/src/render/cli.mjs +40 -1
  39. package/src/schema/index.ts +21 -0
  40. package/src/types/Folder.tsx +2 -0
  41. package/src/types/Model3D.tsx +91 -0
  42. package/src/vision/cli.mjs +63 -50
  43. package/tests/mcp-design-mode.test.ts +100 -0
  44. package/tests/mcp-editor-decisions-mobile.test.ts +35 -0
  45. package/tests/mcp-preview-bridge.test.ts +44 -3
  46. package/tests/mcp-preview-proxy-version.test.mjs +80 -0
  47. package/tests/mcp-preview.test.ts +43 -8
  48. package/tests/mcp-remote-assets.test.ts +17 -0
  49. package/tests/mcp-static-preview.test.ts +1 -1
  50. package/tests/mcp-video-selector.test.ts +55 -0
  51. package/tests/mobile-preview-cli.test.ts +10 -15
  52. package/tests/recipes-catalog.test.ts +141 -0
  53. package/tests/vision-generic-vtt-hooks.test.ts +7 -7
  54. package/tests/vision-normalized-metadata.test.ts +23 -0
@@ -5,6 +5,7 @@ import type {
5
5
  DescriptiveImage,
6
6
  DescriptiveInclude,
7
7
  DescriptiveMap,
8
+ DescriptiveModel3D,
8
9
  DescriptiveMapWaypoint,
9
10
  DescriptiveNode,
10
11
  DescriptiveRhythm,
@@ -35,6 +36,7 @@ export type { ParseContext };
35
36
 
36
37
  const TYPE_TOKENS: Record<string, string> = {
37
38
  image: "image",
39
+ model3d: "model3d",
38
40
  video: "video",
39
41
  audio: "audio",
40
42
  component: "component",
@@ -104,6 +106,7 @@ function preserveVariantAttrs(node: Record<string, unknown>, attrs: Record<strin
104
106
  "view", "camera", "cinematic", "streetView", "routeAnimation",
105
107
  "name", "title", "transition", "transitionTime", "layout",
106
108
  "componentName", "props", "speaker", "isNarration",
109
+ "motion", "turns", "rotation", "position", "scale", "autoFit", "background",
107
110
  ]);
108
111
  for (const [k, v] of Object.entries(attrs)) {
109
112
  if (!STANDARD.has(k)) {
@@ -182,6 +185,33 @@ function parseNodeLine(content: string, lineNum?: number): DescriptiveNode {
182
185
  preserveVariantAttrs(node, attrs);
183
186
  return node;
184
187
  }
188
+ case "model3d": {
189
+ const src = firstPositional ?? (attrs.src as string | undefined);
190
+ if (!src) throw new DslError("model3d requires src (.glb or .gltf)", ctx);
191
+ const node: DescriptiveModel3D = {
192
+ type: "model3d",
193
+ id: attrs.id as any,
194
+ src,
195
+ duration: attrs.duration as any,
196
+ start: attrs.start as any,
197
+ motion: attrs.motion as any,
198
+ turns: attrs.turns as any,
199
+ rotation: attrs.rotation as any,
200
+ position: attrs.position as any,
201
+ scale: attrs.scale as any,
202
+ autoFit: attrs.autoFit as any,
203
+ camera: attrs.camera as any,
204
+ background: attrs.background as any,
205
+ instruction: attrs.instruction as any,
206
+ visible: attrs.visible as any,
207
+ isBackground: attrs.isBackground as any,
208
+ style: attrs.style as any,
209
+ effects: attrs.effects as any,
210
+ on: attrs.on as any,
211
+ };
212
+ preserveVariantAttrs(node, attrs);
213
+ return node;
214
+ }
185
215
  case "video": {
186
216
  const src = firstPositional ?? (attrs.src as string | undefined);
187
217
  const prompt = attrs.prompt as string | undefined;
@@ -0,0 +1,38 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { parseMarkdownDescriptive } from "./markdown";
3
+ import { compileDescriptiveRoot } from "./compiler";
4
+ import { root as rootSchema } from "../schema/index";
5
+ import { model3dAngle } from "../types/Model3D";
6
+
7
+ const doc = `# video
8
+ width:640 height:640 fps:30 layout:series
9
+ ## Toy
10
+ - model3d src:assets/toy.glb duration:6 motion:turntable turns:1 rotation:[0,30,0] camera:{"position":[0,1,5],"fov":34} background:#eeeeee`;
11
+
12
+ describe("model3d native stream", () => {
13
+ it("parses Markdown through compiler and strict Zod stream schema", () => {
14
+ const descriptive = parseMarkdownDescriptive(doc);
15
+ const input = (descriptive.children[0] as any).children[0];
16
+ expect(input).toMatchObject({ type: "model3d", src: "assets/toy.glb", motion: "turntable", duration: 6, rotation: [0, 30, 0] });
17
+ const compiled = compileDescriptiveRoot(descriptive);
18
+ const parsed = rootSchema.parse(compiled);
19
+ const model = (parsed.children[0] as any).children[0];
20
+ expect(model).toMatchObject({ type: "model3d", src: "assets/toy.glb", motion: "turntable", turns: 1, durationInSeconds: 6, camera: { position: [0, 1, 5], fov: 34 } });
21
+ });
22
+
23
+ it("works with defaults and rejects USDZ, broken vectors and unknown motion", () => {
24
+ const parsed = rootSchema.parse(compileDescriptiveRoot(parseMarkdownDescriptive('# video\n## Static\n- model3d src:toy.glb')));
25
+ const model = (parsed.children[0] as any).children[0];
26
+ expect(model).toMatchObject({ motion: "none", turns: 1, autoFit: true, rotation: [0, 0, 0], durationInSeconds: 4 });
27
+ expect(() => rootSchema.parse(compileDescriptiveRoot(parseMarkdownDescriptive('# video\n- model3d src:toy.usdz duration:2')))).toThrow(/glb|gltf/i);
28
+ expect(() => rootSchema.parse(compileDescriptiveRoot(parseMarkdownDescriptive('# video\n- model3d src:toy.glb rotation:[0,20]')))).toThrow();
29
+ expect(() => rootSchema.parse(compileDescriptiveRoot(parseMarkdownDescriptive('# video\n- model3d src:toy.glb motion:fly')))).toThrow();
30
+ });
31
+
32
+ it("never accumulates rotation between seeks", () => {
33
+ expect(model3dAngle(0, 121, 1)).toBe(0);
34
+ expect(model3dAngle(60, 121, 1)).toBeCloseTo(Math.PI);
35
+ expect(model3dAngle(120, 121, 1)).toBeCloseTo(Math.PI * 2);
36
+ expect(model3dAngle(60, 121, 1)).toBeCloseTo(Math.PI);
37
+ });
38
+ });
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import {readFileSync,writeFileSync} from 'node:fs';
3
+ import {resolve,dirname,basename,join} from 'node:path';
4
+ import {loadEditorDecision,editorDecisionToMarkdown} from './index.mjs';
5
+ const [command,videoArg,...rest]=process.argv.slice(2);
6
+ if(command!=='edl'||!videoArg||!videoArg.endsWith('.md')){
7
+ console.error('Usage: markcut edl <video.md> [--output <video.edl.md>]');
8
+ process.exit(2);
9
+ }
10
+ const pos=rest.indexOf('--output');
11
+ if(pos>=0&&(!rest[pos+1]||rest.length!==2))throw Error('--output requires a file');
12
+ if(pos<0&&rest.length)throw Error('Unknown editor decision options: '+rest.join(' '));
13
+ const video=resolve(videoArg);
14
+ const source=readFileSync(video,'utf8');
15
+ const sidecar=loadEditorDecision(video,source);
16
+ if(!sidecar)throw Error('No Editor Decision sidecar found for '+videoArg);
17
+ const rendered=editorDecisionToMarkdown(video,sidecar.edl,source);
18
+ const output=pos>=0?resolve(rest[pos+1]):join(dirname(video),basename(video,'.md')+'.edl.md');
19
+ if(output===video||output===sidecar.path)throw Error('Editor Decision output must not overwrite source files');
20
+ writeFileSync(output,rendered,'utf8');
21
+ console.log(output);
@@ -0,0 +1,41 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Markcut Editor Decision List v1",
4
+ "description": "Optional editable source-linked decisions accompanying an executable Markcut video.md.",
5
+ "type": "object",
6
+ "required": ["schema_version", "edits"],
7
+ "properties": {
8
+ "schema_version": {"const": 1},
9
+ "editorial_intent": {"type": "string"},
10
+ "personal_story_id": {"type": "string"},
11
+ "edits": {
12
+ "type": "array", "minItems": 1,
13
+ "items": {
14
+ "type": "object",
15
+ "required": ["shot_id", "in_seconds", "out_seconds"],
16
+ "anyOf": [{"required": ["source_id"]}, {"required": ["source_src"]}],
17
+ "properties": {
18
+ "shot_id": {"type": "string", "minLength": 1},
19
+ "sceneId": {"type": "string"},
20
+ "source_id": {"type": "string", "minLength": 1},
21
+ "source_src": {"type": "string", "minLength": 1},
22
+ "in_seconds": {"type": "number", "minimum": 0},
23
+ "out_seconds": {"type": "number", "exclusiveMinimum": 0},
24
+ "playbackSpeed": {"type": "number", "exclusiveMinimum": 0},
25
+ "timelineDuration": {"type": "number", "exclusiveMinimum": 0},
26
+ "shot_purpose": {"type": "string"},
27
+ "editor_reason": {"type": "string"},
28
+ "cut_reason": {"type": "string"},
29
+ "visual_relationship": {"type": "string"},
30
+ "sound_decision": {"type": "string"},
31
+ "revision_note": {"type": "string"},
32
+ "beat": {"type": "string"},
33
+ "story_beat_id": {"type": "string"},
34
+ "transition": {"type": "string"}
35
+ },
36
+ "additionalProperties": true
37
+ }
38
+ }
39
+ },
40
+ "additionalProperties": true
41
+ }
@@ -0,0 +1,115 @@
1
+ /** Markcut built-in Editor Decision sidecar and its playable video converter.
2
+ * The executable Markdown remains authoritative for the finished film.
3
+ */
4
+ import {readFileSync, existsSync, readdirSync, realpathSync} from 'node:fs';
5
+ import {resolve, dirname, basename, extname, relative, isAbsolute, sep, join} from 'node:path';
6
+ import * as yaml from 'js-yaml';
7
+
8
+ const videoExts=new Set(['.mp4','.mov','.m4v','.webm','.mkv','.avi']);
9
+ const imageExts=new Set(['.png','.jpg','.jpeg','.webp','.gif','.bmp']);
10
+ const nonEmpty=x=>typeof x==='string'&&x.trim().length>0;
11
+ const finite=x=>typeof x==='number'&&Number.isFinite(x);
12
+ const inside=(base,path)=>{const rel=relative(base,path);return !!rel&&rel!=='..'&&!rel.startsWith('..'+sep)&&!isAbsolute(rel);};
13
+ const frontRe=/^\uFEFF?---\s*\r?\n([\s\S]*?)\r?\n---(?:\s*\r?\n|\s*$)/;
14
+
15
+ export function frontmatterEdl(markdown){
16
+ const found=frontRe.exec(markdown);
17
+ if(!found)return undefined;
18
+ const obj=yaml.load(found[1]);
19
+ if(obj==null)return undefined;
20
+ if(typeof obj!=='object'||Array.isArray(obj))throw Error('Markcut frontmatter must be a YAML mapping');
21
+ if(!Object.hasOwn(obj,'edl'))return undefined;
22
+ if(!nonEmpty(obj.edl))throw Error('Frontmatter edl must name a relative .json file');
23
+ return obj.edl.trim();
24
+ }
25
+
26
+ /** Explicit frontmatter path wins; otherwise discover the existing <name>.edl.json sidecar. */
27
+ export function resolveEditorDecisionPath(videoPath,markdown=readFileSync(videoPath,'utf8')){
28
+ const declared=frontmatterEdl(markdown);
29
+ const name=declared??basename(videoPath,'.md')+'.edl.json';
30
+ if(extname(name).toLowerCase()!=='.json'||isAbsolute(name)||name.includes('\\')||/^[a-z][a-z\d+.-]*:/i.test(name))throw Error('EDL must be a local relative JSON path');
31
+ const base=dirname(resolve(videoPath)),full=resolve(base,name);
32
+ if(!inside(base,full))throw Error('EDL reference escapes the video directory');
33
+ if(!existsSync(full)){
34
+ if(declared)throw Error('Declared EDL not found: '+name);
35
+ return null;
36
+ }
37
+ if(!inside(realpathSync(base),realpathSync(full)))throw Error('EDL symlink escapes the video directory');
38
+ return full;
39
+ }
40
+
41
+ export function validateEditorDecision(edl){
42
+ if(!edl||typeof edl!=='object'||Array.isArray(edl)||edl.schema_version!==1||!Array.isArray(edl.edits)||!edl.edits.length)
43
+ throw Error('Editor Decision v1 requires schema_version:1 and nonempty edits[]');
44
+ if(edl.edits.length>500)throw Error('EDL exceeds 500 shots');
45
+ const ids=new Set();
46
+ for(const [i,e] of edl.edits.entries()){
47
+ if(!e||typeof e!=='object'||!nonEmpty(e.shot_id)||ids.has(e.shot_id))throw Error('EDL edits['+i+'] requires unique shot_id');
48
+ ids.add(e.shot_id);
49
+ if(!nonEmpty(e.source_src)&&!nonEmpty(e.source_id))throw Error('EDL edits['+i+'] requires source_src or source_id');
50
+ if(!finite(e.in_seconds)||e.in_seconds<0||!finite(e.out_seconds)||e.out_seconds<=e.in_seconds)throw Error('EDL edits['+i+'] has invalid in/out seconds');
51
+ if(e.playbackSpeed!=null&&(!finite(e.playbackSpeed)||e.playbackSpeed<=0))throw Error('EDL edits['+i+'] has invalid playbackSpeed');
52
+ if(e.timelineDuration!=null&&(!finite(e.timelineDuration)||e.timelineDuration<=0))throw Error('EDL edits['+i+'] has invalid timelineDuration');
53
+ }
54
+ return edl;
55
+ }
56
+
57
+ export function loadEditorDecision(videoPath,markdown=readFileSync(videoPath,'utf8')){
58
+ const path=resolveEditorDecisionPath(videoPath,markdown);
59
+ if(!path)return null;
60
+ let edl;
61
+ try{edl=JSON.parse(readFileSync(path,'utf8'));}catch(e){throw Error('Invalid EDL JSON '+basename(path)+': '+e.message);}
62
+ validateEditorDecision(edl);
63
+ return {path,edl};
64
+ }
65
+ function confinedMediaSrc(videoPath,src){
66
+ const base=dirname(resolve(videoPath));
67
+ if(!nonEmpty(src)||isAbsolute(src)||src.includes('\\')||/^[a-z][a-z\d+.-]*:/i.test(src))throw Error('EDL media must be local relative path: '+src);
68
+ const full=resolve(base,src);
69
+ if(!inside(base,full)||!existsSync(full)||!inside(realpathSync(base),realpathSync(full)))throw Error('EDL media is missing or outside video directory: '+src);
70
+ const rel=relative(base,full).split(sep).join('/');
71
+ if(/[\s"\r\n]/.test(rel))throw Error('EDL media path must not contain whitespace or quotes: '+rel);
72
+ return rel;
73
+ }
74
+ function mediaSrc(videoPath,edit){
75
+ if(nonEmpty(edit.source_src))return confinedMediaSrc(videoPath,edit.source_src);
76
+ const id=edit.source_id;
77
+ if(/[/\\]/.test(id))return confinedMediaSrc(videoPath,id);
78
+ if(extname(id)){
79
+ if(existsSync(resolve(dirname(videoPath),id)))return confinedMediaSrc(videoPath,id);
80
+ return confinedMediaSrc(videoPath,'input/media/'+id);
81
+ }
82
+ const dir=join(dirname(resolve(videoPath)),'input','media');
83
+ const candidates=existsSync(dir)?readdirSync(dir).filter(name=>basename(name,extname(name))===id&&(videoExts.has(extname(name).toLowerCase())||imageExts.has(extname(name).toLowerCase()))):[];
84
+ if(candidates.length!==1)throw Error('EDL source_id '+JSON.stringify(id)+' does not uniquely resolve; specify source_src');
85
+ return confinedMediaSrc(videoPath,'input/media/'+candidates[0]);
86
+ }
87
+ const html=s=>String(s??'').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;').replace(/[\r\n]+/g,' ');
88
+ const short=(s,n=140)=>{const text=String(s??'').trim();return text.length>n?text.slice(0,n-1)+'…':text;};
89
+ function overlay(edit,index,src){
90
+ const fields=[edit.shot_purpose||edit.beat||edit.story_beat_id,edit.editor_reason||edit.cut_reason,edit.visual_relationship,edit.sound_decision||edit.audioIntent,edit.revision_note].filter(nonEmpty).map(s=>short(s));
91
+ const lines=['SOURCE: '+src+' ['+edit.in_seconds.toFixed(2)+'–'+edit.out_seconds.toFixed(2)+'s]',...fields].slice(0,5);
92
+ const body=lines.map((line,i)=>'<div style={{fontSize:'+(i===0?18:24)+',opacity:'+(i===0?0.7:1)+",marginTop:10,overflowWrap:'anywhere'}}>"+html(line)+'</div>').join('');
93
+ return "<div style={{boxSizing:'border-box',width:'100%',height:'100%',display:'flex',flexDirection:'column',justifyContent:'flex-end',padding:'5%',color:'white',fontFamily:'Arial,sans-serif',background:'linear-gradient(0deg,rgba(0,0,0,.94),rgba(0,0,0,.6) 45%,transparent 90%)'}}><div style={{fontSize:33,fontWeight:700}}>SHOT "+(index+1)+' · '+html(edit.shot_id)+'</div>'+body+'</div>';
94
+ }
95
+ export function editorDecisionToMarkdown(videoPath,edl,markdown=readFileSync(videoPath,'utf8')){
96
+ validateEditorDecision(edl);
97
+ const width=Number(/\bwidth:(\d+)/.exec(markdown)?.[1]||1080),height=Number(/\bheight:(\d+)/.exec(markdown)?.[1]||1920);
98
+ const fps=Number(/\bfps:(\d+)/.exec(markdown)?.[1]||30);
99
+ const out=['# video','width:'+width+' height:'+height+' fps:'+fps+' layout:series'];
100
+ if(nonEmpty(edl.editorial_intent)){
101
+ const jsx="<div style={{boxSizing:'border-box',width:'100%',height:'100%',background:'#111827',color:'white',display:'flex',alignItems:'center',justifyContent:'center',padding:'10%',fontSize:46,textAlign:'center'}}>"+html(short(edl.editorial_intent,320))+'</div>';
102
+ out.push('','## EditorialIntent','layout:parallel','- component duration:3 jsx:'+JSON.stringify(jsx));
103
+ }
104
+ for(const [i,e] of edl.edits.entries()){
105
+ const src=mediaSrc(videoPath,e),ext=extname(src).toLowerCase(),speed=e.playbackSpeed||1;
106
+ const duration=e.timelineDuration||(e.out_seconds-e.in_seconds)/speed;
107
+ if(!finite(duration)||duration<=0)throw Error('EDL shot '+e.shot_id+' has invalid duration');
108
+ out.push('','## Shot'+(i+1),'layout:parallel');
109
+ if(imageExts.has(ext))out.push('- image src:'+src+' duration:'+duration.toFixed(4)+' fit:cover');
110
+ else if(videoExts.has(ext))out.push('- video src:'+src+' startFrom:'+e.in_seconds+' endAt:'+e.out_seconds+' duration:'+duration.toFixed(4)+' playbackRate:'+speed+' volume:1 fit:cover');
111
+ else throw Error('Unsupported EDL media format: '+src);
112
+ out.push('- component duration:'+duration.toFixed(4)+' jsx:'+JSON.stringify(overlay(e,i,src)));
113
+ }
114
+ return out.join('\n')+'\n';
115
+ }
@@ -0,0 +1,63 @@
1
+ import {test} from 'vitest';
2
+ import assert from 'node:assert/strict';
3
+ import {mkdtempSync,mkdirSync,writeFileSync,rmSync,readFileSync} from 'node:fs';
4
+ import {tmpdir} from 'node:os';
5
+ import {join} from 'node:path';
6
+ import {frontmatterEdl,loadEditorDecision,resolveEditorDecisionPath,validateEditorDecision,editorDecisionToMarkdown} from './index.mjs';
7
+
8
+ const BASE='# video\nwidth:320 height:568 fps:24 layout:series\n## Main\n- video src:input/media/001.mp4 startFrom:0 endAt:1 duration:1\n';
9
+ const EDL={schema_version:1,editorial_intent:'An honest visual observation',edits:[
10
+ {shot_id:'wide',source_src:'input/media/001.mp4',in_seconds:0,out_seconds:1,shot_purpose:'Set geography',editor_reason:'Hold the wide frame long enough to orient viewers.'},
11
+ {shot_id:'reaction',source_id:'001',in_seconds:1,out_seconds:2,editor_reason:'Cut on the response, not on an arbitrary transition.',visual_relationship:'wide to close',sound_decision:'retain source sound'}
12
+ ]};
13
+ function setup(){
14
+ const folder=mkdtempSync(join(tmpdir(),'markcut-editor-decision-'));
15
+ mkdirSync(join(folder,'input','media'),{recursive:true});
16
+ writeFileSync(join(folder,'input','media','001.mp4'),'fixture');
17
+ const video=join(folder,'video.md');
18
+ writeFileSync(video,'---\nedl: ./video.edl.json\n---\n'+BASE);
19
+ writeFileSync(join(folder,'video.edl.json'),JSON.stringify(EDL));
20
+ return {folder,video,cleanup:()=>rmSync(folder,{recursive:true,force:true})};
21
+ }
22
+
23
+ test('frontmatter declares sidecar, same-basename sidecar is automatically discovered',()=>{
24
+ const f=setup();
25
+ try {
26
+ assert.equal(frontmatterEdl(readFileSync(f.video,'utf8')),'./video.edl.json');
27
+ assert.equal(loadEditorDecision(f.video)?.edl.edits.length,2);
28
+ writeFileSync(f.video,BASE);
29
+ assert.equal(resolveEditorDecisionPath(f.video),join(f.folder,'video.edl.json'));
30
+ rmSync(join(f.folder,'video.edl.json'));
31
+ assert.equal(loadEditorDecision(f.video),null);
32
+ } finally {f.cleanup();}
33
+ });
34
+
35
+ test('converts decisions into playable Markcut Markdown with original source and visible shot reasoning',()=>{
36
+ const f=setup();
37
+ try{
38
+ const md=editorDecisionToMarkdown(f.video,EDL);
39
+ assert.match(md,/# video\nwidth:320 height:568 fps:24 layout:series/);
40
+ assert.match(md,/## EditorialIntent/);
41
+ assert.match(md,/## Shot1/);
42
+ assert.match(md,/## Shot2/);
43
+ assert.match(md,/startFrom:1 endAt:2 duration:1.0000/);
44
+ assert.match(md,/Set geography/);
45
+ assert.match(md,/retain source sound/);
46
+ assert.match(md,/- component duration:1.0000 jsx:/);
47
+ assert.equal((md.match(/- video src:/g)||[]).length,2);
48
+ assert.doesNotMatch(md,/src:https?:/);
49
+ }finally{f.cleanup();}
50
+ });
51
+
52
+ test('refuses malformed timing, duplicate shots and path traversal rather than rendering invented footage',()=>{
53
+ const f=setup();
54
+ try{
55
+ assert.throws(()=>validateEditorDecision({...EDL,edits:[{...EDL.edits[0],out_seconds:0}]}),/invalid in\/out/);
56
+ assert.throws(()=>validateEditorDecision({...EDL,edits:[EDL.edits[0],{...EDL.edits[0]}]}),/unique shot_id/);
57
+ assert.throws(()=>editorDecisionToMarkdown(f.video,{...EDL,edits:[{...EDL.edits[0],source_src:'../../outside.mp4'}]}),/missing or outside/);
58
+ writeFileSync(f.video,'---\nedl: ../outside.json\n---\n'+BASE);
59
+ assert.throws(()=>loadEditorDecision(f.video),/escapes the video directory/);
60
+ writeFileSync(f.video,'---\nedl: ./missing.json\n---\n'+BASE);
61
+ assert.throws(()=>loadEditorDecision(f.video),/Declared EDL not found/);
62
+ }finally{f.cleanup();}
63
+ });
@@ -2,7 +2,15 @@ export function buildPreviewBridgeScript() {
2
2
  return `
3
3
  const feedback=document.getElementById('feedback'),status=document.getElementById('status'),pathLabel=document.getElementById('path-label');
4
4
  let nextId=0,identity=null,busy=false,expectedPath=null,activePath=null,activeReview={delivery:"text"},expectedDelivery="text",expectedReadonly=false,submittedRevision=null,submission=null;
5
+ const standaloneDesign=typeof location!=='undefined' && location.pathname.endsWith('/_neoy/markcut/design.html');
6
+ if(standaloneDesign){window.__markcutDesignMode=true;document.body.classList.add('markcut-design-mode');}
7
+
5
8
  const comments=[];
9
+ let questions=[],questionAnswers={};
10
+ const isQuestionMode=()=>activeReview?.mode==='questions';
11
+ window.addEventListener('markcut:questions-change',event=>{
12
+ if(isQuestionMode())questionAnswers={...(event.detail?.answers||{})};
13
+ });
6
14
  let currentScene={sceneId:null,sceneName:null,sceneStart:0,timeSeconds:0},selectedId=0,nextCommentId=0;
7
15
  const mode=document.getElementById('comment-mode');
8
16
  const isViewOnly=()=>expectedReadonly||activeReview?.readonly===true;
@@ -238,14 +246,21 @@ function reviewReadonly(readonly,message){
238
246
  for(const id of ['approve','changes']){
239
247
  const button=document.getElementById(id);
240
248
  button.disabled=viewOnly||readonly;
241
- button.style.display=viewOnly?'none':'';
249
+ button.style.display=viewOnly||isQuestionMode()?'none':'';
242
250
  }
243
- document.getElementById('comment-entry').style.display=viewOnly?'none':'';
251
+ document.getElementById('comment-entry').style.display=viewOnly||isQuestionMode()?'none':'';
252
+ const actions=document.querySelector('.review-actions');
253
+ actions.style.display=isQuestionMode()?'flex':'';
254
+ actions.style.justifyContent=isQuestionMode()?'center':'';
255
+ actions.style.flexWrap=isQuestionMode()?'wrap':'';
256
+ const submitButton=document.getElementById('questions-submit');
257
+ submitButton.hidden=!isQuestionMode();
258
+ submitButton.disabled=!isQuestionMode()||viewOnly||readonly;
244
259
  if(readonly&&message)status.textContent=message;
245
260
  }
246
261
  async function renderRevision(data){
247
262
  const generation=++renderGeneration;
248
- if(identity?.revisionId&&identity.revisionId!==data.revisionId)clearComments();
263
+ if(!standaloneDesign&&identity?.revisionId&&identity.revisionId!==data.revisionId)clearComments();
249
264
  if(data.path){pathLabel.textContent=data.path;showVideoName(data.path,data.title||data.videoTitle);}
250
265
  if(!data.compiled&&!data.compiledUrl){status.textContent='Compiled scenes unavailable';return;}
251
266
  identity={requestId:data.requestId||data.operationId||data.revisionId,previewId:data.id,revisionId:data.revisionId,contentHash:data.contentHash};
@@ -258,7 +273,7 @@ async function renderRevision(data){
258
273
  let compiled=data.compiled;
259
274
  if(data.compiledUrl){
260
275
  const url=new URL(data.compiledUrl);
261
- if(url.origin!==__MARKCUT_ORIGIN__||!url.pathname.startsWith('/files/_neoy/markcut/cache/')||!(/^[a-f0-9]{64}[.]json$/.test(url.pathname.split('/').pop())))
276
+ if(url.origin!==__MARKCUT_ORIGIN__||!url.pathname.startsWith('/files/_neoy/markcut/cache/')||!(/^[a-f0-9]{64}(?:-[a-f0-9]{16})?[.]json$/.test(url.pathname.split('/').pop())))
262
277
  throw new Error('Invalid immutable preview URL');
263
278
  const response=await fetch(url.href,{cache:'force-cache'});
264
279
  if(!response.ok)throw new Error('Static compiled scenes unavailable: HTTP '+response.status);
@@ -267,6 +282,8 @@ async function renderRevision(data){
267
282
  if(generation!==renderGeneration)return;
268
283
  document.getElementById('interactive-ui').hidden=false;
269
284
  window.__markcutRevision={...data,compiled};
285
+ questions=(compiled.root?.children||compiled.children||[]).filter(scene=>scene.type==='scene').map((scene,index)=>({name:String(scene.name||'Q'+(index+1)),id:scene.id}));
286
+ questionAnswers={};
270
287
  window.dispatchEvent(new CustomEvent('markcut:revision',{detail:window.__markcutRevision}));
271
288
  status.textContent='';
272
289
  if(!data.compiledUrl){
@@ -285,6 +302,27 @@ async function renderRevision(data){
285
302
  reviewReadonly(true,'Preview unavailable or review state unverified: '+String(e));
286
303
  }
287
304
  }
305
+ // Editor Decisions are an informational subview, not the film approval target.
306
+ // Hide film-review actions while the editor-decision timeline is active.
307
+ let editorReviewControls=null;
308
+ window.addEventListener('markcut:edl-view',event=>{
309
+ const edl=Boolean(event.detail?.active);
310
+ const ids=['approve','changes','comment-entry'];
311
+ if(edl&&!editorReviewControls){
312
+ editorReviewControls=ids.map(id=>{
313
+ const node=document.getElementById(id);
314
+ return {node,display:node?.style.display,disabled:node?.disabled};
315
+ });
316
+ for(const item of editorReviewControls){
317
+ if(item.node){item.node.style.display='none';if('disabled' in item.node)item.node.disabled=true;}
318
+ }
319
+ }else if(!edl&&editorReviewControls){
320
+ for(const item of editorReviewControls){
321
+ if(item.node){item.node.style.display=item.display;if('disabled' in item.node)item.node.disabled=item.disabled;}
322
+ }
323
+ editorReviewControls=null;
324
+ }
325
+ });
288
326
  window.addEventListener('message',event=>{
289
327
  if(event.source!==window.parent)return;
290
328
  const message=event.data;
@@ -301,21 +339,21 @@ async function initialize(){
301
339
  catch(e){status.textContent=e.message||'MCP initialization failed';}
302
340
  }
303
341
  async function submit(decision){
304
- if(busy||isViewOnly())return;
305
- if(document.getElementById(decision==='approved'?'approve':'changes').disabled){
342
+ if(standaloneDesign||busy||isViewOnly())return;
343
+ if(document.getElementById(isQuestionMode()?'questions-submit':(decision==='approved'?'approve':'changes')).disabled){
306
344
  status.textContent='Review disabled for this revision or delivery configuration.';return;
307
345
  }
308
346
  // The submission button must save a draft, not silently require a second '+' action.
309
- if(feedback.value.trim()){
347
+ if(!isQuestionMode()&&feedback.value.trim()){
310
348
  if(decision==='approved'){
311
349
  status.textContent='You have draft feedback. Submit feedback or clear it before approving.';
312
350
  return;
313
351
  }
314
352
  if(!saveDraft({fallbackOverall:true}))return;
315
353
  }
316
- const preparedComments=allComments();
317
- if(decision==='changes_requested'&&!preparedComments.length){status.textContent='Feedback is required.';return;}
318
- if(decision==='approved'&&preparedComments.length){status.textContent='Submit or remove draft comments before approval.';return;}
354
+ const preparedComments=isQuestionMode()?questions.map(q=>({scope:'scene',text:questionAnswers[q.name]||'',playbackContext:{sceneId:q.id||null,sceneName:q.name,sceneStart:0,timeSeconds:0}})):allComments();
355
+ if(!isQuestionMode()&&decision==='changes_requested'&&!preparedComments.length){status.textContent='Feedback is required.';return;}
356
+ if(!isQuestionMode()&&decision==='approved'&&preparedComments.length){status.textContent='Submit or remove draft comments before approval.';return;}
319
357
  if(!identity){status.textContent='Preview identity unavailable.';return;}
320
358
  if(window.__markcutRevision?.compiledUrl){
321
359
  try{if(!await currentRevisionMatches(activePath,identity.contentHash)){reviewReadonly(true,'Historical Preview · Read-only');return;}}
@@ -325,6 +363,7 @@ async function submit(decision){
325
363
  sceneId:item.playbackContext?.sceneId||null,timeSeconds:Number(item.playbackContext?.timeSeconds)||0,
326
364
  text:item.text,scope:item.scope,playbackContext:item.playbackContext
327
365
  }))};
366
+ if(isQuestionMode()){result.status='submitted';result.answers=questions.map(q=>({questionId:q.name,answer:questionAnswers[q.name]||''}));}
328
367
  // Retain the same submission key across retries, including lost ACKs.
329
368
  const signature=JSON.stringify({result,delivery:activeReview.delivery});
330
369
  if(!submission || submission.signature!==signature)submission={signature,key:crypto.randomUUID()};
@@ -341,14 +380,55 @@ async function submit(decision){
341
380
  if(!delivered){busy=false;return;}
342
381
  if(identity?.revisionId===submittedId){submittedRevision=submittedId;status.textContent=activeReview.delivery==='event'
343
382
  ? 'Review event submitted (transport accepted; awaiting consumer).'
344
- : (decision==='approved'?'Review sent.':'Feedback sent. Waiting for the updated preview.');}
383
+ : (isQuestionMode()?'Answers submitted.':(decision==='approved'?'Review sent.':'Feedback sent. Waiting for the updated preview.'));}
345
384
  }
346
385
  catch(e){busy=false;status.textContent='Review not submitted: '+(e.message||'Unable to submit review');}
347
386
  }
387
+ document.getElementById('questions-submit').onclick=()=>submit('approved');
348
388
  document.getElementById('approve').onclick=()=>submit('approved');
349
389
  document.getElementById('changes').onclick=()=>submit('changes_requested');
350
390
  redrawComments();
351
391
  updateDeliveryMode();
352
- initialize();
392
+ if(standaloneDesign){
393
+ // Agent reads draft notes via WebHelm in the shared tab; design notes are
394
+ // never published as a review or sent to an MCP host.
395
+ window.__markcutDesignNotes=()=>allComments();
396
+ const rawPath=new URLSearchParams(location.search).get('path');
397
+ // The browser can only address a public, mounted Markdown file. Never
398
+ // expose a local absolute path, accept another origin, or query _neoy assets.
399
+ if(!rawPath || !/^\\/files\\/(?!_neoy\\/)[A-Za-z0-9_-]+\\/(?:[^/?#]+\\/)*[^/?#]+\\.md$/i.test(rawPath) ||
400
+ rawPath.split('/').some(part=>part==='.'||part==='..'||part.startsWith('.'))){
401
+ status.textContent='Invalid design path: use a mounted /files/<mount>/video.md URL.';
402
+ } else {
403
+ expectedPath=rawPath;
404
+ showVideoName(rawPath);
405
+ status.textContent='Waiting for Markcut compilation…';
406
+ const digestPromise=crypto.subtle.digest('SHA-256',new TextEncoder().encode(rawPath))
407
+ .then(bytes=>Array.from(new Uint8Array(bytes),x=>x.toString(16).padStart(2,'0')).join(''));
408
+ let loading=false;
409
+ async function refreshDesign(){
410
+ if(loading)return;
411
+ loading=true;
412
+ try{
413
+ const hash=await digestPromise;
414
+ const url=__MARKCUT_ORIGIN__+'/files/_neoy/markcut/revisions/'+hash+'.json?time='+Date.now();
415
+ const response=await fetch(url,{cache:'no-store'});
416
+ if(!response.ok){if(!identity)status.textContent='Waiting for Markcut compilation…';return;}
417
+ const data=await response.json();
418
+ if(data.requestedPath!==rawPath || !data.compiledUrl || typeof data.contentHash!=='string')return;
419
+ const changed=!identity || identity.contentHash!==data.contentHash ||
420
+ window.__markcutRevision?.edlCompiledUrl!==data.edlCompiledUrl;
421
+ if(changed){
422
+ // Preserve player context while React's existing player reloads its tree.
423
+ window.__markcutDesignRestoreTime=Number(window.__markcutPlaybackContext?.timeSeconds)||0;
424
+ await renderRevision({...data,review:{delivery:'text',readonly:true}});
425
+ }
426
+ }catch(error){status.textContent='Preview refresh failed: '+String(error?.message||error);}
427
+ finally{loading=false;}
428
+ }
429
+ refreshDesign();
430
+ window.setInterval(refreshDesign,2500);
431
+ }
432
+ } else initialize();
353
433
  `;
354
434
  }
@@ -14,10 +14,10 @@ try{
14
14
  if(actualHash!==sourceHash)throw new Error("Source changed while queued; retry preview");
15
15
  const result=await ensureVideoPreview(path,{onProgress:update});
16
16
  update("publishing");
17
- publishPreviewRevision(requestedPath,{...result,requestedPath});
17
+ publishPreviewRevision(requestedPath,{...result,requestedPath,...(review.title ? {title:review.title} : {})});
18
18
  // Markcut is a pure preview provider. The Neo MCP wrapper owns mobile delivery.
19
19
  writeOperation(id,{id,state:"ready",stage:"complete",startedAt,updatedAt:Date.now(),requestedPath,
20
- result:{...result,requestedPath,requestId:id,review}});
20
+ result:{...result,requestedPath,requestId:id,review,...(review.title ? {title:review.title} : {})}});
21
21
 
22
22
  }catch(e){
23
23
  writeOperation(id,{id,state:"failed",stage:"failed",startedAt,updatedAt:Date.now(),requestedPath,review,error:e?.message||String(e)});