MCPcopy
hub / github.com/wavetermdev/waveterm / truncateData

Function truncateData

pkg/aiusechat/tools_readfile.go:85–104  ·  view source on GitHub ↗

truncateData truncates data to maxBytes while respecting line boundaries. For origin "start", keeps the beginning and truncates at last newline before maxBytes. For origin "end", keeps the end and truncates from beginning at first newline after removing excess.

(data string, origin string, maxBytes int)

Source from the content-addressed store, hash-verified

83// For origin "start", keeps the beginning and truncates at last newline before maxBytes.
84// For origin "end", keeps the end and truncates from beginning at first newline after removing excess.
85func truncateData(data string, origin string, maxBytes int) string {
86 if len(data) <= maxBytes {
87 return data
88 }
89
90 if origin == "end" {
91 excessBytes := len(data) - maxBytes
92 truncateIdx := strings.Index(data[excessBytes:], "\n")
93 if truncateIdx == -1 {
94 return data[excessBytes:]
95 }
96 return data[excessBytes+truncateIdx+1:]
97 }
98
99 truncateIdx := strings.LastIndex(data[:maxBytes], "\n")
100 if truncateIdx == -1 {
101 return data[:maxBytes]
102 }
103 return data[:truncateIdx+1]
104}
105
106func isBlockedFile(expandedPath string) (bool, string) {
107 homeDir := os.Getenv("HOME")

Callers 1

readTextFileCallbackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected