runeBoundaryDown walks i left to a rune start so out[:i] never ends mid-sequence. Safe for i == len(out).
(out string, i int)
| 98 | // the model never reads "rerun the command" and "don't rerun it" in one |
| 99 | // result; rerunning narrower is only the fallback when no spill happened. |
| 100 | func Truncate(out string) string { |
| 101 | total := Tokens(out) |
| 102 | if total <= ToolOutputCap { |
| 103 | return out |
| 104 | } |
| 105 | head := runeBoundaryDown(out, ToolTruncHead*4) |
| 106 | tail := runeBoundaryUp(out, len(out)-ToolTruncTail*4) |
| 107 | marker := fmt.Sprintf("\n───── truncated: %d tokens total, first %d + last %d shown, the middle is OMITTED. This is a PARTIAL view; you can't review or conclude from what you can't see here. If a line below names a full output file, grep or read that file for the omitted span; otherwise rerun narrower (grep/sed/head/tail). ─────\n", |
| 108 | total, ToolTruncHead, ToolTruncTail) |
| 109 | return out[:head] + marker + out[tail:] |
| 110 | } |
| 111 |