aidaemon-channels 0.29.0

Chat channel contract and the runner that connects channels to aidaemon agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
//! Approval and goal-confirmation prompts on any SDK channel.
//!
//! A prompt is sent with [`Channel::ask`] (buttons) and waits for an
//! `ApprovalAnswer`; the answer replaces the prompt with its outcome.
//! Who may answer is the caller's decision, made before [`Prompts::answer`].

use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;

use crate::{ApprovalChoice, ApprovalPrompt, Channel, Conversation, MessageRef, OutboundMessage};
use tokio::sync::{Mutex, oneshot};
use tracing::{info, warn};

use crate::approval_render;
use aidaemon_tools::command_risk::{PermissionMode, RiskLevel};
use aidaemon_tools::semantics::{ApprovalResponse, GoalConfirmationStyle};

const APPROVAL_TIMEOUT: Duration = Duration::from_secs(300);
const GOAL_TIMEOUT: Duration = Duration::from_secs(1800);
/// How long before an approval card expires the owner is reminded of it
/// (at most a fifth of its wait).
const APPROVAL_REMINDER_BEFORE: Duration = Duration::from_secs(60);
/// The reminder sent while an approval card still waits.
const APPROVAL_REMINDER: &str = "⏳ Still waiting for your answer on the card above. It \
expires in about a minute; then that step is skipped, not refused.";

tokio::task_local! {
    /// Set by the hub around a card it may close because the card was
    /// answered elsewhere (the Client Gateway): the closing line to show
    /// on the card instead of "expired".
    pub(crate) static ANSWERED_ELSEWHERE: Arc<std::sync::Mutex<Option<String>>>;
}

/// The closing line set for the card being dropped, if it was answered
/// elsewhere.
fn answered_elsewhere() -> Option<String> {
    ANSWERED_ELSEWHERE
        .try_with(|note| note.lock().ok().and_then(|note| note.clone()))
        .ok()
        .flatten()
}

#[derive(Clone, Copy)]
enum Kind {
    Approval,
    Goal(GoalConfirmationStyle),
}

struct Open {
    kind: Kind,
    answer: oneshot::Sender<ApprovalResponse>,
    /// The message carrying the buttons and its text, once sent.
    shown: Option<(MessageRef, String)>,
}

/// The prompts a channel has open, by id.
#[derive(Default)]
pub struct Prompts {
    open: Arc<Mutex<HashMap<String, Open>>>,
}

/// Closes a prompt that ends without an answer (it timed out, or whoever
/// asked stopped waiting and dropped the request): the prompt leaves the
/// open book and its message loses its buttons, so a stale card can never
/// be pressed as if it still decided something.
struct Unanswered {
    id: String,
    open: Arc<Mutex<HashMap<String, Open>>>,
    channel: Arc<dyn Channel>,
    done: bool,
}

impl Drop for Unanswered {
    fn drop(&mut self) {
        if self.done {
            return;
        }
        let (id, open, channel) = (self.id.clone(), self.open.clone(), self.channel.clone());
        let elsewhere = answered_elsewhere();
        let Ok(runtime) = tokio::runtime::Handle::try_current() else {
            return;
        };
        runtime.spawn(async move {
            let Some(prompt) = open.lock().await.remove(&id) else {
                return; // answered meanwhile
            };
            if let Some((message, text)) = prompt.shown {
                let closed = match elsewhere {
                    Some(line) => format!(
                        "{}\n\n{line}",
                        approval_render::strip_approval_footer(&text).trim_end()
                    ),
                    None => expired_text(prompt.kind, &text),
                };
                if let Err(error) = channel.edit(&message, &closed).await {
                    warn!(%error, prompt = %id, "Failed to mark an unanswered prompt expired");
                }
            }
        });
    }
}

/// A prompt's text once it ended without an answer.
fn expired_text(kind: Kind, text: &str) -> String {
    match kind {
        Kind::Approval => format!(
            "{}\n\n⌛ Expired: no answer in time, so it was declined. Nothing was done.",
            approval_render::strip_approval_footer(text).trim_end()
        ),
        Kind::Goal(_) => format!(
            "{}\n\n⌛ Expired: no answer in time. Nothing was activated.",
            text.trim_end()
        ),
    }
}

/// What answering a prompt changed.
pub struct Answered {
    /// The message to replace, and its new text (without buttons).
    pub update: Option<(MessageRef, String)>,
    /// A short confirmation of the answer ("✅ Allowed this once").
    pub label: String,
    /// It was an approval (not a goal confirmation).
    pub approval: bool,
}

