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
//! Keep authored prose separate from host diagnostics until the display boundary.
//!
//! Transient composition only: persistent identity belongs to Observed Report's
//! canonical content address and the existing turn-outcome artifact.
#[derive(Debug, Default)]
pub(crate) struct FinalReply {
pub(super) model: String,
pub(super) notices: Vec<String>,
}
impl From<String> for FinalReply {
fn from(model: String) -> Self {
Self {
model,
notices: Vec::new(),
}
}
}
impl FinalReply {
pub(super) fn harness(notice: String) -> Self {
Self::default().with_notice(notice)
}
pub(super) fn with_notice(mut self, notice: String) -> Self {
if !notice.trim().is_empty() {
self.notices.push(notice);
}
self
}
pub(super) fn annotation(&mut self, annotated: String) {
if annotated != self.model {
// Existing gates append diagnostics. A gate that deduplicates an
// existing annotation may rewrite its presentation; preserve the
// original model bytes and show that checked view as harness data.
self.notices.push(
annotated
.strip_prefix(&self.model)
.unwrap_or(&annotated)
.trim()
.to_owned(),
);
}
}
#[cfg(test)]
pub(super) fn test_text(&self) -> String {
std::iter::once(self.model.as_str())
.chain(self.notices.iter().map(String::as_str))
.filter(|s| !s.is_empty())
.collect::<Vec<_>>()
.join("\n\n")
}
}