MCPcopy Create free account
hub / github.com/anomalyco/opencode / derive

Function derive

packages/core/src/patch.ts:71–81  ·  view source on GitHub ↗
(path: string, chunks: ReadonlyArray<UpdateFileChunk>, original: string)

Source from the content-addressed store, hash-verified

69}
70
71export function derive(path: string, chunks: ReadonlyArray<UpdateFileChunk>, original: string): FileUpdate {
72 const source = splitBom(original)
73 const lines = source.text.split("\n")
74 if (lines.at(-1) === "") lines.pop()
75 const replacements = computeReplacements(lines, path, chunks)
76 const updated = [...lines]
77 for (const [start, remove, insert] of replacements.toReversed()) updated.splice(start, remove, ...insert)
78 if (updated.at(-1) !== "") updated.push("")
79 const next = splitBom(updated.join("\n"))
80 return { content: next.text, bom: source.bom || next.bom }
81}
82
83export function joinBom(text: string, bom: boolean) {
84 const stripped = splitBom(text).text

Callers

nothing calls this directly

Calls 4

atMethod · 0.80
pushMethod · 0.80
splitBomFunction · 0.70
computeReplacementsFunction · 0.70

Tested by

no test coverage detected