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#[expect(
100 clippy::trivially_copy_pass_by_ref,
101 reason = "serde skip_serializing_if requires a reference"
102)]
103const fn zero_count(count: &usize) -> bool {
104 *count == 0
105}
106
107/// Per-category issue counts for dead-code analysis. Always present in
108/// `CheckOutput`; when `--summary` is used the individual issue arrays are
109/// omitted but this object stays populated.
110#[derive(Debug, Clone, Default, Serialize)]
111#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
112pub struct CheckSummary {
113 /// Total number of issues across all categories.
114 pub total_issues: usize,
115 /// Prop chains whose saved effective severity explicitly enforces error policy.
116 #[serde(default, skip_serializing_if = "zero_count")]
117 pub prop_drilling_chains: usize,
118 /// Unused source files.
119 pub unused_files: usize,
120 /// Unused value exports.
121 pub unused_exports: usize,
122 /// Unused type exports.
123 pub unused_types: usize,
124 /// Public exports whose signature references same-file private types.
125 pub private_type_leaks: usize,
126 /// Exports marked `@deprecated` that are still referenced.
127 pub deprecated_exports_in_use: usize,
128 /// Combined count of unused entries across `dependencies`,
129 /// `devDependencies`, and `optionalDependencies`. The per-section
130 /// breakdown lives in the individual issue arrays on `CheckOutput`.
131 pub unused_dependencies: usize,
132 /// Unused enum members.
133 pub unused_enum_members: usize,
134 /// Unused class members.
135 pub unused_class_members: usize,
136 /// Unused store members.
137 #[serde(default)]
138 pub unused_store_members: usize,
139 /// Vue/Svelte injects whose key is provided nowhere in the project.
140 #[serde(default)]
141 pub unprovided_injects: usize,
142 /// Vue/Svelte components reachable but rendered nowhere in the project.
143 #[serde(default)]
144 pub unrendered_components: usize,
145 /// Vue, Svelte, or React props referenced nowhere inside their own component.
146 #[serde(default)]
147 pub unused_component_props: usize,
148 /// Optional consumed props omitted by known reachable callers, for manual review.
149 #[serde(default)]
150 pub absent_component_props: usize,
151 /// Vue `<script setup>` emits emitted nowhere inside their own SFC.
152 #[serde(default)]
153 pub unused_component_emits: usize,
154 /// Angular `@Input()` bindings referenced nowhere inside their own component.
155 #[serde(default)]
156 pub unused_component_inputs: usize,
157 /// Angular `@Output()` bindings emitted nowhere inside their own component.
158 #[serde(default)]
159 pub unused_component_outputs: usize,
160 /// Svelte components dispatching a custom event via `createEventDispatcher`
161 /// whose name is listened to nowhere in the project.
162 #[serde(default)]
163 pub unused_svelte_events: usize,
164 /// Effect layers composed only into layers that nothing uses.
165 #[serde(default)]
166 pub unused_effect_layers: usize,
167 /// Effect tagged error classes that no code constructs or fails with.
168 #[serde(default)]
169 pub unused_tagged_errors: usize,
170 /// `catchTag` handlers for a project tag that no code produces.
171 #[serde(default)]
172 pub unproduced_catch_tags: usize,
173 /// Next.js Server Actions (exports of `"use server"` files) referenced by no
174 /// code in the project.
175 #[serde(default)]
176 pub unused_server_actions: usize,
177 /// SvelteKit `load()` return-object keys read by no consumer.
178 #[serde(default)]
179 pub unused_load_data_keys: usize,
180 /// Imports that could not be resolved against the project's module graph.
181 pub unresolved_imports: usize,
182 /// Dependencies imported but absent from `package.json`.
183 pub unlisted_dependencies: usize,
184 /// Same-named exports declared in more than one module.
185 pub duplicate_exports: usize,
186 /// Production dependencies only used via type-only imports (could be
187 /// devDependencies). Only populated in production mode.
188 pub type_only_dependencies: usize,
189 /// Production dependencies only imported by test files (could be
190 /// devDependencies).
191 pub test_only_dependencies: usize,
192 /// devDependencies imported by production source code with a runtime/value
193 /// import (should be promoted to dependencies).
194 pub dev_dependencies_in_production: usize,
195 /// Cycles detected in the import graph.
196 pub circular_dependencies: usize,
197 /// Cycles or self-loops in the re-export edge subgraph (barrel files
198 /// re-exporting from each other in a loop).
199 #[serde(default)]
200 pub re_export_cycles: usize,
201 /// Dependency cycles between workspace packages.
202 #[serde(default)]
203 pub package_cycles: usize,
204 /// Imports that cross architecture boundary rules.
205 pub boundary_violations: usize,
206 /// Files that match no architecture boundary zone.
207 #[serde(default)]
208 pub boundary_coverage_violations: usize,
209 /// Calls from zoned files to callees forbidden for that zone.
210 #[serde(default)]
211 pub boundary_call_violations: usize,
212 /// Banned calls, imports, and catalogue-derived effects matched by
213 /// declarative rule packs.
214 #[serde(default)]
215 pub policy_violations: usize,
216 /// Suppression comments that no longer match a finding.
217 pub stale_suppressions: usize,
218 /// Unused pnpm-workspace catalog entries.
219 pub unused_catalog_entries: usize,
220 /// Empty named catalog groups.
221 pub empty_catalog_groups: usize,
222 /// Workspace package.json catalog references the workspace catalogs
223 /// do not declare.
224 pub unresolved_catalog_references: usize,
225 /// Package-manager overrides whose target package is not declared by any
226 /// workspace package and not present in the active readable lockfile.
227 pub unused_dependency_overrides: usize,
228 /// Package-manager overrides whose key or value cannot be parsed.
229 pub misconfigured_dependency_overrides: usize,
230 /// `"use client"` files that export a Next.js server-only / route-config name.
231 #[serde(default)]
232 pub invalid_client_exports: usize,
233 /// Barrel files that re-export both a `"use client"` origin and a
234 /// server-only origin.
235 #[serde(default)]
236 pub mixed_client_server_barrels: usize,
237 /// Misplaced `"use client"` / `"use server"` directives written as
238 /// expression statements after a non-directive statement.
239 #[serde(default)]
240 pub misplaced_directives: usize,
241 /// Next.js App Router route files that resolve to the same URL within one
242 /// app-root.
243 #[serde(default)]
244 pub route_collisions: usize,
245 /// Sibling Next.js dynamic route segments at one position using different
246 /// param spellings.
247 #[serde(default)]
248 pub dynamic_segment_name_conflicts: usize,
249}
250
251/// Per-category delta comparison against a saved baseline. Only present in
252/// `CheckOutput` when `--baseline` is used.
253#[derive(Debug, Clone, Default, Serialize)]
254#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
255pub struct BaselineDeltas {
256 /// Net change in total issues vs baseline (positive = more issues).
257 pub total_delta: i64,
258 /// Per-category breakdown of current, baseline, and delta counts.
259 pub per_category: BTreeMap<String, BaselineCategoryDelta>,
260}
261
262/// Single-category baseline delta entry inside [`BaselineDeltas::per_category`].
263#[derive(Debug, Clone, Copy, Default, Serialize)]
264#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
265pub struct BaselineCategoryDelta {
266 /// Current issue count for this category.
267 pub current: usize,
268 /// Baseline issue count for this category.
269 pub baseline: usize,
270 /// Change from baseline (current - baseline).
271 pub delta: i64,
272}
273
274/// Baseline match statistics. Shows how many baseline entries existed and how
275/// many matched current issues. Useful for detecting stale baselines
276/// programmatically. Only present in `CheckOutput` when `--baseline` is used.
277#[derive(Debug, Clone, Copy, Default, Serialize)]
278#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
279pub struct BaselineMatch {
280 /// Total number of entries in the loaded baseline file.
281 pub entries: usize,
282 /// Number of baseline entries that matched current issues and were
283 /// filtered.
284 pub matched: usize,
285}
286
287/// Result of regression detection (`--fail-on-regression`). Compares current
288/// issue counts against a baseline from config or an explicit file.
289#[derive(Debug, Clone, Serialize)]
290#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
291pub struct RegressionResult {
292 /// Outcome of the regression check.
293 pub status: RegressionStatus,
294 /// Baseline total before the change. Absent when status is `skipped`.
295 #[serde(default, skip_serializing_if = "Option::is_none")]
296 pub baseline_total: Option<i64>,
297 /// Current total after the change. Absent when status is `skipped`.
298 #[serde(default, skip_serializing_if = "Option::is_none")]
299 pub current_total: Option<i64>,
300 /// Difference current - baseline. Absent when status is `skipped`.
301 #[serde(default, skip_serializing_if = "Option::is_none")]
302 pub delta: Option<i64>,
303 /// Configured tolerance, interpreted per [`RegressionToleranceKind`].
304 /// Absent when status is `skipped`.
305 #[serde(default, skip_serializing_if = "Option::is_none")]
306 pub tolerance: Option<f64>,
307 /// Interpretation of the tolerance value.
308 #[serde(default, skip_serializing_if = "Option::is_none")]
309 pub tolerance_kind: Option<RegressionToleranceKind>,
310 /// Whether the regression exceeded the tolerance.
311 pub exceeded: bool,
312 /// Only present when status is `skipped`.
313 #[serde(default, skip_serializing_if = "Option::is_none")]
314 pub reason: Option<String>,
315}
316
317/// Status of a regression-check pass.
318#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
319#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
320#[serde(rename_all = "lowercase")]
321pub enum RegressionStatus {
322 /// Issue count within tolerance.
323 Pass,
324 /// Issue count exceeded tolerance.
325 Exceeded,
326 /// Regression check did not run (missing baseline, etc.).
327 Skipped,
328}
329
330/// Interpretation of [`RegressionResult::tolerance`].
331#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
332#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
333#[serde(rename_all = "lowercase")]
334pub enum RegressionToleranceKind {
335 /// Tolerance is interpreted as an absolute issue-count delta.
336 Absolute,
337 /// Tolerance is interpreted as a percentage of the baseline total.
338 Percentage,
339}
340
341/// Metric and rule definitions emitted under `_meta` when `--explain` is
342/// passed (always present in MCP responses). Helps AI agents and CI systems
343/// interpret metric values without re-reading the docs site.
344#[derive(Debug, Clone, Default, Serialize)]
345#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
346pub struct Meta {
347 /// URL to the documentation page for this command.
348 #[serde(default, skip_serializing_if = "Option::is_none")]
349 pub docs: Option<String>,
350 /// Local telemetry correlation metadata for agent follow-up runs.
351 #[serde(default, skip_serializing_if = "Option::is_none")]
352 pub telemetry: Option<TelemetryMeta>,
353 /// Provenance for the opt-in TypeScript semantic analysis pass.
354 #[serde(default, skip_serializing_if = "Option::is_none")]
355 pub type_aware: Option<TypeAwareMeta>,
356 /// Per-field definitions for envelope fields and action payload fields.
357 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
358 pub field_definitions: BTreeMap<String, String>,
359 /// Per-metric definitions: name, description, range, interpretation.
360 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
361 pub metrics: BTreeMap<String, MetaMetric>,
362 /// Per-rule definitions for check command output.
363 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
364 pub rules: BTreeMap<String, MetaRule>,
365}
366
367/// Bounded provenance emitted when the opt-in type-aware pass runs.
368#[derive(Debug, Clone, Default, Deserialize, Serialize)]
369#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
370pub struct TypeAwareMeta {
371 /// Compatibility identity used by audit, baselines, snapshots, and stores.
372 #[serde(default, skip_serializing_if = "Option::is_none")]
373 pub identity: Option<SemanticAnalysisIdentity>,
374 /// Effective CLI or repository policy for incomplete semantic evidence.
375 #[serde(default, skip_serializing_if = "Option::is_none")]
376 pub required_completeness: Option<crate::semantic::SemanticCompletenessRequirement>,
377 /// Compact status for every requested semantic query.
378 #[serde(default, skip_serializing_if = "Vec::is_empty")]
379 pub queries: Vec<SemanticQuerySummary>,
380 /// Bounded decision and evidence for each semantic dead-code candidate.
381 #[serde(default, skip_serializing_if = "Vec::is_empty")]
382 pub candidate_decisions: Vec<SemanticCandidateDecision>,
383 /// Checker-backed trace evidence requested by focused symbol queries.
384 #[serde(default, skip_serializing_if = "Vec::is_empty")]
385 pub symbol_traces: Vec<SemanticSymbolTrace>,
386 /// Package-public surface and confirmed private type leaks.
387 #[serde(default, skip_serializing_if = "Option::is_none")]
388 pub api_surface: Option<ApiSurfaceResult>,
389 /// Exact-symbol blast radius and targeted-test recommendations.
390 #[serde(default, skip_serializing_if = "Vec::is_empty")]
391 pub symbol_impacts: Vec<SemanticSymbolImpact>,
392 /// Advisory project-local public-signature coupling.
393 #[serde(default, skip_serializing_if = "Option::is_none")]
394 pub type_coupling: Option<TypeCouplingReport>,
395 /// Whether the semantic companion executed at least one query.
396 pub executed: bool,
397 /// Version of Fallow's backend-neutral sidecar protocol.
398 pub protocol_version: u32,
399 /// Version of the sidecar package that executed the query.
400 #[serde(default, skip_serializing_if = "Option::is_none")]
401 pub sidecar_version: Option<String>,
402 /// Semantic backend capability identifier.
403 pub backend: String,
404 /// Backend compiler or engine version that executed the query.
405 #[serde(default, skip_serializing_if = "Option::is_none")]
406 pub backend_version: Option<String>,
407 /// TypeScript project configs selected for candidate files.
408 pub selected_tsconfigs: Vec<String>,
409 /// Number of candidate findings sent to the sidecar.
410 pub candidate_count: usize,
411 /// Number of candidates confirmed as used and removed.
412 pub confirmed_used_count: usize,
413 /// Number of candidates preserved because they implement or override a contract.
414 pub contract_preserved_count: usize,
415 /// Number of candidates with complete, closed-world no-static-reference evidence.
416 pub no_static_references_count: usize,
417 /// Number of retained class members eligible for a guarded type-aware fix.
418 pub fix_eligible_count: usize,
419 /// Number of candidates retained because semantic use was unresolved.
420 pub unresolved_count: usize,
421 /// Number of candidates retained because semantic analysis abstained.
422 pub abstained_count: usize,
423 /// Stable abstention reason counts for automation and diagnostics.
424 pub abstention_reasons: TypeAwareAbstentionCounts,
425 /// Per-project semantic refinement status and evidence.
426 pub projects: Vec<TypeAwareProjectMeta>,
427 /// Number of bounded warnings returned by the sidecar.
428 pub warning_count: usize,
429 /// Bounded semantic warnings. Findings mentioned here were retained.
430 pub warnings: Vec<String>,
431 /// Semantic pass duration as reported by the sidecar.
432 pub elapsed_ms: u64,
433 /// Bounded semantic phase timings reported by the sidecar.
434 pub phase_timings_ms: TypeAwarePhaseTimings,
435}
436
437/// Closed set of reasons for retaining a candidate without semantic scanning.
438#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
439#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
440#[serde(rename_all = "kebab-case")]
441pub enum TypeAwareAbstentionReason {
442 /// No selected TypeScript project contains the candidate file.
443 #[default]
444 NoProject,
445 /// Multiple explicit TypeScript projects contain the candidate file.
446 AmbiguousProject,
447 /// Structural TypeScript diagnostics make exact matching unsafe.
448 BlockingDiagnostics,
449}
450
451/// Closed abstention reason counts for stable machine consumption.
452#[derive(Debug, Clone, Default, Deserialize, Serialize)]
453#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
454pub struct TypeAwareAbstentionCounts {
455 /// Candidates not contained by a selected TypeScript project.
456 pub no_project: usize,
457 /// Candidates contained by more than one explicit TypeScript project.
458 pub ambiguous_project: usize,
459 /// Candidates retained because structural diagnostics block scanning.
460 pub blocking_diagnostics: usize,
461 /// Candidates retained because the raw TypeScript-Go host cannot expose
462 /// named exports from Svelte virtual modules.
463 pub svelte_virtual_module_exports: usize,
464 /// Candidates whose exact declaration identity could not be resolved.
465 pub unknown_symbol: usize,
466 /// Candidates using declaration syntax unsupported by the semantic backend.
467 pub unsupported_syntax: usize,
468 /// Candidates retained because the bounded semantic request reached capacity.
469 pub capacity: usize,
470}
471
472/// How a TypeScript project was selected for semantic refinement.
473#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
474#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
475#[serde(rename_all = "kebab-case")]
476pub enum TypeAwareProjectSource {
477 /// Fallow selected the nearest discovered project automatically.
478 #[default]
479 Auto,
480 /// The project was supplied with `--type-aware-project`.
481 Explicit,
482}
483
484/// Outcome of semantic refinement for one TypeScript project.
485#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
486#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
487#[serde(rename_all = "kebab-case")]
488pub enum TypeAwareProjectStatus {
489 /// The project was structurally safe and its candidates were scanned.
490 #[default]
491 Refined,
492 /// Structural diagnostics prevented candidate scanning.
493 Abstained,
494 /// All semantic queries assigned to this Program completed.
495 Complete,
496 /// The Program could not answer its assigned semantic queries safely.
497 Unavailable,
498}
499
500/// How a persistent semantic snapshot was refreshed.
501#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
502#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
503#[serde(rename_all = "kebab-case")]
504pub enum TypeAwareInvalidationKind {
505 /// The backend rebuilt project state from a clean snapshot.
506 Full,
507 /// The backend applied an explicit source-file change set.
508 Incremental,
509 /// No filesystem change was reported between compatible requests.
510 None,
511}
512
513/// Semantic sidecar timings, separated from Fallow's syntactic pipeline.
514#[derive(Debug, Clone, Default, Deserialize, Serialize)]
515#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
516pub struct TypeAwarePhaseTimings {
517 /// TypeScript API construction and project snapshot selection.
518 pub project_setup: u64,
519 /// TypeScript diagnostics collected before any candidate refinement.
520 pub diagnostics: u64,
521 /// Batched symbol lookup and exact declaration matching.
522 pub symbol_scan: u64,
523}
524
525/// Bounded provenance for one TypeScript project handled by the sidecar.
526#[derive(Debug, Clone, Default, Deserialize, Serialize)]
527#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
528pub struct TypeAwareProjectMeta {
529 /// Project config relative to the analysis root, or `<inferred>`.
530 pub config: String,
531 /// How the project was selected: `auto` or `explicit`.
532 pub source: TypeAwareProjectSource,
533 /// Project result: `refined`, `abstained`, `complete`, or `unavailable`.
534 pub status: TypeAwareProjectStatus,
535 /// Candidates assigned to this project.
536 pub candidate_count: usize,
537 /// Candidates confirmed as used and removed.
538 pub confirmed_used_count: usize,
539 /// Candidates retained because they implement or override a contract.
540 pub contract_preserved_count: usize,
541 /// Candidates with complete no-static-reference evidence.
542 pub no_static_references_count: usize,
543 /// Candidates eligible for a guarded class-member fix.
544 pub fix_eligible_count: usize,
545 /// Candidates whose exact semantic outcome remained unresolved.
546 pub unresolved_count: usize,
547 /// Candidates retained without scanning because the project was unsafe.
548 pub abstained_count: usize,
549 /// Config, program, syntactic, and bind diagnostics that block scanning.
550 pub blocking_diagnostic_count: usize,
551 /// Source files loaded into this TypeScript program.
552 pub source_file_count: usize,
553 /// Whether this Program served more than one semantic query in the batch.
554 #[serde(default, skip_serializing_if = "Option::is_none")]
555 pub program_reused: Option<bool>,
556 /// Whether this Program served more than one query in the current batch.
557 #[serde(default, skip_serializing_if = "Option::is_none")]
558 pub program_shared_across_queries: Option<bool>,
559 /// Whether the root-bound semantic session reused the prior snapshot.
560 #[serde(default, skip_serializing_if = "Option::is_none")]
561 pub program_reused_from_previous_snapshot: Option<bool>,
562 /// Monotonic revision within the root-bound semantic session.
563 #[serde(default, skip_serializing_if = "Option::is_none")]
564 pub snapshot_revision: Option<u64>,
565 /// Full, incremental, or no invalidation before this query.
566 #[serde(default, skip_serializing_if = "Option::is_none")]
567 pub invalidation_kind: Option<TypeAwareInvalidationKind>,
568 /// Stable project-level gap reason.
569 #[serde(default, skip_serializing_if = "Option::is_none")]
570 pub reason_code: Option<SemanticGapReason>,
571 /// Stable reason code when `status` is `abstained`.
572 #[serde(default, skip_serializing_if = "Option::is_none")]
573 #[cfg_attr(feature = "schema", schemars(with = "TypeAwareAbstentionReason"))]
574 pub abstain_reason: Option<TypeAwareAbstentionReason>,
575}
576
577/// Privacy-safe local run metadata emitted for JSON consumers.
578#[derive(Debug, Clone, Default, Serialize)]
579#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
580pub struct TelemetryMeta {
581 /// Ephemeral local token that may be passed to the hidden `--parent-run`
582 /// flag on a later command. It is not derived from repository, path, user,
583 /// machine, project, or cloud data.
584 #[serde(default, skip_serializing_if = "Option::is_none")]
585 pub analysis_run_id: Option<String>,
586}
587
588/// Single-metric definition inside [`Meta::metrics`].
589#[derive(Debug, Clone, Default, Serialize)]
590#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
591pub struct MetaMetric {
592 /// Human-readable metric name.
593 #[serde(default, skip_serializing_if = "Option::is_none")]
594 pub name: Option<String>,
595 /// What this metric measures and how it is computed.
596 #[serde(default, skip_serializing_if = "Option::is_none")]
597 pub description: Option<String>,
598 /// Valid value range (e.g., `"[0, 100]"`).
599 #[serde(default, skip_serializing_if = "Option::is_none")]
600 pub range: Option<String>,
601 /// How to read the value (e.g., `"lower is better"`).
602 #[serde(default, skip_serializing_if = "Option::is_none")]
603 pub interpretation: Option<String>,
604}
605
606/// Single-rule definition inside [`Meta::rules`].
607#[derive(Debug, Clone, Default, Serialize)]
608#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
609pub struct MetaRule {
610 /// Human-readable rule name.
611 #[serde(default, skip_serializing_if = "Option::is_none")]
612 pub name: Option<String>,
613 /// What this rule detects.
614 #[serde(default, skip_serializing_if = "Option::is_none")]
615 pub description: Option<String>,
616 /// URL to the rule documentation.
617 #[serde(default, skip_serializing_if = "Option::is_none")]
618 pub docs: Option<String>,
619}