mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
sdk/guides/craft/components.md (raea guide components): the component-first order of work, what a raea component is (frame-pure, JSON props, its name on what it draws) and the contracts it keeps for time, space, look and sound, who owns what in a composition, where each kind gets made (TSX, solids, sdf/grow, a generator, Blender through a saved script, Godot, Rust rows) and why Godot and Blender are workshops rather than runtimes, materials and shaders as components, a fixture and checks per kind, shadcn's components on screens and panels, and promotion from a project to shared/ to a registry. tools/skills.sh copies it to the skill's root; raea guide lists it; the router, scenes, godot, materials and parts guides link it. docs/components.md: raea's registry as shadcn's format (every item a valid registry-item.json, raea's kinds and assets, contracts, fixture, checks, stills and engine range in meta.raea), components.json namespaces, the theme and story bridges, and the build order CP1-CP10.
167 lines
11 KiB
Rust
167 lines
11 KiB
Rust
use super::*;
|
|
|
|
/// Said above the motion and bevy guides: they're the feed agent's, whose shell has commands of its own
|
|
pub const GUIDE_NOTE: &str = "> These guides are written for the feed's agent. `raea render`, `raea guide NAME` and the other engine commands\n> are the same everywhere; `raea brand`, `cut`, `script`, `frame`, `part` and `still` are the agent shell's own\n> (engine/cli), not yet in the native `raea`.\n\n";
|
|
|
|
/// `raea guide [NAME]` (or `raea craft`, its old name): one craft guide's text, or the list of them, from
|
|
/// raea_io_home::home()'s sdk/guides/craft: the checkout, or an install's share/raea (tools/release.sh ships them).
|
|
/// NAME is `craft` (the floor), `router`, or a guide's path there without .md, found in the folder itself, then modes/,
|
|
/// verbs/ and motion/: `rubric`, `pitch`, `quieter`, `music`, `motion/music`, `bevy`, `bevy/games`, `story/router`.
|
|
/// engine/cli/conformance/surface.test.ts checks every name the agent's context gives against this rule.
|
|
pub fn guide(name: Option<&str>) -> R<String> {
|
|
let craft = raea_io_home::home().join("sdk/guides/craft");
|
|
let listed = |dir: &str| {
|
|
let mut v: Vec<String> = std::fs::read_dir(craft.join(dir)).map(|d| d.flatten().filter_map(|e| e.file_name().to_str()?.strip_suffix(".md").map(str::to_string)).collect()).unwrap_or_default();
|
|
v.sort();
|
|
v
|
|
};
|
|
// the craft system: the floor, read before every edit, and one guide per mode (docs/craft-system.md, D and G)
|
|
let (modes, verbs, names, bevy) = (listed("modes"), listed("verbs"), listed("motion"), listed("bevy"));
|
|
let story: Vec<String> = listed("story").iter().map(|n| format!("story/{n}")).collect();
|
|
if names.is_empty() {
|
|
return Err(format!("no craft guides at {}: reinstall raea (curl -fsSL https://raea.io/install | sh)", craft.display()));
|
|
}
|
|
let bevy: Vec<String> = bevy.iter().map(|n| format!("bevy/{n}")).collect();
|
|
let Some(n) = name.map(|n| n.trim_end_matches(".md")) else {
|
|
return Ok(format!("raea guide NAME prints one.\n\nThe craft (router: the order of work and reading notes; craft right before any edit; a mode's guide when a brief names it):\n router\n craft\n rubric (how a critique is measured, judged and ranked)\n components (anything built as components that fit together: what each owns, where each kind is made, registries)\n {}\n\nWhat a note asks for (read the one a note calls for before acting on it):\n {}\n\nWriting compositions (motion is the overview; read it first):\n motion\n {}\n\n3D and games drawn by Bevy (bevy is the overview; read it first):\n bevy\n {}\n coverage (what of Bevy and Blitz the SDK reaches, type by type)\n\nStories as data, raea/story (story/router first; a page per framework):\n {}\n\n(the files: {})", modes.join("\n "), verbs.join("\n "), names.join("\n "), bevy.join("\n "), story.join("\n "), craft.display()));
|
|
};
|
|
// what of Bevy and Blitz the SDK reaches, type by type: generated by tools/sdk-coverage, shipped beside the guides
|
|
if n == "coverage" {
|
|
let p = raea_io_home::home().join("docs/sdk-coverage.md");
|
|
return std::fs::read_to_string(&p).map_err(|e| format!("{}: {e}", p.display()));
|
|
}
|
|
let file = match n {
|
|
"craft" => "floor",
|
|
"router" => "ROUTER",
|
|
n => n,
|
|
};
|
|
let path = (!file.split('/').any(|p| matches!(p, "" | "." | "..")))
|
|
.then(|| ["", "modes/", "verbs/", "motion/"].iter().map(|d| craft.join(format!("{d}{file}.md"))).find(|p| p.is_file()))
|
|
.flatten()
|
|
.ok_or_else(|| format!("no guide named {n:?}: router, craft, rubric, {}, {}, motion, {}, bevy, {}", modes.join(", "), verbs.join(", "), names.join(", "), bevy.join(", ")))?;
|
|
let text = std::fs::read_to_string(&path).map_err(|e| e.to_string())?;
|
|
let shell = path.starts_with(craft.join("motion")) || path.starts_with(craft.join("bevy")) || matches!(file, "motion" | "bevy");
|
|
Ok(if shell { format!("{GUIDE_NOTE}{text}") } else { text })
|
|
}
|
|
|
|
/// The taste files a mode reads beside taste.ts, which is always read
|
|
pub fn taste_kinds(mode: &str) -> &'static [&'static str] {
|
|
match mode {
|
|
"pitch" | "explain" | "story" => &["motion", "sound"],
|
|
"play" => &["games", "sound"],
|
|
"tool" => &["ui"],
|
|
_ => &[],
|
|
}
|
|
}
|
|
|
|
/// `raea context PROJECT`: everything an agent reads before working on a project, in the order it should be read. That
|
|
/// is the person's taste (~/.raea/taste/taste.ts, then the files its modes need; RAEA_TASTE moves the folder), the
|
|
/// project's brief and the briefs and script it names, its look (the brief's look and brand/brand.css), and the craft
|
|
/// floor and each mode's guide. PROJECT is a folder holding brief.ts, or the file.
|
|
pub fn context(project: Option<&str>) -> R<String> {
|
|
let project = project.ok_or("usage: raea context PROJECT (a folder with brief.ts, or a brief.ts file)")?;
|
|
let brief_path = brief_at(project)?;
|
|
let spec::Loaded { path: brief_path, text: brief, title, modes, more: subs, look, .. } = spec::load_brief_ts(&brief_path)?;
|
|
let dir = brief_path.parent().unwrap_or(Path::new(".")).to_path_buf();
|
|
let taste_dir = raea_app_direction::check::taste_dir();
|
|
// a cheap doctor (file reads and git config): CONTEXT_STALE when this project or the agent's skill is from another raea
|
|
let stale = raea_app_workspace::doctor::findings(&dir, &tools::agent_skills::agents(), &skill::version());
|
|
let stale = match stale.first() {
|
|
Some(f) => format!("CONTEXT_STALE raea doctor finds {} thing(s), first: {} (raea doctor --fix)\n\n", stale.len(), f.says),
|
|
None => String::new(),
|
|
};
|
|
let mut out = format!(
|
|
"{stale}# raea context: {title}\n\nRead all of this before any work on the project, in this order. The person's taste beats every guide's default; the brief\nbeats your own taste. Modes: {}.\n",
|
|
if modes.is_empty() { "none yet (shape the brief first: who it's for, what they should believe, what kind of piece)".to_string() } else { modes.join(", ") }
|
|
);
|
|
context_body(&mut out, &dir, taste_dir, &modes, &brief_path, brief, subs, look);
|
|
Ok(out)
|
|
}
|
|
|
|
/// `raea next [DIR]`: the two or three useful next steps for the project (apps/workspace next.rs).
|
|
pub fn next(args: &[String]) -> R<String> {
|
|
let brief_path = brief_at(args.first().map(String::as_str).unwrap_or("."))?;
|
|
let l = spec::load_brief_ts(&brief_path)?;
|
|
let dir = brief_path.parent().unwrap_or(Path::new(".")).to_path_buf();
|
|
let stale = raea_app_workspace::doctor::findings(&dir, &tools::agent_skills::agents(), &skill::version()).len();
|
|
Ok(raea_app_workspace::next::text(&dir, &raea_app_workspace::next::Brief { needs: l.missing, modes: l.modes }, stale))
|
|
}
|
|
|
|
/// The brief.ts for a folder anywhere inside a project, or the file named.
|
|
fn brief_at(project: &str) -> R<PathBuf> {
|
|
let path = Path::new(project);
|
|
let brief_path = if path.is_dir() {
|
|
// from anywhere inside a project: the nearest folder up with a brief.ts or a .raea/project
|
|
let dir = dunce::canonicalize(&path).ok().and_then(|d| d.ancestors().find(|a| a.join("brief.ts").is_file() || a.join(".raea/project").is_file()).map(Path::to_path_buf));
|
|
dir.unwrap_or_else(|| path.to_path_buf()).join("brief.ts")
|
|
} else {
|
|
path.to_path_buf()
|
|
};
|
|
if !brief_path.is_file() {
|
|
return Err(format!("no brief at {}: a project starts as brief.ts (`export default brief({{ title: ... }})` from \"raea/brief\")", brief_path.display()));
|
|
}
|
|
Ok(brief_path)
|
|
}
|
|
|
|
/// The sections of `raea context` after its head, in reading order.
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn context_body(out: &mut String, dir: &Path, taste_dir: Option<PathBuf>, modes: &[String], brief_path: &Path, brief: String, subs: Vec<(PathBuf, String)>, look: Option<String>) {
|
|
let mut section = |name: String, body: String| out.push_str(&format!("\n\n===== {name} =====\n\n{}\n", body.trim_end()));
|
|
// the person's taste: always taste.ts, then each kind its modes need, once
|
|
match taste_dir.as_deref().and_then(|t| spec::taste_file(t, "taste").map(|f| (t, f))) {
|
|
Some((t, (p, text))) => {
|
|
section(format!("TASTE {}", p.display()), text);
|
|
let mut kinds: Vec<&str> = Vec::new();
|
|
for m in modes {
|
|
for k in taste_kinds(m) {
|
|
if !kinds.contains(k) {
|
|
kinds.push(k);
|
|
}
|
|
}
|
|
}
|
|
for k in kinds {
|
|
if let Some((p, text)) = spec::taste_file(t, k) {
|
|
section(format!("TASTE {}", p.display()), text);
|
|
}
|
|
}
|
|
}
|
|
None => section("TASTE".into(), "(no taste yet: ~/.raea/taste/taste.ts holds the person's standing corrections)".into()),
|
|
}
|
|
// the workspace's house rules, which every project in it follows (docs/projects.feature)
|
|
if let Some((p, text)) = raea_app_workspace::up(&dir, ".raea/workspace").and_then(|ws| spec::taste_file(&ws, "taste")) {
|
|
section(format!("WORKSPACE TASTE {}", p.display()), text);
|
|
}
|
|
// the project's own rules, which raea check holds beside the person's and the workspace's (DR4)
|
|
if raea_app_workspace::up(dir, ".raea/workspace").as_deref() != Some(dir)
|
|
&& let Some((p, text)) = spec::taste_file(dir, "taste")
|
|
{
|
|
section(format!("PROJECT TASTE {}", p.display()), text);
|
|
}
|
|
// the project's compositions and components as raea reads them (docs/projects.feature PJ8)
|
|
for (name, text) in raea_app_workspace::context(dir) {
|
|
section(name, text);
|
|
}
|
|
section(format!("BRIEF {}", brief_path.display()), brief.clone());
|
|
for (p, t) in &subs {
|
|
section(format!("{} {}", if p.to_string_lossy().contains("script") { "SCRIPT" } else { "BRIEF" }, p.display()), t.clone());
|
|
}
|
|
// the look: the brief's own section, and the brand's tokens when the project has them
|
|
let mut look = look.unwrap_or_else(|| "(the brief has no look yet)".into());
|
|
if let Ok(css) = std::fs::read_to_string(dir.join("brand/brand.css")) {
|
|
look.push_str(&format!("\n\nbrand/brand.css:\n{css}"));
|
|
}
|
|
section("LOOK".into(), look);
|
|
// the floor, then each mode's guide (sdk/guides/craft/modes/MODE.md)
|
|
let craft = raea_io_home::home().join("sdk/guides/craft");
|
|
if let Ok(t) = std::fs::read_to_string(craft.join("floor.md")) {
|
|
section(format!("GUIDE craft floor ({})", craft.join("floor.md").display()), t);
|
|
}
|
|
for m in modes {
|
|
let p = craft.join("modes").join(format!("{m}.md"));
|
|
match std::fs::read_to_string(&p) {
|
|
Ok(t) => section(format!("GUIDE mode {m} ({})", p.display()), t),
|
|
Err(_) => section(format!("GUIDE mode {m}"), format!("(raea has no guide for the mode {m:?} yet)")),
|
|
}
|
|
}
|
|
}
|