MCPcopy Create free account
hub / github.com/AIScientists-Dev/Flowtrace / classify

Function classify

crates/flowtrace-cli/src/serve/classify.rs:8–86  ·  view source on GitHub ↗

Classify a filesystem event path into an SSE event body. `scope_root` MUST be canonicalized (see AppState::new). `path` MUST be the absolute path produced by notify.

(scope_root: &Path, path: &Path)

Source from the content-addressed store, hash-verified

6/// `scope_root` MUST be canonicalized (see AppState::new).
7/// `path` MUST be the absolute path produced by notify.
8pub fn classify(scope_root: &Path, path: &Path) -> SseEventBody {
9 let rel = match path.strip_prefix(scope_root) {
10 Ok(r) => r,
11 Err(_) => {
12 return SseEventBody::Other {
13 path: path.display().to_string(),
14 };
15 }
16 };
17 let comps: Vec<&str> = rel
18 .components()
19 .filter_map(|c| match c {
20 Component::Normal(s) => s.to_str(),
21 _ => None,
22 })
23 .collect();
24 if comps.is_empty() {
25 return SseEventBody::Other {
26 path: path.display().to_string(),
27 };
28 }
29 // Layout under scope: <trace_id>/(trace.json | runs/<run>/...)
30 let trace_id = comps[0].to_string();
31 if comps.len() == 1 {
32 return SseEventBody::Other {
33 path: path.display().to_string(),
34 };
35 }
36 match comps.as_slice() {
37 [_, "trace.json"] => SseEventBody::TraceUpdated { trace_id },
38 [_, "runs", run_id] => SseEventBody::RunCreated {
39 trace_id,
40 run_id: (*run_id).into(),
41 },
42 [_, "runs", run_id, "state.json"] => SseEventBody::RunUpdated {
43 trace_id,
44 run_id: (*run_id).into(),
45 },
46 [_, "runs", run_id, "replies", reply_file] => {
47 // Skip writer tempfiles (`.tmp.<pid>.<nanos>.reply`) and any other
48 // hidden / non-NNNN.json names. Otherwise a bad parse would emit
49 // ReplyAppended{seq=0}, which the frontend dedupes — silently
50 // dropping the real reply that follows.
51 if reply_file.starts_with('.') {
52 return SseEventBody::Other {
53 path: path.display().to_string(),
54 };
55 }
56 let Some(stem) = reply_file.strip_suffix(".json") else {
57 return SseEventBody::Other {
58 path: path.display().to_string(),
59 };
60 };
61 let Ok(seq) = stem.parse::<u32>() else {
62 eprintln!(
63 "[trace] warn: watcher saw non-numeric reply filename `{}` — \
64 ignoring; expected NNNN.json",
65 reply_file

Callers 7

spawnFunction · 0.85
classifies_trace_jsonFunction · 0.85
classifies_state_jsonFunction · 0.85
classifies_reply_jsonFunction · 0.85
classifies_run_dirFunction · 0.85
classifies_outside_scopeFunction · 0.85

Calls

no outgoing calls

Tested by 6

classifies_trace_jsonFunction · 0.68
classifies_state_jsonFunction · 0.68
classifies_reply_jsonFunction · 0.68
classifies_run_dirFunction · 0.68
classifies_outside_scopeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…