feat(analysis): consume the current public Analysis v3 contract

- add the process boundary for the core CLI: explicit MARQDO_BIN/--marqdo-bin
  only (never PATH), argv-only invocation of check ENTRY --emit, bounded
  timeout, private temp artifact, exit checks and absolute-path sanitisation
- deserialize every Analysis record with closed serde shapes and validate
  semantic invariants that JSON Schema cannot express: identities, source
  digests, UTF-8 spans, unit tree/order/mode ancestry, anchors, functions and
  signatures, references states, calls, resources, diagnostics and budgets
- validate statement/expression trees structurally with depth and span checks
- convert accepted modules into DocumentFacts, preserving honest upstream
  reference states and one node per Exec unit/function
- merge modules across entry contexts only when identity and source agree,
  otherwise report knowledge.analysis_context_conflict
- add the real rc.4 Analysis positive fixture (with provenance and regeneration
  script), tamper negative tests and optional real-binary integration tests
This commit is contained in:
marqdo-knowledge committed 2026-11-26 00:29:19 +08:00
1 parent 682717a610
commit 59d5afe10b
14 files changed
+3474 -57

No files matched your search

+9 -9
View File
@@ -49,14 +49,14 @@ pub fn parse_plain(file: &SourceFile) -> DocumentFacts {
.push(Diagnostic::error(code::MARKDOWN_INVALID, message).with_path(&file.rel_path));
}
let front_matter = extract_front_matter(&ast, &mut diagnostics, &file.rel_path);
let front_matter = front_matter_fact(&ast, &mut diagnostics, &file.rel_path);
let mut units = build_units(&ast, file);
fix_unit_spans(&mut units, source.len() as u64);
let anchors = build_anchors(&units);
let title = document_title(&units, &file.rel_path);
let references = extract_references(&ast, &units);
let blocks = extract_blocks(&ast, &units);
let blocks = searchable_blocks(&ast, &units);
DocumentFacts {
rel_path: file.rel_path.clone(),
@@ -358,12 +358,12 @@ fn fix_unit_spans(units: &mut [UnitFact], source_len: u64) {
.map(|span| span.start)
.unwrap_or(units[index].span.start);
let mut end = source_len;
for later in index + 1..units.len() {
if units[later].level <= level {
end = units[later]
for later in units.iter().skip(index + 1) {
if later.level <= level {
end = later
.heading_span
.map(|span| span.start)
.unwrap_or(units[later].span.start);
.unwrap_or(later.span.start);
break;
}
}
@@ -446,7 +446,7 @@ fn document_title(units: &[UnitFact], rel_path: &str) -> String {
file.to_string()
}
fn extract_front_matter(
pub(crate) fn front_matter_fact(
ast: &AstNode,
diagnostics: &mut DiagnosticSet,
rel_path: &str,
@@ -631,7 +631,7 @@ fn extract_references(ast: &AstNode, units: &[UnitFact]) -> Vec<ReferenceFact> {
references
}
fn innermost_unit(units: &[UnitFact], span: Span) -> usize {
pub(crate) fn innermost_unit(units: &[UnitFact], span: Span) -> usize {
let mut best = 0usize;
let mut best_level = 0u8;
for (index, unit) in units.iter().enumerate() {
@@ -646,7 +646,7 @@ fn innermost_unit(units: &[UnitFact], span: Span) -> usize {
best
}
fn extract_blocks(ast: &AstNode, units: &[UnitFact]) -> Vec<BlockFact> {
pub(crate) fn searchable_blocks(ast: &AstNode, units: &[UnitFact]) -> Vec<BlockFact> {
let mut blocks = Vec::new();
for child in &ast.children {
if child.kind == AstKind::FrontMatter || child.kind == AstKind::Heading {