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.

Plugins a person installs: compositions import them after the project's own packages (engine/bundle edit.rs: RAEA_PLUGINS, else ~/.raea/plugins), and docs/ecosystem.feature records phase 2's start (the manifest, per-person installs, approval, permissions, a network allowlist; tools, panels and item types) and the two answered questions

shinyobjectz8b9419077892
diff --git a/docs/ecosystem.feature b/docs/ecosystem.feature
index 894d1945..b5d2a2a5 100644
--- a/docs/ecosystem.feature
+++ b/docs/ecosystem.feature
@@ -2,8 +2,9 @@
Feature: raea's plugin ecosystem: extending the engine and the app, made, shared and installed the same way
Shane, 11-09: "write a plan for this, that fully charts out what a plugin ecosystem looks like both for the engine
itself and the app". This is that plan: what exists, the one package format both sides share, the engine's three
- tiers, the app's extension host, and the order to build it in. Built so far: what "What exists" names, and phase
- 1 (EC12). The Bevy plugin catalog's own work stays in docs/plugins.feature.
+ tiers, the app's extension host, and the order to build it in. Built so far: what "What exists" names, phase
+ 1 (EC12), and the first of phase 2: the manifest, installing per person, and tools, panels and item types
+ (EC12). The Bevy plugin catalog's own work stays in docs/plugins.feature.
What exists (11-09):
- The engine is extended through its SDK. TypeScript (components, parts, systems on BevyApp, npm packages through
@@ -49,24 +50,30 @@ Feature: raea's plugin ecosystem: extending the engine and the app, made, shared
Given a package.json whose "raea" key says what the package adds:
"""
"raea": {
- "raea": ">=0.1.0 <0.3",
- "engine": { "exports": "./src/index.ts", "shaders": "./shaders", "plugins": { "hanabi": { ... } } },
- "app": { "entry": "./app/index.tsx", "contributes": { "tools": [...], "itemTypes": [...], "panels": [...] } },
- "permissions": ["feed.read", "comments.write", "net:api.example.com"]
+ "title": "Film grain",
+ "raea": ">=0.1.0",
+ "engine": { "imports": ["@you/raea-grain"] },
+ "app": {
+ "contributes": [{ "point": "tool", "id": "measure", "title": "Measure", "entry": "./app/Measure.tsx" }],
+ "permissions": ["items:read", "comments:write", "notify"],
+ "network": ["api.example.com"]
+ }
}
"""
- Then `raea add NAME` installs it into a project (raea.lock, node_modules), and `raea add --global NAME` into
- ~/.raea for every project, as `raea add` does for npm packages now
+ Then the app's Plugins page installs it for the person, in every project (Shane 11-09: per person), into
+ ~/.raea/plugins (RAEA_PLUGINS) from an npm name, a Git URL or a folder, with npm's install scripts off; a
+ composition imports its packages by name, resolved after the project's own (engine/bundle edit.rs)
+ And (not built) `raea add --global NAME` does the same from the CLI
And a package can be engine only, app only, or both (a particle editor: the components and the panel that
tunes them)
And the "raea" range is checked at install and at load: a package made for another raea is refused with the
version it wants and the one it found, never loaded and left to fail
Scenario: EC2. Installed packages are visible and reversible
- Then the Plugins page lists installed packages beside the integrations, by project and global, each with what it
- adds, its permissions, its version and its source
- And each can be turned off per project without uninstalling, and removed, and either leaves no trace in the
- project's files beyond raea.lock
+ Then the Plugins page lists installed packages beside the integrations, each with what it adds, its permissions,
+ the hosts it may reach, its version and its source
+ And a package installs off: none of its code runs until the person has read that and pressed Approve
+ And each can be turned off without uninstalling, and removed, and neither touches a project's files
Rule: The engine: three tiers, by how they load
@@ -171,11 +178,26 @@ Feature: raea's plugin ecosystem: extending the engine and the app, made, shared
tools/raea-app/artifact.sh), raea-skills #14 (SKILL.md §5, feed.md). Tests: host/artifact.test.ts and
src/artifacts/protocol.test.ts; smoke "an agent posts its own React file as an artifact" passes in Chrome (dev and
the built page) and on the Blitz window (blitz/pw-run.mjs). Not yet run in a full signed raea.app build.)
+ (11-09, phase 2 begun, Shane: "can we have the plugins in the app allow for you to install a custom plugin":
+ plugins for the engine and the app, from npm, Git or a folder, per person, network only to named hosts. Built:
+ the manifest (apps/app src/plugins/manifest.ts, EC1); install, approve, turn off, remove (host/packages.ts, the
+ Plugins page's Installed section, EC2), npm with --ignore-scripts; compositions import a person's plugins after
+ the project's own packages (engine/bundle edit.rs, EC3); three of EC7's points, the detail tool, a panel beside
+ the feed, and an item type agents post with feed_post type "plugin"; each a .tsx run in the artifact's frame
+ with permissions checked per call (items:read, comments:write, notify) and a network allowlist (EC6); a folder
+ plugin reloads as its author saves (EC8 without the CLI verb). raea-feed 6e65cf8. Tests: manifest.test.ts,
+ host/packages.test.ts (a Git install whose postinstall doesn't run), protocol.test.ts, engine/bundle
+ bundles_a_composition_with_the_persons_plugins, and smoke "a person installs a plugin from a folder" in Chrome
+ (dev and built), on the Blitz window, and an esbuild host.mjs run with raea.app's environment. Not built: `raea
+ add`, `raea app dev|check|bundle`, the raea range checked at load, rail tabs, commands, agent tools, settings,
+ the index (EC10, EC11), a native plugin outside the catalog (EC5). On the Blitz window the frame's network is
+ held by the wrapped calls alone, as Blitz has no CSP.)
Rule: Open questions for Shane
Scenario: EC13. Decisions this plan needs
- Then may an extension reach the network, and if so only to the domains its manifest names?
+ Then an extension reaches only the hosts its manifest names (Shane 11-09: answered; the frame's CSP and its
+ wrapped fetch, XHR, WebSocket, EventSource and sendBeacon hold it to them)
And may an extension restyle the app itself (a theme), or only draw inside its own frames?
- And are packages installed per project by default (they travel with the repo) or per person?
+ And packages install per person, in every project (Shane 11-09: answered)
And will packages ever be sold through raea, or stay free with raea taking no part?
diff --git a/engine/bundle/src/edit.rs b/engine/bundle/src/edit.rs
index 18ab4572..ecaca4a7 100644
--- a/engine/bundle/src/edit.rs
+++ b/engine/bundle/src/edit.rs
@@ -3,6 +3,9 @@
//! had installed. A bare import from the edit's sources resolves from the edit's own folder first (its node_modules,
//! then its parents', as Node and Vite would), then the engine's; the packages the engine carries (react, mediabunny,
//! bevy-react...) resolve to its copies from any package, so a bundle has one React however the edit installed its own.
+//! A package the edit's folders don't have resolves from the person's plugins last (~/.raea/plugins, RAEA_PLUGINS:
+//! what the raea app's Plugins page installs for every project, docs/ecosystem.feature EC1), so a component a person
+//! installed once imports in any composition.
use rolldown_plugin::{HookResolveIdArgs, HookResolveIdOutput, HookResolveIdReturn, HookUsage, Plugin, PluginContext, PluginContextResolveOptions};
use std::borrow::Cow;
use std::path::{Path, PathBuf};
@@ -82,6 +85,11 @@ mod tests {
}
}
+/// The person's plugins (the raea app's Plugins page installs them here with npm): RAEA_PLUGINS, else ~/.raea/plugins.
+pub fn plugins() -> PathBuf {
+ raea_io_home::env_path("RAEA_PLUGINS", ".raea/plugins")
+}
+
/// `spec` resolved by Rolldown's resolver as if imported from a file in `dir`
async fn resolve_from(ctx: &PluginContext, spec: &str, dir: &Path) -> anyhow::Result<Option<HookResolveIdOutput>> {
let importer = dir.join("_raea.js");
@@ -131,7 +139,10 @@ impl Plugin for EditResolve {
// the edit's sources: the engine's copy by the work folder's own resolution (its tsconfig paths point a live
// bundle's react at the live runtime)
(true, true) => Ok(None),
- (true, false) => resolve_from(ctx, spec, &e.dir).await,
+ (true, false) => match resolve_from(ctx, spec, &e.dir).await? {
+ Some(r) => Ok(Some(r)),
+ None => resolve_from(ctx, spec, &plugins()).await,
+ },
// a package (the edit's or the engine's) importing one the engine carries: the engine's
(false, true) => resolve_from(ctx, spec, &e.js).await,
(false, false) => Ok(None),
diff --git a/engine/bundle/tests/bundle.rs b/engine/bundle/tests/bundle.rs
index 82e787d1..8180c74c 100644
--- a/engine/bundle/tests/bundle.rs
+++ b/engine/bundle/tests/bundle.rs
@@ -177,3 +177,35 @@ fn bundles_a_composition_with_the_edits_packages() {
assert!(!before.js.contains("EDIT_ANIM"), "anim/react only resolves from the edit's folder");
let _ = std::fs::remove_dir_all(&d);
}
+
+/// A package the edit's folders don't have resolves from the person's plugins (RAEA_PLUGINS, ~/.raea/plugins: what the
+/// raea app's Plugins page installs), after the edit's own: an edit that installed the same package keeps its copy.
+#[test]
+fn bundles_a_composition_with_the_persons_plugins() {
+ let d = std::env::temp_dir().join(format!("raea-bundle-plugins-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&d);
+ let w = |p: &str, s: &str| {
+ let f = d.join(p);
+ std::fs::create_dir_all(f.parent().unwrap()).unwrap();
+ std::fs::write(f, s).unwrap();
+ };
+ w("js/node_modules/react/package.json", r#"{ "name": "react", "main": "index.js" }"#);
+ w("js/node_modules/react/index.js", "export const version = 'ENGINE_REACT';\n");
+ w("plugins/node_modules/grain/package.json", r#"{ "name": "grain", "main": "index.js", "raea": {} }"#);
+ w("plugins/node_modules/grain/index.js", "import { version } from 'react';\nexport const grain = 'PLUGIN_GRAIN with ' + version;\n");
+ w("plugins/node_modules/both/package.json", r#"{ "name": "both", "main": "index.js" }"#);
+ w("plugins/node_modules/both/index.js", "export const both = 'PLUGIN_BOTH';\n");
+ w("edit/node_modules/both/package.json", r#"{ "name": "both", "main": "index.js" }"#);
+ w("edit/node_modules/both/index.js", "export const both = 'EDIT_BOTH';\n");
+ w("work/src/edit.tsx", "import { grain } from 'grain';\nimport { both } from 'both';\n(globalThis as any).out = [grain, both];\n");
+ w("work/entry.ts", "import './src/edit.tsx';\n");
+ #[cfg(unix)]
+ std::os::unix::fs::symlink(d.join("js/node_modules"), d.join("work/node_modules")).unwrap();
+ // SAFETY: only this test reads RAEA_PLUGINS
+ unsafe { std::env::set_var("RAEA_PLUGINS", d.join("plugins")) };
+ let edit = raea_bundle::edit::Edit { dir: d.join("edit"), js: d.join("js"), work: d.join("work") };
+ let b = raea_bundle::bundle_with(&d.join("work/entry.ts"), raea_bundle::Options { edit: Some(edit), ..Default::default() }).expect("bundles");
+ assert!(b.js.contains("PLUGIN_GRAIN with ") && b.js.contains("ENGINE_REACT"), "the plugin's package, the engine's React: {}", b.js);
+ assert!(b.js.contains("EDIT_BOTH") && !b.js.contains("PLUGIN_BOTH"), "the edit's own copy first");
+ let _ = std::fs::remove_dir_all(&d);
+}