@morshoto/framekit 0.1.5 → 0.1.6

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.
@@ -42,7 +42,8 @@ function validateAssertion(assertion, index) {
42
42
  return;
43
43
  }
44
44
  if (assertion.type === "audio-loudness") {
45
- if (!Number.isFinite(assertion.targetLufs)
45
+ if ((assertion.occurrenceId !== undefined && !assertion.occurrenceId.trim())
46
+ || !Number.isFinite(assertion.targetLufs)
46
47
  || assertion.toleranceDb !== undefined
47
48
  && (!Number.isFinite(assertion.toleranceDb) || assertion.toleranceDb < 0)) {
48
49
  throw new Error(`INVALID_VERIFICATION_POLICY: ${path} has invalid loudness values`);
@@ -125,6 +126,13 @@ export class DefaultVerificationEngine {
125
126
  detail: constructionStateDetail(transaction),
126
127
  });
127
128
  }
129
+ if (transaction.planned.some((operation) => operation.type === "timeline.mask.add")) {
130
+ checks.push({
131
+ name: "mask-state",
132
+ passed: maskStateIsValid(transaction),
133
+ detail: maskStateDetail(transaction),
134
+ });
135
+ }
128
136
  if (policy.requireExpectedChange !== false) {
129
137
  checks.push({
130
138
  name: "expected-change",
@@ -136,8 +144,9 @@ export class DefaultVerificationEngine {
136
144
  }
137
145
  if (policy.maxTruePeakDb !== undefined) {
138
146
  const peaks = transaction.attemptedAfter.media
147
+ .filter((media) => media.audio?.valid !== false)
139
148
  .map((media) => media.audio?.truePeakDb)
140
- .filter((peak) => peak !== undefined);
149
+ .filter((peak) => peak !== undefined && Number.isFinite(peak));
141
150
  const passed = peaks.length > 0 && peaks.every((peak) => peak <= policy.maxTruePeakDb);
142
151
  checks.push({
143
152
  name: "true-peak-limit",
@@ -150,8 +159,9 @@ export class DefaultVerificationEngine {
150
159
  if (policy.targetLufs !== undefined) {
151
160
  const tolerance = policy.loudnessToleranceDb ?? 0.5;
152
161
  const loudness = transaction.attemptedAfter.media
162
+ .filter((media) => media.audio?.valid !== false)
153
163
  .map((media) => media.audio?.integratedLufs)
154
- .filter((value) => value !== undefined);
164
+ .filter((value) => value !== undefined && Number.isFinite(value));
155
165
  const passed = loudness.length > 0 && loudness.every((value) => Math.abs(value - policy.targetLufs) <= tolerance);
156
166
  checks.push({
157
167
  name: "integrated-loudness-target",
@@ -331,9 +341,26 @@ function verifyAudioLoudness(transaction, assertion) {
331
341
  const toleranceDb = assertion.toleranceDb ?? 0.5;
332
342
  const expected = {
333
343
  mediaId: assertion.mediaId,
344
+ ...(assertion.occurrenceId ? { occurrenceId: assertion.occurrenceId } : {}),
334
345
  targetLufs: assertion.targetLufs,
335
346
  toleranceDb,
336
347
  };
348
+ const occurrence = assertion.occurrenceId
349
+ ? transaction.attemptedAfter.timeline.clips.find((clip) => clip.id === assertion.occurrenceId)
350
+ : undefined;
351
+ if (assertion.occurrenceId && (!occurrence || occurrence.mediaId !== assertion.mediaId)) {
352
+ return {
353
+ name: assertion.type,
354
+ passed: false,
355
+ status: "failed",
356
+ expected,
357
+ observed: { mediaId: assertion.mediaId, occurrenceId: assertion.occurrenceId },
358
+ reason: !occurrence ? "OCCURRENCE_NOT_FOUND" : "TARGET_MISMATCH",
359
+ detail: !occurrence
360
+ ? `expected occurrence ${assertion.occurrenceId}, but it was not observed`
361
+ : `occurrence ${assertion.occurrenceId} does not reference media ${assertion.mediaId}`,
362
+ };
363
+ }
337
364
  const media = transaction.attemptedAfter.media.find((candidate) => candidate.mediaId === assertion.mediaId);
338
365
  if (!media) {
339
366
  return {
@@ -357,6 +384,19 @@ function verifyAudioLoudness(transaction, assertion) {
357
384
  detail: `audio analysis is unavailable for media ${assertion.mediaId}`,
358
385
  };
359
386
  }
387
+ if (media.audio.valid === false
388
+ || !Number.isFinite(media.audio.integratedLufs)
389
+ || !Number.isFinite(media.audio.truePeakDb)) {
390
+ return {
391
+ name: assertion.type,
392
+ passed: false,
393
+ status: "failed",
394
+ expected,
395
+ observed: media.audio,
396
+ reason: "AUDIO_MEASUREMENT_INVALID",
397
+ detail: `audio measurement for media ${assertion.mediaId} is invalid`,
398
+ };
399
+ }
360
400
  const observed = media.audio.integratedLufs;
361
401
  const passed = Math.abs(observed - assertion.targetLufs) <= toleranceDb;
362
402
  return {
@@ -652,9 +692,23 @@ function audioStateDetail(transaction) {
652
692
  ? "music placement, duration, gain, and fades match the planned audio state"
653
693
  : "music placement, duration, gain, or fades do not match the planned audio state";
654
694
  }
695
+ function maskStateIsValid(transaction) {
696
+ return transaction.planned.every((operation) => {
697
+ if (operation.type !== "timeline.mask.add")
698
+ return true;
699
+ const clip = transaction.after.timeline.clips.find(({ id }) => id === operation.occurrenceId);
700
+ return clip?.mask !== undefined && JSON.stringify(clip.mask) === JSON.stringify(operation.mask);
701
+ });
702
+ }
703
+ function maskStateDetail(transaction) {
704
+ return maskStateIsValid(transaction)
705
+ ? "mask target and requested configuration match the canonical timeline state"
706
+ : "mask target or requested configuration does not match the canonical timeline state";
707
+ }
655
708
  function isConstructionOperation(operation) {
656
709
  return operation.type === "media.import"
657
710
  || operation.type === "timeline.media.add"
711
+ || operation.type === "timeline.picture-in-picture.add"
658
712
  || operation.type === "timeline.media.move"
659
713
  || operation.type === "timeline.media.replace"
660
714
  || operation.type === "timeline.media.remove"
@@ -673,6 +727,7 @@ function constructionStateIsValid(transaction) {
673
727
  && media.sourceDigest === operation.sourceDigest;
674
728
  }
675
729
  if (operation.type === "timeline.media.add"
730
+ || operation.type === "timeline.picture-in-picture.add"
676
731
  || operation.type === "timeline.media.move"
677
732
  || operation.type === "timeline.media.replace"
678
733
  || operation.type === "timeline.media.remove"
@@ -714,6 +769,10 @@ function expectedConstructionClips(transaction) {
714
769
  duration: clip.duration,
715
770
  track: clip.track,
716
771
  attachedTo: clip.attachedTo,
772
+ position: clip.position,
773
+ scale: clip.scale,
774
+ crop: clip.crop,
775
+ frame: clip.frame,
717
776
  }]));
718
777
  const media = new Map(transaction.before.media.map((item) => [item.mediaId, item]));
719
778
  for (const operation of transaction.planned) {
@@ -730,6 +789,20 @@ function expectedConstructionClips(transaction) {
730
789
  });
731
790
  continue;
732
791
  }
792
+ if (operation.type === "timeline.picture-in-picture.add") {
793
+ clips.set(operation.occurrenceId, {
794
+ mediaId: operation.mediaId,
795
+ start: operation.start,
796
+ duration: operation.duration,
797
+ track: operation.targetLane,
798
+ attachedTo: operation.attachedTo,
799
+ position: operation.position,
800
+ scale: operation.scale,
801
+ crop: operation.crop,
802
+ frame: operation.frame,
803
+ });
804
+ continue;
805
+ }
733
806
  if (operation.type === "timeline.title.add") {
734
807
  clips.set(operation.occurrenceId, {
735
808
  start: operation.start,
@@ -800,7 +873,11 @@ function sameConstructionClip(actual, expected) {
800
873
  && actual.start === expected.start
801
874
  && actual.duration === expected.duration
802
875
  && actual.track === expected.track
803
- && actual.attachedTo === expected.attachedTo;
876
+ && actual.attachedTo === expected.attachedTo
877
+ && JSON.stringify(actual.position) === JSON.stringify(expected.position)
878
+ && actual.scale === expected.scale
879
+ && JSON.stringify(actual.crop) === JSON.stringify(expected.crop)
880
+ && JSON.stringify(actual.frame) === JSON.stringify(expected.frame);
804
881
  }
805
882
  function applyExpectedRippleDelete(clips, start, end) {
806
883
  const removedDuration = end - start;
@@ -62,6 +62,7 @@ export class InMemoryEditorAdapter {
62
62
  compositeTransactions: true,
63
63
  mediaImport: true,
64
64
  mediaPlacement: true,
65
+ pictureInPicture: true,
65
66
  titlePlacement: true,
66
67
  clipMove: true,
67
68
  clipReplace: true,
@@ -71,6 +72,8 @@ export class InMemoryEditorAdapter {
71
72
  audioMixing: true,
72
73
  noiseReduction: true,
73
74
  colorCorrection: true,
75
+ masking: true,
76
+ personCutout: false,
74
77
  semanticOperations: {
75
78
  "rename-clip": true,
76
79
  "trim-clip": true,
@@ -81,6 +84,7 @@ export class InMemoryEditorAdapter {
81
84
  "add-marker": true,
82
85
  "media.import": true,
83
86
  "timeline.media.add": true,
87
+ "timeline.picture-in-picture.add": true,
84
88
  "timeline.audio.fades": true,
85
89
  "timeline.title.add": true,
86
90
  "timeline.media.move": true,
@@ -89,6 +93,7 @@ export class InMemoryEditorAdapter {
89
93
  "timeline.transition.add": true,
90
94
  "timeline.audio.attach": true,
91
95
  "timeline.audio.mix": true,
96
+ "timeline.mask.add": true,
92
97
  },
93
98
  },
94
99
  analyzers: {
@@ -277,6 +282,76 @@ export class InMemoryEditorAdapter {
277
282
  },
278
283
  };
279
284
  }
285
+ if (operation.type === "timeline.picture-in-picture.add") {
286
+ const media = snapshot.media.find((candidate) => candidate.mediaId === operation.mediaId);
287
+ if (!media)
288
+ throw new Error(`MEDIA_NOT_FOUND: ${operation.mediaId}`);
289
+ if (media.mediaKind !== undefined && media.mediaKind !== "video") {
290
+ throw new Error(`MEDIA_KIND_MISMATCH: ${operation.mediaId}`);
291
+ }
292
+ if (snapshot.timeline.clips.some((clip) => clip.id === operation.occurrenceId)) {
293
+ throw new Error(`OCCURRENCE_ALREADY_EXISTS: ${operation.occurrenceId}`);
294
+ }
295
+ const anchor = snapshot.timeline.clips.find((clip) => clip.id === operation.attachedTo);
296
+ if (!anchor)
297
+ throw new Error(`CLIP_NOT_FOUND: ${operation.attachedTo}`);
298
+ if (anchor.role !== undefined && anchor.role !== "video") {
299
+ throw new Error("INVALID_OPERATION: PIP anchor must be a video occurrence");
300
+ }
301
+ if (!Number.isFinite(operation.start) || !Number.isFinite(operation.duration)
302
+ || operation.start < anchor.start
303
+ || operation.duration <= 0
304
+ || operation.start + operation.duration > anchor.start + anchor.duration
305
+ || media.duration !== undefined && operation.duration > media.duration
306
+ || !Number.isInteger(operation.targetLane)
307
+ || operation.targetLane === 0
308
+ || !Number.isFinite(operation.position.x)
309
+ || !Number.isFinite(operation.position.y)
310
+ || !Number.isFinite(operation.scale)
311
+ || operation.scale <= 0) {
312
+ throw new Error("INVALID_OPERATION: PIP timing, connected lane, position, and scale are invalid");
313
+ }
314
+ if (operation.crop)
315
+ assertPictureInPictureCrop(operation.crop);
316
+ if (operation.frame)
317
+ assertPictureInPictureFrame(operation.frame);
318
+ const clip = withClipTime({
319
+ id: operation.occurrenceId,
320
+ mediaId: operation.mediaId,
321
+ name: media.source.split("/").pop() || media.mediaId,
322
+ start: operation.start,
323
+ duration: operation.duration,
324
+ track: operation.targetLane,
325
+ role: "video",
326
+ attachedTo: operation.attachedTo,
327
+ position: structuredClone(operation.position),
328
+ scale: operation.scale,
329
+ ...(operation.crop ? { crop: structuredClone(operation.crop) } : {}),
330
+ ...(operation.frame ? { frame: structuredClone(operation.frame) } : {}),
331
+ });
332
+ return {
333
+ ...snapshot,
334
+ timeline: {
335
+ ...snapshot.timeline,
336
+ clips: [...snapshot.timeline.clips, clip],
337
+ storyElements: [...snapshot.timeline.storyElements, {
338
+ id: clip.id,
339
+ kind: "asset-clip",
340
+ start: clip.start,
341
+ duration: clip.duration,
342
+ startTime: clip.startTime,
343
+ durationTime: clip.durationTime,
344
+ lane: clip.track,
345
+ mediaId: clip.mediaId,
346
+ attachedTo: clip.attachedTo,
347
+ position: clip.position,
348
+ scale: clip.scale,
349
+ ...(clip.crop ? { crop: clip.crop } : {}),
350
+ ...(clip.frame ? { frame: clip.frame } : {}),
351
+ }],
352
+ },
353
+ };
354
+ }
280
355
  if (operation.type === "timeline.audio.fades") {
281
356
  const clip = snapshot.timeline.clips.find(({ id }) => id === operation.clipId);
282
357
  if (!clip)
@@ -525,6 +600,32 @@ export class InMemoryEditorAdapter {
525
600
  fadeOut,
526
601
  });
527
602
  }
603
+ if (operation.type === "timeline.mask.add") {
604
+ const matches = snapshot.timeline.clips.filter(({ id }) => id === operation.occurrenceId);
605
+ if (matches.length === 0)
606
+ throw new Error(`CLIP_NOT_FOUND: ${operation.occurrenceId}`);
607
+ if (matches.length > 1)
608
+ throw new Error(`AMBIGUOUS_MASK_TARGET: ${operation.occurrenceId}`);
609
+ if (operation.mask.mode === "person-cutout") {
610
+ throw new Error("CAPABILITY_UNAVAILABLE: person cutout");
611
+ }
612
+ const clip = matches[0];
613
+ const media = clip.mediaId ? snapshot.media.find(({ mediaId }) => mediaId === clip.mediaId) : undefined;
614
+ if (clip.role === "audio" || clip.role === "music" || media?.mediaKind === "audio") {
615
+ throw new Error("MASK_TARGET_INCOMPATIBLE: masking requires a video clip");
616
+ }
617
+ if (operation.mask.mode === "supplied-alpha") {
618
+ const alpha = snapshot.media.find(({ mediaId }) => mediaId === operation.mask.alphaMediaId);
619
+ if (!alpha)
620
+ throw new Error(`MEDIA_NOT_FOUND: ${operation.mask.alphaMediaId}`);
621
+ if (alpha.mediaKind !== "video")
622
+ throw new Error(`MEDIA_KIND_MISMATCH: ${operation.mask.alphaMediaId}`);
623
+ }
624
+ return this.updateClip(snapshot, {
625
+ ...clip,
626
+ mask: structuredClone(operation.mask),
627
+ });
628
+ }
528
629
  if (operation.type === "reduce-noise") {
529
630
  const clip = snapshot.timeline.clips.find(({ id }) => id === operation.clipId);
530
631
  if (!clip)
@@ -622,6 +723,7 @@ export class InMemoryEditorAdapter {
622
723
  lane: updatedClip.track,
623
724
  ...(updatedClip.mediaId ? { mediaId: updatedClip.mediaId } : {}),
624
725
  ...(updatedClip.attachedTo ? { attachedTo: updatedClip.attachedTo } : {}),
726
+ ...(updatedClip.mask ? { mask: structuredClone(updatedClip.mask) } : {}),
625
727
  }
626
728
  : element),
627
729
  },
@@ -633,6 +735,9 @@ export class InMemoryEditorAdapter {
633
735
  if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || end <= start) {
634
736
  throw new Error("INVALID_OPERATION: ripple delete range must be positive");
635
737
  }
738
+ if (end > snapshot.timeline.duration) {
739
+ throw new Error(`INVALID_OPERATION: ripple delete range [${start}, ${end}) must fit timeline bounds [0, ${snapshot.timeline.duration})`);
740
+ }
636
741
  const removedDuration = end - start;
637
742
  const clips = snapshot.timeline.clips.flatMap((clip) => {
638
743
  const clipEnd = clip.start + clip.duration;
@@ -743,6 +848,7 @@ function createSnapshot(fixture) {
743
848
  name: fixture.timelineName,
744
849
  duration: clips.reduce((end, clip) => Math.max(end, clip.start + clip.duration), 0),
745
850
  durationTime: decimalToRational(clips.reduce((end, clip) => Math.max(end, clip.start + clip.duration), 0)),
851
+ ...(fixture.frameDuration ? { frameDuration: structuredClone(fixture.frameDuration) } : {}),
746
852
  clips,
747
853
  storyElements: clips.map((clip) => ({
748
854
  id: clip.id,
@@ -754,6 +860,11 @@ function createSnapshot(fixture) {
754
860
  lane: clip.track,
755
861
  mediaId: clip.mediaId,
756
862
  ...(clip.attachedTo ? { attachedTo: clip.attachedTo } : {}),
863
+ ...(clip.position ? { position: structuredClone(clip.position) } : {}),
864
+ ...(clip.scale !== undefined ? { scale: clip.scale } : {}),
865
+ ...(clip.crop ? { crop: structuredClone(clip.crop) } : {}),
866
+ ...(clip.frame ? { frame: structuredClone(clip.frame) } : {}),
867
+ ...(clip.mask ? { mask: structuredClone(clip.mask) } : {}),
757
868
  })),
758
869
  markers: (fixture.markers ?? []).map((marker) => normalizeMarker(marker)),
759
870
  captions: (fixture.captions ?? []).map((caption) => normalizeCaption(caption)),
@@ -802,3 +913,17 @@ function isMediaCompatible(role, mediaKind) {
802
913
  return false;
803
914
  return true;
804
915
  }
916
+ function assertPictureInPictureCrop(crop) {
917
+ const values = [crop.top, crop.right, crop.bottom, crop.left];
918
+ if (!values.every((value) => Number.isFinite(value) && value >= 0 && value < 1)
919
+ || crop.left + crop.right >= 1
920
+ || crop.top + crop.bottom >= 1) {
921
+ throw new Error("INVALID_OPERATION: PIP crop must leave a positive source rectangle");
922
+ }
923
+ }
924
+ function assertPictureInPictureFrame(frame) {
925
+ if (frame.style !== "solid" || !/^#[0-9a-f]{6}$/i.test(frame.color)
926
+ || !Number.isFinite(frame.width) || frame.width < 0) {
927
+ throw new Error("INVALID_OPERATION: PIP frame must be a solid hex-colored non-negative width");
928
+ }
929
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morshoto/framekit",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "packageManager": "pnpm@12.3.4",
5
5
  "private": false,
6
6
  "type": "module",
@@ -28,6 +28,7 @@
28
28
  "test:golden": "tsx --test tests/golden/*.test.ts",
29
29
  "test:release-gate": "tsx --test tests/release-gate/*.test.ts",
30
30
  "release-gate": "tsx scripts/run-release-gate.ts",
31
+ "verify-release-provenance": "tsx scripts/verify-release-provenance.ts",
31
32
  "test:codex-plugin": "node scripts/codex-plugin-smoke.mjs",
32
33
  "test:clean-mcp-clients": "node scripts/clean-mcp-client-smoke.mjs",
33
34
  "evaluate": "tsx scripts/run-mcp-evaluation.ts",
@@ -41,6 +42,9 @@
41
42
  "test:watch": "tsx --test --watch tests/integration/*.test.ts tests/evaluation/*.test.ts tests/filler-removal/*.test.ts tests/golden/*.test.ts",
42
43
  "test:final-cut-disposable-headed": "node scripts/final-cut-disposable-native-headed-e2e.mjs",
43
44
  "test:final-cut-transition-headed": "node scripts/final-cut-transition-headed-e2e.mjs",
45
+ "test:final-cut-pip-headed": "node scripts/final-cut-picture-in-picture-headed-e2e.mjs",
46
+ "test:final-cut-masking-headed": "node scripts/final-cut-masking-headed-e2e.mjs",
47
+ "test:final-cut-title-headed": "node scripts/final-cut-title-discovery-headed-e2e.mjs",
44
48
  "hooks:install": "node scripts/install-git-hooks.mjs",
45
49
  "mcp": "tsx apps/mcp-server/src/main.ts",
46
50
  "framekit": "node ./bin/framekit.mjs",
@@ -65,6 +69,7 @@
65
69
  "zod": "^3.25.76"
66
70
  },
67
71
  "devDependencies": {
72
+ "@openai/codex": "0.144.1",
68
73
  "@types/node": "24.13.3",
69
74
  "tsc-alias": "1.9.4",
70
75
  "tsx": "4.23.13",