agy-git-graph 1.1.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/mcp/server.mjs DELETED
@@ -1,289 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { dirname, join, resolve } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- import { createHandlers } from '../sidecars/git_graph/lib/handlers.mjs';
5
- import { renderIndexHtml } from '../sidecars/git_graph/lib/render.mjs';
6
- import { discoverWorkspaces } from '../sidecars/git_graph/lib/workspaces.mjs';
7
-
8
- const __dirname = dirname(fileURLToPath(import.meta.url));
9
- const PLUGIN_ROOT = resolve(__dirname, '..');
10
- const APP_URI = 'ui://git-graph/app.html';
11
- const APP_MIME = 'text/html;profile=mcp-app';
12
-
13
- for (const stream of [process.stdout, process.stderr]) {
14
- stream.on('error', (error) => {
15
- if (error?.code !== 'EPIPE') throw error;
16
- });
17
- }
18
-
19
- function readPackageVersion() {
20
- try {
21
- const pkg = JSON.parse(readFileSync(join(PLUGIN_ROOT, 'package.json'), 'utf8'));
22
- if (typeof pkg?.version === 'string' && pkg.version.trim()) return pkg.version.trim();
23
- } catch {
24
- // Fallback below.
25
- }
26
- return '1.1.0';
27
- }
28
-
29
- const SERVER_VERSION = readPackageVersion();
30
- const handlers = createHandlers();
31
-
32
- const TOOLS = [
33
- {
34
- name: 'open_git_graph',
35
- title: 'Git Graph',
36
- description:
37
- 'Open the Git Graph view to inspect working-tree changes, stage/commit files, view diffs, and browse the multi-branch SVG commit graph.',
38
- inputSchema: {
39
- type: 'object',
40
- properties: {
41
- repoPath: {
42
- type: 'string',
43
- description: 'Optional local Git repository path to open.',
44
- },
45
- },
46
- additionalProperties: false,
47
- },
48
- _meta: {
49
- ui: { resourceUri: APP_URI },
50
- 'com.google.antigravity/ui': {
51
- entrypoints: [{ type: 'global', title: 'Git Graph' }],
52
- },
53
- },
54
- },
55
- {
56
- name: 'git_graph_rpc',
57
- title: 'Git Graph App RPC',
58
- description: 'App-only RPC bridge for Git Graph UI.',
59
- inputSchema: {
60
- type: 'object',
61
- properties: {
62
- route: { type: 'string' },
63
- payload: { type: 'object' },
64
- },
65
- required: ['route'],
66
- additionalProperties: false,
67
- },
68
- _meta: {
69
- ui: { visibility: ['app'] },
70
- },
71
- },
72
- ];
73
-
74
- const RESOURCES = [
75
- {
76
- uri: APP_URI,
77
- name: 'Git Graph',
78
- description: 'Interactive Git working-tree changes, diffs, and multi-branch SVG commit graph.',
79
- mimeType: APP_MIME,
80
- _meta: {
81
- ui: { prefersBorder: false },
82
- },
83
- },
84
- ];
85
-
86
- function sendMessage(msg) {
87
- try {
88
- process.stdout.write(JSON.stringify(msg) + '\n');
89
- } catch {
90
- // Ignore closed stdout during shutdown.
91
- }
92
- }
93
-
94
- function sendResult(id, result) {
95
- if (id === undefined || id === null) return;
96
- sendMessage({ jsonrpc: '2.0', id, result });
97
- }
98
-
99
- function sendError(id, code, message) {
100
- if (id === undefined || id === null) return;
101
- sendMessage({ jsonrpc: '2.0', id, error: { code, message: String(message || 'Internal error') } });
102
- }
103
-
104
- function readAppHtml() {
105
- const bridgePath = join(__dirname, 'ext-apps-bridge.js');
106
- const mcpBridgeScript = readFileSync(bridgePath, 'utf8');
107
- return renderIndexHtml({ mcpBridgeScript });
108
- }
109
-
110
- async function handleToolCall(params = {}) {
111
- const name = params?.name;
112
- const args = params?.arguments && typeof params.arguments === 'object' ? params.arguments : {};
113
-
114
- if (name === 'open_git_graph') {
115
- const { repos } = await discoverWorkspaces();
116
- const initialRepoPath = typeof args.repoPath === 'string' ? args.repoPath.trim() : '';
117
- const structuredContent = { ok: true, initialRepoPath, repos };
118
- return {
119
- content: [{ type: 'text', text: 'Opened Git Graph.' }],
120
- structuredContent,
121
- };
122
- }
123
-
124
- if (name === 'git_graph_rpc') {
125
- const route = typeof args.route === 'string' ? args.route.trim().replace(/^\/+/, '') : '';
126
- const apiRoute = '/api/' + route;
127
- if (!route || !Object.hasOwn(handlers, apiRoute)) {
128
- const msg = `Unknown Git Graph RPC route: ${route}`;
129
- return {
130
- isError: true,
131
- content: [{ type: 'text', text: msg }],
132
- structuredContent: { ok: false, error: msg },
133
- };
134
- }
135
- try {
136
- const payload = args.payload && typeof args.payload === 'object' ? args.payload : {};
137
- const result = await handlers[apiRoute](payload);
138
- return {
139
- content: [{ type: 'text', text: JSON.stringify(result) }],
140
- structuredContent: result,
141
- };
142
- } catch (error) {
143
- const msg = error?.message || String(error);
144
- return {
145
- isError: true,
146
- content: [{ type: 'text', text: msg }],
147
- structuredContent: { ok: false, error: msg },
148
- };
149
- }
150
- }
151
-
152
- return {
153
- isError: true,
154
- content: [{ type: 'text', text: `Unknown tool: ${name}` }],
155
- };
156
- }
157
-
158
- async function dispatch(msg) {
159
- if (!msg || typeof msg !== 'object') {
160
- sendError(null, -32600, 'Invalid Request');
161
- return;
162
- }
163
- const { id, method, params } = msg;
164
- const isNotification = id === undefined || id === null;
165
-
166
- if (typeof method !== 'string') {
167
- if (!isNotification) sendError(id, -32600, 'Invalid Request');
168
- return;
169
- }
170
-
171
- if (method === 'notifications/initialized' || method === 'notifications/cancelled') {
172
- return;
173
- }
174
-
175
- try {
176
- switch (method) {
177
- case 'initialize': {
178
- const protocolVersion = typeof params?.protocolVersion === 'string' && params.protocolVersion
179
- ? params.protocolVersion
180
- : '2025-03-26';
181
- sendResult(id, {
182
- protocolVersion,
183
- capabilities: {
184
- tools: { listChanged: false },
185
- resources: { subscribe: false, listChanged: false },
186
- },
187
- serverInfo: {
188
- name: 'agy-git-graph_git_graph',
189
- version: SERVER_VERSION,
190
- },
191
- });
192
- return;
193
- }
194
- case 'ping':
195
- sendResult(id, {});
196
- return;
197
- case 'tools/list':
198
- sendResult(id, { tools: TOOLS });
199
- return;
200
- case 'tools/call':
201
- sendResult(id, await handleToolCall(params));
202
- return;
203
- case 'resources/list':
204
- sendResult(id, { resources: RESOURCES });
205
- return;
206
- case 'resources/templates/list':
207
- sendResult(id, { resourceTemplates: [] });
208
- return;
209
- case 'resources/read': {
210
- if (params?.uri !== APP_URI) {
211
- sendError(id, -32602, `Resource not found: ${params?.uri || ''}`);
212
- return;
213
- }
214
- sendResult(id, {
215
- contents: [
216
- {
217
- uri: APP_URI,
218
- mimeType: APP_MIME,
219
- text: readAppHtml(),
220
- },
221
- ],
222
- });
223
- return;
224
- }
225
- default:
226
- if (!isNotification) sendError(id, -32601, `Method not found: ${method}`);
227
- }
228
- } catch (error) {
229
- if (!isNotification) sendError(id, -32603, error?.message || 'Internal error');
230
- }
231
- }
232
-
233
- export function startStdioServer() {
234
- const inFlight = new Set();
235
- let closing = false;
236
-
237
- const track = (parsed) => {
238
- if (closing) return;
239
- const task = dispatch(parsed).catch((error) => {
240
- sendError(parsed?.id, -32603, error?.message || 'Internal error');
241
- });
242
- inFlight.add(task);
243
- task.finally(() => inFlight.delete(task));
244
- };
245
-
246
- let buffer = '';
247
- process.stdin.setEncoding('utf8');
248
- process.stdin.on('data', (chunk) => {
249
- buffer += chunk;
250
- const lines = buffer.split(/\r?\n/);
251
- buffer = lines.pop() ?? '';
252
- for (const rawLine of lines) {
253
- const line = rawLine.trim();
254
- if (!line) continue;
255
- try {
256
- track(JSON.parse(line));
257
- } catch {
258
- sendError(null, -32700, 'Parse error');
259
- }
260
- }
261
- });
262
-
263
- const shutdown = async () => {
264
- if (closing) return;
265
- closing = true;
266
- await Promise.allSettled([...inFlight]);
267
- process.exit(0);
268
- };
269
-
270
- process.stdin.on('end', () => {
271
- const trailing = buffer.trim();
272
- if (trailing) {
273
- try {
274
- track(JSON.parse(trailing));
275
- } catch {
276
- sendError(null, -32700, 'Parse error');
277
- }
278
- }
279
- void shutdown();
280
- });
281
-
282
- process.once('SIGINT', () => void shutdown());
283
- process.once('SIGTERM', () => void shutdown());
284
- }
285
-
286
- const isMain = process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url));
287
- if (isMain) {
288
- startStdioServer();
289
- }
package/mcp_config.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "mcpServers": {
3
- "git_graph": {
4
- "command": "node",
5
- "args": ["${PLUGIN_ROOT}/mcp/server.mjs", "--data-dir", "${PLUGIN_DATA}"]
6
- }
7
- }
8
- }