MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / applyChunksToContent

Function applyChunksToContent

src/core/tools/apply-patch/apply.ts:123–142  ·  view source on GitHub ↗
(originalContent: string, filePath: string, chunks: UpdateFileChunk[])

Source from the content-addressed store, hash-verified

121 * @returns The new file content
122 */
123export function applyChunksToContent(originalContent: string, filePath: string, chunks: UpdateFileChunk[]): string {
124 // Split content into lines
125 let originalLines = originalContent.split("\n")
126
127 // Drop trailing empty element that results from final newline
128 // so that line counts match standard diff behavior
129 if (originalLines.length > 0 && originalLines[originalLines.length - 1] === "") {
130 originalLines = originalLines.slice(0, -1)
131 }
132
133 const replacements = computeReplacements(originalLines, filePath, chunks)
134 let newLines = applyReplacements(originalLines, replacements)
135
136 // Ensure file ends with newline
137 if (newLines.length === 0 || newLines[newLines.length - 1] !== "") {
138 newLines = [...newLines, ""]
139 }
140
141 return newLines.join("\n")
142}
143
144/**
145 * Process a single hunk and return the file change.

Callers 2

apply.spec.tsFile · 0.90
processHunkFunction · 0.85

Calls 2

computeReplacementsFunction · 0.85
applyReplacementsFunction · 0.85

Tested by

no test coverage detected