Skip to main content

fallow_types/
envelope.rs

1//! Typed envelope and utility-shape structs for the JSON output contract.
2//!
3//! Today the JSON serialization layer (`crates/cli/src/report/json.rs`) builds
4//! its envelopes (`CheckOutput`, `HealthOutput`, ...) via `serde_json::json!`
5//! macros and ad-hoc map merging. The types in this module are the schema-side
6//! counterpart of those envelopes plus a small set of utility shapes
7//! (`SchemaVersion`, `Meta`, `BaselineDeltas`, ...) that the envelopes
8//! reference.
9//!
10//! Gated on the `schema` cargo feature so consumers that do not need the
11//! `schemars::JsonSchema` derive (every crate except `fallow-cli` with
12//! `--features schema-emit`) skip the schemars compile cost.
13
14use std::collections::BTreeMap;
15
16use serde::{Deserialize, Serialize};
17
18use crate::semantic::{
19    ApiSurfaceResult, SemanticAnalysisIdentity, SemanticCandidateDecision, SemanticGapReason,
20    SemanticQuerySummary, SemanticSymbolImpact, SemanticSymbolTrace, TypeCouplingReport,
21};
22
23/// Schema version for this output format (independent of tool version). Bump
24/// policy: ADDITIVE changes (new optional top-level fields, new optional struct
25/// fields, new array entries, new MCP tools, new CLI flags that map to new
26/// optional fields) do NOT bump the version; consumers receive new fields
27/// without breaking. BREAKING changes (renamed fields, removed fields, type
28/// changes, enum-variant removals, semantic changes to existing fields) DO
29/// bump. Additions to existing enum-valued required fields bump the affected
30/// envelope version so strict JSON Schema consumers can migrate.
31/// `ComplexityContributionKind` is non-exhaustive so Rust consumers retain a
32/// wildcard. To
33/// detect newly-added fields without a bump, check field presence via
34/// JSON-key existence rather than gating on the version. v4 was introduced
35/// alongside fallow-cov-protocol 0.2 (per-finding verdict, stable IDs, evidence
36/// block, renamed summary fields); v5 introduced health_score formula_version 2
37/// with scale-invariant scoring semantics; v6 widened `AddToConfigAction.value`
38/// from a scalar string to `oneOf: [string, array]` so the new `ignoreExports`
39/// action can carry a paste-ready array of `{ file, exports }` rule objects
40/// (the legacy `ignoreDependencies` etc. variants still emit strings, so
41/// consumers that switch on `config_key` keep working unchanged). v8 added the
42/// required duplication `spread` field and changed `duplicated_tokens` to count
43/// redundant copies, excluding the retained copy in each group. Envelopes
44/// embedding health use their own version marker, so health-only contract
45/// changes do not advance dead-code or unrelated sibling envelopes. The
46/// runtime-coverage block is extended additively as the protocol evolves
47/// (currently 0.3, which adds an optional capture_quality summary field). Other
48/// additive examples: dupes --group-by adds optional grouped_by, total_issues,
49/// groups fields without bumping.
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
51#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
52#[serde(transparent)]
53pub struct SchemaVersion(pub u32);
54
55/// Fallow CLI version that produced this envelope. Renders to the JSON wire as
56/// a bare string (e.g. `"2.74.0"`).
57#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
58#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
59#[serde(transparent)]
60pub struct ToolVersion(pub String);
61
62/// Analysis duration in milliseconds. Renders to the JSON wire as a bare
63/// integer.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
65#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
66#[serde(transparent)]
67pub struct ElapsedMs(pub u64);
68
69/// Audit-mode marker emitted on each finding when `fallow audit --format json`
70/// runs with a base ref. `true` means the finding's structural key was not
71/// present at the base ref (introduced by the current changeset); `false`
72/// means it was inherited. Duplication findings carry one carve-out: a clone
73/// group whose structural key is new but whose instances contain no added line
74/// from the diff (a group re-shaped by removing duplication elsewhere) is
75/// demoted to inherited and serializes `false` (issue #2164). Such demoted
76/// groups additionally carry a `demotion_reason` field naming the rule, and
77/// are counted in `attribution.duplication_demoted` (issue #2220).
78///
79/// Outside of audit sub-results the field is omitted, so call sites typically
80/// hold `Option<AuditIntroduced>`. Renders to the JSON wire as a bare boolean.
81#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
82#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
83#[serde(transparent)]
84pub struct AuditIntroduced(pub bool);
85
86/// Entry-point detection summary embedded in `CheckOutput` and the combined
87/// envelope.
88#[derive(Debug, Clone, Default, Serialize)]
89#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
90pub struct EntryPoints {
91    /// Total number of detected entry points.
92    pub total: usize,
93    /// Breakdown of entry points by detection source (e.g., `"package.json"`,
94    /// `"next.js"`, `"config entry"`). Underscored keys so dashboards can
95    /// drill into individual sources.
96    pub sources: BTreeMap<String, usize>,
97}
98
99/// Per-category issue counts for dead-code analysis. Always present in
100/// `CheckOutput`; when `--summary` is used the individual issue arrays are
101/// omitted but this object stays populated.
102#[derive(Debug, Clone, Default, Serialize)]
103#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
104pub struct CheckSummary {
105    /// Total number of issues across all categories.
106    pub total_issues: usize,
107    /// Unused source files.
108    pub unused_files: usize,
109    /// Unused value exports.
110    pub unused_exports: usize,
111    /// Unused type exports.
112    pub unused_types: usize,
113    /// Public exports whose signature references same-file private types.
114    pub private_type_leaks: usize,
115    /// Exports marked `@deprecated` that are still referenced.
116    pub deprecated_exports_in_use: usize,
117    /// Combined count of unused entries across `dependencies`,
118    /// `devDependencies`, and `optionalDependencies`. The per-section
119    /// breakdown lives in the individual issue arrays on `CheckOutput`.
120    pub unused_dependencies: usize,
121    /// Unused enum members.
122    pub unused_enum_members: usize,
123    /// Unused class members.
124    pub unused_class_members: usize,
125    /// Unused store members.
126    #[serde(default)]
127    pub unused_store_members: usize,
128    /// Vue/Svelte injects whose key is provided nowhere in the project.
129    #[serde(default)]
130    pub unprovided_injects: usize,
131    /// Vue/Svelte components reachable but rendered nowhere in the project.
132    #[serde(default)]
133    pub unrendered_components: usize,
134    /// Vue, Svelte, or React props referenced nowhere inside their own component.
135    #[serde(default)]
136    pub unused_component_props: usize,
137    /// Optional consumed props omitted by known reachable callers, for manual review.
138    #[serde(default)]
139    pub absent_component_props: usize,
140    /// Vue `<script setup>` emits emitted nowhere inside their own SFC.
141    #[serde(default)]
142    pub unused_component_emits: usize,
143    /// Angular `@Input()` bindings referenced nowhere inside their own component.
144    #[serde(default)]
145    pub unused_component_inputs: usize,
146    /// Angular `@Output()` bindings emitted nowhere inside their own component.
147    #[serde(default)]
148    pub unused_component_outputs: usize,
149    /// Svelte components dispatching a custom event via `createEventDispatcher`
150    /// whose name is listened to nowhere in the project.
151    #[serde(default)]
152    pub unused_svelte_events: usize,
153    /// Next.js Server Actions (exports of `"use server"` files) referenced by no
154    /// code in the project.
155    #[serde(default)]
156    pub unused_server_actions: usize,
157    /// SvelteKit `load()` return-object keys read by no consumer.
158    #[serde(default)]
159    pub unused_load_data_keys: usize,
160    /// Imports that could not be resolved against the project's module graph.
161    pub unresolved_imports: usize,
162    /// Dependencies imported but absent from `package.json`.
163    pub unlisted_dependencies: usize,
164    /// Same-named exports declared in more than one module.
165    pub duplicate_exports: usize,
166    /// Production dependencies only used via type-only imports (could be
167    /// devDependencies). Only populated in production mode.
168    pub type_only_dependencies: usize,
169    /// Production dependencies only imported by test files (could be
170    /// devDependencies).
171    pub test_only_dependencies: usize,
172    /// devDependencies imported by production source code with a runtime/value
173    /// import (should be promoted to dependencies).
174    pub dev_dependencies_in_production: usize,
175    /// Cycles detected in the import graph.
176    pub circular_dependencies: usize,
177    /// Cycles or self-loops in the re-export edge subgraph (barrel files
178    /// re-exporting from each other in a loop).
179    #[serde(default)]
180    pub re_export_cycles: usize,
181    /// Dependency cycles between workspace packages.
182    #[serde(default)]
183    pub package_cycles: usize,
184    /// Imports that cross architecture boundary rules.
185    pub boundary_violations: usize,
186    /// Files that match no architecture boundary zone.
187    #[serde(default)]
188    pub boundary_coverage_violations: usize,
189    /// Calls from zoned files to callees forbidden for that zone.
190    #[serde(default)]
191    pub boundary_call_violations: usize,
192    /// Banned calls, imports, and catalogue-derived effects matched by
193    /// declarative rule packs.
194    #[serde(default)]
195    pub policy_violations: usize,
196    /// Suppression comments that no longer match a finding.
197    pub stale_suppressions: usize,
198    /// Unused pnpm-workspace catalog entries.
199    pub unused_catalog_entries: usize,
200    /// Empty named catalog groups.
201    pub empty_catalog_groups: usize,
202    /// Workspace package.json catalog references the workspace catalogs
203    /// do not declare.
204    pub unresolved_catalog_references: usize,
205    /// Package-manager overrides whose target package is not declared by any
206    /// workspace package and not present in the active readable lockfile.
207    pub unused_dependency_overrides: usize,
208    /// Package-manager overrides whose key or value cannot be parsed.
209    pub misconfigured_dependency_overrides: usize,
210    /// `"use client"` files that export a Next.js server-only / route-config name.
211    #[serde(default)]
212    pub invalid_client_exports: usize,
213    /// Barrel files that re-export both a `"use client"` origin and a
214    /// server-only origin.
215    #[serde(default)]
216    pub mixed_client_server_barrels: usize,
217    /// Misplaced `"use client"` / `"use server"` directives written as
218    /// expression statements after a non-directive statement.
219    #[serde(default)]
220    pub misplaced_directives: usize,
221    /// Next.js App Router route files that resolve to the same URL within one
222    /// app-root.
223    #[serde(default)]
224    pub route_collisions: usize,
225    /// Sibling Next.js dynamic route segments at one position using different
226    /// param spellings.
227    #[serde(default)]
228    pub dynamic_segment_name_conflicts: usize,
229}
230
231/// Per-category delta comparison against a saved baseline. Only present in
232/// `CheckOutput` when `--baseline` is used.
233#[derive(Debug, Clone, Default, Serialize)]
234#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
235pub struct BaselineDeltas {
236    /// Net change in total issues vs baseline (positive = more issues).
237    pub total_delta: i64,
238    /// Per-category breakdown of current, baseline, and delta counts.
239    pub per_category: BTreeMap<String, BaselineCategoryDelta>,
240}
241
242/// Single-category baseline delta entry inside [`BaselineDeltas::per_category`].
243#[derive(Debug, Clone, Copy, Default, Serialize)]
244#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
245pub struct BaselineCategoryDelta {
246    /// Current issue count for this category.
247    pub current: usize,
248    /// Baseline issue count for this category.
249    pub baseline: usize,
250    /// Change from baseline (current - baseline).
251    pub delta: i64,
252}
253
254/// Baseline match statistics. Shows how many baseline entries existed and how
255/// many matched current issues. Useful for detecting stale baselines
256/// programmatically. Only present in `CheckOutput` when `--baseline` is used.
257#[derive(Debug, Clone, Copy, Default, Serialize)]
258#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
259pub struct BaselineMatch {
260    /// Total number of entries in the loaded baseline file.
261    pub entries: usize,
262    /// Number of baseline entries that matched current issues and were
263    /// filtered.
264    pub matched: usize,
265}
266
267/// Result of regression detection (`--fail-on-regression`). Compares current
268/// issue counts against a baseline from config or an explicit file.
269#[derive(Debug, Clone, Serialize)]
270#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
271pub struct RegressionResult {
272    /// Outcome of the regression check.
273    pub status: RegressionStatus,
274    /// Baseline total before the change. Absent when status is `skipped`.
275    #[serde(default, skip_serializing_if = "Option::is_none")]
276    pub baseline_total: Option<i64>,
277    /// Current total after the change. Absent when status is `skipped`.
278    #[serde(default, skip_serializing_if = "Option::is_none")]
279    pub current_total: Option<i64>,
280    /// Difference current - baseline. Absent when status is `skipped`.
281    #[serde(default, skip_serializing_if = "Option::is_none")]
282    pub delta: Option<i64>,
283    /// Configured tolerance, interpreted per [`RegressionToleranceKind`].
284    /// Absent when status is `skipped`.
285    #[serde(default, skip_serializing_if = "Option::is_none")]
286    pub tolerance: Option<f64>,
287    /// Interpretation of the tolerance value.
288    #[serde(default, skip_serializing_if = "Option::is_none")]
289    pub tolerance_kind: Option<RegressionToleranceKind>,
290    /// Whether the regression exceeded the tolerance.
291    pub exceeded: bool,
292    /// Only present when status is `skipped`.
293    #[serde(default, skip_serializing_if = "Option::is_none")]
294    pub reason: Option<String>,
295}
296
297/// Status of a regression-check pass.
298#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
299#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
300#[serde(rename_all = "lowercase")]
301pub enum RegressionStatus {
302    /// Issue count within tolerance.
303    Pass,
304    /// Issue count exceeded tolerance.
305    Exceeded,
306    /// Regression check did not run (missing baseline, etc.).
307    Skipped,
308}
309
310/// Interpretation of [`RegressionResult::tolerance`].
311#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
312#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
313#[serde(rename_all = "lowercase")]
314pub enum RegressionToleranceKind {
315    /// Tolerance is interpreted as an absolute issue-count delta.
316    Absolute,
317    /// Tolerance is interpreted as a percentage of the baseline total.
318    Percentage,
319}
320
321/// Metric and rule definitions emitted under `_meta` when `--explain` is
322/// passed (always present in MCP responses). Helps AI agents and CI systems
323/// interpret metric values without re-reading the docs site.
324#[derive(Debug, Clone, Default, Serialize)]
325#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
326pub struct Meta {
327    /// URL to the documentation page for this command.
328    #[serde(default, skip_serializing_if = "Option::is_none")]
329    pub docs: Option<String>,
330    /// Local telemetry correlation metadata for agent follow-up runs.
331    #[serde(default, skip_serializing_if = "Option::is_none")]
332    pub telemetry: Option<TelemetryMeta>,
333    /// Provenance for the opt-in TypeScript semantic analysis pass.
334    #[serde(default, skip_serializing_if = "Option::is_none")]
335    pub type_aware: Option<TypeAwareMeta>,
336    /// Per-field definitions for envelope fields and action payload fields.
337    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
338    pub field_definitions: BTreeMap<String, String>,
339    /// Per-metric definitions: name, description, range, interpretation.
340    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
341    pub metrics: BTreeMap<String, MetaMetric>,
342    /// Per-rule definitions for check command output.
343    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
344    pub rules: BTreeMap<String, MetaRule>,
345}
346
347/// Bounded provenance emitted when the opt-in type-aware pass runs.
348#[derive(Debug, Clone, Default, Deserialize, Serialize)]
349#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
350pub struct TypeAwareMeta {
351    /// Compatibility identity used by audit, baselines, snapshots, and stores.
352    #[serde(default, skip_serializing_if = "Option::is_none")]
353    pub identity: Option<SemanticAnalysisIdentity>,
354    /// Effective CLI or repository policy for incomplete semantic evidence.
355    #[serde(default, skip_serializing_if = "Option::is_none")]
356    pub required_completeness: Option<crate::semantic::SemanticCompletenessRequirement>,
357    /// Compact status for every requested semantic query.
358    #[serde(default, skip_serializing_if = "Vec::is_empty")]
359    pub queries: Vec<SemanticQuerySummary>,
360    /// Bounded decision and evidence for each semantic dead-code candidate.
361    #[serde(default, skip_serializing_if = "Vec::is_empty")]
362    pub candidate_decisions: Vec<SemanticCandidateDecision>,
363    /// Checker-backed trace evidence requested by focused symbol queries.
364    #[serde(default, skip_serializing_if = "Vec::is_empty")]
365    pub symbol_traces: Vec<SemanticSymbolTrace>,
366    /// Package-public surface and confirmed private type leaks.
367    #[serde(default, skip_serializing_if = "Option::is_none")]
368    pub api_surface: Option<ApiSurfaceResult>,
369    /// Exact-symbol blast radius and targeted-test recommendations.
370    #[serde(default, skip_serializing_if = "Vec::is_empty")]
371    pub symbol_impacts: Vec<SemanticSymbolImpact>,
372    /// Advisory project-local public-signature coupling.
373    #[serde(default, skip_serializing_if = "Option::is_none")]
374    pub type_coupling: Option<TypeCouplingReport>,
375    /// Whether the semantic companion executed at least one query.
376    pub executed: bool,
377    /// Version of Fallow's backend-neutral sidecar protocol.
378    pub protocol_version: u32,
379    /// Version of the sidecar package that executed the query.
380    #[serde(default, skip_serializing_if = "Option::is_none")]
381    pub sidecar_version: Option<String>,
382    /// Semantic backend capability identifier.
383    pub backend: String,
384    /// Backend compiler or engine version that executed the query.
385    #[serde(default, skip_serializing_if = "Option::is_none")]
386    pub backend_version: Option<String>,
387    /// TypeScript project configs selected for candidate files.
388    pub selected_tsconfigs: Vec<String>,
389    /// Number of candidate findings sent to the sidecar.
390    pub candidate_count: usize,
391    /// Number of candidates confirmed as used and removed.
392    pub confirmed_used_count: usize,
393    /// Number of candidates preserved because they implement or override a contract.
394    pub contract_preserved_count: usize,
395    /// Number of candidates with complete, closed-world no-static-reference evidence.
396    pub no_static_references_count: usize,
397    /// Number of retained class members eligible for a guarded type-aware fix.
398    pub fix_eligible_count: usize,
399    /// Number of candidates retained because semantic use was unresolved.
400    pub unresolved_count: usize,
401    /// Number of candidates retained because semantic analysis abstained.
402    pub abstained_count: usize,
403    /// Stable abstention reason counts for automation and diagnostics.
404    pub abstention_reasons: TypeAwareAbstentionCounts,
405    /// Per-project semantic refinement status and evidence.
406    pub projects: Vec<TypeAwareProjectMeta>,
407    /// Number of bounded warnings returned by the sidecar.
408    pub warning_count: usize,
409    /// Bounded semantic warnings. Findings mentioned here were retained.
410    pub warnings: Vec<String>,
411    /// Semantic pass duration as reported by the sidecar.
412    pub elapsed_ms: u64,
413    /// Bounded semantic phase timings reported by the sidecar.
414    pub phase_timings_ms: TypeAwarePhaseTimings,
415}
416
417/// Closed set of reasons for retaining a candidate without semantic scanning.
418#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
419#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
420#[serde(rename_all = "kebab-case")]
421pub enum TypeAwareAbstentionReason {
422    /// No selected TypeScript project contains the candidate file.
423    #[default]
424    NoProject,
425    /// Multiple explicit TypeScript projects contain the candidate file.
426    AmbiguousProject,
427    /// Structural TypeScript diagnostics make exact matching unsafe.
428    BlockingDiagnostics,
429}
430
431/// Closed abstention reason counts for stable machine consumption.
432#[derive(Debug, Clone, Default, Deserialize, Serialize)]
433#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
434pub struct TypeAwareAbstentionCounts {
435    /// Candidates not contained by a selected TypeScript project.
436    pub no_project: usize,
437    /// Candidates contained by more than one explicit TypeScript project.
438    pub ambiguous_project: usize,
439    /// Candidates retained because structural diagnostics block scanning.
440    pub blocking_diagnostics: usize,
441    /// Candidates retained because the raw TypeScript-Go host cannot expose
442    /// named exports from Svelte virtual modules.
443    pub svelte_virtual_module_exports: usize,
444    /// Candidates whose exact declaration identity could not be resolved.
445    pub unknown_symbol: usize,
446    /// Candidates using declaration syntax unsupported by the semantic backend.
447    pub unsupported_syntax: usize,
448    /// Candidates retained because the bounded semantic request reached capacity.
449    pub capacity: usize,
450}
451
452/// How a TypeScript project was selected for semantic refinement.
453#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
454#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
455#[serde(rename_all = "kebab-case")]
456pub enum TypeAwareProjectSource {
457    /// Fallow selected the nearest discovered project automatically.
458    #[default]
459    Auto,
460    /// The project was supplied with `--type-aware-project`.
461    Explicit,
462}
463
464/// Outcome of semantic refinement for one TypeScript project.
465#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
466#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
467#[serde(rename_all = "kebab-case")]
468pub enum TypeAwareProjectStatus {
469    /// The project was structurally safe and its candidates were scanned.
470    #[default]
471    Refined,
472    /// Structural diagnostics prevented candidate scanning.
473    Abstained,
474    /// All semantic queries assigned to this Program completed.
475    Complete,
476    /// The Program could not answer its assigned semantic queries safely.
477    Unavailable,
478}
479
480/// How a persistent semantic snapshot was refreshed.
481#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
482#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
483#[serde(rename_all = "kebab-case")]
484pub enum TypeAwareInvalidationKind {
485    /// The backend rebuilt project state from a clean snapshot.
486    Full,
487    /// The backend applied an explicit source-file change set.
488    Incremental,
489    /// No filesystem change was reported between compatible requests.
490    None,
491}
492
493/// Semantic sidecar timings, separated from Fallow's syntactic pipeline.
494#[derive(Debug, Clone, Default, Deserialize, Serialize)]
495#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
496pub struct TypeAwarePhaseTimings {
497    /// TypeScript API construction and project snapshot selection.
498    pub project_setup: u64,
499    /// TypeScript diagnostics collected before any candidate refinement.
500    pub diagnostics: u64,
501    /// Batched symbol lookup and exact declaration matching.
502    pub symbol_scan: u64,
503}
504
505/// Bounded provenance for one TypeScript project handled by the sidecar.
506#[derive(Debug, Clone, Default, Deserialize, Serialize)]
507#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
508pub struct TypeAwareProjectMeta {
509    /// Project config relative to the analysis root, or `<inferred>`.
510    pub config: String,
511    /// How the project was selected: `auto` or `explicit`.
512    pub source: TypeAwareProjectSource,
513    /// Project result: `refined`, `abstained`, `complete`, or `unavailable`.
514    pub status: TypeAwareProjectStatus,
515    /// Candidates assigned to this project.
516    pub candidate_count: usize,
517    /// Candidates confirmed as used and removed.
518    pub confirmed_used_count: usize,
519    /// Candidates retained because they implement or override a contract.
520    pub contract_preserved_count: usize,
521    /// Candidates with complete no-static-reference evidence.
522    pub no_static_references_count: usize,
523    /// Candidates eligible for a guarded class-member fix.
524    pub fix_eligible_count: usize,
525    /// Candidates whose exact semantic outcome remained unresolved.
526    pub unresolved_count: usize,
527    /// Candidates retained without scanning because the project was unsafe.
528    pub abstained_count: usize,
529    /// Config, program, syntactic, and bind diagnostics that block scanning.
530    pub blocking_diagnostic_count: usize,
531    /// Source files loaded into this TypeScript program.
532    pub source_file_count: usize,
533    /// Whether this Program served more than one semantic query in the batch.
534    #[serde(default, skip_serializing_if = "Option::is_none")]
535    pub program_reused: Option<bool>,
536    /// Whether this Program served more than one query in the current batch.
537    #[serde(default, skip_serializing_if = "Option::is_none")]
538    pub program_shared_across_queries: Option<bool>,
539    /// Whether the root-bound semantic session reused the prior snapshot.
540    #[serde(default, skip_serializing_if = "Option::is_none")]
541    pub program_reused_from_previous_snapshot: Option<bool>,
542    /// Monotonic revision within the root-bound semantic session.
543    #[serde(default, skip_serializing_if = "Option::is_none")]
544    pub snapshot_revision: Option<u64>,
545    /// Full, incremental, or no invalidation before this query.
546    #[serde(default, skip_serializing_if = "Option::is_none")]
547    pub invalidation_kind: Option<TypeAwareInvalidationKind>,
548    /// Stable project-level gap reason.
549    #[serde(default, skip_serializing_if = "Option::is_none")]
550    pub reason_code: Option<SemanticGapReason>,
551    /// Stable reason code when `status` is `abstained`.
552    #[serde(default, skip_serializing_if = "Option::is_none")]
553    #[cfg_attr(feature = "schema", schemars(with = "TypeAwareAbstentionReason"))]
554    pub abstain_reason: Option<TypeAwareAbstentionReason>,
555}
556
557/// Privacy-safe local run metadata emitted for JSON consumers.
558#[derive(Debug, Clone, Default, Serialize)]
559#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
560pub struct TelemetryMeta {
561    /// Ephemeral local token that may be passed to the hidden `--parent-run`
562    /// flag on a later command. It is not derived from repository, path, user,
563    /// machine, project, or cloud data.
564    #[serde(default, skip_serializing_if = "Option::is_none")]
565    pub analysis_run_id: Option<String>,
566}
567
568/// Single-metric definition inside [`Meta::metrics`].
569#[derive(Debug, Clone, Default, Serialize)]
570#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
571pub struct MetaMetric {
572    /// Human-readable metric name.
573    #[serde(default, skip_serializing_if = "Option::is_none")]
574    pub name: Option<String>,
575    /// What this metric measures and how it is computed.
576    #[serde(default, skip_serializing_if = "Option::is_none")]
577    pub description: Option<String>,
578    /// Valid value range (e.g., `"[0, 100]"`).
579    #[serde(default, skip_serializing_if = "Option::is_none")]
580    pub range: Option<String>,
581    /// How to read the value (e.g., `"lower is better"`).
582    #[serde(default, skip_serializing_if = "Option::is_none")]
583    pub interpretation: Option<String>,
584}
585
586/// Single-rule definition inside [`Meta::rules`].
587#[derive(Debug, Clone, Default, Serialize)]
588#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
589pub struct MetaRule {
590    /// Human-readable rule name.
591    #[serde(default, skip_serializing_if = "Option::is_none")]
592    pub name: Option<String>,
593    /// What this rule detects.
594    #[serde(default, skip_serializing_if = "Option::is_none")]
595    pub description: Option<String>,
596    /// URL to the rule documentation.
597    #[serde(default, skip_serializing_if = "Option::is_none")]
598    pub docs: Option<String>,
599}