Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
feat(optimus): live narration, sturdier actions, paste and draw (0.3.0)
Salman Qureshi2aadac8fe925
diff --git a/plugins/optimus/companion/Cargo.lock b/plugins/optimus/companion/Cargo.lockindex 323020a7..568024aa 100644--- a/plugins/optimus/companion/Cargo.lock+++ b/plugins/optimus/companion/Cargo.lock@@ -1280,7 +1280,7 @@ dependencies = [[[package]]name = "mercury-optimus"-version = "0.2.0"+version = "0.3.0"dependencies = ["base64 0.22.1","core-foundation",diff --git a/plugins/optimus/companion/Cargo.toml b/plugins/optimus/companion/Cargo.tomlindex 148700e4..a9bcab45 100644--- a/plugins/optimus/companion/Cargo.toml+++ b/plugins/optimus/companion/Cargo.toml@@ -1,6 +1,6 @@[package]name = "mercury-optimus"-version = "0.2.1"+version = "0.3.0"edition = "2024"rust-version = "1.94"description = "Optimus: full computer control for Mercury (screen, mouse, keyboard, apps, voice)"diff --git a/plugins/optimus/companion/src/core.rs b/plugins/optimus/companion/src/core.rsindex fca9283d..e8702b65 100644--- a/plugins/optimus/companion/src/core.rs+++ b/plugins/optimus/companion/src/core.rs@@ -131,6 +131,12 @@ pub fn run(inbox: std::sync::mpsc::Receiver<Value>, send: impl Fn(Value) + Send});continue;}+ // In a voice session, say what's happening as it happens.+ if let Some(line) = narration(&name, &args) {+ if let Some(s) = shared.session.lock().unwrap().as_ref() {+ s.narrate(line);+ }+ }rt.spawn_blocking(move || {let r = sh.ops.lock().unwrap_or_else(|e| e.into_inner()).run(&name, &args);sh.out.op_result(id, r);@@ -148,6 +154,32 @@ pub fn run(inbox: std::sync::mpsc::Receiver<Value>, send: impl Fn(Value) + Sendrt.shutdown_timeout(Duration::from_secs(2));}+/// A few words for the voice about an action: the model's own `say`, else one from the action.+fn narration(op: &str, args: &Value) -> Option<String> {+ if let Some(s) = args.get("say").and_then(Value::as_str).map(str::trim).filter(|s| !s.is_empty()) {+ return Some(s.chars().take(120).collect());+ }+ match op {+ "open" => args.get("target").and_then(Value::as_str).map(|t| format!("Opening {t}")),+ "act" => {+ let first = match args.get("actions") {+ Some(Value::Array(a)) => a.first().cloned(),+ Some(Value::String(s)) => serde_json::from_str::<Value>(s).ok().and_then(|v| v.as_array().and_then(|a| a.first().cloned())),+ _ => None,+ }?;+ Some(match first.get("type").and_then(Value::as_str)? {+ "type" | "paste" => "Typing".into(),+ "draw" => "Drawing".into(),+ "scroll" => "Scrolling".into(),+ "drag" => "Dragging".into(),+ "key" => return first.get("keys").and_then(Value::as_str).map(|k| format!("Pressing {k}")),+ _ => "Clicking".into(),+ })+ }+ _ => None,+ }+}+fn start_hotkey(shared: &Arc<Shared>) {let status = |detail: String| {shared.out.notify("mercury/channel/status", json!({ "state": "connected", "account": "this computer", "detail": detail }));@@ -233,3 +265,17 @@ fn on_mercury(shared: &Arc<Shared>, msg: &Value) {_ => {}}}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn narration_lines() {+ assert_eq!(narration("open", &json!({ "target": "Gmail", "say": "Opening your inbox" })).as_deref(), Some("Opening your inbox"));+ assert_eq!(narration("open", &json!({ "target": "Gmail" })).as_deref(), Some("Opening Gmail"));+ assert_eq!(narration("act", &json!({ "actions": [{ "type": "paste", "text": "hi" }] })).as_deref(), Some("Typing"));+ assert_eq!(narration("act", &json!({ "actions": "[{\"type\":\"key\",\"keys\":\"cmd+a\"}]" })).as_deref(), Some("Pressing cmd+a"));+ assert_eq!(narration("look", &json!({})), None);+ }+}diff --git a/plugins/optimus/companion/src/main.rs b/plugins/optimus/companion/src/main.rsindex f095c967..83b7cd6b 100644--- a/plugins/optimus/companion/src/main.rs+++ b/plugins/optimus/companion/src/main.rs@@ -166,17 +166,18 @@ fn action_schema() -> Value {"actions": {"type": "array","minItems": 1,- "maxItems": 40,+ "maxItems": 60,"description": "Done in order. Coordinates are pixels in the latest screenshot.","items": {"type": "object","properties": {- "type": { "type": "string", "enum": ["click", "double_click", "triple_click", "right_click", "middle_click", "move", "drag", "mouse_down", "mouse_up", "type", "key", "scroll", "wait"] },+ "type": { "type": "string", "enum": ["click", "double_click", "triple_click", "right_click", "middle_click", "move", "drag", "draw", "mouse_down", "mouse_up", "type", "paste", "key", "scroll", "wait"] },"x": { "type": "number" },"y": { "type": "number" },"to_x": { "type": "number", "description": "drag: end x" },"to_y": { "type": "number", "description": "drag: end y" },- "text": { "type": "string", "description": "type: the text (with x/y, clicks there first)" },+ "text": { "type": "string", "description": "type/paste: the text (with x/y, clicks there first). Use paste for posts, emails and long text in web editors (X, Gmail, LinkedIn, Docs)" },+ "points": { "type": "array", "items": { "type": "array", "items": { "type": "number" } }, "description": "draw: [[x, y], …] one freehand stroke with the button held (many points for curves)" },"keys": { "type": "string", "description": "key: one key or a combo, e.g. \"enter\", \"cmd+t\", \"ctrl+shift+esc\"" },"modifiers": { "type": "string", "description": "click: keys held while clicking, e.g. \"cmd\" or \"shift\"" },"repeat": { "type": "integer", "minimum": 1, "maximum": 50 },@@ -187,6 +188,7 @@ fn action_schema() -> Value {"required": ["type"]}},+ "say": { "type": "string", "description": "A few words saying what this does, present tense ('Opening the compose box', 'Typing your post'). Spoken live when the owner is talking to you." },"screenshot": { "type": "boolean", "description": "Return a screenshot afterwards (default true)." },"settle_ms": { "type": "integer", "minimum": 0, "maximum": 5000, "description": "Wait before that screenshot (default 500)." }},@@ -196,9 +198,9 @@ fn action_schema() -> Value {const TOOL_DESCRIPTIONS: [(&str, &str); 7] = [("look", "See the screen: a screenshot of the display the mouse is on (or `display` N), with the active window. Use `zoom` [x0,y0,x1,y1] for a closer look at part of the last screenshot (coordinates stay in the full screenshot)."),- ("act", "Use the mouse and keyboard like a person: click, type, press keys, scroll, drag. Returns a fresh screenshot. Only for ordinary, reversible steps. Anything that submits, sends, posts, pays, buys, deletes, installs or changes settings must go through act_consequential instead. Never type passwords, card numbers or 2FA codes: ask the owner to do that part."),+ ("act", "Use the mouse and keyboard like a person: click, type, paste, press keys, scroll, drag, draw freehand. Returns a fresh screenshot. Pass `actions` as a list. For posts, emails and long text in web pages, use paste (click the box first) rather than type. Only for ordinary, reversible steps. Anything that submits, sends, posts, pays, buys, deletes, installs or changes settings must go through act_consequential instead. Never type passwords, card numbers or 2FA codes: ask the owner to do that part."),("act_consequential", "Same as act, for the step that commits something: submit a form, send a message or email, post, pay or buy, delete, install, change a setting. The owner approves it first, so say what it will do."),- ("open", "Open an app by name (\"Safari\", \"Blender\", \"Notepad\"), a URL, or a file/folder path. Faster and more reliable than clicking through menus."),+ ("open", "Open an app by name (\"Chrome\", \"Notes\", \"Freeform\"), a URL, or a file/folder path. Faster and more reliable than clicking through menus. If the app isn't installed, the reply lists what is. For drawing use Freeform (Mac), Paint (Windows) or a web canvas like https://excalidraw.com."),("windows", "List open windows (app and title), front first."),("permissions", "Check what the OS lets Optimus do (macOS: Accessibility and Screen Recording). With request=true, shows the system prompts and opens the right Settings page."),("listen", "Start a voice conversation on this computer right now (as if the owner pressed the talk key): Mercury listens through the microphone and answers out loud. Use when the owner asks to talk instead of type."),@@ -214,7 +216,10 @@ fn tools() -> Value {}}),"act" | "act_consequential" => action_schema(),- "open" => json!({ "type": "object", "properties": { "target": { "type": "string" } }, "required": ["target"] }),+ "open" => json!({ "type": "object", "properties": {+ "target": { "type": "string" },+ "say": { "type": "string", "description": "A few words, spoken live in a voice session, e.g. 'Opening Gmail'" }+ }, "required": ["target"] }),"permissions" => json!({ "type": "object", "properties": { "request": { "type": "boolean" } } }),_ => json!({ "type": "object", "properties": {} }),};diff --git a/plugins/optimus/companion/src/ops.rs b/plugins/optimus/companion/src/ops.rsindex 17e98507..4dabeed2 100644--- a/plugins/optimus/companion/src/ops.rs+++ b/plugins/optimus/companion/src/ops.rs@@ -24,7 +24,9 @@ const MAX_H: u32 = 800;const JPEG_QUALITY: u8 = 80;/// The user moving the mouse this far during a batch stops Optimus.const TAKEOVER_PX: i32 = 12;-const MAX_ACTIONS: usize = 40;+const MAX_ACTIONS: usize = 60;+/// Points in one freehand stroke.+const MAX_DRAW_POINTS: usize = 2000;const MAX_TYPE_CHARS: usize = 4000;/// Where the last screenshot came from, to map its pixels back to the screen.@@ -193,7 +195,8 @@ impl Ops {// ── Acting ─────────────────────────────────────────────────────────fn act(&mut self, args: &Value) -> OpResult {- let actions = args.get("actions").and_then(Value::as_array).ok_or("actions must be a list")?;+ let actions = actions_of(args)?;+ let actions = &actions;if actions.is_empty() {return Err("no actions given".into());}@@ -344,10 +347,61 @@ impl Ops {if let Some(p) = at {move_to(e, p, last_set)?;e.button(Button::Left, Direction::Click).map_err(err)?;+ std::thread::sleep(Duration::from_millis(200)); // let the field take focus}e.text(text).map_err(err)?;Ok(format!("typed {} characters", text.chars().count()))}+ "paste" => {+ // Rich web editors (X, Gmail, LinkedIn, Docs) take pasted text more reliably than typed keys.+ let text = a.get("text").and_then(Value::as_str).ok_or("paste needs text")?;+ if let Some(p) = at {+ move_to(e, p, last_set)?;+ e.button(Button::Left, Direction::Click).map_err(err)?;+ std::thread::sleep(Duration::from_millis(200));+ }+ let previous = clipboard_get();+ clipboard_set(text)?;+ std::thread::sleep(Duration::from_millis(80));+ let modifier = if cfg!(target_os = "macos") { Key::Meta } else { Key::Control };+ e.key(modifier, Direction::Press).map_err(err)?;+ e.key(Key::Unicode('v'), Direction::Click).map_err(err)?;+ e.key(modifier, Direction::Release).map_err(err)?;+ std::thread::sleep(Duration::from_millis(250));+ if let Some(prev) = previous {+ let _ = clipboard_set(&prev);+ }+ Ok(format!("pasted {} characters", text.chars().count()))+ }+ "draw" => {+ // A freehand stroke: the button stays down through every point.+ let pts = a.get("points").and_then(points_of).ok_or("draw needs points: [[x, y], …] in screenshot pixels")?;+ if pts.len() < 2 {+ return Err("draw needs at least two points".into());+ }+ if pts.len() > MAX_DRAW_POINTS {+ return Err(format!("at most {MAX_DRAW_POINTS} points per stroke"));+ }+ let shot = self.shot.ok_or("take a screenshot (look) first, so coordinates have a frame")?;+ let screen: Vec<(i32, i32)> = pts.iter().map(|(x, y)| shot.to_screen(*x, *y)).collect::<Result<_, _>>()?;+ let e = self.enigo()?;+ move_to(e, screen[0], last_set)?;+ e.button(Button::Left, Direction::Press).map_err(err)?;+ std::thread::sleep(Duration::from_millis(30));+ for w in screen.windows(2) {+ let (a0, b0) = (w[0], w[1]);+ let steps = (((b0.0 - a0.0).abs().max((b0.1 - a0.1).abs())) / 6).clamp(1, 20);+ for s in 1..=steps {+ let t = s as f64 / steps as f64;+ let p = (a0.0 + ((b0.0 - a0.0) as f64 * t).round() as i32, a0.1 + ((b0.1 - a0.1) as f64 * t).round() as i32);+ e.move_mouse(p.0, p.1, Coordinate::Abs).map_err(err)?;+ std::thread::sleep(Duration::from_millis(4));+ }+ }+ *last_set = screen.last().copied();+ e.button(Button::Left, Direction::Release).map_err(err)?;+ Ok(format!("drew a stroke through {} points", pts.len()))+ }"key" => {let combo = a.get("keys").and_then(Value::as_str).ok_or("key needs keys, e.g. \"cmd+t\" or \"enter\"")?;let repeat = a.get("repeat").and_then(Value::as_u64).unwrap_or(1).clamp(1, 50);@@ -493,9 +547,17 @@ fn open_target(args: &Value) -> OpResult {let status = if cfg!(target_os = "macos") {let mut c = std::process::Command::new("open");if !is_url && !is_path {- c.arg("-a");+ // "Chrome" is "Google Chrome", "Word" is "Microsoft Word": match installed apps by name.+ match find_mac_app(target) {+ Ok(path) => {+ c.arg(path);+ }+ Err(e) => return Err(e),+ }+ } else {+ c.arg(target);}- c.arg(target).status()+ c.status()} else if cfg!(windows) {std::process::Command::new("cmd").args(["/C", "start", "", target]).status()} else if is_url || is_path {@@ -516,6 +578,124 @@ fn open_target(args: &Value) -> OpResult {}}+/// Installed macOS apps whose name matches `name` best: exact, then+/// containing it (shortest first), e.g. "chrome" → Google Chrome.app.+fn find_mac_app(name: &str) -> Result<String, String> {+ let norm = |s: &str| s.to_lowercase().chars().filter(|c| c.is_alphanumeric()).collect::<String>();+ let want = norm(name.trim_end_matches(".app"));+ let home = std::env::var("HOME").unwrap_or_default();+ let dirs = [+ "/Applications".to_string(),+ "/Applications/Utilities".to_string(),+ "/System/Applications".to_string(),+ "/System/Applications/Utilities".to_string(),+ format!("{home}/Applications"),+ "/System/Library/CoreServices/Applications".to_string(),+ ];+ let mut apps: Vec<(String, String)> = Vec::new(); // (display name, path)+ for d in &dirs {+ let Ok(entries) = std::fs::read_dir(d) else { continue };+ for e in entries.flatten() {+ let file = e.file_name().to_string_lossy().to_string();+ if let Some(stem) = file.strip_suffix(".app") {+ apps.push((stem.to_string(), e.path().to_string_lossy().to_string()));+ }+ }+ }+ if let Some((_, p)) = apps.iter().find(|(n, _)| norm(n) == want) {+ return Ok(p.clone());+ }+ let mut close: Vec<&(String, String)> = apps.iter().filter(|(n, _)| !want.is_empty() && norm(n).contains(&want)).collect();+ close.sort_by_key(|(n, _)| n.len());+ if let Some((_, p)) = close.first() {+ return Ok(p.clone());+ }+ let mut names: Vec<&str> = apps.iter().map(|(n, _)| n.as_str()).collect();+ names.sort_unstable();+ names.dedup();+ Err(format!(+ "{name} isn't installed. Installed apps include: {}. For drawing, Freeform or a web canvas (e.g. open https://excalidraw.com) works.",+ names.iter().take(60).copied().collect::<Vec<_>>().join(", ")+ ))+}++/// The action list, however the model sent it: a list, a JSON string of+/// one, a single action, or the action's fields at the top level.+fn actions_of(args: &Value) -> Result<Vec<Value>, String> {+ let raw = match args.get("actions") {+ Some(Value::String(s)) => serde_json::from_str::<Value>(s).map_err(|_| "actions must be a list of {\"type\": …} steps".to_string())?,+ Some(v) => v.clone(),+ None if args.get("type").is_some() => args.clone(),+ None => return Err("actions must be a list of {\"type\": …} steps".into()),+ };+ let list = match raw {+ Value::Array(a) => a,+ Value::Object(_) => vec![raw],+ _ => return Err("actions must be a list of {\"type\": …} steps".into()),+ };+ // Numbers sent as strings ("x": "120") are fine too.+ Ok(list+ .into_iter()+ .map(|mut a| {+ if let Some(o) = a.as_object_mut() {+ for k in ["x", "y", "to_x", "to_y", "amount", "seconds", "repeat"] {+ if let Some(n) = o.get(k).and_then(Value::as_str).and_then(|s| s.trim().parse::<f64>().ok()) {+ o.insert(k.into(), json!(n));+ }+ }+ if let Some(p) = o.get("points").and_then(Value::as_str).and_then(|s| serde_json::from_str::<Value>(s).ok()) {+ o.insert("points".into(), p);+ }+ }+ a+ })+ .collect())+}++/// [[x, y], …] or [{"x": …, "y": …}, …]+fn points_of(v: &Value) -> Option<Vec<(f64, f64)>> {+ v.as_array()?+ .iter()+ .map(|p| match p {+ Value::Array(xy) if xy.len() >= 2 => Some((xy[0].as_f64()?, xy[1].as_f64()?)),+ Value::Object(o) => Some((o.get("x")?.as_f64()?, o.get("y")?.as_f64()?)),+ _ => None,+ })+ .collect()+}++fn clipboard_get() -> Option<String> {+ let out = if cfg!(target_os = "macos") {+ std::process::Command::new("pbpaste").output().ok()?+ } else if cfg!(windows) {+ std::process::Command::new("powershell").args(["-NoProfile", "-Command", "Get-Clipboard -Raw"]).output().ok()?+ } else {+ std::process::Command::new("xclip").args(["-selection", "clipboard", "-o"]).output().ok()?+ };+ out.status.success().then(|| String::from_utf8_lossy(&out.stdout).into_owned())+}++fn clipboard_set(text: &str) -> Result<(), String> {+ use std::io::Write as _;+ let mut cmd = if cfg!(target_os = "macos") {+ std::process::Command::new("pbcopy")+ } else if cfg!(windows) {+ let mut c = std::process::Command::new("powershell");+ c.args(["-NoProfile", "-Command", "$input | Set-Clipboard"]);+ c+ } else if std::env::var("WAYLAND_DISPLAY").is_ok() {+ std::process::Command::new("wl-copy")+ } else {+ let mut c = std::process::Command::new("xclip");+ c.args(["-selection", "clipboard"]);+ c+ };+ let mut child = cmd.stdin(std::process::Stdio::piped()).spawn().map_err(|e| format!("can't reach the clipboard: {e}"))?;+ child.stdin.take().ok_or("clipboard")?.write_all(text.as_bytes()).map_err(|e| e.to_string())?;+ let status = child.wait().map_err(|e| e.to_string())?;+ if status.success() { Ok(()) } else { Err("couldn't set the clipboard".into()) }+}+// ── Keys ──────────────────────────────────────────────────────────────fn key_named(name: &str) -> Result<Key, String> {@@ -624,3 +804,30 @@ mod tests {assert_eq!((w, h), (800, 600));}}++#[cfg(test)]+mod action_input_tests {+ use super::*;++ #[test]+ fn actions_in_any_shape() {+ let list = json!({ "actions": [{ "type": "click", "x": 1, "y": 2 }] });+ assert_eq!(actions_of(&list).unwrap().len(), 1);+ // Some models send the list as a JSON string, numbers as strings.+ let stringy = json!({ "actions": "[{\"type\":\"click\",\"x\":\"10\",\"y\":20}]" });+ let a = actions_of(&stringy).unwrap();+ assert_eq!(a[0]["x"], json!(10.0));+ // One action, or its fields at the top level.+ assert_eq!(actions_of(&json!({ "actions": { "type": "key", "keys": "enter" } })).unwrap().len(), 1);+ assert_eq!(actions_of(&json!({ "type": "key", "keys": "enter" })).unwrap().len(), 1);+ assert!(actions_of(&json!({})).is_err());+ assert!(actions_of(&json!({ "actions": "not json" })).is_err());+ }++ #[test]+ fn draw_points() {+ assert_eq!(points_of(&json!([[1, 2], [3.5, 4]])), Some(vec![(1.0, 2.0), (3.5, 4.0)]));+ assert_eq!(points_of(&json!([{ "x": 1, "y": 2 }])), Some(vec![(1.0, 2.0)]));+ assert_eq!(points_of(&json!([[1]])), None);+ }+}diff --git a/plugins/optimus/companion/src/voice.rs b/plugins/optimus/companion/src/voice.rsindex 7d87389d..37e1a0f4 100644--- a/plugins/optimus/companion/src/voice.rs+++ b/plugins/optimus/companion/src/voice.rs@@ -28,6 +28,8 @@ pub enum Ctl {/// The talk key: interrupt Mercury if it's speaking, otherwise stop listening.Press,Stop,+ /// What Mercury is doing on the screen right now, to say as it happens.+ Narrate(String),}pub struct SessionCtl {@@ -38,6 +40,9 @@ impl SessionCtl {pub fn stop(&self) {let _ = self.tx.send(Ctl::Stop);}+ pub fn narrate(&self, line: String) {+ let _ = self.tx.send(Ctl::Narrate(line));+ }}/// The talk key was pressed (or the `listen` tool called).@@ -111,8 +116,10 @@ fn instructions_for(instructions: &str) -> String {('what's this?', 'what am I looking at?'), for doing things on the computer (open apps, click, type, fill a form, search), \for news, facts that may have changed, or the user's own things (memory, files, calendar), call ask_mercury with a clear, complete request. \Mercury can see and use the screen, search the web and use its tools. \- Before a request that will take a while (web searches, several steps on the screen), say in a few words that you're on it. \- Then say its answer in your own words. If you get a status update while Mercury is still working, give one short, natural sentence about it. \+ Before a request, say two or three words at most ('On it.') and call ask_mercury straight away. \+ While Mercury works you'll get live updates of what it is doing on the screen right now: say each one in a few words, present tense \+ ('Opening Gmail', 'Selecting the junk emails'), and nothing else. Never announce something as upcoming once an update or the answer shows it's done. \+ When ask_mercury returns, say what was done or found, briefly and in the past tense. \Some actions need the user's approval. When you get an approval request, ask the user plainly whether to go ahead, wait for their answer, \then call answer_approval. Never answer an approval yourself: only the user's own words count. \Links, lists and details go to the user's Mercury chat automatically; just say you've sent them. \@@ -200,6 +207,9 @@ async fn bridge(status_tick.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);let mut ask_seq = 0u32;let silence = vec![0i16; FRAME];+ // Live narration: the newest line waits while the voice is speaking; older ones are dropped.+ let mut narration: Option<String> = None;+ let mut last_narrated = Instant::now() - Duration::from_secs(60);let max_minutes = settings().get("maxSessionMinutes").and_then(Value::as_f64).unwrap_or(30.0).clamp(1.0, 240.0);let deadline = tokio::time::sleep(Duration::from_secs_f64(max_minutes * 60.0));@@ -231,6 +241,13 @@ async fn bridge(_ = &mut deadline => break Ok(()),c = ctl.recv() => match c {None | Some(Ctl::Stop) => break Ok(()),+ Some(Ctl::Narrate(line)) => {+ last_narrated = Instant::now();+ narration = Some(line);+ if !responding && ready_answers.is_empty() {+ speak_narration(&link, brain, &mut narration, &mut responding);+ }+ }Some(Ctl::Press) => {if responding || out.recently_audible(300) {// Mercury is talking: the key interrupts.@@ -250,6 +267,7 @@ async fn bridge(}Some(a) = answer_rx.recv() => {if a.1.starts_with("(superseded") { continue; }+ narration = None; // the result supersedes anything still unsaidready_answers.push_back(a);if !responding { deliver(&link, brain, &mut ready_answers, &mut responding); }}@@ -305,7 +323,7 @@ async fn bridge(} else { None }})};- if let Some((n, secs)) = due {+ if let Some((n, secs)) = due.filter(|_| last_narrated.elapsed() > Duration::from_secs(12)) {let doing = sh.call_activity.lock().unwrap().get(call_id).cloned().unwrap_or_else(|| "working on it".into());match brain {Brain::Voice => link.send(LinkCmd::Instruct(if n == 1 {@@ -326,6 +344,7 @@ async fn bridge(LinkEvent::ResponseDone => {responding = false;if !ready_answers.is_empty() { deliver(&link, brain, &mut ready_answers, &mut responding); }+ else if narration.is_some() { speak_narration(&link, brain, &mut narration, &mut responding); }}LinkEvent::Audio(pcm) => out.play(&pcm),LinkEvent::SpeechStarted => {@@ -447,6 +466,18 @@ pub fn spoken_verdict(said: &[(Instant, String)], since: Instant) -> Option<boolNone}+fn speak_narration(link: &Link, brain: Brain, pending: &mut Option<String>, responding: &mut bool) {+ if let Some(line) = pending.take() {+ match brain {+ Brain::Voice => link.send(LinkCmd::Instruct(format!(+ "[Live update, not said by the user] Mercury is doing this on the screen right now: {line}. Say it in a few words, present tense, and nothing else."+ ))),+ Brain::Mercury => link.send(LinkCmd::Say(line)),+ }+ *responding = true;+ }+}+fn deliver(link: &Link, brain: Brain, ready: &mut VecDeque<(String, String)>, responding: &mut bool) {if let Some((id, answer)) = ready.pop_front() {match brain {diff --git a/plugins/optimus/mercury-plugin.template.json b/plugins/optimus/mercury-plugin.template.jsonindex 71203cd5..26b2b349 100644--- a/plugins/optimus/mercury-plugin.template.json+++ b/plugins/optimus/mercury-plugin.template.json@@ -2,7 +2,7 @@"manifestVersion": 1,"id": "optimus","name": "Optimus",- "version": "0.2.1",+ "version": "0.3.0","description": "Mercury uses your computer like a person: sees the screen, moves the mouse, types and opens apps, by chat or out loud with a talk key. macOS, Windows and Linux. Asks before anything that submits, sends, pays or deletes.","kind": "out-of-process","author": "Cosmic Stack",@@ -32,7 +32,7 @@},{"name": "act",- "description": "Use the mouse and keyboard like a person: click, type, press keys, scroll, drag. Returns a fresh screenshot. Only for ordinary, reversible steps. Anything that submits, sends, posts, pays, buys, deletes, installs or changes settings must go through act_consequential instead. Never type passwords, card numbers or 2FA codes: ask the owner to do that part.",+ "description": "Use the mouse and keyboard like a person: click, type, paste, press keys, scroll, drag, draw freehand. Returns a fresh screenshot. Pass `actions` as a list. For posts, emails and long text in web pages, use paste (click the box first) rather than type. Only for ordinary, reversible steps. Anything that submits, sends, posts, pays, buys, deletes, installs or changes settings must go through act_consequential instead. Never type passwords, card numbers or 2FA codes: ask the owner to do that part.","readOnly": true,"timeoutMs": 120000},@@ -44,7 +44,7 @@},{"name": "open",- "description": "Open an app by name (\"Safari\", \"Blender\", \"Notepad\"), a URL, or a file/folder path. Faster and more reliable than clicking through menus.",+ "description": "Open an app by name (\"Chrome\", \"Notes\", \"Freeform\"), a URL, or a file/folder path. Faster and more reliable than clicking through menus. If the app isn't installed, the reply lists what is. For drawing use Freeform (Mac), Paint (Windows) or a web canvas like https://excalidraw.com.","readOnly": true,"timeoutMs": 30000},diff --git a/src/plugins/channel-bridge.ts b/src/plugins/channel-bridge.tsindex c4eb0cd8..46a8229a 100644--- a/src/plugins/channel-bridge.ts+++ b/src/plugins/channel-bridge.ts@@ -607,7 +607,7 @@ export class PluginChannel extends BaseChannel {return [`## Channel: ${name} (voice, on the owner's computer)`,'You\'re talking with the owner, out loud, at their own computer. Your answer is spoken: one to three short sentences, no markdown, lists, links or code.',- `To see their screen use ${this.manifest.id}__look; to do things on it use ${this.manifest.id}__open and ${this.manifest.id}__act, and ${this.manifest.id}__act_consequential for anything that submits, sends, pays, deletes or installs. Say briefly what you're doing as you go.`,+ `To see their screen use ${this.manifest.id}__look; to do things on it use ${this.manifest.id}__open and ${this.manifest.id}__act, and ${this.manifest.id}__act_consequential for the step that submits, sends, posts, pays, deletes or installs (e.g. the final Post or Send button). Give every open/act call a short \`say\` ("Opening Gmail", "Typing your post"): it is spoken the moment it happens, so the owner hears each step live. Look after each step and check it worked before the next.`,'Access: Extended. Use your tools, skills, files and memory as you would anywhere else. Approvals are asked out loud and answered by voice.',].join('\n');}