Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions apps/check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ struct Taste {
line: String,
}

/// The checks among a person's taste rules (taste.ts and its kinds), each with the line it stands for.
/// The checks among a person's taste rules (taste.ts and its kinds) that a video alone shows (the six forms), each
/// with the line it stands for.
fn taste_rules(tastes: &[raea_core_brief::Taste]) -> Vec<Taste> {
tastes.iter().flat_map(|t| &t.sections).flat_map(|s| &s.rules).filter_map(|r| r.check.map(|c| Taste { form: c.form(), value: c.value(), line: r.text.clone() })).collect()
tastes.iter().flat_map(|t| t.checks()).map(|(line, c)| Taste { form: c.form(), value: c.value(), line: line.to_string() }).collect()
}

fn taste_of<'a>(rules: &'a [Taste], form: &str) -> Option<&'a Taste> {
Expand Down
2 changes: 1 addition & 1 deletion apps/direction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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"
# `raea check PROJECT | EDIT.tsx` (DR4): taste and controllers' rules, the floor on a composition's newest render, the
# `raea check PROJECT | EDIT.tsx` (DR4): the taste files' rules, the floor on a composition's newest render, the
# project's compositions
raea-core-brief = { path = "../../core/brief" }
raea-app-check = { path = "../check" }
Expand Down
41 changes: 16 additions & 25 deletions apps/direction/src/check.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! `raea check PROJECT|EDIT.tsx` (docs/direction.feature DR4): every check that applies, run over each
//! composition's worlds. The rules come from raea's floor, the person's taste (and the workspace's), and the
//! workspace's and the project's controllers; each is one of raea's named checks (systems.rs) or a project's TS check
//! (ts.rs), and where it was written changes nothing about how it runs. A check that needs a render runs on the
//! composition's worlds. The rules come from raea's floor and the taste files: the person's, the workspace's and the
//! project's; each is one of raea's named checks (systems.rs) or a project's TS check (ts.rs), and where it was
//! written changes nothing about how it runs. A check that needs a render runs on the
//! composition's newest render; with none, it waits, and the command says what for. `raea check VIDEO.mp4` is the
//! floor alone (apps/check).

use std::path::{Path, PathBuf};

use raea_core_brief::{controller, taste};
use raea_core_brief::taste;
use raea_core_facts::{finding, record, Facts, Finding, Level, Rule, Shot};
use raea_runtime_bundle::flag;
use raea_runtime_world::{Ask, Render};
Expand All @@ -18,7 +18,7 @@ use crate::ts;

type R<T> = Result<T, String>;

pub const USAGE: &str = "raea check [PROJECT|EDIT.tsx] [--composition ID] [--only ID] [--taste T] [--render OUT | --no-render] [--json] (every check that applies to each composition, over its frames: raea's floor on its newest render, the person's taste, the workspace's and the project's rules (a controller's rule fields: one of raea's checks by name, or a project's .ts check); what needs a render and has none waits, and says so)";
pub const USAGE: &str = "raea check [PROJECT|EDIT.tsx] [--composition ID] [--only ID] [--taste T] [--render OUT | --no-render] [--json] (every check that applies to each composition, over its frames: raea's floor on its newest render, the person's, the workspace's and the project's taste.ts (each line's check: one of raea's forms or checks by name, or a project's .ts check); what needs a render and has none waits, and says so)";

/// The flags raea check takes with a value (its own, and the floor's on a video).
const TAKES: [&str; 10] = ["--composition", "--only", "--taste", "--render", "--manifest", "--words", "--perception", "--shape", "--platform", "-o"];
Expand Down Expand Up @@ -71,7 +71,12 @@ fn tastes(project: &Path, given: Vec<PathBuf>, host: &Host) -> Vec<PathBuf> {
}
}
}
out.extend(record::up(project, ".raea/workspace").map(|ws| ws.join("taste.ts")).filter(|f| f.is_file()));
// the workspace's, then the project's own (the same file when the project is the workspace's folder)
for f in record::up(project, ".raea/workspace").map(|ws| ws.join("taste.ts")).into_iter().chain([project.join("taste.ts")]) {
if f.is_file() && !out.contains(&f) {
out.push(f);
}
}
out
}

Expand All @@ -98,43 +103,29 @@ fn rules(project: &Path, given: Vec<PathBuf>, host: &Host) -> (Vec<Rule>, Vec<Fi
(out, bad, notes)
}

/// raea's floor, the person's taste and the workspace's and project's controllers' rules, and a finding for each file
/// of them raea couldn't read.
/// raea's floor and every taste file's rules (the person's, the workspace's, the project's), and a finding for each
/// file of them raea couldn't read.
fn held(project: &Path, given: Vec<PathBuf>, host: &Host) -> (Vec<Rule>, Vec<Finding>) {
// raea's own: the floor, and the reading check (DR28: its findings keep their own levels, so no rule level)
let read = Rule { level: None, ..Rule::named("text-read", "text can be read for as long as it needs, and OCR reads it", Default::default(), Level::Warn, "raea") };
let mut out = vec![Rule::named("floor", "raea's floor", Default::default(), Level::Error, "raea"), read];
let mut bad = Vec::new();
let name = |f: &Path| f.strip_prefix(project).unwrap_or(f).display().to_string();
for f in tastes(project, given, host) {
let (dir, by) = (f.parent().unwrap_or(Path::new(".")).to_path_buf(), format!("taste {}", name(&f)));
match (host.ts.eval)(&f).and_then(|j| raea_core_brief::read::<taste::Taste>(&name(&f), &j)) {
Ok(t) => out.extend(t.sections.iter().flat_map(|s| &s.rules).filter_map(|r| Some(Rule::of_taste(&r.text, r.check?, &name(&f))))),
Ok(t) => out.extend(t.sections.iter().flat_map(|s| &s.rules).filter_map(|r| Rule::of_taste(r, &dir, &by))),
Err(e) => bad.push(Finding::new("taste", Level::Error, format!("raea can't read it: {e}"), "raea check").about(name(&f), None)),
}
}
let ws = record::up(project, ".raea/workspace");
for (dir, scope) in ws.iter().map(|w| (raea_app_registry::shared_dir(w, "controllers"), "workspace")).chain([(project.join("controllers"), "project")]) {
// a workspace's own folder is its project's too: read once
if scope == "project" && ws.as_deref() == Some(project) {
continue;
}
let mut files: Vec<PathBuf> = std::fs::read_dir(&dir).into_iter().flatten().flatten().map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "ts")).collect();
files.sort();
for f in files {
match (host.ts.eval)(&f).and_then(|j| controller::of_json(&j)) {
Ok(c) => out.extend(Rule::of_controller(&c, &dir, &format!("{scope} {}", name(&f)))),
Err(e) => bad.push(Finding::new("controller", Level::Error, format!("raea can't read it: {e}"), "raea check").about(name(&f), None)),
}
}
}
(out, bad)
}

