Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions desktop/src-tauri/src/bench/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -224,6 +225,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`)
Expand Down Expand Up @@ -1265,8 +1270,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).
Expand Down
9 changes: 1 addition & 8 deletions desktop/src-tauri/src/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions desktop/src-tauri/src/bench/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
role: Option<AnswerRole>,
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.
Expand Down
56 changes: 46 additions & 10 deletions desktop/src-tauri/src/bench/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`<writer>-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::<Vec<_>>() {
let item = s.items[&id].clone();
let ch = card_channel(s, &item);
Expand All @@ -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) {
Expand Down Expand Up @@ -646,9 +672,19 @@ pub(super) async fn publish(
if !spend(budget, 1) {
return Ok(());
}
let text = item::render_route_reply(&item, &local_when(r.at, now)) + &link;
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,
Expand Down
53 changes: 52 additions & 1 deletion desktop/src-tauri/src/bench/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub(crate) fn render_route(item: &Item, prev: Option<usize>, 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
Expand Down Expand Up @@ -142,6 +143,56 @@ pub(crate) fn render_route_reply(item: &Item, hhmm: &str) -> String {
}
}

/// The notice for the owner's question on a #bench card, told to the
/// writer's questions route (`<writer>-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();
};
let (id, w) = (&item.id, &item.writer);
// 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!(
" The card's current answer is {}. {}.",
n + 1,
plain_text(o, usize::MAX)
)
});
let links: Vec<String> = 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!("{} (a PR link names its repo), and ", links.join("; "))
};
format!(
"Bench question \u{b7} {id}\nCard: {}\nThe owner asked a question in this thread at \
{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 \
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 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),
r.event_id,
)
}

/// 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.
Expand Down
Loading
Loading