feat(#2196): move Write/Edit diff body to backend, drop JS branch
- fmt_builtin_tool: Edit gets its own arm computing `-N +M` line counts
in _summary (was shared with Read/Write as bare file-path).
- is_rich_tool: drop Write (content is huge/one-sided; flat _summary row
is correct); Edit stays rich since it has an old/new diff.
- rich_tool_body: now returns Option<(String, &'static str)> where the
second field is the body type ('diff' or 'plain'). Edit arm builds the
'-'/'+ ' prefixed diff body; mcp__bash__run gets type 'plain'.
- enrich_tool_use_entry: stamps both _body and _body_type.
Frontend (app.js):
- Remove the Write/Edit branch from renderRichToolUse (~25 lines).
- Generic _body path now dispatches on _body_type: 'diff' ->
api.detailsDiff (colour-coded spans), default -> api.details.
No tool-specific JS remains for file diff rendering.
This commit is contained in:
parent
da056d0043
commit
0e4b69dd20
2 changed files with 64 additions and 43 deletions
|
|
@ -1483,33 +1483,6 @@ window.marked = marked;
|
|||
const name = c.name || '';
|
||||
const input = c.input || {};
|
||||
const icon = c._icon || '🔧';
|
||||
if (name === 'Write' || name === 'Edit') {
|
||||
const path = input.file_path || '?';
|
||||
let body;
|
||||
let plus = 0;
|
||||
let minus = 0;
|
||||
if (name === 'Write') {
|
||||
const content = String(input.content || '');
|
||||
const lines = content.split('\n');
|
||||
plus = lines.length;
|
||||
body = lines.map(l => '+ ' + l).join('\n');
|
||||
} else {
|
||||
const oldLines = String(input.old_string || '').split('\n');
|
||||
const newLines = String(input.new_string || '').split('\n');
|
||||
minus = oldLines.length;
|
||||
plus = newLines.length;
|
||||
body = oldLines.map(l => '- ' + l).join('\n')
|
||||
+ '\n'
|
||||
+ newLines.map(l => '+ ' + l).join('\n');
|
||||
}
|
||||
// The tool icon goes in the shared `.row-glyph` cell (4th arg) so it
|
||||
// lines up with flat-row icons; the summary text carries no
|
||||
// directional `→` (the row's cyan colour signals "outbound tool" and
|
||||
// the CSS disclosure caret leads the text).
|
||||
const summary = name + ' ' + path + ' · '
|
||||
+ (minus ? '-' + minus + ' ' : '') + '+' + plus;
|
||||
return api.detailsDiff('tool-use', summary, body, icon);
|
||||
}
|
||||
// Message-bearing tools render default-open with a markdown body so
|
||||
// the operator sees the content without an extra click. send / ask
|
||||
// address a target; answer attaches to an existing question id.
|
||||
|
|
@ -1559,11 +1532,15 @@ window.marked = marked;
|
|||
'answer #' + id + (lines > 1 ? ` · ${lines}L` : ''),
|
||||
a, icon);
|
||||
}
|
||||
// Generic plain-text body: the backend stamps `_body` for tools whose
|
||||
// expandable content is plain text (e.g. mcp__bash__run full command).
|
||||
// Render as a collapsible details row without any tool-specific logic.
|
||||
if (c._body) {
|
||||
return api.details('tool-use', c._summary || name || '?', c._body, icon);
|
||||
// Generic backend-computed body: the backend stamps `_body` + `_body_type`
|
||||
// for tools whose expandable content is pre-computable (Edit diff,
|
||||
// mcp__bash__run command). Dispatch on type — no tool-specific JS needed.
|
||||
if (c._body != null) {
|
||||
const summary = c._summary || name || '?';
|
||||
if (c._body_type === 'diff') {
|
||||
return api.detailsDiff('tool-use', summary, c._body, icon);
|
||||
}
|
||||
return api.details('tool-use', summary, c._body, icon);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue