Files
Memoh/internal/agent/tools/prune.go
Acbox c1e6e0cc7a feat(agent): add pagination and smart collapsing to container list tool
Large directories like node_modules/.venv could return thousands of entries,
wasting tokens and causing timeouts. Add offset/limit pagination to ListDir
RPC and collapse heavy subdirectories (>50 items) into summaries in recursive
mode. Collapsing runs at the bridge layer before pagination so the page window
reflects the collapsed view.
2026-04-02 01:51:19 +08:00

36 lines
823 B
Go

package tools
import (
textprune "github.com/memohai/memoh/internal/prune"
)
const (
toolOutputHeadBytes = 4 * 1024
toolOutputTailBytes = 1 * 1024
toolOutputHeadLines = 150
toolOutputTailLines = 50
readMaxLines = 200
readMaxBytes = 5120
readMaxLineLength = 1000
readHeadBytes = 3072
readTailBytes = 1024
readHeadLines = 120
readTailLines = 40
listMaxEntries = 200
listCollapseThreshold = 50
)
func pruneToolOutputText(text, label string) string {
return textprune.PruneWithEdges(text, label, textprune.Config{
MaxBytes: textprune.DefaultMaxBytes,
MaxLines: textprune.DefaultMaxLines,
HeadBytes: toolOutputHeadBytes,
TailBytes: toolOutputTailBytes,
HeadLines: toolOutputHeadLines,
TailLines: toolOutputTailLines,
Marker: textprune.DefaultMarker,
})
}