[core] API: scaena-core public API (canon, claims, hooks), bodies pending

This commit is contained in:
2026-11-23 01:15:41 +01:00
parent 5dd554d52e
commit 6f30efb79b
8 changed files with 832 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: CPAL-1.0
// Copyright (c) 2026 Marek Novák. Exhibit A notice: LICENSE at the repository root.
//! The claim checker.
//!
//! Every sentence that states a fact carries at least one `[app#Fn]` reference (several may be adjacent:
//! `[tabula#F3][tabula#F7]`) at its end, and every reference must point to a confirmed canon fact.
//! Fail closed: a sentence states a fact unless it is one of a short list of plain phrases
//! ("Here's what's new.", "Try it today.").
use serde::{Deserialize, Serialize};
use crate::canon::Canon;
/// A claim reference `[app#F<fact>]`.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Ref {
pub app: String,
pub fact: u32,
}
/// Why a text fails the claim check.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Problem {
/// A sentence that states a fact without any reference.
Unsourced { sentence: String },
/// The app exists, the fact does not.
MissingFact { r: Ref },
/// No canon file for the app.
UnknownApp { r: Ref },
/// The fact is marked `(assumption)`.
Unconfirmed { r: Ref },
/// Something that looks like a reference but is not `[app#Fn]`.
MalformedRef { text: String },
/// A URL that is not in [`Canon::allowed_urls`].
UrlNotInCanon { url: String },
/// A control, hidden or direction-changing character (addition to the Day 1 contract).
HiddenCharacter { codepoint: u32 },
}
impl Problem {
/// Plain English, for "Needs facts".
pub fn reason(&self) -> String {
todo!()
}
}
/// The result of [`check`].
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Report {
/// Every well-formed reference found, sorted and unique.
pub refs: Vec<Ref>,
pub problems: Vec<Problem>,
}
impl Report {
pub fn ok(&self) -> bool {
self.problems.is_empty()
}
}
/// Check generated text against the canon.
pub fn check(text: &str, canon: &Canon) -> Report {
let _ = (text, canon);
todo!()
}
/// Remove every well-formed `[app#Fn]` reference (and the spaces before it), for display and posting.
pub fn strip_refs(text: &str) -> String {
let _ = text;
todo!()
}
/// Split text into sentences the way [`check`] does.
pub fn sentences(text: &str) -> Vec<String> {
let _ = text;
todo!()
}
/// Whether [`check`] treats this sentence (without its references) as stating a fact. Fail closed.
pub fn states_fact(sentence: &str, canon: &Canon) -> bool {
let _ = (sentence, canon);
todo!()
}