Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
DR4: a rule is a line and the check that holds it (core/facts rule.rs): one of raea's checks by name with its values, or a project's .ts check by its path; taste's six forms are six named checks with the same names and values; a controller gains the field type rule ({ label, check, values?, level? }), each a rule; brief.gen.ts regenerated
shinyobjectz5ba4688c74cd
diff --git a/Cargo.lock b/Cargo.lockindex f4c347a4..a86199ce 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -14032,6 +14032,7 @@ version = "0.1.0"name = "raea-core-facts"version = "0.1.0"dependencies = [+ "raea-core-brief","serde","serde_json","ts-rs",diff --git a/core/brief/src/controller.rs b/core/brief/src/controller.rsindex 0807670d..0e9e3524 100644--- a/core/brief/src/controller.rs+++ b/core/brief/src/controller.rs@@ -63,9 +63,19 @@ pub enum Kind {Servers { value: Vec<String> },/// skills: links to SKILL.md, read into every agent's contextSkills { value: Vec<String> },+ /// a rule the work is held to, its label the rule's words (docs/direction.feature DR4): `check` is one of raea's+ /// checks by name with its `values`, or a path to the project's own check (a .ts file, from the controller's+ /// folder); `level` is error (when unset), warn or note. `raea check` runs it.+ Rule {+ check: String,+ #[serde(skip_serializing_if = "Option::is_none")]+ #[ts(type = "Record<string, number | string | boolean>")]+ values: Option<Map<String, Value>>,+ #[serde(skip_serializing_if = "Option::is_none")] level: Option<String>,+ },}-const TYPES: &str = "toggle, choice, number, text, list, agents, channels, workflow, servers, skills";+const TYPES: &str = "toggle, choice, number, text, list, agents, channels, workflow, servers, skills, rule";fn slug(s: &str) -> String {let mut out = String::new();@@ -144,6 +154,14 @@ pub fn normalize_field(raw: &Value, at: &str) -> Result<Field, String> {Some("servers") => Kind::Servers { value: strings(value, &format!("{w}: value"))? },Some("skills") => Kind::Skills { value: strings(value, &format!("{w}: value"))? },Some("workflow") => Kind::Workflow { value: steps(value, &w)?, channels: o.get("channels").map(|c| strings(Some(c), &format!("{w}: channels"))).transpose()? },+ Some("rule") => {+ let check = text(o, "check").ok_or_else(|| format!("{w}: a rule needs a check: one of raea's by name, or a path to a .ts check"))?;+ let level = text(o, "level");+ if level.as_deref().is_some_and(|l| !matches!(l, "error" | "warn" | "note")) {+ return Err(format!("{w}: a rule's level is error, warn or note"));+ }+ Kind::Rule { check, values: o.get("values").and_then(Value::as_object).cloned(), level }+ }_ => return Err(format!("{w}: type must be one of {TYPES}")),};Ok(Field { id, label, help: text(o, "help"), kind })diff --git a/core/brief/src/tests.rs b/core/brief/src/tests.rsindex 775bbb5e..742cc6cf 100644--- a/core/brief/src/tests.rs+++ b/core/brief/src/tests.rs@@ -104,6 +104,20 @@ fn a_controller_says_what_is_wrong_in_a_sentence_the_agent_can_act_on() {assert!(bad(r#"{"title": "X"}"#).contains("needs groups"));assert!(bad(r#"{"groups": []}"#).contains("needs a title"));assert!(bad(r#"{"title": "X", "groups": [{"title": "G", "fields": [{"label": "A", "type": "toggle"}, {"label": "a", "type": "toggle"}]}]}"#).contains("two fields are called a"));+ assert!(bad(r#"{"title": "X", "groups": [{"title": "G", "fields": [{"label": "A", "type": "rule"}]}]}"#).contains("a rule needs a check"));+ assert!(bad(r#"{"title": "X", "groups": [{"title": "G", "fields": [{"label": "A", "type": "rule", "check": "x", "level": "p0"}]}]}"#).contains("error, warn or note"));+}++#[test]+fn a_rule_field_is_a_check_by_name_with_values_or_a_path() {+ let j = r#"{"title": "Rules", "groups": [{"title": "Vertical", "fields": [+ {"label": "Captions clear the button band", "type": "rule", "check": "./checks/clear.ts", "values": {"platform": "tiktok"}, "level": "warn"},+ {"label": "Words stay up long enough to read", "type": "rule", "check": "text-hold", "values": {"value": 1.5}}]}]}"#;+ let c = controller::normalize(&serde_json::from_str(j).unwrap()).unwrap();+ let controller::Kind::Rule { check, values, level } = &c.groups[0].fields[0].kind else { panic!("a rule") };+ assert_eq!((check.as_str(), level.as_deref()), ("./checks/clear.ts", Some("warn")));+ assert_eq!(values.as_ref().unwrap()["platform"], "tiktok");+ assert_eq!(controller::normalize(&serde_json::to_value(&c).unwrap()).unwrap(), c, "it reads back as written");}#[test]diff --git a/core/facts/Cargo.toml b/core/facts/Cargo.tomlindex 43816f11..f494134a 100644--- a/core/facts/Cargo.toml+++ b/core/facts/Cargo.toml@@ -7,6 +7,8 @@ publish = falsedescription = "A project as one world of facts in raea/ecs's form: its layers, text, parts, shots, clips and cues as entities with components, for any kind of piece"[dependencies]+# a rule's taste form and controller field (rule.rs)+raea-core-brief = { path = "../brief" }serde = { version = "1", features = ["derive"] }serde_json = "1"# the TypeScript declarations are generated from these types, so a check's types can't drift from what raea readsdiff --git a/core/facts/src/lib.rs b/core/facts/src/lib.rsindex fb3bc848..c95930dd 100644--- a/core/facts/src/lib.rs+++ b/core/facts/src/lib.rs@@ -19,6 +19,10 @@ pub use rendered::*;// the project's record: what each render and check found, kept by render and commit (DR3)pub mod record;+// a rule the work is held to: one of raea's checks by name with its values, or a project's TS check (DR4)+pub mod rule;+pub use rule::Rule;+/// A JSON value as text: a string as it is, anything else as its JSON (a list key may be a number, a stamp a string).pub fn text_of(v: &serde_json::Value) -> String {match v {diff --git a/core/facts/src/rule.rs b/core/facts/src/rule.rsnew file mode 100644index 00000000..8abd6b47--- /dev/null+++ b/core/facts/src/rule.rs@@ -0,0 +1,97 @@+//! A rule: a line the work is held to, and the check that holds it (docs/direction.feature DR4). The check is one of+//! raea's, by name with its values (apps/direction systems.rs), or a project's own TS check by its path (sdk/raea+//! check.ts). Where a rule was written (raea's floor, the person's taste, a workspace's or a project's controller)+//! changes nothing about how it runs: it is only said, as its findings' `by`. A taste file's six forms are six of+//! raea's named checks with the same names and values, so every taste file reads as it did.++use std::path::{Path, PathBuf};++use raea_core_brief::{controller, taste};+use serde::{Deserialize, Serialize};+use serde_json::{Map, Value};++use crate::Level;++#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]+pub struct Rule {+ /// what `--only` names: a named check's name, or a check file's name without .ts+ pub id: String,+ /// the line it holds the work to+ pub text: String,+ /// one of raea's checks by name, or a .ts check's path (resolved from the file the rule was written in)+ pub check: String,+ #[serde(default, skip_serializing_if = "Map::is_empty")]+ pub values: Map<String, Value>,+ pub level: Level,+ /// where it was written: "raea", or "taste", "workspace" or "project" and the file+ pub by: String,+}++impl Rule {+ /// One of raea's checks by `name`, held to `values`.+ pub fn named(name: &str, text: &str, values: Map<String, Value>, level: Level, by: &str) -> Rule {+ Rule { id: name.into(), text: text.into(), check: name.into(), values, level, by: by.into() }+ }++ /// The project's .ts check this rule runs, when it runs one.+ pub fn file(&self) -> Option<&Path> {+ self.check.ends_with(".ts").then(|| Path::new(&self.check))+ }++ /// A value the rule holds its check to: a number.+ pub fn number(&self, name: &str) -> Option<f64> {+ self.values.get(name).and_then(Value::as_f64)+ }++ /// A taste line that carries a check: the named check of its form (text-hold, text-above, text-below,+ /// text-margin, loudness, still-max), its value as `value`. Taste's lines are errors, as raea check held them.+ pub fn of_taste(text: &str, c: taste::Check, file: &str) -> Rule {+ let values = Map::from_iter([("value".to_string(), Value::from(c.value()))]);+ Rule::named(c.form(), text, values, Level::Error, &format!("taste {file}"))+ }++ /// A controller's rule fields, each a rule: a path from `dir` (the controller's folder) made whole, the field's+ /// label its words. `by`: "workspace" or "project", with the controller's file.+ pub fn of_controller(c: &controller::Controller, dir: &Path, by: &str) -> Vec<Rule> {+ let mut out = Vec::new();+ for f in c.groups.iter().flat_map(|g| &g.fields) {+ let controller::Kind::Rule { check, values, level } = &f.kind else { continue };+ let (check, id) = match check.ends_with(".ts") {+ true => {+ let path: PathBuf = dir.join(check);+ let id = path.file_stem().map(|s| s.to_string_lossy().into_owned()).unwrap_or_default();+ (path.display().to_string(), id)+ }+ false => (check.clone(), check.clone()),+ };+ let level = level.as_deref().map_or(Level::Error, Level::of_word);+ out.push(Rule { id, text: f.label.clone(), check, values: values.clone().unwrap_or_default(), level, by: by.into() });+ }+ out+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn a_taste_form_is_the_named_check_of_the_same_name_and_value() {+ let r = Rule::of_taste("Captions sit clear of the bottom.", taste::Check::TextAbove(62.0), "taste.ts");+ assert_eq!((r.id.as_str(), r.check.as_str(), r.number("value"), r.level), ("text-above", "text-above", Some(62.0), Level::Error));+ assert!(r.file().is_none() && r.by == "taste taste.ts");+ }++ #[test]+ fn a_controllers_rule_fields_are_rules_and_a_path_is_from_its_folder() {+ let raw = serde_json::json!({"title": "Rules", "groups": [{"title": "G", "fields": [+ {"label": "Captions clear the button band", "type": "rule", "check": "../checks/clear.ts", "level": "warn"},+ {"label": "Loud enough", "type": "rule", "check": "loudness", "values": {"value": -14}},+ {"label": "Burn in captions", "type": "toggle", "value": true}]}]});+ let c = controller::normalize(&raw).unwrap();+ let rs = Rule::of_controller(&c, Path::new("/p/controllers"), "project controllers/rules.ts");+ assert_eq!(rs.len(), 2, "a toggle is no rule");+ assert_eq!((rs[0].id.as_str(), rs[0].file(), rs[0].level), ("clear", Some(Path::new("/p/controllers/../checks/clear.ts")), Level::Warn));+ assert_eq!((rs[1].check.as_str(), rs[1].number("value"), rs[1].level), ("loudness", Some(-14.0), Level::Error));+ }+}diff --git a/sdk/raea/src/brief.gen.ts b/sdk/raea/src/brief.gen.tsindex c54db366..8f492391 100644--- a/sdk/raea/src/brief.gen.ts+++ b/sdk/raea/src/brief.gen.ts@@ -194,8 +194,8 @@ export type Controller = { id: string, title: string, help?: string, groups: Arrexport type Group = { id: string, title: string, help?: string, fields: Array<Field>, };-export type Field = { id: string, label: string, help?: string, } & ({ "type": "toggle", value: boolean, } | { "type": "choice", options: Array<string>, value: string, } | { "type": "number", value: number, unit?: string, min?: number, max?: number, step?: number, } | { "type": "text", value: string, placeholder?: string, multiline?: boolean, } | { "type": "list", value: Array<string>, placeholder?: string, } | { "type": "agents", value: Array<string>, } | { "type": "channels", value: Array<string>, } | { "type": "workflow", value: Array<Step>, channels?: Array<string>, } | { "type": "servers", value: Array<string>, } | { "type": "skills", value: Array<string>, });+export type Field = { id: string, label: string, help?: string, } & ({ "type": "toggle", value: boolean, } | { "type": "choice", options: Array<string>, value: string, } | { "type": "number", value: number, unit?: string, min?: number, max?: number, step?: number, } | { "type": "text", value: string, placeholder?: string, multiline?: boolean, } | { "type": "list", value: Array<string>, placeholder?: string, } | { "type": "agents", value: Array<string>, } | { "type": "channels", value: Array<string>, } | { "type": "workflow", value: Array<Step>, channels?: Array<string>, } | { "type": "servers", value: Array<string>, } | { "type": "skills", value: Array<string>, } | { "type": "rule", check: string, values: Record<string, number | string | boolean>, level?: string, });-export type Kind = { "type": "toggle", value: boolean, } | { "type": "choice", options: Array<string>, value: string, } | { "type": "number", value: number, unit?: string, min?: number, max?: number, step?: number, } | { "type": "text", value: string, placeholder?: string, multiline?: boolean, } | { "type": "list", value: Array<string>, placeholder?: string, } | { "type": "agents", value: Array<string>, } | { "type": "channels", value: Array<string>, } | { "type": "workflow", value: Array<Step>, channels?: Array<string>, } | { "type": "servers", value: Array<string>, } | { "type": "skills", value: Array<string>, };+export type Kind = { "type": "toggle", value: boolean, } | { "type": "choice", options: Array<string>, value: string, } | { "type": "number", value: number, unit?: string, min?: number, max?: number, step?: number, } | { "type": "text", value: string, placeholder?: string, multiline?: boolean, } | { "type": "list", value: Array<string>, placeholder?: string, } | { "type": "agents", value: Array<string>, } | { "type": "channels", value: Array<string>, } | { "type": "workflow", value: Array<Step>, channels?: Array<string>, } | { "type": "servers", value: Array<string>, } | { "type": "skills", value: Array<string>, } | { "type": "rule", check: string, values: Record<string, number | string | boolean>, level?: string, };export type Step = { name: string, by?: string, back?: string, };