impl Prompts {
    /// Ask to approve `command`; waits up to five minutes. A timeout, a
    /// failed send or a closed prompt is an error (and declines).
    #[allow(clippy::too_many_arguments)]
    pub async fn approval(
        &self,
        channel: Arc<dyn Channel>,
        conversation: &Conversation,
        command: &str,
        risk_level: RiskLevel,
        warnings: &[String],
        permission_mode: PermissionMode,
        one_time_only: bool,
    ) -> anyhow::Result<ApprovalResponse> {
        self.approval_ask(
            channel,
            conversation,
            &approval_render::ApprovalAsk {
                command,
                card: None,
                risk_level,
                warnings,
                permission_mode,
                one_time_only,
            },
        )
        .await
    }

    /// Ask for `ask`, rendered from its typed card when it has one; waits up
    /// to five minutes. A timeout, a failed send or a closed prompt is an
    /// error (and declines).
    pub async fn approval_ask(
        &self,
        channel: Arc<dyn Channel>,
        conversation: &Conversation,
        ask: &approval_render::ApprovalAsk<'_>,
    ) -> anyhow::Result<ApprovalResponse> {
        let session_button =
            approval_render::approval_use_session_button(ask.permission_mode, ask.risk_level);
        let takes_over = ask
            .card
            .is_some_and(|card| matches!(card.action, aidaemon_core::CardAction::TakeOver { .. }));
        let choices = if takes_over {
            handoff_choices()
        } else {
            approval_choices(session_button, ask.one_time_only)
        };
        let text = approval_render::build_approval_ask_markdown(ask);
        info!(
            risk = %ask.risk_level,
            mode = %ask.permission_mode,
            card = ask.card.is_some(),
            "Asking for an approval"
        );
        self.ask(
            channel,
            conversation,
            Kind::Approval,
            &[text],
            choices,
            APPROVAL_TIMEOUT,
        )
        .await
    }

    /// Ask to confirm a goal; waits up to thirty minutes. True to confirm.
    pub async fn goal(
        &self,
        channel: Arc<dyn Channel>,
        conversation: &Conversation,
        description: &str,
        details: &[String],
        style: GoalConfirmationStyle,
    ) -> anyhow::Result<bool> {
        let pages = approval_render::build_goal_confirmation_pages(description, details, style);
        let choices = goal_choices(style);
        let response = self
            .ask(
                channel,
                conversation,
                Kind::Goal(style),
                &pages,
                choices,
                GOAL_TIMEOUT,
            )
            .await?;
        Ok(!matches!(response, ApprovalResponse::Deny))
    }

    async fn ask(
        &self,
        channel: Arc<dyn Channel>,
        conversation: &Conversation,
        kind: Kind,
        pages: &[String],
        choices: Vec<ApprovalChoice>,
        timeout: Duration,
    ) -> anyhow::Result<ApprovalResponse> {
        let Some((last, leading)) = pages.split_last() else {
            anyhow::bail!("empty prompt");
        };
        let id = uuid::Uuid::new_v4().to_string();
        let (answer, answered) = oneshot::channel();
        self.open.lock().await.insert(
            id.clone(),
            Open {
                kind,
                answer,
                shown: None,
            },
        );
        let mut unanswered = Unanswered {
            id: id.clone(),
            open: self.open.clone(),
            channel: channel.clone(),
            done: false,
        };
        let sent = async {
            for page in leading {
                channel
                    .send(conversation, &OutboundMessage::text(page.clone()))
                    .await?;
            }
            channel
                .ask(&ApprovalPrompt::new(
                    id.clone(),
                    conversation.clone(),
                    last.clone(),
                    choices,
                ))
                .await
        }
        .await;
        match sent {
            Ok(message) => {
                if let Some(open) = self.open.lock().await.get_mut(&id) {
                    open.shown = Some((message, last.clone()));
                }
            }
            Err(error) => {
                unanswered.done = true;
                self.open.lock().await.remove(&id);
                warn!(%error, "Failed to send a prompt");
                anyhow::bail!("the prompt could not be delivered: {error}");
            }
        }
        let mut answered = answered;
        // An approval card nobody has answered gets one reminder shortly
        // before it expires: a helper working in the background may have
        // asked while the owner looked elsewhere.
        let remind_at = matches!(kind, Kind::Approval)
            .then(|| timeout.checked_sub(APPROVAL_REMINDER_BEFORE.min(timeout / 5)))
            .flatten()
            .filter(|at| !at.is_zero());
        let outcome = match remind_at {
            Some(at) => match tokio::time::timeout(at, &mut answered).await {
                Ok(answer) => Ok(answer),
                Err(_) => {
                    if let Err(error) = channel
                        .send(conversation, &OutboundMessage::text(APPROVAL_REMINDER))
                        .await
                    {
                        warn!(%error, prompt = %id, "Failed to remind about a waiting card");
                    }
                    tokio::time::timeout(timeout - at, &mut answered).await
                }
            },
            None => tokio::time::timeout(timeout, &mut answered).await,
        };
        // An answer already took the prompt out of the book and replaced its
        // message; anything else leaves it to `unanswered`, which expires it.
        unanswered.done = matches!(outcome, Ok(Ok(_)));
        drop(unanswered);
        match outcome {
            Ok(Ok(response)) => Ok(response),
            Ok(Err(_)) => anyhow::bail!("the prompt was closed without an answer"),
            Err(_) => {
                warn!(prompt = %id, "Prompt timed out");
                anyhow::bail!("the prompt timed out")
            }
        }
    }

    /// Whether `prompt_id` is open (an answer to anything else is stale).
    pub async fn is_open(&self, prompt_id: &str) -> bool {
        self.open.lock().await.contains_key(prompt_id)
    }

    /// Answer prompt `prompt_id` with `choice_id`. `None` if the prompt is
    /// not open or the choice is not one of its own.
    pub async fn answer(&self, prompt_id: &str, choice_id: &str) -> Option<Answered> {
        let mut open = self.open.lock().await;
        let kind = open.get(prompt_id)?.kind;
        let response = response_for(kind, choice_id)?;
        let prompt = open.remove(prompt_id)?;
        let _ = prompt.answer.send(response.clone());
        let update = prompt.shown.map(|(message, text)| {
            let outcome = match kind {
                Kind::Approval => approval_render::finalize_approval_message(&text, &response),
                Kind::Goal(style) => goal_outcome(&text, style, choice_id, &response),
            };
            (message, outcome)
        });
        let label = match kind {
            Kind::Approval => {
                let (icon, status) = approval_render::response_status(&response);
                format!("{icon} {status}")
            }
            Kind::Goal(style) => goal_label(style, choice_id, &response).to_string(),
        };
        Some(Answered {
            update,
            label,
            approval: matches!(kind, Kind::Approval),
        })
    }
}

/// Allow (this once), then (unless the grant is one-time only) until a
/// restart or always, then deny. The labels say what each grant lasts, so
/// the card needs no footer explaining them.
fn approval_choices(session_button: bool, one_time_only: bool) -> Vec<ApprovalChoice> {
    let mut choices = vec![choice("once", "Allow")];
    if !one_time_only {
        choices.push(if session_button {
            choice("session", "Allow until restart")
        } else {
            choice("always", "Always allow")
        });
    }
    choices.push(choice("deny", "Deny"));
    choices
}

/// Confirm, (for Autopilot) edit, cancel.
fn goal_choices(style: GoalConfirmationStyle) -> Vec<ApprovalChoice> {
    let mut choices = vec![choice(
        "confirm",
        match style {
            GoalConfirmationStyle::Standard => "Approve & activate",
            GoalConfirmationStyle::Autopilot => "Enable Autopilot",
        },
    )];
    if matches!(style, GoalConfirmationStyle::Autopilot) {
        choices.push(choice("edit", "Edit permissions"));
    }
    choices.push(choice("cancel", "Cancel"));
    choices
}

/// A handoff: the owner did it (Done) or will not now. Their ids are the
/// once and deny answers, so every channel reads them the same way.
fn handoff_choices() -> Vec<ApprovalChoice> {
    vec![choice("once", "Done"), choice("deny", "Not now")]
}

fn choice(id: &str, label: &str) -> ApprovalChoice {
    ApprovalChoice {
        id: id.to_string(),
        label: label.to_string(),
    }
}

fn response_for(kind: Kind, choice_id: &str) -> Option<ApprovalResponse> {
    Some(match (kind, choice_id) {
        (Kind::Approval, "once") => ApprovalResponse::AllowOnce,
        (Kind::Approval, "session") => ApprovalResponse::AllowSession,
        (Kind::Approval, "always") => ApprovalResponse::AllowAlways,
        (Kind::Approval, "deny") => ApprovalResponse::Deny,
        (Kind::Goal(_), "confirm") => ApprovalResponse::AllowOnce,
        (Kind::Goal(_), "cancel" | "edit") => ApprovalResponse::Deny,
        _ => return None,
    })
}

