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

Function toolChip

apps/kimi-web/src/lib/toolMeta.ts:257–309  ·  view source on GitHub ↗
(tool: ToolChipInput)

Source from the content-addressed store, hash-verified

255}
256
257export function toolChip(tool: ToolChipInput): string {
258 try {
259 switch (normalizeToolName(tool.name)) {
260 case 'bash': {
261 // Prefer timing if present
262 if (tool.timing) return tool.timing;
263 return '';
264 }
265 case 'read': {
266 // Count output lines
267 if (tool.output && tool.output.length > 0) {
268 const count = tool.output.length;
269 return t('tools.chip.lines', { count });
270 }
271 return '';
272 }
273 case 'edit':
274 case 'multi_edit':
275 case 'write': {
276 // Try to parse +A −B from output (unified diff summary)
277 if (tool.output) {
278 for (const line of tool.output) {
279 const m = line.match(/\+(\d+).*[-−](\d+)/);
280 if (m) return `+${m[1]} −${m[2]}`;
281 }
282 // Also check for simple "N lines" style
283 const summary = tool.output.find(l => /\d+/.test(l));
284 if (summary) {
285 const addMatch = summary.match(/\+(\d+)/);
286 const remMatch = summary.match(/[-−](\d+)/);
287 if (addMatch || remMatch) {
288 return `${addMatch ? `+${addMatch[1]}` : ''} ${remMatch ? `−${remMatch[1]}` : ''}`.trim();
289 }
290 }
291 // Succeeded but no diff counts available → just signal "edited".
292 if (tool.status !== 'error') return t('tools.chip.edited');
293 }
294 return '';
295 }
296 case 'grep':
297 case 'search': {
298 if (tool.output && tool.output.length > 0) {
299 return t('tools.chip.results', { count: tool.output.length });
300 }
301 return '';
302 }
303 default:
304 return '';
305 }
306 } catch {
307 return '';
308 }
309}

Callers

nothing calls this directly

Calls 1

normalizeToolNameFunction · 0.85

Tested by

no test coverage detected