greppy/daemon/
protocol.rs

1use crate::daemon::events::DaemonEvent;
2use crate::search::SearchResponse;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Request {
7    pub id: String,
8    pub method: Method,
9}
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12#[serde(tag = "type", content = "params")]
13pub enum Method {
14    Search {
15        query: String,
16        project: String,
17        limit: usize,
18    },
19    Index {
20        project: String,
21        force: bool,
22    },
23    IndexWatch {
24        project: String,
25    },
26    Status,
27    List,
28    Forget {
29        project: String,
30    },
31    Stop,
32    /// Subscribe to daemon events (returns a stream)
33    Subscribe,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct Response {
38    pub id: String,
39    pub result: ResponseResult,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(tag = "type", content = "data")]
44pub enum ResponseResult {
45    Search(SearchResponse),
46    Index {
47        project: String,
48        file_count: usize,
49        chunk_count: usize,
50        elapsed_ms: f64,
51    },
52    Status {
53        running: bool,
54        pid: u32,
55        projects: Vec<ProjectInfo>,
56    },
57    List {
58        projects: Vec<ProjectInfo>,
59    },
60    Forget {
61        project: String,
62        success: bool,
63    },
64    Stop {
65        success: bool,
66    },
67    /// Subscribed to events successfully
68    Subscribed,
69    /// An event from the daemon (streamed after Subscribe)
70    Event(DaemonEvent),
71    Error {
72        message: String,
73    },
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct ProjectInfo {
78    pub path: String,
79    pub name: String,
80    pub chunk_count: usize,
81    pub watching: bool,
82}