fn goal_label(
    style: GoalConfirmationStyle,
    choice_id: &str,
    response: &ApprovalResponse,
) -> &'static str {
    let autopilot = matches!(style, GoalConfirmationStyle::Autopilot);
    match (autopilot, choice_id, response) {
        (true, "edit", _) => "Edit Autopilot permissions",
        (true, _, ApprovalResponse::Deny) => "Autopilot cancelled",
        (true, _, _) => "Autopilot enabled ✅",
        (false, _, ApprovalResponse::Deny) => "Goal cancelled",
        (false, _, _) => "Goal approved ✅",
    }
}

fn goal_outcome(
    text: &str,
    style: GoalConfirmationStyle,
    choice_id: &str,
    response: &ApprovalResponse,
) -> String {
    let autopilot = matches!(style, GoalConfirmationStyle::Autopilot);
    let status = match (autopilot, choice_id, response) {
        (true, "edit", _) => {
            "✏️ Autopilot not activated\nSend the accounts, actions, limits, or guardrails you want changed."
        }
        (true, _, ApprovalResponse::Deny) => {
            "❌ Autopilot cancelled\nNo new autonomy was activated."
        }
        (true, _, _) => "✅ Autopilot enabled\nActivation is continuing now.",
        (false, _, ApprovalResponse::Deny) => "❌ Goal cancelled\nNothing was activated.",
        (false, _, _) => "✅ Goal approved\nActivation is continuing now.",
    };
    format!("{}\n\n{status}", text.trim_end())
}

/// A bot that asks its prompts over its SDK transport. The three prompt
/// methods of [`crate::hub::HubChannel`] are [`PromptSurface::ask_approval`]
/// and [`PromptSurface::confirm_goal`] for it, so every bot logs, asks and
/// names its failures the same way.
#[async_trait::async_trait]
pub trait PromptSurface: Send + Sync {
    /// The bot's open prompts.
    fn prompts(&self) -> &Prompts;
    /// The platform's name in errors ("Slack").
    fn platform(&self) -> &'static str;
    /// The transport and conversation a session's prompts go to.
    async fn prompt_target(
        &self,
        session_id: &str,
    ) -> anyhow::Result<(Arc<dyn Channel>, Conversation)>;

    /// Ask the owner to approve `ask` in the session's chat.
    async fn ask_approval(
        &self,
        session_id: &str,
        ask: &approval_render::ApprovalAsk<'_>,
    ) -> anyhow::Result<ApprovalResponse> {
        info!(
            session_id,
            platform = self.platform(),
            card = ask.card.is_some(),
            risk = %ask.risk_level,
            "Approval requested"
        );
        let (channel, conversation) = self.prompt_target(session_id).await?;
        self.prompts()
            .approval_ask(channel, &conversation, ask)
            .await
            .map_err(|e| anyhow::anyhow!("{} approval request failed: {e}", self.platform()))
    }

