use super::{path::normalize_workspace_paths, provenance::insert_provenance_fields};
use serde_json::{Map, Value, json};
use std::path::Path;
pub fn enrich_tool_input_with_runtime_context(
tool_input: &Value,
workspace_dir: &Path,
current_model: Option<&str>,
session_id: &str,
agent_name: &str,
provenance: Option<&crate::provenance::ExecutionProvenance>,
) -> Value {
let mut enriched = tool_input.clone();
if let Value::Object(ref mut obj) = enriched {
insert_field(obj, "__ct_current_model", current_model);
obj.entry("__ct_session_id".to_string())
.or_insert_with(|| json!(session_id));
obj.entry("__ct_agent_name".to_string())
.or_insert_with(|| json!(agent_name));
if let Some(provenance) = provenance {
insert_provenance_fields(obj, provenance);
}
normalize_workspace_paths(obj, workspace_dir);
}
enriched
}
pub fn insert_field(obj: &mut Map<String, Value>, key: &str, value: Option<&str>) {
if let Some(value) = value {
obj.entry(key.to_string()).or_insert_with(|| json!(value));
}
}