BlueGit

ict rusty-teams

feat(agents): brand write-with identity and paint call reaction emoji

When Write with picks a chat profile, composer and the chat island follow
that name and ask path; match chat language in local prompts. Call
reactions use the emoji font so hearts and faces stay colored.

metis Joachim Mild · pushed by metis

Authored 2026-11-11 · 2 weeks ago

Hash
713ab758924e03da1a5743710d2acefdcb023881
Parent
16954693
14 files changed +548 −69
crates/agents/src/settings.rs +31 −0
@@ -64,6 +64,16 @@ fn check_placeholders(item_id: &str, texts: &[&str], problems: &mut Vec<Settings
64 64 }
65 65
66 66 impl AgentSettings {
67 /// Chat profile chosen under «Write with», or `None` for Microsoft Copilot.
68 pub fn write_with_profile(&self) -> Option<&AgentProfile> {
69 if self.write_with.is_empty() {
70 return None;
71 }
72 self.agents
73 .iter()
74 .find(|agent| agent.id == self.write_with && agent.is_chat())
75 }
76
67 77 pub fn to_json(&self) -> String {
68 78 serde_json::to_string(self).unwrap_or_else(|_| "{}".to_string())
69 79 }
@@ -279,4 +289,25 @@ mod tests {
279 289 assert_eq!(loaded.write_with, "ollama");
280 290 assert!(loaded.validate().is_empty());
281 291 }
292
293 #[test]
294 fn write_with_profile_is_none_for_microsoft_and_missing_ids() {
295 let mut settings = AgentSettings::default();
296 assert!(settings.write_with_profile().is_none());
297 settings.write_with = "missing".to_owned();
298 assert!(settings.write_with_profile().is_none());
299 settings.agents.push(AgentProfile::ollama());
300 settings.agents.last_mut().unwrap().backend = AgentBackend::OpenAi {
301 base_url: "http://127.0.0.1:11434/v1".to_owned(),
302 model: "qwen3.5:9b".to_owned(),
303 api_key: String::new(),
304 };
305 settings.write_with = "ollama".to_owned();
306 assert_eq!(
307 settings.write_with_profile().map(|profile| profile.name.as_str()),
308 Some("Ollama")
309 );
310 settings.write_with = "claude".to_owned();
311 assert!(settings.write_with_profile().is_none());
312 }
282 313 }
@@ -64,6 +64,16 @@ fn check_placeholders(item_id: &str, texts: &[&str], problems: &mut Vec<Settings
64}
64}
65
65
66impl AgentSettings {
66impl AgentSettings {
67 /// Chat profile chosen under «Write with», or `None` for Microsoft Copilot.
68 pub fn write_with_profile(&self) -> Option<&AgentProfile> {
69 if self.write_with.is_empty() {
70 return None;
71 }
72 self.agents
73 .iter()
74 .find(|agent| agent.id == self.write_with && agent.is_chat())
75 }
76
67 pub fn to_json(&self) -> String {
77 pub fn to_json(&self) -> String {
68 serde_json::to_string(self).unwrap_or_else(|_| "{}".to_string())
78 serde_json::to_string(self).unwrap_or_else(|_| "{}".to_string())
69 }
79 }
@@ -279,4 +289,25 @@ mod tests {
279 assert_eq!(loaded.write_with, "ollama");
289 assert_eq!(loaded.write_with, "ollama");
280 assert!(loaded.validate().is_empty());
290 assert!(loaded.validate().is_empty());
281 }
291 }
292
293 #[test]
294 fn write_with_profile_is_none_for_microsoft_and_missing_ids() {
295 let mut settings = AgentSettings::default();
296 assert!(settings.write_with_profile().is_none());
297 settings.write_with = "missing".to_owned();
298 assert!(settings.write_with_profile().is_none());
299 settings.agents.push(AgentProfile::ollama());
300 settings.agents.last_mut().unwrap().backend = AgentBackend::OpenAi {
301 base_url: "http://127.0.0.1:11434/v1".to_owned(),
302 model: "qwen3.5:9b".to_owned(),
303 api_key: String::new(),
304 };
305 settings.write_with = "ollama".to_owned();
306 assert_eq!(
307 settings.write_with_profile().map(|profile| profile.name.as_str()),
308 Some("Ollama")
309 );
310 settings.write_with = "claude".to_owned();
311 assert!(settings.write_with_profile().is_none());
312 }
282}
313}
crates/app-state/src/agents/message_context.rs +78 −0
@@ -118,6 +118,66 @@ pub fn preview_prompt(
118 118 ))
119 119 }
120 120
121 /// Newest non-deleted messages of a chat, oldest-first, capped at [`THREAD_LIMIT`].
122 pub fn recent_thread(state: &AppState, conversation_id: &str) -> Vec<ThreadMessage> {
123 let names = local_names(state);
124 let sender_of = |entry: &MessageRecord| {
125 entry
126 .sender_name
127 .clone()
128 .filter(|name| !name.trim().is_empty())
129 .or_else(|| {
130 entry
131 .sender_id
132 .as_ref()
133 .and_then(|user_id| names.get(user_id).cloned())
134 })
135 .unwrap_or_else(|| UNKNOWN_SENDER.to_owned())
136 };
137 let mut records = state
138 .store
139 .messages(conversation_id, None, THREAD_LIMIT)
140 .unwrap_or_default();
141 records.retain(|entry| !entry.deleted);
142 let skipped = records.len().saturating_sub(THREAD_LIMIT);
143 records
144 .into_iter()
145 .skip(skipped)
146 .map(|entry| ThreadMessage {
147 sender: sender_of(&entry),
148 text: message_text(&entry),
149 time: entry
150 .created_at
151 .with_timezone(&Local)
152 .format(TIME_FORMAT)
153 .to_string(),
154 })
155 .collect()
156 }
157
158 pub fn chat_title(state: &AppState, conversation_id: &str) -> String {
159 selection_for(&state.sidebar, conversation_id)
160 .as_ref()
161 .map(|selection| selection_title(&state.sidebar, selection))
162 .unwrap_or_else(|| "Chat".to_owned())
163 }
164
165 /// Plain-text ask for a local write-with profile: chat title, recent thread, question.
166 pub fn ask_prompt(chat: &str, thread: &[ThreadMessage], question: &str) -> String {
167 let thread_block = if thread.is_empty() {
168 "(no messages yet)".to_owned()
169 } else {
170 thread
171 .iter()
172 .map(|entry| format!("{} ({}): {}", entry.sender, entry.time, entry.text))
173 .collect::<Vec<_>>()
174 .join("\n")
175 };
176 format!(
177 "Chat \"{chat}\"\n\n{thread_block}\n\nQuestion: {question}"
178 )
179 }
180
121 181 #[cfg(test)]
122 182 mod tests {
123 183 use std::sync::Arc;
@@ -240,4 +300,22 @@ mod tests {
240 300 assert!(prompt.starts_with("Ada asked me in the Teams chat \"Ops\""));
241 301 assert!(prompt.contains("session_id \"(session id)\""));
242 302 }
303
304 #[test]
305 fn recent_thread_keeps_the_newest_twenty_non_deleted() {
306 let mut records: Vec<MessageRecord> = (0..25)
307 .map(|minute| message(&format!("m{minute}"), None, minute, "Ada"))
308 .collect();
309 records[0].deleted = true;
310 let state = state_with(&records);
311 let thread = recent_thread(&state, "19:chat");
312 assert_eq!(thread.len(), 20);
313 assert_eq!(thread[0].text, "text m5");
314 assert_eq!(thread[19].text, "text m24");
315 assert_eq!(chat_title(&state, "19:chat"), "Ops");
316 let prompt = ask_prompt("Ops", &thread, "Summarize this chat");
317 assert!(prompt.contains("Chat \"Ops\""));
318 assert!(prompt.contains("text m5"));
319 assert!(prompt.contains("Question: Summarize this chat"));
320 }
243 321 }
@@ -118,6 +118,66 @@ pub fn preview_prompt(
118 ))
118 ))
119}
119}
120
120
121/// Newest non-deleted messages of a chat, oldest-first, capped at [`THREAD_LIMIT`].
122pub fn recent_thread(state: &AppState, conversation_id: &str) -> Vec<ThreadMessage> {
123 let names = local_names(state);
124 let sender_of = |entry: &MessageRecord| {
125 entry
126 .sender_name
127 .clone()
128 .filter(|name| !name.trim().is_empty())
129 .or_else(|| {
130 entry
131 .sender_id
132 .as_ref()
133 .and_then(|user_id| names.get(user_id).cloned())
134 })
135 .unwrap_or_else(|| UNKNOWN_SENDER.to_owned())
136 };
137 let mut records = state
138 .store
139 .messages(conversation_id, None, THREAD_LIMIT)
140 .unwrap_or_default();
141 records.retain(|entry| !entry.deleted);
142 let skipped = records.len().saturating_sub(THREAD_LIMIT);
143 records
144 .into_iter()
145 .skip(skipped)
146 .map(|entry| ThreadMessage {
147 sender: sender_of(&entry),
148 text: message_text(&entry),
149 time: entry
150 .created_at
151 .with_timezone(&Local)
152 .format(TIME_FORMAT)
153 .to_string(),
154 })
155 .collect()
156}
157
158pub fn chat_title(state: &AppState, conversation_id: &str) -> String {
159 selection_for(&state.sidebar, conversation_id)
160 .as_ref()
161 .map(|selection| selection_title(&state.sidebar, selection))
162 .unwrap_or_else(|| "Chat".to_owned())
163}
164
165/// Plain-text ask for a local write-with profile: chat title, recent thread, question.
166pub fn ask_prompt(chat: &str, thread: &[ThreadMessage], question: &str) -> String {
167 let thread_block = if thread.is_empty() {
168 "(no messages yet)".to_owned()
169 } else {
170 thread
171 .iter()
172 .map(|entry| format!("{} ({}): {}", entry.sender, entry.time, entry.text))
173 .collect::<Vec<_>>()
174 .join("\n")
175 };
176 format!(
177 "Chat \"{chat}\"\n\n{thread_block}\n\nQuestion: {question}"
178 )
179}
180
121#[cfg(test)]
181#[cfg(test)]
122mod tests {
182mod tests {
123 use std::sync::Arc;
183 use std::sync::Arc;
@@ -240,4 +300,22 @@ mod tests {
240 assert!(prompt.starts_with("Ada asked me in the Teams chat \"Ops\""));
300 assert!(prompt.starts_with("Ada asked me in the Teams chat \"Ops\""));
241 assert!(prompt.contains("session_id \"(session id)\""));
301 assert!(prompt.contains("session_id \"(session id)\""));
242 }
302 }
303
304 #[test]
305 fn recent_thread_keeps_the_newest_twenty_non_deleted() {
306 let mut records: Vec<MessageRecord> = (0..25)
307 .map(|minute| message(&format!("m{minute}"), None, minute, "Ada"))
308 .collect();
309 records[0].deleted = true;
310 let state = state_with(&records);
311 let thread = recent_thread(&state, "19:chat");
312 assert_eq!(thread.len(), 20);
313 assert_eq!(thread[0].text, "text m5");
314 assert_eq!(thread[19].text, "text m24");
315 assert_eq!(chat_title(&state, "19:chat"), "Ops");
316 let prompt = ask_prompt("Ops", &thread, "Summarize this chat");
317 assert!(prompt.contains("Chat \"Ops\""));
318 assert!(prompt.contains("text m5"));
319 assert!(prompt.contains("Question: Summarize this chat"));
320 }
243}
321}
crates/app-state/src/agents/mod.rs +10 −1
@@ -12,7 +12,7 @@ pub mod store;
12 12 use std::path::PathBuf;
13 13 use std::time::Duration;
14 14
15 use agents::{AgentAction, Environment};
15 use agents::{AgentAction, AgentProfile, Environment};
16 16 pub use app_base::agents::{lanes, settings_problems};
17 17 pub use app_ui_kit::{settings_controls, spinner};
18 18 use directories::ProjectDirs;
@@ -44,6 +44,15 @@ pub fn runs_handle(cx: &App) -> Option<Entity<AgentRuns>> {
44 44 .map(|handle| handle.0.clone())
45 45 }
46 46
47 /// Chat profile for «Write with», or `None` when Microsoft Copilot is selected.
48 pub fn local_writer(cx: &App) -> Option<AgentProfile> {
49 runs_handle(cx)?
50 .read(cx)
51 .settings()
52 .write_with_profile()
53 .cloned()
54 }
55
47 56 pub fn agents_enabled(cx: &App) -> bool {
48 57 runs_handle(cx).is_some_and(|runs| !runs.read(cx).settings().actions.is_empty())
49 58 }
@@ -12,7 +12,7 @@ pub mod store;
12use std::path::PathBuf;
12use std::path::PathBuf;
13use std::time::Duration;
13use std::time::Duration;
14
14
15use agents::{AgentAction, Environment};
15use agents::{AgentAction, AgentProfile, Environment};
16pub use app_base::agents::{lanes, settings_problems};
16pub use app_base::agents::{lanes, settings_problems};
17pub use app_ui_kit::{settings_controls, spinner};
17pub use app_ui_kit::{settings_controls, spinner};
18use directories::ProjectDirs;
18use directories::ProjectDirs;
@@ -44,6 +44,15 @@ pub fn runs_handle(cx: &App) -> Option<Entity<AgentRuns>> {
44 .map(|handle| handle.0.clone())
44 .map(|handle| handle.0.clone())
45}
45}
46
46
47/// Chat profile for «Write with», or `None` when Microsoft Copilot is selected.
48pub fn local_writer(cx: &App) -> Option<AgentProfile> {
49 runs_handle(cx)?
50 .read(cx)
51 .settings()
52 .write_with_profile()
53 .cloned()
54}
55
47pub fn agents_enabled(cx: &App) -> bool {
56pub fn agents_enabled(cx: &App) -> bool {
48 runs_handle(cx).is_some_and(|runs| !runs.read(cx).settings().actions.is_empty())
57 runs_handle(cx).is_some_and(|runs| !runs.read(cx).settings().actions.is_empty())
49}
58}
crates/app/src/agents/settings_section.rs +1 −1
@@ -970,7 +970,7 @@ impl AgentsSettings {
970 970 div()
971 971 .text_size(px(12.))
972 972 .text_color(theme::text_muted())
973 .child("Rewrite and proofread in the composer. Microsoft Copilot needs the licence."),
973 .child("Rewrite in the composer and the chat assistant island. Microsoft Copilot needs the licence."),
974 974 )
975 975 .child(dropdown("write-with", write_label, write_entries)),
976 976 )
@@ -970,7 +970,7 @@ impl AgentsSettings {
970 div()
970 div()
971 .text_size(px(12.))
971 .text_size(px(12.))
972 .text_color(theme::text_muted())
972 .text_color(theme::text_muted())
973 .child("Rewrite and proofread in the composer. Microsoft Copilot needs the licence."),
973 .child("Rewrite in the composer and the chat assistant island. Microsoft Copilot needs the licence."),
974 )
974 )
975 .child(dropdown("write-with", write_label, write_entries)),
975 .child(dropdown("write-with", write_label, write_entries)),
976 )
976 )
crates/app/src/views/call_view.rs +8 −1
@@ -88,8 +88,13 @@ const PUSH_TO_TALK_TOP: f32 = 12.;
88 88
89 89 pub fn reaction_glyph(reaction: &Reaction) -> String {
90 90 match reaction {
91 Reaction::Like => "\u{1F44D}".to_owned(),
92 // Keep VS16 so the heart stays emoji-style, not a text outline.
93 Reaction::Heart => "\u{2764}\u{FE0F}".to_owned(),
91 94 Reaction::Applause => "\u{1F44F}".to_owned(),
92 other => chat_reaction_glyph(other.name()),
95 Reaction::Laugh => "\u{1F606}".to_owned(),
96 Reaction::Surprised => "\u{1F62E}".to_owned(),
97 Reaction::Other(name) => chat_reaction_glyph(name),
93 98 }
94 99 }
95 100
@@ -141,6 +146,7 @@ fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {
141 146 .rounded_full()
142 147 .bg(theme::popup())
143 148 .text_size(px(if emoji { 20. } else { 13. }))
149 .when(emoji, |chip| chip.font_family(theme::EMOJI_FONT_FAMILY))
144 150 .child(glyph)
145 151 .with_animation(
146 152 ("call-reaction", serial as usize),
@@ -914,6 +920,7 @@ fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
914 920 .justify_center()
915 921 .rounded(px(8.))
916 922 .text_size(px(24.))
923 .font_family(theme::EMOJI_FONT_FAMILY)
917 924 .cursor_pointer()
918 925 .hover(|cell| cell.bg(theme::border_strong()))
919 926 .child(reaction_glyph(&reaction))
@@ -88,8 +88,13 @@ const PUSH_TO_TALK_TOP: f32 = 12.;
88
88
89pub fn reaction_glyph(reaction: &Reaction) -> String {
89pub fn reaction_glyph(reaction: &Reaction) -> String {
90 match reaction {
90 match reaction {
91 Reaction::Like => "\u{1F44D}".to_owned(),
92 // Keep VS16 so the heart stays emoji-style, not a text outline.
93 Reaction::Heart => "\u{2764}\u{FE0F}".to_owned(),
91 Reaction::Applause => "\u{1F44F}".to_owned(),
94 Reaction::Applause => "\u{1F44F}".to_owned(),
92 other => chat_reaction_glyph(other.name()),
95 Reaction::Laugh => "\u{1F606}".to_owned(),
96 Reaction::Surprised => "\u{1F62E}".to_owned(),
97 Reaction::Other(name) => chat_reaction_glyph(name),
93 }
98 }
94}
99}
95
100
@@ -141,6 +146,7 @@ fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {
141 .rounded_full()
146 .rounded_full()
142 .bg(theme::popup())
147 .bg(theme::popup())
143 .text_size(px(if emoji { 20. } else { 13. }))
148 .text_size(px(if emoji { 20. } else { 13. }))
149 .when(emoji, |chip| chip.font_family(theme::EMOJI_FONT_FAMILY))
144 .child(glyph)
150 .child(glyph)
145 .with_animation(
151 .with_animation(
146 ("call-reaction", serial as usize),
152 ("call-reaction", serial as usize),
@@ -914,6 +920,7 @@ fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
914 .justify_center()
920 .justify_center()
915 .rounded(px(8.))
921 .rounded(px(8.))
916 .text_size(px(24.))
922 .text_size(px(24.))
923 .font_family(theme::EMOJI_FONT_FAMILY)
917 .cursor_pointer()
924 .cursor_pointer()
918 .hover(|cell| cell.bg(theme::border_strong()))
925 .hover(|cell| cell.bg(theme::border_strong()))
919 .child(reaction_glyph(&reaction))
926 .child(reaction_glyph(&reaction))
crates/app/src/views/composer/rewrite.rs +48 −31
@@ -17,7 +17,7 @@ use app_ui_kit::spinner::spinner;
17 17 pub const REWRITE_BUTTON_TAG: &str = "composer/actions/copilot";
18 18 pub const REWRITE_PANEL_TAG: &str = "composer/copilot";
19 19 const BUTTON_LABEL: &str = "Write with Copilot";
20 const REWRITE_SYSTEM: &str = "You rewrite a Teams chat draft. Reply with only the new message text. Keep the meaning. Do not add a preamble.";
20 const REWRITE_SYSTEM: &str = "You rewrite a Teams chat draft. Reply with only the new message text. Keep the meaning. Do not add a preamble. Write in the same language as the draft.";
21 21 const SWITCH_HINT: &str = "Choose another model under Settings > Agents, Write with.";
22 22 const CLOSE_LABEL: &str = "Close";
23 23 const ADJUST_LABEL: &str = "Adjust";
@@ -25,12 +25,9 @@ const CUSTOM_LABEL: &str = "Customised";
25 25 const CUSTOM_PLACEHOLDER: &str = "Describe how to adjust it, e.g. make it sound friendlier";
26 26 const REPLACE_LABEL: &str = "Replace";
27 27 const DISCLAIMER: &str = "AI-generated content may be incorrect";
28 const WORKING: &str = "Copilot is writing ...";
29 const FAILED: &str = "Copilot could not rewrite this:";
30 const EMPTY_DRAFT: &str = "Type a message first, then let Copilot rewrite it.";
31 const TEXT_ONLY: &str =
32 "Copilot rewrites text only. Move images and tables out of the message first.";
28 const COPILOT_NAME: &str = "Copilot";
33 29 const BUTTON_ICON: &str = "auto_fix_high";
30 const LOCAL_BUTTON_ICON: &str = "smart_toy";
34 31 const PANEL_WIDTH: f32 = 600.;
35 32 const PANEL_PADDING: f32 = 16.;
36 33 const PANEL_RADIUS: f32 = 10.;
@@ -103,6 +100,12 @@ impl Composer {
103 100 return None;
104 101 }
105 102 let open = self.rewrite.open;
103 let writer = local_writer(cx);
104 let local = writer.is_some();
105 let tooltip = writer
106 .as_ref()
107 .map(|profile| format!("Rewrite with {}", profile.name))
108 .unwrap_or_else(|| BUTTON_LABEL.to_owned());
106 109 Some(
107 110 div()
108 111 .id("composer-copilot")
@@ -116,14 +119,13 @@ impl Composer {
116 119 .cursor_pointer()
117 120 .when(open, |button| button.bg(theme::popup_hover()))
118 121 .hover(|button| button.bg(theme::popup_hover()))
119 .popup_trigger_tooltip_text(
120 open,
121 local_writer(cx)
122 .map(|profile| format!("Rewrite with {}", profile.name))
123 .unwrap_or_else(|| BUTTON_LABEL.to_owned()),
124 )
122 .popup_trigger_tooltip_text(open, tooltip)
125 123 .child(symbol(
126 BUTTON_ICON,
124 if local {
125 LOCAL_BUTTON_ICON
126 } else {
127 BUTTON_ICON
128 },
127 129 COMPOSER_ICON_SIZE,
128 130 if open {
129 131 theme::accent_text()
@@ -163,17 +165,19 @@ impl Composer {
163 165 let Some(chat_id) = self.conversation_id.clone() else {
164 166 return;
165 167 };
168 let writer = writer_display_name(cx);
169 let failed = failed_rewrite(&writer);
166 170 let refusal = if draft.is_blank() {
167 Some(EMPTY_DRAFT)
171 Some(empty_draft_message(&writer))
168 172 } else if draft.text().contains([OBJECT_MARK, TABLE_MARK]) {
169 Some(TEXT_ONLY)
173 Some(text_only_message(&writer))
170 174 } else {
171 175 None
172 176 };
173 177 if let Some(refusal) = refusal {
174 178 self.rewrite.result = Some(RewriteResult {
175 179 action,
176 answer: RewriteAnswer::Failed(refusal.to_owned()),
180 answer: RewriteAnswer::Failed(refusal),
177 181 });
178 182 cx.notify();
179 183 return;
@@ -193,8 +197,8 @@ impl Composer {
193 197 cx.spawn(async move |this, cx| {
194 198 let answer = match receiver.await {
195 199 Ok(Ok(text)) => RewriteAnswer::Ready(Draft::from_markdown(&text)),
196 Ok(Err(error)) => RewriteAnswer::Failed(format!("{FAILED} {error}")),
197 Err(error) => RewriteAnswer::Failed(format!("{FAILED} {error}")),
200 Ok(Err(error)) => RewriteAnswer::Failed(format!("{failed} {error}")),
201 Err(error) => RewriteAnswer::Failed(format!("{failed} {error}")),
198 202 };
199 203 this.update(cx, |this, cx| {
200 204 if this.rewrite.generation == generation
@@ -224,9 +228,9 @@ impl Composer {
224 228 RewriteAnswer::Ready(Draft::from_spans(&html_to_spans(&html)).trimmed())
225 229 }
226 230 Ok(Err(error)) => {
227 RewriteAnswer::Failed(format!("{FAILED} {error} {SWITCH_HINT}"))
231 RewriteAnswer::Failed(format!("{failed} {error} {SWITCH_HINT}"))
228 232 }
229 Err(error) => RewriteAnswer::Failed(format!("{FAILED} {error} {SWITCH_HINT}")),
233 Err(error) => RewriteAnswer::Failed(format!("{failed} {error} {SWITCH_HINT}")),
230 234 },
231 235 };
232 236 this.update(cx, |this, cx| {
@@ -498,7 +502,7 @@ impl Composer {
498 502 div()
499 503 .text_size(px(14.))
500 504 .text_color(theme::text_soft())
501 .child(WORKING),
505 .child(working_message(&writer_display_name(cx))),
502 506 ),
503 507 ),
504 508 RewriteAnswer::Failed(reason) => card.child(
@@ -550,16 +554,29 @@ impl Composer {
550 554 }
551 555
552 556 fn local_writer(cx: &App) -> Option<agents::AgentProfile> {
553 let runs = crate::agents::runs_handle(cx)?;
554 let settings = runs.read(cx).settings();
555 if settings.write_with.is_empty() {
556 return None;
557 }
558 settings
559 .agents
560 .iter()
561 .find(|agent| agent.id == settings.write_with && agent.is_chat())
562 .cloned()
557 crate::agents::local_writer(cx)
558 }
559
560 fn writer_display_name(cx: &App) -> String {
561 local_writer(cx)
562 .map(|profile| profile.name)
563 .unwrap_or_else(|| COPILOT_NAME.to_owned())
564 }
565
566 fn working_message(name: &str) -> String {
567 format!("{name} is writing ...")
568 }
569
570 fn failed_rewrite(name: &str) -> String {
571 format!("{name} could not rewrite this:")
572 }
573
574 fn empty_draft_message(name: &str) -> String {
575 format!("Type a message first, then let {name} rewrite it.")
576 }
577
578 fn text_only_message(name: &str) -> String {
579 format!("{name} rewrites text only. Move images and tables out of the message first.")
563 580 }
564 581
565 582 fn rewrite_instruction(action: &ComposeAction, draft: &str) -> String {
@@ -17,7 +17,7 @@ use app_ui_kit::spinner::spinner;
17pub const REWRITE_BUTTON_TAG: &str = "composer/actions/copilot";
17pub const REWRITE_BUTTON_TAG: &str = "composer/actions/copilot";
18pub const REWRITE_PANEL_TAG: &str = "composer/copilot";
18pub const REWRITE_PANEL_TAG: &str = "composer/copilot";
19const BUTTON_LABEL: &str = "Write with Copilot";
19const BUTTON_LABEL: &str = "Write with Copilot";
20const REWRITE_SYSTEM: &str = "You rewrite a Teams chat draft. Reply with only the new message text. Keep the meaning. Do not add a preamble.";
20const REWRITE_SYSTEM: &str = "You rewrite a Teams chat draft. Reply with only the new message text. Keep the meaning. Do not add a preamble. Write in the same language as the draft.";
21const SWITCH_HINT: &str = "Choose another model under Settings > Agents, Write with.";
21const SWITCH_HINT: &str = "Choose another model under Settings > Agents, Write with.";
22const CLOSE_LABEL: &str = "Close";
22const CLOSE_LABEL: &str = "Close";
23const ADJUST_LABEL: &str = "Adjust";
23const ADJUST_LABEL: &str = "Adjust";
@@ -25,12 +25,9 @@ const CUSTOM_LABEL: &str = "Customised";
25const CUSTOM_PLACEHOLDER: &str = "Describe how to adjust it, e.g. make it sound friendlier";
25const CUSTOM_PLACEHOLDER: &str = "Describe how to adjust it, e.g. make it sound friendlier";
26const REPLACE_LABEL: &str = "Replace";
26const REPLACE_LABEL: &str = "Replace";
27const DISCLAIMER: &str = "AI-generated content may be incorrect";
27const DISCLAIMER: &str = "AI-generated content may be incorrect";
28const WORKING: &str = "Copilot is writing ...";
28const COPILOT_NAME: &str = "Copilot";
29const FAILED: &str = "Copilot could not rewrite this:";
30const EMPTY_DRAFT: &str = "Type a message first, then let Copilot rewrite it.";
31const TEXT_ONLY: &str =
32 "Copilot rewrites text only. Move images and tables out of the message first.";
33const BUTTON_ICON: &str = "auto_fix_high";
29const BUTTON_ICON: &str = "auto_fix_high";
30const LOCAL_BUTTON_ICON: &str = "smart_toy";
34const PANEL_WIDTH: f32 = 600.;
31const PANEL_WIDTH: f32 = 600.;
35const PANEL_PADDING: f32 = 16.;
32const PANEL_PADDING: f32 = 16.;
36const PANEL_RADIUS: f32 = 10.;
33const PANEL_RADIUS: f32 = 10.;
@@ -103,6 +100,12 @@ impl Composer {
103 return None;
100 return None;
104 }
101 }
105 let open = self.rewrite.open;
102 let open = self.rewrite.open;
103 let writer = local_writer(cx);
104 let local = writer.is_some();
105 let tooltip = writer
106 .as_ref()
107 .map(|profile| format!("Rewrite with {}", profile.name))
108 .unwrap_or_else(|| BUTTON_LABEL.to_owned());
106 Some(
109 Some(
107 div()
110 div()
108 .id("composer-copilot")
111 .id("composer-copilot")
@@ -116,14 +119,13 @@ impl Composer {
116 .cursor_pointer()
119 .cursor_pointer()
117 .when(open, |button| button.bg(theme::popup_hover()))
120 .when(open, |button| button.bg(theme::popup_hover()))
118 .hover(|button| button.bg(theme::popup_hover()))
121 .hover(|button| button.bg(theme::popup_hover()))
119 .popup_trigger_tooltip_text(
122 .popup_trigger_tooltip_text(open, tooltip)
120 open,
121 local_writer(cx)
122 .map(|profile| format!("Rewrite with {}", profile.name))
123 .unwrap_or_else(|| BUTTON_LABEL.to_owned()),
124 )
125 .child(symbol(
123 .child(symbol(
126 BUTTON_ICON,
124 if local {
125 LOCAL_BUTTON_ICON
126 } else {
127 BUTTON_ICON
128 },
127 COMPOSER_ICON_SIZE,
129 COMPOSER_ICON_SIZE,
128 if open {
130 if open {
129 theme::accent_text()
131 theme::accent_text()
@@ -163,17 +165,19 @@ impl Composer {
163 let Some(chat_id) = self.conversation_id.clone() else {
165 let Some(chat_id) = self.conversation_id.clone() else {
164 return;
166 return;
165 };
167 };
168 let writer = writer_display_name(cx);
169 let failed = failed_rewrite(&writer);
166 let refusal = if draft.is_blank() {
170 let refusal = if draft.is_blank() {
167 Some(EMPTY_DRAFT)
171 Some(empty_draft_message(&writer))
168 } else if draft.text().contains([OBJECT_MARK, TABLE_MARK]) {
172 } else if draft.text().contains([OBJECT_MARK, TABLE_MARK]) {
169 Some(TEXT_ONLY)
173 Some(text_only_message(&writer))
170 } else {
174 } else {
171 None
175 None
172 };
176 };
173 if let Some(refusal) = refusal {
177 if let Some(refusal) = refusal {
174 self.rewrite.result = Some(RewriteResult {
178 self.rewrite.result = Some(RewriteResult {
175 action,
179 action,
176 answer: RewriteAnswer::Failed(refusal.to_owned()),
180 answer: RewriteAnswer::Failed(refusal),
177 });
181 });
178 cx.notify();
182 cx.notify();
179 return;
183 return;
@@ -193,8 +197,8 @@ impl Composer {
193 cx.spawn(async move |this, cx| {
197 cx.spawn(async move |this, cx| {
194 let answer = match receiver.await {
198 let answer = match receiver.await {
195 Ok(Ok(text)) => RewriteAnswer::Ready(Draft::from_markdown(&text)),
199 Ok(Ok(text)) => RewriteAnswer::Ready(Draft::from_markdown(&text)),
196 Ok(Err(error)) => RewriteAnswer::Failed(format!("{FAILED} {error}")),
200 Ok(Err(error)) => RewriteAnswer::Failed(format!("{failed} {error}")),
197 Err(error) => RewriteAnswer::Failed(format!("{FAILED} {error}")),
201 Err(error) => RewriteAnswer::Failed(format!("{failed} {error}")),
198 };
202 };
199 this.update(cx, |this, cx| {
203 this.update(cx, |this, cx| {
200 if this.rewrite.generation == generation
204 if this.rewrite.generation == generation
@@ -224,9 +228,9 @@ impl Composer {
224 RewriteAnswer::Ready(Draft::from_spans(&html_to_spans(&html)).trimmed())
228 RewriteAnswer::Ready(Draft::from_spans(&html_to_spans(&html)).trimmed())
225 }
229 }
226 Ok(Err(error)) => {
230 Ok(Err(error)) => {
227 RewriteAnswer::Failed(format!("{FAILED} {error} {SWITCH_HINT}"))
231 RewriteAnswer::Failed(format!("{failed} {error} {SWITCH_HINT}"))
228 }
232 }
229 Err(error) => RewriteAnswer::Failed(format!("{FAILED} {error} {SWITCH_HINT}")),
233 Err(error) => RewriteAnswer::Failed(format!("{failed} {error} {SWITCH_HINT}")),
230 },
234 },
231 };
235 };
232 this.update(cx, |this, cx| {
236 this.update(cx, |this, cx| {
@@ -498,7 +502,7 @@ impl Composer {
498 div()
502 div()
499 .text_size(px(14.))
503 .text_size(px(14.))
500 .text_color(theme::text_soft())
504 .text_color(theme::text_soft())
501 .child(WORKING),
505 .child(working_message(&writer_display_name(cx))),
502 ),
506 ),
503 ),
507 ),
504 RewriteAnswer::Failed(reason) => card.child(
508 RewriteAnswer::Failed(reason) => card.child(
@@ -550,16 +554,29 @@ impl Composer {
550}
554}
551
555
552fn local_writer(cx: &App) -> Option<agents::AgentProfile> {
556fn local_writer(cx: &App) -> Option<agents::AgentProfile> {
553 let runs = crate::agents::runs_handle(cx)?;
557 crate::agents::local_writer(cx)
554 let settings = runs.read(cx).settings();
558}
555 if settings.write_with.is_empty() {
559
556 return None;
560fn writer_display_name(cx: &App) -> String {
557 }
561 local_writer(cx)
558 settings
562 .map(|profile| profile.name)
559 .agents
563 .unwrap_or_else(|| COPILOT_NAME.to_owned())
560 .iter()
564}
561 .find(|agent| agent.id == settings.write_with && agent.is_chat())
565
562 .cloned()
566fn working_message(name: &str) -> String {
567 format!("{name} is writing ...")
568}
569
570fn failed_rewrite(name: &str) -> String {
571 format!("{name} could not rewrite this:")
572}
573
574fn empty_draft_message(name: &str) -> String {
575 format!("Type a message first, then let {name} rewrite it.")
576}
577
578fn text_only_message(name: &str) -> String {
579 format!("{name} rewrites text only. Move images and tables out of the message first.")
563}
580}
564
581
565fn rewrite_instruction(action: &ComposeAction, draft: &str) -> String {
582fn rewrite_instruction(action: &ComposeAction, draft: &str) -> String {
crates/app/src/views/conversation/chat_header_actions.rs +3 −3
@@ -110,7 +110,7 @@ impl ConversationView {
110 110 } else {
111 111 open_details
112 112 };
113 let copilot_label = self.copilot_label();
113 let copilot_label = self.copilot_label(cx);
114 114 Some(
115 115 Button::new(CHAT_HEADER_MORE_TAG)
116 116 .icon(IconName::Ellipsis)
@@ -121,7 +121,7 @@ impl ConversationView {
121 121 .debug_selector(|| CHAT_HEADER_MORE_TAG.into())
122 122 .dropdown_menu(move |popup, window, cx| {
123 123 let popup = if overflow {
124 overflow_items(popup, view.clone(), copilot_label, details_label)
124 overflow_items(popup, view.clone(), copilot_label.clone(), details_label)
125 125 } else {
126 126 popup
127 127 };
@@ -140,7 +140,7 @@ impl ConversationView {
140 140 fn overflow_items(
141 141 popup: PopupMenu,
142 142 view: WeakEntity<ConversationView>,
143 copilot_label: &'static str,
143 copilot_label: String,
144 144 details_label: &'static str,
145 145 ) -> PopupMenu {
146 146 let (find_view, details_view) = (view.clone(), view.clone());
@@ -110,7 +110,7 @@ impl ConversationView {
110 } else {
110 } else {
111 open_details
111 open_details
112 };
112 };
113 let copilot_label = self.copilot_label();
113 let copilot_label = self.copilot_label(cx);
114 Some(
114 Some(
115 Button::new(CHAT_HEADER_MORE_TAG)
115 Button::new(CHAT_HEADER_MORE_TAG)
116 .icon(IconName::Ellipsis)
116 .icon(IconName::Ellipsis)
@@ -121,7 +121,7 @@ impl ConversationView {
121 .debug_selector(|| CHAT_HEADER_MORE_TAG.into())
121 .debug_selector(|| CHAT_HEADER_MORE_TAG.into())
122 .dropdown_menu(move |popup, window, cx| {
122 .dropdown_menu(move |popup, window, cx| {
123 let popup = if overflow {
123 let popup = if overflow {
124 overflow_items(popup, view.clone(), copilot_label, details_label)
124 overflow_items(popup, view.clone(), copilot_label.clone(), details_label)
125 } else {
125 } else {
126 popup
126 popup
127 };
127 };
@@ -140,7 +140,7 @@ impl ConversationView {
140fn overflow_items(
140fn overflow_items(
141 popup: PopupMenu,
141 popup: PopupMenu,
142 view: WeakEntity<ConversationView>,
142 view: WeakEntity<ConversationView>,
143 copilot_label: &'static str,
143 copilot_label: String,
144 details_label: &'static str,
144 details_label: &'static str,
145) -> PopupMenu {
145) -> PopupMenu {
146 let (find_view, details_view) = (view.clone(), view.clone());
146 let (find_view, details_view) = (view.clone(), view.clone());
crates/app/src/views/conversation/copilot.rs +89 −32
@@ -7,23 +7,20 @@ use gpui_kit::prelude::FluentBuilder as _;
7 7 use gpui_kit::*;
8 8
9 9 use super::ConversationView;
10 use crate::agents::message_context;
10 11 use crate::app_state::Selection;
11 12 use crate::render::{layout_card_blocks, render_blocks};
12 13 use crate::runtime;
13 14 use crate::theme;
14 15 use crate::views::scroll_edge::with_top_edge;
16 use crate::views::widgets::symbol;
15 17
16 18 pub const COPILOT_PANE_TAG: &str = "shell/islands/copilot";
17 19 const COPILOT_SCROLL_DIVIDER: &str = "shell/islands/copilot/divider-scroll";
18 const TITLE: &str = "Copilot";
19 const OPEN_LABEL: &str = "Open Copilot";
20 const CLOSE_LABEL: &str = "Close Copilot";
21 const PLACEHOLDER: &str = "Message Copilot";
22 const WORKING: &str = "Copilot is reading the chat ...";
23 const UNAVAILABLE: &str = "Copilot needs a signed-in account.";
24 const FAILED: &str = "Copilot could not answer:";
20 const COPILOT_NAME: &str = "Copilot";
25 21 const GREETING: &str = "Hi, how can I help?";
26 22 const LOGO_ASSET: &str = "symbols/copilot_color.svg";
23 const LOCAL_ICON: &str = "smart_toy";
27 24 const LOGO_BUTTON: f32 = 18.;
28 25 const LOGO_TITLE: f32 = 20.;
29 26 const INPUT_MIN_HEIGHT: f32 = 72.;
@@ -40,6 +37,7 @@ const PANE_PADDING: f32 = 16.;
40 37 const HEADER_HEIGHT: f32 = 48.;
41 38 const BUTTON_SIZE: f32 = 32.;
42 39 const BUBBLE_RADIUS: f32 = 8.;
40 const ASK_SYSTEM: &str = "You answer questions about a Teams chat. Use only the messages provided. Do not invent messages. Reply in plain text. Answer in the same language as the chat messages.";
43 41
44 42 #[derive(Default)]
45 43 pub(super) struct CopilotPane {
@@ -70,25 +68,28 @@ impl ConversationView {
70 68 }
71 69 }
72 70
73 pub(super) fn copilot_label(&self) -> &'static str {
71 pub(super) fn copilot_label(&self, cx: &App) -> String {
72 let name = writer_display_name(cx);
74 73 if self.copilot.open {
75 CLOSE_LABEL
74 format!("Close {name}")
76 75 } else {
77 OPEN_LABEL
76 format!("Open {name}")
78 77 }
79 78 }
80 79
81 80 pub(super) fn copilot_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
82 81 self.copilot_chat_id()?;
83 82 let open = self.copilot.open;
83 let local = crate::agents::local_writer(cx).is_some();
84 let label = self.copilot_label(cx);
84 85 Some(
85 86 Button::new("copilot-toggle")
86 .child(copilot_logo(LOGO_BUTTON))
87 .child(identity_mark(local, LOGO_BUTTON, theme::text_muted()))
87 88 .ghost()
88 89 .size(px(BUTTON_SIZE))
89 90 .rounded(px(8.))
90 91 .when(open, |button| button.selected(true))
91 .tooltip(if open { CLOSE_LABEL } else { OPEN_LABEL })
92 .tooltip(label)
92 93 .on_click(cx.listener(|this, _, window, cx| this.toggle_copilot(window, cx)))
93 94 .into_any_element(),
94 95 )
@@ -97,7 +98,8 @@ impl ConversationView {
97 98 pub(super) fn toggle_copilot(&mut self, window: &mut Window, cx: &mut Context<Self>) {
98 99 self.copilot.open = !self.copilot.open;
99 100 if self.copilot.open && self.copilot.input.is_none() {
100 let input = cx.new(|cx| InputState::new(window, cx).placeholder(PLACEHOLDER));
101 let placeholder = format!("Message {}", writer_display_name(cx));
102 let input = cx.new(|cx| InputState::new(window, cx).placeholder(placeholder));
101 103 let subscription = cx.subscribe_in(
102 104 &input,
103 105 window,
@@ -152,16 +154,51 @@ impl ConversationView {
152 154 });
153 155 self.copilot.scroll.scroll_to_bottom();
154 156 cx.notify();
157 let failed = failed_answer(&writer_display_name(cx));
158 if let Some(profile) = crate::agents::local_writer(cx) {
159 let state = self.app.read(cx);
160 let chat = message_context::chat_title(state, &chat_id);
161 let thread = message_context::recent_thread(state, &chat_id);
162 let user = message_context::ask_prompt(&chat, &thread, &prompt);
163 let receiver = runtime::spawn(async move {
164 agents::complete_text(&profile, ASK_SYSTEM, &user).await
165 });
166 cx.spawn(async move |this, cx| {
167 let answer = match receiver.await {
168 Ok(Ok(text)) => Ok(text),
169 Ok(Err(error)) => Err(error),
170 Err(error) => Err(error.to_string()),
171 };
172 this.update(cx, |this, cx| {
173 this.settle_copilot(generation, index, answer.map_err(|error| format!("{failed} {error}")), cx)
174 })
175 .ok();
176 })
177 .detach();
178 return;
179 }
155 180 let Some(engine) = self.app.read(cx).engine.clone() else {
156 self.settle_copilot(generation, index, Err(UNAVAILABLE.to_owned()), cx);
181 self.settle_copilot(
182 generation,
183 index,
184 Err(unavailable_message(&writer_display_name(cx))),
185 cx,
186 );
157 187 return;
158 188 };
159 189 let receiver = runtime::spawn(async move { engine.ask_copilot(&chat_id, &prompt).await });
160 190 cx.spawn(async move |this, cx| {
161 191 let answer = match receiver.await {
162 192 Ok(Ok(text)) => Ok(text),
163 Ok(Err(error)) => Err(error.to_string()),
164 Err(error) => Err(error.to_string()),
193 Ok(Err(error)) => Err(format!(
194 "{failed} {}",
195 error
196 .to_string()
197 .split(" (https://")
198 .next()
199 .unwrap_or_default()
200 )),
201 Err(error) => Err(format!("{failed} {error}")),
165 202 };
166 203 this.update(cx, |this, cx| {
167 204 this.settle_copilot(generation, index, answer, cx)
@@ -186,10 +223,7 @@ impl ConversationView {
186 223 };
187 224 turn.answer = match answer {
188 225 Ok(text) => CopilotAnswer::Ready(text),
189 Err(error) => CopilotAnswer::Failed(format!(
190 "{FAILED} {}",
191 error.split(" (https://").next().unwrap_or_default()
192 )),
226 Err(error) => CopilotAnswer::Failed(error),
193 227 };
194 228 self.copilot.scroll.scroll_to_bottom();
195 229 cx.notify();
@@ -200,6 +234,8 @@ impl ConversationView {
200 234 return None;
201 235 }
202 236 self.copilot_chat_id()?;
237 let local = crate::agents::local_writer(cx).is_some();
238 let name = writer_display_name(cx);
203 239 let busy = self
204 240 .copilot
205 241 .turns
@@ -215,6 +251,7 @@ impl ConversationView {
215 251 .bg(theme::surface_raised())
216 252 .child(Input::new(input).appearance(false).bordered(false))
217 253 });
254 let working = working_message(&name);
218 255 let content = if self.copilot.turns.is_empty() {
219 256 let suggestions =
220 257 v_flex()
@@ -262,11 +299,9 @@ impl ConversationView {
262 299 .pb(px(PANE_PADDING))
263 300 .gap(px(12.));
264 301 for (index, turn) in self.copilot.turns.iter().enumerate() {
265 body = body.child(prompt_bubble(&turn.prompt)).child(answer_view(
266 index,
267 &turn.answer,
268 cx,
269 ));
302 body = body
303 .child(prompt_bubble(&turn.prompt))
304 .child(answer_view(index, &turn.answer, &working, cx));
270 305 }
271 306 v_flex()
272 307 .flex_1()
@@ -315,13 +350,13 @@ impl ConversationView {
315 350 h_flex()
316 351 .gap(px(8.))
317 352 .items_center()
318 .child(copilot_logo(LOGO_TITLE))
353 .child(identity_mark(local, LOGO_TITLE, theme::text()))
319 354 .child(
320 355 div()
321 356 .text_size(px(15.))
322 357 .font_weight(FontWeight::SEMIBOLD)
323 358 .text_color(theme::text())
324 .child(TITLE),
359 .child(name),
325 360 ),
326 361 )
327 362 .child(
@@ -330,7 +365,7 @@ impl ConversationView {
330 365 .ghost()
331 366 .size(px(BUTTON_SIZE))
332 367 .rounded(px(8.))
333 .tooltip(CLOSE_LABEL)
368 .tooltip(format!("Close {}", writer_display_name(cx)))
334 369 .on_click(cx.listener(|this, _, _, cx| {
335 370 this.copilot.open = false;
336 371 cx.notify();
@@ -344,8 +379,30 @@ impl ConversationView {
344 379 }
345 380 }
346 381
347 fn copilot_logo(size: f32) -> Img {
348 img(LOGO_ASSET).size(px(size)).flex_none()
382 fn writer_display_name(cx: &App) -> String {
383 crate::agents::local_writer(cx)
384 .map(|profile| profile.name)
385 .unwrap_or_else(|| COPILOT_NAME.to_owned())
386 }
387
388 fn working_message(name: &str) -> String {
389 format!("{name} is reading the chat ...")
390 }
391
392 fn failed_answer(name: &str) -> String {
393 format!("{name} could not answer:")
394 }
395
396 fn unavailable_message(name: &str) -> String {
397 format!("{name} needs a signed-in account.")
398 }
399
400 fn identity_mark(local: bool, size: f32, color: Hsla) -> AnyElement {
401 if local {
402 symbol(LOCAL_ICON, size, color).into_any_element()
403 } else {
404 img(LOGO_ASSET).size(px(size)).flex_none().into_any_element()
405 }
349 406 }
350 407
351 408 fn prompt_bubble(prompt: &str) -> Div {
@@ -362,12 +419,12 @@ fn prompt_bubble(prompt: &str) -> Div {
362 419 )
363 420 }
364 421
365 fn answer_view(index: usize, answer: &CopilotAnswer, cx: &App) -> AnyElement {
422 fn answer_view(index: usize, answer: &CopilotAnswer, working: &str, cx: &App) -> AnyElement {
366 423 match answer {
367 424 CopilotAnswer::Waiting => div()
368 425 .text_size(px(13.))
369 426 .text_color(theme::text_muted())
370 .child(WORKING)
427 .child(working.to_owned())
371 428 .into_any_element(),
372 429 CopilotAnswer::Failed(error) => div()
373 430 .text_size(px(13.))
@@ -7,23 +7,20 @@ use gpui_kit::prelude::FluentBuilder as _;
7use gpui_kit::*;
7use gpui_kit::*;
8
8
9use super::ConversationView;
9use super::ConversationView;
10use crate::agents::message_context;
10use crate::app_state::Selection;
11use crate::app_state::Selection;
11use crate::render::{layout_card_blocks, render_blocks};
12use crate::render::{layout_card_blocks, render_blocks};
12use crate::runtime;
13use crate::runtime;
13use crate::theme;
14use crate::theme;
14use crate::views::scroll_edge::with_top_edge;
15use crate::views::scroll_edge::with_top_edge;
16use crate::views::widgets::symbol;
15
17
16pub const COPILOT_PANE_TAG: &str = "shell/islands/copilot";
18pub const COPILOT_PANE_TAG: &str = "shell/islands/copilot";
17const COPILOT_SCROLL_DIVIDER: &str = "shell/islands/copilot/divider-scroll";
19const COPILOT_SCROLL_DIVIDER: &str = "shell/islands/copilot/divider-scroll";
18const TITLE: &str = "Copilot";
20const COPILOT_NAME: &str = "Copilot";
19const OPEN_LABEL: &str = "Open Copilot";
20const CLOSE_LABEL: &str = "Close Copilot";
21const PLACEHOLDER: &str = "Message Copilot";
22const WORKING: &str = "Copilot is reading the chat ...";
23const UNAVAILABLE: &str = "Copilot needs a signed-in account.";
24const FAILED: &str = "Copilot could not answer:";
25const GREETING: &str = "Hi, how can I help?";
21const GREETING: &str = "Hi, how can I help?";
26const LOGO_ASSET: &str = "symbols/copilot_color.svg";
22const LOGO_ASSET: &str = "symbols/copilot_color.svg";
23const LOCAL_ICON: &str = "smart_toy";
27const LOGO_BUTTON: f32 = 18.;
24const LOGO_BUTTON: f32 = 18.;
28const LOGO_TITLE: f32 = 20.;
25const LOGO_TITLE: f32 = 20.;
29const INPUT_MIN_HEIGHT: f32 = 72.;
26const INPUT_MIN_HEIGHT: f32 = 72.;
@@ -40,6 +37,7 @@ const PANE_PADDING: f32 = 16.;
40const HEADER_HEIGHT: f32 = 48.;
37const HEADER_HEIGHT: f32 = 48.;
41const BUTTON_SIZE: f32 = 32.;
38const BUTTON_SIZE: f32 = 32.;
42const BUBBLE_RADIUS: f32 = 8.;
39const BUBBLE_RADIUS: f32 = 8.;
40const ASK_SYSTEM: &str = "You answer questions about a Teams chat. Use only the messages provided. Do not invent messages. Reply in plain text. Answer in the same language as the chat messages.";
43
41
44#[derive(Default)]
42#[derive(Default)]
45pub(super) struct CopilotPane {
43pub(super) struct CopilotPane {
@@ -70,25 +68,28 @@ impl ConversationView {
70 }
68 }
71 }
69 }
72
70
73 pub(super) fn copilot_label(&self) -> &'static str {
71 pub(super) fn copilot_label(&self, cx: &App) -> String {
72 let name = writer_display_name(cx);
74 if self.copilot.open {
73 if self.copilot.open {
75 CLOSE_LABEL
74 format!("Close {name}")
76 } else {
75 } else {
77 OPEN_LABEL
76 format!("Open {name}")
78 }
77 }
79 }
78 }
80
79
81 pub(super) fn copilot_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
80 pub(super) fn copilot_button(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
82 self.copilot_chat_id()?;
81 self.copilot_chat_id()?;
83 let open = self.copilot.open;
82 let open = self.copilot.open;
83 let local = crate::agents::local_writer(cx).is_some();
84 let label = self.copilot_label(cx);
84 Some(
85 Some(
85 Button::new("copilot-toggle")
86 Button::new("copilot-toggle")
86 .child(copilot_logo(LOGO_BUTTON))
87 .child(identity_mark(local, LOGO_BUTTON, theme::text_muted()))
87 .ghost()
88 .ghost()
88 .size(px(BUTTON_SIZE))
89 .size(px(BUTTON_SIZE))
89 .rounded(px(8.))
90 .rounded(px(8.))
90 .when(open, |button| button.selected(true))
91 .when(open, |button| button.selected(true))
91 .tooltip(if open { CLOSE_LABEL } else { OPEN_LABEL })
92 .tooltip(label)
92 .on_click(cx.listener(|this, _, window, cx| this.toggle_copilot(window, cx)))
93 .on_click(cx.listener(|this, _, window, cx| this.toggle_copilot(window, cx)))
93 .into_any_element(),
94 .into_any_element(),
94 )
95 )
@@ -97,7 +98,8 @@ impl ConversationView {
97 pub(super) fn toggle_copilot(&mut self, window: &mut Window, cx: &mut Context<Self>) {
98 pub(super) fn toggle_copilot(&mut self, window: &mut Window, cx: &mut Context<Self>) {
98 self.copilot.open = !self.copilot.open;
99 self.copilot.open = !self.copilot.open;
99 if self.copilot.open && self.copilot.input.is_none() {
100 if self.copilot.open && self.copilot.input.is_none() {
100 let input = cx.new(|cx| InputState::new(window, cx).placeholder(PLACEHOLDER));
101 let placeholder = format!("Message {}", writer_display_name(cx));
102 let input = cx.new(|cx| InputState::new(window, cx).placeholder(placeholder));
101 let subscription = cx.subscribe_in(
103 let subscription = cx.subscribe_in(
102 &input,
104 &input,
103 window,
105 window,
@@ -152,16 +154,51 @@ impl ConversationView {
152 });
154 });
153 self.copilot.scroll.scroll_to_bottom();
155 self.copilot.scroll.scroll_to_bottom();
154 cx.notify();
156 cx.notify();
157 let failed = failed_answer(&writer_display_name(cx));
158 if let Some(profile) = crate::agents::local_writer(cx) {
159 let state = self.app.read(cx);
160 let chat = message_context::chat_title(state, &chat_id);
161 let thread = message_context::recent_thread(state, &chat_id);
162 let user = message_context::ask_prompt(&chat, &thread, &prompt);
163 let receiver = runtime::spawn(async move {
164 agents::complete_text(&profile, ASK_SYSTEM, &user).await
165 });
166 cx.spawn(async move |this, cx| {
167 let answer = match receiver.await {
168 Ok(Ok(text)) => Ok(text),
169 Ok(Err(error)) => Err(error),
170 Err(error) => Err(error.to_string()),
171 };
172 this.update(cx, |this, cx| {
173 this.settle_copilot(generation, index, answer.map_err(|error| format!("{failed} {error}")), cx)
174 })
175 .ok();
176 })
177 .detach();
178 return;
179 }
155 let Some(engine) = self.app.read(cx).engine.clone() else {
180 let Some(engine) = self.app.read(cx).engine.clone() else {
156 self.settle_copilot(generation, index, Err(UNAVAILABLE.to_owned()), cx);
181 self.settle_copilot(
182 generation,
183 index,
184 Err(unavailable_message(&writer_display_name(cx))),
185 cx,
186 );
157 return;
187 return;
158 };
188 };
159 let receiver = runtime::spawn(async move { engine.ask_copilot(&chat_id, &prompt).await });
189 let receiver = runtime::spawn(async move { engine.ask_copilot(&chat_id, &prompt).await });
160 cx.spawn(async move |this, cx| {
190 cx.spawn(async move |this, cx| {
161 let answer = match receiver.await {
191 let answer = match receiver.await {
162 Ok(Ok(text)) => Ok(text),
192 Ok(Ok(text)) => Ok(text),
163 Ok(Err(error)) => Err(error.to_string()),
193 Ok(Err(error)) => Err(format!(
164 Err(error) => Err(error.to_string()),
194 "{failed} {}",
195 error
196 .to_string()
197 .split(" (https://")
198 .next()
199 .unwrap_or_default()
200 )),
201 Err(error) => Err(format!("{failed} {error}")),
165 };
202 };
166 this.update(cx, |this, cx| {
203 this.update(cx, |this, cx| {
167 this.settle_copilot(generation, index, answer, cx)
204 this.settle_copilot(generation, index, answer, cx)
@@ -186,10 +223,7 @@ impl ConversationView {
186 };
223 };
187 turn.answer = match answer {
224 turn.answer = match answer {
188 Ok(text) => CopilotAnswer::Ready(text),
225 Ok(text) => CopilotAnswer::Ready(text),
189 Err(error) => CopilotAnswer::Failed(format!(
226 Err(error) => CopilotAnswer::Failed(error),
190 "{FAILED} {}",
191 error.split(" (https://").next().unwrap_or_default()
192 )),
193 };
227 };
194 self.copilot.scroll.scroll_to_bottom();
228 self.copilot.scroll.scroll_to_bottom();
195 cx.notify();
229 cx.notify();
@@ -200,6 +234,8 @@ impl ConversationView {
200 return None;
234 return None;
201 }
235 }
202 self.copilot_chat_id()?;
236 self.copilot_chat_id()?;
237 let local = crate::agents::local_writer(cx).is_some();
238 let name = writer_display_name(cx);
203 let busy = self
239 let busy = self
204 .copilot
240 .copilot
205 .turns
241 .turns
@@ -215,6 +251,7 @@ impl ConversationView {
215 .bg(theme::surface_raised())
251 .bg(theme::surface_raised())
216 .child(Input::new(input).appearance(false).bordered(false))
252 .child(Input::new(input).appearance(false).bordered(false))
217 });
253 });
254 let working = working_message(&name);
218 let content = if self.copilot.turns.is_empty() {
255 let content = if self.copilot.turns.is_empty() {
219 let suggestions =
256 let suggestions =
220 v_flex()
257 v_flex()
@@ -262,11 +299,9 @@ impl ConversationView {
262 .pb(px(PANE_PADDING))
299 .pb(px(PANE_PADDING))
263 .gap(px(12.));
300 .gap(px(12.));
264 for (index, turn) in self.copilot.turns.iter().enumerate() {
301 for (index, turn) in self.copilot.turns.iter().enumerate() {
265 body = body.child(prompt_bubble(&turn.prompt)).child(answer_view(
302 body = body
266 index,
303 .child(prompt_bubble(&turn.prompt))
267 &turn.answer,
304 .child(answer_view(index, &turn.answer, &working, cx));
268 cx,
269 ));
270 }
305 }
271 v_flex()
306 v_flex()
272 .flex_1()
307 .flex_1()
@@ -315,13 +350,13 @@ impl ConversationView {
315 h_flex()
350 h_flex()
316 .gap(px(8.))
351 .gap(px(8.))
317 .items_center()
352 .items_center()
318 .child(copilot_logo(LOGO_TITLE))
353 .child(identity_mark(local, LOGO_TITLE, theme::text()))
319 .child(
354 .child(
320 div()
355 div()
321 .text_size(px(15.))
356 .text_size(px(15.))
322 .font_weight(FontWeight::SEMIBOLD)
357 .font_weight(FontWeight::SEMIBOLD)
323 .text_color(theme::text())
358 .text_color(theme::text())
324 .child(TITLE),
359 .child(name),
325 ),
360 ),
326 )
361 )
327 .child(
362 .child(
@@ -330,7 +365,7 @@ impl ConversationView {
330 .ghost()
365 .ghost()
331 .size(px(BUTTON_SIZE))
366 .size(px(BUTTON_SIZE))
332 .rounded(px(8.))
367 .rounded(px(8.))
333 .tooltip(CLOSE_LABEL)
368 .tooltip(format!("Close {}", writer_display_name(cx)))
334 .on_click(cx.listener(|this, _, _, cx| {
369 .on_click(cx.listener(|this, _, _, cx| {
335 this.copilot.open = false;
370 this.copilot.open = false;
336 cx.notify();
371 cx.notify();
@@ -344,8 +379,30 @@ impl ConversationView {
344 }
379 }
345}
380}
346
381
347fn copilot_logo(size: f32) -> Img {
382fn writer_display_name(cx: &App) -> String {
348 img(LOGO_ASSET).size(px(size)).flex_none()
383 crate::agents::local_writer(cx)
384 .map(|profile| profile.name)
385 .unwrap_or_else(|| COPILOT_NAME.to_owned())
386}
387
388fn working_message(name: &str) -> String {
389 format!("{name} is reading the chat ...")
390}
391
392fn failed_answer(name: &str) -> String {
393 format!("{name} could not answer:")
394}
395
396fn unavailable_message(name: &str) -> String {
397 format!("{name} needs a signed-in account.")
398}
399
400fn identity_mark(local: bool, size: f32, color: Hsla) -> AnyElement {
401 if local {
402 symbol(LOCAL_ICON, size, color).into_any_element()
403 } else {
404 img(LOGO_ASSET).size(px(size)).flex_none().into_any_element()
405 }
349}
406}
350
407
351fn prompt_bubble(prompt: &str) -> Div {
408fn prompt_bubble(prompt: &str) -> Div {
@@ -362,12 +419,12 @@ fn prompt_bubble(prompt: &str) -> Div {
362 )
419 )
363}
420}
364
421
365fn answer_view(index: usize, answer: &CopilotAnswer, cx: &App) -> AnyElement {
422fn answer_view(index: usize, answer: &CopilotAnswer, working: &str, cx: &App) -> AnyElement {
366 match answer {
423 match answer {
367 CopilotAnswer::Waiting => div()
424 CopilotAnswer::Waiting => div()
368 .text_size(px(13.))
425 .text_size(px(13.))
369 .text_color(theme::text_muted())
426 .text_color(theme::text_muted())
370 .child(WORKING)
427 .child(working.to_owned())
371 .into_any_element(),
428 .into_any_element(),
372 CopilotAnswer::Failed(error) => div()
429 CopilotAnswer::Failed(error) => div()
373 .text_size(px(13.))
430 .text_size(px(13.))
openspec/changes/archive/2026-11-11-write-with-identity/.openspec.yaml added +2 −0
@@ -0,0 +1,2 @@
1 schema: spec-driven
2 created: 2026-11-11
@@ -0,0 +1,2 @@
1schema: spec-driven
2created: 2026-11-11
openspec/changes/archive/2026-11-11-write-with-identity/design.md added +91 −0
@@ -0,0 +1,91 @@
1 # Design
2
3 ## Context
4
5 Siehe `proposal.md` — Why. Heute:
6
7 - `AgentSettings.write_with` (leer = Microsoft) steuert Composer-Rewrite in `crates/app/src/views/composer/rewrite.rs` über `local_writer` → `agents::complete_text`.
8 - Tooltips nutzen bereits den Profilnamen; Status-/Fehlerstrings und Icons bleiben «Copilot» / `auto_fix_high`.
9 - Die Chat-Insel in `crates/app/src/views/conversation/copilot.rs` brandet fest mit `symbols/copilot_color.svg` und ruft nur `engine.ask_copilot` (Teams Sydney).
10 - Agent-Threads mit Limit 20 leben in `crates/app-state/src/agents/message_context.rs` — aber an einer festen `message_id`. Die Insel braucht denselben Limit-Gedanken für den ganzen offenen Chat.
11
12 ## Goals / Non-Goals
13
14 **Goals:**
15
16 - Eine gemeinsame «aktive Writer»-Auflösung (Profil oder Microsoft) für Branding und Ask/Rewrite.
17 - Insel-Ask lokal mit Thread-Text (max. 20 Nachrichten), ohne Tools.
18 - Kein Copilot-Logo/Copy, wenn der Writer lokal ist.
19
20 **Non-Goals:**
21
22 - Kein MCP/Tool-Loop in der Insel.
23 - Keine Provider-spezifischen Marken-Assets (Ollama-/OpenAI-Logos); ein generisches Bot-Symbol reicht.
24 - Kein Umschreiben der Roboter-Agenten-Delegation (Hover-Toolbar).
25 - Kein Entfernen des Microsoft-Pfads.
26
27 ## Decisions
28
29 ### 1. Gemeinsamer Writer-Resolver
30
31 Eine kleine Hilfsfunktion (App-seitig, z. B. neben Agents-Runs-Handle) liefert:
32
33 - `None` / Microsoft → leeres `write_with`
34 - `Some(profile)` → gültiges Chat-Profil
35
36 Composer und Insel lesen dieselbe Quelle. Anzeigename = `profile.name`.
37
38 **Alternative:** Modellstring aus `AgentBackend` — verworfen, weil das Dropdown und die Spec den Profilnamen festlegen.
39
40 ### 2. Branding
41
42 | Oberfläche | Microsoft | Lokal |
43 |---|---|---|
44 | Insel-Logo / Header | `copilot_color.svg` | Symbol `smart_toy` / Bot (bestehendes Asset) |
45 | Labels / Status | «Copilot …» | «{profile.name} …» |
46 | Composer-Button | `auto_fix_high` ok oder gleiches Bot-Symbol | gleiches Non-Copilot-Symbol + Tooltip «Rewrite with {name}» |
47
48 Overflow-Menü (`chat_header_actions.rs`) nutzt denselben dynamischen Label-String statt `'static` Copilot-Text.
49
50 ### 3. Insel-Ask-Pfad
51
52 ```
53 ask
54 |
55 +-- local_writer Some(profile)
56 | build thread text (newest 20 non-deleted)
57 | complete_text(system, thread + question)
58 |
59 +-- else
60 engine.ask_copilot (wie heute; ohne Engine → UNAVAILABLE)
61 ```
62
63 Systemprompt: Fragen zum aktuellen Teams-Chat beantworten; nur den gelieferten Thread nutzen; keine erfundenen Nachrichten.
64
65 Thread-Bau: `store.messages(chat_id, None, 20)` (bzw. äquivalent), Senderauflösung analog `message_context` (`local_names` / `sender_name`). Keine Abhängigkeit von einer angeklickten `message_id`.
66
67 **Alternative:** Insel an Agent-Run + MCP anbinden — verworfen (Explorations-Entscheidung: Option 1).
68
69 ### 4. Verfügbarkeit ohne Engine
70
71 - Rewrite: `rewrite_available` schon `local_writer.is_some() || engine` — belassen/härten.
72 - Insel-Button/Ask: bei lokalem Writer Engine nicht voraussetzen; `ask_copilot`-Zweig nur auf Microsoft-Pfad.
73
74 ### 5. Settings-Hinweis
75
76 Kurztext unter «Write with» erwähnen, dass Rewrite **und** die Chat-Insel dem Eintrag folgen.
77
78 ## Risks / Trade-offs
79
80 - [Dünner Kontext] 20 Nachrichten reichen für lange Chats nicht → Mitigation: gleiches Limit wie Agent-Thread; später erweiterbar, Spec bleibt «at most twenty».
81 - [Kanal vs Chat] Insel heute nur bei `Selection::Chat` → bleibt so; Kanäle out of scope.
82 - [Mehrere Insel-Turns] Folgefragen bekommen weiterhin den aktuellen Chat-Thread, nicht zwingend den Insel-Dialogverlauf → akzeptiert für v1; Dialog-Turns nur in der UI.
83 - [Falsches Profil gelöscht] `write_with` zeigt auf fehlende ID → wie heute Fallback Richtung Microsoft-Label in Settings; Ask sollte klar fehlschlagen oder Writer als fehlend behandeln — Implementierung: fehlendes Profil = kein local_writer (wie `local_writer` heute).
84
85 ## Migration Plan
86
87 Kein Datenmigrationsschritt: `write_with` existiert. Reines UI-/Ask-Verhalten. Rollback = vorheriges Binary.
88
89 ## Open Questions
90
91 Keine spez-relevanten. Icon-Wahl (`smart_toy` vs `bot`) ist Implementierungsdetail.
@@ -0,0 +1,91 @@
1# Design
2
3## Context
4
5Siehe `proposal.md` — Why. Heute:
6
7- `AgentSettings.write_with` (leer = Microsoft) steuert Composer-Rewrite in `crates/app/src/views/composer/rewrite.rs` über `local_writer` → `agents::complete_text`.
8- Tooltips nutzen bereits den Profilnamen; Status-/Fehlerstrings und Icons bleiben «Copilot» / `auto_fix_high`.
9- Die Chat-Insel in `crates/app/src/views/conversation/copilot.rs` brandet fest mit `symbols/copilot_color.svg` und ruft nur `engine.ask_copilot` (Teams Sydney).
10- Agent-Threads mit Limit 20 leben in `crates/app-state/src/agents/message_context.rs` — aber an einer festen `message_id`. Die Insel braucht denselben Limit-Gedanken für den ganzen offenen Chat.
11
12## Goals / Non-Goals
13
14**Goals:**
15
16- Eine gemeinsame «aktive Writer»-Auflösung (Profil oder Microsoft) für Branding und Ask/Rewrite.
17- Insel-Ask lokal mit Thread-Text (max. 20 Nachrichten), ohne Tools.
18- Kein Copilot-Logo/Copy, wenn der Writer lokal ist.
19
20**Non-Goals:**
21
22- Kein MCP/Tool-Loop in der Insel.
23- Keine Provider-spezifischen Marken-Assets (Ollama-/OpenAI-Logos); ein generisches Bot-Symbol reicht.
24- Kein Umschreiben der Roboter-Agenten-Delegation (Hover-Toolbar).
25- Kein Entfernen des Microsoft-Pfads.
26
27## Decisions
28
29### 1. Gemeinsamer Writer-Resolver
30
31Eine kleine Hilfsfunktion (App-seitig, z. B. neben Agents-Runs-Handle) liefert:
32
33- `None` / Microsoft → leeres `write_with`
34- `Some(profile)` → gültiges Chat-Profil
35
36Composer und Insel lesen dieselbe Quelle. Anzeigename = `profile.name`.
37
38**Alternative:** Modellstring aus `AgentBackend` — verworfen, weil das Dropdown und die Spec den Profilnamen festlegen.
39
40### 2. Branding
41
42| Oberfläche | Microsoft | Lokal |
43|---|---|---|
44| Insel-Logo / Header | `copilot_color.svg` | Symbol `smart_toy` / Bot (bestehendes Asset) |
45| Labels / Status | «Copilot …» | «{profile.name} …» |
46| Composer-Button | `auto_fix_high` ok oder gleiches Bot-Symbol | gleiches Non-Copilot-Symbol + Tooltip «Rewrite with {name}» |
47
48Overflow-Menü (`chat_header_actions.rs`) nutzt denselben dynamischen Label-String statt `'static` Copilot-Text.
49
50### 3. Insel-Ask-Pfad
51
52```
53ask
54 |
55 +-- local_writer Some(profile)
56 | build thread text (newest 20 non-deleted)
57 | complete_text(system, thread + question)
58 |
59 +-- else
60 engine.ask_copilot (wie heute; ohne Engine → UNAVAILABLE)
61```
62
63Systemprompt: Fragen zum aktuellen Teams-Chat beantworten; nur den gelieferten Thread nutzen; keine erfundenen Nachrichten.
64
65Thread-Bau: `store.messages(chat_id, None, 20)` (bzw. äquivalent), Senderauflösung analog `message_context` (`local_names` / `sender_name`). Keine Abhängigkeit von einer angeklickten `message_id`.
66
67**Alternative:** Insel an Agent-Run + MCP anbinden — verworfen (Explorations-Entscheidung: Option 1).
68
69### 4. Verfügbarkeit ohne Engine
70
71- Rewrite: `rewrite_available` schon `local_writer.is_some() || engine` — belassen/härten.
72- Insel-Button/Ask: bei lokalem Writer Engine nicht voraussetzen; `ask_copilot`-Zweig nur auf Microsoft-Pfad.
73
74### 5. Settings-Hinweis
75
76Kurztext unter «Write with» erwähnen, dass Rewrite **und** die Chat-Insel dem Eintrag folgen.
77
78## Risks / Trade-offs
79
80- [Dünner Kontext] 20 Nachrichten reichen für lange Chats nicht → Mitigation: gleiches Limit wie Agent-Thread; später erweiterbar, Spec bleibt «at most twenty».
81- [Kanal vs Chat] Insel heute nur bei `Selection::Chat` → bleibt so; Kanäle out of scope.
82- [Mehrere Insel-Turns] Folgefragen bekommen weiterhin den aktuellen Chat-Thread, nicht zwingend den Insel-Dialogverlauf → akzeptiert für v1; Dialog-Turns nur in der UI.
83- [Falsches Profil gelöscht] `write_with` zeigt auf fehlende ID → wie heute Fallback Richtung Microsoft-Label in Settings; Ask sollte klar fehlschlagen oder Writer als fehlend behandeln — Implementierung: fehlendes Profil = kein local_writer (wie `local_writer` heute).
84
85## Migration Plan
86
87Kein Datenmigrationsschritt: `write_with` existiert. Reines UI-/Ask-Verhalten. Rollback = vorheriges Binary.
88
89## Open Questions
90
91Keine spez-relevanten. Icon-Wahl (`smart_toy` vs `bot`) ist Implementierungsdetail.
openspec/changes/archive/2026-11-11-write-with-identity/proposal.md added +33 −0
@@ -0,0 +1,33 @@
1 # Proposal
2
3 ## Why
4
5 «Write with» kann Microsoft Copilot schon durch ein Chat-Profil ersetzen, aber Composer und Chat-Insel bleiben optisch und textlich «Copilot». Wer kein MS-Abo nutzt, sieht weiter Copilot-Branding und die Insel spricht weiterhin nur die Teams-API.
6
7 ## What Changes
8
9 - Wenn «Write with» ein Chat-Profil ist, zeigen Composer-Rewrite und die Chat-Header-Insel die Identität dieses Profils (Name + Non-Copilot-Icon), nicht «Copilot».
10 - Die Chat-Insel beantwortet Fragen dann über dasselbe Chat-Profil; Kontext sind die letzten ~20 Nachrichten des offenen Chats als Text (kein MCP/Tools).
11 - Composer-Status- und Fehlertexte folgen derselben Identität.
12 - Mit lokalem Writer bleiben Rewrite und Insel auch ohne Teams-Engine / ohne Copilot-Lizenz erreichbar.
13 - Leer belassenes «Write with» behält den Microsoft-Pfad inkl. Copilot-Branding (wie heute).
14
15 Annahme (Explorations-Feinheit): sichtbarer Anzeigename ist der **Profilname** aus den Agents-Einstellungen, nicht der Backend-Modellstring.
16
17 ## Capabilities
18
19 ### New Capabilities
20
21 - (keine)
22
23 ### Modified Capabilities
24
25 - `agent-providers`: «Write with» steuert nicht nur den Rewrite-Backend-Pfad, sondern die gemeinsame Assistenten-Identität und den Ask-Pfad der Chat-Insel.
26
27 ## Impact
28
29 - UI: `crates/app/src/views/composer/rewrite.rs`, `crates/app/src/views/conversation/copilot.rs`, Overflow-Menü in `chat_header_actions.rs`
30 - Settings-Texte optional: `settings_section.rs` (Hinweis, dass Insel mitwechselt)
31 - Kontextaufbau: Wiederverwendung/Erweiterung um Chat-Thread ohne feste `message_id` (Vorbild `message_context`, Limit 20)
32 - Lauf: `agents::complete_text` für Insel-Ask; Microsoft `ask_copilot` nur bei leerem `write_with`
33 - Spec-Baseline `openspec/specs/agent-providers` nach Archive
@@ -0,0 +1,33 @@
1# Proposal
2
3## Why
4
5«Write with» kann Microsoft Copilot schon durch ein Chat-Profil ersetzen, aber Composer und Chat-Insel bleiben optisch und textlich «Copilot». Wer kein MS-Abo nutzt, sieht weiter Copilot-Branding und die Insel spricht weiterhin nur die Teams-API.
6
7## What Changes
8
9- Wenn «Write with» ein Chat-Profil ist, zeigen Composer-Rewrite und die Chat-Header-Insel die Identität dieses Profils (Name + Non-Copilot-Icon), nicht «Copilot».
10- Die Chat-Insel beantwortet Fragen dann über dasselbe Chat-Profil; Kontext sind die letzten ~20 Nachrichten des offenen Chats als Text (kein MCP/Tools).
11- Composer-Status- und Fehlertexte folgen derselben Identität.
12- Mit lokalem Writer bleiben Rewrite und Insel auch ohne Teams-Engine / ohne Copilot-Lizenz erreichbar.
13- Leer belassenes «Write with» behält den Microsoft-Pfad inkl. Copilot-Branding (wie heute).
14
15Annahme (Explorations-Feinheit): sichtbarer Anzeigename ist der **Profilname** aus den Agents-Einstellungen, nicht der Backend-Modellstring.
16
17## Capabilities
18
19### New Capabilities
20
21- (keine)
22
23### Modified Capabilities
24
25- `agent-providers`: «Write with» steuert nicht nur den Rewrite-Backend-Pfad, sondern die gemeinsame Assistenten-Identität und den Ask-Pfad der Chat-Insel.
26
27## Impact
28
29- UI: `crates/app/src/views/composer/rewrite.rs`, `crates/app/src/views/conversation/copilot.rs`, Overflow-Menü in `chat_header_actions.rs`
30- Settings-Texte optional: `settings_section.rs` (Hinweis, dass Insel mitwechselt)
31- Kontextaufbau: Wiederverwendung/Erweiterung um Chat-Thread ohne feste `message_id` (Vorbild `message_context`, Limit 20)
32- Lauf: `agents::complete_text` für Insel-Ask; Microsoft `ask_copilot` nur bei leerem `write_with`
33- Spec-Baseline `openspec/specs/agent-providers` nach Archive
openspec/changes/archive/2026-11-11-write-with-identity/specs/agent-providers/spec.md added +44 −0
@@ -0,0 +1,44 @@
1 # Spec Delta
2
3 ## ADDED Requirements
4
5 ### Requirement: Write-with identity brands assistant surfaces
6
7 When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL present that profile's name and a non-Copilot icon instead of Microsoft Copilot branding. When «Write with» is empty, those surfaces SHALL keep Microsoft Copilot branding.
8
9 #### Scenario: Local writer rebrands composer and island
10
11 - **WHEN** the user has chosen a chat profile under Settings > Agents > Write with
12 - **THEN** the composer rewrite tooltip, working and failure copy name that profile
13 - **AND** the chat-header island title, open/close labels, placeholder and working/failure copy name that profile
14 - **AND** neither surface shows the Copilot colour logo as its identity mark
15
16 #### Scenario: Empty write-with keeps Copilot branding
17
18 - **WHEN** Write with is left empty (Microsoft Copilot)
19 - **THEN** composer rewrite and the chat-header island keep Copilot labels and the Copilot logo where they already appear today
20
21 ### Requirement: Chat island asks through the write-with profile
22
23 When «Write with» selects a chat profile, questions from the chat-header assistant island SHALL be answered by that profile. The prompt SHALL include up to the newest twenty non-deleted messages of the open chat as plain text plus the user's question. The island SHALL NOT call Microsoft Copilot for those asks. Empty Write with keeps the Microsoft ask path.
24
25 #### Scenario: Local ask uses recent chat messages
26
27 - **WHEN** Write with is a chat profile and the user asks a question in the chat-header island
28 - **THEN** the answer comes from that profile
29 - **AND** the model input includes at most the newest twenty non-deleted messages of that chat plus the question
30 - **AND** Microsoft Copilot is not invoked for that ask
31
32 #### Scenario: Empty write-with still uses Microsoft ask
33
34 - **WHEN** Write with is empty and the user asks in the chat-header island
35 - **THEN** the ask follows the existing Microsoft Copilot path
36
37 ### Requirement: Local writer surfaces work without a Teams engine
38
39 When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL remain available for an open chat even if the Teams sync engine is absent, so users without a Microsoft Copilot licence can still use the local writer.
40
41 #### Scenario: Island opens without engine when a local writer is set
42
43 - **WHEN** Write with is a chat profile, a chat is open, and no Teams sync engine is connected
44 - **THEN** the user can still open the chat-header assistant island and send a question to that profile
@@ -0,0 +1,44 @@
1# Spec Delta
2
3## ADDED Requirements
4
5### Requirement: Write-with identity brands assistant surfaces
6
7When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL present that profile's name and a non-Copilot icon instead of Microsoft Copilot branding. When «Write with» is empty, those surfaces SHALL keep Microsoft Copilot branding.
8
9#### Scenario: Local writer rebrands composer and island
10
11- **WHEN** the user has chosen a chat profile under Settings > Agents > Write with
12- **THEN** the composer rewrite tooltip, working and failure copy name that profile
13- **AND** the chat-header island title, open/close labels, placeholder and working/failure copy name that profile
14- **AND** neither surface shows the Copilot colour logo as its identity mark
15
16#### Scenario: Empty write-with keeps Copilot branding
17
18- **WHEN** Write with is left empty (Microsoft Copilot)
19- **THEN** composer rewrite and the chat-header island keep Copilot labels and the Copilot logo where they already appear today
20
21### Requirement: Chat island asks through the write-with profile
22
23When «Write with» selects a chat profile, questions from the chat-header assistant island SHALL be answered by that profile. The prompt SHALL include up to the newest twenty non-deleted messages of the open chat as plain text plus the user's question. The island SHALL NOT call Microsoft Copilot for those asks. Empty Write with keeps the Microsoft ask path.
24
25#### Scenario: Local ask uses recent chat messages
26
27- **WHEN** Write with is a chat profile and the user asks a question in the chat-header island
28- **THEN** the answer comes from that profile
29- **AND** the model input includes at most the newest twenty non-deleted messages of that chat plus the question
30- **AND** Microsoft Copilot is not invoked for that ask
31
32#### Scenario: Empty write-with still uses Microsoft ask
33
34- **WHEN** Write with is empty and the user asks in the chat-header island
35- **THEN** the ask follows the existing Microsoft Copilot path
36
37### Requirement: Local writer surfaces work without a Teams engine
38
39When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL remain available for an open chat even if the Teams sync engine is absent, so users without a Microsoft Copilot licence can still use the local writer.
40
41#### Scenario: Island opens without engine when a local writer is set
42
43- **WHEN** Write with is a chat profile, a chat is open, and no Teams sync engine is connected
44- **THEN** the user can still open the chat-header assistant island and send a question to that profile
openspec/changes/archive/2026-11-11-write-with-identity/tasks.md added +22 −0
@@ -0,0 +1,22 @@
1 # Tasks
2
3 ## 1. Writer-Resolver und Chat-Thread
4
5 - [x] 1.1 Gemeinsame Auflösung von «Write with» (Chat-Profil oder Microsoft) für App-UI bereitstellen und mit `cargo test -p app --lib` bzw. einem gezielten Unit-Test für leeres/`write_with`-Profil verifizieren
6 - [x] 1.2 Thread-Text für einen offenen Chat bauen (max. 20 nicht gelöschte Nachrichten, Sender analog `message_context`) und Unit-Test in `app-state` oder `agents` grün halten (`cargo test -p app-state --lib` bzw. passender Filter)
7
8 ## 2. Composer-Branding
9
10 - [x] 2.1 In `crates/app/src/views/composer/rewrite.rs` Working-/Failed-/Empty-/Text-only-Strings und Button-Icon an den lokalen Writer-Namen koppeln; Microsoft-Pfad unverändert lassen — verifizieren durch Review der Strings und `cargo test -p app --lib` falls vorhandene Rewrite-Tests greifen
11 - [x] 2.2 Settings-Hinweis unter «Write with» so anpassen, dass Rewrite und Chat-Insel erwähnt werden; manuell im Settings-Dialog prüfen
12
13 ## 3. Chat-Insel: Branding und lokaler Ask
14
15 - [x] 3.1 In `copilot.rs` und `chat_header_actions.rs` Titel, Tooltips, Placeholder, Working/Failed und Logo/Icon dynamisch aus dem Writer ableiten — verifizieren: mit lokalem Profil kein `copilot_color.svg` als Identitätsmarke
16 - [x] 3.2 Insel-Ask bei lokalem Writer über `complete_text` mit Thread+Frage; ohne Engine erreichbar; bei leerem `write_with` weiter `ask_copilot` — verifizieren mit gezieltem Test oder manuellem Smoke (lokales Profil vs. Microsoft)
17 - [x] 3.3 Integration: `cargo test -p agents --lib` und `cargo test -p app-state --lib` (oder engere Filter) grün; kurzer Smoke: Write with → Ollama/OpenAI-Profil → Insel-Frage und Composer-Rewrite zeigen Profilname
18
19 ## Workflow follow-up
20
21 - Archive nach Review und Merge der Spec-Deltas in `openspec/specs/agent-providers`
22 - Alltagskomits nach `fork` pushen, nicht nach `origin`
@@ -0,0 +1,22 @@
1# Tasks
2
3## 1. Writer-Resolver und Chat-Thread
4
5- [x] 1.1 Gemeinsame Auflösung von «Write with» (Chat-Profil oder Microsoft) für App-UI bereitstellen und mit `cargo test -p app --lib` bzw. einem gezielten Unit-Test für leeres/`write_with`-Profil verifizieren
6- [x] 1.2 Thread-Text für einen offenen Chat bauen (max. 20 nicht gelöschte Nachrichten, Sender analog `message_context`) und Unit-Test in `app-state` oder `agents` grün halten (`cargo test -p app-state --lib` bzw. passender Filter)
7
8## 2. Composer-Branding
9
10- [x] 2.1 In `crates/app/src/views/composer/rewrite.rs` Working-/Failed-/Empty-/Text-only-Strings und Button-Icon an den lokalen Writer-Namen koppeln; Microsoft-Pfad unverändert lassen — verifizieren durch Review der Strings und `cargo test -p app --lib` falls vorhandene Rewrite-Tests greifen
11- [x] 2.2 Settings-Hinweis unter «Write with» so anpassen, dass Rewrite und Chat-Insel erwähnt werden; manuell im Settings-Dialog prüfen
12
13## 3. Chat-Insel: Branding und lokaler Ask
14
15- [x] 3.1 In `copilot.rs` und `chat_header_actions.rs` Titel, Tooltips, Placeholder, Working/Failed und Logo/Icon dynamisch aus dem Writer ableiten — verifizieren: mit lokalem Profil kein `copilot_color.svg` als Identitätsmarke
16- [x] 3.2 Insel-Ask bei lokalem Writer über `complete_text` mit Thread+Frage; ohne Engine erreichbar; bei leerem `write_with` weiter `ask_copilot` — verifizieren mit gezieltem Test oder manuellem Smoke (lokales Profil vs. Microsoft)
17- [x] 3.3 Integration: `cargo test -p agents --lib` und `cargo test -p app-state --lib` (oder engere Filter) grün; kurzer Smoke: Write with → Ollama/OpenAI-Profil → Insel-Frage und Composer-Rewrite zeigen Profilname
18
19## Workflow follow-up
20
21- Archive nach Review und Merge der Spec-Deltas in `openspec/specs/agent-providers`
22- Alltagskomits nach `fork` pushen, nicht nach `origin`
openspec/specs/agent-providers/spec.md added +88 −0
@@ -0,0 +1,88 @@
1 # agent-providers Specification
2
3 ## Purpose
4
5 Die Fork-App erkennt lokale Agent-CLIs, lässt Profile und Aktionen in den Einstellungen pflegen und startet Agent-Läufe inkl. Chat-Runs aus der UI.
6
7 ## Requirements
8
9 ### Requirement: Installed CLIs are discoverable
10
11 The app SHALL scan for known agent CLIs on the host (including user bin directories that a desktop session often omits from PATH) and offer them as installable profiles.
12
13 #### Scenario: Claude on PATH or user bin
14
15 - **WHEN** a `claude` binary exists on PATH or under `~/.local/bin`
16 - **THEN** the agents settings can offer it as an installable host profile
17
18 #### Scenario: Cursor agent binary aliases
19
20 - **WHEN** `cursor-agent` or `agent` is available as the Cursor CLI
21 - **THEN** it appears as a Cursor host profile candidate
22
23 ### Requirement: Agent settings persist profiles and actions
24
25 Agent settings SHALL store profiles, actions, recent working directories, and which agent is used for «write with», and SHALL reject unknown placeholders and empty commands.
26
27 #### Scenario: Invalid action is rejected
28
29 - **WHEN** an action references an agent id that is not in the profile list
30 - **THEN** settings validation reports that problem
31 - **AND** the invalid configuration is not treated as healthy
32
33 #### Scenario: Write-with can target a chat profile
34
35 - **WHEN** the user picks a chat-capable agent for «write with»
36 - **THEN** that choice is stored in agent settings
37 - **AND** empty write-with means Microsoft Copilot
38
39 ### Requirement: Chat and task runs are started from the app
40
41 The user SHALL be able to start agent runs and chat runs from the app against a configured profile, with working-directory context remembered per agent.
42
43 #### Scenario: Recent working directories are remembered
44
45 - **WHEN** the user runs an agent with a working directory
46 - **THEN** that directory is kept in the recent list for that agent (capped)
47 - **AND** it can be chosen again later without retyping
48
49 ### Requirement: Write-with identity brands assistant surfaces
50
51 When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL present that profile's name and a non-Copilot icon instead of Microsoft Copilot branding. When «Write with» is empty, those surfaces SHALL keep Microsoft Copilot branding.
52
53 #### Scenario: Local writer rebrands composer and island
54
55 - **WHEN** the user has chosen a chat profile under Settings > Agents > Write with
56 - **THEN** the composer rewrite tooltip, working and failure copy name that profile
57 - **AND** the chat-header island title, open/close labels, placeholder and working/failure copy name that profile
58 - **AND** neither surface shows the Copilot colour logo as its identity mark
59
60 #### Scenario: Empty write-with keeps Copilot branding
61
62 - **WHEN** Write with is left empty (Microsoft Copilot)
63 - **THEN** composer rewrite and the chat-header island keep Copilot labels and the Copilot logo where they already appear today
64
65 ### Requirement: Chat island asks through the write-with profile
66
67 When «Write with» selects a chat profile, questions from the chat-header assistant island SHALL be answered by that profile. The prompt SHALL include up to the newest twenty non-deleted messages of the open chat as plain text plus the user's question. The island SHALL NOT call Microsoft Copilot for those asks. Empty Write with keeps the Microsoft ask path.
68
69 #### Scenario: Local ask uses recent chat messages
70
71 - **WHEN** Write with is a chat profile and the user asks a question in the chat-header island
72 - **THEN** the answer comes from that profile
73 - **AND** the model input includes at most the newest twenty non-deleted messages of that chat plus the question
74 - **AND** Microsoft Copilot is not invoked for that ask
75
76 #### Scenario: Empty write-with still uses Microsoft ask
77
78 - **WHEN** Write with is empty and the user asks in the chat-header island
79 - **THEN** the ask follows the existing Microsoft Copilot path
80
81 ### Requirement: Local writer surfaces work without a Teams engine
82
83 When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL remain available for an open chat even if the Teams sync engine is absent, so users without a Microsoft Copilot licence can still use the local writer.
84
85 #### Scenario: Island opens without engine when a local writer is set
86
87 - **WHEN** Write with is a chat profile, a chat is open, and no Teams sync engine is connected
88 - **THEN** the user can still open the chat-header assistant island and send a question to that profile
@@ -0,0 +1,88 @@
1# agent-providers Specification
2
3## Purpose
4
5Die Fork-App erkennt lokale Agent-CLIs, lässt Profile und Aktionen in den Einstellungen pflegen und startet Agent-Läufe inkl. Chat-Runs aus der UI.
6
7## Requirements
8
9### Requirement: Installed CLIs are discoverable
10
11The app SHALL scan for known agent CLIs on the host (including user bin directories that a desktop session often omits from PATH) and offer them as installable profiles.
12
13#### Scenario: Claude on PATH or user bin
14
15- **WHEN** a `claude` binary exists on PATH or under `~/.local/bin`
16- **THEN** the agents settings can offer it as an installable host profile
17
18#### Scenario: Cursor agent binary aliases
19
20- **WHEN** `cursor-agent` or `agent` is available as the Cursor CLI
21- **THEN** it appears as a Cursor host profile candidate
22
23### Requirement: Agent settings persist profiles and actions
24
25Agent settings SHALL store profiles, actions, recent working directories, and which agent is used for «write with», and SHALL reject unknown placeholders and empty commands.
26
27#### Scenario: Invalid action is rejected
28
29- **WHEN** an action references an agent id that is not in the profile list
30- **THEN** settings validation reports that problem
31- **AND** the invalid configuration is not treated as healthy
32
33#### Scenario: Write-with can target a chat profile
34
35- **WHEN** the user picks a chat-capable agent for «write with»
36- **THEN** that choice is stored in agent settings
37- **AND** empty write-with means Microsoft Copilot
38
39### Requirement: Chat and task runs are started from the app
40
41The user SHALL be able to start agent runs and chat runs from the app against a configured profile, with working-directory context remembered per agent.
42
43#### Scenario: Recent working directories are remembered
44
45- **WHEN** the user runs an agent with a working directory
46- **THEN** that directory is kept in the recent list for that agent (capped)
47- **AND** it can be chosen again later without retyping
48
49### Requirement: Write-with identity brands assistant surfaces
50
51When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL present that profile's name and a non-Copilot icon instead of Microsoft Copilot branding. When «Write with» is empty, those surfaces SHALL keep Microsoft Copilot branding.
52
53#### Scenario: Local writer rebrands composer and island
54
55- **WHEN** the user has chosen a chat profile under Settings > Agents > Write with
56- **THEN** the composer rewrite tooltip, working and failure copy name that profile
57- **AND** the chat-header island title, open/close labels, placeholder and working/failure copy name that profile
58- **AND** neither surface shows the Copilot colour logo as its identity mark
59
60#### Scenario: Empty write-with keeps Copilot branding
61
62- **WHEN** Write with is left empty (Microsoft Copilot)
63- **THEN** composer rewrite and the chat-header island keep Copilot labels and the Copilot logo where they already appear today
64
65### Requirement: Chat island asks through the write-with profile
66
67When «Write with» selects a chat profile, questions from the chat-header assistant island SHALL be answered by that profile. The prompt SHALL include up to the newest twenty non-deleted messages of the open chat as plain text plus the user's question. The island SHALL NOT call Microsoft Copilot for those asks. Empty Write with keeps the Microsoft ask path.
68
69#### Scenario: Local ask uses recent chat messages
70
71- **WHEN** Write with is a chat profile and the user asks a question in the chat-header island
72- **THEN** the answer comes from that profile
73- **AND** the model input includes at most the newest twenty non-deleted messages of that chat plus the question
74- **AND** Microsoft Copilot is not invoked for that ask
75
76#### Scenario: Empty write-with still uses Microsoft ask
77
78- **WHEN** Write with is empty and the user asks in the chat-header island
79- **THEN** the ask follows the existing Microsoft Copilot path
80
81### Requirement: Local writer surfaces work without a Teams engine
82
83When «Write with» selects a chat profile, the composer rewrite control and the chat-header assistant island SHALL remain available for an open chat even if the Teams sync engine is absent, so users without a Microsoft Copilot licence can still use the local writer.
84
85#### Scenario: Island opens without engine when a local writer is set
86
87- **WHEN** Write with is a chat profile, a chat is open, and no Teams sync engine is connected
88- **THEN** the user can still open the chat-header assistant island and send a question to that profile