Skip to content

armgit / raea

Public Imported from GitHub
0

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.

DR3: the project's record keeps what each render and check found; raea findings reads it, raea next steps by it

shinyobjectzaebbdb2d4a9f
diff --git a/Cargo.lock b/Cargo.lock
index 4d74b4d3..4e4e694d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13594,6 +13594,7 @@ version = "0.1.0"
dependencies = [
"raea-core-brief",
"raea-core-facts",
+ "raea-io-trace",
"serde_json",
]
@@ -13611,6 +13612,7 @@ name = "raea-app-direction"
version = "0.1.0"
dependencies = [
"raea-core-facts",
+ "raea-io-trace",
"raea-runtime-bundle",
"raea-runtime-world",
"serde_json",
@@ -13740,6 +13742,7 @@ version = "0.1.0"
dependencies = [
"raea-app-registry",
"raea-core-brief",
+ "raea-core-facts",
"serde_json",
]
diff --git a/apps/check/Cargo.toml b/apps/check/Cargo.toml
index 88f66cf8..9cff13cd 100644
--- a/apps/check/Cargo.toml
+++ b/apps/check/Cargo.toml
@@ -11,4 +11,6 @@ description = "`raea check`: the floor's measurable lines on an export, ranked P
raea-core-brief = { path = "../../core/brief" }
# a transcript's words, read as `raea world` reads them (docs/direction.feature DR1)
raea-core-facts = { path = "../../core/facts" }
+# a check's record named by when it was (UTC, DR3)
+raea-io-trace = { path = "../../io/trace" }
serde_json = "1"
diff --git a/apps/check/src/lib.rs b/apps/check/src/lib.rs
index b34f27e9..abeef5c4 100644
--- a/apps/check/src/lib.rs
+++ b/apps/check/src/lib.rs
@@ -176,7 +176,10 @@ fn report(video: &str, mut issues: Vec<Issue>, more: Vec<Finding>, passed: Vec<S
std::fs::write(out, serde_json::to_string_pretty(&j).unwrap()).map_err(|e| format!("{out}: {e}"))?;
}
let mut s = format!("raea check {video}\n");
- for line in found.iter().map(Finding::line).chain(passed.iter().map(|p| format!("ok {p}"))) {
+ // kept in its project's record beside its renders (DR3), what `raea findings` and `raea next` read
+ let kept = raea_core_facts::record::keep("raea check", std::path::Path::new(video), out.map(std::path::Path::new), &found, vec![], &raea_io_trace::utc(std::time::SystemTime::now()).1);
+ let kept = kept.map(|e| format!("kept in the project's record as {}", e.id));
+ for line in found.iter().map(Finding::line).chain(passed.iter().map(|p| format!("ok {p}"))).chain(kept) {
s.push_str(&line);
s.push('\n');
}
diff --git a/apps/direction/Cargo.toml b/apps/direction/Cargo.toml
index d33503e3..a1090a54 100644
--- a/apps/direction/Cargo.toml
+++ b/apps/direction/Cargo.toml
@@ -10,4 +10,6 @@ description = "How raea takes direction (docs/direction.feature): `raea world`,
raea-runtime-world = { path = "../../runtime/world" }
raea-runtime-bundle = { path = "../../runtime/bundle" }
raea-core-facts = { path = "../../core/facts" }
+# a render's record named by when it was (UTC)
+raea-io-trace = { path = "../../io/trace" }
serde_json = "1"
diff --git a/apps/direction/src/findings.rs b/apps/direction/src/findings.rs
new file mode 100644
index 00000000..9969b2c6
--- /dev/null
+++ b/apps/direction/src/findings.rs
@@ -0,0 +1,122 @@
+//! `raea findings` (docs/direction.feature DR3): what renders and checks found, read from the project's record
+//! (core/facts record.rs). For each thing rendered or checked, its latest entry against the one before (or the one
+//! `--since` names): what was fixed, what is new and what is carried, and since which render.
+
+use std::path::{Path, PathBuf};
+
+use raea_core_facts::record::{self, Entry};
+use raea_core_facts::{Finding, finding};
+use raea_runtime_bundle::flag;
+use serde_json::{Value, json};
+
+pub const USAGE: &str = "raea findings [PROJECT | EDIT.tsx] [--about NAME] [--check ID] [--open] [--since RENDER] [--json] (what each render and raea check found, from the project's record: fixed, new and carried since the one before, or since RENDER; --open: only what stands)";
+
+/// The oldest entry of the unbroken run up to the latest that all found `f`.
+fn carried_since(entries: &[&Entry], f: &Finding) -> String {
+ let key = record::same(f);
+ let run = entries.iter().rev().take_while(|e| e.findings.iter().any(|g| record::same(g) == key));
+ run.last().map(|e| e.id.clone()).unwrap_or_default()
+}
+
+/// One thing's latest entry against the one before it (or `since`), each list filtered by `keep`.
+fn compare(entries: &[&Entry], since: Option<&str>, keep: &dyn Fn(&Finding) -> bool, open: bool) -> Option<Value> {
+ let (now, earlier) = entries.split_last()?;
+ let before = match since {
+ Some(id) => earlier.iter().rev().find(|e| e.id.starts_with(id)),
+ None => earlier.last(),
+ };
+ let none = Vec::new();
+ let ch = record::changes(before.map_or(&none, |b| &b.findings), &now.findings);
+ let list = |fs: Vec<&Finding>| fs.into_iter().filter(|f| keep(f)).cloned().collect::<Vec<Finding>>();
+ let carried: Vec<Value> = list(ch.carried).into_iter().map(|f| json!({"since": carried_since(entries, &f), "finding": f})).collect();
+ let fixed = if open { Vec::new() } else { list(ch.fixed) };
+ Some(json!({"of": now.of, "id": now.id, "by": now.by, "commit": now.commit, "out": now.out, "against": before.map(|b| &b.id),
+ "new": list(ch.new), "carried": carried, "fixed": fixed, "despite": now.despite}))
+}
+
+/// One thing's lines: its entry, then what is new, carried and fixed.
+fn lines(r: &Value) -> Vec<String> {
+ let read = |v: &Value| serde_json::from_value::<Finding>(v.clone()).ok();
+ let mut t = vec![format!(
+ "{} ({} {}{}, against {})",
+ r["of"].as_str().unwrap_or(""),
+ r["by"].as_str().unwrap_or(""),
+ r["id"].as_str().unwrap_or(""),
+ r["commit"].as_str().map(|c| format!(" at {c}")).unwrap_or_default(),
+ r["against"].as_str().unwrap_or("nothing: its first")
+ )];
+ t.extend(r["new"].as_array().into_iter().flatten().filter_map(read).map(|f| format!(" new {}", f.line())));
+ for c in r["carried"].as_array().into_iter().flatten() {
+ if let Some(f) = read(&c["finding"]) {
+ t.push(format!(" carried {} (since {})", f.line(), c["since"].as_str().unwrap_or("")));
+ }
+ }
+ t.extend(r["fixed"].as_array().into_iter().flatten().filter_map(read).map(|f| format!(" fixed {}", f.line())));
+ t
+}
+
+/// What stands across the reports: each one's new and carried.
+fn standing(reports: &[Value]) -> Vec<Finding> {
+ let mut out = Vec::new();
+ for r in reports {
+ out.extend(r["new"].as_array().into_iter().flatten().filter_map(|v| serde_json::from_value(v.clone()).ok()));
+ out.extend(r["carried"].as_array().into_iter().flatten().filter_map(|c| serde_json::from_value(c["finding"].clone()).ok()));
+ }
+ out
+}
+
+/// `raea findings ...` (args from "findings").
+pub fn cli(args: &[String]) -> Result<String, String> {
+ let target = args.get(1).filter(|a| !a.starts_with("--")).map_or_else(|| PathBuf::from("."), PathBuf::from);
+ let from = if target.is_file() { target.parent().unwrap_or(Path::new(".")).to_path_buf() } else { target.clone() };
+ let project = record::up(&from, ".raea/project").ok_or_else(|| format!("raea findings: {} isn't in a raea project (no .raea/project at or above it), so nothing is recorded\n{USAGE}", target.display()))?;
+ let (about, check, since) = (flag(args, "--about"), flag(args, "--check"), flag(args, "--since"));
+ let keep = |f: &Finding| about.as_deref().is_none_or(|n| f.about.iter().any(|a| a.name == n || a.key.as_deref() == Some(n))) && check.as_deref().is_none_or(|c| f.check == c);
+ let all = record::read(&project);
+ let only = target.is_file().then(|| record::rel(&project, &target));
+ let mut ofs: Vec<&str> = all.iter().map(|e| e.of.as_str()).filter(|o| only.as_deref().is_none_or(|w| w == *o)).collect();
+ ofs.sort();
+ ofs.dedup();
+ let open = args.iter().any(|a| a == "--open");
+ let reports: Vec<Value> = ofs.iter().filter_map(|of| compare(&all.iter().filter(|e| e.of == *of).collect::<Vec<_>>(), since.as_deref(), &keep, open)).collect();
+ let count = finding::count(&standing(&reports));
+ if args.iter().any(|a| a == "--json") {
+ return Ok(serde_json::to_string_pretty(&json!({"project": project, "entries": all.len(), "reports": reports, "standing": count})).unwrap_or_default());
+ }
+ let mut t = vec![format!("raea findings: {} ({} entries in .raea/record)", project.display(), all.len())];
+ if reports.is_empty() {
+ t.push(" nothing recorded yet: a render or raea check of a file in this project keeps what it found".into());
+ }
+ t.extend(reports.iter().flat_map(lines));
+ t.push(format!("raea findings: {count} standing"));
+ Ok(t.join("\n"))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use raea_core_facts::Level;
+
+ fn entry(id: &str, fs: Vec<Finding>) -> Entry {
+ Entry { id: id.into(), at: 0, by: "raea render".into(), of: "edit.tsx".into(), out: None, commit: None, findings: fs, despite: vec![] }
+ }
+
+ #[test]
+ fn the_latest_render_against_the_one_before_says_fixed_new_and_carried_since_when() {
+ let clips = Finding::new("clips", Level::Error, "rider in seat", "raea render").about("rider", None);
+ let tilt = Finding::new("tilted", Level::Warn, "vase leans", "raea render").about("vase", None);
+ let float = Finding::new("floats", Level::Error, "lamp floats", "raea render").about("lamp", None);
+ let es = [entry("a", vec![clips.clone(), tilt.clone()]), entry("b", vec![clips.clone(), tilt]), entry("c", vec![clips, float])];
+ let refs: Vec<&Entry> = es.iter().collect();
+ let all = |_: &Finding| true;
+ let r = compare(&refs, None, &all, false).unwrap();
+ assert_eq!((r["against"].as_str(), r["new"][0]["check"].as_str(), r["fixed"][0]["check"].as_str()), (Some("b"), Some("floats"), Some("tilted")));
+ assert_eq!((r["carried"][0]["finding"]["check"].as_str(), r["carried"][0]["since"].as_str()), (Some("clips"), Some("a")));
+ // against a named render, and only what stands
+ let r = compare(&refs, Some("a"), &all, true).unwrap();
+ assert_eq!((r["against"].as_str(), r["fixed"].as_array().map(Vec::len)), (Some("a"), Some(0)));
+ assert_eq!(finding::count(&standing(&[r])), "2 errors, 0 warns, 0 notes");
+ let lamp = |f: &Finding| f.about.iter().any(|a| a.name == "lamp");
+ assert_eq!(compare(&refs, None, &lamp, false).unwrap()["carried"].as_array().map(Vec::len), Some(0));
+ }
+}
diff --git a/apps/direction/src/lib.rs b/apps/direction/src/lib.rs
index 3cc5c56f..236e1a2a 100644
--- a/apps/direction/src/lib.rs
+++ b/apps/direction/src/lib.rs
@@ -7,3 +7,6 @@ pub use world::{cli, find, Find, USAGE};
// how `raea render` ends: its findings counted last, and 1 on an error not let through (DR3)
mod rendered;
pub use rendered::rendered;
+
+// `raea findings`: the project's record read back, fixed, new and carried (DR3)
+pub mod findings;
diff --git a/apps/direction/src/rendered.rs b/apps/direction/src/rendered.rs
index dc4c3da5..0c216cc0 100644
--- a/apps/direction/src/rendered.rs
+++ b/apps/direction/src/rendered.rs
@@ -4,6 +4,10 @@
//! compares pixels, not scenes, by RAEA_DESPITE="CHECK: why" (which a raea before this ignores, as it would refuse the
//! flag). What was let through, and why, is written into the render's manifest.
+use std::path::PathBuf;
+use std::time::SystemTime;
+
+use raea_core_facts::record::{self, Despite};
use raea_core_facts::{Finding, Level, finding};
use serde_json::{Value, json};
@@ -28,20 +32,29 @@ fn ending(found: &[Finding], through: &[(String, String)]) -> (String, i32) {
(line, i32::from(errors(false) > 0))
}
-/// `raea render`'s exit, once its findings' count is printed; 0 for any other command.
+/// `raea render`'s exit, once its findings' count is printed; 0 for any other command. Its findings (the clipping
+/// check's, its exposure's) go into its manifest, with what was let through and why, and into its project's record.
pub fn rendered(args: &[String]) -> i32 {
if args.first().map(String::as_str) != Some("render") {
return 0;
}
let found = finding::taken();
let through = despite(args, std::env::var("RAEA_DESPITE").ok());
- if let (Some(m), false) = (raea_runtime_bundle::flag(args, "--manifest"), through.is_empty()) {
- // the reasons beside the findings they let through
+ let excused: Vec<Despite> = through.iter().map(|(c, w)| Despite { check: c.clone(), why: w.clone() }).collect();
+ if let Some(m) = raea_runtime_bundle::flag(args, "--manifest") {
if let Some(mut v) = std::fs::read(&m).ok().and_then(|b| serde_json::from_slice::<Value>(&b).ok()) {
- v["despite"] = Value::Array(through.iter().map(|(c, w)| json!({"check": c, "why": w})).collect());
+ v["findings"] = json!(found);
+ if !excused.is_empty() {
+ v["despite"] = json!(excused);
+ }
let _ = std::fs::write(&m, v.to_string());
}
}
+ let file = args.get(1).filter(|a| !a.starts_with('-')).map(PathBuf::from);
+ let out = raea_runtime_bundle::flag(args, "-o").map(PathBuf::from);
+ if let Some(e) = file.and_then(|f| record::keep("raea render", &f, out.as_deref(), &found, excused, &raea_io_trace::utc(SystemTime::now()).1)) {
+ println!("raea render: kept in the project's record as {} (raea findings reads it)", e.id);
+ }
let (line, code) = ending(&found, &through);
println!("{line}");
code
diff --git a/apps/workspace/Cargo.toml b/apps/workspace/Cargo.toml
index a229256f..1518c24d 100644
--- a/apps/workspace/Cargo.toml
+++ b/apps/workspace/Cargo.toml
@@ -12,3 +12,5 @@ raea-core-brief = { path = "../../core/brief" }
serde_json = "1"
# a project's compositions, components and controllers read from their source (docs/projects.feature PJ8)
raea-app-registry = { path = "registry" }
+# the project's record of what renders and checks found, which raea next reads (docs/direction.feature DR3)
+raea-core-facts = { path = "../../core/facts" }
diff --git a/apps/workspace/registry/src/lib.rs b/apps/workspace/registry/src/lib.rs
index bf203b1e..64471887 100644
--- a/apps/workspace/registry/src/lib.rs
+++ b/apps/workspace/registry/src/lib.rs
@@ -19,11 +19,8 @@ mod read;
pub use lint::{Fix, Level, Lint, apply};
pub use read::{Facts, Prop};
-/// The nearest folder at or above `from` that holds `marker` (.raea/workspace, .raea/project).
-pub fn up(from: &Path, marker: &str) -> Option<PathBuf> {
- let from = from.canonicalize().ok()?;
- from.ancestors().find(|d| d.join(marker).is_file()).map(Path::to_path_buf)
-}
+/// The nearest folder at or above a path that holds a marker (.raea/workspace, .raea/project), as the record finds it.
+pub use raea_core_facts::record::up;
/// A name as a folder: lowercase, dashes. A controller's id from its title is this (core/brief fills it the same way).
pub fn slug(s: &str) -> String {
diff --git a/apps/workspace/src/next.rs b/apps/workspace/src/next.rs
index 1f7ff128..60a455d2 100644
--- a/apps/workspace/src/next.rs
+++ b/apps/workspace/src/next.rs
@@ -1,9 +1,11 @@
//! `raea next` (docs/skills.feature SK10): the two or three useful next steps for a project, read from its files: the
-//! brief (what it still needs, from the raea CLI's brief doctor), the storyboard its modes want, its compositions, its
-//! renders in out/ and their checks (`raea check ... -o out/NAME.check.json`). A menu for the agent or the person to
-//! pick from; nothing runs.
+//! brief (what it still needs, from the raea CLI's brief doctor), the storyboard its modes want, its compositions, and
+//! from the project's record (docs/direction.feature DR3) its renders and their checks and what each found. A menu for
+//! the agent or the person to pick from; nothing runs.
use super::*;
-use std::time::SystemTime;
+use raea_core_facts::Level;
+use raea_core_facts::record::{self, Entry};
+use std::time::{SystemTime, UNIX_EPOCH};
/// What the raea CLI read from the project's brief.
pub struct Brief {
@@ -27,16 +29,29 @@ fn name(p: &Path) -> String {
full.rsplit(['/', '\\']).next().unwrap_or_default().to_string()
}
-/// The errors a check file holds (its findings, docs/direction.feature DR3), as their lines.
-fn blocking(check: &Path) -> Vec<String> {
- let Ok(j) = std::fs::read_to_string(check).map_err(drop).and_then(|t| serde_json::from_str::<serde_json::Value>(&t).map_err(drop)) else { return vec![] };
- let mut out = Vec::new();
- for f in j["findings"].as_array().into_iter().flatten() {
- if let (Some("error"), Some(check), Some(says)) = (f["level"].as_str(), f["check"].as_str(), f["says"].as_str()) {
- out.push(format!("{check}: {says}"));
- }
+/// An entry's first error, as `check: says`.
+fn first_error(e: &Entry) -> Option<String> {
+ e.findings.iter().find(|f| f.level == Level::Error).map(|f| format!("{}: {}", f.check, f.says))
+}
+
+/// The step after a composition's latest render in the project's record (docs/direction.feature DR3): its errors,
+/// then its video's check (a `raea check` of what it wrote, kept after it) and what that found.
+fn after_render(c: &Path, record: &[Entry], i: usize) -> String {
+ let e = &record[i];
+ if let Some(err) = first_error(e) {
+ return format!("fix {}: {err} (its render {} found it; `raea findings {}` lists them all)", name(c), e.id, name(c));
+ }
+ let Some(out) = e.out.as_deref().filter(|o| o.ends_with(".mp4")) else {
+ return format!("render the video: `raea render {} -o out/{}`", name(c), name(&c.with_extension("mp4")));
+ };
+ let check = out.replace(".mp4", ".check.json");
+ match record[i + 1..].iter().rev().find(|k| k.by == "raea check" && k.of == out) {
+ None => format!("check {out}: `raea check {out} -o {check}` (add --manifest when the render wrote one)"),
+ Some(k) => match first_error(k) {
+ Some(err) => format!("polish {out}: {err} (`raea guide polish`)"),
+ None => format!("show {out}: post it to the project's feed (feed_post), or give the person its path, and read their notes"),
+ },
}
- out
}
/// The steps, most useful first, at most three. `stale` is what `raea doctor` found here.
@@ -59,23 +74,18 @@ pub fn steps(dir: &Path, brief: &Brief, stale: usize) -> Vec<String> {
if let Some(first) = loose.first() {
out.push(format!("connect the project's files: {} thing(s) aren't connected, first {} (`raea project scan` lists them, `raea doctor --fix` fixes what it can)", loose.len(), first.line()));
}
+ // the newest composition's renders and checks, from the project's record (DR3)
let comps = reg.composition_files();
- let renders = files(&dir.join("out"), ".mp4");
- match (comps.first(), renders.first()) {
- (None, _) => out.push("make the first item: one .tsx whose root registers a Composition (`raea guide craft` first)".into()),
- (Some(c), None) => out.push(format!("render {}: stills to look at first (`raea render {} --at 0,45,89 -o frames/`), then the video into out/", name(c), name(c))),
- (Some(c), Some(r)) if modified(c) > modified(r) => out.push(format!("render again: {} changed after {}", name(c), name(r))),
- (_, Some(r)) => {
- let check = r.with_extension("check.json");
- if !check.is_file() || modified(&check) < modified(r) {
- out.push(format!("check {}: `raea check out/{} -o out/{}` (add --manifest when the render wrote one)", name(r), name(r), name(&check)));
- } else {
- match blocking(&check).first() {
- Some(issue) => out.push(format!("polish {}: {issue} (`raea guide polish`)", name(r))),
- None => out.push(format!("show {}: post it to the project's feed (feed_post), or give the person its path, and read their notes", name(r))),
- }
- }
- }
+ let project = record::up(dir, ".raea/project").unwrap_or_else(|| dir.to_path_buf());
+ let kept = record::read(&project);
+ let secs = |p: &Path| modified(p).duration_since(UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
+ match comps.first() {
+ None => out.push("make the first item: one .tsx whose root registers a Composition (`raea guide craft` first)".into()),
+ Some(c) => match kept.iter().rposition(|e| e.by == "raea render" && e.of == record::rel(&project, c)) {
+ None => out.push(format!("render {}: stills to look at first (`raea render {} --at 0,45,89 -o frames/`), then the video into out/", name(c), name(c))),
+ Some(i) if secs(c) > kept[i].at => out.push(format!("render again: {} changed after its render {}", name(c), kept[i].id)),
+ Some(i) => out.push(after_render(c, &kept, i)),
+ },
}
out.truncate(3);
out
diff --git a/apps/workspace/src/tests.rs b/apps/workspace/src/tests.rs
index 158b139a..97c57464 100644
--- a/apps/workspace/src/tests.rs
+++ b/apps/workspace/src/tests.rs
@@ -47,15 +47,23 @@ fn next_walks_a_project_from_brief_to_show() {
assert!(s[0].starts_with("connect the project's files: 1 thing(s) aren't connected, first card.tsx:1: isn't a composition"), "{s:?}");
std::fs::write(d.join("piece.tsx"), "import { Composition, registerRoot } from \"raea\";\nimport { Card } from \"./card\";\nregisterRoot(() => <Composition id=\"piece\" component={Card} width={1080} height={1920} fps={30} durationInFrames={90} />);\n").unwrap();
assert!(next::steps(&d, &shaped, 0)[0].starts_with("render piece.tsx"), "{:?}", next::steps(&d, &shaped, 0));
+ // the rest is read from the project's record (DR3): what each render and check found
+ use raea_core_facts::{Finding, Level, record::keep};
+ let (piece, video) = (d.join("piece.tsx"), d.join("out/piece.mp4"));
std::fs::create_dir_all(d.join("out")).unwrap();
- std::thread::sleep(std::time::Duration::from_millis(20));
- std::fs::write(d.join("out/piece.mp4"), "").unwrap();
- assert!(next::steps(&d, &shaped, 0)[0].starts_with("check piece.mp4"));
- std::thread::sleep(std::time::Duration::from_millis(20));
- std::fs::write(d.join("out/piece.check.json"), r#"{"findings":[{"check":"clipped","level":"error","says":"text clipped at 2 s","by":"raea check"}]}"#).unwrap();
- assert_eq!(next::steps(&d, &shaped, 0)[0], "polish piece.mp4: clipped: text clipped at 2 s (`raea guide polish`)");
- std::fs::write(d.join("out/piece.check.json"), r#"{"findings":[{"check":"reading","level":"note","says":"minor","by":"raea check"}]}"#).unwrap();
- assert!(next::steps(&d, &shaped, 0)[0].starts_with("show piece.mp4"));
+ std::fs::write(&video, "").unwrap();
+ let clips = Finding::new("clips", Level::Error, "the rider is in the seat", "raea render");
+ keep("raea render", &piece, Some(&video), &[clips], vec![], "20261110-160000").unwrap();
+ assert!(next::steps(&d, &shaped, 0)[0].starts_with("fix piece.tsx: clips: the rider is in the seat (its render 20261110-160000-piece found it"), "{:?}", next::steps(&d, &shaped, 0));
+ keep("raea render", &piece, Some(&video), &[], vec![], "20261110-160001").unwrap();
+ assert!(next::steps(&d, &shaped, 0)[0].starts_with("check out/piece.mp4: `raea check out/piece.mp4 -o out/piece.check.json`"));
+ keep("raea check", &video, None, &[Finding::new("clipped", Level::Error, "text clipped at 2 s", "raea check")], vec![], "20261110-160002").unwrap();
+ assert_eq!(next::steps(&d, &shaped, 0)[0], "polish out/piece.mp4: clipped: text clipped at 2 s (`raea guide polish`)");
+ keep("raea check", &video, None, &[Finding::new("reading", Level::Note, "minor", "raea check")], vec![], "20261110-160003").unwrap();
+ assert!(next::steps(&d, &shaped, 0)[0].starts_with("show out/piece.mp4"));
+ // stills alone: the video next
+ keep("raea render", &piece, Some(&d.join("out")), &[], vec![], "20261110-160004").unwrap();
+ assert_eq!(next::steps(&d, &shaped, 0)[0], "render the video: `raea render piece.tsx -o out/piece.mp4`");
let _ = std::fs::remove_dir_all(&d);
}
diff --git a/core/facts/src/lib.rs b/core/facts/src/lib.rs
index 4b6490c0..31bbf5ad 100644
--- a/core/facts/src/lib.rs
+++ b/core/facts/src/lib.rs
@@ -12,6 +12,9 @@ pub use words::transcript_words;
pub mod finding;
pub use finding::{About, Finding, Level, Measure};
+// the project's record: what each render and check found, kept by render and commit (DR3)
+pub mod record;
+
/// 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/record.rs b/core/facts/src/record.rs
new file mode 100644
index 00000000..239fc89a
--- /dev/null
+++ b/core/facts/src/record.rs
@@ -0,0 +1,153 @@
+//! The project's record (docs/direction.feature DR3): what each render and each `raea check` found, one JSON file
+//! apiece under the project's .raea/record/, with the commit the project was at. `raea findings` reads it back across
+//! renders (what was fixed, what is new, what is carried) and `raea next` reads what stands. A file outside a raea
+//! project (no .raea/project at or above it) has no record.
+
+use std::path::{Path, PathBuf};
+
+use serde::{Deserialize, Serialize};
+
+use crate::Finding;
+
+/// The most entries a project keeps; the oldest go first.
+const KEEP: usize = 500;
+
+/// What `--despite` let through, and why.
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub struct Despite {
+ pub check: String,
+ pub why: String,
+}
+
+/// One render's or check's findings, as the record keeps them.
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub struct Entry {
+ /// its name in the record: when (UTC) and of what, `20261110-161530-edit`
+ pub id: String,
+ /// seconds since 1970, for order
+ pub at: u64,
+ /// "raea render" or "raea check"
+ pub by: String,
+ /// what was rendered (the composition) or checked (the video), relative to the project
+ pub of: String,
+ /// what it wrote, relative to the project when it's in it
+ #[serde(default)]
+ pub out: Option<String>,
+ /// the project's commit, "+" after it when the file it's of has changes not committed (None: no git repository)
+ #[serde(default)]
+ pub commit: Option<String>,
+ pub findings: Vec<Finding>,
+ #[serde(default)]
+ pub despite: Vec<Despite>,
+}
+
+/// The nearest folder at or above `from` that holds `marker` (.raea/workspace, .raea/project).
+pub fn up(from: &Path, marker: &str) -> Option<PathBuf> {
+ let from = from.canonicalize().ok()?;
+ from.ancestors().find(|d| d.join(marker).is_file()).map(Path::to_path_buf)
+}
+
+/// A path made absolute through its nearest folder that exists (an output may not be written yet).
+fn real(p: &Path) -> PathBuf {
+ if let Ok(c) = p.canonicalize() {
+ return c;
+ }
+ match (p.parent().filter(|d| !d.as_os_str().is_empty()), p.file_name()) {
+ (Some(d), Some(n)) => real(d).join(n),
+ _ => std::env::current_dir().map(|c| c.join(p)).unwrap_or_else(|_| p.to_path_buf()),
+ }
+}
+
+/// A path as the record names it: relative to the project when it's in it.
+pub fn rel(project: &Path, p: &Path) -> String {
+ let full = real(p);
+ full.strip_prefix(project).map(|r| r.display().to_string()).unwrap_or_else(|_| full.display().to_string())
+}
+
+/// The project's commit, with "+" when `of` differs from it.
+fn commit(project: &Path, of: &str) -> Option<String> {
+ let git = |a: &[&str]| std::process::Command::new("git").arg("-C").arg(project).args(a).output().ok().filter(|o| o.status.success()).map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string());
+ let head = git(&["rev-parse", "--short", "HEAD"])?;
+ let changed = git(&["status", "--porcelain", "--", of]).is_some_and(|s| !s.is_empty());
+ Some(if changed { format!("{head}+") } else { head })
+}
+
+/// What `by` found of `file` (writing `out`) kept in its project's record, named by `stamp` (UTC, 20261110-161530)
+/// and the file's name: the entry, or None outside a project.
+pub fn keep(by: &str, file: &Path, out: Option<&Path>, findings: &[Finding], despite: Vec<Despite>, stamp: &str) -> Option<Entry> {
+ let project = up(file.parent().unwrap_or(Path::new(".")), ".raea/project")?;
+ let dir = project.join(".raea/record");
+ std::fs::create_dir_all(&dir).ok()?;
+ let at = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
+ let of = rel(&project, file);
+ let base = format!("{stamp}-{}", file.file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_default());
+ let id = (1..100).map(|n| if n == 1 { base.clone() } else { format!("{base}-{n}") }).find(|id| !dir.join(format!("{id}.json")).exists())?;
+ let entry = Entry { id: id.clone(), at, by: by.into(), commit: commit(&project, &of), of, out: out.map(|o| rel(&project, o)), findings: findings.to_vec(), despite };
+ std::fs::write(dir.join(format!("{id}.json")), serde_json::to_vec_pretty(&entry).ok()?).ok()?;
+ // the oldest past KEEP go (the names sort by time)
+ let mut names: Vec<PathBuf> = std::fs::read_dir(&dir).into_iter().flatten().flatten().map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "json")).collect();
+ names.sort();
+ for p in names.iter().take(names.len().saturating_sub(KEEP)) {
+ let _ = std::fs::remove_file(p);
+ }
+ Some(entry)
+}
+
+/// The project's record, oldest first.
+pub fn read(project: &Path) -> Vec<Entry> {
+ let mut v: Vec<Entry> = std::fs::read_dir(project.join(".raea/record")).into_iter().flatten().flatten().filter_map(|e| serde_json::from_slice(&std::fs::read(e.path()).ok()?).ok()).collect();
+ v.sort_by(|a, b| (a.at, &a.id).cmp(&(b.at, &b.id)));
+ v
+}
+
+/// A finding as the same finding in another render: its check and what it is about (its words when it names
+/// nothing), not its frames, which move as the piece is cut.
+pub fn same(f: &Finding) -> String {
+ let about: Vec<&str> = f.about.iter().map(|a| a.key.as_deref().unwrap_or(&a.name)).collect();
+ if about.is_empty() { format!("{} {}", f.check, f.says) } else { format!("{} {}", f.check, about.join(", ")) }
+}
+
+/// Between two entries of one thing: what was fixed (found before, not now), what is new and what is carried.
+pub struct Changes<'a> {
+ pub fixed: Vec<&'a Finding>,
+ pub new: Vec<&'a Finding>,
+ pub carried: Vec<&'a Finding>,
+}
+
+pub fn changes<'a>(before: &'a [Finding], now: &'a [Finding]) -> Changes<'a> {
+ let has = |fs: &[Finding], f: &Finding| fs.iter().any(|g| same(g) == same(f));
+ Changes {
+ fixed: before.iter().filter(|f| !has(now, f)).collect(),
+ new: now.iter().filter(|f| !has(before, f)).collect(),
+ carried: now.iter().filter(|f| has(before, f)).collect(),
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::Level;
+
+ #[test]
+ fn a_render_is_kept_in_its_projects_record_and_compared_with_the_one_before() {
+ let root = std::env::temp_dir().join(format!("raea-record-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&root);
+ std::fs::create_dir_all(root.join(".raea")).unwrap();
+ std::fs::write(root.join(".raea/project"), "").unwrap();
+ std::fs::write(root.join("edit.tsx"), "").unwrap();
+ let clips = Finding::new("clips", Level::Error, "rider in seat", "raea render").about("rider", None).about("seat", None).frames(10, 20);
+ let tilt = Finding::new("tilted", Level::Warn, "vase leans", "raea render").about("vase", None);
+ let a = keep("raea render", &root.join("edit.tsx"), Some(&root.join("out/edit.mp4")), &[clips.clone(), tilt.clone()], vec![], "20261110-160000").unwrap();
+ // the same clip on other frames is the same finding
+ let b = keep("raea render", &root.join("edit.tsx"), None, &[clips.frames(12, 22)], vec![], "20261110-160000").unwrap();
+ assert_eq!((a.id.as_str(), b.id.as_str(), a.of.as_str(), a.out.as_deref()), ("20261110-160000-edit", "20261110-160000-edit-2", "edit.tsx", Some("out/edit.mp4")));
+ let all = read(&root);
+ assert_eq!(all.len(), 2);
+ let ch = changes(&all[0].findings, &all[1].findings);
+ assert_eq!((ch.fixed.len(), ch.new.len(), ch.carried.len()), (1, 0, 1));
+ assert_eq!(ch.fixed[0].check, "tilted");
+ // outside a project, nothing is kept
+ assert!(keep("raea render", &std::env::temp_dir().join("loose.tsx"), None, &[], vec![], "x").is_none());
+ let _ = std::fs::remove_dir_all(&root);
+ }
+}
diff --git a/docs/direction.feature b/docs/direction.feature
index 839330ec..ebd12e1e 100644
--- a/docs/direction.feature
+++ b/docs/direction.feature
@@ -228,7 +228,10 @@ Feature: Direction that holds: one world of facts, findings and rules, so a pers
# Fixed in the code (DR3): the plan gave raea check's Issue -> Finding a file of 150 lines in apps/direction. It is
# six lines in apps/check's report, which writes check.json, and its crate had the room; a second crate would
# have converted raea check's output after the fact instead of raea check writing Findings.
- | raea-app-direction | apps/direction/src/record.rs | 220 | the project's record: findings by render and by commit, read back |
+ | raea-core-facts | core/facts/src/record.rs | 220 | the project's record: findings by render and by commit, read back |
+ # Fixed in the code (DR3): the plan put the record in apps/direction. The render, `raea check` and `raea next`
+ # all write or read it, and apps/direction brings raea-runtime-world with it; core/facts, which each already uses
+ # for Finding, holds it instead, and the registry's `up` (the nearest .raea/project) moved there with it.
| raea-app-direction | apps/direction/src/findings.rs | 160 | `raea findings` |
Then these write Findings and nothing else: the render's clipping check, `raea scene lint|light`, `raea check`
(and --quick, --taste), `raea gen check`, `raea solid info --expect`, `raea project scan`, raea/room's
diff --git a/docs/manual/reference/cli/check.md b/docs/manual/reference/cli/check.md
index 560da036..b59117f5 100644
--- a/docs/manual/reference/cli/check.md
+++ b/docs/manual/reference/cli/check.md
@@ -10,6 +10,8 @@ clipped, cramped, inside the safe areas, large enough to read, and what the stil
That takes about a second, so run it after every save. On an exported video, it measures everything the floor asks
of a finished piece. Each finding is an error, a warn or a note (raea's one finding, as `raea scene lint` and a
render's manifest have it), says on which frames and how to fix it, and the command exits 1 while an error stands.
+A check of a file in a raea project keeps its findings in the project's record (`.raea/record/`), beside its
+renders', which `raea findings` and `raea next` read.
```sh
raea check piece.tsx --quick --platform tiktok
diff --git a/docs/manual/reference/cli/render.md b/docs/manual/reference/cli/render.md
index 85dce7b1..ecc78bf1 100644
--- a/docs/manual/reference/cli/render.md
+++ b/docs/manual/reference/cli/render.md
@@ -35,10 +35,12 @@ to the composition are loaded on their own, as `raea play` loads them; a flag na
A whole video made from the same inputs as an earlier one is copied from the export cache rather than drawn again,
and the command says so.
-A render checks what it draws: 3D parts passing into each other (the clipping check). Each finding is said on stderr
-as it is found, written into the manifest with `--manifest`, and counted on the last line the command prints
-(`raea render: 1 error, 0 warns, 0 notes`). An error makes the render exit 1 once its output is written;
-`--despite CHECK WHY` lets that check's errors through and puts the reason in the manifest.
+A render checks what it draws: 3D parts passing into each other (the clipping check) and its pictures' exposure
+(clipping to white, crushing to black). Each finding is said as it is found, written into the manifest with
+`--manifest`, and counted on the last line the command prints (`raea render: 1 error, 0 warns, 0 notes`). An error
+makes the render exit 1 once its output is written; `--despite CHECK WHY` lets that check's errors through and puts
+the reason in the manifest. A render of a file in a raea project also keeps its findings in the project's record
+(`.raea/record/`, by render and commit), which `raea findings` and `raea next` read.
<!-- generated:begin by tools/manual-ref/cli.ts from `raea help --json`; edit only the flag descriptions -->
diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs
index def54e3e..473f34c8 100644
--- a/engine/cli/src/cli.rs
+++ b/engine/cli/src/cli.rs
@@ -203,6 +203,7 @@ pub fn run(args: &[String]) -> R<String> {
std::process::exit(raea_app_check::cli_with(&args[1..], spec::tastes_ts(args)?));
}
if args[0] == "world" { std::process::exit(raea_app_direction::cli(&args[1..])); } // a frame as one world of facts (docs/direction.feature DR1)
+ if args[0] == "findings" { return raea_app_direction::findings::cli(args); } // the project's record read back (DR3)
if args.first().map(String::as_str) == Some("traces") {
return traces(args);
}
diff --git a/io/trace/src/lib.rs b/io/trace/src/lib.rs
index e5d81bd3..5595c63e 100644
--- a/io/trace/src/lib.rs
+++ b/io/trace/src/lib.rs
@@ -62,7 +62,7 @@ fn root() -> PathBuf {
}
/// UTC as 2026-10-17T23:40:12.345Z (and the folder-safe 20261017-234012).
-fn utc(t: SystemTime) -> (String, String) {
+pub fn utc(t: SystemTime) -> (String, String) {
let d = t.duration_since(UNIX_EPOCH).unwrap_or_default();
let secs = d.as_secs() as i64;
let (days, rem) = (secs.div_euclid(86400), secs.rem_euclid(86400));