pub fn log_llm_request(
datalog_dir: &Path,
messages: &[Message],
tool_defs: &[ToolDef],
model: &str,
context_window: usize,
step: usize,
enabled: bool,
) -> Option<PathBuf>Expand description
Per-round LLM log files live under <datalog_dir>/llm/ where
<datalog_dir> is the per-project directory resolved by
DatalogWriter::resolve_log_dir (typically
~/.atomcode/datalog/<project-slug>/). The caller is responsible for
passing in the resolved dir — see runner.rs. This keeps the JSONL dump
in lockstep with the markdown writer’s [datalog].dir config; the prior
hard-coded <working_dir>/datalog/llm/ would silently ignore the user’s
dir override.
One file per LLM round-trip, containing both request and response
sections. Filename = timestamp. calls.log is a one-line-per-round index.
Split-file layout (prior design) produced two JSONs per round plus a CSV entry per half — hard to read and review. One-file-per-round is both AI-friendly (single JSON to grep/diff/feed back) and human-friendly.
Request / response pairing: log_llm_request returns the path of the
JSON file it wrote; the caller holds that PathBuf locally and passes
it to log_llm_response so the response section merges into the SAME
file. No process-wide shared state — safe for concurrent chat_stream
handlers in the daemon (prior design used a static Mutex<Option<PathBuf>>
that bled across sessions).
Log the LLM request. Writes a JSON file containing the request section
under <datalog_dir>/llm/<timestamp>.json.
Returns the path so the caller can pass it to log_llm_response for
in-place merge. Returns None if enabled is false or the write failed.