Preserve conversation context and separate next actions in recaps (#45090)

## Why

The 900-byte recap prompt limit leaves little room for completed progress, unresolved caveats, and recent corrections. Recaps need this context to distinguish completed work from pending requests.

## What changed

- Introduce a shared `RecapPrompt` with a 32 KiB ceiling for instructions and history, using an 8,192-token estimate. Instruct summaries to retain the broader goal, completed outcomes, and unresolved availability or validation caveats.
- Select up to eight answered exchanges plus a pending request, preserving adjacent steering and progress messages. Drop older whole exchanges before excerpting both ends of oversized messages, while retaining the newest answer and pending correction.
- Require a `summary` and nullable `next_action`, bounded to 700 and 200 characters respectively. Reject malformed or oversized responses and display an optional, separately styled `Next:` line.

## Testing

Add coverage for UTF-8 prompt bounds, exchange selection, pending corrections, excerpt boundaries, strict response parsing, and next-action rendering. Extend the recap generation integration test to verify bounded history and the structured response schema.

GitOrigin-RevId: 6c6a84bc602a168418c1952feb1d286ec0cb9e28
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-12 18:16:17 +00:00
1 parent f16c2237a5
commit 8d3c6cc13d
9 files changed
+544 -141

No files matched your search

+22 -5
View File
@@ -317,12 +317,21 @@ impl HistoryCell for ThreadRecapLoadingCell {
#[derive(Debug)]
pub(crate) struct ThreadRecapHistoryCell {
recap: String,
next_action: Option<String>,
}
#[cfg_attr(not(test), allow(dead_code))]
impl ThreadRecapHistoryCell {
pub(crate) fn new(recap: String) -> Self {
Self { recap }
Self {
recap,
next_action: None,
}
}
pub(crate) fn with_next_action(mut self, next_action: Option<String>) -> Self {
self.next_action = next_action;
self
}
}
@@ -333,10 +342,15 @@ impl HistoryCell for ThreadRecapHistoryCell {
}
let wrap_width = usize::from(width.saturating_sub(/*rhs*/ 2).max(/*other*/ 1));
let mut body = raw_lines_from_source(&self.recap)
.into_iter()
.map(Line::italic)
.collect::<Vec<_>>();
let mut body = raw_lines_from_source(&self.recap);
if let Some(action) = &self.next_action {
body.extend(prefix_lines(
raw_lines_from_source(action),
"Next: ".bold().cyan(),
"".into(),
));
}
let mut body = body.into_iter().map(Line::italic).collect::<Vec<_>>();
let prefix = Line::from(vec![" ".into(), "↳ ".dim(), "Recap: ".bold()]).italic();
let mut options = if wrap_width <= prefix.width() {
// Keep the text readable when the terminal cannot fit the hanging indent.
@@ -371,6 +385,9 @@ impl HistoryCell for ThreadRecapHistoryCell {
fn raw_lines(&self) -> Vec<Line<'static>> {
let mut lines = vec![Line::from(RECAP_HEADING)];
lines.extend(raw_lines_from_source(&self.recap));
if let Some(action) = &self.next_action {
lines.extend(raw_lines_from_source(&format!("Next: {action}")));
}
lines
}
}