Concatenate files under a byte budget, marking truncation.
(
files: Array<{ name: string; content: string }>,
budget: number,
)
| 84 | |
| 85 | /** Concatenate files under a byte budget, marking truncation. */ |
| 86 | function packFiles( |
| 87 | files: Array<{ name: string; content: string }>, |
| 88 | budget: number, |
| 89 | ): string { |
| 90 | const parts: string[] = []; |
| 91 | let used = 0; |
| 92 | for (const f of files) { |
| 93 | if (used >= budget) { parts.push(`… (${files.length - parts.length} more file(s) omitted)`); break; } |
| 94 | const remaining = budget - used; |
| 95 | const body = f.content.length > remaining |
| 96 | ? f.content.slice(0, remaining) + '\n… (truncated)' |
| 97 | : f.content; |
| 98 | parts.push(`### ${f.name}\n${body}`); |
| 99 | used += body.length + f.name.length + 8; |
| 100 | } |
| 101 | return parts.join('\n\n'); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Load and render the Trellis context block for `cwd`. Returns null when there's |
no test coverage detected