Skip to content

Commit 21843c6

Browse files
committed
Wire content phase into pack output
1 parent 212a8e6 commit 21843c6

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/eval.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn parse_pipe(output: &str) -> ParsedPipe {
119119
if part.starts_with('[')
120120
|| part.starts_with("root:")
121121
|| part.starts_with("IMPORTANT:")
122+
|| part.starts_with("CONTENT:")
122123
{
123124
continue;
124125
}

src/packer/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,28 @@ fn pack_impl(
467467
}
468468
}
469469

470+
// Phase 3: CONTENT
471+
if !budget.is_exhausted() {
472+
for file in &files_by_priority {
473+
if budget.is_exhausted() {
474+
break;
475+
}
476+
477+
let Some(content_text) = content::read_entry_content(file) else {
478+
continue;
479+
};
480+
481+
let rel_path = file.relative_path.to_string_lossy().to_string();
482+
let safe_content = sanitize_content_for_pipe(&content_text);
483+
let segment = format!("CONTENT:{}\n```\n{}\n```", rel_path, safe_content);
484+
485+
if !push_segment(&mut segments, &mut budget, segment) {
486+
// Try the next file in case a smaller one fits.
487+
continue;
488+
}
489+
}
490+
}
491+
470492
// Add truncation indicator if anything was cut
471493
// Space was reserved upfront via TRUNCATION_INDICATOR_RESERVE
472494
if let Some(indicator) = truncation.format_indicator() {
@@ -772,3 +794,7 @@ fn top_level_dir(path: &Path) -> String {
772794
}
773795
}
774796
}
797+
798+
fn sanitize_content_for_pipe(content: &str) -> String {
799+
content.replace('|', "<PIPE>")
800+
}

tests/edge_cases.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn test_spine_exceeds_budget() {
8585
false,
8686
);
8787
// With a tiny budget and a huge flat dir, tree segments should be omitted.
88-
assert!(!output.contains("file001.rs"));
88+
assert!(!output.contains(".:{file001.rs"));
8989
}
9090

9191
#[test]
@@ -406,7 +406,7 @@ fn test_flat_1000_files_root_listing() {
406406
false,
407407
);
408408
assert!(output.contains("root:"));
409-
assert!(!output.contains("file_0001.txt"));
409+
assert!(!output.contains(".:{file_0001.txt"));
410410
}
411411

412412
#[test]

0 commit comments

Comments
 (0)