@baixfeng/godot-mcp-cli 1.0.11

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 (115) hide show
  1. package/README.md +187 -0
  2. package/addons/godot_mcp/command_handler.gd +161 -0
  3. package/addons/godot_mcp/command_handler.gd.uid +1 -0
  4. package/addons/godot_mcp/commands/base_command_processor.gd +221 -0
  5. package/addons/godot_mcp/commands/base_command_processor.gd.uid +1 -0
  6. package/addons/godot_mcp/commands/debugger_commands.gd +221 -0
  7. package/addons/godot_mcp/commands/debugger_commands.gd.uid +1 -0
  8. package/addons/godot_mcp/commands/editor_commands.gd +237 -0
  9. package/addons/godot_mcp/commands/editor_commands.gd.uid +1 -0
  10. package/addons/godot_mcp/commands/editor_script_commands.gd +365 -0
  11. package/addons/godot_mcp/commands/editor_script_commands.gd.uid +1 -0
  12. package/addons/godot_mcp/commands/input_commands.gd +337 -0
  13. package/addons/godot_mcp/commands/input_commands.gd.uid +1 -0
  14. package/addons/godot_mcp/commands/node_commands.gd +222 -0
  15. package/addons/godot_mcp/commands/node_commands.gd.uid +1 -0
  16. package/addons/godot_mcp/commands/project_commands.gd +298 -0
  17. package/addons/godot_mcp/commands/project_commands.gd.uid +1 -0
  18. package/addons/godot_mcp/commands/scene_commands.gd +337 -0
  19. package/addons/godot_mcp/commands/scene_commands.gd.uid +1 -0
  20. package/addons/godot_mcp/commands/script_commands.gd +349 -0
  21. package/addons/godot_mcp/commands/script_commands.gd.uid +1 -0
  22. package/addons/godot_mcp/mcp_asset_commands.gd +153 -0
  23. package/addons/godot_mcp/mcp_asset_commands.gd.uid +1 -0
  24. package/addons/godot_mcp/mcp_debug_output_publisher.gd +1669 -0
  25. package/addons/godot_mcp/mcp_debug_output_publisher.gd.uid +1 -0
  26. package/addons/godot_mcp/mcp_debugger_bridge.gd +1455 -0
  27. package/addons/godot_mcp/mcp_debugger_bridge.gd.uid +1 -0
  28. package/addons/godot_mcp/mcp_enhanced_commands.gd +1083 -0
  29. package/addons/godot_mcp/mcp_enhanced_commands.gd.uid +1 -0
  30. package/addons/godot_mcp/mcp_input_handler.gd +545 -0
  31. package/addons/godot_mcp/mcp_input_handler.gd.uid +1 -0
  32. package/addons/godot_mcp/mcp_runtime_debugger_bridge.gd +464 -0
  33. package/addons/godot_mcp/mcp_runtime_debugger_bridge.gd.uid +1 -0
  34. package/addons/godot_mcp/mcp_script_resource_commands.gd +165 -0
  35. package/addons/godot_mcp/mcp_script_resource_commands.gd.uid +1 -0
  36. package/addons/godot_mcp/mcp_server.gd +260 -0
  37. package/addons/godot_mcp/mcp_server.gd.uid +1 -0
  38. package/addons/godot_mcp/plugin.cfg +7 -0
  39. package/addons/godot_mcp/runtime_debugger.gd +81 -0
  40. package/addons/godot_mcp/runtime_debugger.gd.uid +1 -0
  41. package/addons/godot_mcp/ui/mcp_panel.gd +94 -0
  42. package/addons/godot_mcp/ui/mcp_panel.gd.uid +1 -0
  43. package/addons/godot_mcp/ui/mcp_panel.tscn +96 -0
  44. package/addons/godot_mcp/utils/node_utils.gd +82 -0
  45. package/addons/godot_mcp/utils/node_utils.gd.uid +1 -0
  46. package/addons/godot_mcp/utils/resource_utils.gd +81 -0
  47. package/addons/godot_mcp/utils/resource_utils.gd.uid +1 -0
  48. package/addons/godot_mcp/utils/script_utils.gd +114 -0
  49. package/addons/godot_mcp/utils/script_utils.gd.uid +1 -0
  50. package/addons/godot_mcp/websocket_server.gd +197 -0
  51. package/addons/godot_mcp/websocket_server.gd.uid +1 -0
  52. package/dist/cli.d.ts +2 -0
  53. package/dist/cli.js +561 -0
  54. package/dist/cli.js.map +1 -0
  55. package/dist/index.d.ts +1 -0
  56. package/dist/index.js +156 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/resources/asset_resources.d.ts +29 -0
  59. package/dist/resources/asset_resources.js +145 -0
  60. package/dist/resources/asset_resources.js.map +1 -0
  61. package/dist/resources/debug_resources.d.ts +11 -0
  62. package/dist/resources/debug_resources.js +106 -0
  63. package/dist/resources/debug_resources.js.map +1 -0
  64. package/dist/resources/debugger_resources.d.ts +62 -0
  65. package/dist/resources/debugger_resources.js +201 -0
  66. package/dist/resources/debugger_resources.js.map +1 -0
  67. package/dist/resources/editor_resources.d.ts +47 -0
  68. package/dist/resources/editor_resources.js +155 -0
  69. package/dist/resources/editor_resources.js.map +1 -0
  70. package/dist/resources/project_resources.d.ts +33 -0
  71. package/dist/resources/project_resources.js +137 -0
  72. package/dist/resources/project_resources.js.map +1 -0
  73. package/dist/resources/scene_resources.d.ts +33 -0
  74. package/dist/resources/scene_resources.js +160 -0
  75. package/dist/resources/scene_resources.js.map +1 -0
  76. package/dist/resources/script_resources.d.ts +51 -0
  77. package/dist/resources/script_resources.js +203 -0
  78. package/dist/resources/script_resources.js.map +1 -0
  79. package/dist/tools/asset_tools.d.ts +5 -0
  80. package/dist/tools/asset_tools.js +125 -0
  81. package/dist/tools/asset_tools.js.map +1 -0
  82. package/dist/tools/debugger_tools.d.ts +2 -0
  83. package/dist/tools/debugger_tools.js +342 -0
  84. package/dist/tools/debugger_tools.js.map +1 -0
  85. package/dist/tools/editor_tools.d.ts +2 -0
  86. package/dist/tools/editor_tools.js +165 -0
  87. package/dist/tools/editor_tools.js.map +1 -0
  88. package/dist/tools/enhanced_tools.d.ts +5 -0
  89. package/dist/tools/enhanced_tools.js +706 -0
  90. package/dist/tools/enhanced_tools.js.map +1 -0
  91. package/dist/tools/input_tools.d.ts +2 -0
  92. package/dist/tools/input_tools.js +408 -0
  93. package/dist/tools/input_tools.js.map +1 -0
  94. package/dist/tools/node_tools.d.ts +5 -0
  95. package/dist/tools/node_tools.js +217 -0
  96. package/dist/tools/node_tools.js.map +1 -0
  97. package/dist/tools/project_tools.d.ts +5 -0
  98. package/dist/tools/project_tools.js +162 -0
  99. package/dist/tools/project_tools.js.map +1 -0
  100. package/dist/tools/scene_tools.d.ts +5 -0
  101. package/dist/tools/scene_tools.js +260 -0
  102. package/dist/tools/scene_tools.js.map +1 -0
  103. package/dist/tools/script_resource_tools.d.ts +5 -0
  104. package/dist/tools/script_resource_tools.js +5 -0
  105. package/dist/tools/script_resource_tools.js.map +1 -0
  106. package/dist/tools/script_tools.d.ts +5 -0
  107. package/dist/tools/script_tools.js +154 -0
  108. package/dist/tools/script_tools.js.map +1 -0
  109. package/dist/utils/godot_connection.d.ts +30 -0
  110. package/dist/utils/godot_connection.js +285 -0
  111. package/dist/utils/godot_connection.js.map +1 -0
  112. package/dist/utils/types.d.ts +16 -0
  113. package/dist/utils/types.js +2 -0
  114. package/dist/utils/types.js.map +1 -0
  115. package/package.json +58 -0
