(
config: &Config,
query_str: &str,
source: &str,
file_pattern: Option<String>,
format: OutputFormat,
)
| 101 | } |
| 102 | |
| 103 | pub async fn query( |
| 104 | config: &Config, |
| 105 | query_str: &str, |
| 106 | source: &str, |
| 107 | file_pattern: Option<String>, |
| 108 | format: OutputFormat, |
| 109 | ) -> Result<()> { |
| 110 | let engine = QueryEngine::new(); |
| 111 | |
| 112 | let data = match source { |
| 113 | "history" => { |
| 114 | let ds = HistoryDataSource::new(config.clone()); |
| 115 | ds.load_raw().await? |
| 116 | } |
| 117 | "jhistory" => { |
| 118 | let ds = CodexHistoryDataSource::new(config.clone()); |
| 119 | ds.load_raw().await? |
| 120 | } |
| 121 | "codex_history" => { |
| 122 | let ds = CodexHistoryDataSource::new(config.clone()); |
| 123 | ds.load_raw().await? |
| 124 | } |
| 125 | "transcripts" => { |
| 126 | let ds = TranscriptDataSource::new(config.clone()); |
| 127 | let sessions = ds.load_all_sessions().await?; |
| 128 | let mut all = Vec::new(); |
| 129 | for (session_id, entries) in sessions { |
| 130 | if let Some(ref pattern) = file_pattern { |
| 131 | if !session_id.contains(pattern) { |
| 132 | continue; |
| 133 | } |
| 134 | } |
| 135 | all.extend(entries); |
| 136 | } |
| 137 | all |
| 138 | } |
| 139 | "stats" => { |
| 140 | let ds = StatsDataSource::new(config.clone()); |
| 141 | vec![ds.load_raw().await?] |
| 142 | } |
| 143 | "todos" => { |
| 144 | let ds = TodoDataSource::new(config.clone()); |
| 145 | let files = ds.load_all().await?; |
| 146 | files |
| 147 | .into_iter() |
| 148 | .map(|f| { |
| 149 | serde_json::json!({ |
| 150 | "workspace_id": f.workspace_id, |
| 151 | "agent_id": f.agent_id, |
| 152 | "todos": f.todos |
| 153 | }) |
| 154 | }) |
| 155 | .collect() |
| 156 | } |
| 157 | _ => { |
| 158 | return Err(crate::error::Error::DataSource(format!( |
| 159 | "Unknown source: {}. Use: history, jhistory, codex_history, transcripts, stats, todos", |
| 160 | source |
no test coverage detected