    /// Ask the owner to confirm a goal in the session's chat.
    async fn confirm_goal(
        &self,
        session_id: &str,
        description: &str,
        details: &[String],
        style: GoalConfirmationStyle,
    ) -> anyhow::Result<bool> {
        let (channel, conversation) = self.prompt_target(session_id).await?;
        self.prompts()
            .goal(channel, &conversation, description, details, style)
            .await
            .map_err(|e| anyhow::anyhow!("{} goal confirmation failed: {e}", self.platform()))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    /// A card nobody answers loses its buttons: when it times out, and when
    /// whoever asked stops waiting and drops the request.
    #[tokio::test]
    async fn an_unanswered_card_expires() {
        use crate::testing::{TestChannel, direct};
        for dropped in [false, true] {
            let channel = Arc::new(
                TestChannel::new("synthetic")
                    .with_buttons(true)
                    .with_edits(true),
            );
            let prompts = Prompts::default();
            let conversation = direct("synthetic-user-1");
            let pages = ["Summarize the Acme forecast every Monday".to_string()];
            let ask = prompts.ask(
                channel.clone(),
                &conversation,
                Kind::Goal(GoalConfirmationStyle::Standard),
                &pages,
                goal_choices(GoalConfirmationStyle::Standard),
                Duration::from_millis(if dropped { 60_000 } else { 50 }),
            );
            if dropped {
                let _ = tokio::time::timeout(Duration::from_millis(50), ask).await;
            } else {
                assert!(ask.await.is_err(), "a timeout declines");
            }
            assert!(
                channel
                    .wait_for(Duration::from_secs(2), |c| !c.edits().is_empty())
                    .await,
                "dropped={dropped}: the card was not expired"
            );
            let edit = &channel.edits()[0];
            assert!(edit.text.contains("Expired"), "{}", edit.text);
            assert!(!prompts.is_open(&channel.prompts()[0].id).await);
        }
    }

    /// A card closed because it was answered elsewhere (the hub sets the
    /// line around the ask) says that answer, not "expired".
    #[tokio::test]
    async fn a_card_answered_elsewhere_says_so() {
        use crate::testing::{TestChannel, direct};
        let channel = Arc::new(
            TestChannel::new("synthetic")
                .with_buttons(true)
                .with_edits(true),
        );
        let prompts = Prompts::default();
        let conversation = direct("synthetic-user-1");
        let pages = ["Your assistant wants to run a command on your computer.".to_string()];
        let note = Arc::new(std::sync::Mutex::new(None));
        let mut ask = Box::pin(ANSWERED_ELSEWHERE.scope(
            note.clone(),
            prompts.ask(
                channel.clone(),
                &conversation,
                Kind::Approval,
                &pages,
                approval_choices(false, true),
                Duration::from_secs(60),
            ),
        ));
        assert!(
            tokio::time::timeout(Duration::from_millis(50), &mut ask)
                .await
                .is_err()
        );
        *note.lock().unwrap() = Some("✅ Allowed this once, from the app.".to_string());
        drop(ask);
        assert!(
            channel
                .wait_for(Duration::from_secs(2), |c| !c.edits().is_empty())
                .await
        );
        let edit = &channel.edits()[0];
        assert!(edit.text.contains("from the app"), "{}", edit.text);
        assert!(!edit.text.contains("Expired"), "{}", edit.text);
    }

    /// A waiting approval card gets one reminder before it expires.
    #[tokio::test]
    async fn a_waiting_approval_card_is_reminded_once_before_it_expires() {
        use crate::testing::{TestChannel, direct};
        let channel = Arc::new(
            TestChannel::new("synthetic")
                .with_buttons(true)
                .with_edits(true),
        );
        let prompts = Prompts::default();
        let conversation = direct("synthetic-user-1");
        let pages = ["Your assistant wants to run a command on your computer.".to_string()];
        let ask = prompts.ask(
            channel.clone(),
            &conversation,
            Kind::Approval,
            &pages,
            approval_choices(false, true),
            Duration::from_millis(300),
        );
        assert!(ask.await.is_err(), "nobody answered");
        let reminders: Vec<String> = channel
            .sent()
            .into_iter()
            .map(|sent| sent.message.text)
            .filter(|text| text.contains("Still waiting"))
            .collect();
        assert_eq!(reminders.len(), 1, "{reminders:?}");
    }

    fn labels(choices: Vec<ApprovalChoice>) -> Vec<String> {
        choices.into_iter().map(|c| c.label).collect()
    }

    #[test]
    fn approval_buttons_follow_the_grant_offered() {
        assert_eq!(
            labels(approval_choices(false, false)),
            ["Allow", "Always allow", "Deny"]
        );
        assert_eq!(
            labels(approval_choices(true, false)),
            ["Allow", "Allow until restart", "Deny"]
        );
        // A one-time grant offers nothing that persists.
        assert_eq!(labels(approval_choices(true, true)), ["Allow", "Deny"]);
    }

    #[test]
    fn autopilot_confirmation_can_be_sent_back_for_edits() {
        assert_eq!(
            labels(goal_choices(GoalConfirmationStyle::Standard)),
            ["Approve & activate", "Cancel"]
        );
        assert_eq!(
            labels(goal_choices(GoalConfirmationStyle::Autopilot)),
            ["Enable Autopilot", "Edit permissions", "Cancel"]
        );
    }

    #[test]
    fn choices_belong_to_their_kind() {
        assert!(response_for(Kind::Approval, "confirm").is_none());
        assert!(response_for(Kind::Goal(GoalConfirmationStyle::Standard), "always").is_none());
        assert!(matches!(
            response_for(Kind::Goal(GoalConfirmationStyle::Autopilot), "edit"),
            Some(ApprovalResponse::Deny)
        ));
    }

    #[test]
    fn a_goal_outcome_keeps_the_proposal() {
        let text = goal_outcome(
            "Post daily",
            GoalConfirmationStyle::Standard,
            "confirm",
            &ApprovalResponse::AllowOnce,
        );
        assert!(text.starts_with("Post daily\n\n✅ Goal approved"));
    }
}