@wonderwhy-er/desktop-commander 0.2.5 → 0.2.7

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 (113) hide show
  1. package/dist/index-dxt.js +10 -47
  2. package/dist/server.js +6 -0
  3. package/dist/tools/filesystem.js +37 -4
  4. package/dist/utils/usageTracker.js +8 -5
  5. package/dist/version.d.ts +1 -1
  6. package/dist/version.js +1 -1
  7. package/package.json +2 -1
  8. package/dist/REPLSessionManager.d.ts +0 -109
  9. package/dist/REPLSessionManager.js +0 -364
  10. package/dist/REPLSessionManager.test.d.ts +0 -1
  11. package/dist/REPLSessionManager.test.js +0 -75
  12. package/dist/client/replClient.d.ts +0 -63
  13. package/dist/client/replClient.js +0 -217
  14. package/dist/client/sshClient.d.ts +0 -82
  15. package/dist/client/sshClient.js +0 -200
  16. package/dist/command-manager.js.map +0 -1
  17. package/dist/config-manager.js.map +0 -1
  18. package/dist/config.js.map +0 -1
  19. package/dist/custom-stdio.js.map +0 -1
  20. package/dist/error-handlers.js.map +0 -1
  21. package/dist/handlers/command-handlers.d.ts +0 -13
  22. package/dist/handlers/command-handlers.js +0 -43
  23. package/dist/handlers/edit-search-handlers.js.map +0 -1
  24. package/dist/handlers/filesystem-handlers.js.map +0 -1
  25. package/dist/handlers/fuzzy-search-log-handlers.d.ts +0 -13
  26. package/dist/handlers/fuzzy-search-log-handlers.js +0 -179
  27. package/dist/handlers/index.js.map +0 -1
  28. package/dist/handlers/process-handlers.js.map +0 -1
  29. package/dist/handlers/repl-handlers.d.ts +0 -21
  30. package/dist/handlers/repl-handlers.js +0 -37
  31. package/dist/handlers/replCommandHandler.d.ts +0 -125
  32. package/dist/handlers/replCommandHandler.js +0 -255
  33. package/dist/handlers/replCommandHandler.test.d.ts +0 -1
  34. package/dist/handlers/replCommandHandler.test.js +0 -103
  35. package/dist/handlers/terminal-handlers.js.map +0 -1
  36. package/dist/index-with-startup-detection.d.ts +0 -5
  37. package/dist/index-with-startup-detection.js +0 -180
  38. package/dist/index.js.map +0 -1
  39. package/dist/logging.d.ts +0 -2
  40. package/dist/logging.js +0 -28
  41. package/dist/polyform-license-src/edit/edit.d.ts +0 -15
  42. package/dist/polyform-license-src/edit/edit.js +0 -163
  43. package/dist/polyform-license-src/edit/fuzzySearch.d.ts +0 -30
  44. package/dist/polyform-license-src/edit/fuzzySearch.js +0 -121
  45. package/dist/polyform-license-src/edit/handlers.d.ts +0 -16
  46. package/dist/polyform-license-src/edit/handlers.js +0 -24
  47. package/dist/polyform-license-src/edit/index.d.ts +0 -12
  48. package/dist/polyform-license-src/edit/index.js +0 -13
  49. package/dist/polyform-license-src/edit/schemas.d.ts +0 -25
  50. package/dist/polyform-license-src/edit/schemas.js +0 -16
  51. package/dist/polyform-license-src/index.d.ts +0 -9
  52. package/dist/polyform-license-src/index.js +0 -10
  53. package/dist/repl-manager.d.ts +0 -73
  54. package/dist/repl-manager.js +0 -407
  55. package/dist/replIntegration.d.ts +0 -14
  56. package/dist/replIntegration.js +0 -27
  57. package/dist/sandbox/index.d.ts +0 -9
  58. package/dist/sandbox/index.js +0 -50
  59. package/dist/sandbox/mac-sandbox.d.ts +0 -19
  60. package/dist/sandbox/mac-sandbox.js +0 -174
  61. package/dist/server.js.map +0 -1
  62. package/dist/setup.log +0 -32
  63. package/dist/terminal-manager.js.map +0 -1
  64. package/dist/tools/client.d.ts +0 -10
  65. package/dist/tools/client.js +0 -13
  66. package/dist/tools/command-block.d.ts +0 -18
  67. package/dist/tools/command-block.js +0 -62
  68. package/dist/tools/config.js.map +0 -1
  69. package/dist/tools/debug-path.d.ts +0 -1
  70. package/dist/tools/debug-path.js +0 -44
  71. package/dist/tools/edit.js.map +0 -1
  72. package/dist/tools/enhanced-read-output.js +0 -69
  73. package/dist/tools/enhanced-send-input.js +0 -111
  74. package/dist/tools/environment.d.ts +0 -55
  75. package/dist/tools/environment.js +0 -65
  76. package/dist/tools/execute.d.ts +0 -10
  77. package/dist/tools/execute.js +0 -158
  78. package/dist/tools/execute.js.map +0 -1
  79. package/dist/tools/filesystem-fixed.d.ts +0 -22
  80. package/dist/tools/filesystem-fixed.js +0 -176
  81. package/dist/tools/filesystem.js.map +0 -1
  82. package/dist/tools/fuzzySearch.js.map +0 -1
  83. package/dist/tools/mime-types.js.map +0 -1
  84. package/dist/tools/pdf-reader.d.ts +0 -13
  85. package/dist/tools/pdf-reader.js +0 -214
  86. package/dist/tools/process.js.map +0 -1
  87. package/dist/tools/progress.d.ts +0 -20
  88. package/dist/tools/progress.js +0 -59
  89. package/dist/tools/repl.d.ts +0 -21
  90. package/dist/tools/repl.js +0 -217
  91. package/dist/tools/schemas.js.map +0 -1
  92. package/dist/tools/search.js.map +0 -1
  93. package/dist/tools/send-input.d.ts +0 -2
  94. package/dist/tools/send-input.js +0 -45
  95. package/dist/types.js.map +0 -1
  96. package/dist/utils/capture.js.map +0 -1
  97. package/dist/utils/early-logger.d.ts +0 -4
  98. package/dist/utils/early-logger.js +0 -35
  99. package/dist/utils/fuzzySearchLogger.js.map +0 -1
  100. package/dist/utils/lineEndingHandler.js.map +0 -1
  101. package/dist/utils/lineEndingHandler_optimized.d.ts +0 -21
  102. package/dist/utils/lineEndingHandler_optimized.js +0 -77
  103. package/dist/utils/mcp-logger.d.ts +0 -30
  104. package/dist/utils/mcp-logger.js +0 -59
  105. package/dist/utils/smithery-detector.d.ts +0 -94
  106. package/dist/utils/smithery-detector.js +0 -292
  107. package/dist/utils/startup-detector.d.ts +0 -65
  108. package/dist/utils/startup-detector.js +0 -390
  109. package/dist/utils/trackTools.js.map +0 -1
  110. package/dist/utils/withTimeout.js.map +0 -1
  111. package/dist/utils.d.ts +0 -26
  112. package/dist/utils.js +0 -227
  113. package/dist/version.js.map +0 -1
@@ -1,179 +0,0 @@
1
- import { fuzzySearchLogger } from '../utils/fuzzySearchLogger.js';
2
- import { createErrorResponse } from '../error-handlers.js';
3
- import { ViewFuzzySearchLogsArgsSchema, AnalyzeFuzzySearchLogsArgsSchema, ClearFuzzySearchLogsArgsSchema } from '../tools/schemas.js';
4
- /**
5
- * View recent fuzzy search logs
6
- */
7
- export async function handleViewFuzzySearchLogs(args) {
8
- try {
9
- const parsed = ViewFuzzySearchLogsArgsSchema.parse(args);
10
- const logs = await fuzzySearchLogger.getRecentLogs(parsed.count);
11
- const logPath = await fuzzySearchLogger.getLogPath();
12
- if (logs.length === 0) {
13
- return {
14
- content: [{
15
- type: "text",
16
- text: `No fuzzy search logs found. Log file location: ${logPath}`
17
- }],
18
- };
19
- }
20
- // Parse and format logs for better readability
21
- const formattedLogs = logs.map((log, index) => {
22
- const parts = log.split('\t');
23
- if (parts.length >= 16) {
24
- const [timestamp, searchText, foundText, similarity, executionTime, exactMatchCount, expectedReplacements, fuzzyThreshold, belowThreshold, diff, searchLength, foundLength, fileExtension, characterCodes, uniqueCharacterCount, diffLength] = parts;
25
- return `
26
- --- Log Entry ${index + 1} ---
27
- Timestamp: ${timestamp}
28
- File Extension: ${fileExtension}
29
- Search Text: ${searchText.replace(/\\n/g, '\n').replace(/\\t/g, '\t')}
30
- Found Text: ${foundText.replace(/\\n/g, '\n').replace(/\\t/g, '\t')}
31
- Similarity: ${(parseFloat(similarity) * 100).toFixed(2)}%
32
- Execution Time: ${parseFloat(executionTime).toFixed(2)}ms
33
- Exact Match Count: ${exactMatchCount}
34
- Expected Replacements: ${expectedReplacements}
35
- Below Threshold: ${belowThreshold}
36
- Diff: ${diff.replace(/\\n/g, '\n').replace(/\\t/g, '\t')}
37
- Search Length: ${searchLength}
38
- Found Length: ${foundLength}
39
- Character Codes: ${characterCodes}
40
- Unique Characters: ${uniqueCharacterCount}
41
- Diff Length: ${diffLength}
42
- `;
43
- }
44
- return `Malformed log entry: ${log}`;
45
- }).join('\n');
46
- return {
47
- content: [{
48
- type: "text",
49
- text: `Recent Fuzzy Search Logs (${logs.length} entries):\n\n${formattedLogs}\n\nLog file location: ${logPath}`
50
- }],
51
- };
52
- }
53
- catch (error) {
54
- return createErrorResponse(`Failed to view fuzzy search logs: ${error instanceof Error ? error.message : String(error)}`);
55
- }
56
- }
57
- /**
58
- * Analyze fuzzy search logs to identify patterns and issues
59
- */
60
- export async function handleAnalyzeFuzzySearchLogs(args) {
61
- try {
62
- const parsed = AnalyzeFuzzySearchLogsArgsSchema.parse(args);
63
- const logs = await fuzzySearchLogger.getRecentLogs(100); // Analyze more logs
64
- const logPath = await fuzzySearchLogger.getLogPath();
65
- if (logs.length === 0) {
66
- return {
67
- content: [{
68
- type: "text",
69
- text: `No fuzzy search logs found. Log file location: ${logPath}`
70
- }],
71
- };
72
- }
73
- // Parse logs and gather statistics
74
- let totalEntries = 0;
75
- let exactMatches = 0;
76
- let fuzzyMatches = 0;
77
- let failures = 0;
78
- let belowThresholdCount = 0;
79
- const executionTimes = [];
80
- const similarities = [];
81
- const fileExtensions = new Map();
82
- const commonCharacterCodes = new Map();
83
- for (const log of logs) {
84
- const parts = log.split('\t');
85
- if (parts.length >= 16) {
86
- totalEntries++;
87
- const [timestamp, searchText, foundText, similarity, executionTime, exactMatchCount, expectedReplacements, fuzzyThreshold, belowThreshold, diff, searchLength, foundLength, fileExtension, characterCodes, uniqueCharacterCount, diffLength] = parts;
88
- const simValue = parseFloat(similarity);
89
- const execTime = parseFloat(executionTime);
90
- const exactCount = parseInt(exactMatchCount);
91
- const belowThresh = belowThreshold === 'true';
92
- if (exactCount > 0) {
93
- exactMatches++;
94
- }
95
- else if (simValue >= parsed.failureThreshold) {
96
- fuzzyMatches++;
97
- }
98
- else {
99
- failures++;
100
- }
101
- if (belowThresh) {
102
- belowThresholdCount++;
103
- }
104
- executionTimes.push(execTime);
105
- similarities.push(simValue);
106
- // Track file extensions
107
- fileExtensions.set(fileExtension, (fileExtensions.get(fileExtension) || 0) + 1);
108
- // Track character codes that appear in diffs
109
- if (characterCodes && characterCodes !== '') {
110
- const codes = characterCodes.split(',');
111
- for (const code of codes) {
112
- const key = code.split(':')[0];
113
- commonCharacterCodes.set(key, (commonCharacterCodes.get(key) || 0) + 1);
114
- }
115
- }
116
- }
117
- }
118
- // Calculate statistics
119
- const avgExecutionTime = executionTimes.reduce((a, b) => a + b, 0) / executionTimes.length;
120
- const avgSimilarity = similarities.reduce((a, b) => a + b, 0) / similarities.length;
121
- // Sort by frequency
122
- const sortedExtensions = Array.from(fileExtensions.entries()).sort((a, b) => b[1] - a[1]);
123
- const sortedCharCodes = Array.from(commonCharacterCodes.entries()).sort((a, b) => b[1] - a[1]);
124
- const analysis = `
125
- === Fuzzy Search Analysis ===
126
-
127
- Total Entries: ${totalEntries}
128
- Exact Matches: ${exactMatches} (${((exactMatches / totalEntries) * 100).toFixed(2)}%)
129
- Fuzzy Matches: ${fuzzyMatches} (${((fuzzyMatches / totalEntries) * 100).toFixed(2)}%)
130
- Failures: ${failures} (${((failures / totalEntries) * 100).toFixed(2)}%)
131
- Below Threshold: ${belowThresholdCount} (${((belowThresholdCount / totalEntries) * 100).toFixed(2)}%)
132
-
133
- Performance:
134
- Average Execution Time: ${avgExecutionTime.toFixed(2)}ms
135
- Average Similarity: ${(avgSimilarity * 100).toFixed(2)}%
136
-
137
- File Extensions (Top 5):
138
- ${sortedExtensions.slice(0, 5).map(([ext, count]) => `${ext || 'none'}: ${count} times`).join('\n')}
139
-
140
- Common Character Codes in Diffs (Top 5):
141
- ${sortedCharCodes.slice(0, 5).map(([code, count]) => {
142
- const charCode = parseInt(code);
143
- const char = String.fromCharCode(charCode);
144
- const display = charCode < 32 || charCode > 126 ? `\\x${charCode.toString(16).padStart(2, '0')}` : char;
145
- return `${code} [${display}]: ${count} times`;
146
- }).join('\n')}
147
-
148
- Log file location: ${logPath}
149
- `;
150
- return {
151
- content: [{
152
- type: "text",
153
- text: analysis
154
- }],
155
- };
156
- }
157
- catch (error) {
158
- return createErrorResponse(`Failed to analyze fuzzy search logs: ${error instanceof Error ? error.message : String(error)}`);
159
- }
160
- }
161
- /**
162
- * Clear fuzzy search logs
163
- */
164
- export async function handleClearFuzzySearchLogs(args) {
165
- try {
166
- ClearFuzzySearchLogsArgsSchema.parse(args);
167
- await fuzzySearchLogger.clearLog();
168
- const logPath = await fuzzySearchLogger.getLogPath();
169
- return {
170
- content: [{
171
- type: "text",
172
- text: `Fuzzy search logs cleared. Log file location: ${logPath}`
173
- }],
174
- };
175
- }
176
- catch (error) {
177
- return createErrorResponse(`Failed to clear fuzzy search logs: ${error instanceof Error ? error.message : String(error)}`);
178
- }
179
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"process-handlers.js","sourceRoot":"","sources":["../../src/handlers/process-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,WAAW,EACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACH,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAI7B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACrC,OAAO,aAAa,EAAE,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAa;IACjD,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
@@ -1,21 +0,0 @@
1
- import { ServerResult } from '../types.js';
2
- /**
3
- * Handle create_repl_session command
4
- */
5
- export declare function handleCreateREPLSession(args: unknown): Promise<ServerResult>;
6
- /**
7
- * Handle execute_repl_code command
8
- */
9
- export declare function handleExecuteREPLCode(args: unknown): Promise<ServerResult>;
10
- /**
11
- * Handle terminate_repl_session command
12
- */
13
- export declare function handleTerminateREPLSession(args: unknown): Promise<ServerResult>;
14
- /**
15
- * Handle list_repl_sessions command
16
- */
17
- export declare function handleListREPLSessions(args?: unknown): Promise<ServerResult>;
18
- /**
19
- * Handle get_repl_session_info command
20
- */
21
- export declare function handleGetREPLSessionInfo(args: unknown): Promise<ServerResult>;
@@ -1,37 +0,0 @@
1
- import { createREPLSession, executeREPLCode, terminateREPLSession, listREPLSessions, getREPLSessionInfo } from '../tools/repl.js';
2
- import { CreateREPLSessionArgsSchema, ExecuteREPLCodeArgsSchema, TerminateREPLSessionArgsSchema, ListREPLSessionsArgsSchema, GetREPLSessionInfoArgsSchema } from '../tools/schemas.js';
3
- /**
4
- * Handle create_repl_session command
5
- */
6
- export async function handleCreateREPLSession(args) {
7
- const parsed = CreateREPLSessionArgsSchema.parse(args);
8
- return createREPLSession(parsed);
9
- }
10
- /**
11
- * Handle execute_repl_code command
12
- */
13
- export async function handleExecuteREPLCode(args) {
14
- const parsed = ExecuteREPLCodeArgsSchema.parse(args);
15
- return executeREPLCode(parsed);
16
- }
17
- /**
18
- * Handle terminate_repl_session command
19
- */
20
- export async function handleTerminateREPLSession(args) {
21
- const parsed = TerminateREPLSessionArgsSchema.parse(args);
22
- return terminateREPLSession(parsed);
23
- }
24
- /**
25
- * Handle list_repl_sessions command
26
- */
27
- export async function handleListREPLSessions(args = {}) {
28
- const parsed = ListREPLSessionsArgsSchema.parse(args);
29
- return listREPLSessions(parsed);
30
- }
31
- /**
32
- * Handle get_repl_session_info command
33
- */
34
- export async function handleGetREPLSessionInfo(args) {
35
- const parsed = GetREPLSessionInfoArgsSchema.parse(args);
36
- return getREPLSessionInfo(parsed);
37
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * Initialize the REPL manager with a terminal manager instance
3
- * @param terminalManager - The terminal manager instance
4
- */
5
- export declare function initializeREPLManager(terminalManager: any): void;
6
- interface REPLSessionParams {
7
- language: string;
8
- options?: any;
9
- }
10
- interface ExecuteCodeParams {
11
- pid: number | string;
12
- code: string;
13
- options?: any;
14
- }
15
- interface SSHSessionParams {
16
- host: string;
17
- username?: string;
18
- port?: number;
19
- identity?: string;
20
- password?: string;
21
- options?: any;
22
- }
23
- interface CommandParams {
24
- pid: number | string;
25
- command: string;
26
- options?: any;
27
- }
28
- interface IdleSessionParams {
29
- maxIdleMs?: number;
30
- }
31
- /**
32
- * Command handler for REPL-related operations
33
- */
34
- export declare const replCommandHandler: {
35
- /**
36
- * Create a new REPL session
37
- * @param params - Command parameters
38
- * @returns Result object with session PID
39
- */
40
- createREPLSession: (params: REPLSessionParams) => Promise<{
41
- success: boolean;
42
- pid: number;
43
- message: string;
44
- error?: undefined;
45
- } | {
46
- success: boolean;
47
- error: any;
48
- pid?: undefined;
49
- message?: undefined;
50
- }>;
51
- /**
52
- * Execute code in an existing REPL session
53
- * @param params - Command parameters
54
- * @returns Result with execution output
55
- */
56
- executeREPLCode: (params: ExecuteCodeParams) => Promise<any>;
57
- /**
58
- * Create a new SSH session
59
- * @param params - Command parameters
60
- * @returns Result object with session PID
61
- */
62
- createSSHSession: (params: SSHSessionParams) => Promise<{
63
- success: boolean;
64
- pid: number;
65
- message: string;
66
- error?: undefined;
67
- } | {
68
- success: boolean;
69
- error: any;
70
- pid?: undefined;
71
- message?: undefined;
72
- }>;
73
- /**
74
- * Execute a command in an SSH session
75
- * @param params - Command parameters
76
- * @returns Result with execution output
77
- */
78
- executeSSHCommand: (params: CommandParams) => Promise<any>;
79
- /**
80
- * List all active REPL sessions
81
- * @returns List of active sessions
82
- */
83
- listREPLSessions: () => {
84
- success: boolean;
85
- sessions: any[];
86
- error?: undefined;
87
- } | {
88
- success: boolean;
89
- error: any;
90
- sessions?: undefined;
91
- };
92
- /**
93
- * Close a specific REPL session
94
- * @param params - Command parameters
95
- * @returns Result indicating success
96
- */
97
- closeREPLSession: (params: {
98
- pid: number | string;
99
- }) => Promise<{
100
- success: boolean;
101
- message: string;
102
- error?: undefined;
103
- } | {
104
- success: boolean;
105
- error: any;
106
- message?: undefined;
107
- }>;
108
- /**
109
- * Close all idle REPL sessions
110
- * @param params - Command parameters
111
- * @returns Result with number of closed sessions
112
- */
113
- closeIdleREPLSessions: (params?: IdleSessionParams) => Promise<{
114
- success: boolean;
115
- closedCount: number;
116
- message: string;
117
- error?: undefined;
118
- } | {
119
- success: boolean;
120
- error: any;
121
- closedCount?: undefined;
122
- message?: undefined;
123
- }>;
124
- };
125
- export {};
@@ -1,255 +0,0 @@
1
- import { REPLSessionManager } from '../REPLSessionManager.js';
2
- let replManager = null;
3
- /**
4
- * Initialize the REPL manager with a terminal manager instance
5
- * @param terminalManager - The terminal manager instance
6
- */
7
- export function initializeREPLManager(terminalManager) {
8
- if (!replManager) {
9
- replManager = new REPLSessionManager(terminalManager);
10
- }
11
- }
12
- /**
13
- * Command handler for REPL-related operations
14
- */
15
- export const replCommandHandler = {
16
- /**
17
- * Create a new REPL session
18
- * @param params - Command parameters
19
- * @returns Result object with session PID
20
- */
21
- createREPLSession: async (params) => {
22
- try {
23
- if (!replManager) {
24
- return {
25
- success: false,
26
- error: "REPL Manager not initialized"
27
- };
28
- }
29
- const language = params.language;
30
- if (!language) {
31
- return {
32
- success: false,
33
- error: "Language parameter is required"
34
- };
35
- }
36
- const pid = await replManager.createSession(language, params.options || {});
37
- return {
38
- success: true,
39
- pid,
40
- message: `${language} REPL session started with PID ${pid}`
41
- };
42
- }
43
- catch (error) {
44
- return {
45
- success: false,
46
- error: error.message || "Failed to create REPL session"
47
- };
48
- }
49
- },
50
- /**
51
- * Execute code in an existing REPL session
52
- * @param params - Command parameters
53
- * @returns Result with execution output
54
- */
55
- executeREPLCode: async (params) => {
56
- try {
57
- if (!replManager) {
58
- return {
59
- success: false,
60
- error: "REPL Manager not initialized"
61
- };
62
- }
63
- const { pid, code } = params;
64
- if (!pid || !code) {
65
- return {
66
- success: false,
67
- error: "Both pid and code parameters are required"
68
- };
69
- }
70
- const result = await replManager.executeCode(typeof pid === 'string' ? parseInt(pid) : pid, code, params.options || {});
71
- return {
72
- success: true,
73
- ...result
74
- };
75
- }
76
- catch (error) {
77
- return {
78
- success: false,
79
- error: error.message || "Failed to execute code in REPL session"
80
- };
81
- }
82
- },
83
- /**
84
- * Create a new SSH session
85
- * @param params - Command parameters
86
- * @returns Result object with session PID
87
- */
88
- createSSHSession: async (params) => {
89
- try {
90
- if (!replManager) {
91
- return {
92
- success: false,
93
- error: "REPL Manager not initialized"
94
- };
95
- }
96
- const { host, username, port, identity, password } = params;
97
- if (!host) {
98
- return {
99
- success: false,
100
- error: "Host parameter is required"
101
- };
102
- }
103
- const options = {
104
- username,
105
- port,
106
- identity,
107
- password,
108
- ...(params.options || {})
109
- };
110
- const pid = await replManager.createSSHSession(host, options);
111
- return {
112
- success: true,
113
- pid,
114
- message: `SSH session to ${host} started with PID ${pid}`
115
- };
116
- }
117
- catch (error) {
118
- return {
119
- success: false,
120
- error: error.message || "Failed to create SSH session"
121
- };
122
- }
123
- },
124
- /**
125
- * Execute a command in an SSH session
126
- * @param params - Command parameters
127
- * @returns Result with execution output
128
- */
129
- executeSSHCommand: async (params) => {
130
- try {
131
- if (!replManager) {
132
- return {
133
- success: false,
134
- error: "REPL Manager not initialized"
135
- };
136
- }
137
- const { pid, command } = params;
138
- if (!pid || !command) {
139
- return {
140
- success: false,
141
- error: "Both pid and command parameters are required"
142
- };
143
- }
144
- // For SSH, we use the same sendAndReadREPL method but specify 'ssh' as the language
145
- const parsedPid = typeof pid === 'string' ? parseInt(pid) : pid;
146
- const session = replManager.listSessions().find(s => s.pid === parsedPid);
147
- if (!session || session.language !== 'ssh') {
148
- return {
149
- success: false,
150
- error: "Invalid SSH session PID"
151
- };
152
- }
153
- const result = await replManager.sendAndReadREPL(parsedPid, command, 'ssh', params.options?.timeout || 10000);
154
- return {
155
- success: true,
156
- ...result
157
- };
158
- }
159
- catch (error) {
160
- return {
161
- success: false,
162
- error: error.message || "Failed to execute command in SSH session"
163
- };
164
- }
165
- },
166
- /**
167
- * List all active REPL sessions
168
- * @returns List of active sessions
169
- */
170
- listREPLSessions: () => {
171
- try {
172
- if (!replManager) {
173
- return {
174
- success: false,
175
- error: "REPL Manager not initialized"
176
- };
177
- }
178
- const sessions = replManager.listSessions();
179
- return {
180
- success: true,
181
- sessions
182
- };
183
- }
184
- catch (error) {
185
- return {
186
- success: false,
187
- error: error.message || "Failed to list REPL sessions"
188
- };
189
- }
190
- },
191
- /**
192
- * Close a specific REPL session
193
- * @param params - Command parameters
194
- * @returns Result indicating success
195
- */
196
- closeREPLSession: async (params) => {
197
- try {
198
- if (!replManager) {
199
- return {
200
- success: false,
201
- error: "REPL Manager not initialized"
202
- };
203
- }
204
- const { pid } = params;
205
- if (!pid) {
206
- return {
207
- success: false,
208
- error: "PID parameter is required"
209
- };
210
- }
211
- const parsedPid = typeof pid === 'string' ? parseInt(pid) : pid;
212
- const success = await replManager.closeSession(parsedPid);
213
- return {
214
- success,
215
- message: success
216
- ? `REPL session with PID ${pid} closed successfully`
217
- : `Failed to close REPL session with PID ${pid}`
218
- };
219
- }
220
- catch (error) {
221
- return {
222
- success: false,
223
- error: error.message || "Failed to close REPL session"
224
- };
225
- }
226
- },
227
- /**
228
- * Close all idle REPL sessions
229
- * @param params - Command parameters
230
- * @returns Result with number of closed sessions
231
- */
232
- closeIdleREPLSessions: async (params) => {
233
- try {
234
- if (!replManager) {
235
- return {
236
- success: false,
237
- error: "REPL Manager not initialized"
238
- };
239
- }
240
- const maxIdleMs = params?.maxIdleMs || 30 * 60 * 1000; // Default 30 minutes
241
- const closedCount = await replManager.closeIdleSessions(maxIdleMs);
242
- return {
243
- success: true,
244
- closedCount,
245
- message: `Closed ${closedCount} idle REPL session(s)`
246
- };
247
- }
248
- catch (error) {
249
- return {
250
- success: false,
251
- error: error.message || "Failed to close idle REPL sessions"
252
- };
253
- }
254
- }
255
- };
@@ -1 +0,0 @@
1
- export {};