starmux 0.12.0 → 0.13.0

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.
Files changed (93) hide show
  1. package/dist/src/cli/mac-mcp-gateway.js +4 -3
  2. package/dist/src/cli/mac-mcp-gateway.js.map +1 -1
  3. package/dist/src/cli/starmux.js +1 -1
  4. package/dist/src/cli/starmux.js.map +1 -1
  5. package/dist/src/runtime-paths.js +3 -3
  6. package/dist/src/runtime-paths.js.map +1 -1
  7. package/dist/vendor/desktop-commander/LICENSE +21 -0
  8. package/dist/vendor/desktop-commander/dist/bootstrap.js +22 -0
  9. package/dist/vendor/desktop-commander/dist/command-manager.js +246 -0
  10. package/dist/vendor/desktop-commander/dist/config-field-definitions.js +37 -0
  11. package/dist/vendor/desktop-commander/dist/config-manager.js +634 -0
  12. package/dist/vendor/desktop-commander/dist/config-recovery.js +81 -0
  13. package/dist/vendor/desktop-commander/dist/config.js +19 -0
  14. package/dist/vendor/desktop-commander/dist/custom-stdio.js +358 -0
  15. package/dist/vendor/desktop-commander/dist/error-handlers.js +15 -0
  16. package/dist/vendor/desktop-commander/dist/handlers/edit-search-handlers.js +6 -0
  17. package/dist/vendor/desktop-commander/dist/handlers/filesystem-handlers.js +450 -0
  18. package/dist/vendor/desktop-commander/dist/handlers/history-handlers.js +67 -0
  19. package/dist/vendor/desktop-commander/dist/handlers/index.js +7 -0
  20. package/dist/vendor/desktop-commander/dist/handlers/process-handlers.js +15 -0
  21. package/dist/vendor/desktop-commander/dist/handlers/search-answers.js +172 -0
  22. package/dist/vendor/desktop-commander/dist/handlers/search-handlers.js +136 -0
  23. package/dist/vendor/desktop-commander/dist/handlers/terminal-handlers.js +35 -0
  24. package/dist/vendor/desktop-commander/dist/index.js +88 -0
  25. package/dist/vendor/desktop-commander/dist/search-manager.js +1262 -0
  26. package/dist/vendor/desktop-commander/dist/server.js +1414 -0
  27. package/dist/vendor/desktop-commander/dist/terminal-manager.js +757 -0
  28. package/dist/vendor/desktop-commander/dist/tools/config.js +211 -0
  29. package/dist/vendor/desktop-commander/dist/tools/edit.js +455 -0
  30. package/dist/vendor/desktop-commander/dist/tools/feedback.js +10 -0
  31. package/dist/vendor/desktop-commander/dist/tools/filesystem.js +1047 -0
  32. package/dist/vendor/desktop-commander/dist/tools/fuzzySearch.js +74 -0
  33. package/dist/vendor/desktop-commander/dist/tools/fuzzySearchCore.js +125 -0
  34. package/dist/vendor/desktop-commander/dist/tools/improved-process-tools.js +726 -0
  35. package/dist/vendor/desktop-commander/dist/tools/mime-types.js +28 -0
  36. package/dist/vendor/desktop-commander/dist/tools/pdf/extract-images.js +131 -0
  37. package/dist/vendor/desktop-commander/dist/tools/pdf/index.js +4 -0
  38. package/dist/vendor/desktop-commander/dist/tools/pdf/lib/pdf2md.js +78 -0
  39. package/dist/vendor/desktop-commander/dist/tools/pdf/manipulations.js +112 -0
  40. package/dist/vendor/desktop-commander/dist/tools/pdf/markdown.js +30 -0
  41. package/dist/vendor/desktop-commander/dist/tools/pdf/utils.js +45 -0
  42. package/dist/vendor/desktop-commander/dist/tools/process.js +90 -0
  43. package/dist/vendor/desktop-commander/dist/tools/prompts.js +259 -0
  44. package/dist/vendor/desktop-commander/dist/tools/schemas.js +242 -0
  45. package/dist/vendor/desktop-commander/dist/tools/usage.js +24 -0
  46. package/dist/vendor/desktop-commander/dist/types.js +1 -0
  47. package/dist/vendor/desktop-commander/dist/ui/config-editor/config-editor-runtime.js +150 -0
  48. package/dist/vendor/desktop-commander/dist/ui/config-editor/index.html +13 -0
  49. package/dist/vendor/desktop-commander/dist/ui/config-editor/styles.css +587 -0
  50. package/dist/vendor/desktop-commander/dist/ui/contracts.js +57 -0
  51. package/dist/vendor/desktop-commander/dist/ui/file-preview/index.html +16 -0
  52. package/dist/vendor/desktop-commander/dist/ui/file-preview/preview-runtime.js +471 -0
  53. package/dist/vendor/desktop-commander/dist/ui/file-preview/shared/preview-file-types.js +59 -0
  54. package/dist/vendor/desktop-commander/dist/ui/file-preview/styles.css +1631 -0
  55. package/dist/vendor/desktop-commander/dist/ui/resources.js +93 -0
  56. package/dist/vendor/desktop-commander/dist/utils/ab-test.js +122 -0
  57. package/dist/vendor/desktop-commander/dist/utils/atomic-write.js +80 -0
  58. package/dist/vendor/desktop-commander/dist/utils/capture.js +40 -0
  59. package/dist/vendor/desktop-commander/dist/utils/dockerPrompt.js +9 -0
  60. package/dist/vendor/desktop-commander/dist/utils/exit-process.js +31 -0
  61. package/dist/vendor/desktop-commander/dist/utils/feature-flags.js +18 -0
  62. package/dist/vendor/desktop-commander/dist/utils/files/base.js +5 -0
  63. package/dist/vendor/desktop-commander/dist/utils/files/binary.js +65 -0
  64. package/dist/vendor/desktop-commander/dist/utils/files/docx.js +694 -0
  65. package/dist/vendor/desktop-commander/dist/utils/files/excel.js +497 -0
  66. package/dist/vendor/desktop-commander/dist/utils/files/factory.js +168 -0
  67. package/dist/vendor/desktop-commander/dist/utils/files/image.js +89 -0
  68. package/dist/vendor/desktop-commander/dist/utils/files/index.js +14 -0
  69. package/dist/vendor/desktop-commander/dist/utils/files/pdf.js +124 -0
  70. package/dist/vendor/desktop-commander/dist/utils/files/text.js +423 -0
  71. package/dist/vendor/desktop-commander/dist/utils/fuzzySearchLogger.js +126 -0
  72. package/dist/vendor/desktop-commander/dist/utils/internal-facts.js +23 -0
  73. package/dist/vendor/desktop-commander/dist/utils/lazy-package.js +44 -0
  74. package/dist/vendor/desktop-commander/dist/utils/lineEndingHandler.js +77 -0
  75. package/dist/vendor/desktop-commander/dist/utils/logger.js +72 -0
  76. package/dist/vendor/desktop-commander/dist/utils/mcp-ui-ab-test.js +62 -0
  77. package/dist/vendor/desktop-commander/dist/utils/open-browser.js +2 -0
  78. package/dist/vendor/desktop-commander/dist/utils/process-detection.js +260 -0
  79. package/dist/vendor/desktop-commander/dist/utils/process-tree.js +223 -0
  80. package/dist/vendor/desktop-commander/dist/utils/rename.js +74 -0
  81. package/dist/vendor/desktop-commander/dist/utils/ripgrep-resolver.js +69 -0
  82. package/dist/vendor/desktop-commander/dist/utils/shell.js +187 -0
  83. package/dist/vendor/desktop-commander/dist/utils/system-info.js +727 -0
  84. package/dist/vendor/desktop-commander/dist/utils/terminal-timestamps.js +18 -0
  85. package/dist/vendor/desktop-commander/dist/utils/toolHistory.js +309 -0
  86. package/dist/vendor/desktop-commander/dist/utils/trackTools.js +55 -0
  87. package/dist/vendor/desktop-commander/dist/utils/unsupportedParams.js +66 -0
  88. package/dist/vendor/desktop-commander/dist/utils/usageTracker.js +225 -0
  89. package/dist/vendor/desktop-commander/dist/utils/welcome-onboarding.js +2 -0
  90. package/dist/vendor/desktop-commander/dist/utils/withTimeout.js +85 -0
  91. package/dist/vendor/desktop-commander/dist/version.js +1 -0
  92. package/dist/vendor/desktop-commander/package.json +15 -0
  93. package/package.json +14 -2
