codetether_agent/telemetry/tools/execution.rs
1//! A single tool invocation record with timing, outcome, and file changes.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use super::FileChange;
7
8/// Telemetry record for one tool invocation.
9///
10/// Build one with [`ToolExecution::start`] at the top of your tool's
11/// `execute()` impl, then finalize it with [`ToolExecution::complete`] /
12/// [`ToolExecution::fail`] before returning.
13///
14/// # Examples
15///
16/// ```rust
17/// use codetether_agent::telemetry::ToolExecution;
18/// use serde_json::json;
19///
20/// let mut exec = ToolExecution::start("read", json!({"path": "foo.rs"}));
21/// assert!(!exec.success);
22/// exec.complete(true, 42);
23/// assert!(exec.success);
24/// assert_eq!(exec.duration_ms, 42);
25/// ```
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct ToolExecution {
28 /// Unique id for cross-referencing with the audit log.
29 pub id: String,
30 /// Registered tool name (e.g. `"bash"`, `"read"`).
31 pub tool_name: String,
32 /// When execution *started*.
33 pub timestamp: DateTime<Utc>,
34 /// Wall-clock duration in milliseconds.
35 pub duration_ms: u64,
36 /// `true` iff the tool returned Ok.
37 pub success: bool,
38 /// Error message when `success` is `false`.
39 pub error: Option<String>,
40 /// Tokens attributed to this invocation, when known.
41 pub tokens_used: Option<u64>,
42 /// Owning session's UUID, when available.
43 pub session_id: Option<String>,
44 /// Raw tool input as JSON.
45 pub input: Option<serde_json::Value>,
46 /// Files the tool touched during this invocation.
47 #[serde(default)]
48 pub file_changes: Vec<FileChange>,
49}
50
51mod execution_methods;