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

Function insertBlockAfterToolResults

src/utils/contentArray.ts:21–51  ·  view source on GitHub ↗
(
  content: unknown[],
  block: unknown,
)

Source from the content-addressed store, hash-verified

19 * @param block - The block to insert
20 */
21export function insertBlockAfterToolResults(
22 content: unknown[],
23 block: unknown,
24): void {
25 // Find position after the last tool_result block
26 let lastToolResultIndex = -1
27 for (let i = 0; i < content.length; i++) {
28 const item = content[i]
29 if (
30 item &&
31 typeof item === 'object' &&
32 'type' in item &&
33 (item as { type: string }).type === 'tool_result'
34 ) {
35 lastToolResultIndex = i
36 }
37 }
38
39 if (lastToolResultIndex >= 0) {
40 const insertPos = lastToolResultIndex + 1
41 content.splice(insertPos, 0, block)
42 // Append a text continuation if the inserted block is now last
43 if (insertPos === content.length - 1) {
44 content.push({ type: 'text', text: '.' })
45 }
46 } else {
47 // No tool_result blocks — insert before the last block
48 const insertIndex = Math.max(0, content.length - 1)
49 content.splice(insertIndex, 0, block)
50 }
51}
52

Callers 1

addCacheBreakpointsFunction · 0.85

Calls 3

spliceMethod · 0.80
maxMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected