fallow_config/run_inputs/mod.rs
1//! The raw inputs of one run, before the engine resolves them.
2//!
3//! Each surface (the CLI, the Rust API, the Node bindings, the language
4//! server and the MCP server) translates its own flags, options, settings or
5//! tool parameters into one [`RunInputs`]. The engine resolves the inputs,
6//! the config file and the [`EnvSnapshot`] into one decision per setting.
7
8mod dupes;
9mod env;
10
11use std::path::PathBuf;
12
13use fallow_types::output_format::OutputFormat;
14use fallow_types::sourced::{Given, Origin};
15use serde::Serialize;
16
17pub use dupes::DupesInputs;
18pub use env::{EnvProblem, EnvSnapshot, EnvValue, EnvVar};
19
20use crate::{PlannedAnalysis, TypeAwareRequire};
21
22/// The type-aware settings that a surface gives, such as the
23/// `--type-aware`, `--type-aware-project` and `--type-aware-require` flags.
24#[derive(Debug, Clone, Default, PartialEq, Eq)]
25pub struct TypeAwareInputs {
26 /// Turn type-aware analysis on or off.
27 pub enabled: Option<Given<bool>>,
28 /// The TypeScript project configs. An empty list is not an input.
29 pub projects: Option<Given<Vec<PathBuf>>>,
30 /// The completeness policy.
31 pub require: Option<Given<TypeAwareRequire>>,
32}
33
34/// The surface that starts a run.
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, schemars::JsonSchema)]
36#[serde(rename_all = "kebab-case")]
37pub enum Surface {
38 /// The `fallow` command line.
39 Cli,
40 /// The Rust API of `fallow-api`.
41 Api,
42 /// The Node bindings.
43 Node,
44 /// The language server.
45 Lsp,
46 /// The MCP server.
47 Mcp,
48}
49
50/// The command of a run. There is one variant per distinct rule for the
51/// environment variables and for the selection of analyses.
52#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, schemars::JsonSchema)]
53#[serde(rename_all = "kebab-case")]
54pub enum CommandKind {
55 /// The bare `fallow` run and the combined API route.
56 Combined,
57 /// `fallow audit`.
58 Audit,
59 /// `fallow dead-code` and the dead-code routes.
60 DeadCode,
61 /// `fallow dupes` and the duplication routes.
62 Dupes,
63 /// `fallow health` and the health routes.
64 Health,
65 /// `fallow list`.
66 List,
67 /// `fallow fix`.
68 Fix,
69 /// `fallow watch`.
70 Watch,
71 /// `fallow viz`.
72 Viz,
73 /// `fallow flags`.
74 Flags,
75 /// `fallow suppressions`.
76 Suppressions,
77 /// `fallow trace` for a dependency.
78 TraceDependency,
79 /// `fallow trace --path`.
80 TracePath,
81 /// `fallow trace` for a re-export chain.
82 TraceChain,
83 /// `fallow trace-error`.
84 TraceError,
85 /// `fallow security`.
86 Security,
87 /// `fallow inspect`.
88 Inspect,
89 /// `fallow coverage analyze`.
90 CoverageAnalyze,
91 /// `fallow coverage upload`.
92 CoverageUpload,
93 /// `fallow guard`.
94 Guard,
95 /// `fallow rule-pack`.
96 RulePack,
97 /// `fallow baselines prune`.
98 BaselinesPrune,
99 /// `fallow mutation`.
100 Mutation,
101 /// `fallow similar-code`.
102 SimilarCode,
103 /// `fallow plugin-check`.
104 PluginCheck,
105 /// The MCP decision surface.
106 DecisionSurface,
107 /// `fallow doctor`.
108 Doctor,
109 /// An editor session of the language server.
110 Editor,
111}
112
113/// How a run selects its analyses.
114#[derive(Debug, Clone, PartialEq, Eq)]
115pub enum SelectionInput {
116 /// `--only` and `--skip` lists.
117 Lists {
118 /// The analyses that `--only` names.
119 only: Vec<PlannedAnalysis>,
120 /// The analyses that `--skip` names.
121 skip: Vec<PlannedAnalysis>,
122 /// The input that carries the lists.
123 origin: Origin,
124 },
125 /// One bool for each analysis, as the options of the combined API route.
126 Booleans {
127 /// Run the dead-code analysis.
128 dead_code: bool,
129 /// Run the duplication analysis.
130 duplication: bool,
131 /// Run the health analysis.
132 health: bool,
133 /// The input that carries the bools.
134 origin: Origin,
135 },
136 /// One optional bool for each analysis, as the options of the audit API
137 /// route.
138 Options {
139 /// The request for the dead-code analysis.
140 dead_code: Option<bool>,
141 /// The request for the duplication analysis.
142 duplication: Option<bool>,
143 /// The request for the health analysis.
144 health: Option<bool>,
145 /// The input that carries the options.
146 origin: Origin,
147 },
148 /// A command that runs exactly one analysis.
149 Single(PlannedAnalysis),
150}
151
152/// What a run does when its config cannot be used.
153#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
154pub enum ConfigFallback {
155 /// The run fails.
156 #[default]
157 Fail,
158 /// A discovered config that fails to load, to validate, or to give
159 /// workspace metadata gives the defaults. An explicit config path still
160 /// fails.
161 DefaultsOnDiscoveredError,
162}
163
164/// The raw inputs of one run.
165///
166/// The surface and the environment snapshot are private: [`RunInputs::new`]
167/// is the only way to set them, so each run names both.
168#[derive(Debug, Clone)]
169pub struct RunInputs {
170 surface: Surface,
171 env: EnvSnapshot,
172 /// The command of the run.
173 pub command: CommandKind,
174 /// How the run selects its analyses.
175 pub selection: SelectionInput,
176 /// What the run does when its config cannot be used.
177 pub config_fallback: ConfigFallback,
178 /// The project root. Without it, the current directory of the snapshot.
179 pub root: Option<Given<PathBuf>>,
180 /// An explicit config file. A relative path joins the current directory
181 /// of the snapshot.
182 pub config_path: Option<Given<PathBuf>>,
183 /// Permit `https://` entries in the `extends` chain of the config.
184 pub allow_remote_extends: Option<Given<bool>>,
185 /// Bypass the parse cache.
186 pub no_cache: Option<Given<bool>>,
187 /// The number of worker threads.
188 pub threads: Option<Given<usize>>,
189 /// The largest file to analyze, in megabytes. `0` means no limit.
190 pub max_file_size_mb: Option<Given<u32>>,
191 /// The cache directory.
192 pub cache_dir: Option<Given<PathBuf>>,
193 /// Read `workspaces.changedSince` of the config.
194 pub package_baselines: Option<Given<bool>>,
195 /// Report unused exports of entry files.
196 pub include_entry_exports: Option<Given<bool>>,
197 /// The production mode of every analysis.
198 pub production: Option<Given<bool>>,
199 /// The production mode of the dead-code analysis.
200 pub production_dead_code: Option<Given<bool>>,
201 /// The production mode of the health analysis.
202 pub production_health: Option<Given<bool>>,
203 /// The production mode of the duplication analysis.
204 pub production_dupes: Option<Given<bool>>,
205 /// The analysis flags of the run, such as `--unused-exports`, with the
206 /// analysis that each flag belongs to.
207 pub analysis_flags: Vec<(PlannedAnalysis, Origin)>,
208 /// The type-aware settings that the surface gives.
209 pub type_aware: TypeAwareInputs,
210 /// The base ref of an audit that the caller names, such as `--base` or
211 /// the `base` parameter of an MCP tool.
212 pub audit_base: Option<Given<String>>,
213 /// The output format.
214 pub output: OutputFormat,
215 /// Suppress progress output.
216 pub quiet: bool,
217}
218
219impl RunInputs {
220 /// The inputs of a run of `command` on `surface`, with every optional
221 /// input unset, human output and no progress output.
222 #[must_use]
223 pub fn new(
224 surface: Surface,
225 env: EnvSnapshot,
226 command: CommandKind,
227 selection: SelectionInput,
228 ) -> Self {
229 Self {
230 surface,
231 env,
232 command,
233 selection,
234 config_fallback: ConfigFallback::Fail,
235 root: None,
236 config_path: None,
237 allow_remote_extends: None,
238 no_cache: None,
239 threads: None,
240 max_file_size_mb: None,
241 cache_dir: None,
242 package_baselines: None,
243 include_entry_exports: None,
244 production: None,
245 production_dead_code: None,
246 production_health: None,
247 production_dupes: None,
248 analysis_flags: Vec::new(),
249 type_aware: TypeAwareInputs::default(),
250 audit_base: None,
251 output: OutputFormat::Human,
252 quiet: true,
253 }
254 }
255
256 /// The surface that starts the run.
257 #[must_use]
258 pub const fn surface(&self) -> Surface {
259 self.surface
260 }
261
262 /// The environment snapshot of the run.
263 #[must_use]
264 pub const fn env(&self) -> &EnvSnapshot {
265 &self.env
266 }
267}
268
269/// The inputs of a host that starts runs without a command, such as a
270/// session store of the language server.
271#[derive(Debug, Clone)]
272pub struct HostInputs {
273 /// The surface of the host.
274 pub surface: Surface,
275 /// The environment snapshot of the host.
276 pub env: EnvSnapshot,
277}