chore: bootstrap nana-story M0

This commit is contained in:
Codex
2026-07-28 12:51:00 +08:00
commit 3dacc92423
71 changed files with 6840 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "nana-engine"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
[dependencies]
nana-domain.workspace = true
thiserror.workspace = true
[lints]
workspace = true
+48
View File
@@ -0,0 +1,48 @@
use nana_domain::{RuntimeState, StateDelta};
use thiserror::Error;
#[derive(Debug, Error, PartialEq, Eq)]
pub enum ReduceError {
#[error("state delta is not implemented yet: {0} operation(s)")]
NotImplemented(usize),
}
/// M0 contract seam. M1 replaces this placeholder with the only authoritative
/// state mutation path in the application.
pub fn apply_delta(state: &RuntimeState, delta: &StateDelta) -> Result<RuntimeState, ReduceError> {
if delta.ops.is_empty() {
Ok(state.clone())
} else {
Err(ReduceError::NotImplemented(delta.ops.len()))
}
}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use nana_domain::{RuntimeState, StateDelta};
use super::apply_delta;
#[test]
fn empty_delta_is_identity() {
let state = RuntimeState {
story_id: "story_demo".to_owned(),
current_node: "node_001".to_owned(),
current_branch: "branch_main".to_owned(),
world_flags: BTreeMap::new(),
relationships: BTreeMap::new(),
relationship_states: Vec::new(),
promises: Vec::new(),
knowledge: Vec::new(),
items: Vec::new(),
clocks: Vec::new(),
checks: Vec::new(),
};
assert_eq!(
apply_delta(&state, &StateDelta { ops: Vec::new() }),
Ok(state)
);
}
}