//! Typed public Analysis DTO (spec/analysis.md). //! //! These types are the boundary model, not a dump of internal IR: every field //! is projected explicitly from the prepared program. The canonical encoder //! serializes this model once; the file writer and the Observation digest use //! the same bytes. use serde::Serialize; use serde_json::Value; /// Half-open UTF-8 byte span in the owning module's `source`. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] pub struct SpanJson { /// Inclusive byte offset. pub start: usize, /// Exclusive byte offset. pub end: usize, } impl From for SpanJson { fn from(span: marqdo_span::Span) -> Self { Self { start: span.start, end: span.end, } } } /// Root Analysis document. #[derive(Debug, Clone, Serialize)] pub struct Analysis { /// `marqdo.analysis`. pub schema: &'static str, /// Current revision. pub schema_version: u32, /// Producer identity. pub producer: Producer, /// Project snapshot and entry context. pub project: Project, /// Loaded modules, sorted by id. pub modules: Vec, /// Deterministic diagnostics. pub diagnostics: Vec, } /// Producer identity. #[derive(Debug, Clone, Serialize)] pub struct Producer { /// Always `marqdo`. pub name: &'static str, /// Product version. pub version: &'static str, /// Markdown profile id. pub markdown_profile: &'static str, } /// Project snapshot identity. #[derive(Debug, Clone, Serialize)] pub struct Project { /// Logical root id. pub root_id: String, /// `manifest` or `workspace_snapshot`. pub identity_kind: &'static str, /// Module loaded from the CLI entry. pub entry_module_id: String, /// Captured lock digest, empty when no lock exists. pub lock_digest: String, /// Captured manifest digest, empty when no manifest exists. pub manifest_digest: String, /// Verified stdlib identity, if any. pub stdlib: Option, /// Static extension identities that participated in preparation. pub extensions: Vec, } /// Verified bundled stdlib identity. #[derive(Debug, Clone, Serialize)] pub struct Stdlib { /// Declared version. pub version: String, /// Verified content digest. pub digest: String, /// Package instance id. pub instance_id: String, } /// One static extension identity. #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct Extension { /// `plugin`, `kernel` or `provider`. pub kind: &'static str, /// Declared package/provider name. pub name: String, /// Declared version. pub version: String, /// Logical owner package instance. pub logical_owner: String, /// Declared activation source, or `--plugin`. pub source: String, /// Manifest digest (`sha256:`). pub manifest_digest: String, /// Selected artifact digest (`sha256:`). pub artifact_digest: String, /// Selected host target triple. pub selected_target: String, } /// One loaded module. #[derive(Debug, Clone, Serialize)] pub struct ModuleAnalysis { /// Canonical module id. pub id: String, /// Package instance. pub package_instance_id: String, /// Package-relative path with `/` separators. pub relative_path: String, /// SHA-256 of the exact source bytes. pub source_digest: String, /// Exact UTF-8 source text. pub source: String, /// Public Markdown AST. pub document: Value, /// Heading units in document order. pub units: Vec, /// Anchor map sorted by anchor. pub anchors: Vec, /// Exec H2 functions in document order. pub functions: Vec, /// Explicit imports in document order. pub imports: Vec, /// Markdown references in source order. pub references: Vec, /// Static call bindings in source order. pub calls: Vec, /// Inert resources in document order. pub resources: Vec, } /// One addressable heading range. #[derive(Debug, Clone, Serialize)] pub struct UnitRecord { /// Canonical unit id. pub id: String, /// Structured canonical path. pub path: Vec, /// Parent unit id, root `null`. pub parent_id: Option, /// `root`, `namespace`, `function`, `knowledge` or `section`. pub kind: &'static str, /// Normalised heading name. pub name: String, /// Heading level, root 0. pub level: u8, /// Effective mode. pub mode: &'static str, /// `default`, `explicit` or `inherited`. pub mode_origin: &'static str, /// Unit that provided the effective mode. pub mode_source_unit_id: String, /// Original heading span, root `null`. pub heading_span: Option, /// Complete section range. pub span: SpanJson, /// Owning function id. pub function: Option, } /// One anchor entry. #[derive(Debug, Clone, Serialize)] pub struct AnchorRecord { /// GitHub-style anchor. pub anchor: String, /// Addressable unit. pub unit_id: String, } /// One Exec H2 function. #[derive(Debug, Clone, Serialize)] pub struct FunctionRecord { /// Canonical function id. pub id: String, /// Addressable unit. pub unit_id: String, /// Local function name. pub local_name: String, /// Enclosing namespace. pub namespace: Option, /// Declaration span. pub span: SpanJson, /// Heading span. pub heading_span: SpanJson, /// Signature. pub signature: SignatureRecord, /// Conservative effects. pub effects: Vec<&'static str>, /// Statements. pub body: Vec, } /// Function signature. #[derive(Debug, Clone, Serialize)] pub struct SignatureRecord { /// `explicit` or `inferred`. pub kind: &'static str, /// Parameters. pub params: Vec, } /// One function parameter. #[derive(Debug, Clone, Serialize)] pub struct ParamRecord { /// Parameter name. pub name: String, /// Whether no default value exists. pub required: bool, /// Declared type annotation. pub r#type: Option, /// Default expression. pub default: Option, /// Declaration span. pub span: SpanJson, } /// One explicit import. #[derive(Debug, Clone, Serialize)] pub struct ImportRecord { /// Local alias. pub alias: String, /// Declared target. pub target: String, /// Declaration span. pub span: SpanJson, /// Resolved module id. pub resolved: Option, } /// One resolved document reference. #[derive(Debug, Clone, Serialize)] pub struct ReferenceRecord { /// Source module. pub source: String, /// Innermost owning unit. pub source_unit: String, /// Raw URL. pub url: String, /// Link span. pub span: SpanJson, /// Resolver state. pub state: &'static str, /// `module`, `file` or `null`. pub target_kind: Option<&'static str>, /// Resolved module. pub target_module: Option, /// Resolved unit. pub target_unit: Option, /// Logical candidate package instance. pub candidate_package_instance_id: Option, /// Normalised package-relative candidate. pub candidate_path: Option, /// Decoded fragment. pub fragment: Option, /// Ambiguous exact candidates. pub candidates: Vec, } /// One static call record. #[derive(Debug, Clone, Serialize)] pub struct CallRecord { /// Caller function id. pub function: String, /// Call expression span. pub span: SpanJson, /// Callee shape. pub callee: Value, /// Function, builtin, plugin or unresolved. pub state: &'static str, /// Bound target value. pub target: Option, /// `function`, `builtin`, `plugin` or `null`. pub target_kind: Option<&'static str>, /// Static plugin owner, if any. pub target_owner: Option, /// `dynamic`, `unbound` or `null`. pub reason: Option<&'static str>, } /// Static plugin owner of a bound export. #[derive(Debug, Clone, Serialize)] pub struct TargetOwner { /// Always `plugin`. pub kind: &'static str, /// Plugin package. pub package: String, /// Verified artifact digest. pub digest: String, } /// One inert resource. #[derive(Debug, Clone, Serialize)] pub struct ResourceRecord { /// Module-local ordinal id. pub id: String, /// Owning module. pub module_id: String, /// Innermost owning unit. pub unit_id: String, /// `formula` or `code`. pub kind: &'static str, /// AST node span. pub span: SpanJson, /// Payload digest. pub content_digest: String, /// Code fence language. pub language: Option, /// Formula display mode (`null` for code). pub display: Option, } /// One diagnostic. #[derive(Debug, Clone, Serialize)] pub struct DiagnosticRecord { /// Owning module. pub module: String, /// Package-relative path. pub relative_path: String, /// Primary span. pub span: Option, /// 1-based line. pub line: Option, /// 1-based column. pub column: Option, /// `error` or `warning`. pub severity: &'static str, /// Stable code. pub code: String, /// Message. pub message: String, /// Hints. pub hints: Vec, }