MCPcopy Create free account
hub / github.com/codehamr/codehamr / Truncate

Function Truncate

internal/ctx/ctx.go:85–96  ·  view source on GitHub ↗

Truncate collapses oversized tool outputs to first 2k + last 2k tokens; inputs at or under 6k pass through unchanged. Head/tail can't overlap: >6k tokens means >24k bytes, well over the 16k kept. Boundaries snap to a valid UTF-8 rune start so non-ASCII output never breaks mid-sequence.

(out string)

Source from the content-addressed store, hash-verified

83func ResponseReserve(ctxSize int) int {
84 if r := ctxSize / 8; r > 8000 {
85 return r
86 }
87 return 8000
88}
89
90// Truncate collapses oversized tool outputs to first 1k + last 3k tokens;
91// inputs at or under 6k pass through unchanged. Head/tail can't overlap:
92// >6k tokens means >24k bytes, well over the 16k kept. Boundaries snap to a
93// valid UTF-8 rune start so non-ASCII output never breaks mid-sequence.
94// The marker defers to the spill file tools.Execute names right below it, so
95// the model never reads "re-run the command" and "don't re-run it" in one
96// result; re-running narrower is only the fallback when no spill happened.
97func Truncate(out string) string {
98 total := Tokens(out)
99 if total <= ToolOutputCap {

Callers 3

Calls 3

TokensFunction · 0.85
runeBoundaryDownFunction · 0.85
runeBoundaryUpFunction · 0.85

Tested by 3