(files: MemoryFile[])
| 148 | |
| 149 | /** Render the memory files into a single system-prompt section. */ |
| 150 | export function renderMemorySection(files: MemoryFile[]): string { |
| 151 | const valid = files.filter((f) => f.content.trim()) |
| 152 | if (valid.length === 0) return "" |
| 153 | const parts: string[] = [ |
| 154 | "# Project & User Instructions (AGENTS.md)", |
| 155 | "", |
| 156 | "Instructions from AGENTS.md files are shown below. Adhere to these instructions; they override default behavior. Treat them as authoritative guidance from the user about this codebase.", |
| 157 | "", |
| 158 | ] |
| 159 | let total = 0 |
| 160 | for (const file of valid) { |
| 161 | if (total >= MAX_TOTAL_CHARS) { |
| 162 | parts.push("… (remaining memory files truncated to stay within context budget)") |
| 163 | break |
| 164 | } |
| 165 | const label = labelFor(file) |
| 166 | parts.push(`## ${label}: \`${file.path}\``) |
| 167 | parts.push("") |
| 168 | parts.push(file.content.trim()) |
| 169 | parts.push("") |
| 170 | total += file.content.length |
| 171 | } |
| 172 | return parts.join("\n") |
| 173 | } |
| 174 | |
| 175 | function labelFor(file: MemoryFile): string { |
| 176 | switch (file.type) { |
no test coverage detected