Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

Groups get an About that their bots are told; bots join a group as chips on every app; threads have their own full conversation and mark replies read

leepokai93d143885c60
diff --git a/apps/linux/src/dialogs.rs b/apps/linux/src/dialogs.rs
index 5c77612b..6537aaef 100644
--- a/apps/linux/src/dialogs.rs
+++ b/apps/linux/src/dialogs.rs
@@ -376,7 +376,7 @@ pub fn editor(ui: &App, bot: Option<Value>) {
// MARK: group editor
-/// Create a group chat, or rename one and change who's in it (up to six bots).
+/// Create a group chat, or rename one, describe it and change who's in it.
pub fn group_editor(ui: &App, group: Option<Value>) {
let is_new = group.is_none();
let group_id = group
@@ -410,6 +410,12 @@ pub fn group_editor(ui: &App, group: Option<Value>) {
let page = adw::PreferencesPage::new();
let profile = adw::PreferencesGroup::new();
+ // The sidebar's avatar: the first two members overlapped.
+ let preview = gtk::Box::builder()
+ .halign(gtk::Align::Center)
+ .margin_bottom(8)
+ .build();
+ profile.add(&preview);
let name = adw::EntryRow::builder()
.title("Name")
.text(
@@ -422,6 +428,35 @@ pub fn group_editor(ui: &App, group: Option<Value>) {
profile.add(&name);
page.add(&profile);
+ let about_group = adw::PreferencesGroup::builder()
+ .title("About this group")
+ .description("Optional. Every bot in the group sees it.")
+ .build();
+ let about = gtk::TextView::builder()
+ .wrap_mode(gtk::WrapMode::WordChar)
+ .top_margin(8)
+ .bottom_margin(8)
+ .left_margin(8)
+ .right_margin(8)
+ .build();
+ about.buffer().set_text(
+ group
+ .as_ref()
+ .and_then(|g| g["description"].as_str())
+ .unwrap_or(""),
+ );
+ about_group.add(
+ &gtk::Frame::builder()
+ .child(
+ &gtk::ScrolledWindow::builder()
+ .min_content_height(70)
+ .child(&about)
+ .build(),
+ )
+ .build(),
+ );
+ page.add(&about_group);
+
let bots_group = adw::PreferencesGroup::builder()
.description("Everyone answers in turn unless you @mention someone. Each bot works in its own folder with its own tools.")
.build();
@@ -461,17 +496,28 @@ pub fn group_editor(ui: &App, group: Option<Value>) {
drop(st);
page.add(&bots_group);
let checks = Rc::new(checks);
- // "Alice, Bob" when no name is typed; at most six; nothing to save without a bot.
+ // "Alice, Bob" when no name is typed; nothing to save without a bot.
let sync = {
- let (members, checks, bots_group, name, save) = (
+ let (members, checks, bots_group, name, save, ui2) = (
members.clone(),
checks.clone(),
bots_group.clone(),
name.clone(),
save.clone(),
+ ui.clone(),
);
move || {
let m = members.borrow();
+ while let Some(c) = preview.first_child() {
+ preview.remove(&c);
+ }
+ preview.append(&avatar::of(
+ &ui2.state.borrow().bots,
+ &json!({"kind": "group", "members": *m}),
+ 84,
+ false,
+ "",
+ ));
bots_group.set_title(&format!("Bots · {}", m.len()));
let names: Vec<&str> = m
.iter()
@@ -537,14 +583,19 @@ pub fn group_editor(ui: &App, group: Option<Value>) {
} else {
typed
};
+ let buf = about.buffer();
+ let description = buf
+ .text(&buf.start_iter(), &buf.end_iter(), false)
+ .trim()
+ .to_owned();
let (method, body) = match &group_id {
Some(id) => (
"updateBot",
- json!({"id": id, "name": final_name, "members": m}),
+ json!({"id": id, "name": final_name, "members": m, "description": description}),
),
None => (
"createBot",
- json!({"id": "", "kind": "group", "name": final_name, "members": m}),
+ json!({"id": "", "kind": "group", "name": final_name, "members": m, "description": description}),
),
};
btn.set_sensitive(false);
@@ -616,9 +667,63 @@ pub fn trace(ui: &App) {
.margin_bottom(16)
.build();
let entries = st.entries.get(&id).cloned().unwrap_or_default();
+ // Main chat first, then each thread under its root's text.
+ for (thread, lane) in lanes(&entries) {
+ if let Some(root) = thread {
+ let text = entries
+ .iter()
+ .find(|x| x["id"] == root)
+ .and_then(|x| x["data"]["text"].as_str())
+ .unwrap_or("");
+ list.append(
+ &gtk::Label::builder()
+ .label(format!("Thread · {}", short(text, 60)))
+ .xalign(0.0)
+ .ellipsize(gtk::pango::EllipsizeMode::End)
+ .css_classes(["title-4"])
+ .margin_top(16)
+ .build(),
+ );
+ }
+ trace_lane(&list, &lane);
+ }
+ view.set_content(Some(
+ &gtk::ScrolledWindow::builder()
+ .child(&list)
+ .vexpand(true)
+ .build(),
+ ));
+ dialog.present(Some(&ui.window));
+}
+
+fn short(text: &str, n: usize) -> String {
+ let line = text.lines().next().unwrap_or("");
+ if line.chars().count() > n || text.contains('\n') {
+ format!("{}…", line.chars().take(n).collect::<String>())
+ } else {
+ line.to_owned()
+ }
+}
+
+/// Entries split by lane: the main chat (`None`) first, then threads in the order
+/// they first appear, each keeping its entries' order.
+fn lanes(entries: &[Value]) -> Vec<(Option<String>, Vec<&Value>)> {
+ let mut out: Vec<(Option<String>, Vec<&Value>)> = vec![(None, vec![])];
+ for e in entries {
+ let t = e["threadId"].as_str().map(str::to_owned);
+ match out.iter_mut().find(|(k, _)| *k == t) {
+ Some((_, l)) => l.push(e),
+ None => out.push((t, vec![e])),
+ }
+ }
+ out
+}
+
+/// One lane's entries grouped by turn, each group titled by that turn's message.
+fn trace_lane(list: &gtk::Box, entries: &[&Value]) {
let mut turn = -1i64;
let mut group = adw::PreferencesGroup::new();
- for e in &entries {
+ for e in entries {
let t = e["turn"].as_i64().unwrap_or(0);
if t != turn {
turn = t;
@@ -742,13 +847,6 @@ pub fn trace(ui: &App) {
};
group.add(&widget);
}
- view.set_content(Some(
- &gtk::ScrolledWindow::builder()
- .child(&list)
- .vexpand(true)
- .build(),
- ));
- dialog.present(Some(&ui.window));
}
// MARK: bot menu
@@ -1077,3 +1175,33 @@ pub fn host_missing(ui: &App) {
});
dialog.present(Some(&ui.window));
}
+
+#[cfg(test)]
+mod tests {
+ use super::lanes;
+ use serde_json::json;
+
+ #[test]
+ fn trace_lanes() {
+ let e = [
+ json!({"id": "a"}),
+ json!({"id": "b", "threadId": "a"}),
+ json!({"id": "c"}),
+ json!({"id": "d", "threadId": "c"}),
+ json!({"id": "e", "threadId": "a"}),
+ ];
+ let ids = |l: &[&serde_json::Value]| {
+ l.iter()
+ .map(|x| x["id"].as_str().unwrap_or(""))
+ .collect::<String>()
+ };
+ let l = lanes(&e);
+ assert_eq!(l.len(), 3);
+ assert_eq!((l[0].0.as_deref(), ids(&l[0].1).as_str()), (None, "ac"));
+ assert_eq!(
+ (l[1].0.as_deref(), ids(&l[1].1).as_str()),
+ (Some("a"), "be")
+ );
+ assert_eq!((l[2].0.as_deref(), ids(&l[2].1).as_str()), (Some("c"), "d"));
+ }
+}
diff --git a/apps/linux/src/rows.rs b/apps/linux/src/rows.rs
index dc425404..cdec9745 100644
--- a/apps/linux/src/rows.rs
+++ b/apps/linux/src/rows.rs
@@ -266,8 +266,9 @@ pub fn author_label(st: &State, id: Option<&str>) -> gtk::Widget {
.upcast()
}
-/// A main-chat message with a "Reply in thread" button that shows on hover or focus.
-pub fn with_reply(ui: &App, w: &gtk::Widget, end: bool, root: &str) -> gtk::Widget {
+/// A main-chat message with a "Reply in thread" button that shows on hover or focus,
+/// and the same action (plus Copy) on right-click or long-press, so touchscreens reach it.
+pub fn with_reply(ui: &App, w: &gtk::Widget, end: bool, root: &str, text: &str) -> gtk::Widget {
let host = gtk::Box::builder()
.spacing(4)
.css_classes(["reply-host"])
@@ -281,8 +282,8 @@ pub fn with_reply(ui: &App, w: &gtk::Widget, end: bool, root: &str) -> gtk::Widg
.css_classes(["flat", "circular", "reply-btn"])
.valign(gtk::Align::Center)
.build();
- let (ui2, root) = (ui.clone(), root.to_owned());
- btn.connect_clicked(move |_| ui::open_thread(&ui2, &root));
+ let (ui2, root2) = (ui.clone(), root.to_owned());
+ btn.connect_clicked(move |_| ui::open_thread(&ui2, &root2));
if end {
host.append(&btn);
host.append(w);
@@ -290,9 +291,79 @@ pub fn with_reply(ui: &App, w: &gtk::Widget, end: bool, root: &str) -> gtk::Widg
host.append(w);
host.append(&btn);
}
+ let menu = {
+ let (ui2, root, text, host2) = (ui.clone(), root.to_owned(), text.to_owned(), host.clone());
+ move |x: f64, y: f64| message_menu(&ui2, &host2, x, y, &root, &text)
+ };
+ // Capture phase: runs before the selectable label's own context menu.
+ let click = gtk::GestureClick::builder()
+ .button(gtk::gdk::BUTTON_SECONDARY)
+ .propagation_phase(gtk::PropagationPhase::Capture)
+ .build();
+ {
+ let menu = menu.clone();
+ click.connect_pressed(move |g, _, x, y| {
+ g.set_state(gtk::EventSequenceState::Claimed);
+ menu(x, y);
+ });
+ }
+ host.add_controller(click);
+ let hold = gtk::GestureLongPress::builder()
+ .touch_only(true)
+ .propagation_phase(gtk::PropagationPhase::Capture)
+ .build();
+ hold.connect_pressed(move |g, x, y| {
+ g.set_state(gtk::EventSequenceState::Claimed);
+ menu(x, y);
+ });
+ host.add_controller(hold);
host.upcast()
}
+/// The message's context menu: a popover of flat buttons, like the bot menu.
+fn message_menu(ui: &App, host: &gtk::Box, x: f64, y: f64, root: &str, text: &str) {
+ let pop = gtk::Popover::builder()
+ .pointing_to(&gtk::gdk::Rectangle::new(x as i32, y as i32, 1, 1))
+ .has_arrow(false)
+ .build();
+ let col = gtk::Box::builder()
+ .orientation(gtk::Orientation::Vertical)
+ .spacing(2)
+ .build();
+ let reply = gtk::Button::builder()
+ .label("Reply in thread")
+ .css_classes(["flat"])
+ .build();
+ let copy = gtk::Button::builder()
+ .label("Copy text")
+ .css_classes(["flat"])
+ .build();
+ col.append(&reply);
+ col.append(&copy);
+ pop.set_child(Some(&col));
+ {
+ let (pop2, ui2, root) = (pop.clone(), ui.clone(), root.to_owned());
+ reply.connect_clicked(move |_| {
+ pop2.popdown();
+ ui::open_thread(&ui2, &root);
+ });
+ }
+ {
+ let (pop2, text) = (pop.clone(), text.to_owned());
+ copy.connect_clicked(move |b| {
+ b.clipboard().set_text(&text);
+ pop2.popdown();
+ });
+ }
+ // The chat re-renders often; the popover lives only while shown.
+ pop.connect_closed(|p| {
+ let p = p.clone();
+ gtk::glib::idle_add_local_once(move || p.unparent());
+ });
+ pop.set_parent(host);
+ pop.popup();
+}
+
/// Under a message with a thread (Slack's): who replied, how many, how recently.
pub fn thread_chip(ui: &App, st: &State, e: &Value, end: bool) -> Option<gtk::Widget> {
let t = &e["data"]["thread"];
diff --git a/apps/linux/src/ui.rs b/apps/linux/src/ui.rs
index cedfed79..78837ae1 100644
--- a/apps/linux/src/ui.rs
+++ b/apps/linux/src/ui.rs
@@ -112,7 +112,14 @@ pub struct Ui {
chat_list: gtk::Box,
scroller: gtk::ScrolledWindow,
compose: Composer,
+ convo: gtk::Box,
pane: gtk::Revealer,
+ pane_box: gtk::Box,
+ pane_sep: gtk::Separator,
+ thread_back: gtk::Button,
+ close_thread: gtk::Button,
+ /// Below the breakpoint an open thread covers the chat instead of sitting beside it.
+ narrow: std::cell::Cell<bool>,
pane_title: adw::WindowTitle,
pane_list: gtk::Box,
pane_scroller: gtk::ScrolledWindow,
@@ -220,6 +227,13 @@ pub fn build(app: &adw::Application) {
// Thread pane beside the chat (Slack's).
let pane_title = adw::WindowTitle::new("Thread", "");
+ let thread_back = gtk::Button::builder()
+ .icon_name("go-previous-symbolic")
+ .tooltip_text("Back to chat")
+ .css_classes(["flat", "circular"])
+ .valign(gtk::Align::Center)
+ .visible(false)
+ .build();
let close_thread = gtk::Button::builder()
.icon_name("window-close-symbolic")
.tooltip_text("Close thread")
@@ -228,12 +242,13 @@ pub fn build(app: &adw::Application) {
.build();
let pane_head = gtk::Box::builder()
.spacing(8)
- .margin_start(12)
+ .margin_start(8)
.margin_end(8)
.margin_top(6)
.margin_bottom(6)
.build();
pane_title.set_hexpand(true);
+ pane_head.append(&thread_back);
pane_head.append(&pane_title);
pane_head.append(&close_thread);
let pane_list = entry_list();
@@ -253,7 +268,8 @@ pub fn build(app: &adw::Application) {
pane_box.append(&gtk::Separator::new(gtk::Orientation::Horizontal));
pane_box.append(&reply.root);
let pane_outer = gtk::Box::new(gtk::Orientation::Horizontal, 0);
- pane_outer.append(&gtk::Separator::new(gtk::Orientation::Vertical));
+ let pane_sep = gtk::Separator::new(gtk::Orientation::Vertical);
+ pane_outer.append(&pane_sep);
pane_outer.append(&pane_box);
let pane = gtk::Revealer::builder()
.transition_type(gtk::RevealerTransitionType::SlideLeft)
@@ -295,7 +311,7 @@ pub fn build(app: &adw::Application) {
adw::LengthUnit::Sp,
));
bp.add_setter(&split, "collapsed", Some(&true.to_value()));
- window.add_breakpoint(bp);
+ window.add_breakpoint(bp.clone());
let ui: App = Rc::new(Ui {
window,
@@ -309,7 +325,13 @@ pub fn build(app: &adw::Application) {
chat_list,
scroller,
compose,
+ convo,
pane,
+ pane_box,
+ pane_sep,
+ thread_back: thread_back.clone(),
+ close_thread: close_thread.clone(),
+ narrow: std::cell::Cell::new(false),
pane_title,
pane_list,
pane_scroller,
@@ -344,13 +366,25 @@ pub fn build(app: &adw::Application) {
let ui2 = ui.clone();
group_btn.connect_clicked(move |_| dialogs::group_editor(&ui2, None));
}
- {
+ for b in [&close_thread, &thread_back] {
let ui2 = ui.clone();
- close_thread.connect_clicked(move |_| {
+ b.connect_clicked(move |_| {
ui2.state.borrow_mut().open_thread = None;
schedule(&ui2);
});
}
+ for narrow in [true, false] {
+ let ui2 = ui.clone();
+ let f = move |_: &adw::Breakpoint| {
+ ui2.narrow.set(narrow);
+ schedule(&ui2);
+ };
+ if narrow {
+ bp.connect_apply(f);
+ } else {
+ bp.connect_unapply(f);
+ }
+ }
{
let ui2 = ui.clone();
settings_btn.connect_clicked(move |_| dialogs::settings(&ui2));
@@ -912,11 +946,13 @@ fn render_pane(ui: &App) {
st.current.as_ref().and_then(|id| st.bots.get(id)),
st.open_thread.as_deref(),
) else {
+ layout_pane(ui, false);
ui.pane.set_reveal_child(false);
ui.shown_thread.replace(String::new());
return;
};
let id = bot["id"].as_str().unwrap_or_default();
+ layout_pane(ui, true);
ui.pane.set_reveal_child(true);
ui.pane_title
.set_subtitle(bot["name"].as_str().unwrap_or(""));
@@ -956,6 +992,19 @@ fn render_pane(ui: &App) {
}
}
+/// Wide windows keep the thread in a side pane; narrow ones let it cover the chat,
+/// with a back button in place of close.
+fn layout_pane(ui: &App, open: bool) {
+ let cover = open && ui.narrow.get();
+ ui.convo.set_visible(!cover);
+ ui.pane.set_hexpand(cover);
+ ui.pane_box.set_hexpand(cover);
+ ui.pane_box.set_width_request(if cover { -1 } else { 380 });
+ ui.pane_sep.set_visible(!cover);
+ ui.thread_back.set_visible(cover);
+ ui.close_thread.set_visible(!cover);
+}
+
/// Chat-visible entries with time separators (gaps > 1 h) and author grouping.
/// `main`: the main chat, where messages can start threads and show their summary.
fn append_entries(
@@ -1000,7 +1049,13 @@ fn append_entries(
let reply = |w: gtk::Widget, end: bool| {
// Local echoes have no id on the host yet.
if main && !entry_id.starts_with("local-") {
- with_reply(ui, &w, end, entry_id)
+ with_reply(
+ ui,
+ &w,
+ end,
+ entry_id,
+ e["data"]["text"].as_str().unwrap_or(""),
+ )
} else {
w
}
diff --git a/docs/features/groups-and-threads.md b/docs/features/groups-and-threads.md
index 087836ab..692caf96 100644
--- a/docs/features/groups-and-threads.md
+++ b/docs/features/groups-and-threads.md
@@ -30,7 +30,7 @@ replies itself.
|---|---|---|
| `send` | `botId, text, clientNonce, threadId?` | `botId` is a bot or a group. `threadId` replies in that root's thread. Works in the relay mailbox too. |
| `thread` | `botId, rootId` | `{entries}`: the thread's replies, oldest first. |
-| `createBot` | `{kind:"group", name, members}` | Returns the existing group when these exact bots already share one. |
+| `createBot` | `{kind:"group", name, description?, members}` | Returns the existing group when these exact bots already share one. |
| `updateBot` | `{id, name?, members?, pinned?, hidden?}` | A group can't become a bot or the reverse. |
| `deleteBot` | `botId` | A group's bots stay. A deleted bot leaves its groups. |
| `stop` | `botId` | For a group: ends its room turns (main and threads) and stops members working in it. |
@@ -43,6 +43,7 @@ replies itself.
- Who answers each round: the members @-mentioned since the user's last message (full
name, name without spaces, or first word; `@all` / `@everyone`), or everyone if none is.
Members speak one at a time; each round starts one member later.
+- A group's `description` ("About") tells its members what the room is for.
- A member runs the turn in its **own main session** (its history is unified across chats),
told who's in the room and what was said since it last spoke there, framed as
`[Group chat: "<name>" - with …]`. Its final reply is the one message the room sees; replying
@@ -62,7 +63,7 @@ replies itself.
## Client checklist
-Roster row for groups (member avatars), author label on group replies, the thread summary
+Roster row for groups (member avatars), a trace per lane (main chat, or one thread), author label on group replies, the thread summary
under a root (opens the thread), "Reply in thread" on any main-chat message, a thread view
(root, replies, composer sending `threadId`), group create/edit (name, members), Stop in a
group calls `stop` with the group id.
diff --git a/host/src/group.rs b/host/src/group.rs
index f8d4b7d1..cfe92afa 100644
--- a/host/src/group.rs
+++ b/host/src/group.rs
@@ -214,10 +214,10 @@ fn member_prompt(hub: &Hub, group: &BotConfig, members: &[BotConfig], me: &BotCo
} else {
peers.iter().map(|p| p.name.as_str()).collect::<Vec<_>>().join(", ")
};
- let mut out = vec![format!(
- "You are {}, one participant in a group chat (\"{}\") with the user and {peer_names}.",
- me.name, group.name
- )];
+ let about = group.description.trim();
+ let room = if about.is_empty() { format!("\"{}\"", group.name) } else { format!("\"{}\" — {about}", group.name) };
+ let mut out =
+ vec![format!("You are {}, one participant in a group chat ({room}) with the user and {peer_names}.", me.name)];
if !peers.is_empty() {
out.push("Other participants in the room:".into());
for p in &peers {
@@ -354,7 +354,7 @@ mod tests {
let group = hub
.create_bot(
serde_json::from_value(
- json!({"id": "", "kind": "group", "name": "Crew", "members": ["a", "b", "a"]}),
+ json!({"id": "", "kind": "group", "name": "Crew", "description": "Ship the release", "members": ["a", "b", "a"]}),
)
.unwrap(),
)
@@ -435,6 +435,11 @@ mod tests {
assert_eq!(room.replies(&main).len(), 2);
let listed = room.hub.bot_value_for_test(&room.group);
assert_eq!(listed["lastMessage"], "b: reply: group");
+ let prompts = std::fs::read_to_string(room.dir.join("a/prompts.jsonl")).unwrap();
+ assert!(
+ prompts.contains("Ship the release) with the user"),
+ "members are told what the room is for: {prompts}"
+ );
// The members' own chats stay private: the room's entries live in the group.
assert!(room.hub.store.messages_after(&Lane::main("a"), 0, 100).unwrap().is_empty());
room.shutdown().await;
diff --git a/host/src/tui/app.rs b/host/src/tui/app.rs
index 794bed53..8894f63a 100644
--- a/host/src/tui/app.rs
+++ b/host/src/tui/app.rs
@@ -387,6 +387,8 @@ pub enum Action {
Keys,
}
+pub const NEW_GROUP: &str = "New group chat";
+
pub const ACTIONS: [(&str, &str, Action); 6] = [
("New bot…", "n", Action::NewBot),
("New group chat…", "m", Action::NewGroup),
@@ -508,15 +510,37 @@ impl Form {
}
}
+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
+pub enum GroupField {
+ Name,
+ About,
+ Bots,
+}
+
+impl GroupField {
+ fn next(self) -> Self {
+ match self {
+ Self::Name => Self::About,
+ Self::About => Self::Bots,
+ Self::Bots => Self::Name,
+ }
+ }
+
+ fn prev(self) -> Self {
+ self.next().next()
+ }
+}
+
/// Create a group chat, or rename one and change who's in it.
pub struct GroupForm {
/// The group being edited; `None` creates one.
pub group_id: Option<String>,
pub name: Editor,
+ /// What the group is for; sent as `description`, shown to its members.
+ pub about: Editor,
/// Picked bot ids, in the order they were picked.
pub members: Vec<String>,
- /// Typing the name (else moving in the bot list).
- pub on_name: bool,
+ pub field: GroupField,
pub cursor: usize,
pub error: Option<String>,
pub saving: bool,
@@ -867,6 +891,10 @@ impl App {
self.bots.clear();
self.entries.clear();
self.history_done.clear();
+ // Catch-up carries only recent thread replies: fetch the open thread whole again.
+ if let (Some(id), Some(root)) = (&self.selected, &self.thread) {
+ self.call("thread", json!({"botId": id, "rootId": root}), After::Thread);
+ }
}
Msg::Event(v) => self.on_event(&v),
Msg::Reply(after, r) => self.on_reply(after, r),
@@ -1072,7 +1100,11 @@ impl App {
Overlay::Help(e) => Some(e),
Overlay::Agents(a) => Some(&mut a.query),
Overlay::Folder(p) => Some(&mut p.query),
- Overlay::Group(g) if g.on_name => Some(&mut g.name),
+ Overlay::Group(g) => match g.field {
+ GroupField::Name => Some(&mut g.name),
+ GroupField::About => Some(&mut g.about),
+ GroupField::Bots => None,
+ },
Overlay::Form(f) => match f.current() {
Field::Name => Some(&mut f.name),
Field::Instructions => Some(&mut f.instructions),
@@ -1529,8 +1561,9 @@ impl App {
self.overlays.push(Overlay::Group(GroupForm {
group_id: None,
name: Editor::default(),
+ about: Editor::default(),
members: vec![],
- on_name: false,
+ field: GroupField::Bots,
cursor: 0,
error: None,
saving: false,
@@ -1557,12 +1590,14 @@ impl App {
KeyCode::Esc => return None,
KeyCode::Enter => self.save_group(&mut g),
KeyCode::Char('s') if ctrl => self.save_group(&mut g),
- KeyCode::Tab | KeyCode::BackTab => g.on_name = !g.on_name,
- KeyCode::Down if g.on_name => g.on_name = false,
+ KeyCode::Tab => g.field = g.field.next(),
+ KeyCode::BackTab => g.field = g.field.prev(),
+ KeyCode::Down if g.field != GroupField::Bots => g.field = g.field.next(),
KeyCode::Down => g.cursor = (g.cursor + 1).min(n.saturating_sub(1)),
- KeyCode::Up if g.cursor == 0 => g.on_name = true,
- KeyCode::Up if !g.on_name => g.cursor -= 1,
- KeyCode::Char(' ') if !g.on_name => {
+ KeyCode::Up if g.field == GroupField::About => g.field = GroupField::Name,
+ KeyCode::Up if g.field == GroupField::Bots && g.cursor == 0 => g.field = GroupField::About,
+ KeyCode::Up if g.field == GroupField::Bots => g.cursor -= 1,
+ KeyCode::Char(' ') if g.field == GroupField::Bots => {
let id = self.group_candidates(&g.members).get(g.cursor).map(|b| b.id.clone());
if let Some(id) = id {
g.error = None;
@@ -1573,9 +1608,12 @@ impl App {
}
}
}
- _ if g.on_name => {
+ _ if g.field == GroupField::Name => {
g.name.key(k);
}
+ _ if g.field == GroupField::About => {
+ g.about.key(k);
+ }
_ => {}
}
Some(Overlay::Group(g))
@@ -1591,7 +1629,7 @@ impl App {
}
let typed = g.name.text.trim();
let name = if typed.is_empty() { self.group_default_name(&g.members) } else { typed.to_owned() };
- let mut body = json!({"name": name, "members": g.members});
+ let mut body = json!({"name": name, "members": g.members, "description": g.about.text.trim()});
g.saving = true;
g.error = None;
if let Some(id) = &g.group_id {
@@ -1610,8 +1648,9 @@ impl App {
self.overlays.push(Overlay::Group(GroupForm {
group_id: Some(b.id.clone()),
name: Editor::with(&b.name),
+ about: Editor::with(&b.description),
members: b.members.clone(),
- on_name: true,
+ field: GroupField::Name,
cursor: 0,
error: None,
saving: false,
@@ -1771,12 +1810,22 @@ impl App {
Some(Overlay::Goto(g))
}
+ /// The agent picker's last row, "New group chat", when the filter matches it.
+ pub fn agent_group_row(query: &str) -> bool {
+ fuzzy(query, &[NEW_GROUP])
+ }
+
fn agents_key(&mut self, mut a: AgentPicker, k: KeyEvent) -> Option<Overlay> {
- let n = self.agent_choices(&a.query.text).len();
+ let agents = self.agent_choices(&a.query.text).len();
+ let n = agents + usize::from(Self::agent_group_row(&a.query.text));
match k.code {
KeyCode::Esc => return None,
KeyCode::Down => a.cursor = (a.cursor + 1).min(n.saturating_sub(1)),
KeyCode::Up => a.cursor = a.cursor.saturating_sub(1),
+ KeyCode::Enter if a.cursor == agents && Self::agent_group_row(&a.query.text) => {
+ self.new_group();
+ return None;
+ }
KeyCode::Enter => {
let backend =
self.agent_choices(&a.query.text).get(a.cursor).and_then(|b| b["id"].as_str()).map(str::to_owned);
diff --git a/host/src/tui/view.rs b/host/src/tui/view.rs
index 8925f619..e9c29ce1 100644
--- a/host/src/tui/view.rs
+++ b/host/src/tui/view.rs
@@ -15,8 +15,8 @@ use std::collections::{BTreeSet, HashMap};
use std::sync::LazyLock;
use super::app::{
- ACTIONS, App, Bot, COLORS, Click, Editor, Entry, FIELDS, FILTERS, Field, Focus, Form, GotoItem, GroupForm, Kind,
- Mark, Overlay, SHAPES, Status, TraceMode, Width, tilde,
+ ACTIONS, App, Bot, COLORS, Click, Editor, Entry, FIELDS, FILTERS, Field, Focus, Form, GotoItem, GroupField,
+ GroupForm, Kind, Mark, NEW_GROUP, Overlay, SHAPES, Status, TraceMode, Width, tilde,
};
use super::md::{self, truncate, width as w};
@@ -157,17 +157,35 @@ pub fn glyph(app: &App, m: Mark) -> (&'static str, Style) {
}
}
-fn avatar(b: &Bot) -> Span<'static> {
+fn avatar(app: &App, b: &Bot) -> Line<'static> {
let t = theme();
if b.group {
- // A group: # and how many bots are in it.
- return Span::styled(format!("#{}", b.members.len().min(9)), t.bold.patch(t.btn));
+ // A group: its first two bots, like the apps' avatar stack.
+ let mut v: Vec<Span<'static>> = b.members.iter().take(2).map(|m| person(app, m)).collect();
+ v.resize(2, Span::raw(" "));
+ return Line::from(v);
}
- if t.color {
+ Line::from(if t.color {
Span::styled("••", Style::default().fg(t.on_color).bg(bot_color(&b.color)).add_modifier(Modifier::BOLD))
} else {
Span::styled("[]", t.bold)
+ })
+}
+
+/// One cell for a bot id (its initial on its color) or `"user"` (Y), as in a group's avatar stack.
+fn person(app: &App, id: &str) -> Span<'static> {
+ let t = theme();
+ if id == "user" {
+ return Span::styled("Y", t.text.patch(t.btn).add_modifier(Modifier::BOLD));
}
+ let Some(b) = app.bots.get(id) else { return Span::styled("?", t.dim) };
+ let initial: String = b.name.chars().next().map_or_else(|| "?".into(), |c| c.to_uppercase().collect());
+ let style = if t.color {
+ Style::default().fg(t.on_color).bg(bot_color(&b.color)).add_modifier(Modifier::BOLD)
+ } else {
+ t.bold
+ };
+ Span::styled(initial, style)
}
pub const FACE: [&str; 7] = [
@@ -575,7 +593,7 @@ fn roster(buf: &mut Buffer, r: Rect, app: &mut App, narrow: bool) {
put(buf, x0, yy, 1, "▌", bar);
put(buf, x0, yy + 1, 1, "▌", bar);
}
- put_line(buf, x0 + 2, yy, 2, &Line::from(avatar(b)));
+ put_line(buf, x0 + 2, yy, 2, &avatar(app, b));
let (g, gs) = glyph(app, b.mark());
let time = if b.status == Status::Working { elapsed(b.started_at) } else { when(b.last_at) };
let tx = rput(buf, r.right() - 1, yy, &time, if b.unread > 0 { t.bold } else { t.dim });
@@ -646,7 +664,7 @@ fn compact_roster(buf: &mut Buffer, r: Rect, app: &mut App) {
restyle(buf, row, t.sel);
put(buf, r.x, y, 1, "▌", if app.focus == Focus::Roster { t.bold } else { t.secondary });
}
- put_line(buf, r.x + 1, y, 2, &Line::from(avatar(b)));
+ put_line(buf, r.x + 1, y, 2, &avatar(app, b));
let (g, gs) = glyph(app, b.mark());
put(buf, r.x + 3, y, 1, g, gs);
}
@@ -681,7 +699,7 @@ fn chat(buf: &mut Buffer, r: Rect, app: &mut App, narrow: bool) {
fill(buf, Rect::new(r.x, r.y, r.width, 1), t.panel);
x = put(buf, x, r.y, 2, "‹", t.bold) + 1;
}
- put_line(buf, x, r.y, 2, &Line::from(avatar(&b)));
+ put_line(buf, x, r.y, 2, &avatar(app, &b));
let title = if app.thread.is_some() { format!("Thread · {}", b.name) } else { b.name.clone() };
x = put(buf, x + 3, r.y, r.width / 3, &title, t.bold) + 2;
let (status, ss) = match b.mark() {
@@ -1027,7 +1045,7 @@ fn entry_lines(
out.lines.extend(with_bg(body, width, t.band));
out.messages.push((e.id.clone(), from, out.lines.len()));
if main {
- thread_line(out, e);
+ thread_line(out, app, e);
}
}
Kind::Agent if e.is_final() => {
@@ -1055,7 +1073,7 @@ fn entry_lines(
)));
}
if main {
- thread_line(out, e);
+ thread_line(out, app, e);
}
}
Kind::Permission => {
@@ -1095,10 +1113,22 @@ fn entry_lines(
}
/// Under a message with a thread: how many replies, how recently (click opens it).
-fn thread_line(out: &mut Built, e: &Entry) {
+fn thread_line(out: &mut Built, app: &App, e: &Entry) {
let Some(text) = thread_summary(&e.data["thread"]) else { return };
- out.buttons.push((out.lines.len(), 3, u(w(&text)), Click::Thread(e.id.clone())));
- out.lines.push(Line::from(vec![Span::raw(" "), Span::styled(text, theme().secondary)]));
+ let mut line = vec![Span::raw(" "), Span::styled(text, theme().secondary)];
+ // Who replied: one cell each, first reply first (the host keeps them distinct).
+ let authors: Vec<&str> =
+ e.data["thread"]["authors"].as_array().into_iter().flatten().filter_map(|a| a.as_str()).collect();
+ for a in authors.iter().take(5) {
+ line.push(Span::raw(" "));
+ line.push(person(app, a));
+ }
+ if authors.len() > 5 {
+ line.push(Span::styled(format!(" +{}", authors.len() - 5), theme().dim));
+ }
+ let width = u(line.iter().skip(1).map(|s| w(&s.content)).sum());
+ out.buttons.push((out.lines.len(), 3, width, Click::Thread(e.id.clone())));
+ out.lines.push(Line::from(line));
}
/// "↳ 3 replies · 12:31" from the host's `data.thread`, or nothing without replies.
@@ -1507,13 +1537,14 @@ fn overlay(buf: &mut Buffer, area: Rect, app: &mut App, top: &Overlay) {
Overlay::Agents(a) => {
let t = theme();
let choices: Vec<serde_json::Value> = app.agent_choices(&a.query.text).into_iter().cloned().collect();
- let h = u(choices.len() + 8).min(area.height.saturating_sub(2)).max(10);
+ let group_row = App::agent_group_row(&a.query.text);
+ let h = u(choices.len() + usize::from(group_row) + 8).min(area.height.saturating_sub(2)).max(10);
let r = centered(area, 74, h);
let inner = frame_box(buf, r, t.text, t.panel, Some(("New bot · 1/3 agent", t.text)));
field_line(buf, inner, inner.y, &a.query, "type to filter", true);
let list_h = usize::from(inner.height.saturating_sub(4));
let off = a.cursor.saturating_sub(list_h.saturating_sub(1));
- if choices.is_empty() {
+ if choices.is_empty() && !group_row {
put(
buf,
inner.x,
@@ -1550,6 +1581,19 @@ fn overlay(buf: &mut Buffer, area: Rect, app: &mut App, top: &Overlay) {
let how = if installed { "on this computer".to_owned() } else { "fetched on first use".to_owned() };
rput(buf, inner.right(), y, &how, t.dim.patch(base));
}
+ // Last row: a group chat instead of a bot.
+ let gi = choices.len();
+ if group_row && gi >= off && gi < off + list_h {
+ let y = inner.y + 2 + u(gi - off);
+ let sel = gi == a.cursor;
+ let base = if sel { t.sel } else { t.panel };
+ if sel {
+ restyle(buf, Rect::new(inner.x - 1, y, inner.width + 2, 1), t.sel);
+ }
+ put(buf, inner.x, y, 2, "+", t.secondary.patch(base));
+ put(buf, inner.x + 2, y, inner.width / 2, NEW_GROUP, if sel { t.bold } else { t.text }.patch(base));
+ rput(buf, inner.right(), y, "several bots, one chat", t.dim.patch(base));
+ }
put(
buf,
inner.x,
@@ -1698,7 +1742,7 @@ fn goto(buf: &mut Buffer, area: Rect, app: &mut App, g: &super::app::Goto, items
app.hits.clicks.push((Rect::new(inner.x - 1, y, inner.width + 2, 1), Click::Bot(id.clone())));
let (gl, gs) = glyph(app, b.mark());
put(buf, inner.x, y, 1, gl, gs.patch(base));
- put_line(buf, inner.x + 2, y, 2, &Line::from(avatar(b)));
+ put_line(buf, inner.x + 2, y, 2, &avatar(app, b));
put(buf, inner.x + 5, y, 10, &b.name, t.bold.patch(base));
put(buf, inner.x + 16, y, 10, if b.group { "group" } else { &b.backend }, t.secondary.patch(base));
let cwd =
@@ -1995,11 +2039,12 @@ fn form_view(buf: &mut Buffer, area: Rect, app: &App, f: &Form) {
fn group_view(buf: &mut Buffer, area: Rect, app: &App, g: &GroupForm) {
let t = theme();
let bots = app.group_candidates(&g.members);
- let r = centered(area, 74, u(bots.len() + 10).max(14));
+ let r = centered(area, 74, u(bots.len() + 12).max(16));
let title = if g.group_id.is_some() { "Group chat" } else { "New group chat" };
let inner = frame_box(buf, r, t.text, t.panel, Some((title, t.text)));
let label = |on: bool| if on { t.bold } else { t.secondary }.patch(t.panel);
- put(buf, inner.x, inner.y, 8, "Name", label(g.on_name));
+ let on_bots = g.field == GroupField::Bots;
+ put(buf, inner.x, inner.y, 8, "Name", label(g.field == GroupField::Name));
let default = app.group_default_name(&g.members);
let placeholder = if default.is_empty() { "Name" } else { default.as_str() };
field_line(
@@ -2008,23 +2053,32 @@ fn group_view(buf: &mut Buffer, area: Rect, app: &App, g: &GroupForm) {
inner.y,
&g.name,
placeholder,
- g.on_name,
+ g.field == GroupField::Name,
+ );
+ put(buf, inner.x, inner.y + 2, 8, "About", label(g.field == GroupField::About));
+ field_line(
+ buf,
+ Rect::new(inner.x + 8, inner.y + 2, inner.width.saturating_sub(8), 1),
+ inner.y + 2,
+ &g.about,
+ "optional: what this group is for",
+ g.field == GroupField::About,
);
- put(buf, inner.x, inner.y + 2, inner.width, &format!("Bots · {}", g.members.len()), label(!g.on_name));
- let list_h = usize::from(inner.height.saturating_sub(7));
+ put(buf, inner.x, inner.y + 4, inner.width, &format!("Bots · {}", g.members.len()), label(on_bots));
+ let list_h = usize::from(inner.height.saturating_sub(9));
let off = g.cursor.saturating_sub(list_h.saturating_sub(1));
if bots.is_empty() {
- put(buf, inner.x, inner.y + 3, inner.width, "No bots yet. n creates one.", t.dim.patch(t.panel));
+ put(buf, inner.x, inner.y + 5, inner.width, "No bots yet. n creates one.", t.dim.patch(t.panel));
}
- for (y, (i, b)) in (inner.y + 3..).zip(bots.iter().enumerate().skip(off).take(list_h)) {
- let sel = !g.on_name && i == g.cursor;
+ for (y, (i, b)) in (inner.y + 5..).zip(bots.iter().enumerate().skip(off).take(list_h)) {
+ let sel = on_bots && i == g.cursor;
let base = if sel { t.sel } else { t.panel };
if sel {
restyle(buf, Rect::new(inner.x - 1, y, inner.width + 2, 1), t.sel);
}
let on = g.members.contains(&b.id);
put(buf, inner.x, y, 2, if on { "☑" } else { "☐" }, if on { t.bold } else { t.dim }.patch(base));
- put_line(buf, inner.x + 2, y, 2, &Line::from(avatar(b)));
+ put_line(buf, inner.x + 2, y, 2, &avatar(app, b));
put(buf, inner.x + 5, y, inner.width / 2, &b.name, if sel { t.bold } else { t.text }.patch(base));
let folder =
std::path::Path::new(&b.cwd).file_name().map(|f| f.to_string_lossy().into_owned()).unwrap_or_default();
@@ -2056,7 +2110,7 @@ fn group_view(buf: &mut Buffer, area: Rect, app: &App, g: &GroupForm) {
buf,
inner.right(),
by,
- if g.on_name { "tab bots" } else { "↑↓ move · space pick · tab name" },
+ if on_bots { "↑↓ move · space pick · tab name" } else { "tab next field" },
t.dim.patch(t.panel),
);
}
diff --git a/kit/Sources/CodyncKit/Models/Models.swift b/kit/Sources/CodyncKit/Models/Models.swift
index d4bf9387..88e75e66 100644
--- a/kit/Sources/CodyncKit/Models/Models.swift
+++ b/kit/Sources/CodyncKit/Models/Models.swift
@@ -383,17 +383,21 @@ public struct GroupDraft: Codable, Hashable, Sendable {
public var id: String?
public var kind = "group"
public var name: String
+ /// What the group is for; its bots are told.
+ public var description = ""
public var members: [String]
public var pinned: Bool?
- public init(name: String, members: [String]) {
+ public init(name: String, description: String = "", members: [String]) {
self.name = name
+ self.description = description
self.members = members
}
public init(_ group: Bot) {
id = group.id
name = group.name
+ description = group.description
members = group.members
pinned = group.pinned
}
diff --git a/kit/Sources/CodyncUI/Bots/GroupEditorView.swift b/kit/Sources/CodyncUI/Bots/GroupEditorView.swift
index 2372a44d..c7891459 100644
--- a/kit/Sources/CodyncUI/Bots/GroupEditorView.swift
+++ b/kit/Sources/CodyncUI/Bots/GroupEditorView.swift
@@ -1,14 +1,17 @@
import CodyncKit
import SwiftUI
-/// Create a group chat, or rename one and change who's in it.
+/// Create a group chat, or change its name, what it's for and who's in it. Bots are
+/// picked like recipients: chips on top, a search, and the bots not in it yet.
public struct GroupEditorView: View {
@Environment(BotStore.self) private var model
@Environment(\.dismissModal) private var dismiss
/// The group being edited; nil creates one.
let groupId: String?
@State private var name: String
+ @State private var about: String
@State private var members: [String]
+ @State private var query = ""
@State private var saving = false
@State private var error: String?
@State private var confirmDelete: Bot?
@@ -16,10 +19,16 @@ public struct GroupEditorView: View {
public init(group: Bot? = nil, members: [String] = []) {
groupId = group?.id
_name = State(initialValue: group?.name ?? "")
+ _about = State(initialValue: group?.description ?? "")
_members = State(initialValue: group?.members ?? members)
}
- private var candidates: [Bot] { model.roster.filter { !$0.isGroup } + model.hiddenBots.filter { members.contains($0.id) } }
+ private var picked: [Bot] { members.compactMap { model.bots[$0] } }
+ /// Bots that can still join, filtered by the search.
+ private var candidates: [Bot] {
+ let q = query.trimmingCharacters(in: .whitespaces)
+ return model.roster.filter { !$0.isGroup && !members.contains($0.id) && (q.isEmpty || $0.name.localizedCaseInsensitiveContains(q)) }
+ }
private var isNew: Bool { groupId == nil }
private var canSave: Bool { !members.isEmpty && !saving }
@@ -35,20 +44,41 @@ public struct GroupEditorView: View {
}
ScrollView {
VStack(alignment: .leading, spacing: InterfaceMetrics.value(mac: 12, mobile: 18)) {
- GroupAvatar(members: members.compactMap { model.bots[$0] }, size: 72)
+ GroupAvatar(members: picked, size: 72)
.frame(maxWidth: .infinity)
.animation(Motion.layout, value: members)
- Field("Name") {
- TextField(defaultName, text: $name).fieldBox()
- }
Field("Bots · \(members.count)") {
- VStack(spacing: 2) {
- ForEach(candidates) { bot in memberRow(bot) }
+ VStack(alignment: .leading, spacing: 8) {
+ if !picked.isEmpty {
+ ScrollView(.horizontal, showsIndicators: false) {
+ HStack(spacing: 6) {
+ ForEach(picked) { bot in
+ BotChip(bot: bot) { toggle(bot.id) }
+ .transition(.scale(scale: 0.85).combined(with: .opacity))
+ }
+ }
+ }
+ }
+ TextField(picked.isEmpty ? "Search bots" : "Add another bot", text: $query)
+ .fieldBox()
+ .onSubmit { if let first = candidates.first { toggle(first.id) } }
+ VStack(spacing: 2) {
+ ForEach(candidates) { bot in candidateRow(bot) }
+ }
}
+ .animation(Motion.layout, value: members)
Text("Everyone answers in turn unless you @mention someone. Each bot works in its own folder with its own tools.")
.font(.caption)
.foregroundStyle(Palette.tertiary)
}
+ Field("Name") {
+ TextField(defaultName, text: $name).fieldBox()
+ }
+ Field("About") {
+ TextField("What this group works on (optional)", text: $about, axis: .vertical)
+ .lineLimit(2...5)
+ .fieldBox()
+ }
if let error {
Text(error).font(.footnote).foregroundStyle(Palette.danger).transition(.opacity)
}
@@ -60,6 +90,7 @@ public struct GroupEditorView: View {
}
.padding(InterfaceMetrics.value(mac: 16, mobile: 20))
}
+ .scrollDismissesKeyboard(.interactively)
}
.background(Palette.background)
.deleteBotConfirmation($confirmDelete) { dismiss() }
@@ -67,17 +98,19 @@ public struct GroupEditorView: View {
/// "Alice, Bob" when no name is typed.
private var defaultName: String {
- let names = members.compactMap { model.bots[$0]?.name }
+ let names = picked.map(\.name)
return names.isEmpty ? "Name" : names.joined(separator: ", ")
}
- private func memberRow(_ bot: Bot) -> some View {
- let on = members.contains(bot.id)
- return Button {
- withAnimation(Motion.layout) {
- if on { members.removeAll { $0 == bot.id } } else { members.append(bot.id) }
- }
- } label: {
+ private func toggle(_ id: String) {
+ withAnimation(Motion.layout) {
+ if members.contains(id) { members.removeAll { $0 == id } } else { members.append(id) }
+ }
+ query = ""
+ }
+
+ private func candidateRow(_ bot: Bot) -> some View {
+ Button { toggle(bot.id) } label: {
HStack(spacing: 12) {
CharacterAvatar(bot: bot, size: InterfaceMetrics.value(mac: 26, mobile: 34), animated: false)
VStack(alignment: .leading, spacing: 1) {
@@ -85,17 +118,16 @@ public struct GroupEditorView: View {
Text(bot.folderName).font(.caption).foregroundStyle(Palette.tertiary).lineLimit(1)
}
Spacer()
- Image(systemName: on ? "checkmark.circle.fill" : "circle")
+ Image(systemName: "plus.circle")
.font(.system(size: 20))
- .foregroundStyle(on ? Palette.accent : Palette.tertiary)
- .contentTransition(.symbolEffect(.replace))
+ .foregroundStyle(Palette.tertiary)
}
.padding(.horizontal, 12)
.padding(.vertical, 8)
.contentShape(Rectangle())
}
.buttonStyle(PressScale())
- .accessibilityAddTraits(on ? .isSelected : [])
+ .accessibilityLabel("Add \(bot.name)")
}
private func save() {
@@ -103,14 +135,16 @@ public struct GroupEditorView: View {
error = nil
let typed = name.trimmingCharacters(in: .whitespacesAndNewlines)
let finalName = typed.isEmpty ? defaultName : typed
+ let about = about.trimmingCharacters(in: .whitespacesAndNewlines)
Task {
do {
if let groupId {
- var draft = GroupDraft(name: finalName, members: members)
+ var draft = GroupDraft(name: finalName, description: about, members: members)
draft.id = groupId
+ draft.pinned = model.bots[groupId]?.pinned
try await model.updateGroup(draft)
} else {
- _ = try await model.createGroup(name: finalName, members: members)
+ _ = try await model.createGroup(name: finalName, description: about, members: members)
}
dismiss()
} catch {
@@ -120,3 +154,36 @@ public struct GroupEditorView: View {
}
}
}
+
+/// A picked bot (To: field, group editor); its x takes it back out.
+struct BotChip: View {
+ let bot: Bot
+ let remove: () -> Void
+
+ var body: some View {
+ HStack(spacing: 6) {
+ CharacterAvatar(bot: bot, size: 20, animated: false)
+ Text(bot.name)
+ .font(.body)
+ .foregroundStyle(Palette.text)
+ .lineLimit(1)
+ .frame(maxWidth: 220, alignment: .leading)
+ .fixedSize(horizontal: true, vertical: false)
+ Button(action: remove) {
+ Image(systemName: "xmark")
+ .font(.system(size: 10, weight: .semibold))
+ .foregroundStyle(Palette.secondary)
+ .frame(width: 18, height: 18)
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .accessibilityLabel("Remove \(bot.name)")
+ .help("Remove \(bot.name)")
+ }
+ .padding(.leading, 8)
+ .padding(.trailing, 6)
+ .padding(.vertical, 5)
+ .background(Palette.bubbleAgent, in: Capsule())
+ }
+}
+
diff --git a/kit/Sources/CodyncUI/Bots/NewChatView.swift b/kit/Sources/CodyncUI/Bots/NewChatView.swift
index f15147c9..3d39bb7c 100644
--- a/kit/Sources/CodyncUI/Bots/NewChatView.swift
+++ b/kit/Sources/CodyncUI/Bots/NewChatView.swift
@@ -35,7 +35,7 @@ public struct NewChatView: View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 6) {
ForEach(picked) { bot in
- RecipientChip(bot: bot) { remove(bot.id) }
+ BotChip(bot: bot) { remove(bot.id) }
.transition(.scale(scale: 0.85).combined(with: .opacity))
}
TextField(recipients.isEmpty ? "Search or create bots" : "Add another bot", text: $query)
@@ -203,38 +203,6 @@ public struct NewChatView: View {
}
}
-/// A picked bot in the To: field; its x takes it back out.
-private struct RecipientChip: View {
- let bot: Bot
- let remove: () -> Void
-
- var body: some View {
- HStack(spacing: 6) {
- CharacterAvatar(bot: bot, size: 20, animated: false)
- Text(bot.name)
- .font(.body)
- .foregroundStyle(Palette.text)
- .lineLimit(1)
- .frame(maxWidth: 220, alignment: .leading)
- .fixedSize(horizontal: true, vertical: false)
- Button(action: remove) {
- Image(systemName: "xmark")
- .font(.system(size: 10, weight: .semibold))
- .foregroundStyle(Palette.secondary)
- .frame(width: 18, height: 18)
- .contentShape(Rectangle())
- }
- .buttonStyle(.plain)
- .accessibilityLabel("Remove \(bot.name)")
- .help("Remove \(bot.name)")
- }
- .padding(.leading, 8)
- .padding(.trailing, 6)
- .padding(.vertical, 5)
- .background(Palette.bubbleAgent, in: Capsule())
- }
-}
-
private struct PickRow<Icon: View, Label: View>: View {
let shortcut: Int?
let action: () -> Void
diff --git a/kit/Sources/CodyncUI/Store/BotStore.swift b/kit/Sources/CodyncUI/Store/BotStore.swift
index 2236b3a5..60376121 100644
--- a/kit/Sources/CodyncUI/Store/BotStore.swift
+++ b/kit/Sources/CodyncUI/Store/BotStore.swift
@@ -631,8 +631,8 @@ public final class BotStore {
}
/// Creates a group chat (or opens the one these bots already share) and selects it.
- public func createGroup(name: String, members: [String]) async throws -> Bot {
- let group = try await require().createGroup(GroupDraft(name: name, members: members))
+ public func createGroup(name: String, description: String = "", members: [String]) async throws -> Bot {
+ let group = try await require().createGroup(GroupDraft(name: name, description: description, members: members))
bots[group.id] = group
selection = group.id
return group
diff --git a/kit/Sources/CodyncUI/Thread/RepliesView.swift b/kit/Sources/CodyncUI/Thread/RepliesView.swift
index 9970c395..b28fae21 100644
--- a/kit/Sources/CodyncUI/Thread/RepliesView.swift
+++ b/kit/Sources/CodyncUI/Thread/RepliesView.swift
@@ -64,8 +64,11 @@ struct RepliesView: View {
}
.background(Palette.background)
.task(id: rootId) { await model.loadThread(botId, root: rootId) }
+ // Replies count as unread too: reading the thread reads them.
+ .onAppear { model.markRead(botId) }
+ .onChange(of: replies.last?.id) { _, _ in model.markRead(botId) }
.codyncSheet(isPresented: $showTrace) {
- TraceView(botId: botId)
+ TraceView(botId: botId, thread: rootId)
#if os(macOS)
.frame(width: 620, height: 560)
#endif
diff --git a/kit/Sources/CodyncUI/Thread/ThreadView.swift b/kit/Sources/CodyncUI/Thread/ThreadView.swift
index b838c700..65451d85 100644
--- a/kit/Sources/CodyncUI/Thread/ThreadView.swift
+++ b/kit/Sources/CodyncUI/Thread/ThreadView.swift
@@ -372,6 +372,12 @@ private struct GroupIntroCard: View {
.font(.subheadline)
.foregroundStyle(Palette.secondary)
.multilineTextAlignment(.center)
+ if !group.description.isEmpty {
+ Text(group.description)
+ .font(.subheadline)
+ .foregroundStyle(Palette.secondary)
+ .multilineTextAlignment(.center)
+ }
Text("Everyone answers in turn. @mention a bot to ask just that one. Each bot works in its own folder.")
.font(.footnote)
.foregroundStyle(Palette.tertiary)
diff --git a/kit/Sources/CodyncUI/Thread/TraceView.swift b/kit/Sources/CodyncUI/Thread/TraceView.swift
index 331c47f4..e53db253 100644
--- a/kit/Sources/CodyncUI/Thread/TraceView.swift
+++ b/kit/Sources/CodyncUI/Thread/TraceView.swift
@@ -3,14 +3,19 @@ import SwiftUI
/// "Full conversation": everything the agent did — narration, thinking, tool
/// calls with output and diffs, plans — grouped by turn.
+/// A chat's trace, or one thread's (`thread`: its root).
public struct TraceView: View {
let botId: String
+ let thread: String?
- public init(botId: String) { self.botId = botId }
+ public init(botId: String, thread: String? = nil) {
+ self.botId = botId
+ self.thread = thread
+ }
@Environment(BotStore.self) private var model
public var body: some View {
- let turns = Dictionary(grouping: model.allEntries(botId), by: \.turn)
+ let turns = Dictionary(grouping: model.allEntries(botId).filter { $0.threadId == thread }, by: \.turn)
.sorted { $0.key < $1.key }
VStack(spacing: 0) {
ModalHeader("Full conversation")