@@ -0,0 +1,706 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ // File: /server/src/tools/enhanced_tools.ts
38
+ import { z } from 'zod';
39
+ import { getGodotConnection } from '../utils/godot_connection.js';
40
+ /**
41
+ * Enhanced tools for more complex operations in Godot
42
+ */
43
+ // Constants
44
+ var MAX_FRAMES_DISPLAY = 10;
45
+ var DEFAULT_INDENT_SIZE = 2;
46
+ // Utility Functions
47
+ function formatNode(node, depth, includeVisibility) {
48
+ if (depth === void 0) { depth = 0; }
49
+ if (includeVisibility === void 0) { includeVisibility = false; }
50
+ var indent = ' '.repeat(depth * DEFAULT_INDENT_SIZE);
51
+ var output = "".concat(indent).concat(node.name, " (").concat(node.type, ")");
52
+ if (includeVisibility && node.visibility) {
53
+ var flags = [];
54
+ if (node.visibility.has_visible_method)
55
+ flags.push('has-visible');
56
+ if (node.visibility.visible)
57
+ flags.push('visible');
58
+ if (node.visibility.visible_in_tree)
59
+ flags.push('visible-in-tree');
60
+ if (flags.length > 0) {
61
+ output += " [".concat(flags.join(', '), "]");
62
+ }
63
+ }
64
+ if (node.children && node.children.length > 0) {
65
+ output += '\n';
66
+ output += node.children
67
+ .map(function (child) { return formatNode(child, depth + 1, includeVisibility); })
68
+ .join('\n');
69
+ }
70
+ return output;
71
+ }
72
+ function summarizeStackFrame(frame) {
73
+ var indexValue = typeof frame.index === 'number'
74
+ ? frame.index
75
+ : (typeof frame.index === 'string' && frame.index.length > 0 ? Number(frame.index) : undefined);
76
+ var fnName = typeof frame.function === 'string' && frame.function.length > 0
77
+ ? frame.function
78
+ : '(anonymous)';
79
+ var location = typeof frame.location === 'string' && frame.location.length > 0
80
+ ? frame.location
81
+ : (function () {
82
+ var script = typeof frame.script === 'string' ? frame.script : '';
83
+ var line = typeof frame.line === 'number' ? frame.line : undefined;
84
+ if (script && line !== undefined) {
85
+ return "".concat(script, ":").concat(line);
86
+ }
87
+ return script || 'location unavailable';
88
+ })();
89
+ if (typeof indexValue === 'number' && Number.isFinite(indexValue)) {
90
+ return "[".concat(indexValue, "] ").concat(fnName, " \u2014 ").concat(location);
91
+ }
92
+ return "".concat(fnName, " \u2014 ").concat(location);
93
+ }
94
+ function formatValue(value) {
95
+ if (value === undefined) {
96
+ return 'undefined';
97
+ }
98
+ if (value === null) {
99
+ return 'null';
100
+ }
101
+ if (typeof value === 'string') {
102
+ return "\"".concat(value, "\"");
103
+ }
104
+ if (typeof value === 'number' || typeof value === 'boolean') {
105
+ return String(value);
106
+ }
107
+ try {
108
+ return JSON.stringify(value, null, 2);
109
+ }
110
+ catch (_a) {
111
+ return String(value);
112
+ }
113
+ }
114
+ function safeGetDiagnostics(result) {
115
+ if (typeof result.diagnostics === 'object' && result.diagnostics !== null) {
116
+ return result.diagnostics;
117
+ }
118
+ return {};
119
+ }
120
+ function safeGetStringArray(value) {
121
+ if (Array.isArray(value)) {
122
+ return value.map(function (item) { return String(item); });
123
+ }
124
+ return [];
125
+ }
126
+ function formatEmptyDebugOutput(diagnostics) {
127
+ var source = diagnostics.source || 'unknown';
128
+ var detail = diagnostics.detail || 'No additional detail from publisher.';
129
+ var controlClass = diagnostics.control_class || 'unset';
130
+ var controlPath = diagnostics.control_path || 'unset';
131
+ var logFilePath = diagnostics.log_file_path || 'not-found';
132
+ var controlSearch = diagnostics.control_search || 'control search summary unavailable';
133
+ return [
134
+ 'No debug output available.',
135
+ "Capture source: ".concat(source),
136
+ "Detail: ".concat(detail),
137
+ "Control class: ".concat(controlClass),
138
+ "Control path: ".concat(controlPath),
139
+ "Log file path: ".concat(logFilePath),
140
+ "Control search: ".concat(controlSearch),
141
+ ].join('\n');
142
+ }
143
+ function formatPanelHeader(diagnostics, lineCount, frameCount, successMessage) {
144
+ var header = [];
145
+ if (diagnostics.error) {
146
+ header.push("".concat(successMessage, ": ").concat(diagnostics.error));
147
+ }
148
+ else {
149
+ header.push("".concat(successMessage, "."));
150
+ }
151
+ header.push("Lines captured: ".concat(lineCount));
152
+ header.push("Frames parsed: ".concat(frameCount));
153
+ if (diagnostics.control_path) {
154
+ header.push("Panel control: ".concat(diagnostics.control_path));
155
+ }
156
+ else if (diagnostics.control_class) {
157
+ header.push("Panel type: ".concat(diagnostics.control_class));
158
+ }
159
+ if (diagnostics.tab_title) {
160
+ header.push("Tab title: ".concat(diagnostics.tab_title));
161
+ }
162
+ if (diagnostics.fallback_source) {
163
+ header.push("Fallback source: ".concat(diagnostics.fallback_source));
164
+ }
165
+ if (typeof diagnostics.timestamp === 'number') {
166
+ header.push("Captured: ".concat(new Date(diagnostics.timestamp).toISOString()));
167
+ }
168
+ if (diagnostics.search_summary) {
169
+ header.push("Search summary: ".concat(diagnostics.search_summary));
170
+ }
171
+ return header;
172
+ }
173
+ function formatStackFrames(frames) {
174
+ if (frames.length === 0) {
175
+ return 'No structured frames were parsed.';
176
+ }
177
+ return frames
178
+ .slice(0, MAX_FRAMES_DISPLAY)
179
+ .map(function (frame, index) { return "#".concat(index, ": ").concat(summarizeStackFrame(frame)); })
180
+ .join('\n');
181
+ }
182
+ // Module state for debug output streaming
183
+ var debugOutputListenerAttached = false;
184
+ /**
185
+ * Enhanced tools for more complex operations in Godot
186
+ */
187
+ export var enhancedTools = [
188
+ {
189
+ name: 'get_editor_scene_structure',
190
+ description: 'Get the current scene hierarchy with optional detail flags',
191
+ parameters: z.object({
192
+ include_properties: z.boolean().optional()
193
+ .describe('Include common editor properties (position, rotation, etc.)'),
194
+ include_scripts: z.boolean().optional()
195
+ .describe('Include attached script information'),
196
+ max_depth: z.number().int().min(0).optional()
197
+ .describe('Limit traversal depth (0 = only root)')
198
+ }),
199
+ execute: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
200
+ var godot, params, result, structure, err_1;
201
+ var include_properties = _b.include_properties, include_scripts = _b.include_scripts, max_depth = _b.max_depth;
202
+ return __generator(this, function (_c) {
203
+ switch (_c.label) {
204
+ case 0:
205
+ godot = getGodotConnection();
206
+ _c.label = 1;
207
+ case 1:
208
+ _c.trys.push([1, 3, , 4]);
209
+ params = {};
210
+ if (include_properties !== undefined)
211
+ params.include_properties = include_properties;
212
+ if (include_scripts !== undefined)
213
+ params.include_scripts = include_scripts;
214
+ if (max_depth !== undefined)
215
+ params.max_depth = max_depth;
216
+ return [4 /*yield*/, godot.sendCommand('get_editor_scene_structure', params)];
217
+ case 2:
218
+ result = _c.sent();
219
+ if (result.error) {
220
+ return [2 /*return*/, "Scene structure unavailable: ".concat(result.error)];
221
+ }
222
+ if (!result.structure || Object.keys(result.structure).length === 0) {
223
+ return [2 /*return*/, 'No scene is currently open or the scene is empty.'];
224
+ }
225
+ structure = result.structure;
226
+ return [2 /*return*/, [
227
+ "Current Scene: ".concat(result.path),
228
+ "Root Node: ".concat(result.root_node_name, " (").concat(result.root_node_type, ")"),
229
+ '',
230
+ 'Scene Tree:',
231
+ formatNode(structure)
232
+ ].join('\n')];
233
+ case 3:
234
+ err_1 = _c.sent();
235
+ throw new Error("Failed to get scene structure: ".concat(err_1.message));
236
+ case 4: return [2 /*return*/];
237
+ }
238
+ });
239
+ }); },
240
+ },
241
+ {
242
+ name: 'get_runtime_scene_structure',
243
+ description: 'Inspect the live scene tree from the running game via the debugger',
244
+ parameters: z.object({
245
+ include_properties: z.boolean().optional()
246
+ .describe('Include common properties (position, rotation, etc.) when available'),
247
+ include_scripts: z.boolean().optional()
248
+ .describe('Include script information when available'),
249
+ max_depth: z.number().int().min(0).optional()
250
+ .describe('Limit traversal depth (0 = only root)'),
251
+ timeout_ms: z.number().int().min(100).max(5000).optional()
252
+ .describe('How long to wait for a live scene snapshot (milliseconds)')
253
+ }),
254
+ execute: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
255
+ var godot, params, result, structure, scenePath, rootName, rootType, err_2;
256
+ var include_properties = _b.include_properties, include_scripts = _b.include_scripts, max_depth = _b.max_depth, timeout_ms = _b.timeout_ms;
257
+ return __generator(this, function (_c) {
258
+ switch (_c.label) {
259
+ case 0:
260
+ godot = getGodotConnection();
261
+ _c.label = 1;
262
+ case 1:
263
+ _c.trys.push([1, 3, , 4]);
264
+ params = {};
265
+ if (include_properties !== undefined)
266
+ params.include_properties = include_properties;
267
+ if (include_scripts !== undefined)
268
+ params.include_scripts = include_scripts;
269
+ if (max_depth !== undefined)
270
+ params.max_depth = max_depth;
271
+ if (timeout_ms !== undefined)
272
+ params.timeout_ms = timeout_ms;
273
+ return [4 /*yield*/, godot.sendCommand('get_runtime_scene_structure', params)];
274
+ case 2:
275
+ result = _c.sent();
276
+ if (result.error) {
277
+ return [2 /*return*/, "Runtime scene structure unavailable: ".concat(result.error)];
278
+ }
279
+ if (!result.structure) {
280
+ return [2 /*return*/, 'Runtime scene data is unavailable. Ensure the project is running with the debugger attached.'];
281
+ }
282
+ structure = result.structure;
283
+ scenePath = result.scene_path || 'Unknown scene';
284
+ rootName = result.root_node_name || structure.name || 'Root';
285
+ rootType = result.root_node_type || structure.type || 'Node';
286
+ return [2 /*return*/, [
287
+ "Runtime Scene Path: ".concat(scenePath),
288
+ "Root Node: ".concat(rootName, " (").concat(rootType, ")"),
289
+ '',
290
+ 'Live Scene Tree:',
291
+ formatNode(structure, 0, true)
292
+ ].join('\n')];
293
+ case 3:
294
+ err_2 = _c.sent();
295
+ throw new Error("Failed to get runtime scene structure: ".concat(err_2.message));
296
+ case 4: return [2 /*return*/];
297
+ }
298
+ });
299
+ }); },
300
+ },
301
+ {
302
+ name: 'get_debug_output',
303
+ description: 'Get the debug output from the Godot editor',
304
+ parameters: z.object({}),
305
+ execute: function () { return __awaiter(void 0, void 0, void 0, function () {
306
+ var godot, result, outputText, diagnostics, err_3;
307
+ return __generator(this, function (_a) {
308
+ switch (_a.label) {
309
+ case 0:
310
+ godot = getGodotConnection();
311
+ _a.label = 1;
312
+ case 1:
313
+ _a.trys.push([1, 3, , 4]);
314
+ return [4 /*yield*/, godot.sendCommand('get_debug_output', {})];
315
+ case 2:
316
+ result = _a.sent();
317
+ outputText = typeof result.output === 'string' ? result.output : '';
318
+ diagnostics = safeGetDiagnostics(result);
319
+ if (!outputText || outputText.length === 0) {
320
+ return [2 /*return*/, formatEmptyDebugOutput(diagnostics)];
321
+ }
322
+ return [2 /*return*/, "Debug Output:\n".concat(outputText)];
323
+ case 3:
324
+ err_3 = _a.sent();
325
+ throw new Error("Failed to get debug output: ".concat(err_3.message));
326
+ case 4: return [2 /*return*/];
327
+ }
328
+ });
329
+ }); },
330
+ },
331
+ {
332
+ name: 'get_editor_errors',
333
+ description: 'Read the Errors tab from the Godot editor bottom panel.',
334
+ parameters: z.object({}),
335
+ execute: function () { return __awaiter(void 0, void 0, void 0, function () {
336
+ var godot, result, text, lines, lineCount, diagnostics, detailLines, headerSections, body, err_4;
337
+ return __generator(this, function (_a) {
338
+ switch (_a.label) {
339
+ case 0:
340
+ godot = getGodotConnection();
341
+ _a.label = 1;
342
+ case 1:
343
+ _a.trys.push([1, 3, , 4]);
344
+ return [4 /*yield*/, godot.sendCommand('get_editor_errors', {})];
345
+ case 2:
346
+ result = _a.sent();
347
+ text = typeof (result === null || result === void 0 ? void 0 : result.text) === 'string' ? result.text : '';
348
+ lines = safeGetStringArray(result === null || result === void 0 ? void 0 : result.lines);
349
+ lineCount = typeof (result === null || result === void 0 ? void 0 : result.line_count) === 'number'
350
+ ? result.line_count
351
+ : (lines.length > 0 ? lines.length : (text.length > 0 ? text.split('\n').length : 0));
352
+ diagnostics = safeGetDiagnostics(result);
353
+ detailLines = [];
354
+ if (diagnostics.control_path) {
355
+ detailLines.push("Control path: ".concat(diagnostics.control_path));
356
+ }
357
+ else if (diagnostics.control_class) {
358
+ detailLines.push("Control class: ".concat(diagnostics.control_class));
359
+ }
360
+ if (typeof diagnostics.timestamp === 'number') {
361
+ detailLines.push("Captured: ".concat(new Date(diagnostics.timestamp).toISOString()));
362
+ }
363
+ if (diagnostics.search_summary) {
364
+ detailLines.push("Search summary: ".concat(diagnostics.search_summary));
365
+ }
366
+ if (text.length === 0) {
367
+ return [2 /*return*/, detailLines.length > 0
368
+ ? "Errors tab is empty.\n".concat(detailLines.join('\n'))
369
+ : 'Errors tab is empty.'];
370
+ }
371
+ headerSections = ['Errors Tab Contents', "Lines: ".concat(lineCount)];
372
+ if (detailLines.length > 0) {
373
+ headerSections.push(detailLines.join(' | '));
374
+ }
375
+ body = lines.length > 0 ? lines.join('\n') : text;
376
+ return [2 /*return*/, "".concat(headerSections.join('\n'), "\n\n").concat(body)];
377
+ case 3:
378
+ err_4 = _a.sent();
379
+ throw new Error("Failed to read Errors tab: ".concat(err_4.message));
380
+ case 4: return [2 /*return*/];
381
+ }
382
+ });
383
+ }); },
384
+ },
385
+ {
386
+ name: 'get_stack_trace_panel',
387
+ description: 'Capture the Godot debugger Stack Trace panel text and structured frames.',
388
+ parameters: z.object({
389
+ session_id: z.number().int().optional()
390
+ .describe('Optional debugger session ID to associate with the capture (defaults to the active session).')
391
+ }),
392
+ execute: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
393
+ var godot, params, result, panel, diagnostics, lines, frames_1, lineCount, resolvedSessionId, header, frameSection, body, err_5;
394
+ var _c;
395
+ var session_id = _b.session_id;
396
+ return __generator(this, function (_d) {
397
+ switch (_d.label) {
398
+ case 0:
399
+ godot = getGodotConnection();
400
+ params = {};
401
+ if (session_id !== undefined) {
402
+ params.session_id = session_id;
403
+ }
404
+ _d.label = 1;
405
+ case 1:
406
+ _d.trys.push([1, 3, , 4]);
407
+ return [4 /*yield*/, godot.sendCommand('get_stack_trace_panel', params)];
408
+ case 2:
409
+ result = _d.sent();
410
+ panel = ((_c = result === null || result === void 0 ? void 0 : result.stack_trace_panel) !== null && _c !== void 0 ? _c : {});
411
+ diagnostics = safeGetDiagnostics(panel);
412
+ lines = safeGetStringArray(panel.lines);
413
+ frames_1 = Array.isArray(panel.frames) ? panel.frames : [];
414
+ lineCount = typeof panel.line_count === 'number' ? panel.line_count : lines.length;
415
+ resolvedSessionId = typeof (result === null || result === void 0 ? void 0 : result.session_id) === 'number' ? result.session_id : undefined;
416
+ header = formatPanelHeader(diagnostics, lineCount, frames_1.length, 'Stack trace panel captured successfully');
417
+ if (resolvedSessionId !== undefined && resolvedSessionId >= 0) {
418
+ header.push("Session ID: ".concat(resolvedSessionId));
419
+ }
420
+ frameSection = formatStackFrames(frames_1);
421
+ body = lines.length > 0
422
+ ? lines.join('\n')
423
+ : (typeof panel.text === 'string' && panel.text.length > 0
424
+ ? panel.text
425
+ : 'Stack Trace tab is empty.');
426
+ return [2 /*return*/, [
427
+ header.join('\n'),
428
+ '',
429
+ 'Parsed Frames:',
430
+ frameSection,
431
+ '',
432
+ 'Stack Trace Panel:',
433
+ body
434
+ ].join('\n')];
435
+ case 3:
436
+ err_5 = _d.sent();
437
+ throw new Error("Failed to capture stack trace panel: ".concat(err_5.message));
438
+ case 4: return [2 /*return*/];
439
+ }
440
+ });
441
+ }); },
442
+ },
443
+ {
444
+ name: 'get_stack_frames_panel',
445
+ description: 'Capture the Stack Frames panel contents (tree or text fallback) from the Godot editor.',
446
+ parameters: z.object({
447
+ session_id: z.number().int().optional()
448
+ .describe('Optional debugger session ID (defaults to the active session).'),
449
+ refresh: z.boolean().optional()
450
+ .describe('Request a fresh stack dump from the debugger before capturing.')
451
+ }),
452
+ execute: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
453
+ var godot, params, result, panel, diagnostics, lines, frames_2, lineCount, header, frameSection, body, err_6;
454
+ var _c;
455
+ var session_id = _b.session_id, refresh = _b.refresh;
456
+ return __generator(this, function (_d) {
457
+ switch (_d.label) {
458
+ case 0:
459
+ godot = getGodotConnection();
460
+ params = {};
461
+ if (session_id !== undefined)
462
+ params.session_id = session_id;
463
+ if (refresh !== undefined)
464
+ params.refresh = refresh;
465
+ _d.label = 1;
466
+ case 1:
467
+ _d.trys.push([1, 3, , 4]);
468
+ return [4 /*yield*/, godot.sendCommand('get_stack_frames_panel', params)];
469
+ case 2:
470
+ result = _d.sent();
471
+ panel = ((_c = result === null || result === void 0 ? void 0 : result.stack_frames_panel) !== null && _c !== void 0 ? _c : {});
472
+ diagnostics = safeGetDiagnostics(panel);
473
+ lines = safeGetStringArray(panel.lines);
474
+ frames_2 = Array.isArray(panel.frames) ? panel.frames : [];
475
+ lineCount = typeof panel.line_count === 'number' ? panel.line_count : lines.length;
476
+ header = formatPanelHeader(diagnostics, lineCount, frames_2.length, 'Stack Frames panel captured successfully');
477
+ frameSection = formatStackFrames(frames_2);
478
+ body = lines.length > 0
479
+ ? lines.join('\n')
480
+ : (typeof panel.text === 'string' && panel.text.length > 0
481
+ ? panel.text
482
+ : 'Stack Frames tab is empty.');
483
+ return [2 /*return*/, [
484
+ header.join('\n'),
485
+ '',
486
+ 'Parsed Frames:',
487
+ frameSection,
488
+ '',
489
+ 'Stack Frames Panel:',
490
+ body
491
+ ].join('\n')];
492
+ case 3:
493
+ err_6 = _d.sent();
494
+ throw new Error("Failed to capture stack frames panel: ".concat(err_6.message));
495
+ case 4: return [2 /*return*/];
496
+ }
497
+ });
498
+ }); },
499
+ },
500
+ {
501
+ name: 'evaluate_runtime_expression',
502
+ description: 'Evaluate a GDScript expression inside the running game via the remote debugger',
503
+ parameters: z.object({
504
+ expression: z.string().min(1)
505
+ .describe('Expression to evaluate in the runtime context (executed with the chosen node as self).'),
506
+ context_path: z.string().optional()
507
+ .describe('Optional node path (e.g. "/root/Main/Player") to use as the evaluation context.'),
508
+ capture_prints: z.boolean().optional()
509
+ .describe('Include print output from the expression (default true).'),
510
+ timeout_ms: z.number().int().min(100).max(5000).optional()
511
+ .describe('How long to wait for the evaluation result in milliseconds.')
512
+ }),
513
+ execute: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
514
+ var godot, params, result, success, formattedValue, outputLines, sections, err_7;
515
+ var expression = _b.expression, context_path = _b.context_path, capture_prints = _b.capture_prints, timeout_ms = _b.timeout_ms;
516
+ return __generator(this, function (_c) {
517
+ switch (_c.label) {
518
+ case 0:
519
+ godot = getGodotConnection();
520
+ params = { expression: expression };
521
+ if (context_path !== undefined)
522
+ params.context_path = context_path;
523
+ if (capture_prints !== undefined)
524
+ params.capture_prints = capture_prints;
525
+ if (timeout_ms !== undefined)
526
+ params.timeout_ms = timeout_ms;
527
+ _c.label = 1;
528
+ case 1:
529
+ _c.trys.push([1, 3, , 4]);
530
+ return [4 /*yield*/, godot.sendCommand('evaluate_runtime', params)];
531
+ case 2:
532
+ result = _c.sent();
533
+ if (!result) {
534
+ return [2 /*return*/, 'Runtime evaluation did not return a result.'];
535
+ }
536
+ if (result.error) {
537
+ return [2 /*return*/, "Runtime evaluation failed: ".concat(result.error)];
538
+ }
539
+ success = result.success !== false;
540
+ formattedValue = formatValue(result.result);
541
+ outputLines = safeGetStringArray(result.output);
542
+ sections = [];
543
+ sections.push(success ? 'Runtime evaluation succeeded.' : 'Runtime evaluation completed with errors.');
544
+ sections.push("Result: ".concat(formattedValue));
545
+ if (outputLines.length > 0) {
546
+ sections.push('Print Output:');
547
+ sections.push(outputLines.join('\n'));
548
+ }
549
+ if (result.error && result.error.length > 0 && success) {
550
+ sections.push("Notes: ".concat(result.error));
551
+ }
552
+ return [2 /*return*/, sections.join('\n')];
553
+ case 3:
554
+ err_7 = _c.sent();
555
+ throw new Error("Failed to evaluate expression: ".concat(err_7.message));
556
+ case 4: return [2 /*return*/];
557
+ }
558
+ });
559
+ }); },
560
+ },
561
+ {
562
+ name: 'clear_debug_output',
563
+ description: 'Clear the Godot editor Output panel and reset streaming state.',
564
+ parameters: z.object({}),
565
+ execute: function () { return __awaiter(void 0, void 0, void 0, function () {
566
+ var godot, result, diagnostics, reason, method, attempts, timestamp, err_8;
567
+ return __generator(this, function (_a) {
568
+ switch (_a.label) {
569
+ case 0:
570
+ godot = getGodotConnection();
571
+ _a.label = 1;
572
+ case 1:
573
+ _a.trys.push([1, 3, , 4]);
574
+ return [4 /*yield*/, godot.sendCommand('clear_debug_output', {})];
575
+ case 2:
576
+ result = _a.sent();
577
+ diagnostics = safeGetDiagnostics(result);
578
+ if (!(result === null || result === void 0 ? void 0 : result.cleared)) {
579
+ reason = typeof (result === null || result === void 0 ? void 0 : result.message) === 'string' && result.message.length > 0
580
+ ? result.message
581
+ : (diagnostics.error || 'Unknown reason');
582
+ return [2 /*return*/, "Failed to clear debug output: ".concat(reason)];
583
+ }
584
+ method = typeof result.method === 'string' && result.method.length > 0
585
+ ? result.method
586
+ : 'unspecified method';
587
+ attempts = Array.isArray(diagnostics.attempts)
588
+ ? diagnostics.attempts.map(function (entry) { return String(entry); }).join(', ')
589
+ : 'n/a';
590
+ timestamp = typeof diagnostics.timestamp === 'number'
591
+ ? new Date(diagnostics.timestamp).toISOString()
592
+ : 'n/a';
593
+ return [2 /*return*/, [
594
+ 'Debug Output panel cleared successfully.',
595
+ "Method: ".concat(method),
596
+ "Attempts: ".concat(attempts),
597
+ "Timestamp: ".concat(timestamp)
598
+ ].join('\n')];
599
+ case 3:
600
+ err_8 = _a.sent();
601
+ throw new Error("Failed to clear debug output: ".concat(err_8.message));
602
+ case 4: return [2 /*return*/];
603
+ }
604
+ });
605
+ }); },
606
+ },
607
+ {
608
+ name: 'stream_debug_output',
609
+ description: 'Subscribe or unsubscribe from live streaming of the editor Output panel.',
610
+ parameters: z.object({
611
+ action: z.enum(['start', 'stop']).default('start')
612
+ .describe('Choose "start" to begin streaming or "stop" to unsubscribe.')
613
+ }),
614
+ execute: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
615
+ var godot;
616
+ var action = _b.action;
617
+ return __generator(this, function (_c) {
618
+ switch (_c.label) {
619
+ case 0:
620
+ godot = getGodotConnection();
621
+ if (!debugOutputListenerAttached) {
622
+ debugOutputListenerAttached = true;
623
+ godot.on('debug_output_frame', function (frame) {
624
+ try {
625
+ var frameData = frame;
626
+ var lines = safeGetStringArray(frameData.lines);
627
+ var chunk = typeof frameData.chunk === 'string' ? frameData.chunk : '';
628
+ if (frameData.reset) {
629
+ console.log('\n[Godot Debug] Log reset.');
630
+ }
631
+ if (lines.length > 0) {
632
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
633
+ var line = lines_1[_i];
634
+ console.log("[Godot Debug] ".concat(line));
635
+ }
636
+ }
637
+ else if (chunk.length > 0) {
638
+ console.log("[Godot Debug] ".concat(chunk));
639
+ }
640
+ }
641
+ catch (err) {
642
+ console.error('Failed to print debug frame:', err);
643
+ }
644
+ });
645
+ }
646
+ if (!(action === 'start')) return [3 /*break*/, 2];
647
+ return [4 /*yield*/, godot.sendCommand('subscribe_debug_output', {})];
648
+ case 1:
649
+ _c.sent();
650
+ return [2 /*return*/, 'Subscribed to live debug output. New log lines will appear in the console.'];
651
+ case 2: return [4 /*yield*/, godot.sendCommand('unsubscribe_debug_output', {})];
652
+ case 3:
653
+ _c.sent();
654
+ return [2 /*return*/, 'Unsubscribed from live debug output.'];
655
+ }
656
+ });
657
+ }); },
658
+ },
659
+ {
660
+ name: 'clear_editor_errors',
661
+ description: 'Clear the Errors tab in the Godot editor debugger panel.',
662
+ parameters: z.object({}),
663
+ execute: function () { return __awaiter(void 0, void 0, void 0, function () {
664
+ var godot, result, diagnostics, reason, method, attempts, timestamp, err_9;
665
+ return __generator(this, function (_a) {
666
+ switch (_a.label) {
667
+ case 0:
668
+ godot = getGodotConnection();
669
+ _a.label = 1;
670
+ case 1:
671
+ _a.trys.push([1, 3, , 4]);
672
+ return [4 /*yield*/, godot.sendCommand('clear_editor_errors', {})];
673
+ case 2:
674
+ result = _a.sent();
675
+ diagnostics = safeGetDiagnostics(result);
676
+ if (!(result === null || result === void 0 ? void 0 : result.cleared)) {
677
+ reason = typeof (result === null || result === void 0 ? void 0 : result.message) === 'string' && result.message.length > 0
678
+ ? result.message
679
+ : (diagnostics.error || 'Unknown reason');
680
+ return [2 /*return*/, "Failed to clear Errors tab: ".concat(reason)];
681
+ }
682
+ method = typeof result.method === 'string' && result.method.length > 0
683
+ ? result.method
684
+ : 'unspecified method';
685
+ attempts = Array.isArray(diagnostics.attempts)
686
+ ? diagnostics.attempts.map(function (entry) { return String(entry); }).join(', ')
687
+ : 'n/a';
688
+ timestamp = typeof diagnostics.timestamp === 'number'
689
+ ? new Date(diagnostics.timestamp).toISOString()
690
+ : 'n/a';
691
+ return [2 /*return*/, [
692
+ 'Errors tab cleared successfully.',
693
+ "Method: ".concat(method),
694
+ "Attempts: ".concat(attempts),
695
+ "Timestamp: ".concat(timestamp)
696
+ ].join('\n')];
697
+ case 3:
698
+ err_9 = _a.sent();
699
+ throw new Error("Failed to clear Errors tab: ".concat(err_9.message));
700
+ case 4: return [2 /*return*/];
701
+ }
702
+ });
703
+ }); },
704
+ },
705
+ ];
706
+ //# sourceMappingURL=enhanced_tools.js.map