feat: add TraceArtifacts phase + VLM waits for all key_frame.jpg

- Add TraceArtifacts phase to TkgPhase enum (phase 18)
- Report progress as key_frame.jpg/key_face.jpg are created
- VLM trigger now polls until ALL key_frame.jpg files exist
  (was: started after TKG build, before artifacts were ready)
- Add iron rule to AGENTS.md: ask before removing data

Tested: Gamma 8 (27 traces) → 27/27 VLM summaries completed
This commit is contained in:
Accusys
2026-08-24 19:13:11 +08:00
parent d29b4804af
commit 9f12e835b8
43 changed files with 3993 additions and 491 deletions
-88
View File
@@ -178,91 +178,3 @@ pub async fn probe_audio_track(file_path: &str) -> Result<Option<AudioTrackResul
duration,
}))
}
/// Extract key frames from each scene in cut.json for VLM analysis
pub async fn extract_cut_key_frames(
file_uuid: &str,
video_path: &str,
output_dir: &str,
) -> Result<Vec<String>> {
let cut_json = PathBuf::from(output_dir).join(format!("{}.cut.json", file_uuid));
if !cut_json.exists() {
tracing::warn!("[CUT_KEY_FRAME] cut.json not found: {}", cut_json.display());
return Ok(vec![]);
}
let script = std::path::Path::new("/Users/accusys/momentry_core/scripts/cut_key_frame.py");
if !script.exists() {
tracing::warn!("[CUT_KEY_FRAME] Script not found: {}", script.display());
return Ok(vec![]);
}
let file_uuid_owned = file_uuid.to_string();
let video_path_owned = video_path.to_string();
let cut_json_str = cut_json.to_string_lossy().to_string();
let output_dir_owned = output_dir.to_string();
let script_str = script.to_string_lossy().to_string();
let python_path = PYTHON_PATH.as_str().to_string();
let output = tokio::task::spawn_blocking(move || {
Command::new(&python_path)
.arg(&script_str)
.arg("--file-uuid")
.arg(&file_uuid_owned)
.arg("--video")
.arg(&video_path_owned)
.arg("--cut-json")
.arg(&cut_json_str)
.arg("--output-dir")
.arg(&output_dir_owned)
.arg("--json")
.output()
})
.await
.context("Spawn blocking failed")?
.context("Failed to spawn python")?;
if !output.status.success() {
tracing::warn!(
"[CUT_KEY_FRAME] Extraction failed: {}",
String::from_utf8_lossy(&output.stderr)
);
return Ok(vec![]);
}
let stdout = String::from_utf8_lossy(&output.stdout);
let json: serde_json::Value = match serde_json::from_str(&stdout) {
Ok(v) => v,
Err(e) => {
tracing::warn!("[CUT_KEY_FRAME] JSON parse error: {}", e);
return Ok(vec![]);
}
};
let scenes: Vec<String> = json
.get("scenes")
.and_then(|s| s.as_array())
.map(|arr| {
arr.iter()
.filter_map(|s| {
if s.get("success").and_then(|b| b.as_bool()) == Some(true) {
s.get("output_path")
.and_then(|p| p.as_str().map(|p| p.to_string()))
} else {
None
}
})
.collect()
})
.unwrap_or_default();
tracing::info!(
"[CUT_KEY_FRAME] Extracted {} scene key frames for {}",
scenes.len(),
file_uuid
);
Ok(scenes)
}