MCPcopy Create free account
hub / github.com/diillson/chatcli / snippetAround

Function snippetAround

cli/session_manager.go:287–309  ·  view source on GitHub ↗

snippetAround returns a trimmed, single-line window of content centered on the first occurrence of term, capped to keep search output compact.

(content, lowerContent, term string)

Source from the content-addressed store, hash-verified

285// snippetAround returns a trimmed, single-line window of content centered on
286// the first occurrence of term, capped to keep search output compact.
287func snippetAround(content, lowerContent, term string) string {
288 const window = 120
289 idx := strings.Index(lowerContent, term)
290 if idx < 0 {
291 idx = 0
292 }
293 start := idx - window/2
294 if start < 0 {
295 start = 0
296 }
297 end := idx + window/2
298 if end > len(content) {
299 end = len(content)
300 }
301 s := strings.TrimSpace(strings.ReplaceAll(content[start:end], "\n", " "))
302 if start > 0 {
303 s = "…" + s
304 }
305 if end < len(content) {
306 s += "…"
307 }
308 return s
309}
310
311// ForkSession creates a copy of an existing session with a new name.
312// The forked session is an independent copy — changes to either session don't affect the other.

Callers 3

TestSnippetAroundFunction · 0.85
SearchSessionsMethod · 0.85
TestSnippetAroundHelperFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestSnippetAroundFunction · 0.68
TestSnippetAroundHelperFunction · 0.68