[core] Docs: README section What's in v0 with the scaena-core API

This commit is contained in:
2026-11-23 01:43:02 +01:00
parent 5b6cc34b6f
commit 87a5f4f33f
+97
View File
@@ -4,6 +4,103 @@ The pure core of Scaena, Domi's video studio: canon parser and claim checker, ho
model, ffmpeg argument compiler, ASS subtitle builder, audits, similarity scoring, hook evolution and Thompson model, ffmpeg argument compiler, ASS subtitle builder, audits, similarity scoring, hook evolution and Thompson
sampling. Pure Rust, no I/O. Used by Praeco Domi by git tag. sampling. Pure Rust, no I/O. Used by Praeco Domi by git tag.
## What's in v0
Crate `scaena-core` (`crates/scaena-core`), tag `core-v0.1.0`. Pure Rust, `#![forbid(unsafe_code)]`, no I/O;
dependencies are serde, thiserror and unicode-segmentation only. Builds for Windows, Android
(`aarch64-linux-android`) and the web (`wasm32-unknown-unknown`). If you redistribute it, alone or inside your own
app, show the Exhibit B credit (see [Licence](#licence)).
```toml
scaena-core = { git = "https://gitea.marek-novak.cz/mnovak/ScaenaPublic.git", tag = "core-v0.1.0" }
```
### `scaena_core::canon`: canon files
```rust
pub fn parse(file_stem: &str, text: &str) -> Result<CanonFile, CanonError>; // CanonError { line, code }
pub struct CanonFile { pub id: String, pub front: FrontMatter, pub facts: Vec<Fact> }
pub struct FrontMatter { pub name, one_liner, audience, price, clicks: String, pub status: Status,
pub aula: Option<String>, pub site: Option<String> }
pub enum Status { Released, Beta, Planned }
pub struct Fact { pub id: u32, pub text: String, pub assumption: bool, pub line: usize }
impl CanonFile { fn fact(&self, id: u32) -> Option<&Fact>; fn urls(&self) -> Vec<String>;
fn adhoc(id: &str, name: &str, facts: Vec<(u32, String)>) -> CanonFile; }
pub struct Canon; // new, insert (duplicate id = error), get, apps, fact, allowed_urls
pub fn is_valid_app_id(id: &str) -> bool;
pub fn is_assumption_value(value: &str) -> bool;
```
The format of `apps/<id>.md` (UTF-8, at most 64 KiB):
```markdown
---
id: tabula
name: Tabula
one_liner: Notes that stay on your own computer.
audience: People who want notes without an account.
price: (assumption) one-time purchase
clicks: New note in 1 click.
status: released
aula: https://aula.marek-novak.cz/tabula/
---
## What it does
- [F1] Tabula keeps notes on your own computer.
- [F2] It syncs between your devices without a cloud account. (assumption)
```
- Front matter: flat `key: value` lines between two `---` lines. Required: `id name one_liner audience price clicks
status`; optional: `aula`, `site` (each a single `https://` URL). Unknown, duplicate, missing or empty keys are
errors. `id` equals the file stem: 1–32 of `[a-z0-9-]`, no leading or trailing `-`. `status` is `released`,
`beta` or `planned`.
- Facts: `- [F<n>] <text>`, `n` 1–9999 without leading zeros, unique, under any heading. Any bullet line starting
`[F` that does not match exactly is an error. A fact ending in `(assumption)` is unconfirmed; the marker is removed
from `text` and `assumption` is set (a marker elsewhere in the text also sets it).
- Hostile input: a leading BOM and CRLF line endings are accepted; a lone CR, control characters other than tab,
bidi controls, zero-width space, word joiner, BOM inside the text and tag characters are errors.
- Allowed URLs: `aula`, `site` and every `https://` URL in a fact's text.
### `scaena_core::claims`: the claim checker
```rust
pub fn check(text: &str, canon: &Canon) -> Report;
pub struct Report { pub refs: Vec<Ref> /* sorted, unique */, pub problems: Vec<Problem> } // ok() = no problems
pub struct Ref { pub app: String, pub fact: u32 }
pub enum Problem { Unsourced { sentence }, MissingFact { r }, UnknownApp { r }, Unconfirmed { r },
MalformedRef { text }, UrlNotInCanon { url }, HiddenCharacter { codepoint } } // non_exhaustive
impl Problem { pub fn reason(&self) -> String } // plain English
pub fn strip_refs(text: &str) -> String;
pub fn sentences(text: &str) -> Vec<String>;
pub fn states_fact(sentence: &str, canon: &Canon) -> bool;
```
- References look like `[tabula#F3]`; several may be adjacent (`[tabula#F3][tabula#F7]`), at the end of the
sentence they support (before or after its full stop). A sentence ends at `.`, `!`, `?` or `…` followed by
whitespace, and at every line break; `1.2` and URLs do not end one. The checker cannot tell whether a fact
really supports its sentence: a valid reference anywhere in a sentence sources the whole sentence.
- Fail closed: every sentence needs a reference to a confirmed fact unless it is one of a short list of plain
phrases ("Here's what's new.", "Try it today.", "Try Tabula today.", "Learn more.", "Thanks for reading."…).
So numbers, prices, platforms and feature claims always need one.
- Rejected: unsourced sentences, references to unknown apps or missing facts, references to `(assumption)` facts
("unconfirmed fact"), malformed references (`[F3]`, `[Tabula#F3]`, `tabula#F3`…), URLs not in
`Canon::allowed_urls` (`scheme://`, `www.` and bare `host.tld/path` forms), hidden or direction-changing
characters.
### `scaena_core::hooks`: hook templates
```rust
pub fn parse(md: &str) -> Result<Vec<HookTemplate>, HookError>; // brand/hooks.md: "- [H<n>] <template>"
pub struct HookTemplate { pub id: String /* "H3" */, pub text: String, pub slots: Vec<String>, pub genome: Genome }
impl HookTemplate { pub fn fill(&self, values: &BTreeMap<String, String>) -> Result<String, HookError>; }
pub struct Genome { pub opening: Opening, pub words: usize, pub has_number: bool, pub lead_verb: Option<String> }
pub enum Opening { Question, Statement, Number, Command }
pub const SLOTS: [&str; 7] = ["app", "feature", "pain", "number", "platform", "clicks", "audience"];
```
Any slot outside `SLOTS` and any unbalanced brace is an error. `fill` fails on a missing value and never expands
braces inside values.
## Licence ## Licence
Common Public Attribution License 1.0 (CPAL-1.0), see [LICENSE](LICENSE). Common Public Attribution License 1.0 (CPAL-1.0), see [LICENSE](LICENSE).