Skip to main content

vtcode_core/tools/registry/
history_facade.rs

1//! Tool execution history accessors for ToolRegistry.
2
3use serde_json::Value;
4use std::time::Duration;
5
6use super::{ToolExecutionRecord, ToolRegistry, ToolTaskTelemetrySnapshot};
7
8impl ToolRegistry {
9    /// Get recent tool executions (successes and failures).
10    pub fn get_recent_tool_records(&self, count: usize) -> Vec<ToolExecutionRecord> {
11        self.execution_history.get_recent_records(count)
12    }
13
14    /// Get recent tool execution failures.
15    pub fn get_recent_tool_failures(&self, count: usize) -> Vec<ToolExecutionRecord> {
16        self.execution_history.get_recent_failures(count)
17    }
18
19    /// Aggregate representative task telemetry from recorded tool executions.
20    pub fn task_tool_telemetry_snapshot(
21        &self,
22        task_id: Option<&str>,
23        task_completed_successfully: Option<bool>,
24    ) -> ToolTaskTelemetrySnapshot {
25        self.execution_history
26            .task_telemetry_snapshot(task_id, task_completed_successfully)
27    }
28
29    /// Find a recent spooled output for a tool call with identical args.
30    pub fn find_recent_spooled_output(&self, tool_name: &str, args: &Value, max_age: Duration) -> Option<Value> {
31        self.execution_history.find_recent_spooled_result(tool_name, args, max_age)
32    }
33
34    /// Find a recent successful output for a tool call with identical args.
35    pub fn find_recent_successful_output(&self, tool_name: &str, args: &Value, max_age: Duration) -> Option<Value> {
36        self.execution_history.find_recent_successful_result(tool_name, args, max_age)
37    }
38
39    /// Find the most recent successful output for a read-only tool call that
40    /// targets the same file path with a compatible read shape.  Returns
41    /// `None` for non-read-only tools or when no path can be extracted.
42    pub fn find_recent_successful_by_read_target(
43        &self,
44        tool_name: &str,
45        args: &Value,
46        max_age: Duration,
47    ) -> Option<Value> {
48        self.execution_history
49            .find_recent_successful_by_read_target(tool_name, args, max_age)
50    }
51
52    /// Find continuation metadata from a recent chunked file-read result for the same path.
53    ///
54    /// Supports both `read_file` and `file_operation` (read action) history records.
55    pub fn find_recent_read_file_spool_progress(&self, path: &str, max_age: Duration) -> Option<(usize, usize)> {
56        self.execution_history.find_recent_read_file_spool_progress(path, max_age)
57    }
58
59    /// Clear the execution history.
60    pub fn clear_execution_history(&self) {
61        self.execution_history.clear();
62    }
63
64    /// Get the current number of stored execution records.
65    pub fn execution_history_len(&self) -> usize {
66        self.execution_history.len()
67    }
68}