From 7302d3cc4e539cb1f6147f3859b96366851c352c Mon Sep 17 00:00:00 2001 From: omesser Date: Mon, 26 Oct 2026 16:12:14 +0200 Subject: [PATCH 01/12] feat(mcp): Take instance_id on every tool and refuse an unknown one Co-Authored-By: Claude Opus 5.5 --- crates/core/src/dispatch.rs | 132 ++++++++++++++++++++++++++++++------ crates/core/src/tools.rs | 14 +--- 2 files changed, 113 insertions(+), 33 deletions(-) diff --git a/crates/core/src/dispatch.rs b/crates/core/src/dispatch.rs index fe27a543b..c0158cf00 100644 --- a/crates/core/src/dispatch.rs +++ b/crates/core/src/dispatch.rs @@ -80,11 +80,35 @@ fn parse_args Deserialize<'de>>( }) } +fn unknown_instance(id: &str, roster: &[InstanceInfo]) -> String { + if roster.is_empty() { + return format!("No Character Instance has id {id}. No Character Instance is running."); + } + let running = roster + .iter() + .map(|info| format!("{} ({})", info.id, info.name)) + .collect::>() + .join(", "); + format!( + "No Character Instance has id {id}. Running: {running}. \ + Pass your own instance_id from your opening prompt." + ) +} + pub fn dispatch( tool_name: &str, arguments: Value, context: &mut DispatchContext, ) -> Result { + // One gate for every tool, so a tool added later refuses a stray id too. + if let Some(id) = arguments.get("instance_id").and_then(Value::as_str) { + if !context.roster.iter().any(|info| info.id == id) { + return Err(DispatchError { + code: ErrorCode::InvalidArguments, + message: unknown_instance(id, context.roster), + }); + } + } match tool_name { "speak" => { #[derive(Deserialize)] @@ -233,7 +257,7 @@ pub struct ToolInfo { /// The tools in `tools`, and none that post input events. pub fn list_tools() -> Vec { - vec![ + let mut tools = vec![ ToolInfo { name: "speak".to_string(), description: "Make the Character speak a line of dialogue".to_string(), @@ -243,10 +267,6 @@ pub fn list_tools() -> Vec { "message": { "type": "string", "description": "The message to speak" - }, - "instance_id": { - "type": "string", - "description": "Optional instance ID to target" } }, "required": ["message"] @@ -261,10 +281,6 @@ pub fn list_tools() -> Vec { "behavior": { "type": "string", "description": "The name of the Behavior to play" - }, - "instance_id": { - "type": "string", - "description": "Optional instance ID to target" } }, "required": ["behavior"] @@ -341,7 +357,14 @@ pub fn list_tools() -> Vec { } }), }, - ] + ]; + for tool in &mut tools { + tool.input_schema["properties"]["instance_id"] = serde_json::json!({ + "type": "string", + "description": "Your Character Instance id, named in your opening prompt. speak and play_behavior act on that Instance. Optional while only one Instance runs." + }); + } + tools } #[cfg(test)] @@ -1059,27 +1082,94 @@ mod tests { ); } + /// Every tool, not only the Expression ones, refuses an id no Instance + /// carries, and the refusal names the ids that would work. #[test] - fn unknown_instance_id_is_failure() { + fn every_tool_refuses_an_unknown_instance_id_and_names_the_running_ones() { let temp = tempfile::tempdir().expect("temp dir is creatable"); let source = fake_source(vec![]); - let infos = [InstanceInfo { - id: "known-instance".to_string(), - name: "Known".to_string(), - }]; + let infos = [ + InstanceInfo { + id: "pip".to_string(), + name: "Pip".to_string(), + }, + InstanceInfo { + id: "rex".to_string(), + name: "Rex".to_string(), + }, + ]; let mut context = test_context(&temp, &source, &infos); - let args = json!({"message": "Hello", "instance_id": "unknown-instance"}); - let result = dispatch("speak", args, &mut context).expect("dispatch succeeds"); + for tool in list_tools() { + let refused = dispatch( + &tool.name, + json!({"message": "hi", "behavior": "wave", "instance_id": "nope"}), + &mut context, + ) + .expect_err(&format!("{} accepted an unknown instance_id", tool.name)); + assert_eq!(refused.code, ErrorCode::InvalidArguments, "{}", tool.name); + assert_eq!( + refused.message, + "No Character Instance has id nope. Running: pip (Pip), rex (Rex). \ + Pass your own instance_id from your opening prompt.", + "{}", + tool.name + ); + } + } + + #[test] + fn an_instance_id_with_nothing_running_says_so() { + let temp = tempfile::tempdir().expect("temp dir is creatable"); + let source = fake_source(vec![]); + let mut context = test_context(&temp, &source, &[]); + + let refused = dispatch("recall", json!({"instance_id": "nope"}), &mut context) + .expect_err("an id is refused when no Instance runs"); - assert_eq!(result["success"], false); - assert_eq!(result["message"], "Hello"); assert_eq!( - result["reason"], - "No Character Instance has id unknown-instance" + refused.message, + "No Character Instance has id nope. No Character Instance is running." ); } + /// A known id is accepted by a tool that does not target anything. + #[test] + fn a_known_instance_id_passes_through_a_sensing_tool() { + let temp = tempfile::tempdir().expect("temp dir is creatable"); + let source = fake_source(vec![window("Terminal", 0.0, 0.0, 10.0, 10.0)]); + let infos = [InstanceInfo { + id: "pip".to_string(), + name: "Pip".to_string(), + }]; + let mut context = test_context(&temp, &source, &infos); + + let result = dispatch("list_windows", json!({"instance_id": "pip"}), &mut context) + .expect("a known id is accepted"); + + assert_eq!(result["windows"][0]["owner"], "Terminal"); + } + + /// Optional, so the stdio shim in the user's own sessions keeps working + /// with one Instance (ADR-0026). + #[test] + fn every_tool_advertises_an_optional_instance_id() { + for tool in list_tools() { + let schema = &tool.input_schema; + assert_eq!( + schema["properties"]["instance_id"]["type"], "string", + "{}", + tool.name + ); + let required = schema["required"].as_array().cloned().unwrap_or_default(); + assert!( + !required.contains(&json!("instance_id")), + "{} requires instance_id", + tool.name + ); + } + } + /// Break: success on an empty roster lets a stdio verification pass /// against nothing at all. #[test] diff --git a/crates/core/src/tools.rs b/crates/core/src/tools.rs index d2e9c79d0..b0c5fdae1 100644 --- a/crates/core/src/tools.rs +++ b/crates/core/src/tools.rs @@ -252,9 +252,6 @@ mod helpers { "No Character Instance is running, so nothing changed on screen".to_string(), ); } - TargetResolution::UnknownInstance(id) => { - return Err(format!("No Character Instance has id {id}")); - } TargetResolution::AmbiguousTarget => { return Err( "Several Character Instances are running; name one with instance_id" @@ -288,24 +285,17 @@ mod helpers { enum TargetResolution { Resolved(String), NoInstances, - /// The caller named an id no Instance in the roster carries. - UnknownInstance(String), AmbiguousTarget, } /// Target resolution against roster for both speak and play_behavior. + /// `dispatch` already refused an id the roster does not carry. fn resolve_target_instance( instance_id: Option<&str>, roster: &[InstanceInfo], ) -> TargetResolution { match instance_id { - Some(id) => { - if roster.iter().any(|info| info.id == id) { - TargetResolution::Resolved(id.to_string()) - } else { - TargetResolution::UnknownInstance(id.to_string()) - } - } + Some(id) => TargetResolution::Resolved(id.to_string()), None => match roster.len() { 0 => TargetResolution::NoInstances, 1 => TargetResolution::Resolved(roster[0].id.clone()), From 802bec60b172b6757f39370ecd0950991362bd46 Mon Sep 17 00:00:00 2001 From: omesser Date: Wed, 28 Oct 2026 13:12:08 +0200 Subject: [PATCH 02/12] feat(director): Name the Instance's own id in its session's opening turn Co-Authored-By: Claude Opus 5.5 --- README.md | 2 + crates/core/src/director.rs | 61 +++++++++++++++++++++--------- crates/core/src/director/prompt.rs | 15 ++++++-- crates/core/src/roster.rs | 1 + src-tauri/src/harness.rs | 32 +++++++++------- 5 files changed, 76 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index f9d26f4fc..64f02ff42 100644 --- a/README.md +++ b/README.md @@ -336,6 +336,8 @@ Fidget attaches to a Harness over ACP on stdio. The Harness calls back over MCP, | `list_instances` | Identity | List Character Instances and their names | | `whereabouts` | Placement | Which display each Instance is on, the other displays, and its feet in that display. Each display includes its name when the platform has one, its origin, and its size, in logical points | +Every tool takes an optional `instance_id`. Each Character Instance has its own Harness session, and that session's opening turn names its id, so `speak` and `play_behavior` land on the Instance whose session called them. An id no running Instance has is refused. + **Three readonly resources** (`resources/list`, `resources/read`; no write, no subscribe): | URI | What it is | diff --git a/crates/core/src/director.rs b/crates/core/src/director.rs index 0b8e9d16d..157416fc1 100644 --- a/crates/core/src/director.rs +++ b/crates/core/src/director.rs @@ -353,7 +353,7 @@ impl ModelDirector { if self.opened.load(Ordering::SeqCst) { follow_up(context) } else { - character_prompt(context, self.behaviors.iter(), self.blank) + character_prompt(context, &self.instance, self.behaviors.iter(), self.blank) } } @@ -1844,7 +1844,7 @@ mod tests { fn the_completer_is_sent_the_character_prompt() { let director = directing(Scripted::says("wave"), ["wave"]); let moment = context(working(), &["nap"]); - let expected = character_prompt(&moment, ["wave"], false); + let expected = character_prompt(&moment, "buddy-1", ["wave"], false); director.wake(&moment); @@ -2145,7 +2145,7 @@ mod tests { caffeinate: None, }; - let payload = character_prompt(&moment, ["greet", "stroll", "wave"], false); + let payload = character_prompt(&moment, "buddy-1", ["greet", "stroll", "wave"], false); assert!( payload.contains("Blip is cheerful."), @@ -2208,7 +2208,7 @@ mod tests { fn an_empty_instance_prompt_assembles_the_payload_it_always_did() { let moment = context(working(), &["nap"]); - let payload = character_prompt(&moment, ["wave"], false); + let payload = character_prompt(&moment, "buddy-1", ["wave"], false); assert!( payload.starts_with("a shy robot.\n\nYou may propose one of these behaviors: wave"), @@ -2226,7 +2226,7 @@ mod tests { ..context(working(), &["nap"]) }; - let payload = character_prompt(&moment, ["wave"], false); + let payload = character_prompt(&moment, "buddy-1", ["wave"], false); let personality = payload.find("a shy robot.").expect("the author's layer"); let instance = payload.find("Answer in haiku.").expect("the user's layer"); @@ -2250,12 +2250,15 @@ mod tests { ..context(working(), &["nap"]) }; - let shaped = character_prompt(&moment, ["wave"], false); - let blank = character_prompt(&moment, ["wave"], true); + let shaped = character_prompt(&moment, "buddy-1", ["wave"], false); + let blank = character_prompt(&moment, "buddy-1", ["wave"], true); assert!( - blank.starts_with("Answer in haiku.\n\nwhat just happened:"), - "the Instance Prompt is still in front of the moment: {blank}" + blank.starts_with( + "Answer in haiku.\n\nYour instance_id is buddy-1. \ + Pass it to every tool you call.\n\nwhat just happened:" + ), + "the Instance Prompt and the id are still in front of the moment: {blank}" ); assert!( !blank.contains("a shy robot."), @@ -2298,7 +2301,7 @@ mod tests { #[test] fn a_request_invites_the_tools_without_naming_them() { let moment = context(working(), &["nap"]); - let opening = character_prompt(&moment, ["wave"], false); + let opening = character_prompt(&moment, "buddy-1", ["wave"], false); assert!( opening.contains( @@ -2348,10 +2351,34 @@ mod tests { } #[test] - fn blank_mode_without_an_instance_prompt_is_the_moment() { + fn blank_mode_without_an_instance_prompt_is_the_id_and_the_moment() { let moment = context(working(), &["nap"]); - let blank = character_prompt(&moment, ["wave"], true); - assert_eq!(blank, follow_up(&moment)); + let blank = character_prompt(&moment, "buddy-1", ["wave"], true); + assert_eq!( + blank, + format!( + "Your instance_id is buddy-1. Pass it to every tool you call.\n\n{}", + follow_up(&moment) + ) + ); + } + + /// Each session's opening names its own Instance, so a tool call made + /// from it lands there and not on another Instance (#1700). + #[test] + fn the_opening_names_this_instance_and_later_turns_do_not() { + let moment = context(working(), &["nap"]); + let pip = character_prompt(&moment, "pip", ["wave"], false); + let rex = character_prompt(&moment, "rex", ["wave"], false); + + assert!(pip.contains("Your instance_id is pip."), "{pip}"); + assert!(rex.contains("Your instance_id is rex."), "{rex}"); + assert!(!pip.contains("rex"), "{pip}"); + assert!( + !follow_up(&moment).contains("instance_id"), + "the id is the opening's only: {}", + follow_up(&moment) + ); } /// Each rule the opening turn must carry, and that later wakes do not @@ -2359,7 +2386,7 @@ mod tests { #[test] fn the_character_prompt_carries_the_voice_rules_once() { let moment = context(working(), &["nap"]); - let payload = character_prompt(&moment, ["wave"], false); + let payload = character_prompt(&moment, "buddy-1", ["wave"], false); assert!( payload.contains("always in character"), @@ -2517,7 +2544,7 @@ mod tests { Some(line), "follow-up: {line:?}" ); - let opening = character_prompt(&moment, ["wave"], false); + let opening = character_prompt(&moment, "buddy-1", ["wave"], false); assert_eq!(typed_line(&opening), Some(line), "opening: {line:?}"); } } @@ -2531,7 +2558,7 @@ mod tests { }; assert_eq!(typed_line(&follow_up(&ambient)), None); assert_eq!( - typed_line(&character_prompt(&ambient, ["wave"], false)), + typed_line(&character_prompt(&ambient, "buddy-1", ["wave"], false)), None ); assert_eq!(typed_line("an ordinary prompt"), None); @@ -2546,7 +2573,7 @@ mod tests { ..typed("hello?") }; assert_eq!( - typed_line(&character_prompt(&moment, ["wave"], false)), + typed_line(&character_prompt(&moment, "buddy-1", ["wave"], false)), Some("hello?") ); } diff --git a/crates/core/src/director/prompt.rs b/crates/core/src/director/prompt.rs index c9f4cd84b..5d6e6fc5b 100644 --- a/crates/core/src/director/prompt.rs +++ b/crates/core/src/director/prompt.rs @@ -1,14 +1,21 @@ use super::{Context, Doing, Happened, Lately, State, Step, CHAT_LIMIT}; -/// The opening turn: Personality Prompt, Instance Prompt (ADR-0012), roster -/// and moment; later wakes send `follow_up`. `blank` empties the built-in -/// layers for the control run, keeping the rest; its reply is prose. +/// The opening turn: Personality Prompt, Instance Prompt (ADR-0012), roster, +/// the Instance's own id and moment; later wakes send `follow_up`. `blank` +/// empties the built-in layers for the control run, keeping the rest; its +/// reply is prose. pub(crate) fn character_prompt( context: &Context, + instance: &str, behaviors: impl IntoIterator>, blank: bool, ) -> String { - let moment = follow_up(context); + // Every tool takes this id, and blank mode keeps it: it routes calls to + // this Instance, which is plumbing rather than voice (#1700). + let moment = format!( + "Your instance_id is {instance}. Pass it to every tool you call.\n\n{}", + follow_up(context) + ); // Empty, not `(no personality)`: that placeholder is a Character with an // empty file, which still gets the voice rules. Blank AI is the emptied diff --git a/crates/core/src/roster.rs b/crates/core/src/roster.rs index 41ec2a766..0afd4828d 100644 --- a/crates/core/src/roster.rs +++ b/crates/core/src/roster.rs @@ -976,6 +976,7 @@ mod tests { instance_prompt: instance.prompt().to_string(), ..crate::director::Context::quiet() }, + &id, wolf.behaviors.keys(), false, ); diff --git a/src-tauri/src/harness.rs b/src-tauri/src/harness.rs index 90244a1ec..a6263ad7c 100644 --- a/src-tauri/src/harness.rs +++ b/src-tauri/src/harness.rs @@ -6618,25 +6618,29 @@ mod tests { } /// Two Character Instances never share an ACP session, even when they - /// are the same Character. One Harness child throughout. + /// are the same Character, and turns that alternate between them each go + /// back to their own. One Harness child throughout. #[test] fn two_character_instances_do_not_share_an_acp_session() { let (fx, session) = Fixture::new("happy"); - assert_eq!( - session.complete(&asking_as("buddy-1", "bmo", "hi"), &|_| {}), - Ok(Reply::whole("Hello")) - ); - assert_eq!( - session.complete(&asking_as("buddy-2", "bmo", "hi"), &|_| {}), - Ok(Reply::whole("Hello")) - ); + for instance in ["buddy-1", "buddy-2", "buddy-1", "buddy-2"] { + assert_eq!( + session.complete(&asking_as(instance, "bmo", "hi"), &|_| {}), + Ok(Reply::whole("Hello")) + ); + } session.shutdown(); - let prompts = fx.events("prompt"); - assert_eq!(prompts.len(), 2, "{prompts:?}"); - assert_ne!( - prompts[0]["session_id"], prompts[1]["session_id"], - "Instance B continued Instance A's session: {prompts:?}" + let sessions = prompt_sessions(&fx); + assert_eq!( + sessions, + [ + json!("fresh-id"), + json!("fresh-id-2"), + json!("fresh-id"), + json!("fresh-id-2") + ], + "a turn went to another Instance's session" ); assert_eq!(fx.count("spawn"), 1, "a second Completer was spawned"); let saved: SavedSession = From 686d142df5058bef9c1efc637046b996f246d344 Mon Sep 17 00:00:00 2001 From: omesser Date: Wed, 28 Oct 2026 13:14:19 +0200 Subject: [PATCH 03/12] fix(mcp): Refuse a non-string instance_id and name the id line in the glossary Co-Authored-By: Claude Opus 5.5 --- GLOSSARY.md | 6 ++++-- crates/core/src/director.rs | 2 +- crates/core/src/director/prompt.rs | 2 +- crates/core/src/dispatch.rs | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/GLOSSARY.md b/GLOSSARY.md index 16546179f..0f561d050 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -38,7 +38,8 @@ _Avoid_: System prompt — that is the Character Prompt, which carries this and **Character Prompt**: The opening turn of the Director session: Personality Prompt, Instance Prompt, -the Behaviors it may propose, and this moment. Later wakes send a short +the Behaviors it may propose, the Instance's own id for its tool calls, and this +moment. Later wakes send a short follow-up (what just happened, recent Behaviors, time of day, State, what the user is doing) in the same conversation. Assembled rather than written: two of its layers are authored, the whole is never hand-authored. The Prompt tab shows @@ -58,7 +59,8 @@ The Director mode that empties the built-in prompt layers — the package Personality Prompt and the app-level instructions (voice rules, Behavior roster, reply contract) — and still sends an Instance Prompt the user wrote. Off by default. The Prompt tab shows those emptied fields as Empty: what you see is -what is sent. With no contract the reply is prose, so the character talks and plays +what is sent, apart from the Instance id line, which stays so tool calls still +reach this Instance. With no contract the reply is prose, so the character talks and plays no Behavior unless the Instance Prompt asks for one. That is the control run for telling a model's misbehaviour apart from the shipped prompt, and for iterating a prompt under Fidget's conditions. #657, #680. diff --git a/crates/core/src/director.rs b/crates/core/src/director.rs index 157416fc1..13e194fe0 100644 --- a/crates/core/src/director.rs +++ b/crates/core/src/director.rs @@ -2364,7 +2364,7 @@ mod tests { } /// Each session's opening names its own Instance, so a tool call made - /// from it lands there and not on another Instance (#1700). + /// from it lands there and not on another Instance. #[test] fn the_opening_names_this_instance_and_later_turns_do_not() { let moment = context(working(), &["nap"]); diff --git a/crates/core/src/director/prompt.rs b/crates/core/src/director/prompt.rs index 5d6e6fc5b..5c014f000 100644 --- a/crates/core/src/director/prompt.rs +++ b/crates/core/src/director/prompt.rs @@ -11,7 +11,7 @@ pub(crate) fn character_prompt( blank: bool, ) -> String { // Every tool takes this id, and blank mode keeps it: it routes calls to - // this Instance, which is plumbing rather than voice (#1700). + // this Instance, which is plumbing rather than voice. let moment = format!( "Your instance_id is {instance}. Pass it to every tool you call.\n\n{}", follow_up(context) diff --git a/crates/core/src/dispatch.rs b/crates/core/src/dispatch.rs index c0158cf00..2f8b8a429 100644 --- a/crates/core/src/dispatch.rs +++ b/crates/core/src/dispatch.rs @@ -101,11 +101,17 @@ pub fn dispatch( context: &mut DispatchContext, ) -> Result { // One gate for every tool, so a tool added later refuses a stray id too. - if let Some(id) = arguments.get("instance_id").and_then(Value::as_str) { + if let Some(given) = arguments + .get("instance_id") + .filter(|given| !given.is_null()) + { + let id = given + .as_str() + .map_or_else(|| given.to_string(), str::to_string); if !context.roster.iter().any(|info| info.id == id) { return Err(DispatchError { code: ErrorCode::InvalidArguments, - message: unknown_instance(id, context.roster), + message: unknown_instance(&id, context.roster), }); } } @@ -1148,6 +1154,10 @@ mod tests { .expect("a known id is accepted"); assert_eq!(result["windows"][0]["owner"], "Terminal"); + assert!( + dispatch("list_windows", json!({"instance_id": 5}), &mut context).is_err(), + "an id that is not a string slipped past the check" + ); } /// Optional, so the stdio shim in the user's own sessions keeps working From 1f1ed46d303a423c46b26f6e42e95883b37c95c1 Mon Sep 17 00:00:00 2001 From: omesser Date: Wed, 28 Oct 2026 22:25:26 +0200 Subject: [PATCH 04/12] feat(mcp): Return each Instance's prompt layers from list_instances A session the Harness opens mid-run gets the follow-up, never the opening, so it lacks its instance_id and Character Prompt. list_instances now returns each Instance's id and its three prompt layers, so that session can read them back. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- crates/core/src/dispatch.rs | 50 +++++++++++++++++++++--- crates/core/src/tools.rs | 12 +++++- src-tauri/src/frame_loop.rs | 77 ++++++++++++++++++++++++++++++++++++- 4 files changed, 131 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 64f02ff42..752e6b6b6 100644 --- a/README.md +++ b/README.md @@ -333,7 +333,7 @@ Fidget attaches to a Harness over ACP on stdio. The Harness calls back over MCP, | `describe_screen` | Sensing | Describe screen (v1: window metadata only) | | `recall` | Memory | Read everything Memory holds | | `remember` | Memory | Write one fact under a heading | -| `list_instances` | Identity | List Character Instances and their names | +| `list_instances` | Identity | List Character Instances: id, name, and the three Character Prompt layers | | `whereabouts` | Placement | Which display each Instance is on, the other displays, and its feet in that display. Each display includes its name when the platform has one, its origin, and its size, in logical points | Every tool takes an optional `instance_id`. Each Character Instance has its own Harness session, and that session's opening turn names its id, so `speak` and `play_behavior` land on the Instance whose session called them. An id no running Instance has is refused. diff --git a/crates/core/src/dispatch.rs b/crates/core/src/dispatch.rs index 2f8b8a429..543a1eae0 100644 --- a/crates/core/src/dispatch.rs +++ b/crates/core/src/dispatch.rs @@ -336,7 +336,7 @@ pub fn list_tools() -> Vec { }, ToolInfo { name: "list_instances".to_string(), - description: "List Character Instances and their names".to_string(), + description: "List Character Instances: each one's instance_id, name, and the three layers of its Character Prompt (app_instructions, personality_prompt, instance_prompt). Read it when your session did not open with your instance_id or prompt.".to_string(), input_schema: serde_json::json!({ "type": "object", "properties": {} @@ -496,10 +496,14 @@ mod tests { InstanceInfo { id: "inst-1".to_string(), name: "Clippy".to_string(), + app_instructions: "Reply with behavior: ".to_string(), + personality_prompt: "a paperclip".to_string(), + instance_prompt: "Answer in haiku.".to_string(), }, InstanceInfo { id: "inst-2".to_string(), name: "Ferris".to_string(), + ..Default::default() }, ]; let source = fake_source(vec![]); @@ -512,6 +516,13 @@ mod tests { assert_eq!(instances.len(), 2); assert_eq!(instances[0]["id"], "inst-1"); assert_eq!(instances[0]["name"], "Clippy"); + assert_eq!( + instances[0]["app_instructions"], + "Reply with behavior: " + ); + assert_eq!(instances[0]["personality_prompt"], "a paperclip"); + assert_eq!(instances[0]["instance_prompt"], "Answer in haiku."); + assert_eq!(instances[1]["instance_prompt"], ""); } #[test] @@ -876,7 +887,11 @@ mod tests { .borrow() .list() .into_iter() - .map(|(id, name)| InstanceInfo { id, name }) + .map(|(id, name)| InstanceInfo { + id, + name, + ..Default::default() + }) .collect::>(); let mut expression = SharedRoster(Rc::clone(&shared)); @@ -923,7 +938,11 @@ mod tests { let roster_info = roster .list() .into_iter() - .map(|(id, name)| InstanceInfo { id, name }) + .map(|(id, name)| InstanceInfo { + id, + name, + ..Default::default() + }) .collect::>(); let mut context = DispatchContext { @@ -962,7 +981,11 @@ mod tests { let roster_info = roster .list() .into_iter() - .map(|(id, name)| InstanceInfo { id, name }) + .map(|(id, name)| InstanceInfo { + id, + name, + ..Default::default() + }) .collect::>(); let mut context = DispatchContext { @@ -1027,7 +1050,11 @@ mod tests { let roster_info = roster .list() .into_iter() - .map(|(id, name)| InstanceInfo { id, name }) + .map(|(id, name)| InstanceInfo { + id, + name, + ..Default::default() + }) .collect::>(); let mut context = DispatchContext { @@ -1069,10 +1096,12 @@ mod tests { InstanceInfo { id: "instance-1".to_string(), name: "First".to_string(), + ..Default::default() }, InstanceInfo { id: "instance-2".to_string(), name: "Second".to_string(), + ..Default::default() }, ]; let mut context = test_context(&temp, &source, &infos); @@ -1098,10 +1127,12 @@ mod tests { InstanceInfo { id: "pip".to_string(), name: "Pip".to_string(), + ..Default::default() }, InstanceInfo { id: "rex".to_string(), name: "Rex".to_string(), + ..Default::default() }, ]; let mut context = test_context(&temp, &source, &infos); @@ -1147,6 +1178,7 @@ mod tests { let infos = [InstanceInfo { id: "pip".to_string(), name: "Pip".to_string(), + ..Default::default() }]; let mut context = test_context(&temp, &source, &infos); @@ -1237,6 +1269,7 @@ mod tests { let infos = [InstanceInfo { id: "instance-1".to_string(), name: "Buddy".to_string(), + ..Default::default() }]; // `test_context` carries `expression: None`, which is the shipped // stdio shape. @@ -1267,6 +1300,7 @@ mod tests { let roster_info = [InstanceInfo { id: "retired-instance".to_string(), name: "Gone".to_string(), + ..Default::default() }]; let mut live = crate::roster::Roster::new(); @@ -1299,7 +1333,11 @@ mod tests { let roster_info = roster .list() .into_iter() - .map(|(id, name)| InstanceInfo { id, name }) + .map(|(id, name)| InstanceInfo { + id, + name, + ..Default::default() + }) .collect::>(); let mut context = DispatchContext { diff --git a/crates/core/src/tools.rs b/crates/core/src/tools.rs index b0c5fdae1..dbed65ffc 100644 --- a/crates/core/src/tools.rs +++ b/crates/core/src/tools.rs @@ -77,11 +77,19 @@ pub struct RememberResult { pub recorded: String, } -/// Tool result for the `list_instances` tool. -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +/// Tool result for the `list_instances` tool. The three prompts are the +/// Character Prompt layers the Prompt tab shows, so a session that never +/// heard its opening can read them back (ADR-0012). +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct InstanceInfo { pub id: String, pub name: String, + #[serde(default)] + pub app_instructions: String, + #[serde(default)] + pub personality_prompt: String, + #[serde(default)] + pub instance_prompt: String, } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src-tauri/src/frame_loop.rs b/src-tauri/src/frame_loop.rs index dd801413b..1026d7361 100644 --- a/src-tauri/src/frame_loop.rs +++ b/src-tauri/src/frame_loop.rs @@ -1159,6 +1159,7 @@ pub(crate) fn run_frame_loop( answer_tool_call( call, &mut roster, + &characters, assembler.source(), excluded, &displays, @@ -2925,16 +2926,41 @@ fn replace_session( fn answer_tool_call( call: mcp_http::Call, roster: &mut Roster, + characters: &std::collections::BTreeMap>, source: &dyn WindowSource, excluded_applications: Vec, displays: &platform::Displays, caffeinate: Option<&mut dyn fidget_core::caffeinate::CaffeinateHandle>, ) { let watched = crate::names_hint::live().watching(source); + // The layers the Prompt tab shows, so a session opened mid-run can read + // what its opening turn would have told it. + let blank = model::blank(); let live: Vec = roster .list() .into_iter() - .map(|(id, name)| InstanceInfo { id, name }) + .map(|(id, name)| { + let Some(instance) = roster.get(&id) else { + return InstanceInfo { + id, + name, + ..Default::default() + }; + }; + InstanceInfo { + app_instructions: director::app_instructions( + super::behavior_names_of(characters, instance), + blank, + ), + personality_prompt: match blank { + true => String::new(), + false => super::personality_of(characters, instance), + }, + instance_prompt: instance.prompt().to_string(), + id, + name, + } + }) .collect(); let spots: Vec = live .iter() @@ -3153,6 +3179,7 @@ mod tests { reply, }, &mut roster, + &std::collections::BTreeMap::new(), &EmptyDesktop, Vec::new(), &platform::Displays::default(), @@ -3175,6 +3202,53 @@ mod tests { std::fs::remove_dir_all(&dir).ok(); } + /// A session the Harness opened mid-run never heard its opening turn. It + /// reads its id and the three prompt layers back from the live Instance. + #[test] + fn a_list_instances_call_carries_the_live_prompt_layers() { + let mut roster = Roster::new(); + let id = roster.spawn(&character(), "Pip".to_string(), Point { x: 0.0, y: 0.0 }); + roster + .get_mut(&id) + .expect("just spawned") + .set_prompt("Answer in haiku.".to_string()); + let characters = std::collections::BTreeMap::from([( + "Buddy".to_string(), + Arc::new(Character { + personality: "a shy robot.".to_string(), + ..character() + }), + )]); + + let (reply, answers) = mpsc::channel(); + answer_tool_call( + mcp_http::Call { + tool: "list_instances".to_string(), + arguments: json!({}), + reply, + }, + &mut roster, + &characters, + &EmptyDesktop, + Vec::new(), + &platform::Displays::default(), + None, + ); + let result = answers + .recv() + .expect("the call is answered") + .expect("dispatch succeeds"); + + let pip = &result["instances"][0]; + assert_eq!(pip["id"], json!(id)); + assert_eq!( + pip["app_instructions"], + json!(director::app_instructions(["wave"], false)) + ); + assert_eq!(pip["personality_prompt"], json!("a shy robot.")); + assert_eq!(pip["instance_prompt"], json!("Answer in haiku.")); + } + /// The Harness reads placement from the live Instances and the displays /// the frame loop already holds. #[test] @@ -3215,6 +3289,7 @@ mod tests { reply, }, &mut roster, + &std::collections::BTreeMap::new(), &EmptyDesktop, Vec::new(), &displays, From 2c9fb9d4717b89ac13f8159c8e70e7c917b71edd Mon Sep 17 00:00:00 2001 From: omesser Date: Wed, 28 Oct 2026 22:53:34 +0200 Subject: [PATCH 05/12] fix(mcp): Refuse a non-string instance_id before comparing it A number was printed and compared to roster ids, so the refusal looked like an unknown id. --- crates/core/src/dispatch.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/core/src/dispatch.rs b/crates/core/src/dispatch.rs index 543a1eae0..e6396b6ed 100644 --- a/crates/core/src/dispatch.rs +++ b/crates/core/src/dispatch.rs @@ -105,13 +105,16 @@ pub fn dispatch( .get("instance_id") .filter(|given| !given.is_null()) { - let id = given - .as_str() - .map_or_else(|| given.to_string(), str::to_string); + let Some(id) = given.as_str() else { + return Err(DispatchError { + code: ErrorCode::InvalidArguments, + message: "instance_id must be a string".to_string(), + }); + }; if !context.roster.iter().any(|info| info.id == id) { return Err(DispatchError { code: ErrorCode::InvalidArguments, - message: unknown_instance(&id, context.roster), + message: unknown_instance(id, context.roster), }); } } @@ -1186,10 +1189,10 @@ mod tests { .expect("a known id is accepted"); assert_eq!(result["windows"][0]["owner"], "Terminal"); - assert!( - dispatch("list_windows", json!({"instance_id": 5}), &mut context).is_err(), - "an id that is not a string slipped past the check" - ); + let refused = dispatch("list_windows", json!({"instance_id": 5}), &mut context) + .expect_err("an id that is not a string slipped past the check"); + assert_eq!(refused.code, ErrorCode::InvalidArguments); + assert_eq!(refused.message, "instance_id must be a string"); } /// Optional, so the stdio shim in the user's own sessions keeps working From 0c27062a1b264a447bb3fe1aa84bd711531523d3 Mon Sep 17 00:00:00 2001 From: omesser Date: Wed, 28 Oct 2026 23:36:20 +0200 Subject: [PATCH 06/12] fix(mcp): Send a call without instance_id to the first Instance instance_id is optional, so leaving it out must not fail speak or play_behavior when several Instances run. The Shell logs a warning and the call goes to the first Instance in the roster. Co-Authored-By: Claude Opus 5.5 --- crates/core/src/dispatch.rs | 33 ++++++++++++++++++++++----------- crates/core/src/tools.rs | 16 +++++----------- src-tauri/src/frame_loop.rs | 13 +++++++++++++ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/crates/core/src/dispatch.rs b/crates/core/src/dispatch.rs index e6396b6ed..5ce02dd1e 100644 --- a/crates/core/src/dispatch.rs +++ b/crates/core/src/dispatch.rs @@ -370,7 +370,7 @@ pub fn list_tools() -> Vec { for tool in &mut tools { tool.input_schema["properties"]["instance_id"] = serde_json::json!({ "type": "string", - "description": "Your Character Instance id, named in your opening prompt. speak and play_behavior act on that Instance. Optional while only one Instance runs." + "description": "Your Character Instance id, named in your opening prompt. speak and play_behavior act on that Instance. Optional: without it, the call goes to the first running Instance." }); } tools @@ -1091,8 +1091,18 @@ mod tests { ); } + /// `instance_id` is optional, so leaving it out never fails the call: it + /// goes to the first Instance in the roster. #[test] - fn omitted_instance_id_with_several_instances_is_failure() { + fn omitted_instance_id_with_several_instances_goes_to_the_first() { + struct Recorded(Vec); + impl crate::tools::ExpressionHandle for Recorded { + fn enqueue(&mut self, instance_id: &str, _: crate::engine::BehaviorProposal) -> bool { + self.0.push(instance_id.to_string()); + true + } + } + let temp = tempfile::tempdir().expect("temp dir is creatable"); let source = fake_source(vec![]); let infos = [ @@ -1107,17 +1117,18 @@ mod tests { ..Default::default() }, ]; - let mut context = test_context(&temp, &source, &infos); + let mut recorded = Recorded(Vec::new()); + let mut context = DispatchContext { + expression: Some(&mut recorded), + ..test_context(&temp, &source, &infos) + }; - let args = json!({"message": "Hello"}); - let result = dispatch("speak", args, &mut context).expect("dispatch succeeds"); + let result = dispatch("speak", json!({"message": "Hello"}), &mut context) + .expect("dispatch succeeds"); - assert_eq!(result["success"], false); - assert_eq!(result["message"], "Hello"); - assert_eq!( - result["reason"], - "Several Character Instances are running; name one with instance_id" - ); + assert_eq!(result["success"], true, "{result}"); + drop(context); + assert_eq!(recorded.0, ["instance-1"]); } /// Every tool, not only the Expression ones, refuses an id no Instance diff --git a/crates/core/src/tools.rs b/crates/core/src/tools.rs index dbed65ffc..4ebb52a90 100644 --- a/crates/core/src/tools.rs +++ b/crates/core/src/tools.rs @@ -260,12 +260,6 @@ mod helpers { "No Character Instance is running, so nothing changed on screen".to_string(), ); } - TargetResolution::AmbiguousTarget => { - return Err( - "Several Character Instances are running; name one with instance_id" - .to_string(), - ); - } }; // No handle is no way to reach the Instance the roster just named, so @@ -293,7 +287,6 @@ mod helpers { enum TargetResolution { Resolved(String), NoInstances, - AmbiguousTarget, } /// Target resolution against roster for both speak and play_behavior. @@ -304,10 +297,11 @@ mod helpers { ) -> TargetResolution { match instance_id { Some(id) => TargetResolution::Resolved(id.to_string()), - None => match roster.len() { - 0 => TargetResolution::NoInstances, - 1 => TargetResolution::Resolved(roster[0].id.clone()), - _ => TargetResolution::AmbiguousTarget, + // Optional, so a missing id never fails the call. The Shell + // warns when several run and this picks the first. + None => match roster.first() { + None => TargetResolution::NoInstances, + Some(first) => TargetResolution::Resolved(first.id.clone()), }, } } diff --git a/src-tauri/src/frame_loop.rs b/src-tauri/src/frame_loop.rs index 1026d7361..5ce991afc 100644 --- a/src-tauri/src/frame_loop.rs +++ b/src-tauri/src/frame_loop.rs @@ -2990,6 +2990,19 @@ fn answer_tool_call( }, caffeinate, }; + let targets = matches!(call.tool.as_str(), "speak" | "play_behavior"); + let named = call + .arguments + .get("instance_id") + .is_some_and(|id| !id.is_null()); + if let (true, false, [first, _, ..]) = (targets, named, live.as_slice()) { + eprintln!( + "mcp: {} named no instance_id while {} Instances run; using the first, {}", + call.tool, + live.len(), + first.id + ); + } let _ = call .reply .send(dispatch(&call.tool, call.arguments, &mut context)); From 3aa6562d15674e6e5c486f6c288fa620b71c99e2 Mon Sep 17 00:00:00 2001 From: omesser Date: Thu, 29 Oct 2026 10:53:49 +0200 Subject: [PATCH 07/12] perf(mcp): Build the prompt layers only for list_instances Every tool call composed every Instance's prompt layers, and only list_instances returns them. Co-Authored-By: Claude Opus 5.5 --- src-tauri/src/frame_loop.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/frame_loop.rs b/src-tauri/src/frame_loop.rs index 5ce991afc..3cc638995 100644 --- a/src-tauri/src/frame_loop.rs +++ b/src-tauri/src/frame_loop.rs @@ -2934,13 +2934,15 @@ fn answer_tool_call( ) { let watched = crate::names_hint::live().watching(source); // The layers the Prompt tab shows, so a session opened mid-run can read - // what its opening turn would have told it. + // what its opening turn would have told it. Only list_instances returns + // them, so no other call pays for building them. + let with_prompts = call.tool == "list_instances"; let blank = model::blank(); let live: Vec = roster .list() .into_iter() .map(|(id, name)| { - let Some(instance) = roster.get(&id) else { + let Some(instance) = roster.get(&id).filter(|_| with_prompts) else { return InstanceInfo { id, name, From 657bd4c5d6083be87024826bb97d17a35e547d15 Mon Sep 17 00:00:00 2001 From: omesser Date: Thu, 29 Oct 2026 11:55:30 +0200 Subject: [PATCH 08/12] fix(mcp): Fail a call without instance_id when several Instances run Reverts 0c27062a. The owner took back the silent fallback: it applies only when one Instance runs, and with more the call fails as an ambiguous target, as on main. Co-Authored-By: Claude Opus 5.5 --- crates/core/src/dispatch.rs | 33 +++++++++++---------------------- crates/core/src/tools.rs | 16 +++++++++++----- src-tauri/src/frame_loop.rs | 13 ------------- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/crates/core/src/dispatch.rs b/crates/core/src/dispatch.rs index 5ce02dd1e..e6396b6ed 100644 --- a/crates/core/src/dispatch.rs +++ b/crates/core/src/dispatch.rs @@ -370,7 +370,7 @@ pub fn list_tools() -> Vec { for tool in &mut tools { tool.input_schema["properties"]["instance_id"] = serde_json::json!({ "type": "string", - "description": "Your Character Instance id, named in your opening prompt. speak and play_behavior act on that Instance. Optional: without it, the call goes to the first running Instance." + "description": "Your Character Instance id, named in your opening prompt. speak and play_behavior act on that Instance. Optional while only one Instance runs." }); } tools @@ -1091,18 +1091,8 @@ mod tests { ); } - /// `instance_id` is optional, so leaving it out never fails the call: it - /// goes to the first Instance in the roster. #[test] - fn omitted_instance_id_with_several_instances_goes_to_the_first() { - struct Recorded(Vec); - impl crate::tools::ExpressionHandle for Recorded { - fn enqueue(&mut self, instance_id: &str, _: crate::engine::BehaviorProposal) -> bool { - self.0.push(instance_id.to_string()); - true - } - } - + fn omitted_instance_id_with_several_instances_is_failure() { let temp = tempfile::tempdir().expect("temp dir is creatable"); let source = fake_source(vec![]); let infos = [ @@ -1117,18 +1107,17 @@ mod tests { ..Default::default() }, ]; - let mut recorded = Recorded(Vec::new()); - let mut context = DispatchContext { - expression: Some(&mut recorded), - ..test_context(&temp, &source, &infos) - }; + let mut context = test_context(&temp, &source, &infos); - let result = dispatch("speak", json!({"message": "Hello"}), &mut context) - .expect("dispatch succeeds"); + let args = json!({"message": "Hello"}); + let result = dispatch("speak", args, &mut context).expect("dispatch succeeds"); - assert_eq!(result["success"], true, "{result}"); - drop(context); - assert_eq!(recorded.0, ["instance-1"]); + assert_eq!(result["success"], false); + assert_eq!(result["message"], "Hello"); + assert_eq!( + result["reason"], + "Several Character Instances are running; name one with instance_id" + ); } /// Every tool, not only the Expression ones, refuses an id no Instance diff --git a/crates/core/src/tools.rs b/crates/core/src/tools.rs index 4ebb52a90..dbed65ffc 100644 --- a/crates/core/src/tools.rs +++ b/crates/core/src/tools.rs @@ -260,6 +260,12 @@ mod helpers { "No Character Instance is running, so nothing changed on screen".to_string(), ); } + TargetResolution::AmbiguousTarget => { + return Err( + "Several Character Instances are running; name one with instance_id" + .to_string(), + ); + } }; // No handle is no way to reach the Instance the roster just named, so @@ -287,6 +293,7 @@ mod helpers { enum TargetResolution { Resolved(String), NoInstances, + AmbiguousTarget, } /// Target resolution against roster for both speak and play_behavior. @@ -297,11 +304,10 @@ mod helpers { ) -> TargetResolution { match instance_id { Some(id) => TargetResolution::Resolved(id.to_string()), - // Optional, so a missing id never fails the call. The Shell - // warns when several run and this picks the first. - None => match roster.first() { - None => TargetResolution::NoInstances, - Some(first) => TargetResolution::Resolved(first.id.clone()), + None => match roster.len() { + 0 => TargetResolution::NoInstances, + 1 => TargetResolution::Resolved(roster[0].id.clone()), + _ => TargetResolution::AmbiguousTarget, }, } } diff --git a/src-tauri/src/frame_loop.rs b/src-tauri/src/frame_loop.rs index 3cc638995..cf8eee34f 100644 --- a/src-tauri/src/frame_loop.rs +++ b/src-tauri/src/frame_loop.rs @@ -2992,19 +2992,6 @@ fn answer_tool_call( }, caffeinate, }; - let targets = matches!(call.tool.as_str(), "speak" | "play_behavior"); - let named = call - .arguments - .get("instance_id") - .is_some_and(|id| !id.is_null()); - if let (true, false, [first, _, ..]) = (targets, named, live.as_slice()) { - eprintln!( - "mcp: {} named no instance_id while {} Instances run; using the first, {}", - call.tool, - live.len(), - first.id - ); - } let _ = call .reply .send(dispatch(&call.tool, call.arguments, &mut context)); From f5a96fdb84f0aac0e355adc199b46c28f2820327 Mon Sep 17 00:00:00 2001 From: omesser Date: Thu, 29 Oct 2026 12:02:19 +0200 Subject: [PATCH 09/12] feat(director): Name the Instance's id on every turn A session the Harness opens mid-run hears only follow-ups, so it never learned its id. A missing or unknown id now points the agent at list_instances. Co-Authored-By: Claude Opus 5.5 --- GLOSSARY.md | 2 +- crates/core/src/director.rs | 24 ++++++++++++++++-------- crates/core/src/director/prompt.rs | 18 ++++++++++++------ crates/core/src/dispatch.rs | 9 +++++---- crates/core/src/tools.rs | 3 ++- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/GLOSSARY.md b/GLOSSARY.md index 0f561d050..dcfe72b12 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -40,7 +40,7 @@ _Avoid_: System prompt — that is the Character Prompt, which carries this and The opening turn of the Director session: Personality Prompt, Instance Prompt, the Behaviors it may propose, the Instance's own id for its tool calls, and this moment. Later wakes send a short -follow-up (what just happened, recent Behaviors, time of day, State, what the +follow-up (the Instance's id, what just happened, recent Behaviors, time of day, State, what the user is doing) in the same conversation. Assembled rather than written: two of its layers are authored, the whole is never hand-authored. The Prompt tab shows the three concatenated layers — app-level instructions, Personality Prompt, diff --git a/crates/core/src/director.rs b/crates/core/src/director.rs index 13e194fe0..f0f745886 100644 --- a/crates/core/src/director.rs +++ b/crates/core/src/director.rs @@ -26,8 +26,10 @@ use crate::sensing::Activity; mod prompt; mod recency; +#[cfg(test)] +use prompt::follow_up; pub use prompt::{app_instructions, happened_word, typed_line}; -pub(crate) use prompt::{character_prompt, follow_up}; +pub(crate) use prompt::{character_prompt, named_moment}; pub use recency::{Doing, Lately, Recency, Step}; /// How long the Static Director goes unwoken when nothing notable happens. @@ -351,7 +353,7 @@ impl ModelDirector { /// The user turn for this wake. Settings shows this string. pub fn prompt(&self, context: &Context) -> String { if self.opened.load(Ordering::SeqCst) { - follow_up(context) + named_moment(context, &self.instance) } else { character_prompt(context, &self.instance, self.behaviors.iter(), self.blank) } @@ -2366,7 +2368,7 @@ mod tests { /// Each session's opening names its own Instance, so a tool call made /// from it lands there and not on another Instance. #[test] - fn the_opening_names_this_instance_and_later_turns_do_not() { + fn every_turn_names_this_instance() { let moment = context(working(), &["nap"]); let pip = character_prompt(&moment, "pip", ["wave"], false); let rex = character_prompt(&moment, "rex", ["wave"], false); @@ -2374,11 +2376,17 @@ mod tests { assert!(pip.contains("Your instance_id is pip."), "{pip}"); assert!(rex.contains("Your instance_id is rex."), "{rex}"); assert!(!pip.contains("rex"), "{pip}"); + + // A session the Harness opened mid-run hears only follow-ups, so they + // carry the id too. + let director = directing(Scripted::says("wave"), ["wave"]); + director.wake(&moment); + let later = director.prompt(&moment); assert!( - !follow_up(&moment).contains("instance_id"), - "the id is the opening's only: {}", - follow_up(&moment) + later.starts_with("Your instance_id is buddy-1. Pass it to every tool you call.\n\n"), + "{later}" ); + assert!(!later.contains("always in character"), "{later}"); } /// Each rule the opening turn must carry, and that later wakes do not @@ -2432,7 +2440,7 @@ mod tests { .completer .seen_prompt() .expect("a follow-up was sent"); - assert_eq!(sent, follow_up(&later)); + assert_eq!(sent, named_moment(&later, "buddy-1")); assert!( !sent.contains("a shy robot."), "personality is the opening only: {sent}" @@ -2936,7 +2944,7 @@ mod tests { .completer .seen_prompt() .expect("a follow-up was sent"); - assert_eq!(sent, follow_up(&asked)); + assert_eq!(sent, named_moment(&asked, "buddy-1")); assert!( !sent.contains("a shy robot."), "personality is the opening only: {sent}" diff --git a/crates/core/src/director/prompt.rs b/crates/core/src/director/prompt.rs index 5c014f000..9dd7a75e7 100644 --- a/crates/core/src/director/prompt.rs +++ b/crates/core/src/director/prompt.rs @@ -10,12 +10,7 @@ pub(crate) fn character_prompt( behaviors: impl IntoIterator>, blank: bool, ) -> String { - // Every tool takes this id, and blank mode keeps it: it routes calls to - // this Instance, which is plumbing rather than voice. - let moment = format!( - "Your instance_id is {instance}. Pass it to every tool you call.\n\n{}", - follow_up(context) - ); + let moment = named_moment(context, instance); // Empty, not `(no personality)`: that placeholder is a Character with an // empty file, which still gets the voice rules. Blank AI is the emptied @@ -47,6 +42,17 @@ pub(crate) fn character_prompt( } } +/// The moment, led by this Instance's id. Every turn carries the id, and +/// blank mode keeps it: it routes tool calls to this Instance, which is +/// plumbing rather than voice, and a session the Harness opened mid-run hears +/// only follow-ups. +pub(crate) fn named_moment(context: &Context, instance: &str) -> String { + format!( + "Your instance_id is {instance}. Pass it to every tool you call.\n\n{}", + follow_up(context) + ) +} + /// The app layer of the Character Prompt: voice rules, roster, reply contract. /// Empty under Blank AI, which the Prompt tab shows frozen. Paid every wake, /// so the tools describe themselves over MCP; a copy here would drift. diff --git a/crates/core/src/dispatch.rs b/crates/core/src/dispatch.rs index e6396b6ed..1e365710e 100644 --- a/crates/core/src/dispatch.rs +++ b/crates/core/src/dispatch.rs @@ -91,7 +91,7 @@ fn unknown_instance(id: &str, roster: &[InstanceInfo]) -> String { .join(", "); format!( "No Character Instance has id {id}. Running: {running}. \ - Pass your own instance_id from your opening prompt." + Pass your own instance_id from your prompt, or call list_instances to find it." ) } @@ -370,7 +370,7 @@ pub fn list_tools() -> Vec { for tool in &mut tools { tool.input_schema["properties"]["instance_id"] = serde_json::json!({ "type": "string", - "description": "Your Character Instance id, named in your opening prompt. speak and play_behavior act on that Instance. Optional while only one Instance runs." + "description": "Your Character Instance id, named in your prompt. speak and play_behavior act on that Instance. Optional while only one Instance runs." }); } tools @@ -1116,7 +1116,8 @@ mod tests { assert_eq!(result["message"], "Hello"); assert_eq!( result["reason"], - "Several Character Instances are running; name one with instance_id" + "Several Character Instances are running; name one with instance_id. \ + Call list_instances to find each one's instance_id." ); } @@ -1151,7 +1152,7 @@ mod tests { assert_eq!( refused.message, "No Character Instance has id nope. Running: pip (Pip), rex (Rex). \ - Pass your own instance_id from your opening prompt.", + Pass your own instance_id from your prompt, or call list_instances to find it.", "{}", tool.name ); diff --git a/crates/core/src/tools.rs b/crates/core/src/tools.rs index dbed65ffc..d8c11c355 100644 --- a/crates/core/src/tools.rs +++ b/crates/core/src/tools.rs @@ -262,7 +262,8 @@ mod helpers { } TargetResolution::AmbiguousTarget => { return Err( - "Several Character Instances are running; name one with instance_id" + "Several Character Instances are running; name one with instance_id. \ + Call list_instances to find each one's instance_id." .to_string(), ); } From fd0944b302a8efc28e1e327e697dab6f08a35179 Mon Sep 17 00:00:00 2001 From: Oded Messer Date: Thu, 29 Oct 2026 12:07:09 +0200 Subject: [PATCH 10/12] Apply suggestion from @omesser minor edit of the named moment to specify it's fidget scoped --- crates/core/src/director/prompt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/director/prompt.rs b/crates/core/src/director/prompt.rs index 9dd7a75e7..bb401be7f 100644 --- a/crates/core/src/director/prompt.rs +++ b/crates/core/src/director/prompt.rs @@ -48,7 +48,7 @@ pub(crate) fn character_prompt( /// only follow-ups. pub(crate) fn named_moment(context: &Context, instance: &str) -> String { format!( - "Your instance_id is {instance}. Pass it to every tool you call.\n\n{}", + "Your instance_id is {instance}. Pass it to every Fidget tool you call.\n\n{}", follow_up(context) ) } From b4b658b6e79c4329ca3feb8d6ce34f580c884432 Mon Sep 17 00:00:00 2001 From: omesser Date: Thu, 29 Oct 2026 12:07:45 +0200 Subject: [PATCH 11/12] test(director): Expect the Fidget tool wording in the id line Co-Authored-By: Claude Opus 5.5 --- crates/core/src/director.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/core/src/director.rs b/crates/core/src/director.rs index f0f745886..d02a72648 100644 --- a/crates/core/src/director.rs +++ b/crates/core/src/director.rs @@ -2258,7 +2258,7 @@ mod tests { assert!( blank.starts_with( "Answer in haiku.\n\nYour instance_id is buddy-1. \ - Pass it to every tool you call.\n\nwhat just happened:" + Pass it to every Fidget tool you call.\n\nwhat just happened:" ), "the Instance Prompt and the id are still in front of the moment: {blank}" ); @@ -2359,7 +2359,7 @@ mod tests { assert_eq!( blank, format!( - "Your instance_id is buddy-1. Pass it to every tool you call.\n\n{}", + "Your instance_id is buddy-1. Pass it to every Fidget tool you call.\n\n{}", follow_up(&moment) ) ); @@ -2383,7 +2383,9 @@ mod tests { director.wake(&moment); let later = director.prompt(&moment); assert!( - later.starts_with("Your instance_id is buddy-1. Pass it to every tool you call.\n\n"), + later.starts_with( + "Your instance_id is buddy-1. Pass it to every Fidget tool you call.\n\n" + ), "{later}" ); assert!(!later.contains("always in character"), "{later}"); From 97fb9f439aa1edca6fd7ef596edbc1c3c95a6799 Mon Sep 17 00:00:00 2001 From: omesser Date: Thu, 29 Oct 2026 12:14:56 +0200 Subject: [PATCH 12/12] docs(director): Name named_moment as what later wakes send Co-Authored-By: Claude Opus 5.5 --- crates/core/src/director/prompt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/director/prompt.rs b/crates/core/src/director/prompt.rs index bb401be7f..927304b52 100644 --- a/crates/core/src/director/prompt.rs +++ b/crates/core/src/director/prompt.rs @@ -1,7 +1,7 @@ use super::{Context, Doing, Happened, Lately, State, Step, CHAT_LIMIT}; /// The opening turn: Personality Prompt, Instance Prompt (ADR-0012), roster, -/// the Instance's own id and moment; later wakes send `follow_up`. `blank` +/// the Instance's own id and moment; later wakes send `named_moment`. `blank` /// empties the built-in layers for the control run, keeping the rest; its /// reply is prose. pub(crate) fn character_prompt(