MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / buildEditDiffLines

Function buildEditDiffLines

apps/kimi-web/src/lib/toolDiff.ts:25–42  ·  view source on GitHub ↗
(tool: { name: string; arg: string })

Source from the content-addressed store, hash-verified

23 * (replace_all, append), or when the inputs are too large to diff cheaply.
24 */
25export function buildEditDiffLines(tool: { name: string; arg: string }): DiffViewLine[] | null {
26 const kind = normalizeToolName(tool.name);
27 if (kind !== 'edit' && kind !== 'write') return null;
28 const d = parseArg(tool.arg);
29 if (!d) return null;
30 if (kind === 'edit') {
31 if (d.replace_all === true) return null;
32 const before = typeof d.old_string === 'string' ? d.old_string : undefined;
33 const after = typeof d.new_string === 'string' ? d.new_string : undefined;
34 if (before === undefined || after === undefined) return null;
35 return buildDiffLines(before, after);
36 }
37 // Write only reports the new content (and whether it appended); the client
38 // cannot tell a new file from an overwrite of an existing one. A from-empty
39 // diff would show an overwrite as "all additions, no deletions", which is
40 // misleading — so fall back to the tool output for every Write.
41 return null;
42}
43
44/** Pull the file path out of an Edit/Write tool call's input, if present. */
45export function extractEditPath(arg: string): string | undefined {

Callers 2

lib-logic.test.tsFile · 0.90
useDetailPanelFunction · 0.90

Calls 3

normalizeToolNameFunction · 0.90
buildDiffLinesFunction · 0.90
parseArgFunction · 0.70

Tested by

no test coverage detected