MCPcopy Create free account
hub / github.com/betta-tech/byo-coding-agent / SafeSplitPoint

Function SafeSplitPoint

internal/compact/strategy.go:23–36  ·  view source on GitHub ↗

SafeSplitPoint walks backward from `desired` to find an index where the conversation is in a "clean" state — no tool_use without its tool_result on either side of the split. The split happens just before a user message that is plain text (not tool_results). Returns 0 if no safe boundary is found, me

(messages []api.Message, desired int)

Source from the content-addressed store, hash-verified

21// that is plain text (not tool_results). Returns 0 if no safe boundary is
22// found, meaning "do nothing."
23func SafeSplitPoint(messages []api.Message, desired int) int {
24 if desired <= 0 {
25 return 0
26 }
27 if desired >= len(messages) {
28 return len(messages)
29 }
30 for i := desired; i > 0; i-- {
31 if messages[i].Role == api.RoleUser && !messages[i].HasToolResult() {
32 return i
33 }
34 }
35 return 0
36}

Callers 6

TestSafeSplitPointEdgesFunction · 0.85
CompactMethod · 0.85
CompactMethod · 0.85

Calls 1

HasToolResultMethod · 0.80