MCPcopy Index your code
hub / github.com/codeaashu/claude-code / applyHeadLimit

Function applyHeadLimit

src/tools/GrepTool/GrepTool.ts:110–128  ·  view source on GitHub ↗
(
  items: T[],
  limit: number | undefined,
  offset: number = 0,
)

Source from the content-addressed store, hash-verified

108const DEFAULT_HEAD_LIMIT = 250
109
110function applyHeadLimit<T>(
111 items: T[],
112 limit: number | undefined,
113 offset: number = 0,
114): { items: T[]; appliedLimit: number | undefined } {
115 // Explicit 0 = unlimited escape hatch
116 if (limit === 0) {
117 return { items: items.slice(offset), appliedLimit: undefined }
118 }
119 const effectiveLimit = limit ?? DEFAULT_HEAD_LIMIT
120 const sliced = items.slice(offset, offset + effectiveLimit)
121 // Only report appliedLimit when truncation actually occurred, so the model
122 // knows there may be more results and can paginate with offset.
123 const wasTruncated = items.length - offset > effectiveLimit
124 return {
125 items: sliced,
126 appliedLimit: wasTruncated ? effectiveLimit : undefined,
127 }
128}
129
130// Format limit/offset information for display in tool results.
131// appliedLimit is only set when truncation actually occurred (see applyHeadLimit),

Callers 1

callFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected