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.

raea show posts quietly, and asks everything in one item with previews

shinyobjectzb30ef6adca8d
diff --git a/docs/manual/reference/cli/show.md b/docs/manual/reference/cli/show.md
index 045539f1..3863a9b3 100644
--- a/docs/manual/reference/cli/show.md
+++ b/docs/manual/reference/cli/show.md
@@ -6,10 +6,13 @@ sources: ["engine/cli/src/show.ts"]
---
`raea show` is how an agent working outside the app, in a terminal session such as Claude Code or Codex, shows the
-person its work. It posts the files to the project's feed in the raea app and brings the window up on the new item:
-stills become a look (several, a storyboard), a video a watch, a sound a listen, a `NAME.script.ts` or `.md` a read,
-and a `.tsx` an interactive artifact (one of the project's compositions opens in its editor). `--question` asks,
-with words or stills to pick from. It starts the app if it's installed and not running.
+person its work. It posts the files to the project's feed in the raea app: stills become a look (several, a
+storyboard), a video a watch, a sound a listen, a `NAME.script.ts` or `.md` a read, and a `.tsx` an interactive
+artifact (one of the project's compositions opens in its editor). The post is quiet: the app shows a notice and
+leaves the person where they are, and `--open` brings the window up on the new item instead. `--question` asks,
+with words or stills to pick from; several `--question`s go out as one item, and a `--preview` after a question or
+a choice gives the person something to play or read while they answer. It starts the app if it's installed and not
+running.
What the person sends back (an answer, a comment, a pick) arrives as JSON lines in the session's inbox file, which
the command prints. Without the app on this Mac, the files open in the Mac's own viewer and it says nothing was
@@ -24,6 +27,8 @@ or, with files and `--replaces`, settled by that version. Done stays in view, ch
raea show out/look-1.png out/look-2.png out/look-3.png --ask "Which of these three?"
raea show out/cut.mp4 --replaces i-show-2f9c
raea show --question "Warmer or cooler grade?" --choice Warmer --choice Cooler
+raea show --question "Which opening?" --choice Slam --preview out/slam.mp4 --choice Drift --preview out/drift.mp4 \
+ --question "Narrator speed?" --preview voice/take.mp3 --choice "As is" --choice Faster
raea show --on i-show-2f9c --working c-3 --sub "grade pass"
raea show out/cut-v2.mp4 --replaces i-show-2f9c --done c-3 --done c-4 --note "Warmer grade, title held a beat longer"
```
@@ -33,7 +38,7 @@ raea show out/cut-v2.mp4 --replaces i-show-2f9c --done c-3 --done c-4 --note "Wa
## Usage
```sh
-raea show FILE... [--title T] [--ask LINE] [--project P] [--replaces ITEM] [--as NAME] [--role ROLE] [--inbox NAME] | raea show --question Q --choice A --choice B [STILL...] | raea show --on ITEM [--working ID] [--done ID] [--note LINE] [--sub NAME] (shown in the raea app as an item the person can use and answer, the window brought up on it: stills (several, a storyboard), a video, a sound, a NAME.script.ts or .md, a .tsx (an interactive artifact; a project's composition opens in its editor), or a question; what they send comes to ~/.raea/inbox/INBOX.jsonl; their edit comments are tasks: --working ID as you start one, --done ID when it's settled, or with the version that settles it, FILE --replaces ITEM --done ID; never open media in Preview while the app is installed)
+raea show FILE... [--title T] [--ask LINE] [--project P] [--replaces ITEM] [--as NAME] [--role ROLE] [--inbox NAME] [--open] | raea show --question Q --choice A --choice B [STILL...] | raea show [--title T] --question Q [--preview FILE] --choice A [--preview FILE] --choice B ... [--question Q2] ... | raea show --on ITEM [--working ID] [--done ID] [--note LINE] [--sub NAME] (shown in the raea app as an item the person can use and answer, posted quietly with a notice, the window left where they are unless --open: stills (several, a storyboard), a video, a sound, a NAME.script.ts or .md, a .tsx (an interactive artifact; a project's composition opens in its editor), or questions, all of them one item, each question and choice with a --preview to play or read while answering (a still, a video, a sound, a script or .md; after a --choice that choice's, else the question's); what they send comes to ~/.raea/inbox/INBOX.jsonl; their edit comments are tasks: --working ID as you start one, --done ID when it's settled, or with the version that settles it, FILE --replaces ITEM --done ID; never open media in Preview while the app is installed)
```
Needs the raea app's host running on this machine; then waits for a person's click in the raea app (to answer). Takes any number of arguments besides its flags.
@@ -49,6 +54,8 @@ Needs the raea app's host running on this machine; then waits for a person's cli
| `--inbox` | `NAME` | The inbox the answers go to, `~/.raea/inbox/NAME.jsonl` (one per session when left out). |
| `--note` | `LINE` | With `--done`: a line for the person on what settled it, shown under the comment. |
| `--on` | `ITEM` | The item whose edit comments `--working` and `--done` mark; nothing is shown. |
+| `--open` | – | Brings the window up on the new item. Without it the item is posted quietly with a notice, and the person stays where they are. |
+| `--preview` | `FILE` | A still, video, sound, script or `.md` the person can play or read while answering. After a `--choice` it is that choice's preview, otherwise the question's. |
| `--project` | `P` | The project to post to: its id, title or `Workspace/project`. The project this folder is in when left out. |
| `--question` | `Q` | Ask the person this, with `--choice` answers or stills to pick from. |
| `--replaces` | `ITEM` | The item this is the next version of, so the feed shows it as that item's new version. |
diff --git a/engine/cli/src/app.ts b/engine/cli/src/app.ts
new file mode 100644
index 00000000..51f79974
--- /dev/null
+++ b/engine/cli/src/app.ts
@@ -0,0 +1,115 @@
+// The raea app's host, as the native `raea` reaches it (native.ts): where the running app listens, and the verbs that
+// post to it: `raea show` (and its --on tasks), `raea library`, and the agent harness a show names as its poster.
+import { spawnSync } from "node:child_process";
+import { existsSync, readFileSync } from "node:fs";
+import { homedir } from "node:os";
+import { basename } from "node:path";
+import { HARNESSES } from "./show";
+
+/** The running raea app's host: RAEA_FEED_HOST for an agent the app started, else the address the installed app leaves
+ * in ~/.raea/app-host.json while it runs (apps/app host/host-file.ts), if its process is still there. */
+function appHost(): string | null {
+ if (process.env.RAEA_FEED_HOST) return process.env.RAEA_FEED_HOST;
+ const file = process.env.RAEA_HOST_FILE || `${homedir()}/.raea/app-host.json`;
+ try {
+ const h = JSON.parse(readFileSync(file, "utf8")) as { url?: string; pid?: number };
+ if (h.url && h.pid && spawnSync("kill", ["-0", String(h.pid)]).status === 0) return h.url;
+ } catch {
+ // no app running, or a file left by one that stopped
+ }
+ return null;
+}
+
+/** POST a host route of the raea app at `at`, answering its JSON; its refusal is thrown as it says it. */
+function postHost(at: string, route: string, a: Record<string, unknown>): any {
+ const r = spawnSync("curl", ["-sS", "--max-time", "120", "-w", "\n%{http_code}", "-H", "content-type: application/json", "--data-binary", "@-", `${at.replace(/\/$/, "")}${route}`], { input: JSON.stringify(a), encoding: "utf8", maxBuffer: 64 << 20 });
+ const text = r.stdout ?? "";
+ const cut = text.lastIndexOf("\n");
+ const [body, code] = [text.slice(0, cut), Number(text.slice(cut + 1))];
+ if (r.status !== 0) throw new Error(`the raea app at ${at} didn't answer: ${(r.stderr ?? "").trim()}`);
+ if (!(code >= 200 && code < 300)) throw Object.assign(new Error(body.trim() || `the raea app said ${code}`), { code });
+ return JSON.parse(body);
+}
+
+/** `raea show` (show.ts): the item made by the raea app's host (apps/app host/show.ts), the app started first when it's
+ * installed and not running. The window is brought up on it by its raea:// link only with --open or when the app was
+ * just started; otherwise the page finds it and says so. Without the app, the files open in the Mac's own viewer. */
+export function show(a: Record<string, unknown>): unknown {
+ let at = appHost();
+ let launched = false;
+ if (!at) {
+ const app = [process.env.RAEA_APP, "/Applications/raea.app", `${homedir()}/Applications/raea.app`].find((p) => p && existsSync(p));
+ const files = (a.files as string[]) ?? [];
+ if (!app) {
+ if (a.question || a.questions) throw new Error("a question needs the raea app, and it isn't on this Mac (raea.io)");
+ spawnSync("open", files);
+ return { opened: files };
+ }
+ if (spawnSync("pgrep", ["-f", `${app}/Contents/MacOS/raea-window`]).status === 0)
+ throw new Error("the raea app running here is older than raea show (it leaves no ~/.raea/app-host.json); quit it and open it again to update, then show it again");
+ spawnSync("open", ["-a", app]);
+ launched = true;
+ // the window's host writes its address once it listens: a minute at most, in quarter seconds
+ for (let i = 0; i < 240 && !(at = appHost()); i++) spawnSync("/bin/sleep", ["0.25"]);
+ if (!at) throw new Error(`the raea app didn't start (no ~/.raea/app-host.json after a minute); open ${app} and show it again`);
+ }
+ let shown: { url: string };
+ try {
+ shown = postHost(at, "/host/show", a);
+ } catch (e) {
+ // the host's refusal names the verb, as the shell's report does too
+ throw new Error(String((e as Error).message).replace(/^raea show: /, ""));
+ }
+ // the window comes up on it only when asked (--open) or when it was just started for it: a post otherwise lands
+ // quietly, the page saying so in a notice (Shane 11-10: "any time you make an update to the feed it takes me out of
+ // the thing im currently doing"); RAEA_NO_OPEN: a test's, which mustn't bring up the person's window
+ // an app from before quiet posts (no /host/shown) never finds an item it isn't sent to: there it comes up, as before
+ const finds = (() => {
+ try {
+ postHost(at!, "/host/shown", {});
+ return true;
+ } catch {
+ return false;
+ }
+ })();
+ const brought = !process.env.RAEA_NO_OPEN && (a.open === true || launched || !finds);
+ if (brought) spawnSync("open", [shown.url]);
+ return { ...shown, brought };
+}
+
+/** The agent harness that started this command (show.ts HARNESSES), found up its parent processes: a program's own
+ * name, or the script a runtime runs (`node .../gemini`). Nothing when no harness is up there. */
+export function harness(): { name: string; pid: number } | undefined {
+ let pid = process.ppid;
+ for (let i = 0; i < 16 && pid > 1; i++) {
+ const m = /^\s*(\d+)\s+(.*)$/.exec(spawnSync("ps", ["-o", "ppid=,args=", "-p", String(pid)], { encoding: "utf8" }).stdout ?? "");
+ if (!m) return undefined;
+ for (const w of m[2].split(/\s+/).slice(0, 2).map((w) => basename(w).toLowerCase())) {
+ const hit = HARNESSES.find(([re]) => re.test(w));
+ if (hit) return { name: hit[1], pid };
+ }
+ pid = Number(m[1]);
+ }
+ return undefined;
+}
+
+/** `raea show --on ITEM --working ID` and `--done ID` (show.ts): the person's comments marked on their item by the raea
+ * app's host (apps/app host/tasks.ts), which the window shows as who's on each and which are done. */
+export function task(a: Record<string, unknown>): unknown {
+ const at = appHost();
+ if (!at) throw new Error("the raea app isn't running here: open it, then mark the comments again");
+ try {
+ return postHost(at, "/host/task", a);
+ } catch (e) {
+ const old = (e as { code?: number }).code === 404 && !/^raea show: /.test((e as Error).message); // an app from before --on: its host's bare "not found"
+ throw new Error(old ? "the raea app running here is older than raea show --on; quit it and open it again to update, then mark the comments again" : String((e as Error).message).replace(/^raea show: /, ""));
+ }
+}
+
+/** An op of the feed host's libraries (apps/app host/library/service.ts): POST <the app's host>/host/library. */
+export function library(a: Record<string, unknown>): unknown {
+ const at = appHost();
+ if (!at) throw new Error("libraries live in the raea app: open it on this Mac (or set RAEA_FEED_HOST to its address)");
+ return postHost(at, "/host/library", a);
+}
+
diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs
index 6f4d056d..4c026fa8 100644
--- a/engine/cli/src/cli.rs
+++ b/engine/cli/src/cli.rs
@@ -127,7 +127,7 @@ pub fn run(args: &[String]) -> R<String> {
IN_HELP.set(was);
// `raea library` (engine/cli/src/library.ts) and `raea show` (show.ts: in the raea app, not Preview, Shane 11-09), under render's usage
let usage = format!("{usage}\n raea library [new NAME [--cloud] | add LIBRARY PATH | files LIBRARY | tag SHA TAGS | status | scan ...] | raea library search \"WORDS\" [--library LIBRARY] [--kind KIND] [--limit N] [--sound] (the person's libraries in the raea app: folders and drives indexed on this machine, searched by meaning; a folder an agent adds waits for the person's yes)");
- let usage = format!("{usage}\n raea show FILE... [--title T] [--ask LINE] [--project P] [--replaces ITEM] [--as NAME] [--role ROLE] [--inbox NAME] | raea show --question Q --choice A --choice B [STILL...] | raea show --on ITEM [--working ID] [--done ID] [--note LINE] [--sub NAME] (shown in the raea app as an item the person can use and answer, the window brought up on it: stills (several, a storyboard), a video, a sound, a NAME.script.ts or .md, a .tsx (an interactive artifact; a project's composition opens in its editor), or a question; what they send comes to ~/.raea/inbox/INBOX.jsonl; their edit comments are tasks: --working ID as you start one, --done ID when it's settled, or with the version that settles it, FILE --replaces ITEM --done ID; never open media in Preview while the app is installed)");
+ let usage = format!("{usage}\n raea show FILE... [--title T] [--ask LINE] [--project P] [--replaces ITEM] [--as NAME] [--role ROLE] [--inbox NAME] [--open] | raea show --question Q --choice A --choice B [STILL...] | raea show [--title T] --question Q [--preview FILE] --choice A [--preview FILE] --choice B ... [--question Q2] ... | raea show --on ITEM [--working ID] [--done ID] [--note LINE] [--sub NAME] (shown in the raea app as an item the person can use and answer, posted quietly with a notice, the window left where they are unless --open: stills (several, a storyboard), a video, a sound, a NAME.script.ts or .md, a .tsx (an interactive artifact; a project's composition opens in its editor), or questions, all of them one item, each question and choice with a --preview to play or read while answering (a still, a video, a sound, a script or .md; after a --choice that choice's, else the question's); what they send comes to ~/.raea/inbox/INBOX.jsonl; their edit comments are tasks: --working ID as you start one, --done ID when it's settled, or with the version that settles it, FILE --replaces ITEM --done ID; never open media in Preview while the app is installed)");
// a workspace's files and specs (docs/projects.feature), listed under render's usage like library
let usage = format!("{usage}\n raea spec FILE.ts [--as brief|script|taste|plan|controller] (a spec's default export as JSON, checked against its schema: brief.ts, script.ts, taste.ts, plan.ts, controllers/ID.ts)\n raea workspace init [NAME] [--layout LAYOUT] | raea workspace adopt DIR [--name NAME] | raea workspace [--json] (a workspace: a git repo of projects and controllers under raea.root, ~/Studio unless git config says)\n raea project new NAME [--storage inline|submodule] | raea project split NAME [--remote URL] | raea project join NAME | raea project [--json] (a project in the workspace: its folder, brief.ts, media/, out/; split and join keep its history)\n raea controller ls [--json] | raea controller get PATH [--json] | raea controller set PATH VALUE [--project] [--by NAME] | raea controller write FILE.ts [--by NAME] | raea controller rm ID [--by NAME] (the workspace's controllers, controllers/ID.ts; PATH is controller.group.field; every change a commit)\n raea check EDIT.tsx --quick [--shape S] [--platform P] [--taste T] [-o check.json] (three stills of a composition checked for text: clipped, cramped, safe areas, sizes; about a second)\n raea hook [claude|codex|gemini|kimi] (every agent's tool hooks, which raea skills install adds: before a shell command, media opened in the Mac's viewer while the raea app is installed is stopped once for raea show (the same command again goes through); after a save, the quick check on a composition)\n raea next [DIR] (the two or three useful next steps for the project, from its brief, compositions, renders and checks)\n raea doctor [--fix] [DIR] (what doesn't match this raea: old brief files, an older workspace format, an agent's skill from another version)\n raea app run|check|bundle APP.tsx [--target web|native] [--size WxH] [--script steps.json] [--png DIR] [-o App.app] (a TSX app on @raea/ui: its window, the headless check, a Mac app; web is Blitz on Bevy, native is Rune; the app's `export const app` sets the target, web when it doesn't; raea rune ... is --target native)\n {}\n {}", skill::USAGE, tools::blender::USAGE);
let (export_game, scene, physics, splat) = (raea_app_game::USAGE, export::SCENE_USAGE, motion::physics::USAGE, tools::splat::USAGE);
diff --git a/engine/cli/src/native.ts b/engine/cli/src/native.ts
index 9ee0e3e4..e99f4b84 100644
--- a/engine/cli/src/native.ts
+++ b/engine/cli/src/native.ts
@@ -5,12 +5,12 @@
// native.ts RAEA VERB ARGS... RAEA: the native raea's path, for the engine's own verbs
import { spawnSync } from "node:child_process";
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
-import { homedir, tmpdir } from "node:os";
+import { tmpdir } from "node:os";
import { basename, delimiter, dirname, extname } from "node:path";
import { brandKit } from "./brand";
import { readSite, stylesOf } from "./scrape";
import { wordsOf } from "./heard";
-import { HARNESSES } from "./show";
+import { harness, library, show, task } from "./app";
import { raeaHandler, type Engine, type Host } from "./index";
const [raea, ...args] = process.argv.slice(2);
@@ -366,99 +366,6 @@ function brand(a: { brand: string }): string {
return kit.said;
}
-/** The running raea app's host: RAEA_FEED_HOST for an agent the app started, else the address the installed app leaves
- * in ~/.raea/app-host.json while it runs (apps/app host/host-file.ts), if its process is still there. */
-function appHost(): string | null {
- if (process.env.RAEA_FEED_HOST) return process.env.RAEA_FEED_HOST;
- const file = process.env.RAEA_HOST_FILE || `${homedir()}/.raea/app-host.json`;
- try {
- const h = JSON.parse(readFileSync(file, "utf8")) as { url?: string; pid?: number };
- if (h.url && h.pid && spawnSync("kill", ["-0", String(h.pid)]).status === 0) return h.url;
- } catch {
- // no app running, or a file left by one that stopped
- }
- return null;
-}
-
-/** POST a host route of the raea app at `at`, answering its JSON; its refusal is thrown as it says it. */
-function postHost(at: string, route: string, a: Record<string, unknown>): any {
- const r = spawnSync("curl", ["-sS", "--max-time", "120", "-w", "\n%{http_code}", "-H", "content-type: application/json", "--data-binary", "@-", `${at.replace(/\/$/, "")}${route}`], { input: JSON.stringify(a), encoding: "utf8", maxBuffer: 64 << 20 });
- const text = r.stdout ?? "";
- const cut = text.lastIndexOf("\n");
- const [body, code] = [text.slice(0, cut), Number(text.slice(cut + 1))];
- if (r.status !== 0) throw new Error(`the raea app at ${at} didn't answer: ${(r.stderr ?? "").trim()}`);
- if (!(code >= 200 && code < 300)) throw Object.assign(new Error(body.trim() || `the raea app said ${code}`), { code });
- return JSON.parse(body);
-}
-
-/** `raea show` (show.ts): the item made by the raea app's host (apps/app host/show.ts), the app started first when it's
- * installed and not running, then the window brought up on it by its raea:// link. Without the app, the files open in
- * the Mac's own viewer. */
-function show(a: Record<string, unknown>): unknown {
- let at = appHost();
- if (!at) {
- const app = [process.env.RAEA_APP, "/Applications/raea.app", `${homedir()}/Applications/raea.app`].find((p) => p && existsSync(p));
- const files = (a.files as string[]) ?? [];
- if (!app) {
- if (a.question) throw new Error("a question needs the raea app, and it isn't on this Mac (raea.io)");
- spawnSync("open", files);
- return { opened: files };
- }
- if (spawnSync("pgrep", ["-f", `${app}/Contents/MacOS/raea-window`]).status === 0)
- throw new Error("the raea app running here is older than raea show (it leaves no ~/.raea/app-host.json); quit it and open it again to update, then show it again");
- spawnSync("open", ["-a", app]);
- // the window's host writes its address once it listens: a minute at most, in quarter seconds
- for (let i = 0; i < 240 && !(at = appHost()); i++) spawnSync("/bin/sleep", ["0.25"]);
- if (!at) throw new Error(`the raea app didn't start (no ~/.raea/app-host.json after a minute); open ${app} and show it again`);
- }
- let shown: { url: string };
- try {
- shown = postHost(at, "/host/show", a);
- } catch (e) {
- // the host's refusal names the verb, as the shell's report does too
- throw new Error(String((e as Error).message).replace(/^raea show: /, ""));
- }
- // RAEA_NO_OPEN: a test's, which mustn't bring up the person's window
- if (!process.env.RAEA_NO_OPEN) spawnSync("open", [shown.url]);
- return shown;
-}
-
-/** The agent harness that started this command (show.ts HARNESSES), found up its parent processes: a program's own
- * name, or the script a runtime runs (`node .../gemini`). Nothing when no harness is up there. */
-function harness(): { name: string; pid: number } | undefined {
- let pid = process.ppid;
- for (let i = 0; i < 16 && pid > 1; i++) {
- const m = /^\s*(\d+)\s+(.*)$/.exec(spawnSync("ps", ["-o", "ppid=,args=", "-p", String(pid)], { encoding: "utf8" }).stdout ?? "");
- if (!m) return undefined;
- for (const w of m[2].split(/\s+/).slice(0, 2).map((w) => basename(w).toLowerCase())) {
- const hit = HARNESSES.find(([re]) => re.test(w));
- if (hit) return { name: hit[1], pid };
- }
- pid = Number(m[1]);
- }
- return undefined;
-}
-
-/** `raea show --on ITEM --working ID` and `--done ID` (show.ts): the person's comments marked on their item by the raea
- * app's host (apps/app host/tasks.ts), which the window shows as who's on each and which are done. */
-function task(a: Record<string, unknown>): unknown {
- const at = appHost();
- if (!at) throw new Error("the raea app isn't running here: open it, then mark the comments again");
- try {
- return postHost(at, "/host/task", a);
- } catch (e) {
- const old = (e as { code?: number }).code === 404 && !/^raea show: /.test((e as Error).message); // an app from before --on: its host's bare "not found"
- throw new Error(old ? "the raea app running here is older than raea show --on; quit it and open it again to update, then mark the comments again" : String((e as Error).message).replace(/^raea show: /, ""));
- }
-}
-
-/** An op of the feed host's libraries (apps/app host/library/service.ts): POST <the app's host>/host/library. */
-function library(a: Record<string, unknown>): unknown {
- const at = appHost();
- if (!at) throw new Error("libraries live in the raea app: open it on this Mac (or set RAEA_FEED_HOST to its address)");
- return postHost(at, "/host/library", a);
-}
-
const host: Host = (op, a) => {
switch (op) {
case "shape":
diff --git a/engine/cli/src/show.ts b/engine/cli/src/show.ts
index 405a61e6..50c5d4a6 100644
--- a/engine/cli/src/show.ts
+++ b/engine/cli/src/show.ts
@@ -4,13 +4,23 @@
// things and recording them after making an answer"). The app's host makes the item (apps/app host/show.ts): stills a
// look (several, a storyboard), a video a watch, a sound a listen, a NAME.script.ts or .md a read, a .tsx an interactive
// artifact (or, when it's one of the project's compositions, that composition open in its editor), a question an ask.
-// The window comes up on it (raea://item/...), and what the person sends on it comes back as lines in the session's
-// inbox (~/.raea/inbox/<inbox>.jsonl). Without the app on this Mac, the files open in the Mac's own viewer and it says so.
+// It lands quietly: the page finds it and says so in a notice, the window left where the person is (Shane 11-10: "any
+// time you make an update to the feed it takes me out of the thing im currently doing"); --open brings the window up on
+// it (raea://item/...). Several questions are one item, each question and each choice with a preview to play or read
+// while answering (Shane 11-10: "all in one feed item rather than a bunch of them"). What the person sends on it comes
+// back as lines in the session's inbox (~/.raea/inbox/<inbox>.jsonl). Without the app on this Mac, the files open in
+// the Mac's own viewer and it says so.
type Ask = (op: string, args: Record<string, unknown>) => any;
-export const SHOW_USAGE = `raea show FILE... [--title T] [--ask "what you want from the person"] [--project P] [--replaces ITEM]
-raea show --question "Which look?" (--choice A --choice B ... | STILL.png STILL.png ...) [--project P]
+export const SHOW_USAGE = `raea show FILE... [--title T] [--ask "what you want from the person"] [--project P] [--replaces ITEM] [--open]
+raea show --question "Which look?" (--choice A --choice B ... | STILL.png STILL.png ...) [--project P] [--open]
+raea show [--title T] --question Q1 [--preview FILE] --choice A [--preview FILE] --choice B ... --question Q2 ... [--open]
+ Ask everything at once: one item, every question in it, each question and each choice with what it is to play or
+ read while answering (--preview after a --choice is that choice's, before any choice the question's: a still, a
+ video, a sound, a NAME.script.ts or a .md). The first choice is the one you suggest.
+ It lands in the person's feed with a notice and the window stays where they are; --open brings the window up on it
+ (only when they're waiting on it).
FILE: stills (several make a storyboard), a video, a sound, a NAME.script.ts or .md, or a .tsx (an interactive
artifact; one of the project's compositions opens in its editor). P: the project's id, title or Workspace/project;
else the one this folder is in. Who's showing it: --as NAME [--role ROLE] [--inbox NAME], else your harness's.
@@ -20,7 +30,8 @@ raea show FILE... --replaces ITEM --done ID...
(the version that settles them, with --replaces); --sub names a subagent when several split them.
`;
-const WITH_VALUE = new Set(["--title", "--ask", "--project", "--replaces", "--as", "--role", "--inbox", "--question", "--choice", "--on", "--working", "--done", "--note", "--sub"]);
+const WITH_VALUE = new Set(["--title", "--ask", "--project", "--replaces", "--as", "--role", "--inbox", "--question", "--choice", "--preview", "--on", "--working", "--done", "--note", "--sub"]);
+const FLAGS = new Set(["--open"]);
/** The harness an agent runs in, named as the feed shows it, from the program that started this command (native.ts
* walks up its parents): any harness, not only the ones that mark their shells. */
@@ -52,10 +63,30 @@ export function parseShow(args: string[], cwd: string) {
};
const many = (name: string) => args.flatMap((a, i) => (a === name && args[i + 1] !== undefined ? [args[i + 1]] : []));
const choices = many("--choice");
- const unknown = args.find((a, i) => a.startsWith("--") && !WITH_VALUE.has(a) && !WITH_VALUE.has(args[i - 1] ?? ""));
+ const unknown = args.find((a, i) => a.startsWith("--") && !WITH_VALUE.has(a) && !FLAGS.has(a) && !WITH_VALUE.has(args[i - 1] ?? ""));
if (unknown) throw new Error(`no ${unknown} here\n${SHOW_USAGE}`);
- const files = args.filter((a, i) => !a.startsWith("--") && !WITH_VALUE.has(args[i - 1] ?? "")).map((f) => (f.startsWith("/") ? f : `${cwd.replace(/\/$/, "")}/${f}`));
- return { files, choices, title: one("--title"), ask: one("--ask"), project: one("--project"), replaces: one("--replaces"), question: one("--question"), as: one("--as"), role: one("--role"), inbox: one("--inbox"), on: one("--on"), working: many("--working"), done: many("--done"), note: one("--note"), sub: one("--sub") };
+ const abs = (f: string) => (f.startsWith("/") ? f : `${cwd.replace(/\/$/, "")}/${f}`);
+ const files = args.filter((a, i) => !a.startsWith("--") && !WITH_VALUE.has(args[i - 1] ?? "")).map(abs);
+ // the questions in order: each --question starts one and its --choice's follow; a --preview after a --choice is that
+ // choice's, after the --question (before any choice) the question's own
+ const asked: { ask: string; choices: { label: string; preview?: string }[]; preview?: string }[] = [];
+ for (let i = 0; i < args.length; i++) {
+ const v = args[i + 1];
+ if (args[i] === "--question" && v !== undefined) asked.push({ ask: v, choices: [] });
+ else if (args[i] === "--choice" && v !== undefined) asked.at(-1)?.choices.push({ label: v });
+ else if (args[i] === "--preview" && v !== undefined) {
+ const q = asked.at(-1);
+ if (!q) throw new Error(`--preview goes after the --question or the --choice it shows\n${SHOW_USAGE}`);
+ const at = q.choices.at(-1) ?? q;
+ if (at.preview) throw new Error(`one --preview for ${"label" in at ? `the choice "${at.label}"` : `"${q.ask}"`}\n${SHOW_USAGE}`);
+ at.preview = abs(v);
+ }
+ }
+ if (args.includes("--choice") && args.indexOf("--choice") < args.indexOf("--question")) throw new Error(`a --choice goes after its --question\n${SHOW_USAGE}`);
+ // several questions, or any preview: one item with them all (host/show.ts questions); else the one question as before
+ const questions = asked.length > 1 || asked.some((q) => q.preview || q.choices.some((c) => c.preview)) ? asked : undefined;
+ if (questions && files.length) throw new Error(`with several questions or previews, each file is a --preview of the question or choice it shows\n${SHOW_USAGE}`);
+ return { files, choices, questions, open: args.includes("--open"), title: one("--title"), ask: one("--ask"), project: one("--project"), replaces: one("--replaces"), question: questions ? undefined : one("--question"), as: one("--as"), role: one("--role"), inbox: one("--inbox"), on: one("--on"), working: many("--working"), done: many("--done"), note: one("--note"), sub: one("--sub") };
}
export function showVerb(ask: Ask, args: string[], cwd: string, env: Record<string, string | undefined>): string {
@@ -74,7 +105,7 @@ export function showVerb(ask: Ask, args: string[], cwd: string, env: Record<stri
const mark = (item: string, comments: string[], state: "working" | "done", version?: string) =>
ask("task", { item, comments, state, by, sub: a.sub, note: state === "done" ? a.note : undefined, version }) as { item: string; comments: string[] };
const said = (m: { item: string; comments: string[] }, state: string) => `Marked ${m.comments.join(", ")} ${state} on ${m.item}: the person sees ${a.sub ? `${by.name} · ${a.sub}` : by.name} ${state === "working" ? "on them" : "finished them"}.`;
- if (!a.files.length && !a.question && (a.working.length || a.done.length)) {
+ if (!a.files.length && !a.question && !a.questions && (a.working.length || a.done.length)) {
const item = a.on ?? a.replaces;
if (!item) throw new Error(`which item the comments are on: --on ITEM\n${SHOW_USAGE}`);
const out = [...(a.working.length ? [said(mark(item, a.working, "working"), "working")] : []), ...(a.done.length ? [said(mark(item, a.done, "done"), "done")] : [])];
@@ -82,13 +113,16 @@ export function showVerb(ask: Ask, args: string[], cwd: string, env: Record<stri
}
if (a.working.length) throw new Error(`--working marks comments without showing anything: raea show --on ITEM --working ID\n${SHOW_USAGE}`);
if (a.done.length && !a.replaces) throw new Error(`--done with files settles comments on the item they replace: add --replaces ITEM\n${SHOW_USAGE}`);
- const r = ask("show", { files: a.files, title: a.title, ask: a.ask, question: a.question, choices: a.choices, project: a.project, replaces: a.replaces, cwd, by }) as
+ const r = ask("show", { files: a.files, title: a.title, ask: a.ask, question: a.question, choices: a.choices, questions: a.questions, open: a.open, project: a.project, replaces: a.replaces, cwd, by }) as
| { opened: string[] }
- | { kind: "item" | "composition"; id: string; type: string; title: string; project: string; workspace: string; inbox: string };
+ | { kind: "item" | "composition"; id: string; type: string; title: string; project: string; workspace: string; inbox: string; brought?: boolean };
if ("opened" in r) return `The raea app isn't on this Mac, so ${r.opened.length === 1 ? "it opened" : `${r.opened.length} files opened`} in the Mac's own viewer: nothing was posted and nothing comes back. Install raea (raea.io) to show work as items the person can answer.\n`;
const home = env.HOME ?? "";
const inbox = home && r.inbox.startsWith(home) ? `~${r.inbox.slice(home.length)}` : r.inbox;
- if (r.kind === "composition") return `Opened ${r.title} in the raea app's composition editor (project ${r.project}, ${r.workspace}): the person plays it and changes it there, and their changes save into its file.\n`;
+ if (r.kind === "composition")
+ return r.brought
+ ? `Opened ${r.title} in the raea app's composition editor (project ${r.project}, ${r.workspace}): the person plays it and changes it there, and their changes save into its file.\n`
+ : `Offered ${r.title} in the raea app (project ${r.project}, ${r.workspace}): a notice opens it in the composition editor when the person is ready; --open brings the window up on it now.\n`;
// the version is posted by now: a marking the host refuses is said with it, not thrown over it
const settle = (item: string) => {
try {
@@ -99,7 +133,9 @@ export function showVerb(ask: Ask, args: string[], cwd: string, env: Record<stri
};
const settled = a.done.length && a.replaces ? [settle(a.replaces)] : [];
return [
- `Shown in the raea app: "${r.title}" (${r.type}, item ${r.id}, project ${r.project} in ${r.workspace}); the window is on it.`,
+ r.brought
+ ? `Shown in the raea app: "${r.title}" (${r.type}, item ${r.id}, project ${r.project} in ${r.workspace}); the window is on it.`
+ : `Posted in the raea app: "${r.title}" (${r.type}, item ${r.id}, project ${r.project} in ${r.workspace}), with a notice; the window stayed where the person is.`,
...settled,
`What the person sends on it (notes, edits, picks, answers, results) comes to ${inbox}, one JSON line each. Follow it (tail -n0 -F ${inbox}, or your harness's monitor) and answer each; a next version is raea show --replaces ${r.id} FILE.`,
"",