@lalalic/markcut 3.2.34 → 3.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +17 -302
- package/README.md +9 -0
- package/docs/developer-reference.md +311 -0
- package/package.json +1 -1
- package/skills/markcut/SKILL.md +56 -107
- package/skills/markcut/docs/markdown-descriptive.md +2 -2
- package/skills/markcut/evals/README.md +29 -0
- package/skills/markcut/evals/cases.json +227 -0
- package/skills/markcut/evals/check.mjs +80 -0
- package/skills/markcut/evals/check.selftest.mjs +48 -0
- package/skills/markcut/evals/run-codex.mjs +87 -0
- package/skills/markcut/references/mcp-preview-lifecycle.md +14 -0
- package/skills/markcut/references/preview-troubleshooting.md +21 -49
- package/skills/markcut/review.md +52 -465
- package/src/config.mjs +3 -1
- package/src/render/cli.mjs +5 -2
- package/src/render/validate-assets.mjs +19 -0
- package/src/vision/cli.mjs +79 -28
- package/src/vision/vision_prompts.md +5 -3
- package/tests/validate-assets.test.ts +26 -0
- package/tests/vision-generic-vtt-hooks.test.ts +77 -0
- package/tests/vitest.publish.config.ts +1 -0
package/src/vision/cli.mjs
CHANGED
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
* --label Open label preview → then continue with full AI pipeline
|
|
24
24
|
* --prompts-file <path> Path to prompts markdown file (default: vision_prompts.md)
|
|
25
25
|
* --vtt-sample-interval <n> Sample one video frame every N seconds (default: 5)
|
|
26
|
+
--vtt <template> Video-to-text CLI, accepts {input}, {prompt_quoted}, {sample_interval}
|
|
27
|
+
--itt <template> Image-to-text CLI, accepts {input} and {prompt_quoted}
|
|
28
|
+
--agent <template> Semantic segmentation Agent CLI
|
|
26
29
|
* --context "text" Background context about people/places (injected into prompts)
|
|
27
30
|
* --pick <files> Comma-separated filenames to process
|
|
28
31
|
* --skip-stt Skip speech-to-text for videos
|
|
@@ -373,9 +376,16 @@ function runITT(inputPaths, promptText, ittCli) {
|
|
|
373
376
|
const paths = Array.isArray(inputPaths) ? inputPaths : [inputPaths];
|
|
374
377
|
const tmpl = ittCli || DEFAULT_ITT_CLI;
|
|
375
378
|
const inputStr = paths.map(p => `${shQuote(p)}`).join(" ");
|
|
376
|
-
const cmd = substituteTemplate(tmpl, {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
+
const cmd = substituteTemplate(tmpl, {
|
|
380
|
+
input: inputStr, prompt: promptText, prompt_quoted: shQuote(promptText),
|
|
381
|
+
});
|
|
382
|
+
try {
|
|
383
|
+
const text = run(cmd).trim();
|
|
384
|
+
if (!text) throw new Error("Empty visual inference response");
|
|
385
|
+
return text;
|
|
386
|
+
} catch (e) {
|
|
387
|
+
throw new Error("ITT failed for " + basename(paths[0]) + ": " + e.message);
|
|
388
|
+
}
|
|
379
389
|
}
|
|
380
390
|
|
|
381
391
|
function extractVideoFrames(videoPath, intervalSeconds = DEFAULT_VTT_SAMPLE_INTERVAL) {
|
|
@@ -402,7 +412,10 @@ function extractVideoFrames(videoPath, intervalSeconds = DEFAULT_VTT_SAMPLE_INTE
|
|
|
402
412
|
|
|
403
413
|
function runVTT(videoPath, promptText, vttCli, ittCli, sampleInterval = DEFAULT_VTT_SAMPLE_INTERVAL) {
|
|
404
414
|
if (vttCli) {
|
|
405
|
-
const tryRun = () => { const cmd = substituteTemplate(vttCli, {
|
|
415
|
+
const tryRun = () => { const cmd = substituteTemplate(vttCli, {
|
|
416
|
+
input: shQuote(videoPath), prompt: promptText, prompt_quoted: shQuote(promptText),
|
|
417
|
+
sample_interval: String(sampleInterval),
|
|
418
|
+
}); return run(cmd, { timeout: 600_000 }).trim(); };
|
|
406
419
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
407
420
|
try { return tryRun(); } catch (e) {
|
|
408
421
|
const msg = e.message || "";
|
|
@@ -410,7 +423,7 @@ function runVTT(videoPath, promptText, vttCli, ittCli, sampleInterval = DEFAULT_
|
|
|
410
423
|
emitWarn(` Corrupted video file, removing and retrying...`);
|
|
411
424
|
try { rmSync(videoPath, { force: true }); } catch {} continue;
|
|
412
425
|
}
|
|
413
|
-
|
|
426
|
+
throw new Error(`VTT failed for ${basename(videoPath)}: ${msg}`);
|
|
414
427
|
}
|
|
415
428
|
}
|
|
416
429
|
return "";
|
|
@@ -422,9 +435,8 @@ function runVTT(videoPath, promptText, vttCli, ittCli, sampleInterval = DEFAULT_
|
|
|
422
435
|
.map((item, i) => `Frame ${i + 1}: approximately ${item.seconds.toFixed(1)}s`)
|
|
423
436
|
.join("\n");
|
|
424
437
|
const framePrompt = `${promptText}\n\nThe attached frames are ordered chronologically. Approximate timing:\n${timingContext}`;
|
|
425
|
-
|
|
426
|
-
extracted.cleanup();
|
|
427
|
-
return result;
|
|
438
|
+
try { return runITT(extracted.frames, framePrompt, ittCli); }
|
|
439
|
+
finally { extracted.cleanup(); }
|
|
428
440
|
}
|
|
429
441
|
|
|
430
442
|
/**
|
|
@@ -437,7 +449,7 @@ function runAgent(clipPath, promptText, agentCli) {
|
|
|
437
449
|
// Always quote the prompt text to avoid shell injection from multi-line content
|
|
438
450
|
const cmd = substituteTemplate(tmpl, { input: shQuote(clipPath), prompt: shQuote(promptText) });
|
|
439
451
|
try { return run(cmd, { timeout: 300_000 }).trim(); }
|
|
440
|
-
catch (e) {
|
|
452
|
+
catch (e) { throw new Error("Semantic segmentation Agent failed for " + basename(clipPath) + ": " + e.message); }
|
|
441
453
|
}
|
|
442
454
|
|
|
443
455
|
function runSTT(videoPath, normDir, sttCli) {
|
|
@@ -808,6 +820,7 @@ function analyzeVideo(videoPath, normInfo, normDir, prompts, context = "", userH
|
|
|
808
820
|
emitInfo(` Running video understanding...`);
|
|
809
821
|
const descPrompt = ctx + getPrompt(prompts, "video-perception");
|
|
810
822
|
const descRaw = runVTT(normInfo.path, descPrompt, DEFAULT_VTT_CLI, DEFAULT_ITT_CLI, sampleInterval);
|
|
823
|
+
if (!descRaw.trim()) throw new Error("Video-to-text returned no verified visual response");
|
|
811
824
|
const descText = stripThinkBlocks(extractRawText(descRaw));
|
|
812
825
|
perception.desc = descText.slice(0, 500) || looseJSONParse(descRaw)?.desc || descRaw.slice(0, 500);
|
|
813
826
|
|
|
@@ -858,22 +871,44 @@ function analyzeVideo(videoPath, normInfo, normDir, prompts, context = "", userH
|
|
|
858
871
|
const segRaw = runAgent(dummyInput, `${segPrompt}\n\nInput:\n${segInput}`, DEFAULT_AGENT_CLI || DEFAULT_ITT_CLI);
|
|
859
872
|
const segParsed = looseJSONParse(segRaw);
|
|
860
873
|
|
|
861
|
-
if (segParsed
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
874
|
+
if (!segRaw.trim() || !segParsed || typeof segParsed !== "object" || Array.isArray(segParsed)) {
|
|
875
|
+
throw new Error("Semantic segmentation Agent returned no valid structured response");
|
|
876
|
+
}
|
|
877
|
+
if (Object.keys(segParsed).length > 0) {
|
|
878
|
+
const ranges = Object.keys(segParsed).map(key => {
|
|
879
|
+
const match = /^(\d+)to(\d+)$/.exec(key);
|
|
880
|
+
if (!match || !segParsed[key] || typeof segParsed[key] !== "object" || Array.isArray(segParsed[key])) {
|
|
881
|
+
throw new Error("Invalid Agent segment entry " + key);
|
|
882
|
+
}
|
|
883
|
+
return { start: Number(match[1]), end: Number(match[2]) };
|
|
884
|
+
}).sort((x,y) => x.start-y.start);
|
|
885
|
+
// Validate the optional project-supplied spoken instruction annotations.
|
|
886
|
+
// These remain metadata only: no action or edit is applied by Markcut.
|
|
887
|
+
for (const [key, segment] of Object.entries(segParsed)) {
|
|
888
|
+
if (segment.instructions == null) continue;
|
|
889
|
+
if (!Array.isArray(segment.instructions)) throw new Error("Invalid Agent instructions on " + key);
|
|
890
|
+
const [start,end] = key.split("to").map(Number);
|
|
891
|
+
for (const instruction of segment.instructions) {
|
|
892
|
+
if (!instruction || typeof instruction.utterance !== "string" || !instruction.utterance.trim() ||
|
|
893
|
+
typeof instruction.intent !== "string" || !instruction.intent.trim() ||
|
|
894
|
+
typeof instruction.time_seconds !== "number" || !Number.isFinite(instruction.time_seconds) ||
|
|
895
|
+
instruction.time_seconds * 1000 < start || instruction.time_seconds * 1000 > end) {
|
|
896
|
+
throw new Error("Unverifiable Agent instruction on " + key);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
872
899
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
900
|
+
let cursor = 0;
|
|
901
|
+
for (const range of ranges) {
|
|
902
|
+
if (range.start !== cursor || range.end <= range.start || range.end > totalDurMs) {
|
|
903
|
+
throw new Error("Agent segmentation must cover original source without gaps/overlaps");
|
|
904
|
+
}
|
|
905
|
+
cursor = range.end;
|
|
876
906
|
}
|
|
907
|
+
if (cursor !== totalDurMs) throw new Error("Agent segment timeline is incomplete");
|
|
908
|
+
segments = segParsed;
|
|
909
|
+
emitInfo(" Agent merged into " + Object.keys(segments).length + " source segments");
|
|
910
|
+
} else {
|
|
911
|
+
emitInfo(" Agent found no justified semantic boundaries; preserving one full-source segment");
|
|
877
912
|
}
|
|
878
913
|
}
|
|
879
914
|
|
|
@@ -1035,7 +1070,9 @@ async function runNormalizeAndPercept(folder, metadataPath, prompts, context, pi
|
|
|
1035
1070
|
const ctx = context ? `Context: ${context}\n\n` : "";
|
|
1036
1071
|
const imgPrompt = (userHint ? `User hint: ${userHint}\n\n` : "") + ctx + getPrompt(prompts, "image-perception");
|
|
1037
1072
|
const imgInput = `@${shQuote(normPath)}`;
|
|
1038
|
-
const imgCmd = substituteTemplate(DEFAULT_ITT_CLI, {
|
|
1073
|
+
const imgCmd = substituteTemplate(DEFAULT_ITT_CLI, {
|
|
1074
|
+
input: imgInput, prompt: imgPrompt, prompt_quoted: shQuote(imgPrompt),
|
|
1075
|
+
});
|
|
1039
1076
|
cacheKey = perceptionCacheKey(imgPath, imgCmd, "image");
|
|
1040
1077
|
if (cache[cacheKey]) {
|
|
1041
1078
|
perception = cache[cacheKey];
|
|
@@ -1075,12 +1112,15 @@ async function runNormalizeAndPercept(folder, metadataPath, prompts, context, pi
|
|
|
1075
1112
|
const vidPrompt = (userHint ? `User hint: ${userHint}\n\n` : "") + ctxV + getPrompt(prompts, "video-perception");
|
|
1076
1113
|
let vttActualCmd;
|
|
1077
1114
|
if (DEFAULT_VTT_CLI) {
|
|
1078
|
-
vttActualCmd = substituteTemplate(DEFAULT_VTT_CLI, {
|
|
1115
|
+
vttActualCmd = substituteTemplate(DEFAULT_VTT_CLI, {
|
|
1116
|
+
input: shQuote(normInfo.path), prompt: vidPrompt, prompt_quoted: shQuote(vidPrompt),
|
|
1117
|
+
sample_interval: String(vttSampleInterval),
|
|
1118
|
+
});
|
|
1079
1119
|
} else {
|
|
1080
1120
|
const dur = meta.duration || 0;
|
|
1081
1121
|
const n = Math.max(5, Math.min(10, Math.ceil(dur / vttSampleInterval)));
|
|
1082
1122
|
const framePaths = Array.from({ length: n }, (_, i) => `${basename(normInfo.path, extname(normInfo.path))}_${String(i + 1).padStart(3, "0")}.jpg`);
|
|
1083
|
-
vttActualCmd = substituteTemplate(DEFAULT_ITT_CLI, { input: framePaths.map(p => `@${p}`).join(" "), prompt: vidPrompt });
|
|
1123
|
+
vttActualCmd = substituteTemplate(DEFAULT_ITT_CLI, { input: framePaths.map(p => `@${p}`).join(" "), prompt: vidPrompt, prompt_quoted: shQuote(vidPrompt) });
|
|
1084
1124
|
}
|
|
1085
1125
|
cacheKey = perceptionCacheKey(vidPath, vttActualCmd, "video");
|
|
1086
1126
|
if (cache[cacheKey]) {
|
|
@@ -1118,6 +1158,9 @@ Options:
|
|
|
1118
1158
|
--instruct "text" Background context about people/places (injected into prompts)
|
|
1119
1159
|
--prompts-file <path> Path to prompts markdown file (default: vision_prompts.md)
|
|
1120
1160
|
--vtt-sample-interval <n> Sample one video frame every N seconds (default: 5)
|
|
1161
|
+
--vtt <template> Video-to-text CLI, accepts {input}, {prompt_quoted}, {sample_interval}
|
|
1162
|
+
--itt <template> Image-to-text CLI, accepts {input} and {prompt_quoted}
|
|
1163
|
+
--agent <template> Semantic segmentation Agent CLI
|
|
1121
1164
|
--pick <files> Comma-separated filenames to process
|
|
1122
1165
|
--skip-stt Skip speech-to-text for videos
|
|
1123
1166
|
--dry-run Show what would be processed without running AI
|
|
@@ -1156,6 +1199,7 @@ export async function main(args) {
|
|
|
1156
1199
|
const flag = args[i++];
|
|
1157
1200
|
if (flag === "--help") { printUsage(); return; }
|
|
1158
1201
|
else if (flag === "--label") { doLabel = true; }
|
|
1202
|
+
else if (["--itt", "--vtt", "--agent", "--stt", "--tts", "--tti", "--ttv", "--edit-cli"].includes(flag) && args[i]) { i++; }
|
|
1159
1203
|
else if (flag === "--candidate") { candidateMode = true; }
|
|
1160
1204
|
else if (flag === "--output" && args[i]) { output = resolve(args[i++]); }
|
|
1161
1205
|
else if (flag === "--model-command" && args[i]) { modelCommand = args[i++]; }
|
|
@@ -1175,12 +1219,15 @@ export async function main(args) {
|
|
|
1175
1219
|
else if (flag.startsWith("--") && args[i]) { promptOverrides.set(flag.slice(2), args[i++]); }
|
|
1176
1220
|
}
|
|
1177
1221
|
|
|
1178
|
-
if (!folder) {
|
|
1222
|
+
if (!folder) { throw new Error("No folder specified. Run markcut vision --help for usage."); }
|
|
1179
1223
|
folder = resolve(folder);
|
|
1180
1224
|
if (!existsSync(folder)) { emitError(`Folder not found: ${folder}`); process.exit(1); }
|
|
1181
1225
|
|
|
1182
1226
|
const prompts = loadPrompts(promptsFile);
|
|
1183
|
-
for (const [name, value] of promptOverrides)
|
|
1227
|
+
for (const [name, value] of promptOverrides) {
|
|
1228
|
+
if (!prompts.has(name)) throw new Error(`Unknown vision option: --${name}. See markcut vision --help and available prompt names.`);
|
|
1229
|
+
prompts.set(name, value);
|
|
1230
|
+
}
|
|
1184
1231
|
|
|
1185
1232
|
if (candidateMode) {
|
|
1186
1233
|
if (statSync(folder).isFile() && !VIDEO_EXTS.has(extname(folder).toLowerCase()) && extname(folder).toLowerCase() !== ".json") {
|
|
@@ -1216,6 +1263,10 @@ export async function main(args) {
|
|
|
1216
1263
|
return;
|
|
1217
1264
|
}
|
|
1218
1265
|
emitInfo(`\n🔧 Running full pipeline (normalize → perceive)...`);
|
|
1266
|
+
if (dryRun) {
|
|
1267
|
+
emitInfo(`Dry run: pick=${[...pickSet].join(",") || "all"}. No AI request was submitted.`);
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1219
1270
|
await runNormalizeAndPercept(folder, metadataPath, prompts, context, pickSet, vttSampleInterval, skipSTT);
|
|
1220
1271
|
}
|
|
1221
1272
|
}
|
|
@@ -39,12 +39,14 @@ You are an expert video editor. You are given candidate segment boundaries for a
|
|
|
39
39
|
Your task: merge these candidate boundaries into meaningful, coherent segments.
|
|
40
40
|
|
|
41
41
|
Rules:
|
|
42
|
-
- Each final segment should be a coherent narrative or visual unit (5-60 seconds)
|
|
42
|
+
- Each final segment should be a coherent narrative or visual unit (typically 5-60 seconds; shorter when the original source or evidence requires it)
|
|
43
43
|
- Respect user hint boundaries — they are the most reliable. If the user marked a boundary at 5s, keep it
|
|
44
44
|
- Use subtitle cues to refine: if a subtitle sentence crosses a user hint boundary, prefer the cue boundary
|
|
45
45
|
- Use ffprobe changes as tiebreakers only — they mark raw visual cuts, not narrative breaks
|
|
46
|
-
- Output ONLY a JSON object
|
|
46
|
+
- Output ONLY a JSON object whose keys are time ranges (milliseconds). Each value must have a "description" and may have "instructions".
|
|
47
47
|
- Descriptions: 5-20 words, summarize what happens in that segment (use user hint text or subtitle text)
|
|
48
|
+
- When **provided project context** defines an editing-instruction grammar or wake phrase, interpret matching transcript commands semantically, including continuation across nearby cues. Preserve them in optional "instructions":[{"utterance":"exact spoken words","intent":"plain language meaning","time_seconds":0.0,"confidence":"high|medium|low"}]. The time must be in the original source and fall inside the segment. Do NOT invent commands, confuse ordinary narration with instructions, or execute any edit.
|
|
49
|
+
- The "instructions" field is evidence for a later editor only; never remove or skip source intervals because of it. When no command is supported, omit "instructions" or return an empty array.
|
|
48
50
|
|
|
49
51
|
Input format:
|
|
50
52
|
```
|
|
@@ -61,7 +63,7 @@ Duration: 30000ms
|
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
Output format:
|
|
64
|
-
{"0to5000": {"description": "Introduction and welcome"}, "5000to15250": {"description": "Starting to swim"}, "15250to30000": {"description": "Building sandcastle"}}
|
|
66
|
+
{"0to5000": {"description": "Introduction and welcome"}, "5000to15250": {"description": "Starting to swim", "instructions": [{"utterance": "Keep this part", "intent": "Retain this source portion", "time_seconds": 8.2, "confidence": "high"}]}, "15250to30000": {"description": "Building sandcastle"}}
|
|
65
67
|
|
|
66
68
|
If inputs are too sparse for segmentation, return an empty object {}.
|
|
67
69
|
~~~
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
2
5
|
import {
|
|
3
6
|
classifyAssetPath,
|
|
4
7
|
collectTreeAssets,
|
|
5
8
|
validateAssetsRelative,
|
|
9
|
+
validateLocalAssetsExist,
|
|
6
10
|
} from "../src/render/validate-assets.mjs";
|
|
7
11
|
|
|
8
12
|
const BASE = "/proj/md";
|
|
@@ -104,3 +108,25 @@ describe("validateAssetsRelative", () => {
|
|
|
104
108
|
expect(validateAssetsRelative(null, BASE)).toEqual([]);
|
|
105
109
|
});
|
|
106
110
|
});
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
describe("verify-time local asset existence", () => {
|
|
114
|
+
it("rejects missing local files but ignores remote, inline, generated and include paths", () => {
|
|
115
|
+
const folder = mkdtempSync(join(tmpdir(), "markcut-assets-"));
|
|
116
|
+
try {
|
|
117
|
+
mkdirSync(join(folder, "assets"));
|
|
118
|
+
writeFileSync(join(folder, "assets", "here.jpg"), "mock");
|
|
119
|
+
const tree = { type: "root", children: [
|
|
120
|
+
{ type: "image", src: "assets/here.jpg" },
|
|
121
|
+
{ type: "image", src: "assets/missing.jpg" },
|
|
122
|
+
{ type: "image", src: "https://example.test/remote.png" },
|
|
123
|
+
{ type: "image", src: "assets/image_${width}.jpg" },
|
|
124
|
+
{ type: "subtitle", src: "caption text" },
|
|
125
|
+
{ type: "include", src: "../shared.md" }
|
|
126
|
+
] };
|
|
127
|
+
const errors = validateLocalAssetsExist(tree, folder, { skipIncludeSrc: true });
|
|
128
|
+
expect(errors).toHaveLength(1);
|
|
129
|
+
expect(errors[0]).toContain("assets/missing.jpg");
|
|
130
|
+
} finally { rmSync(folder, { recursive: true, force: true }); }
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe,it,expect,afterAll } from 'vitest';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
const base=resolve(import.meta.dirname,'..');
|
|
7
|
+
const dir=mkdtempSync(join(tmpdir(),'markcut-generic-hooks-'));
|
|
8
|
+
const media=join(dir,'media');
|
|
9
|
+
const visual=join(dir,'mock-visual.mjs');
|
|
10
|
+
const semantic=join(dir,'mock-segment-agent.mjs');
|
|
11
|
+
afterAll(()=>rmSync(dir,{force:true,recursive:true}));
|
|
12
|
+
it('generic --vtt/--itt plus --agent uses the existing STT→semantic segment workflow, no backend flag',()=>{
|
|
13
|
+
mkdirSync(media,{recursive:true});
|
|
14
|
+
execFileSync('ffmpeg',['-hide_banner','-loglevel','error','-y','-f','lavfi',
|
|
15
|
+
'-i','testsrc=size=320x240:rate=8:duration=4','-f','lavfi','-i',
|
|
16
|
+
'sine=frequency=440:sample_rate=44100:duration=4','-c:v','libx264','-pix_fmt',
|
|
17
|
+
'yuv420p','-c:a','aac','-shortest',join(media,'clip.mp4')]);
|
|
18
|
+
execFileSync('ffmpeg',['-hide_banner','-loglevel','error','-y','-f','lavfi',
|
|
19
|
+
'-i','color=c=blue:s=80x60','-frames:v','1',join(media,'photo.png')]);
|
|
20
|
+
writeFileSync(join(media,'clip.vtt'),'WEBVTT\n\n00:00.000 --> 00:01.500\n骑行刚开始。\n\n00:02.000 --> 00:03.700\n嘿 Neo,这里是一个重要镜头。\n');
|
|
21
|
+
writeFileSync(visual,[
|
|
22
|
+
'const args=process.argv.slice(2);',
|
|
23
|
+
'const prompt=args[args.indexOf("--prompt")+1];',
|
|
24
|
+
'const sample=args.includes("--sample-interval")?args[args.indexOf("--sample-interval")+1]:null;',
|
|
25
|
+
'if(sample && sample!=="2")process.exit(14);',
|
|
26
|
+
'console.log("Recognized landscape from WebHelm-style ITT/VTT hook. " + prompt.slice(0,60));',
|
|
27
|
+
].join('\n'));
|
|
28
|
+
writeFileSync(semantic,[
|
|
29
|
+
'const args=process.argv.slice(2);',
|
|
30
|
+
'const prompt=args[args.indexOf("--prompt")+1];',
|
|
31
|
+
'if(!prompt.includes("嘿 Neo"))process.exit(12);',
|
|
32
|
+
'console.log(JSON.stringify({"0to2000":{description:"intro"},',
|
|
33
|
+
'"2000to4000":{description:"important source moment",instructions:[{utterance:"嘿 Neo,这里是一个重要镜头",intent:"emphasize later",time_seconds:2.2,confidence:"high"}]}}));',
|
|
34
|
+
].join('\n'));
|
|
35
|
+
const escaped=(path:string)=>JSON.stringify(path);
|
|
36
|
+
const itm='node '+escaped(visual)+' --input {input} --prompt {prompt_quoted}';
|
|
37
|
+
const vtt=itm+' --sample-interval {sample_interval}';
|
|
38
|
+
const agent='node '+escaped(semantic)+' --prompt {prompt}';
|
|
39
|
+
const args=[join(base,'src/render/cli.mjs'),'vision',media,
|
|
40
|
+
'--vtt',vtt,'--itt',itm,'--agent',agent,
|
|
41
|
+
'--instruct','请按嘿 Neo 规则理解语义,并保留原视频时点。',
|
|
42
|
+
'--vtt-sample-interval','2'];
|
|
43
|
+
execFileSync(process.execPath,args,{cwd:base,timeout:200000,encoding:'utf8'});
|
|
44
|
+
const meta=JSON.parse(readFileSync(join(media,'metadata.json'),'utf8'));
|
|
45
|
+
expect(meta.photo.perception.desc).toContain('Recognized landscape');
|
|
46
|
+
expect(meta.clip.perception.subtitle).toBe('clip.vtt');
|
|
47
|
+
expect(meta.clip.perception.desc).toContain('Recognized landscape');
|
|
48
|
+
expect(Object.keys(meta.clip.perception.segments)).toEqual(['0to2000','2000to4000']);
|
|
49
|
+
expect(meta.clip.perception.segments['0to2000'].vision).toContain('Recognized landscape');
|
|
50
|
+
expect(meta.clip.perception.segments['2000to4000'].instructions).toEqual([
|
|
51
|
+
{utterance:'嘿 Neo,这里是一个重要镜头',intent:'emphasize later',time_seconds:2.2,confidence:'high'},
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('invalid semantic Agent response does not silently fall back to code-selected boundaries',()=>{
|
|
56
|
+
const other=join(dir,'bad-semantic');
|
|
57
|
+
mkdirSync(other,{recursive:true});
|
|
58
|
+
execFileSync('cp',[join(media,'clip.mp4'),join(other,'clip.mp4')]);
|
|
59
|
+
writeFileSync(join(other,'clip.vtt'),['WEBVTT','','00:00.000 --> 00:02.000','骑行。','','00:02.000 --> 00:04.000','嘿 Neo 保留这段。'].join(String.fromCharCode(10)));
|
|
60
|
+
const bad=join(dir,'bad-agent.mjs');
|
|
61
|
+
writeFileSync(bad,'console.log("not JSON")');
|
|
62
|
+
const itm='node '+JSON.stringify(visual)+' --input {input} --prompt {prompt_quoted}';
|
|
63
|
+
const args=[join(base,'src/render/cli.mjs'),'vision',other,
|
|
64
|
+
'--vtt',itm,'--itt',itm,'--agent','node '+JSON.stringify(bad)+' --prompt {prompt}',
|
|
65
|
+
'--instruct','嘿 Neo'];
|
|
66
|
+
expect(()=>execFileSync(process.execPath,args,{cwd:base,timeout:90000,stdio:'pipe'}))
|
|
67
|
+
.toThrow();
|
|
68
|
+
const meta=JSON.parse(readFileSync(join(other,'metadata.json'),'utf8'));
|
|
69
|
+
expect(meta.clip?.perception?.segments).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('obsolete provider switch is rejected instead of silently becoming a prompt override',()=>{
|
|
73
|
+
const folder=join(dir,'invalid-option');
|
|
74
|
+
mkdirSync(folder,{recursive:true});
|
|
75
|
+
expect(()=>execFileSync(process.execPath,[join(base,'src/render/cli.mjs'),'vision',folder,'--backend','deepseek'],{cwd:base,encoding:'utf8',stdio:'pipe'}))
|
|
76
|
+
.toThrow(/Unknown vision option: --backend/);
|
|
77
|
+
});
|
|
@@ -10,6 +10,7 @@ export default defineConfig({
|
|
|
10
10
|
"tests/render.test.ts",
|
|
11
11
|
"tests/vision.test.ts",
|
|
12
12
|
"tests/vision-candidate.test.ts",
|
|
13
|
+
"tests/vision-generic-vtt-hooks.test.ts", // requires ffmpeg; exercise in full/integration suite
|
|
13
14
|
"tests/mcp-remote-assets.test.ts",
|
|
14
15
|
],
|
|
15
16
|
testTimeout: 120_000,
|