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

Function firstLine

internal/tools/bash.go:296–314  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

294// bashOutputHead / bashOutputTail bound what headTailBuffer retains: first 1MB
295// plus last 1MB of combined output. Far above ctx.Truncate's ~24KB relevance
296// threshold (nothing the model would ever see is dropped), small enough that a
297// firehose command can't OOM the process.
298const (
299 bashOutputHead = 1 << 20
300 bashOutputTail = 1 << 20
301)
302
303// headTailBuffer is an io.Writer keeping the first bashOutputHead and the last
304// bashOutputTail bytes written, discarding the middle. The tail is a fixed ring
305// so a firehose costs a bounded copy, never an allocation per write.
306type headTailBuffer struct {
307 head []byte
308 ring []byte
309 pos int // next write index in ring
310 tailBytes int64 // total bytes routed to the ring
311}
312
313func (w *headTailBuffer) Write(p []byte) (int, error) {
314 n := len(p)
315 if room := bashOutputHead - len(w.head); room > 0 {
316 take := min(room, len(p))
317 w.head = append(w.head, p[:take]...)

Callers 1

InlineStatusFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected