Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(importer): keep subtitle cues that follow two blank lines
Max Freedom Pollarde0a4570b7f25
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e2ce2b7a..2f35e8e7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,14 @@ version in [`docs/changelog/`](docs/changelog/):does not run on this machine" for a release that runs from where it isinstalled. A binary that really does not run is still refused, naming thedirectory it was tried from, and its staged copy is removed (#1623).+- The document importer no longer drops a VTT or SRT cue that follows two+ blank lines (or any even number of them). The subtitle reader split cues on+ a single blank line, so the extra one was left at the top of the next block,+ and a block that started with an empty line was skipped whole. A WebVTT file+ whose header was followed by two blank lines lost its first cue, or was+ rejected as containing no extractable text when that was its only cue.+ WebVTT allows any number of blank lines between blocks; the reader now skips+ them before reading a block.## [3.2.2] - 2026-10-22diff --git a/companions/ai-memory-importer/README.md b/companions/ai-memory-importer/README.mdindex 7068737e..ea8fe0d4 100644--- a/companions/ai-memory-importer/README.md+++ b/companions/ai-memory-importer/README.md@@ -145,8 +145,9 @@ by formatting may still be extracted; deleted revisions and field instructionsare excluded. Review `--show-body` before every live import of a document whosevisibility rules matter.-VTT/SRT files accept LF, CRLF, or CR line endings. WebVTT comments are omitted;-identifiers such as `NOTE123` keep their cue text.+VTT/SRT files accept LF, CRLF, or CR line endings and any number of blank lines+between cues. WebVTT comments are omitted; identifiers such as `NOTE123` keep+their cue text.## Safety contractdiff --git a/companions/ai-memory-importer/src/document.rs b/companions/ai-memory-importer/src/document.rsindex 063f1908..3622194b 100644--- a/companions/ai-memory-importer/src/document.rs+++ b/companions/ai-memory-importer/src/document.rs@@ -1029,8 +1029,15 @@ fn extract_transcript(bytes: &[u8], webvtt: bool) -> Result<String> {.replace("\r\n", "\n").replace('\r', "\n");for (block_index, block) in normalized.split("\n\n").enumerate() {- let lines = block.lines().map(str::trim).collect::<Vec<_>>();- let Some(first) = lines.first().copied().filter(|line| !line.is_empty()) else {+ // Blocks can be separated by more than one blank line (WebVTT allows+ // any number: https://www.w3.org/TR/webvtt1/#file-structure), so+ // splitting on a single one can leave a blank line atop the next block.+ let lines = block+ .lines()+ .map(str::trim)+ .skip_while(|line| line.is_empty())+ .collect::<Vec<_>>();+ let Some(first) = lines.first().copied() else {continue;};if webvtt && block_index == 0 && first.starts_with("WEBVTT") {@@ -1752,6 +1759,22 @@ mod tests {}}+ #[test]+ fn transcripts_keep_cues_after_more_than_one_blank_line() {+ let vtt = "WEBVTT\n\n\n00:00:01.000 --> 00:00:02.000\nFirst fact\n\n\n00:00:03.000 --> 00:00:04.000\nSecond fact\n";+ let srt = "1\n00:00:01,000 --> 00:00:02,000\nFirst fact\n\n\n2\n00:00:03,000 --> 00:00:04,000\nSecond fact\n";+ for newline in ["\n", "\r\n", "\r"] {+ for (input, webvtt) in [(vtt, true), (srt, false)] {+ let input = input.replace('\n', newline);+ assert_eq!(+ extract_transcript(input.as_bytes(), webvtt).unwrap().trim(),+ "First fact\n\nSecond fact",+ "line terminator {newline:?}, WebVTT={webvtt}"+ );+ }+ }+ }+#[test]fn subtitle_cues_are_sanitized_before_the_document_plan() {let temp = TempDir::new().unwrap();