pub(crate) fn model_degraded_sources(degraded: bool) -> Vec<String> {
if degraded {
vec!["model-unavailable".to_string()]
} else {
Vec::new()
}
}
const CELL_SUMMARY_CAP: usize = 600;
pub(crate) fn cell_summary(summary: &str) -> String {
let mut lead = String::new();
for line in summary.lines() {
let trimmed = line.trim();
if trimmed.starts_with('|') {
break;
}
if trimmed.is_empty() {
if !lead.is_empty() {
break;
}
continue;
}
if !lead.is_empty() {
lead.push(' ');
}
lead.push_str(trimmed);
}
if lead.is_empty() {
lead = summary.split_whitespace().collect::<Vec<_>>().join(" ");
}
if lead.chars().count() <= CELL_SUMMARY_CAP {
return lead;
}
let mut capped: String = lead.chars().take(CELL_SUMMARY_CAP).collect();
if let Some(space) = capped.rfind(' ') {
capped.truncate(space);
}
capped.push('…');
capped
}
#[cfg(test)]
mod tests {
use super::cell_summary;
#[test]
fn cell_summary_keeps_leading_paragraph_and_drops_embedded_table() {
let summary = "`crates/gcode` owns the code-indexing CLI. It indexes \
source files and projects facts into graph and vector backends.\n\n\
| Area | Responsibility |\n| --- | --- |\n| `src` | CLI dispatch. |";
let cell = cell_summary(summary);
assert_eq!(
cell,
"`crates/gcode` owns the code-indexing CLI. It indexes source files \
and projects facts into graph and vector backends."
);
assert!(
!cell.contains('|'),
"table content must not leak into the cell"
);
}
#[test]
fn cell_summary_stops_at_first_table_row_without_a_blank_line() {
let summary = "Adapts core capabilities to a local daemon transport.\n\
| Surface | Role |\n| --- | --- |\n| Op | sends requests. |";
let cell = cell_summary(summary);
assert_eq!(
cell,
"Adapts core capabilities to a local daemon transport."
);
}
#[test]
fn cell_summary_flattens_when_text_opens_with_a_table() {
let summary = "| Key | Value |\n| --- | --- |\n| a | b |";
let cell = cell_summary(summary);
assert_eq!(cell, "| Key | Value | | --- | --- | | a | b |");
}
#[test]
fn cell_summary_caps_runaway_single_paragraph_on_a_word_boundary() {
let word = "alpha ";
let summary = word.repeat(200);
let cell = cell_summary(&summary);
assert!(cell.chars().count() <= super::CELL_SUMMARY_CAP + 1); assert!(cell.ends_with('…'));
assert!(!cell.contains("alph…"), "cut must land on a word boundary");
}
}