brokkr-ctl blender look: send look, print the receipt's lookPath, selection and edits since the last look
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
54478cd0ad
commit
5fcc890021
2 changed files with 59 additions and 3 deletions
|
|
@ -119,7 +119,13 @@ pub fn run(args: &[String]) -> Result<i32> {
|
|||
return Ok(0);
|
||||
}
|
||||
match sub.as_str() {
|
||||
"send" => send(&options),
|
||||
"send" => send(&options, one_positional(&options, "send <action> [--set key=json]...")?),
|
||||
"look" => {
|
||||
if !options.positional.is_empty() || !options.sets.is_empty() {
|
||||
bail!("usage: brokkr-ctl blender look [--note text] [--agent name] [--no-wait] [--timeout secs]");
|
||||
}
|
||||
send(&options, "look")
|
||||
}
|
||||
"wait" => {
|
||||
let id = one_positional(&options, "wait <commandId>")?;
|
||||
let store = open_store(&options)?;
|
||||
|
|
@ -232,8 +238,7 @@ fn build_intent(
|
|||
Ok(Value::Object(map))
|
||||
}
|
||||
|
||||
fn send(options: &Options) -> Result<i32> {
|
||||
let action = one_positional(options, "send <action> [--set key=json]...")?;
|
||||
fn send(options: &Options, action: &str) -> Result<i32> {
|
||||
let requested_by = requested_by(options)?;
|
||||
let mut store = open_store(options)?;
|
||||
let command_id = uuid::Uuid::now_v7().simple().to_string();
|
||||
|
|
@ -399,6 +404,9 @@ brokkr-ctl blender: send typed intents to the live Blender add-on and read what
|
|||
|
||||
send <action> [--set key=json]... [--note text] [--agent name] [--no-wait] [--timeout secs]
|
||||
Write one intent, then wait for its receipt and print it. `send --help` lists actions.
|
||||
look [--note text] [--agent name] [--no-wait] [--timeout secs]
|
||||
`send look`: capture the 3D view she is looking at. The receipt prints lookPath (a PNG), her
|
||||
Edit Mode selection, and how many edits she made since this agent last looked.
|
||||
wait <commandId> [--timeout secs] Wait for a receipt and print it.
|
||||
receipts [--last n] Print stored receipts, oldest first.
|
||||
status Print the host snapshot summary, agentCommandsEnabled included.
|
||||
|
|
@ -544,6 +552,7 @@ const ACTIONS: &[(&str, &[Field])] = &[
|
|||
("cameraName", "string", ""),
|
||||
],
|
||||
),
|
||||
("look", &[]),
|
||||
(
|
||||
"createNodeGroup",
|
||||
&[
|
||||
|
|
|
|||
|
|
@ -80,6 +80,53 @@ fn send_writes_a_pullable_intent() {
|
|||
assert!(envelopes.iter().any(|e| e.key == "blender/receipts/seed"), "other records survive the write");
|
||||
}
|
||||
|
||||
/// `look` is `send look`: one intent, no fields, the same receipt wait.
|
||||
#[test]
|
||||
fn look_sends_the_look_action_and_prints_the_receipts_look_path() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = store_with_receipts(dir.path(), &[("seed", "accepted")]);
|
||||
let output = ctl(&path, &["look", "--agent", "hands", "--note", "checking the view", "--no-wait"], Some("nibu"));
|
||||
assert_eq!(output.status.code(), Some(0), "{}", String::from_utf8_lossy(&output.stderr));
|
||||
let id = stdout(&output).trim().strip_prefix("commandId: ").unwrap().to_string();
|
||||
let envelopes = SingleFileMessagePackBackingStore::new(&path).pull_all().unwrap();
|
||||
let intent = envelopes.iter().find(|e| e.key == format!("blender/commands/{id}")).expect("intent key");
|
||||
let payload: Value = cultcache_rs::decode_payload(&intent.payload).unwrap();
|
||||
assert_eq!(
|
||||
payload,
|
||||
json!({"schema": INTENT, "commandId": id, "action": "look", "requestedBy": "nibu/hands",
|
||||
"note": "checking the view"})
|
||||
);
|
||||
// the add-on's receipt for it prints like any other: lookPath and the perception fields are plain lines
|
||||
let mut store = SingleFileMessagePackBackingStore::new(&path);
|
||||
let receipt = json!({"schema": RECEIPT, "commandId": id, "status": "accepted", "lookPath": "C:/out/look/x.png",
|
||||
"humanEditSeq": 3, "editSelection": [{"name": "Cube", "vertices": [0, 2]}]});
|
||||
store.push(&envelope(RECEIPT, &format!("blender/receipts/{id}"), &receipt)).unwrap();
|
||||
let waited = ctl(&path, &["wait", &id, "--timeout", "5"], None);
|
||||
assert_eq!(waited.status.code(), Some(0));
|
||||
let text = stdout(&waited);
|
||||
assert!(text.contains("lookPath: C:/out/look/x.png"), "{text}");
|
||||
assert!(text.contains("humanEditSeq: 3") && text.contains("\"vertices\":[0,2]"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn look_takes_no_fields_and_no_second_action() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = store_with_receipts(dir.path(), &[("seed", "accepted")]);
|
||||
for extra in [vec!["--set", "x=1"], vec!["createObject"]] {
|
||||
let mut args = vec!["look", "--agent", "hands", "--no-wait"];
|
||||
args.extend(extra.iter());
|
||||
assert_eq!(ctl(&path, &args, Some("nibu")).status.code(), Some(1), "{extra:?}");
|
||||
}
|
||||
let store = SingleFileMessagePackBackingStore::new(&path).pull_all().unwrap();
|
||||
assert!(!store.iter().any(|e| e.key.starts_with("blender/commands/")), "a refused look writes nothing");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_group_help_names_look() {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_brokkr-ctl")).args(["blender", "--help"]).output().unwrap();
|
||||
assert!(stdout(&output).contains("look"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_intent_without_instance_or_agent_is_refused_and_writes_nothing() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue