mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
c1e6e0cc7a
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.
36 lines
823 B
Go
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,
|
|
})
|
|
}
|