/// The compositions `target` names: each (its file, its id when the file registers several).
fn compositions(target: &Path, args: &[String]) -> R<Vec<(PathBuf, Option<String>)>> {
let one = flag(args, "--composition");
let (dir, file) = if target.is_dir() { (target.to_path_buf(), None) } else { (target.parent().unwrap_or(Path::new(".")).to_path_buf(), Some(dunce::canonicalize(&target).map_err(|e| format!("{}: {e}", target.display()))?)) };
let reg = raea_app_registry::scan(&dir, &[]);
let reg = raea_app_registry::scan(&dir);
let mut out: Vec<(PathBuf, Option<String>)> = Vec::new();
for c in &reg.compositions {
let path = reg.dir.join(&c.file);
Expand Down
2 changes: 1 addition & 1 deletion apps/direction/src/systems/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn placement_and_margin_name_the_worst_frame_of_a_run() {

#[test]
fn a_rule_with_no_value_says_so() {
let r = Rule { level: Some(Level::Warn), ..Rule::named("text-hold", "", Map::new(), Level::Error, "project controllers/rules.ts") };
let r = Rule { level: Some(Level::Warn), ..Rule::named("text-hold", "", Map::new(), Level::Error, "taste taste.ts") };
let got = text(&r, &piece(3, |_| vec![]));
assert_eq!((got.len(), got[0].level), (1, Level::Warn));
assert!(got[0].says.contains("needs a value"));
Expand Down
2 changes: 1 addition & 1 deletion apps/notes/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn numbered<'a>(project: &Path, notes: &'a [Kept]) -> Vec<(u32, &'a Kept, &'a ra
}

/// The notes' asks that have a check, each as a rule: the ask's id (n3.2) and words, its check (a .ts check's path
/// from the note's folder, as a controller's is from its own), its values, `by` the ask; and each note that can't be
/// from the note's folder, as a taste line's is from its file's), its values, `by` the ask; and each note that can't be
/// read, as a finding.
pub fn rules(project: &Path, notes: &[Kept]) -> (Vec<Rule>, Vec<Finding>) {
let bad = notes.iter().filter_map(|k| k.note.as_ref().err().map(|e| Finding::new("note", Level::Error, format!("raea can't read it: {e}"), "raea notes").about(k.file.display().to_string(), None))).collect();
Expand Down
6 changes: 2 additions & 4 deletions apps/workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ version = "0.1.0"
edition = "2024"
license = "FSL-1.1-ALv2"
publish = false
description = "`raea workspace`, `raea project` and `raea controller`: a workspace's folders, projects and controllers, each change a commit"
description = "`raea workspace` and `raea project`: a workspace's folders and projects, each change a commit"

[dependencies]
dunce = "1"
# the controller schema (core/brief controller.rs): a controller file is checked and normalized against it
raea-core-brief = { path = "../../core/brief" }
raea-io-home = { path = "../../io/home" }
# git, which a workspace is: the PATH's, else on Windows the app's or raea's own (raea_io_assets::git)
raea-io-assets = { path = "../../io/assets" }
serde_json = "1"
# a project's compositions, components and controllers read from their source (docs/projects.feature PJ8)
# a project's compositions and components 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" }
Expand Down
2 changes: 1 addition & 1 deletion apps/workspace/registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024"
license = "FSL-1.1-ALv2"
publish = false
description = "A raea project's compositions, components and controllers, read from their source without running it, and lint for what isn't connected (docs/projects.feature PJ8)"
description = "A raea project's compositions and components, read from their source without running it, and lint for what isn't connected (docs/projects.feature PJ8)"

[dependencies]
dunce = "1"
Expand Down
49 changes: 16 additions & 33 deletions apps/workspace/registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
//! A project's compositions, components and controllers, registered by reading its files (docs/projects.feature PJ8),
//! A project's compositions and components, registered by reading its files (docs/projects.feature PJ8),
//! so the raea app, `raea project scan`, `raea doctor` and `raea next` agree on what each file is:
//! - a composition is each <Composition> a registerRoot registers (its props read from the source, not rendered), or a
//! .tsx's default export with none that no other file imports, registered for it under its file's name (versions
//! NAME-vN.tsx are one composition), sized from its newest render's manifest when it has one;
//! - a component is a .tsx a composition imports, directly or through another;
//! - a controller is a module whose default export is `controller({...})` from "raea/brief".
//! What isn't connected is linted (lint.rs), each with its file and line and the fix. raea-app-workspace wraps `scan`
//! with the project's controller overrides (read from .raea/project's git config) and runs it for `raea project scan`,
//! `raea doctor`, `raea next` and `raea context`.
//! - a component is a .tsx a composition imports, directly or through another.
//! What isn't connected is linted (lint.rs), each with its file and line and the fix. raea-app-workspace runs `scan`
//! for `raea project scan`, `raea doctor`, `raea next` and `raea context`.
use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};

Expand All @@ -22,9 +20,9 @@ pub use read::{Facts, Prop};
/// 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;

/// The workspace's shared folder of one kind (docs/layout.feature: shared/compositions, components, controllers, assets,
/// artifacts), which every project can call on as @shared/<kind>/. A workspace from before shared/ keeps that kind at
/// its root (controllers/, artifacts/) until `raea workspace tidy` moves it, and it's read there meanwhile.
/// The workspace's shared folder of one kind (docs/layout.feature: shared/compositions, components, assets, artifacts),
/// which every project can call on as @shared/<kind>/. A workspace from before shared/ keeps that kind at its root
/// (artifacts/) until `raea workspace tidy` moves it, and it's read there meanwhile.
pub fn shared_dir(ws: &Path, kind: &str) -> PathBuf {
let old = ws.join(kind);
if !ws.join("shared").is_dir() && old.is_dir() {
Expand All @@ -33,7 +31,7 @@ pub fn shared_dir(ws: &Path, kind: &str) -> PathBuf {
ws.join("shared").join(kind)
}

/// A name as a folder: lowercase, dashes. A controller's id from its title is this (core/brief fills it the same way).
/// A name as a folder: lowercase, dashes.
pub fn slug(s: &str) -> String {
let mut out = String::new();
for c in s.trim().to_lowercase().chars() {
Expand Down Expand Up @@ -82,21 +80,13 @@ pub struct Component {
pub used_by: Vec<String>,
}

#[derive(Debug, Clone)]
pub struct Controller {
pub id: Option<String>,
pub file: String,
pub line: usize,
}

#[derive(Debug)]
pub struct Registry {
pub dir: PathBuf,
/// the folder is in a raea project (.raea/project at or above it)
pub project: bool,
pub compositions: Vec<Composition>,
pub components: Vec<Component>,
pub controllers: Vec<Controller>,
pub lint: Vec<Lint>,
}

Expand Down Expand Up @@ -180,9 +170,8 @@ fn manifest(path: &Path) -> Option<Value> {
serde_json::from_str(&std::fs::read_to_string(f).ok()?).ok()
}

/// The folder's registry. `overridden`: the controller ids the project's overrides name, each checked against the
/// controllers there (the folder's and its workspace's controllers/).
pub fn scan(dir: &Path, overridden: &[String]) -> Registry {
/// The folder's registry.
pub fn scan(dir: &Path) -> Registry {
let dir = dunce::canonicalize(dir).unwrap_or_else(|_| dir.to_path_buf());
let project = up(&dir, ".raea/project").is_some();
let mut found = Vec::new();
Expand Down Expand Up @@ -243,10 +232,9 @@ pub fn scan(dir: &Path, overridden: &[String]) -> Registry {
.filter(|f| f.rel.ends_with(".tsx") && !comp_files.contains(f.rel.as_str()) && used_by.contains_key(&f.rel))
.map(|f| Component { file: f.rel.clone(), used_by: used_by[&f.rel].iter().cloned().collect() })
.collect();
let controllers = files.iter().filter_map(|f| f.facts.controller.as_ref().map(|c| Controller { id: c.id.clone(), file: f.rel.clone(), line: c.line })).collect();

let mut reg = Registry { dir, project, compositions, components, controllers, lint: Vec::new() };
reg.lint = lint::lint(&reg, &files, &used_by, overridden);
let mut reg = Registry { dir, project, compositions, components, lint: Vec::new() };
reg.lint = lint::lint(&reg, &files, &used_by);
reg
}

Expand Down Expand Up @@ -280,13 +268,12 @@ impl Registry {
"component": c.component, "width": p(&c.width), "height": p(&c.height), "fps": p(&c.fps), "frames": p(&c.frames),
})).collect::<Vec<_>>(),
"components": self.components.iter().map(|c| json!({ "file": c.file, "usedBy": c.used_by })).collect::<Vec<_>>(),
"controllers": self.controllers.iter().map(|c| json!({ "id": c.id, "file": c.file, "line": c.line })).collect::<Vec<_>>(),
"findings": self.lint.iter().map(Lint::finding).collect::<Vec<_>>(),
})
}

/// For an agent (`raea context`): each composition with its id, file, size, fps and length, the components and
/// controllers, and what isn't connected (its warnings, at most ten; the notes are `raea project scan`'s).
/// For an agent (`raea context`): each composition with its id, file, size, fps and length, the components, and
/// what isn't connected (its warnings, at most ten; the notes are `raea project scan`'s).
pub fn summary(&self) -> String {
let p = |v: &Option<Prop>| match v {
Some(Prop::Num(n)) => format!("{n}"),
Expand All @@ -304,9 +291,6 @@ impl Registry {
if !self.components.is_empty() {
out.push_str(&format!("components: {}\n", self.components.iter().map(|c| c.file.as_str()).collect::<Vec<_>>().join(", ")));
}
if !self.controllers.is_empty() {
out.push_str(&format!("controllers: {}\n", self.controllers.iter().map(|c| format!("{} ({})", c.id.as_deref().unwrap_or("?"), c.file)).collect::<Vec<_>>().join(", ")));
}
let warn: Vec<&Lint> = self.warnings().collect();
if !warn.is_empty() {
out.push_str(&format!("\nnot connected ({}; raea doctor --fix fixes what it can):\n", warn.len()));
Expand All @@ -321,11 +305,10 @@ impl Registry {
/// each about its file:line with the fix, and their count last.
pub fn text(&self) -> String {
let mut out = format!(
"{}: {} compositions, {} components, {} controllers",
"{}: {} compositions, {} components",
self.dir.display(),
self.compositions.len(),
self.components.len(),
self.controllers.len()
self.components.len()
);
for c in &self.compositions {
out.push_str(&format!("\n composition {} ({}:{}{})", c.id, c.file, c.line, if c.how == How::Default { ", its default export" } else { "" }));
Expand Down
Loading
Loading