Files
pipelines/app/tool/perf/chat_shown_fixture.dart
T
alan 059eb1bb0d Add show_diff chat tool and diff card
The Pipelines MCP server gains show_diff: it runs Git in a repository
inside the operator's home (default: the chat's directory) and records
the per-file patches. Without base it shows uncommitted work against
HEAD; with base it shows everything since the merge base (a pull
request preview), optionally committed changes only. Bounded at 300
files, 256 KiB per patch and 1 MiB total, with partial diffs labelled;
diff bodies share the per-chat retention budget with HTML views.

The chat draws the item as a card listing each changed file with its
stat; a row opens the existing file diff viewer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 17:08:02 +00:00

133 lines
4.7 KiB
Dart

// `?shown=1` (with `?chats=N&timestamps=1`, and `?files=1` so the files
// resolve to tool/capture/fixtures/files copied under capture-files/): the
// subscribe reply carries one of each Pipelines tool entry, after the last answer of the
// bench transcript's messages (perf-m0..19 at 09:00..09:19 UTC).
import 'package:pipelines_app/core/api_gateway.dart';
int _at(int minute, int second) =>
DateTime.utc(2026, 11, 5, 9, minute, second).millisecondsSinceEpoch;
const String _diagram = '''
<!doctype html><html><body style="margin:0;font:14px system-ui;background:#fff">
<svg viewBox="0 0 520 160" width="100%" height="150" role="img"
aria-label="Build, test and release stages">
<defs><marker id="a" markerWidth="8" markerHeight="8" refX="7" refY="4"
orient="auto"><path d="M0,0 L8,4 L0,8 z" fill="#555"/></marker></defs>
<g font-family="system-ui" font-size="14" text-anchor="middle">
<rect x="10" y="50" width="130" height="56" rx="10" fill="#e3f2fd" stroke="#1e88e5"/>
<text x="75" y="83">Build</text>
<rect x="195" y="50" width="130" height="56" rx="10" fill="#e8f5e9" stroke="#43a047"/>
<text x="260" y="83">Test</text>
<rect x="380" y="50" width="130" height="56" rx="10" fill="#fff3e0" stroke="#fb8c00"/>
<text x="445" y="83">Release</text>
<line x1="140" y1="78" x2="190" y2="78" stroke="#555" stroke-width="2" marker-end="url(#a)"/>
<line x1="325" y1="78" x2="375" y2="78" stroke="#555" stroke-width="2" marker-end="url(#a)"/>
</g></svg>
<details style="padding:0 12px"><summary>Stage timings</summary>
<p>Build 2m 10s · Test 4m 02s · Release 38s</p></details>
</body></html>''';
/// The retained entries the fixture's subscribe reply carries.
JsonMap chatShownFixture(Object? sessionId) => {
'session_id': sessionId,
'items': [
{
'id': 'shown-image',
'kind': 'file',
'created_at': _at(19, 10),
'title': 'Release design',
'path': '/srv/probe/release/design.png',
'name': 'design.png',
'size': 18432,
'mime': 'image/png',
},
{
'id': 'shown-doc',
'kind': 'file',
'created_at': _at(19, 20),
'path': '/srv/probe/release/release.md',
'name': 'release.md',
'size': 640,
'mime': 'text/markdown',
},
{
'id': 'shown-html',
'kind': 'html',
'created_at': _at(19, 30),
'title': 'Pipeline stages',
'html': _diagram,
'html_bytes': _diagram.length,
'height_hint': 220,
},
{
'id': 'shown-notify',
'kind': 'notify',
'created_at': _at(19, 40),
'title': 'Release ready',
'message': 'All three stages passed; the release is ready to publish.',
'priority': 'default',
'delivered': true,
},
{
'id': 'shown-diff',
'kind': 'diff',
'created_at': _at(19, 50),
'title': 'Pull request preview',
'diff_bytes': 612,
'diff': {
'repo': '/srv/probe/pipelines',
'base': 'main',
'base_commit': '79e51834a1b2',
'head': 'show-diff-tool',
'files': 3,
'additions': 7,
'deletions': 2,
'changes': {
'status': 'complete',
'skipped': 0,
'files': [
{
'path': 'internal/chattools/tools.go',
'kind': 'modified',
'patch':
'diff --git a/internal/chattools/tools.go b/internal/chattools/tools.go\n'
'--- a/internal/chattools/tools.go\n'
'+++ b/internal/chattools/tools.go\n'
'@@ -6,7 +6,8 @@ const (\n'
' \tToolShowFile = "show_file"\n'
' \tToolShowImage = "show_image"\n'
'-\tToolShowHTML = "show_html"\n'
'+\tToolShowHTML = "show_html"\n'
'+\tToolShowDiff = "show_diff"\n'
' \tToolNotify = "notify"\n'
' )\n',
},
{
'path': 'internal/server/chat_tools_diff.go',
'kind': 'added',
'patch':
'--- /dev/null\n'
'+++ b/internal/server/chat_tools_diff.go\n'
'@@ -0,0 +1,5 @@\n'
'+package server\n'
'+\n'
'+// runShowDiff compares a repository inside the operator\'s home\n'
'+// and records the per-file patches as one diff item.\n'
'+const showDiffMaxFiles = 300\n',
},
{
'path': 'docs/old-notes.md',
'kind': 'deleted',
'patch':
'--- a/docs/old-notes.md\n'
'+++ /dev/null\n'
'@@ -1,1 +0,0 @@\n'
'-Superseded notes.\n',
},
],
},
},
},
],
};