MK28-MK29: a goal as a fifth kind of make job, held by its commands and a fresh critic, never the agent's word

make: goal({ goal, rules }) on brief.ts: each rule a command that must exit 0 (run, with a timeout), a file that must exist (a deliverable) or words a fresh critic must find true (says). raea make status runs the commands at every status (the Stop hook's too); raea make judge [--by claude|kimi] asks a read-only critic and keeps its verdict in review/goal.judge.json, which clears a says rule only while it is no older than the work's newest file. Make also gets previews (what a job shows but never delivers: review/ and previews/ by default), and status lists files.deliverables and files.previews. runtime/goal-plan holds the gates (raea-app-make was at its size cap).

Test: goal-plan's six (a command passes or says why, a timeout, a stale and a fresh verdict, file rules left to deliverables, the doctor); end to end on a scratch brief, a curt greeting.txt was refused by the critic and a warm one passed, with both commands passing.
This commit is contained in:
shinyobjectz committed 2026-11-26 09:41:28 -08:00
1 parent 04098af5af
commit 2a005e0e30
17 files changed
+548 -15

No files matched your search

Generated
+9
View File
@@ -13897,6 +13897,7 @@ dependencies = [
"raea-core-review",
"raea-io-home",
"raea-runtime-cut-plan",
"raea-runtime-goal-plan",
"raea-runtime-lod-plan",
"resvg 0.48.1",
"serde_json",
@@ -15427,6 +15428,14 @@ dependencies = [
"wgpu",
]
[[package]]
name = "raea-runtime-goal-plan"
version = "0.1.0"
dependencies = [
"raea-core-brief",
"serde_json",
]
[[package]]
name = "raea-runtime-gpuframe"
version = "0.1.0"
+1
View File
@@ -195,6 +195,7 @@ members = [
"runtime/endchecks",
"runtime/lod-plan",
"runtime/cut-plan",
"runtime/goal-plan",
"runtime/live",
"runtime/page",
"runtime/appscreen",
+2
View File
@@ -15,6 +15,8 @@ raea-core-facts = { path = "../../core/facts" }
raea-runtime-lod-plan = { path = "../../runtime/lod-plan" }
# a cut job's gates: its client's brief as rules, held over the delivered files (MK25-MK27)
raea-runtime-cut-plan = { path = "../../runtime/cut-plan" }
# a goal job's gates: its commands and a fresh critic's verdict on its words (/goal)
raea-runtime-goal-plan = { path = "../../runtime/goal-plan" }
# the judge's rounds, passes and blocking defects, read as it keeps them
raea-app-judge = { path = "../judge" }
# the make questions, their calibrations and a sheet's ident, as raea ask keeps them (MK4)
+4 -2
View File
@@ -19,7 +19,8 @@ use std::path::{Path, PathBuf};
use raea_core_brief::make::Make;
use serde_json::Value;
pub const USAGE: &str = "raea make status [DIR] [--json] [--plan] (a scene, kit or shot held to its plan, `make` on brief.ts: what's missing, each gate (renders and checks, raea ask's calibrated questions, the critic on the kind's rubric), the judge's rounds, and whether it's done, decided in code; --plan writes the gates as check lines under the job's task in plan.org; the agent's Stop hook holds it there)
pub const USAGE: &str = "raea make status [DIR] [--json] [--plan] (a scene, kit, shot, cut or goal held to its plan, `make` on brief.ts: what's missing, each gate (renders and checks, raea ask's calibrated questions, the critic on the kind's rubric), the judge's rounds, and whether it's done, decided in code; --plan writes the gates as check lines under the job's task in plan.org; the agent's Stop hook holds it there)
raea make judge [DIR] [--by claude|kimi] (a goal job: a fresh critic, which only reads, judges each `says` rule; review/goal.judge.json)
raea make plan [DIR] [--no-review] (the plan stop: review/plan/floor-plan.png, a grey-box blockout from the entrance and its review sheets, comparison.png beside reference 0)
raea make refs [DIR] [--only ID,...] [--model M] [--dry] (a kit: every object's reference from the style images, in the plan's style, then review/refs.png; --dry quotes it)
raea make sheet refs [DIR] (review/refs.png again: the style images, then every reference)
@@ -102,7 +103,7 @@ pub fn status_in(dir: &Path) -> Result<Option<Value>, String> {
}
/// The flags that take a value: what follows them isn't a positional argument.
const VALUED: [&str; 7] = ["--only", "--model", "--tripo", "--meshy", "--name", "--to", "--out"];
const VALUED: [&str; 8] = ["--only", "--model", "--tripo", "--meshy", "--name", "--to", "--out", "--by"];
fn flag<'a>(args: &'a [String], k: &str) -> Option<&'a str> {
args.iter().position(|a| a == k).and_then(|i| args.get(i + 1)).map(String::as_str)
@@ -184,6 +185,7 @@ fn step(verb: &str, args: &[String]) -> Result<String, String> {
pub fn cli(args: &[String]) -> Result<String, String> {
match args.get(1).map(String::as_str) {
Some("status") => {}
Some("judge") => return job(&PathBuf::from(positional(args, 2).first().map_or(".", String::as_str))).and_then(|(b, m)| raea_runtime_goal_plan::judge(m.goal.as_ref().ok_or("raea make judge: the job isn't a goal({...})")?, b.parent().unwrap_or(Path::new(".")), flag(args, "--by").unwrap_or("claude")).map(|v| serde_json::to_string_pretty(&v).unwrap_or_default())),
Some(v @ ("plan" | "refs" | "sheet" | "gen" | "pick-sheet" | "pick" | "prep" | "kit" | "framing" | "lenschart")) => return step(v, args),
_ => return Err(USAGE.into()),
}
+5 -3
View File
@@ -143,7 +143,7 @@ fn critic(job: &Job, newest: Option<SystemTime>, notes: &str) -> Vec<Value> {
let what = match job.make.kind {
make::Kind::Kit => "raea render shared/components/KIT/lineup.tsx --review review/r1",
make::Kind::Shot => "raea make framing --out review/r1",
make::Kind::Scene | make::Kind::Cut => "raea render EDIT.tsx --review review/r1",
make::Kind::Scene | make::Kind::Cut | make::Kind::Goal => "raea render EDIT.tsx --review review/r1",
};
return vec![gate("critic", None, false, format!("no round yet: {what}, then raea judge review/r1 --kind {kind} --by claude --brief brief.ts"))];
};
@@ -183,7 +183,7 @@ pub fn status(job: &Job) -> Value {
}
}
let notes = notes_text(job.dir).unwrap_or_default();
if !notes.to_lowercase().contains(&SKILL_HEADING.to_lowercase()) {
if job.make.kind != make::Kind::Goal && !notes.to_lowercase().contains(&SKILL_HEADING.to_lowercase()) {
missing.push(format!("NOTES.md with a \"{SKILL_HEADING}\" section (one line per thing that cost time; what the guide got wrong for this job)"));
}
let mut gates = checks(job);
@@ -191,6 +191,7 @@ pub fn status(job: &Job) -> Value {
match (&job.make.cut, job.make.kind) {
// a cut job: its brief's rules over every delivered file (MK25-MK27), and the person's review its critic
(Some(c), make::Kind::Cut) => gates.extend(raea_runtime_cut_plan::gates(c, job.dir).into_iter().map(|g| gate(g.name, g.of.as_deref(), g.clear, g.says))),
(_, make::Kind::Goal) => gates.extend(job.make.goal.iter().flat_map(|g| raea_runtime_goal_plan::gates(g, job.dir)).map(|g| gate(g.name, g.of.as_deref(), g.clear, g.says))),
_ => gates.extend(critic(job, newest, &notes)),
}
let (asks, said) = crate::asked::gates(&sheets(job), job.ledger, &notes);
@@ -215,6 +216,7 @@ pub fn status(job: &Job) -> Value {
"gates": gates,
"judge": {"rounds": job.rounds.len(), "cap": cap, "passesInARow": advice["passesInARow"], "changeApproach": advice["stall"], "again": advice["again"]},
"plan": make::doctor(job.make),
"files": {"deliverables": make::deliverables(job.make), "previews": make::previews(job.make)},
"advice": said,
"why": why,
})
@@ -239,6 +241,6 @@ pub fn text(s: &Value) -> String {
t.push(format!(" {} {}{of}: {}", if g["clear"] == true { "ok " } else { "open" }, g["gate"].as_str().unwrap_or(""), g["says"].as_str().unwrap_or("")));
}
let j = &s["judge"];
t.push(format!("judge: {} of {} rounds, {} passes in a row{}", j["rounds"], j["cap"], j["passesInARow"], if j["changeApproach"] == true { "; the same defect keeps coming back: change the approach for that part, not the dose" } else { "" }));
if s["kind"] != "goal" { t.push(format!("judge: {} of {} rounds, {} passes in a row{}", j["rounds"], j["cap"], j["passesInARow"], if j["changeApproach"] == true { "; the same defect keeps coming back: change the approach for that part, not the dose" } else { "" })); }
t.join("\n")
}
+67
View File
@@ -0,0 +1,67 @@
//! A goal job's contract: `make: goal({...})` on brief.ts, the person's goal written as rules before the work starts
//! (11-26, Shane: "we essentially just need to make sure that it can't stop unless all the goals pass, or all the rules
//! in the brief"). `/goal` in raea.app and an agent's own goal are this: the goal in the person's words, then each
//! thing that must hold, as a command that must pass, a file that must exist, or words a fresh critic must find true.
//! `raea make status` (runtime/goal-plan) decides from them whether the agent may stop; the agent saying so never does.
use serde::{Deserialize, Serialize};
use ts_rs::TS;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[ts(optional_fields)]
#[ts(rename = "MakeGoal")]
pub struct Goal {
/// the goal as the person said it
pub goal: String,
/// what must hold before the agent may stop: every one, each checked in code or by a fresh critic
#[serde(default)]
#[ts(as = "Option<Vec<GoalRule>>", optional)]
pub rules: Vec<GoalRule>,
}
/// One thing that must hold. Exactly one of `run`, `file` or `says`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[ts(optional_fields)]
#[ts(rename = "MakeGoalRule")]
pub struct GoalRule {
/// a short name: [a-z0-9_], how status, the critic and NOTES.md name it
pub id: String,
/// a command that must exit 0, run in the brief's folder (`bun test`, `raea check edit.tsx`)
pub run: Option<String>,
/// the seconds `run` gets before it counts as failed (300 when left out)
pub timeout: Option<u32>,
/// a file that must exist, relative to the brief (`a|b`: either; `dir/`: three or more pictures in it)
pub file: Option<String>,
/// words that must be true of the work, judged by a fresh critic (`raea make judge`), never by the agent that did it
pub says: Option<String>,
}
/// What the goal's rules still lack, each with what to do. Empty when it's ready.
pub fn doctor(g: &Goal) -> Vec<String> {
let mut out = Vec::new();
if g.goal.trim().is_empty() {
out.push("no `goal`: the goal in the person's own words".into());
}
if g.rules.is_empty() {
out.push("no `rules`: what must hold before you stop, each a `run` command, a `file` or words a critic judges (`says`)".into());
}
let mut seen = std::collections::BTreeSet::new();
for r in &g.rules {
if !crate::make::is_name(&r.id) {
out.push(format!("rule `{}`: ids are [a-z0-9_]", r.id));
}
if !seen.insert(r.id.as_str()) {
out.push(format!("rule `{}` is listed twice", r.id));
}
let n = [r.run.is_some(), r.file.is_some(), r.says.is_some()].iter().filter(|x| **x).count();
if n != 1 {
out.push(format!("rule `{}` needs exactly one of `run`, `file` or `says` (it has {n})", r.id));
}
if r.timeout.is_some() && r.run.is_none() {
out.push(format!("rule `{}` has a `timeout` but no `run`", r.id));
}
}
out
}
+2
View File
@@ -5,6 +5,7 @@
pub mod brief;
pub mod cut;
pub mod goal;
pub mod make;
pub mod parts;
pub mod script;
@@ -41,6 +42,7 @@ pub fn declarations() -> String {
parts::Parts, parts::Concept, parts::Level, parts::Count, parts::Part,
make::Make, make::Kind, make::Source, make::DialValue, make::Dial, make::Route, make::Origin, make::Pick, make::Object, make::Shot,
cut::Cut, cut::Quoted<u32>, cut::CutPlan, cut::Phrase, cut::Cta, cut::Open,
goal::Goal, goal::GoalRule,
));
out.join("\n\n") + "\n"
}
+24 -1
View File
@@ -21,6 +21,8 @@ pub enum Kind {
Shot,
/// ads cut from footage to a client's brief: its deliverables, phrases, claims and CTA as rules (cut.rs, MK25)
Cut,
/// any other work held to a goal: commands that must pass, files that must exist, words a critic judges (goal.rs)
Goal,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
@@ -56,6 +58,13 @@ pub struct Make {
pub rounds: Option<u32>,
/// a cut job's contract: the brief as rules (cut.rs)
pub cut: Option<crate::cut::Cut>,
/// a goal job's contract: the goal and its rules (goal.rs)
pub goal: Option<crate::goal::Goal>,
/// what the job shows but never delivers, relative to the brief (pictures, render tests, examples): each a file or a
/// `dir/` (review/ and previews/ when left out). Deliverables are what it hands over; previews are how it got there
#[serde(default)]
#[ts(as = "Option<Vec<String>>", optional)]
pub previews: Vec<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
@@ -194,7 +203,7 @@ impl Kind {
/// as brief.ts writes it, and as raea judge's rubrics are named
pub fn name(self) -> &'static str {
// in the enum's order
["scene", "kit", "shot", "cut"][self as usize]
["scene", "kit", "shot", "cut", "goal"][self as usize]
}
}
@@ -205,6 +214,7 @@ pub fn dials(kind: Kind) -> &'static [&'static str] {
Kind::Kit => &["count", "variety", "detail", "wear", "wetness", "warmth", "look"],
Kind::Shot => &["res", "seconds", "lens", "handheld", "look"],
Kind::Cut => &["look"],
Kind::Goal => &[],
}
}
@@ -232,9 +242,16 @@ pub fn deliverables(m: &Make) -> Vec<String> {
// a shot is a still or a move, so either file answers; apps/make reads `a|b`
Kind::Shot => m.shots.iter().map(|s| format!("out/shots/{0}.png|out/shots/{0}.mp4", s.name)).collect(),
Kind::Cut => m.cut.as_ref().map(crate::cut::deliverables).unwrap_or_default(),
// a goal's `file` rules
Kind::Goal => m.goal.iter().flat_map(|g| &g.rules).filter_map(|r| r.file.clone()).collect(),
}
}
/// What the job shows but doesn't deliver: the plan's own list, else review/ and previews/.
pub fn previews(m: &Make) -> Vec<String> {
if m.previews.is_empty() { vec!["review/".into(), "previews/".into()] } else { m.previews.clone() }
}
/// A name a file lands as: [a-z0-9_], not empty.
pub fn is_name(s: &str) -> bool {
!s.is_empty() && s.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_')
@@ -258,6 +275,12 @@ pub fn doctor(m: &Make) -> Vec<String> {
(Some(_), k) => out.push(format!("`cut` is for a cut job, not a {k:?}: drop it, or make this `cut({{...}})`")),
_ => {}
}
match (&m.goal, m.kind) {
(Some(g), Kind::Goal) => out.extend(crate::goal::doctor(g)),
(None, Kind::Goal) => out.push("no `goal`: the goal in the person's words and its `rules`".into()),
(Some(_), k) => out.push(format!("`goal` is for a goal job, not a {k:?}: drop it, or make this `goal({{...}})`")),
_ => {}
}
if m.kind == Kind::Kit && m.style.is_none() {
out.push("no `style`: one paragraph (era, palette, materials, wear, one fictional maker) every reference carries".into());
}
+31
View File
@@ -286,6 +286,37 @@ Feature: Make: scenes, kits and shots built to a frozen plan and held to a revie
error: no face cut by the frame or a seam, no text under the size floor ("frames")
And the cut job has no critic tier yet: the person's review is its critic
Rule: any goal, held to rules (MK28-MK29)
Shane, 11-26, asking whether raea make is just a version of /goal: "when we use these things, they should just
probably be consolidated into one workflow, because in any case we'll have a goal or a brief or something that
dictates what we need. And then we essentially just need to make sure that it can't stop unless all the goals pass,
or all the rules in the brief". /goal in raea.app's chat let the agent end the loop by writing "GOAL MET"; a goal it
can declare met is advice. So /goal and raea make are one loop: a goal is a fifth kind of job, its words become
rules in brief.ts before the work starts, and only `raea make status` says it's met.
@needs:MK2
Scenario: MK28. A goal as rules: `make: goal({...})`
Given work that isn't a scene, kit, shot or cut (fix a bug, write a page, ship a change)
When the agent writes `make: goal({ goal: "the person's words", rules: [...] })` before it starts
Then core/brief reads `goal` (goal.rs): the goal as the person said it, and `rules`, each an id and exactly one of
`run` (a command that must exit 0 in the brief's folder, within `timeout` seconds, 300 by default), `file` (a
file that must exist: a deliverable) or `says` (words that must be true of the work)
And `doctor` names what it lacks: no goal, no rules, an id that isn't [a-z0-9_] or is listed twice, a rule with
none or more than one of run, file and says, a timeout with no run
And a goal job needs no NOTES.md "What the skill got wrong" section (no skill made it) and has no render critic
@needs:MK28
Scenario: MK29. Held by a command's exit and a fresh critic, never the agent's word
Given a goal job
Then `raea make status` runs every `run` rule at every status, the Stop hook's included, and holds the job on one
that fails or outlives its timeout, with its exit code and last line ("run")
And a `says` rule is clear only when review/goal.judge.json, written by `raea make judge [DIR] [--by claude|kimi]`
(a fresh session that may only read: Read, Grep and Glob), found it true at a time no earlier than the work's
newest file, the job's own review/, .raea/, NOTES.md, .git and node_modules left out, compared at whole seconds
("says")
And `file` rules are its deliverables, listed under missing
And raea.app's /goal is this job: it writes the rules first, and only the status ends the loop
Rule: raea cloud (MK19-MK20)
@needs:MK2 @done
+22 -2
View File
@@ -5,7 +5,7 @@ order: 44
sources: ["apps/make/src/lib.rs", "apps/make/src/status.rs", "apps/make/src/asked.rs", "apps/make/src/plan.rs", "apps/make/src/kit.rs", "apps/make/src/kitout.rs", "apps/make/src/shots.rs", "apps/make/src/floor.rs", "apps/make/src/sheet.rs", "core/brief/src/make.rs", "apps/check/make/src/lib.rs"]
---
`raea make status` reads the job on a project's brief.ts (`make: scene({...})`, `kit({...})` or `shot({...})` from
`raea make status` reads the job on a project's brief.ts (`make: scene({...})`, `kit({...})`, `shot({...})`, `cut({...})` or `goal({...})` from
`raea/brief`) and says what's still missing, from what's on disk and never from what the agent says:
- the kind's deliverables (a scene's three or more stills; a kit's GLB, LOD1 and thumbnail per object, its lineup
@@ -26,6 +26,24 @@ sources: ["apps/make/src/lib.rs", "apps/make/src/status.rs", "apps/make/src/aske
An answer counts for the sheet it was asked of, matched by the file's bytes, so a sheet rendered again is asked
again.
A goal job (`goal({...})`, what raea.app's `/goal` writes) is any other work: the goal in your words and the rules
that must hold before the agent stops. A `run` rule is a command that must exit 0 in the brief's folder (status runs
it every time, 300 seconds unless its `timeout` says otherwise); a `file` rule is a deliverable; a `says` rule is
words that must be true of the work, judged by a fresh critic that may only read: `raea make judge` asks one
(`--by claude` or `kimi`) and keeps its verdict in review/goal.judge.json, and the rule clears only while that verdict
is no older than the work's newest file. A goal job needs no NOTES.md section and has no render critic.
```ts
make: goal({
goal: "the export plays and the README says how to run it",
rules: [
{ id: "tests", run: "bun test" },
{ id: "export", file: "out/final.mp4" },
{ id: "readme", says: "README.md says how to install and run it, in order" },
],
}),
```
`--plan` writes the gates as check lines under the job's own task in the project's plan.org, keeping the person's
mark (DONE, DROPPED) and their own lines; the Stop hook runs it so.
@@ -80,7 +98,8 @@ raea make lenschart counter_push
## Usage
```sh
raea make status [DIR] [--json] [--plan] (a scene, kit or shot held to its plan, `make` on brief.ts: what's missing, each gate (renders and checks, raea ask's calibrated questions, the critic on the kind's rubric), the judge's rounds, and whether it's done, decided in code; --plan writes the gates as check lines under the job's task in plan.org; the agent's Stop hook holds it there)
raea make status [DIR] [--json] [--plan] (a scene, kit, shot, cut or goal held to its plan, `make` on brief.ts: what's missing, each gate (renders and checks, raea ask's calibrated questions, the critic on the kind's rubric), the judge's rounds, and whether it's done, decided in code; --plan writes the gates as check lines under the job's task in plan.org; the agent's Stop hook holds it there)
raea make judge [DIR] [--by claude|kimi] (a goal job: a fresh critic, which only reads, judges each `says` rule; review/goal.judge.json)
raea make plan [DIR] [--no-review] (the plan stop: review/plan/floor-plan.png, a grey-box blockout from the entrance and its review sheets, comparison.png beside reference 0)
raea make refs [DIR] [--only ID,...] [--model M] [--dry] (a kit: every object's reference from the style images, in the plan's style, then review/refs.png; --dry quotes it)
raea make sheet refs [DIR] (review/refs.png again: the style images, then every reference)
@@ -99,6 +118,7 @@ Headless: it needs nothing running and opens no window. Takes up to 5 arguments
| Flag | Takes | What it does |
| --- | --- | --- |
| `--by` | `claude\|kimi` | The critic `judge` asks, a fresh session that may only read (default `claude`). |
| `--dry` | – | Quote the generation (refs, gen) and make nothing. |
| `--json` | – | Print the status as JSON: missing, gates, judge, done, short and why. |
| `--meshy` | `M` | The Meshy model for `gen` (default `fal:meshy/v7.1/image-to-3d`). |
+25 -3
View File
@@ -30,10 +30,10 @@ See [Workspaces and projects](../../concepts/workspaces.md) for where each spec
<!-- generated:begin by tools/manual-ref/sdk.ts from the SDK's exports and doc comments; edit outside this block -->
```ts
import { brief, cut, fingerprint, kit } from "raea/brief"
import { brief, cut, fingerprint, goal } from "raea/brief"
```
`raea/brief` exports 9 functions, 40 types. Source: [sdk/raea/src/brief.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/brief.ts).
`raea/brief` exports 10 functions, 42 types. Source: [sdk/raea/src/brief.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/brief.ts).
## Functions
@@ -62,6 +62,16 @@ A fingerprint (fingerprint.ts): its axes and the encoders its heads were trained
function fingerprint(f: Fingerprint): Fingerprint
```
### `goal`
any other work held to a goal (`/goal`): the goal in the person's words and the rules that must hold before the agent
stops, each a command that must pass (`run`), a file that must exist (`file`) or words a fresh critic judges
(`says`, by `raea make judge`). `raea make status` holds the agent to every one.
```ts
function goal({ goal, rules, ...m }: MakeGoal & Omit<Make, "kind" | "goal">): Make
```
### `kit`
A kit: props in one style at real size (`style` is the paragraph every reference carries: era, palette, materials,
@@ -243,10 +253,22 @@ type MakeDial = MakeDialValue | { value: MakeDialValue, source?: MakeSource, /**
type MakeDialValue = number | string
```
### `MakeGoal`
```ts
type MakeGoal = { /** * the goal as the person said it */ goal: string, /** * what must hold before the agent may stop: every one, each checked in code or by a fresh critic */ rules?: Array<MakeGoalRule>, }
```
### `MakeGoalRule`
```ts
type MakeGoalRule = { /** * a short name: [a-z0-9_], how status, the critic and NOTES.md name it */ id: string, /** * a command that must exit 0, run in the brief's folder (`bun test`, `raea check edit.tsx`) */ run?: string, /** * the seconds `run` gets before it counts as failed (300 when left out) */ timeout?: num…
```
### `MakeKind`
```ts
type MakeKind = "scene" | "kit" | "shot" | "cut"
type MakeKind = "scene" | "kit" | "shot" | "cut" | "goal"
```
### `MakeObject`
+1 -1
View File
@@ -33,7 +33,7 @@ The composition, the app, and the specs and notes an agent writes.
| --- | --- | --- |
| [`raea`](raea.md) | The main entry: compositions, sequences, time, interpolation, springs, footage, sound and words. | 21 components, 9 hooks, 65 functions, 11 values, 109 types |
| [`raea/app`](app.md) | The App, its plugins and schedules, and the registry a video's compositions are kept in. | 1 component, 1 hook, 5 functions, 3 classes, 17 values, 18 types |
| [`raea/brief`](brief.md) | The specs an agent writes as data: brief, script, taste and an object's parts, checked against raea's schemas. | 9 functions, 40 types |
| [`raea/brief`](brief.md) | The specs an agent writes as data: brief, script, taste and an object's parts, checked against raea's schemas. | 10 functions, 42 types |
| [`raea/note`](note.md) | A person's note as a file in the project: their words kept as written, and the asks the agent restates it as. | 1 function, 4 types |
## Time and motion
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "raea-runtime-goal-plan"
version = "0.1.0"
edition = "2024"
license = "FSL-1.1-ALv2"
publish = false
description = "A goal job held to its rules: commands that must pass, and words a fresh critic must find true after the work's last change (make: goal({...}), /goal)"
[dependencies]
# the contract: `make: goal({...})` on brief.ts
raea-core-brief = { path = "../../core/brief" }
serde_json = "1"
+211
View File
@@ -0,0 +1,211 @@
//! A goal job's gates (`make: goal({...})` on brief.ts, core/brief goal.rs): the person's goal held as rules, from what's
//! on disk and what a fresh critic said, never from the agent that did the work. `/goal` in raea.app and an agent's own
//! goal are this one loop (11-26, Shane: "it can't stop unless all the goals pass").
//! run the command exits 0 in the brief's folder, within its timeout (run again at every status)
//! file the file exists: a deliverable, so `raea make status` lists it under missing, not here
//! says a fresh critic (`raea make judge`) found it true of the work, after the work's last change
//! The critic's verdict is review/goal.judge.json: {at, by, rules: {ID: {pass, why}}}.
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant, SystemTime};
use raea_core_brief::goal::Goal;
use serde_json::{Value, json};
/// One gate as `raea make status` lists it: its name, the rule it's about, whether it's clear, what it says.
#[derive(Debug, Clone, PartialEq)]
pub struct Gate {
pub name: &'static str,
pub of: Option<String>,
pub clear: bool,
pub says: String,
}
fn gate(name: &'static str, of: &str, clear: bool, says: String) -> Gate {
Gate { name, of: Some(of.to_string()), clear, says }
}
/// Where the critic's verdict is kept, beside the brief.
pub const VERDICT: &str = "review/goal.judge.json";
/// The seconds a `run` rule gets when it names none.
pub const TIMEOUT: u32 = 300;
/// Folders that aren't the work: what the job writes about itself, and what tools keep.
const NOT_WORK: [&str; 7] = ["review", ".git", "node_modules", ".raea", "target", ".cache", ".raea-cloud"];
/// When the work last changed: the newest file under DIR, its own bookkeeping left out (a bounded walk).
pub fn newest(dir: &Path) -> Option<SystemTime> {
let mut best: Option<SystemTime> = None;
let mut stack = vec![dir.to_path_buf()];
let mut seen = 0usize;
while let Some(d) = stack.pop() {
for e in std::fs::read_dir(&d).into_iter().flatten().flatten() {
seen += 1;
if seen > 20_000 {
return best;
}
let p = e.path();
let name = e.file_name().to_string_lossy().to_string();
let Ok(t) = e.file_type() else { continue };
if t.is_dir() {
if !(d == dir && NOT_WORK.contains(&name.as_str())) && name != "node_modules" && name != ".git" {
stack.push(p);
}
} else if t.is_file() && name != "NOTES.md" {
if let Ok(m) = e.metadata().and_then(|m| m.modified()) {
best = Some(best.map_or(m, |b| b.max(m)));
}
}
}
}
best
}
/// A command run in DIR through the system shell, stopped at its timeout: (passed, its last words).
pub fn run(cmd: &str, dir: &Path, secs: u32) -> (bool, String) {
let mut c = if cfg!(windows) {
let mut c = std::process::Command::new("cmd");
c.args(["/C", cmd]);
c
} else {
let mut c = std::process::Command::new("sh");
c.args(["-c", cmd]);
c
};
let out = std::env::temp_dir().join(format!("raea-goal-{}-{}.log", std::process::id(), Instant::now().elapsed().as_nanos()));
let Ok(log) = std::fs::File::create(&out) else { return (false, "couldn't make a log file for it".into()) };
let Ok(err) = log.try_clone() else { return (false, "couldn't make a log file for it".into()) };
let child = c.current_dir(dir).stdin(std::process::Stdio::null()).stdout(log).stderr(err).spawn();
let mut child = match child {
Ok(ch) => ch,
Err(e) => return (false, format!("couldn't start it: {e}")),
};
let until = Instant::now() + Duration::from_secs(secs as u64);
let status = loop {
match child.try_wait() {
Ok(Some(s)) => break Some(s),
Ok(None) if Instant::now() >= until => {
let _ = child.kill();
let _ = child.wait();
break None;
}
Ok(None) => std::thread::sleep(Duration::from_millis(100)),
Err(_) => break None,
}
};
let text = std::fs::read_to_string(&out).unwrap_or_default();
let _ = std::fs::remove_file(&out);
let last = text.lines().rev().find(|l| !l.trim().is_empty()).unwrap_or("").trim();
let last: String = last.chars().take(200).collect();
match status {
Some(s) if s.success() => (true, "passes".into()),
Some(s) => (false, format!("exits {}{}", s.code().map_or("by a signal".into(), |c| c.to_string()), if last.is_empty() { String::new() } else { format!(": {last}") })),
None => (false, format!("still running after {secs} s: stopped (give the rule a longer `timeout`, or make it quicker)")),
}
}
/// The critic's verdict, when there is one.
pub fn verdict(dir: &Path) -> Option<Value> {
serde_json::from_str(&std::fs::read_to_string(dir.join(VERDICT)).ok()?).ok()
}
/// Every rule's gate but `file` rules (deliverables: status lists them as missing).
pub fn gates(g: &Goal, dir: &Path) -> Vec<Gate> {
let says: Vec<_> = g.rules.iter().filter(|r| r.says.is_some()).collect();
let v = if says.is_empty() { None } else { verdict(dir) };
let judged = v.as_ref().and_then(|v| v["at"].as_u64()).map(|s| SystemTime::UNIX_EPOCH + Duration::from_secs(s));
let changed = if says.is_empty() { None } else { newest(dir) };
// at whole seconds, as the verdict keeps its time: work saved in the second the critic was asked counts as judged
let secs = |t: SystemTime| t.duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
let fresh = match (judged, changed) {
(Some(j), Some(c)) => secs(j) >= secs(c),
(Some(_), None) => true,
_ => false,
};
let mut out = Vec::new();
for r in &g.rules {
if let Some(cmd) = &r.run {
let (ok, said) = run(cmd, dir, r.timeout.unwrap_or(TIMEOUT));
out.push(gate("run", &r.id, ok, if ok { format!("`{cmd}` passes") } else { format!("`{cmd}` {said}") }));
} else if r.says.is_some() {
let one = v.as_ref().map(|v| &v["rules"][&r.id]);
let (clear, said) = match one {
None => (false, "not judged yet: raea make judge".to_string()),
Some(Value::Null) => (false, "the last judging didn't cover it: raea make judge".to_string()),
Some(_) if !fresh => (false, "the work changed after the critic judged it: raea make judge again".to_string()),
Some(x) if x["pass"] == true => (true, format!("a fresh critic found it true: {}", x["why"].as_str().unwrap_or(""))),
Some(x) => (false, format!("a fresh critic found it not true yet: {}", x["why"].as_str().unwrap_or(""))),
};
out.push(gate("says", &r.id, clear, said));
}
}
out
}
/// What the critic is asked: the goal, each `says` rule by id, and the answer's shape. It reads; it changes nothing.
pub fn prompt(g: &Goal, dir: &Path) -> String {
let rules: Vec<String> = g.rules.iter().filter_map(|r| r.says.as_ref().map(|s| format!("- {}: {s}", r.id))).collect();
format!(
"You are a fresh critic. You did none of this work and owe it nothing. The work is in {d}: read whatever you need \
there (its files, its renders, NOTES.md), and change nothing.\n\nThe goal, as the person said it: {goal}\n\nFor each rule \
below, decide whether it is true of the work as it is on disk now. Count it true only when you have seen it hold; if you \
can't tell, it isn't true yet. Say why in one sentence, naming what you looked at.\n\n{rules}\n\nAnswer last with one JSON \
object and nothing after it: {{\"rules\": {{\"ID\": {{\"pass\": true, \"why\": \"...\"}}}}}}",
d = dir.display(),
goal = g.goal,
rules = rules.join("\n")
)
}
/// The verdict: the object around the text's last `"rules"` key (a critic may think aloud, or quote the shape, first).
pub fn last_verdict(text: &str) -> Option<Value> {
let key = text.rfind("\"rules\"")?;
// the nearest brace before the key opens the verdict
let open = text[..key].rfind('{')?;
let v: Value = serde_json::Deserializer::from_str(&text[open..]).into_iter::<Value>().next()?.ok()?;
v["rules"].is_object().then_some(v)
}
/// The critics `raea make judge` can ask, each a fresh session that may only read.
pub const BY: [&str; 2] = ["claude", "kimi"];
/// One fresh critic over the goal's `says` rules: its verdict kept at review/goal.judge.json, stamped with when it was
/// asked (so work changed while it judged counts as changed after). Returns the verdict.
pub fn judge(g: &Goal, dir: &Path, by: &str) -> Result<Value, String> {
if !g.rules.iter().any(|r| r.says.is_some()) {
return Err("raea make judge: the goal has no `says` rules; its `run` and `file` rules are checked by raea make status".into());
}
let asked = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
let p = prompt(g, dir);
let mut cmd = match by {
"claude" => {
let mut c = std::process::Command::new("claude");
c.args(["-p", &p, "--allowedTools", "Read Grep Glob", "--output-format", "json"]);
c
}
"kimi" => {
let mut c = std::process::Command::new("kimi");
c.args(["-p", &p]);
c
}
o => return Err(format!("raea make judge: --by {o}: the critics are {}", BY.join(", "))),
};
let out = cmd.current_dir(dir).stdin(std::process::Stdio::null()).output().map_err(|e| format!("raea make judge: couldn't run {by}: {e} (is its CLI installed and signed in?)"))?;
let text = String::from_utf8_lossy(&out.stdout).to_string();
// claude's json output is {result: "..."}; kimi's is the words
let words = serde_json::from_str::<Value>(&text).ok().and_then(|v| v["result"].as_str().map(String::from)).unwrap_or(text);
let tail = &words[words.floor_char_boundary(words.len().saturating_sub(300))..];
let mut v = last_verdict(&words).ok_or_else(|| format!("raea make judge: {by} answered no verdict: {}", tail.trim()))?;
v["at"] = json!(asked);
v["by"] = json!(by);
v["goal"] = json!(g.goal);
let file: PathBuf = dir.join(VERDICT);
if let Some(parent) = file.parent() {
std::fs::create_dir_all(parent).map_err(|e| format!("raea make judge: {}: {e}", parent.display()))?;
}
std::fs::write(&file, serde_json::to_string_pretty(&v).unwrap_or_default()).map_err(|e| format!("raea make judge: {}: {e}", file.display()))?;
Ok(v)
}
#[cfg(test)]
mod tests;
+84
View File
@@ -0,0 +1,84 @@
use super::*;
use raea_core_brief::goal::{Goal, GoalRule};
fn rule(id: &str) -> GoalRule {
GoalRule { id: id.into(), run: None, timeout: None, file: None, says: None }
}
fn tmp(name: &str) -> PathBuf {
let d = std::env::temp_dir().join(format!("raea-goal-plan-{name}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
std::fs::create_dir_all(&d).unwrap();
d
}
#[test]
fn a_command_passes_or_says_why() {
let d = tmp("run");
let g = Goal { goal: "tests pass".into(), rules: vec![GoalRule { run: Some("true".into()), ..rule("ok") }, GoalRule { run: Some("echo broke; exit 3".into()), ..rule("bad") }] };
let gs = gates(&g, &d);
assert_eq!(gs.len(), 2);
assert!(gs[0].clear, "{gs:?}");
assert!(!gs[1].clear);
assert!(gs[1].says.contains("exits 3") && gs[1].says.contains("broke"), "{}", gs[1].says);
}
#[test]
fn a_command_past_its_timeout_fails() {
let d = tmp("slow");
let (ok, said) = run("sleep 5", &d, 1);
assert!(!ok);
assert!(said.contains("still running after 1 s"), "{said}");
}
#[test]
fn words_need_a_fresh_critic() {
let d = tmp("says");
std::fs::write(d.join("work.txt"), "the work").unwrap();
let g = Goal { goal: "a friendly reply".into(), rules: vec![GoalRule { says: Some("the reply is friendly".into()), ..rule("friendly") }] };
// never judged
let gs = gates(&g, &d);
assert!(!gs[0].clear && gs[0].says.contains("raea make judge"), "{gs:?}");
// judged after the work, and found true
let later = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() + 5;
std::fs::create_dir_all(d.join("review")).unwrap();
let v = json!({"at": later, "by": "claude", "rules": {"friendly": {"pass": true, "why": "it says hello warmly"}}});
std::fs::write(d.join(VERDICT), v.to_string()).unwrap();
assert!(gates(&g, &d)[0].clear);
// the critic's own file doesn't count as the work changing
assert!(newest(&d).unwrap() < SystemTime::UNIX_EPOCH + Duration::from_secs(later));
// judged before the work changed: stale
let earlier = json!({"at": 1, "rules": {"friendly": {"pass": true, "why": ""}}});
std::fs::write(d.join(VERDICT), earlier.to_string()).unwrap();
let gs = gates(&g, &d);
assert!(!gs[0].clear && gs[0].says.contains("changed after"), "{gs:?}");
// judged and found not true
let no = json!({"at": later, "rules": {"friendly": {"pass": false, "why": "it is curt"}}});
std::fs::write(d.join(VERDICT), no.to_string()).unwrap();
let gs = gates(&g, &d);
assert!(!gs[0].clear && gs[0].says.contains("it is curt"), "{gs:?}");
}
#[test]
fn file_rules_are_left_to_the_deliverables() {
let d = tmp("file");
let g = Goal { goal: "an export".into(), rules: vec![GoalRule { file: Some("out/final.mp4".into()), ..rule("export") }] };
assert!(gates(&g, &d).is_empty());
}
#[test]
fn the_verdict_is_the_last_json_with_rules() {
let t = "the shape is {\"rules\": {\"ID\": ...}} so: {\"x\": 1} then {\"rules\": {\"a\": {\"pass\": true, \"why\": \"seen\"}}}";
assert_eq!(last_verdict(t).unwrap()["rules"]["a"]["pass"], true);
assert!(last_verdict("no json here").is_none());
}
#[test]
fn the_rules_are_doctored() {
let g = Goal { goal: "".into(), rules: vec![GoalRule { run: Some("x".into()), says: Some("y".into()), ..rule("Two") }, rule("two")] };
let d = raea_core_brief::goal::doctor(&g);
assert!(d.iter().any(|l| l.contains("no `goal`")), "{d:?}");
assert!(d.iter().any(|l| l.contains("`Two`: ids are")), "{d:?}");
assert!(d.iter().any(|l| l.contains("exactly one") && l.contains("it has 2")), "{d:?}");
assert!(d.iter().any(|l| l.contains("`two` needs exactly one") && l.contains("it has 0")), "{d:?}");
}
+43 -2
View File
@@ -227,9 +227,18 @@ rounds?: number,
/**
* a cut job's contract: the brief as rules (cut.rs)
*/
cut?: MakeCut, };
cut?: MakeCut,
/**
* a goal job's contract: the goal and its rules (goal.rs)
*/
goal?: MakeGoal,
/**
* what the job shows but never delivers, relative to the brief (pictures, render tests, examples): each a file or a
* `dir/` (review/ and previews/ when left out). Deliverables are what it hands over; previews are how it got there
*/
previews?: Array<string>, };
export type MakeKind = "scene" | "kit" | "shot" | "cut";
export type MakeKind = "scene" | "kit" | "shot" | "cut" | "goal";
export type MakeSource = "customer" | "reference";
@@ -412,3 +421,35 @@ about?: string,
* the person's answer, as they gave it, and who gave it: until then the job can't be done
*/
answer?: string, by?: string, };
export type MakeGoal = {
/**
* the goal as the person said it
*/
goal: string,
/**
* what must hold before the agent may stop: every one, each checked in code or by a fresh critic
*/
rules?: Array<MakeGoalRule>, };
export type MakeGoalRule = {
/**
* a short name: [a-z0-9_], how status, the critic and NOTES.md name it
*/
id: string,
/**
* a command that must exit 0, run in the brief's folder (`bun test`, `raea check edit.tsx`)
*/
run?: string,
/**
* the seconds `run` gets before it counts as failed (300 when left out)
*/
timeout?: number,
/**
* a file that must exist, relative to the brief (`a|b`: either; `dir/`: three or more pictures in it)
*/
file?: string,
/**
* words that must be true of the work, judged by a fresh critic (`raea make judge`), never by the agent that did it
*/
says?: string, };
+5 -1
View File
@@ -7,7 +7,7 @@
//
// The types are generated from the Rust schemas (core/brief, raea-core-brief) into brief.gen.ts, so what tsc checks is
// what raea reads: `raea context` evaluates the module and Rust validates its default export again.
import type { Brief, Make, Parts, Script, Taste } from "./brief.gen";
import type { Brief, Make, MakeGoal, Parts, Script, Taste } from "./brief.gen";
export type * from "./brief.gen";
export { fingerprint } from "./fingerprint";
@@ -37,3 +37,7 @@ export const kit = (m: Omit<Make, "kind">): Make => ({ kind: "kit", ...m });
export const shot = (m: Omit<Make, "kind">): Make => ({ kind: "shot", ...m });
/** ads cut from footage to a client's brief: `cut: {...}` is the brief as rules, each quoting it (docs/make.feature MK25) */
export const cut = (m: Omit<Make, "kind">): Make => ({ kind: "cut", ...m });
/** any other work held to a goal (`/goal`): the goal in the person's words and the rules that must hold before the agent
* stops, each a command that must pass (`run`), a file that must exist (`file`) or words a fresh critic judges
* (`says`, by `raea make judge`). `raea make status` holds the agent to every one. */
export const goal = ({ goal, rules, ...m }: MakeGoal & Omit<Make, "kind" | "goal">): Make => ({ kind: "goal", goal: { goal, rules }, ...m });