use super::*;
pub(super) async fn dispatch_file_edit_hook(
graph: &Arc<tokio::sync::RwLock<Graph>>,
ctx: &RequestContext,
req: &Request,
) -> Response {
let input = match &req.cmd {
Command::FileEditHook(i) => i,
_ => unreachable!(),
};
let request_id = req.id;
{
let g = graph.read().await;
let store = g.store();
let file_key = format!("file:{}", input.path);
let agg_key = sess::today_key("analytics:hit_");
let staged_agg = sess::upsert_daily_agg_staged(store, &agg_key, &file_key).await;
let audit_entry = build_audit_entry(
ctx,
request_id,
"file_edit_hook:activity",
&file_key,
true,
None,
);
let audit_key = audit_nanos_key("audit:session:");
let audit_bytes = serialize_audit(&audit_entry);
let mut writes: Vec<(&str, &[u8])> = Vec::new();
if let Ok(ref agg) = staged_agg {
writes.push((&agg.0, &agg.1));
}
if let Some(ref ab) = audit_bytes {
writes.push((&audit_key, ab));
}
if let Err(e) = store.transact_sessions_raw(&writes).await {
tracing::warn!(
request_id = %request_id,
"file_edit_hook: activity substep sessions transaction failed: {e}"
);
}
if let Ok(Some(mut record)) = store.get(&file_key).await {
record.access_count += 1;
record.last_accessed = now_secs();
let _ = store.put(&file_key, &record).await;
}
}
{
let g = graph.read().await;
let store = g.store();
let reparse_input = protocol::FileReparseInput {
path: input.path.clone(),
};
match crate::mcp::handlers::handle_file_reparse(
store,
ctx,
request_id,
&reparse_input,
&ctx.repo_root,
)
.await
{
Ok(_) => {}
Err((_code, msg)) => {
tracing::warn!("file_edit_hook: reparse substep failed: {msg}");
}
}
}
Response::ok(request_id, serde_json::Value::Null)
}