Cap per-file and total content bytes before they're packed into the review prompt. Returns the capped (path, content) list. Sets module-level _last_review_truncated_bytes to the number of bytes dropped (0 if none) so the Stop hook can emit a `diff_truncated` metric. Truncation markers ar
(files)
| 156 | |
| 157 | |
| 158 | def _cap_files_for_prompt(files): |
| 159 | """Cap per-file and total content bytes before they're packed into the |
| 160 | review prompt. Returns the capped (path, content) list. Sets module-level |
| 161 | _last_review_truncated_bytes to the number of bytes dropped (0 if none) so |
| 162 | the Stop hook can emit a `diff_truncated` metric. Truncation markers are |
| 163 | written INSIDE the content so the reviewer knows the file is incomplete. |
| 164 | """ |
| 165 | global _last_review_truncated_bytes |
| 166 | _last_review_truncated_bytes = 0 |
| 167 | out = [] |
| 168 | total = 0 |
| 169 | for fp, content in files: |
| 170 | if len(content) > DIFF_PER_FILE_BYTES: |
| 171 | _last_review_truncated_bytes += len(content) - DIFF_PER_FILE_BYTES |
| 172 | content = content[:DIFF_PER_FILE_BYTES] + "\n... [truncated by security-guidance: file exceeds per-file byte cap]" |
| 173 | room = DIFF_TOTAL_BYTES - total |
| 174 | if room <= 0: |
| 175 | _last_review_truncated_bytes += len(content) |
| 176 | out.append((fp, "[omitted by security-guidance: total diff byte cap reached]")) |
| 177 | continue |
| 178 | if len(content) > room: |
| 179 | _last_review_truncated_bytes += len(content) - room |
| 180 | content = content[:room] + "\n... [truncated by security-guidance: total diff byte cap reached]" |
| 181 | total += len(content) |
| 182 | out.append((fp, content)) |
| 183 | return out |
| 184 | |
| 185 | |
| 186 | # Sticky preference: once the API key 401s and the OAuth token works, all |
no outgoing calls
no test coverage detected