From 511378ba8e8c6150f3b02f9efffa0c8a0264fe1e Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Wed, 18 Nov 2026 09:06:43 -0600 Subject: [PATCH 1/3] Bench: send card questions to the writer's questions route A free-text reply on a card now goes to the agent at routes.json["-questions"] when the owner set one, it is joined to the card's channel, and it is not a stamped answerer on the card. The notice, headed "Bench question" (not "Bench reply", which tells the target to close the card by re-dropping it), says who asked, why this agent got it, where to start (the card's links and its Bench state), and to answer only: never tap, label, rerun, merge, re-drop or clear the card. It carries a df-ask tag with the reply's event id beside the df-answer tag. Taps, owner-signed approvals and Why? lines stay with the writer's route. A Why? line is a reply signed with the desktop's bench:why marker, now kept on item::Reply as `why` (Reply::of builds it, so mod.rs gets shorter). With no questions route, or one that cannot be used, every reply goes to the writer's route exactly as before. The client marker bench:route:{id}@r<16 hex> is unchanged. Owner decision, Wed 18 Nov 2026: whoever gets a Bench question should be able to say where the card came from and why, with sources. Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- desktop/src-tauri/src/bench/item.rs | 8 +- desktop/src-tauri/src/bench/mod.rs | 9 +- desktop/src-tauri/src/bench/pick.rs | 25 +++ desktop/src-tauri/src/bench/publish.rs | 27 ++- desktop/src-tauri/src/bench/route.rs | 45 +++++ desktop/src-tauri/src/bench/tests/routes.rs | 201 +++++++++++++++++++- desktop/src-tauri/src/bench/tests/scoped.rs | 2 + 7 files changed, 304 insertions(+), 13 deletions(-) diff --git a/desktop/src-tauri/src/bench/item.rs b/desktop/src-tauri/src/bench/item.rs index 771c50a2b53..acc50296662 100644 --- a/desktop/src-tauri/src/bench/item.rs +++ b/desktop/src-tauri/src/bench/item.rs @@ -224,6 +224,10 @@ pub(crate) struct Reply { /// The reply's own created_at, never past the Bench clock. pub at: u64, pub hhmm: String, + /// It carries the desktop's Why? marker (`reply_card`): a reason, so it + /// stays with the writer's route, never a questions route. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub why: bool, } /// Who may answer a scoped card, resolved by the service (`roles::stamp`) @@ -1265,8 +1269,8 @@ pub(crate) use super::pick::{ refused_taps, root_until, tell_reply, }; pub(crate) use super::route::{ - owner_route, render_owner_ended, render_owner_withdrawal, render_route, render_route_reply, - route_due, OwnerSent, Routed, ROUTE_SETTLE_SECS, + owner_route, render_owner_ended, render_owner_withdrawal, render_route, render_route_question, + render_route_reply, route_due, OwnerSent, Routed, ROUTE_SETTLE_SECS, }; /// Board text. Stale and superseded items are folded (not rendered). diff --git a/desktop/src-tauri/src/bench/mod.rs b/desktop/src-tauri/src/bench/mod.rs index 4f709f6d3bb..59ab7de7c08 100644 --- a/desktop/src-tauri/src/bench/mod.rs +++ b/desktop/src-tauri/src/bench/mod.rs @@ -1141,14 +1141,7 @@ async fn poll_answers( if seed || !item::tell_reply(item, e, at, owner_set, &writer_hex) { item.routed_reply = Some(e.id.to_hex()); } - Some(item::Reply { - event_id: e.id.to_hex(), - by, - by_name, - role, - at, - hhmm: local_hhmm(at), - }) + Some(item::Reply::of(e, by, by_name, role, at)) } None if unread => item .reply diff --git a/desktop/src-tauri/src/bench/pick.rs b/desktop/src-tauri/src/bench/pick.rs index 914d5339dbe..70c4ace26d2 100644 --- a/desktop/src-tauri/src/bench/pick.rs +++ b/desktop/src-tauri/src/bench/pick.rs @@ -229,6 +229,31 @@ pub(crate) fn pick_reply<'e>( .max_by_key(|e| (e.created_at.as_secs(), e.id.to_hex())) } +impl Reply { + /// The picked reply `e` as the card's Other, by `by` at `at`. + pub(crate) fn of( + e: &nostr::Event, + by: String, + by_name: Option, + role: Option, + at: u64, + ) -> Reply { + let why = e + .tags + .iter() + .any(|t| matches!(t.as_slice(), [k, v, ..] if k == "client" && v == "bench:why")); + Reply { + event_id: e.id.to_hex(), + by, + by_name, + role, + at, + hhmm: super::local_hhmm(at), + why, + } + } +} + /// Whether a newly picked reply `e` (its time `at`) is for the route target /// to be told of. Not one that tags anyone but the writer and the owner's /// keys: tags pick who answers, and a route target it tags hears it itself. diff --git a/desktop/src-tauri/src/bench/publish.rs b/desktop/src-tauri/src/bench/publish.rs index 87409e8c79d..b9b94535901 100644 --- a/desktop/src-tauri/src/bench/publish.rs +++ b/desktop/src-tauri/src/bench/publish.rs @@ -646,9 +646,32 @@ pub(super) async fn publish( if !spend(budget, 1) { return Ok(()); } - let text = item::render_route_reply(&item, &local_when(r.at, now)) + &link; + // A question goes to the writer's questions route, if the owner set + // one that is in this channel and may not answer the card. A Why? + // line is a reason, like a tap, so it stays the writer's. + let ask = routes + .get(&format!("{}-questions", item.writer)) + .filter(|q| !r.why && joined(s, &ch).contains(q)) + .filter(|q| { + !item + .stamp + .iter() + .flat_map(|st| &st.answerers) + .any(|a| a.pk == **q) + }); + let when = local_when(r.at, now); + let (text, ping) = match ask { + Some(q) => (item::render_route_question(&item, &when), [q.as_str()]), + None => (item::render_route_reply(&item, &when), ping), + }; + let text = text + &link; let marker = format!("bench:route:{id}@r{}", &r.event_id[..16]); - let extra = vec![df_answer(["other", &r.by, &r.event_id])?]; + let mut extra = vec![df_answer(["other", &r.by, &r.event_id])?]; + if ask.is_some() { + extra.push( + nostr::Tag::parse(["df-ask", r.event_id.as_str()]).map_err(|e| e.to_string())?, + ); + } let posted = post_message( ctx, s, diff --git a/desktop/src-tauri/src/bench/route.rs b/desktop/src-tauri/src/bench/route.rs index adebbd7755e..5f53e021758 100644 --- a/desktop/src-tauri/src/bench/route.rs +++ b/desktop/src-tauri/src/bench/route.rs @@ -142,6 +142,51 @@ pub(crate) fn render_route_reply(item: &Item, hhmm: &str) -> String { } } +/// The notice for a free-text reply told to the writer's questions route +/// (`-questions` in routes.json), so the person learns where the +/// card came from and why. Never headed "Bench reply": a target told that +/// closes the card by re-dropping it, and a re-dropped steward hold card +/// closes for good. No angle brackets: buzz-acp escapes them. +pub(crate) fn render_route_question(item: &Item, hhmm: &str) -> String { + let Some(r) = &item.reply else { + return String::new(); + }; + let (id, w) = (&item.id, &item.writer); + let theirs = item.answer.as_ref().filter(|a| a.by == r.by); + let chose = theirs + .and_then(|a| Some((a.option, item.options.get(a.option)?))) + .map_or(String::new(), |(n, o)| { + format!(", after choosing {}. {}", n + 1, plain_text(o, usize::MAX)) + }); + let links: Vec = item + .links + .iter() + .map(|l| format!("{} {}", plain_text(&l.label, usize::MAX), l.url)) + .collect(); + let sources = if links.is_empty() { + String::new() + } else { + format!("{} (the repo is in the link), and ", links.join("; ")) + }; + format!( + "Bench question \u{b7} {id}\nCard: {}\n{} asked a question in this thread at \ + {hhmm}{chose}. Their message is event {}.\n\ + Why you: the owner's routes.json sends questions on {w} cards to you ({w}-questions). \ + The {w} agent acts only on taps, so nobody else will answer.\n\ + Sources to start from: {sources}this card, {id}, in the Bench state.\n\ + Answer in this thread: say what this card is, where it came from and why, and link \ + every source you used (the PR, its Factory-Task, Built-by and Claude-Account lines, \ + what triggered it). Mention {} so they see it.\n\ + Answer only. Never tap, label, rerun, merge, or re-drop or clear this card, even when \ + the question asks for an action: point to the card's buttons instead. If the card \ + says a reply does something (for example, stops a line), tell them it did.", + plain_text(&item.title, usize::MAX), + answerer_text(item, r.by_name.as_deref(), r.role), + r.event_id, + r.by + ) +} + /// Text the owner's own message may carry: exactly what both apps showed /// (the desktop prints drop text as it is, the phone through plain_text), /// so nothing the owner signs reads differently from what the owner saw. diff --git a/desktop/src-tauri/src/bench/tests/routes.rs b/desktop/src-tauri/src/bench/tests/routes.rs index 17143feb63c..f88e3f7867f 100644 --- a/desktop/src-tauri/src/bench/tests/routes.rs +++ b/desktop/src-tauri/src/bench/tests/routes.rs @@ -4,7 +4,7 @@ use std::collections::BTreeMap; use super::answers::{last_query, outbox, posted, reply, tap, ITEM}; -use super::channels::{bound_bench, thread_reply, ASK}; +use super::channels::{bound_bench, hex, tags, thread_reply, ASK, X}; use super::*; /// The owner's answer, as the owner's own message. @@ -759,6 +759,7 @@ fn replies_are_read_while_the_route_target_can_be_told() { role: None, at: 1, hhmm: String::new(), + why: false, }); assert!(reads_replies(&s, &item, &BTreeMap::new())); } @@ -1061,3 +1062,201 @@ async fn the_reply_file_goes_when_the_card_closes_or_is_replaced() { assert_eq!(b.card(ITEM).event_id, newer.id.to_hex()); assert_eq!(reply_file(&b, ITEM), None); } + +/// The hold card with the owner's questions route for its writer: A hears +/// taps, Q hears questions, both joined and the join's hold over. +async fn ask_bench() -> (Bench, String, String, String) { + let (mut b, card) = hold_bench().await; + let a = Keys::generate().public_key().to_hex(); + let q = Keys::generate().public_key().to_hex(); + b.ctx.agents = vec![a.clone(), q.clone()]; + let routes = json!({ "orchestrator": a, "orchestrator-questions": q }); + std::fs::write(b.root.join("routes.json"), routes.to_string()).unwrap(); + b.tick().await.unwrap(); + b.now += ROUTE_SETTLE_SECS; + (b, a, q, card) +} + +#[test] +fn render_route_question_text() { + let url = "https://github.com/QuicksilverSlick/Metabolic-reset/pull/870"; + let drop = drop_json(&[ + ( + "title", + json!("reset PR 870 waits for you: Ask members to sign in"), + ), + ("decision", json!("steward-hold")), + ("recommend", json!(1)), + ( + "options", + json!(["Ship it", "Send it back", "Keep holding"]), + ), + ("links", json!([{"label": "Pull request 870", "url": url}])), + ]); + let mut item = validate("steward", "hold-reset-870", &drop, NOW).unwrap(); + let (by, ev) = ("cd".repeat(32), "ab".repeat(32)); + item.reply = Some(Reply { + event_id: ev.clone(), + by: by.clone(), + by_name: None, + role: None, + at: 1, + hhmm: String::new(), + why: false, + }); + let text = render_route_question(&item, "09:12"); + assert_eq!( + text, + format!( + "Bench question \u{b7} steward/hold-reset-870\n\ + Card: reset PR 870 waits for you: Ask members to sign in\n\ + the owner asked a question in this thread at 09:12. Their message is event {ev}.\n\ + Why you: the owner's routes.json sends questions on steward cards to you \ + (steward-questions). The steward agent acts only on taps, so nobody else will \ + answer.\n\ + Sources to start from: Pull request 870 {url} (the repo is in the link), and this \ + card, steward/hold-reset-870, in the Bench state.\n\ + Answer in this thread: say what this card is, where it came from and why, and link \ + every source you used (the PR, its Factory-Task, Built-by and Claude-Account lines, \ + what triggered it). Mention {by} so they see it.\n\ + Answer only. Never tap, label, rerun, merge, or re-drop or clear this card, even \ + when the question asks for an action: point to the card's buttons instead. If the \ + card says a reply does something (for example, stops a line), tell them it did." + ) + ); + assert!(!text.contains(['<', '>'])); + // Beside their own tap it names the choice; with no links, the card only. + item.answer = Some(Answer { + by, + option: 2, + ..Default::default() + }); + item.links.clear(); + let text = render_route_question(&item, "09:12"); + assert!(text.contains(" at 09:12, after choosing 3. Keep holding. Their message is event ")); + assert!(text.contains( + "\nSources to start from: this card, steward/hold-reset-870, in the Bench state.\n" + )); +} + +/// Owner decision, 18 Nov 2026: a question on a card goes to the writer's +/// questions route (`-questions` in routes.json), which says where +/// the card came from and why; taps stay with the writer's route target. +#[tokio::test] +async fn a_question_goes_to_the_questions_route_and_a_tap_to_the_writers() { + let (mut b, a, q, card) = ask_bench().await; + let r1 = thread_reply(&b.ctx.owner, &card, "Where is this from?", b.now, &[]); + reply(&b, &[&r1]); + let n = settle_past(&mut b, 2).await; + assert_eq!(n.len(), 1); + let (ev, id) = (&n[0], r1.id.to_hex()); + let r = b.s.items[ITEM].reply.clone().unwrap(); + assert_eq!( + content(ev), + render_route_question(&b.s.items[ITEM], &local_hhmm(r.at)) + + &thread_line(&b.channel(), &card) + ); + assert!(content(ev).starts_with(&format!("Bench question \u{b7} {ITEM}\n"))); + assert_eq!(tags(ev, "p"), [json!(["p", q])]); + assert_eq!(tags(ev, "df-ask"), [json!(["df-ask", id])]); + assert_eq!( + tags(ev, "df-answer"), + [json!(["df-answer", "other", b.owner_hex(), id])] + ); + assert_eq!( + tag_value(ev, "client").unwrap(), + format!("bench:route:{ITEM}@r{}", &id[..16]) + ); + assert_eq!(b.s.items[ITEM].routed_reply, Some(id)); + // The owner's tap goes to A, as the owner's own message. + let stay = tap(&b.ctx.owner, &card, OPTION_EMOJI[0], b.now); + reply(&b, &[&r1, &stay]); + let before = b.posts().len(); + b.settle(2).await; + assert!(notices(&b, before).is_empty()); + let n = settle_past(&mut b, 2).await; + assert_eq!(n.len(), 1); + assert_eq!(content(&n[0]), chose(&card, "Stay")); + assert_eq!(tags(&n[0], "p"), [json!(["p", a])]); +} + +/// A Why? line is a reason, not a question: it stays with the writer's +/// route target, as today. +#[tokio::test] +async fn a_why_line_stays_with_the_writers_route() { + let (mut b, a, _q, card) = ask_bench().await; + let before = b.posts().len(); + let text = "Waiting on the relay quote"; + crate::bench::commands::reply_card(&b.ctx, &b.s, ITEM, &card, text, b.now) + .await + .unwrap(); + let why: nostr::Event = serde_json::from_value(b.posts()[before].0.clone()).unwrap(); + reply(&b, &[&why]); + let n = settle_past(&mut b, 2).await; + assert_eq!(n.len(), 1); + let r = b.s.items[ITEM].reply.clone().unwrap(); + assert!(r.why); + assert_eq!( + content(&n[0]), + render_route_reply(&b.s.items[ITEM], &local_hhmm(r.at)) + &thread_line(&b.channel(), &card) + ); + assert_eq!(tags(&n[0], "p"), [json!(["p", a])]); + assert!(tags(&n[0], "df-ask").is_empty()); +} + +/// A question beside the owner's own tap still goes to Q, naming the +/// choice; the tap goes to A once it settles. +#[tokio::test] +async fn a_question_beside_the_owners_tap_names_the_choice() { + let (mut b, a, q, card) = ask_bench().await; + let mv = tap(&b.ctx.owner, &card, OPTION_EMOJI[1], b.now); + let r1 = thread_reply(&b.ctx.owner, &card, "Who opened this?", b.now, &[]); + reply(&b, &[&mv, &r1]); + let before = b.posts().len(); + b.settle(2).await; + let n = notices(&b, before); + assert_eq!(n.len(), 1, "the answer waits for the settle"); + assert_eq!(tags(&n[0], "p"), [json!(["p", q])]); + let r = b.s.items[ITEM].reply.clone().unwrap(); + assert!(content(&n[0]).contains(&format!( + "the owner asked a question in this thread at {}, after choosing 2. Move. Their \ + message is event {}.", + local_hhmm(r.at), + r1.id.to_hex() + ))); + let n = settle_past(&mut b, 2).await; + assert_eq!(n.len(), 1); + assert_eq!(content(&n[0]), chose(&card, "Move")); + assert_eq!(tags(&n[0], "p"), [json!(["p", a])]); +} + +/// A questions route not in the card's channel, or one that may answer the +/// card, is not told: the writer's route target hears the reply, as today. +#[tokio::test] +async fn a_questions_route_that_cannot_hear_or_answers_falls_back() { + let (mut b, p, list) = bound_bench().await; + let card = b.card(ASK).event_id; + let (agent, craig) = (hex(&p.agent), hex(&p.craig)); + let mut said = vec![list]; + // A key in #bench only, the card being in X; then Craig, in X (as if + // joined there) and an answerer on the card. + let stranger = Keys::generate().public_key().to_hex(); + for (q, text) in [(stranger, "Where is this from?"), (craig.clone(), "Who?")] { + b.ctx.agents = vec![agent.clone(), q.clone()]; + let routes = json!({ "reset-worker": agent, "reset-worker-questions": q }); + std::fs::write(b.root.join("routes.json"), routes.to_string()).unwrap(); + b.tick().await.unwrap(); + assert!(b.s.unroutable.is_empty() && b.s.members_added.contains(&q)); + assert!(!crate::bench::channels::joined(&b.s, X).contains(&q)); + if q == craig { + b.s.joined.get_mut(X).unwrap().push(q.clone()); + } + said.push(thread_reply(&b.ctx.owner, &card, text, b.now, &[])); + reply(&b, &said.iter().collect::>()); + let n = settle_past(&mut b, 2).await; + assert_eq!(n.len(), 1, "{text}"); + assert!(content(&n[0]).starts_with(&format!("Bench reply \u{b7} {ASK}\n"))); + assert_eq!(tags(&n[0], "p"), [json!(["p", agent])]); + assert!(tags(&n[0], "df-ask").is_empty()); + } +} diff --git a/desktop/src-tauri/src/bench/tests/scoped.rs b/desktop/src-tauri/src/bench/tests/scoped.rs index 41ebac7254d..e562af09c46 100644 --- a/desktop/src-tauri/src/bench/tests/scoped.rs +++ b/desktop/src-tauri/src/bench/tests/scoped.rs @@ -847,6 +847,7 @@ fn receipt_keeps_the_request_and_adds_the_outcome() { role: Some(AnswerRole::Decider), at: 1, hhmm: "14:03".to_string(), + why: false, }); outcome.request = Some(Box::new(request.clone())); let card = render_card(&outcome, "15:10"); @@ -918,6 +919,7 @@ fn notices_name_who_answered_on_scoped_cards() { role: Some(AnswerRole::Decider), at: 1, hhmm: "14:03".to_string(), + why: false, }); assert_eq!( render_route_reply(&item, "14:03"), From 78bcfa29b1fec2ae9c7b7492d3dbc7546e341ca0 Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Wed, 18 Nov 2026 09:33:57 -0600 Subject: [PATCH 2/3] Bench: questions route only for the owner's #bench questions The questions route ("-questions") now takes a reply only when it is the owner's own question on a #bench card, not a Why? line, and the target is joined to #bench, is not a stamped answerer and is not the writer's own route target. df-ask rides only on those notices, so buzz-acp never posts the Factory Steward's final text. Anything else keeps today's notice to the writer's route target. A questions route that cannot take an owner question is an alarm in unroutable ("-questions: ") while it stands, deduped per tick, and the question falls back to the writer's route. repliesTold matches ": ", so it does not read the alarm as the writer's route refused. The question notice now names the owner as the asker, says why this agent got it for any writer, points at grep for state.json, and adds close and the no-text rule for a non-question. Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- desktop/src-tauri/src/bench/item.rs | 3 +- desktop/src-tauri/src/bench/publish.rs | 57 +++-- desktop/src-tauri/src/bench/route.rs | 36 ++-- desktop/src-tauri/src/bench/tests/routes.rs | 226 +++++++++++++++----- 4 files changed, 234 insertions(+), 88 deletions(-) diff --git a/desktop/src-tauri/src/bench/item.rs b/desktop/src-tauri/src/bench/item.rs index acc50296662..291c4d81f1d 100644 --- a/desktop/src-tauri/src/bench/item.rs +++ b/desktop/src-tauri/src/bench/item.rs @@ -212,7 +212,8 @@ pub(crate) enum AnswerSource { } /// The newest free-text reply on a scoped or routed card from someone who -/// may answer it: their "Other", routed to the writer like an answer. +/// may answer it: their "Other", routed to the writer like an answer, or +/// the owner's question on a #bench card to the writer's questions route. #[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] #[serde(rename_all = "camelCase")] pub(crate) struct Reply { diff --git a/desktop/src-tauri/src/bench/publish.rs b/desktop/src-tauri/src/bench/publish.rs index b9b94535901..9521d5cdb2b 100644 --- a/desktop/src-tauri/src/bench/publish.rs +++ b/desktop/src-tauri/src/bench/publish.rs @@ -492,8 +492,10 @@ pub(super) async fn publish( // (a3) Tell the writer's route target of a settled answer change, and of // each new free-text reply on the card, in the card's thread so the - // board stays newest. `routed` lands only once the relay took the notice, - // so a failed post is retried next tick. + // board stays newest; the owner's own question on a #bench card goes to + // the writer's questions route (`-questions`) instead. `routed` + // lands only once the relay took the notice, so a failed post is retried + // next tick. for id in s.items.keys().cloned().collect::>() { let item = s.items[&id].clone(); let ch = card_channel(s, &item); @@ -504,16 +506,40 @@ pub(super) async fn publish( else { continue; }; - if item - .stamp - .iter() - .flat_map(|st| &st.answerers) - .any(|a| a.pk == to) - { + let answers = |k: &str| { + item.stamp + .iter() + .flat_map(|st| &st.answerers) + .any(|a| a.pk == k) + }; + if answers(&to) { s.unroutable .push(format!("{id}: route target is an answerer on this card")); continue; } + // buzz-acp posts the answer to a df-ask notice itself, so only the + // owner's question on a #bench card goes to the questions route, + // never a Why? line (a reason, like a tap) or the writer's agent. A + // route that cannot take it is an alarm while it stands, and the + // writer's route target hears the question, as before. + let qs = format!("{}-questions", item.writer); + let asked = item + .reply + .as_ref() + .is_some_and(|r| ch == s.channel_id && owner_set.contains(&r.by) && !r.why); + let ask = match routes.get(&qs).filter(|_| asked) { + Some(q) if !joined(s, &ch).contains(q) => Err("not joined to #bench".to_string()), + Some(q) if answers(q) => Err("an answerer on a card the owner asked on".to_string()), + Some(q) if *q == to => Err(format!("the same agent as the {} route", item.writer)), + q => Ok(q.cloned()), + }; + let ask = ask.unwrap_or_else(|why| { + let alarm = format!("{qs}: {why}"); + if !s.unroutable.contains(&alarm) { + s.unroutable.push(alarm); + } + None + }); // A channel no longer ready is not read either (an untap there is // unseen), so its answers wait, like a held card's. if now < s.routes_held_until || s.held.contains(&id) || !channel_ready(s, &item) { @@ -646,21 +672,8 @@ pub(super) async fn publish( if !spend(budget, 1) { return Ok(()); } - // A question goes to the writer's questions route, if the owner set - // one that is in this channel and may not answer the card. A Why? - // line is a reason, like a tap, so it stays the writer's. - let ask = routes - .get(&format!("{}-questions", item.writer)) - .filter(|q| !r.why && joined(s, &ch).contains(q)) - .filter(|q| { - !item - .stamp - .iter() - .flat_map(|st| &st.answerers) - .any(|a| a.pk == **q) - }); let when = local_when(r.at, now); - let (text, ping) = match ask { + let (text, ping) = match &ask { Some(q) => (item::render_route_question(&item, &when), [q.as_str()]), None => (item::render_route_reply(&item, &when), ping), }; diff --git a/desktop/src-tauri/src/bench/route.rs b/desktop/src-tauri/src/bench/route.rs index 5f53e021758..ff4d048a127 100644 --- a/desktop/src-tauri/src/bench/route.rs +++ b/desktop/src-tauri/src/bench/route.rs @@ -108,7 +108,8 @@ pub(crate) fn render_route(item: &Item, prev: Option, hhmm: &str) -> Stri } /// The notice for a free-text reply on a card (its Other): any scoped card, -/// and an unscoped one whose writer has a route. Like an +/// and an unscoped one whose writer has a route, unless it is the owner's +/// question for the writer's questions route (`render_route_question`). Like an /// answer notice it carries no reply text: the agent reads the reply itself /// in the thread, with the trust it gives that person, or the owner's in its /// signed file (`outbox`). A reply beside the same person's answer (a hold's @@ -142,11 +143,12 @@ pub(crate) fn render_route_reply(item: &Item, hhmm: &str) -> String { } } -/// The notice for a free-text reply told to the writer's questions route -/// (`-questions` in routes.json), so the person learns where the -/// card came from and why. Never headed "Bench reply": a target told that -/// closes the card by re-dropping it, and a re-dropped steward hold card -/// closes for good. No angle brackets: buzz-acp escapes them. +/// The notice for the owner's question on a #bench card, told to the +/// writer's questions route (`-questions` in routes.json), so the +/// owner learns where the card came from and why. Never headed "Bench +/// reply": a target told that closes the card by re-dropping it, and a +/// re-dropped steward hold card closes for good. No angle brackets (buzz-acp +/// escapes them) and no keys. pub(crate) fn render_route_question(item: &Item, hhmm: &str) -> String { let Some(r) = &item.reply else { return String::new(); @@ -166,24 +168,24 @@ pub(crate) fn render_route_question(item: &Item, hhmm: &str) -> String { let sources = if links.is_empty() { String::new() } else { - format!("{} (the repo is in the link), and ", links.join("; ")) + format!("{} (a PR link names its repo), and ", links.join("; ")) }; format!( - "Bench question \u{b7} {id}\nCard: {}\n{} asked a question in this thread at \ + "Bench question \u{b7} {id}\nCard: {}\nThe owner asked a question in this thread at \ {hhmm}{chose}. Their message is event {}.\n\ - Why you: the owner's routes.json sends questions on {w} cards to you ({w}-questions). \ - The {w} agent acts only on taps, so nobody else will answer.\n\ - Sources to start from: {sources}this card, {id}, in the Bench state.\n\ + Why you: the owner's routes.json sends questions on {w} cards to you ({w}-questions) \ + instead of the {w} route, so nobody else will answer.\n\ + Sources to start from: {sources}this card, {id}: grep state.json in the Bench folder \ + for that id, as the file is large.\n\ Answer in this thread: say what this card is, where it came from and why, and link \ every source you used (the PR, its Factory-Task, Built-by and Claude-Account lines, \ - what triggered it). Mention {} so they see it.\n\ - Answer only. Never tap, label, rerun, merge, or re-drop or clear this card, even when \ - the question asks for an action: point to the card's buttons instead. If the card \ - says a reply does something (for example, stops a line), tell them it did.", + what triggered it). Mention the owner so he sees it.\n\ + Answer only. Never tap, label, rerun, merge, close, re-drop or clear this card, even \ + when the question asks for an action: point to the card's buttons instead. If the \ + card says a reply does something (for example, stops a line), tell the owner it did. \ + If the message is not a question (a thanks, say), end the turn with no text.", plain_text(&item.title, usize::MAX), - answerer_text(item, r.by_name.as_deref(), r.role), r.event_id, - r.by ) } diff --git a/desktop/src-tauri/src/bench/tests/routes.rs b/desktop/src-tauri/src/bench/tests/routes.rs index f88e3f7867f..7cb2c124842 100644 --- a/desktop/src-tauri/src/bench/tests/routes.rs +++ b/desktop/src-tauri/src/bench/tests/routes.rs @@ -1104,44 +1104,50 @@ fn render_route_question_text() { hhmm: String::new(), why: false, }); + // The owner tapped Ship it, then asked: the choice is named. + item.answer = Some(Answer { + by: by.clone(), + option: 0, + ..Default::default() + }); let text = render_route_question(&item, "09:12"); assert_eq!( text, format!( "Bench question \u{b7} steward/hold-reset-870\n\ Card: reset PR 870 waits for you: Ask members to sign in\n\ - the owner asked a question in this thread at 09:12. Their message is event {ev}.\n\ + The owner asked a question in this thread at 09:12, after choosing 1. Ship it. \ + Their message is event {ev}.\n\ Why you: the owner's routes.json sends questions on steward cards to you \ - (steward-questions). The steward agent acts only on taps, so nobody else will \ - answer.\n\ - Sources to start from: Pull request 870 {url} (the repo is in the link), and this \ - card, steward/hold-reset-870, in the Bench state.\n\ + (steward-questions) instead of the steward route, so nobody else will answer.\n\ + Sources to start from: Pull request 870 {url} (a PR link names its repo), and this \ + card, steward/hold-reset-870: grep state.json in the Bench folder for that id, as \ + the file is large.\n\ Answer in this thread: say what this card is, where it came from and why, and link \ every source you used (the PR, its Factory-Task, Built-by and Claude-Account lines, \ - what triggered it). Mention {by} so they see it.\n\ - Answer only. Never tap, label, rerun, merge, or re-drop or clear this card, even \ + what triggered it). Mention the owner so he sees it.\n\ + Answer only. Never tap, label, rerun, merge, close, re-drop or clear this card, even \ when the question asks for an action: point to the card's buttons instead. If the \ - card says a reply does something (for example, stops a line), tell them it did." + card says a reply does something (for example, stops a line), tell the owner it \ + did. If the message is not a question (a thanks, say), end the turn with no text." ) ); - assert!(!text.contains(['<', '>'])); - // Beside their own tap it names the choice; with no links, the card only. - item.answer = Some(Answer { - by, - option: 2, - ..Default::default() - }); + assert!(!text.contains(['<', '>']) && !text.contains(&by)); + // No answer of theirs, no choice; with no links, the card only. + item.answer = None; item.links.clear(); let text = render_route_question(&item, "09:12"); - assert!(text.contains(" at 09:12, after choosing 3. Keep holding. Their message is event ")); + assert!(text.contains(" at 09:12. Their message is event ")); assert!(text.contains( - "\nSources to start from: this card, steward/hold-reset-870, in the Bench state.\n" + "\nSources to start from: this card, steward/hold-reset-870: grep state.json in the \ + Bench folder for that id, as the file is large.\n" )); } -/// Owner decision, 18 Nov 2026: a question on a card goes to the writer's -/// questions route (`-questions` in routes.json), which says where -/// the card came from and why; taps stay with the writer's route target. +/// Owner decision, 18 Nov 2026: the owner's question on a #bench card goes +/// to the writer's questions route (`-questions` in routes.json), +/// which says where the card came from and why; taps stay with the writer's +/// route target. #[tokio::test] async fn a_question_goes_to_the_questions_route_and_a_tap_to_the_writers() { let (mut b, a, q, card) = ask_bench().await; @@ -1219,7 +1225,7 @@ async fn a_question_beside_the_owners_tap_names_the_choice() { assert_eq!(tags(&n[0], "p"), [json!(["p", q])]); let r = b.s.items[ITEM].reply.clone().unwrap(); assert!(content(&n[0]).contains(&format!( - "the owner asked a question in this thread at {}, after choosing 2. Move. Their \ + "The owner asked a question in this thread at {}, after choosing 2. Move. Their \ message is event {}.", local_hhmm(r.at), r1.id.to_hex() @@ -1230,33 +1236,157 @@ async fn a_question_beside_the_owners_tap_names_the_choice() { assert_eq!(tags(&n[0], "p"), [json!(["p", a])]); } -/// A questions route not in the card's channel, or one that may answer the -/// card, is not told: the writer's route target hears the reply, as today. +/// The owner's question on a card in a bound channel is not a #bench one: +/// the writer's route target hears it, with no df-ask and no alarm, though +/// the questions route is in that channel too. #[tokio::test] -async fn a_questions_route_that_cannot_hear_or_answers_falls_back() { +async fn a_question_on_a_bound_card_goes_to_the_writers_route() { let (mut b, p, list) = bound_bench().await; - let card = b.card(ASK).event_id; - let (agent, craig) = (hex(&p.agent), hex(&p.craig)); - let mut said = vec![list]; - // A key in #bench only, the card being in X; then Craig, in X (as if - // joined there) and an answerer on the card. - let stranger = Keys::generate().public_key().to_hex(); - for (q, text) in [(stranger, "Where is this from?"), (craig.clone(), "Who?")] { - b.ctx.agents = vec![agent.clone(), q.clone()]; - let routes = json!({ "reset-worker": agent, "reset-worker-questions": q }); - std::fs::write(b.root.join("routes.json"), routes.to_string()).unwrap(); - b.tick().await.unwrap(); - assert!(b.s.unroutable.is_empty() && b.s.members_added.contains(&q)); - assert!(!crate::bench::channels::joined(&b.s, X).contains(&q)); - if q == craig { - b.s.joined.get_mut(X).unwrap().push(q.clone()); - } - said.push(thread_reply(&b.ctx.owner, &card, text, b.now, &[])); - reply(&b, &said.iter().collect::>()); - let n = settle_past(&mut b, 2).await; - assert_eq!(n.len(), 1, "{text}"); - assert!(content(&n[0]).starts_with(&format!("Bench reply \u{b7} {ASK}\n"))); - assert_eq!(tags(&n[0], "p"), [json!(["p", agent])]); - assert!(tags(&n[0], "df-ask").is_empty()); - } + let (card, agent) = (b.card(ASK).event_id, hex(&p.agent)); + let q = Keys::generate().public_key().to_hex(); + b.ctx.agents = vec![agent.clone(), q.clone()]; + let routes = json!({ "reset-worker": agent, "reset-worker-questions": q }); + std::fs::write(b.root.join("routes.json"), routes.to_string()).unwrap(); + b.tick().await.unwrap(); + assert!(b.s.members_added.contains(&q)); + b.s.joined.get_mut(X).unwrap().push(q.clone()); + let r1 = thread_reply(&b.ctx.owner, &card, "Where is this from?", b.now, &[]); + reply(&b, &[&list, &r1]); + let n = settle_past(&mut b, 2).await; + assert_eq!(n.len(), 1); + assert!(content(&n[0]).starts_with(&format!("Bench reply \u{b7} {ASK}\n"))); + assert_eq!(tags(&n[0], "p"), [json!(["p", agent])]); + assert!(tags(&n[0], "df-ask").is_empty() && b.s.unroutable.is_empty()); +} + +/// A questions route on the writer's own agent gets no df-ask, which would +/// have buzz-acp post that agent's final text: it hears the question as +/// today, the alarm stands meanwhile, and repliesTold (which matches +/// `: `) does not read it as the writer's route refused. +#[tokio::test] +async fn a_questions_route_on_the_writers_agent_is_an_alarm() { + let (mut b, a, _q, card) = ask_bench().await; + let routes = json!({ "orchestrator": a, "orchestrator-questions": a }); + std::fs::write(b.root.join("routes.json"), routes.to_string()).unwrap(); + let r1 = thread_reply(&b.ctx.owner, &card, "Where is this from?", b.now, &[]); + reply(&b, &[&r1]); + let n = settle_past(&mut b, 2).await; + assert_eq!(n.len(), 1); + let r = b.s.items[ITEM].reply.clone().unwrap(); + assert_eq!( + content(&n[0]), + render_route_reply(&b.s.items[ITEM], &local_hhmm(r.at)) + &thread_line(&b.channel(), &card) + ); + assert_eq!(tags(&n[0], "p"), [json!(["p", a])]); + assert!(tags(&n[0], "df-ask").is_empty()); + let alarm = "orchestrator-questions: the same agent as the orchestrator route"; + assert_eq!(b.s.unroutable, [alarm]); + save_state(&b.root, &b.s, &mut String::new()).unwrap(); + let snap = serde_json::to_value(crate::bench::commands::cards(&b.root)).unwrap(); + let items = snap["items"].as_array().unwrap(); + let card = items.iter().find(|i| i["id"] == ITEM).unwrap(); + assert_eq!(card["repliesTold"], json!(true)); +} + +/// publish alone, as the tick calls it, with `routes` and `by`'s `text` as +/// the card's newest reply (`named` when it is not the owner's): for what +/// no tick reaches on a #bench card, where bootstrap joins every route +/// target first and only the owner may reply. The notices it posted. +async fn publish_reply( + b: &mut Bench, + routes: [(&str, &str); 2], + by: &Keys, + named: Option<&str>, + text: &str, +) -> Vec { + let r = thread_reply(by, &b.card(ITEM).event_id, text, b.now, &[]); + let (name, role) = ( + named.map(str::to_string), + named.map(|_| AnswerRole::Decider), + ); + b.s.items.get_mut(ITEM).unwrap().reply = Some(Reply::of(&r, hex(by), name, role, b.now)); + let routes = BTreeMap::from(routes.map(|(w, k)| (w.to_string(), k.to_string()))); + let (before, owner) = (b.posts().len(), [b.owner_hex()]); + let (budget, now) = (&mut 10, b.now); + crate::bench::publish::publish( + &b.ctx, + &mut b.s, + budget, + now, + "09:00", + &routes, + &owner, + &mut Vec::new(), + ) + .await + .unwrap(); + notices(b, before) +} + +/// A stamped answerer's reply is not the owner's question: the writer's +/// route target hears it, with no df-ask and no alarm. +#[tokio::test] +async fn an_answerers_question_goes_to_the_writers_route() { + let (mut b, a, q, _card) = ask_bench().await; + let craig = Keys::generate(); + b.s.items.get_mut(ITEM).unwrap().stamp = Some(Stamp { + answerers: vec![Answerer { + pk: hex(&craig), + name: "Craig".to_string(), + role: AnswerRole::Decider, + agent: false, + }], + ..Default::default() + }); + let routes = [ + ("orchestrator", a.as_str()), + ("orchestrator-questions", q.as_str()), + ]; + let n = publish_reply(&mut b, routes, &craig, Some("Craig"), "Where is this from?").await; + assert_eq!(n.len(), 1); + assert!(content(&n[0]).starts_with(&format!("Bench reply \u{b7} {ITEM}\n"))); + assert!(content(&n[0]).contains("\nCraig (decider) replied in this thread at ")); + assert_eq!(tags(&n[0], "p"), [json!(["p", a])]); + assert!(tags(&n[0], "df-ask").is_empty() && b.s.unroutable.is_empty()); +} + +/// A questions route not joined to #bench, or one that may answer the card, +/// is an alarm, and the writer's route target hears the question as today. +#[tokio::test] +async fn a_questions_route_that_cannot_take_it_is_an_alarm_and_falls_back() { + let (mut b, a, q, _card) = ask_bench().await; + let routes = [ + ("orchestrator", a.as_str()), + ("orchestrator-questions", q.as_str()), + ]; + let owner = b.ctx.owner.clone(); + b.s.members_added.retain(|k| *k != q); + let n = publish_reply(&mut b, routes, &owner, None, "Where is this from?").await; + assert_eq!(n.len(), 1); + assert!(content(&n[0]).starts_with(&format!("Bench reply \u{b7} {ITEM}\n"))); + assert_eq!(tags(&n[0], "p"), [json!(["p", a.clone()])]); + assert!(tags(&n[0], "df-ask").is_empty()); + assert_eq!( + b.s.unroutable, + ["orchestrator-questions: not joined to #bench"] + ); + b.s.members_added.push(q.clone()); + b.s.unroutable.clear(); + b.s.items.get_mut(ITEM).unwrap().stamp = Some(Stamp { + answerers: vec![Answerer { + pk: q.clone(), + name: "Bench Assistant".to_string(), + role: AnswerRole::Decider, + agent: true, + }], + ..Default::default() + }); + let n = publish_reply(&mut b, routes, &owner, None, "Who opened it?").await; + assert_eq!(n.len(), 1); + assert_eq!(tags(&n[0], "p"), [json!(["p", a])]); + assert!(tags(&n[0], "df-ask").is_empty()); + assert_eq!( + b.s.unroutable, + ["orchestrator-questions: an answerer on a card the owner asked on"] + ); } From 177cb22c70028edfece3f6d9d64663b2d0ccf4a7 Mon Sep 17 00:00:00 2001 From: QuicksilverSlick Date: Wed, 18 Nov 2026 09:43:00 -0600 Subject: [PATCH 3/3] Bench: a question notice states the card's current answer, whichever key tapped The owner can tap on the phone key and type on the desktop's, so naming the choice only when the same key did both dropped it from the notice. Claude-Account: russelledeming@gmail.com Co-Authored-By: Claude Opus 5.5 --- desktop/src-tauri/src/bench/route.rs | 12 ++++++++---- desktop/src-tauri/src/bench/tests/routes.rs | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/desktop/src-tauri/src/bench/route.rs b/desktop/src-tauri/src/bench/route.rs index ff4d048a127..821e9d97a24 100644 --- a/desktop/src-tauri/src/bench/route.rs +++ b/desktop/src-tauri/src/bench/route.rs @@ -154,11 +154,15 @@ pub(crate) fn render_route_question(item: &Item, hhmm: &str) -> String { return String::new(); }; let (id, w) = (&item.id, &item.writer); - let theirs = item.answer.as_ref().filter(|a| a.by == r.by); - let chose = theirs + // Whichever key tapped it: the owner may tap on the phone and ask on the desktop. + let chose = (item.answer.as_ref()) .and_then(|a| Some((a.option, item.options.get(a.option)?))) .map_or(String::new(), |(n, o)| { - format!(", after choosing {}. {}", n + 1, plain_text(o, usize::MAX)) + format!( + " The card's current answer is {}. {}.", + n + 1, + plain_text(o, usize::MAX) + ) }); let links: Vec = item .links @@ -172,7 +176,7 @@ pub(crate) fn render_route_question(item: &Item, hhmm: &str) -> String { }; format!( "Bench question \u{b7} {id}\nCard: {}\nThe owner asked a question in this thread at \ - {hhmm}{chose}. Their message is event {}.\n\ + {hhmm}. Their message is event {}.{chose}\n\ Why you: the owner's routes.json sends questions on {w} cards to you ({w}-questions) \ instead of the {w} route, so nobody else will answer.\n\ Sources to start from: {sources}this card, {id}: grep state.json in the Bench folder \ diff --git a/desktop/src-tauri/src/bench/tests/routes.rs b/desktop/src-tauri/src/bench/tests/routes.rs index 7cb2c124842..0d8b3d23d47 100644 --- a/desktop/src-tauri/src/bench/tests/routes.rs +++ b/desktop/src-tauri/src/bench/tests/routes.rs @@ -1116,8 +1116,8 @@ fn render_route_question_text() { format!( "Bench question \u{b7} steward/hold-reset-870\n\ Card: reset PR 870 waits for you: Ask members to sign in\n\ - The owner asked a question in this thread at 09:12, after choosing 1. Ship it. \ - Their message is event {ev}.\n\ + The owner asked a question in this thread at 09:12. Their message is event \ + {ev}. The card's current answer is 1. Ship it.\n\ Why you: the owner's routes.json sends questions on steward cards to you \ (steward-questions) instead of the steward route, so nobody else will answer.\n\ Sources to start from: Pull request 870 {url} (a PR link names its repo), and this \ @@ -1225,8 +1225,8 @@ async fn a_question_beside_the_owners_tap_names_the_choice() { assert_eq!(tags(&n[0], "p"), [json!(["p", q])]); let r = b.s.items[ITEM].reply.clone().unwrap(); assert!(content(&n[0]).contains(&format!( - "The owner asked a question in this thread at {}, after choosing 2. Move. Their \ - message is event {}.", + "The owner asked a question in this thread at {}. Their message is event {}. The \ + card's current answer is 2. Move.", local_hhmm(r.at), r1.id.to_hex() )));