MCPcopy
hub / github.com/codeaashu/claude-code / mapToolResultToToolResultBlockParam

Function mapToolResultToToolResultBlockParam

src/tools/GrepTool/GrepTool.ts:254–309  ·  view source on GitHub ↗
(
    {
      mode = 'files_with_matches',
      numFiles,
      filenames,
      content,
      numLines: _numLines,
      numMatches,
      appliedLimit,
      appliedOffset,
    },
    toolUseID,
  )

Source from the content-addressed store, hash-verified

252 return filenames.join('\n')
253 },
254 mapToolResultToToolResultBlockParam(
255 {
256 mode = 'files_with_matches',
257 numFiles,
258 filenames,
259 content,
260 numLines: _numLines,
261 numMatches,
262 appliedLimit,
263 appliedOffset,
264 },
265 toolUseID,
266 ) {
267 if (mode === 'content') {
268 const limitInfo = formatLimitInfo(appliedLimit, appliedOffset)
269 const resultContent = content || 'No matches found'
270 const finalContent = limitInfo
271 ? `${resultContent}\n\n[Showing results with pagination = ${limitInfo}]`
272 : resultContent
273 return {
274 tool_use_id: toolUseID,
275 type: 'tool_result',
276 content: finalContent,
277 }
278 }
279
280 if (mode === 'count') {
281 const limitInfo = formatLimitInfo(appliedLimit, appliedOffset)
282 const rawContent = content || 'No matches found'
283 const matches = numMatches ?? 0
284 const files = numFiles ?? 0
285 const summary = `\n\nFound ${matches} total ${matches === 1 ? 'occurrence' : 'occurrences'} across ${files} ${files === 1 ? 'file' : 'files'}.${limitInfo ? ` with pagination = ${limitInfo}` : ''}`
286 return {
287 tool_use_id: toolUseID,
288 type: 'tool_result',
289 content: rawContent + summary,
290 }
291 }
292
293 // files_with_matches mode
294 const limitInfo = formatLimitInfo(appliedLimit, appliedOffset)
295 if (numFiles === 0) {
296 return {
297 tool_use_id: toolUseID,
298 type: 'tool_result',
299 content: 'No files found',
300 }
301 }
302 // head_limit has already been applied in call() method, so just show all filenames
303 const result = `Found ${numFiles} ${plural(numFiles, 'file')}${limitInfo ? ` ${limitInfo}` : ''}\n${filenames.join('\n')}`
304 return {
305 tool_use_id: toolUseID,
306 type: 'tool_result',
307 content: result,
308 }
309 },
310 async call(
311 {

Callers

nothing calls this directly

Calls 2

formatLimitInfoFunction · 0.85
pluralFunction · 0.85

Tested by

no test coverage detected