Skip to main content

comindly_api/
answers.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::conventions::{Convention, Manual};
6use crate::graph::{ContractView, Node};
7use crate::search::SearchHit;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Search {
11    pub hits: Vec<SearchHit>,
12    pub markdown: String,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Why {
17    pub name: String,
18    pub markdown: String,
19}
20
21#[derive(Debug, Clone, Default, Serialize, Deserialize)]
22pub struct Ledger {
23    pub markdown: String,
24    /// Said instead of a report, when there is nothing to report.
25    pub note: Option<String>,
26    /// With `check`: a constraint that must hold is violated.
27    pub failed: bool,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct Flow {
32    pub focus: String,
33    /// The stored walkthrough and the questions it answers, when one was written.
34    pub narration: Option<(String, Vec<String>)>,
35    pub steps: Vec<Step>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct Step {
40    pub depth: usize,
41    pub via: String,
42    pub name: String,
43    pub location: String,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct Contracts {
48    /// Every contract, before `kind` and `dangling` narrow the list.
49    pub total: usize,
50    pub views: Vec<ContractView>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct Conventions {
55    pub conventions: Vec<Convention>,
56    pub hidden: Vec<Manual>,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct Explore {
61    pub symbols: usize,
62    pub edges: usize,
63    pub dangling: usize,
64    /// `None` when no symbol matches the focus.
65    pub view: Option<ExploreView>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct ExploreView {
70    pub focus: Option<Node>,
71    pub container: Option<Node>,
72    pub callees: Vec<Node>,
73    pub callers: Vec<Node>,
74    pub importers: Vec<Node>,
75    pub members: Vec<Node>,
76    /// Dependents within the blast radius, and how many per repo.
77    pub dependents: usize,
78    pub by_repo: BTreeMap<String, usize>,
79    pub budget: usize,
80    /// The context pack: symbols to read with their estimated tokens.
81    pub pack: Vec<(Node, usize)>,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct Stats {
86    pub symbols: usize,
87    /// Repos in the index; `repos` holds those reported.
88    pub indexed: usize,
89    /// Asked-for repos the index does not have.
90    pub unknown: Vec<String>,
91    pub repos: Vec<RepoStats>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct RepoStats {
96    pub repo: String,
97    pub symbols: usize,
98    pub edges: usize,
99    pub enriched: usize,
100    pub kinds: BTreeMap<String, usize>,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct Preflight {
105    pub markdown: String,
106    /// A `must` constraint check fails in a changed file.
107    pub blocking: bool,
108}
109
110/// Hops the blast radius follows, and the context pack's token budget.
111pub const RIPPLE_DEPTH: usize = 4;
112
113/// What an agent hook adds to the agent's context: records not yet shown this session.
114#[derive(Debug, Clone, Default, Serialize, Deserialize)]
115pub struct Hook {
116    pub text: String,
117    /// The records `text` shows, for the caller to remember as shown.
118    pub ids: Vec<String>,
119}