@@ -0,0 +1,450 @@
1
+ import { readFile, readMultipleFiles, writeFile, createDirectory, listDirectory, moveFile, getFileInfo, writePdf, getDefaultEditorMetadata } from '../tools/filesystem.js';
2
+ import { TextFileHandler } from '../utils/files/text.js';
3
+ import { withTimeout } from '../utils/withTimeout.js';
4
+ import { createErrorResponse } from '../error-handlers.js';
5
+ import { configManager } from '../config-manager.js';
6
+ import { ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, GetFileInfoArgsSchema, WritePdfArgsSchema } from '../tools/schemas.js';
7
+ import path from 'path';
8
+ import os from 'os';
9
+ import { resolvePreviewFileType } from '../ui/file-preview/shared/preview-file-types.js';
10
+ /**
11
+ * Expand home directory (~) in a file path
12
+ */
13
+ function expandHome(filePath) {
14
+ if (filePath === '~' || filePath.startsWith('~/') || filePath.startsWith(`~${path.sep}`)) {
15
+ return path.join(os.homedir(), filePath.slice(1));
16
+ }
17
+ return filePath;
18
+ }
19
+ /**
20
+ * Resolve a file path to an absolute path for use in structured content.
21
+ * This ensures "Open in folder" always has a valid absolute path.
22
+ */
23
+ export function resolveAbsolutePath(filePath) {
24
+ const expanded = expandHome(filePath);
25
+ return path.isAbsolute(expanded)
26
+ ? path.resolve(expanded)
27
+ : path.resolve(process.cwd(), expanded);
28
+ }
29
+ /**
30
+ * Helper function to check if path contains an error
31
+ */
32
+ function isErrorPath(filePath) {
33
+ return filePath.startsWith('__ERROR__:');
34
+ }
35
+ /**
36
+ * Extract error message from error path
37
+ */
38
+ function getErrorFromPath(path) {
39
+ return path.substring('__ERROR__:'.length).trim();
40
+ }
41
+ /**
42
+ * Handle read_file command
43
+ */
44
+ export async function handleReadFile(args) {
45
+ // Backstop for the whole handler operation. The real control is the
46
+ // 3-minute cancellable read timeout inside readFileFromDisk; this sits just
47
+ // above it (so that one fires first, with cleanup + a useful error) but
48
+ // still below the MCP client's ~4-minute hard cap, so we never leave the
49
+ // client hanging on an opaque timeout.
50
+ const HANDLER_TIMEOUT = 3.5 * 60 * 1000; // 3m30s
51
+ // Add input validation
52
+ if (args === null || args === undefined) {
53
+ return createErrorResponse('No arguments provided for read_file command');
54
+ }
55
+ const readFileOperation = async () => {
56
+ const parsed = ReadFileArgsSchema.parse(args);
57
+ // Get the configuration for file read limits
58
+ const config = await configManager.getConfig();
59
+ if (!config) {
60
+ return createErrorResponse('Configuration not available');
61
+ }
62
+ // The schema fills in `length: 1000` (the default tools/list shows), so
63
+ // whether the caller sent a length is read from the raw arguments: an
64
+ // omitted length follows the fileReadLineLimit setting, as documented.
65
+ const defaultLimit = config.fileReadLineLimit ?? 1000;
66
+ const lengthGiven = args.length !== undefined;
67
+ // The sheet goes as given: the Excel handler knows the sheet names, so it
68
+ // decides whether "2024" is an index or a sheet named 2024
69
+ const options = {
70
+ isUrl: parsed.isUrl,
71
+ offset: parsed.offset ?? 0,
72
+ length: lengthGiven ? parsed.length : defaultLimit,
73
+ sheet: parsed.sheet,
74
+ range: parsed.range,
75
+ // The preview widget draws an SVG as an image (ui/file-preview/src/image-preview.ts);
76
+ // everyone else reads it as the text it is
77
+ svgAsImage: parsed.origin === 'ui'
78
+ };
79
+ // Resolve to absolute path for local files (not URLs) so "Open in folder" works
80
+ const resolvedFilePath = parsed.isUrl
81
+ ? parsed.path
82
+ : resolveAbsolutePath(parsed.path);
83
+ const fileResult = await readFile(parsed.path, options);
84
+ // Handle PDF files
85
+ if (fileResult.metadata?.isPdf) {
86
+ const meta = fileResult.metadata;
87
+ const author = meta?.author ? `, Author: ${meta?.author}` : "";
88
+ const title = meta?.title ? `, Title: ${meta?.title}` : "";
89
+ const pdfContent = fileResult.metadata?.pages?.flatMap((p) => [
90
+ ...(p.images?.map((image) => ({
91
+ type: "image",
92
+ data: image.data,
93
+ mimeType: image.mimeType
94
+ })) ?? []),
95
+ {
96
+ type: "text",
97
+ text: `<!-- Page: ${p.pageNumber} -->\n${p.text}`,
98
+ },
99
+ ]) ?? [];
100
+ return {
101
+ content: [
102
+ {
103
+ type: "text",
104
+ text: `PDF file: ${parsed.path}${author}${title} (${meta?.totalPages} pages) \n`
105
+ },
106
+ ...pdfContent
107
+ ],
108
+ ...(parsed.origin === 'ui' ? {
109
+ structuredContent: {
110
+ fileName: path.basename(resolvedFilePath),
111
+ filePath: resolvedFilePath,
112
+ fileType: 'unsupported',
113
+ ...await getDefaultEditorMetadata(resolvedFilePath),
114
+ },
115
+ } : {}),
116
+ };
117
+ }
118
+ // Handle image files
119
+ if (fileResult.metadata?.isImage) {
120
+ // Return the image bytes in the MCP content array so the host model can
121
+ // actually see the image. The preview widget gets its copy from its own
122
+ // origin:'ui' read — structuredContent stays metadata-only.
123
+ const imageData = typeof fileResult.content === 'string'
124
+ ? fileResult.content
125
+ : fileResult.content.toString('base64');
126
+ const imageSummary = `Image file: ${parsed.path} (${fileResult.mimeType})\n`;
127
+ const imageStructuredContent = {
128
+ fileName: path.basename(resolvedFilePath),
129
+ filePath: resolvedFilePath,
130
+ fileType: 'image',
131
+ ...await getDefaultEditorMetadata(resolvedFilePath),
132
+ mimeType: fileResult.mimeType,
133
+ };
134
+ // Widget pull (origin: 'ui'): return the base64 in a TEXT block, never
135
+ // an image block. An image content block makes the host inline-vision-
136
+ // render the result, which preempts delivery of this RPC response to
137
+ // the widget — leaving the preview stuck on "Preparing preview…" for
138
+ // exactly the host-rendered types (png/jpeg/gif/webp). Text-only lets
139
+ // the RPC response through so the widget can draw the <img>.
140
+ if (parsed.origin === 'ui') {
141
+ return {
142
+ content: [{ type: "text", text: imageData }],
143
+ structuredContent: imageStructuredContent,
144
+ };
145
+ }
146
+ // Model-facing read: keep the image block so the host/model sees it.
147
+ // No structuredContent — the widget renders from its own origin:'ui'
148
+ // read, and nothing else consumes it.
149
+ return {
150
+ content: [
151
+ {
152
+ type: "text",
153
+ text: imageSummary
154
+ },
155
+ {
156
+ type: "image",
157
+ data: imageData,
158
+ mimeType: fileResult.mimeType
159
+ }
160
+ ],
161
+ };
162
+ }
163
+ else {
164
+ // For all other files, return as text.
165
+ // structuredContent carries only file metadata (no content duplication);
166
+ // the widget reads text from the MCP content array (over the RPC read).
167
+ let textContent = typeof fileResult.content === 'string'
168
+ ? fileResult.content
169
+ : fileResult.content.toString('utf8');
170
+ const fileType = fileResult.metadata?.isDirectory ? 'directory' : resolvePreviewFileType(resolvedFilePath);
171
+ // The directory fallback prefixes a "use list_directory instead" hint
172
+ // for the LLM. The widget's own read (a list_directory preview pulls
173
+ // read_file on the dir path) would render that hint as a notice — strip it.
174
+ if (parsed.origin === 'ui' && fileType === 'directory') {
175
+ textContent = textContent.replace(/^This is a directory, not a file\.[^\n]*\n+/, '');
176
+ }
177
+ return {
178
+ content: [{ type: "text", text: textContent }],
179
+ ...(parsed.origin === 'ui' ? {
180
+ structuredContent: {
181
+ fileName: path.basename(resolvedFilePath),
182
+ filePath: resolvedFilePath,
183
+ fileType,
184
+ ...await getDefaultEditorMetadata(resolvedFilePath),
185
+ },
186
+ } : {}),
187
+ };
188
+ }
189
+ };
190
+ // Execute with timeout at the handler level
191
+ const result = await withTimeout(readFileOperation(), HANDLER_TIMEOUT, 'Read file handler operation', null);
192
+ if (result == null) {
193
+ // Handles the impossible case where withTimeout resolves to null instead of throwing
194
+ throw new Error('Failed to read the file');
195
+ }
196
+ return result;
197
+ }
198
+ /**
199
+ * Handle read_multiple_files command
200
+ */
201
+ export async function handleReadMultipleFiles(args, stillLoadingError) {
202
+ const parsed = ReadMultipleFilesArgsSchema.parse(args);
203
+ const fileResults = await readMultipleFiles(parsed.paths, stillLoadingError);
204
+ // Create a text summary of all files
205
+ const textSummary = fileResults.map(result => {
206
+ if (result.error) {
207
+ return `${result.path}: Error - ${result.error}`;
208
+ }
209
+ else if (result.isPdf) {
210
+ return `${result.path}: PDF file with ${result.payload?.pages?.length} pages`;
211
+ }
212
+ else if (result.mimeType) {
213
+ return `${result.path}: ${result.mimeType} ${result.isImage ? '(image)' : '(text)'}`;
214
+ }
215
+ else {
216
+ return `${result.path}: Unknown type`;
217
+ }
218
+ }).join("\n");
219
+ // Create content items for each file
220
+ const contentItems = [];
221
+ // Add the text summary
222
+ contentItems.push({ type: "text", text: textSummary });
223
+ // Add each file content after its path: several images, or a PDF's pages,
224
+ // can't be told apart by their order alone
225
+ for (const result of fileResults) {
226
+ if (!result.error && result.content !== undefined) {
227
+ const header = `\n--- ${result.path} contents: ---\n`;
228
+ if (result.isPdf) {
229
+ contentItems.push({ type: "text", text: header });
230
+ result.payload?.pages.forEach((page, i) => {
231
+ page.images.forEach((image, i) => {
232
+ contentItems.push({
233
+ type: "image",
234
+ data: image.data,
235
+ mimeType: image.mimeType
236
+ });
237
+ });
238
+ contentItems.push({
239
+ type: "text",
240
+ text: page.text,
241
+ });
242
+ });
243
+ }
244
+ else if (result.isImage && result.mimeType) {
245
+ // For image files, add an image content item
246
+ contentItems.push({ type: "text", text: header });
247
+ contentItems.push({
248
+ type: "image",
249
+ data: result.content,
250
+ mimeType: result.mimeType
251
+ });
252
+ }
253
+ else {
254
+ // For text files, add a text summary
255
+ contentItems.push({
256
+ type: "text",
257
+ text: `${header}${result.content}`
258
+ });
259
+ }
260
+ }
261
+ }
262
+ return { content: contentItems };
263
+ }
264
+ /**
265
+ * Handle write_file command
266
+ */
267
+ export async function handleWriteFile(args) {
268
+ try {
269
+ const modeProvided = !!(args && typeof args === 'object' && 'mode' in args);
270
+ const parsed = WriteFileArgsSchema.parse(args);
271
+ // An omitted `mode` falls back to 'rewrite', which silently destroys
272
+ // the target's existing content. The common failure is an LLM caller
273
+ // intending to append but dropping the optional param (issue #541), so
274
+ // require explicit intent when the target already has content;
275
+ // new/empty files keep the zero-friction default.
276
+ if (!modeProvided) {
277
+ let existing = null;
278
+ try {
279
+ existing = await getFileInfo(parsed.path);
280
+ }
281
+ catch {
282
+ // Missing file or invalid path — nothing to protect; the write
283
+ // itself will surface any real path error.
284
+ }
285
+ if (existing?.isFile && existing.size > 0) {
286
+ return createErrorResponse(`Write rejected to prevent accidental data loss: ${parsed.path} already exists ` +
287
+ `with content (${existing.size} bytes), and no 'mode' was specified — the default ` +
288
+ `mode 'rewrite' would REPLACE the entire file. Retry with an explicit mode: ` +
289
+ `'append' to add your content to the end of the existing file, or 'rewrite' ` +
290
+ `to replace all existing content.`);
291
+ }
292
+ }
293
+ // Get the line limit from configuration
294
+ const config = await configManager.getConfig();
295
+ const MAX_LINES = config.fileWriteLineLimit ?? 50; // Default to 50 if not set
296
+ // Lines as read_file counts them: a final line break doesn't start another line
297
+ const lineCount = TextFileHandler.countLines(parsed.content);
298
+ let errorMessage = "";
299
+ if (lineCount > MAX_LINES) {
300
+ errorMessage = `✅ File written successfully! (${lineCount} lines)
301
+
302
+ 💡 Performance tip: For optimal speed, consider chunking files into ≤30 line pieces in future operations.`;
303
+ }
304
+ // Pass the mode parameter to writeFile
305
+ await writeFile(parsed.path, parsed.content, parsed.mode);
306
+ // Provide more informative message based on mode
307
+ const modeMessage = parsed.mode === 'append' ? 'appended to' : 'wrote to';
308
+ // No structuredContent: nothing in the UI calls write_file (the widget
309
+ // previews the write via its own read_file pull at tool-result time).
310
+ return {
311
+ content: [{
312
+ type: "text",
313
+ text: `Successfully ${modeMessage} ${parsed.path} (${lineCount} lines) ${errorMessage}`
314
+ }],
315
+ };
316
+ }
317
+ catch (error) {
318
+ const errorMessage = error instanceof Error ? error.message : String(error);
319
+ return createErrorResponse(errorMessage);
320
+ }
321
+ }
322
+ /**
323
+ * Handle create_directory command
324
+ */
325
+ export async function handleCreateDirectory(args) {
326
+ try {
327
+ const parsed = CreateDirectoryArgsSchema.parse(args);
328
+ await createDirectory(parsed.path);
329
+ return {
330
+ content: [{ type: "text", text: `Successfully created directory ${parsed.path}` }],
331
+ };
332
+ }
333
+ catch (error) {
334
+ const errorMessage = error instanceof Error ? error.message : String(error);
335
+ return createErrorResponse(errorMessage);
336
+ }
337
+ }
338
+ /**
339
+ * Handle list_directory command
340
+ */
341
+ export async function handleListDirectory(args) {
342
+ try {
343
+ const startTime = Date.now();
344
+ const parsed = ListDirectoryArgsSchema.parse(args);
345
+ const entries = await listDirectory(parsed.path, parsed.depth);
346
+ const duration = Date.now() - startTime;
347
+ const resultText = entries.join('\n');
348
+ const resolvedPath = resolveAbsolutePath(parsed.path);
349
+ return {
350
+ content: [{ type: "text", text: resultText }],
351
+ ...(parsed.origin === 'ui' ? {
352
+ structuredContent: {
353
+ fileName: path.basename(resolvedPath),
354
+ filePath: resolvedPath,
355
+ fileType: 'directory',
356
+ },
357
+ } : {}),
358
+ };
359
+ }
360
+ catch (error) {
361
+ const errorMessage = error instanceof Error ? error.message : String(error);
362
+ return createErrorResponse(errorMessage);
363
+ }
364
+ }
365
+ /**
366
+ * Handle move_file command
367
+ */
368
+ export async function handleMoveFile(args) {
369
+ try {
370
+ const parsed = MoveFileArgsSchema.parse(args);
371
+ await moveFile(parsed.source, parsed.destination);
372
+ return {
373
+ content: [{ type: "text", text: `Successfully moved ${parsed.source} to ${parsed.destination}` }],
374
+ };
375
+ }
376
+ catch (error) {
377
+ const errorMessage = error instanceof Error ? error.message : String(error);
378
+ return createErrorResponse(errorMessage);
379
+ }
380
+ }
381
+ /**
382
+ * Format a value for display, handling objects and arrays
383
+ */
384
+ function formatValue(value, indent = '') {
385
+ if (value === null || value === undefined) {
386
+ return String(value);
387
+ }
388
+ if (Array.isArray(value)) {
389
+ if (value.length === 0)
390
+ return '[]';
391
+ // For arrays of objects (like sheets), format each item
392
+ const items = value.map((item, i) => {
393
+ if (typeof item === 'object' && item !== null) {
394
+ const props = Object.entries(item)
395
+ .map(([k, v]) => `${k}: ${v}`)
396
+ .join(', ');
397
+ return `${indent} [${i}] { ${props} }`;
398
+ }
399
+ return `${indent} [${i}] ${item}`;
400
+ });
401
+ return `\n${items.join('\n')}`;
402
+ }
403
+ if (typeof value === 'object') {
404
+ return JSON.stringify(value);
405
+ }
406
+ return String(value);
407
+ }
408
+ /**
409
+ * Handle get_file_info command
410
+ */
411
+ export async function handleGetFileInfo(args) {
412
+ try {
413
+ const parsed = GetFileInfoArgsSchema.parse(args);
414
+ const info = await getFileInfo(parsed.path);
415
+ // Generic formatting for any file type
416
+ const formattedText = Object.entries(info)
417
+ .map(([key, value]) => `${key}: ${formatValue(value)}`)
418
+ .join('\n');
419
+ return {
420
+ content: [{
421
+ type: "text",
422
+ text: formattedText
423
+ }],
424
+ };
425
+ }
426
+ catch (error) {
427
+ const errorMessage = error instanceof Error ? error.message : String(error);
428
+ return createErrorResponse(errorMessage);
429
+ }
430
+ }
431
+ // Use get_config to retrieve the allowedDirectories configuration
432
+ /**
433
+ * Handle write_pdf command
434
+ */
435
+ export async function handleWritePdf(args) {
436
+ try {
437
+ const parsed = WritePdfArgsSchema.parse(args);
438
+ const ignoredOptions = await writePdf(parsed.path, parsed.content, parsed.outputPath, parsed.options);
439
+ const targetPath = parsed.outputPath || parsed.path;
440
+ return {
441
+ content: [{ type: "text", text: `Successfully wrote PDF to ${targetPath}${parsed.outputPath ? `\nOriginal file: ${parsed.path}` : ''}` }],
442
+ // Which options were ignored, and why: internal (tests), not sent to the client (see utils/internal-facts.ts)
443
+ ...(ignoredOptions.length > 0 ? { structuredContent: { ignoredOptions } } : {}),
444
+ };
445
+ }
446
+ catch (error) {
447
+ const errorMessage = error instanceof Error ? error.message : String(error);
448
+ return createErrorResponse(errorMessage);
449
+ }
450
+ }
@@ -0,0 +1,67 @@
1
+ import { toolHistory } from '../utils/toolHistory.js';
2
+ import { GetRecentToolCallsArgsSchema, TrackUiEventArgsSchema } from '../tools/schemas.js';
3
+ import { capture_ui_event } from '../utils/capture.js';
4
+ export function buildTrackUiEventCapturePayload(event, component, params) {
5
+ return {
6
+ ...params,
7
+ component,
8
+ event
9
+ };
10
+ }
11
+ /**
12
+ * Handle get_recent_tool_calls command
13
+ */
14
+ export async function handleGetRecentToolCalls(args) {
15
+ try {
16
+ const parsed = GetRecentToolCallsArgsSchema.parse(args);
17
+ // Use formatted version with local timezone
18
+ const calls = toolHistory.getRecentCallsFormatted({
19
+ maxResults: parsed.maxResults,
20
+ toolName: parsed.toolName,
21
+ since: parsed.since
22
+ });
23
+ const stats = toolHistory.getStats();
24
+ // Format the response (excluding file path per user request)
25
+ const summary = `Tool Call History (${calls.length} results, ${stats.totalEntries} total in memory)`;
26
+ const historyJson = JSON.stringify(calls, null, 2);
27
+ return {
28
+ content: [{
29
+ type: "text",
30
+ text: `${summary}\n\n${historyJson}`
31
+ }]
32
+ };
33
+ }
34
+ catch (error) {
35
+ return {
36
+ content: [{
37
+ type: "text",
38
+ text: `Error getting tool history: ${error instanceof Error ? error.message : String(error)}`
39
+ }],
40
+ isError: true
41
+ };
42
+ }
43
+ }
44
+ /**
45
+ * Handle track_ui_event command
46
+ */
47
+ export async function handleTrackUiEvent(args) {
48
+ try {
49
+ const parsed = TrackUiEventArgsSchema.parse(args);
50
+ await capture_ui_event('mcp_ui_event', buildTrackUiEventCapturePayload(parsed.event, parsed.component, parsed.params));
51
+ return {
52
+ content: [{
53
+ type: "text",
54
+ text: `Tracked UI event: ${parsed.event}`
55
+ }]
56
+ };
57
+ }
58
+ catch (error) {
59
+ return {
60
+ content: [{
61
+ type: "text",
62
+ text: `Error tracking UI event: ${error instanceof Error ? error.message : String(error)}`
63
+ }],
64
+ isError: true
65
+ };
66
+ }
67
+ }
@@ -0,0 +1,7 @@
1
+ // Export all handlers from their respective files
2
+ export * from './filesystem-handlers.js';
3
+ export * from './terminal-handlers.js';
4
+ export * from './process-handlers.js';
5
+ export * from './edit-search-handlers.js';
6
+ export * from './search-handlers.js';
7
+ export * from './history-handlers.js';
@@ -0,0 +1,15 @@
1
+ import { listProcesses, killProcess } from '../tools/process.js';
2
+ import { KillProcessArgsSchema } from '../tools/schemas.js';
3
+ /**
4
+ * Handle list_processes command
5
+ */
6
+ export async function handleListProcesses() {
7
+ return listProcesses();
8
+ }
9
+ /**
10
+ * Handle kill_process command
11
+ */
12
+ export async function handleKillProcess(args) {
13
+ const parsed = KillProcessArgsSchema.parse(args);
14
+ return killProcess(parsed);
15
+ }