@houtini/lm 1.0.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 (260) hide show
  1. package/CHANGELOG.md +273 -0
  2. package/LICENSE +21 -0
  3. package/README.md +203 -0
  4. package/dist/cache/analysis-cache.d.ts +33 -0
  5. package/dist/cache/analysis-cache.d.ts.map +1 -0
  6. package/dist/cache/analysis-cache.js +56 -0
  7. package/dist/cache/analysis-cache.js.map +1 -0
  8. package/dist/cache/cache-manager.d.ts +29 -0
  9. package/dist/cache/cache-manager.d.ts.map +1 -0
  10. package/dist/cache/cache-manager.js +85 -0
  11. package/dist/cache/cache-manager.js.map +1 -0
  12. package/dist/cache/index.d.ts +16 -0
  13. package/dist/cache/index.d.ts.map +1 -0
  14. package/dist/cache/index.js +17 -0
  15. package/dist/cache/index.js.map +1 -0
  16. package/dist/cache/prompt-cache.d.ts +33 -0
  17. package/dist/cache/prompt-cache.d.ts.map +1 -0
  18. package/dist/cache/prompt-cache.js +61 -0
  19. package/dist/cache/prompt-cache.js.map +1 -0
  20. package/dist/config.d.ts +43 -0
  21. package/dist/config.d.ts.map +1 -0
  22. package/dist/config.js +70 -0
  23. package/dist/config.js.map +1 -0
  24. package/dist/core/ThreeStagePromptManager.d.ts +39 -0
  25. package/dist/core/ThreeStagePromptManager.d.ts.map +1 -0
  26. package/dist/core/ThreeStagePromptManager.js +176 -0
  27. package/dist/core/ThreeStagePromptManager.js.map +1 -0
  28. package/dist/index.d.ts +6 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +230 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/plugins/base-plugin.d.ts +47 -0
  33. package/dist/plugins/base-plugin.d.ts.map +1 -0
  34. package/dist/plugins/base-plugin.js +90 -0
  35. package/dist/plugins/base-plugin.js.map +1 -0
  36. package/dist/plugins/index.d.ts +58 -0
  37. package/dist/plugins/index.d.ts.map +1 -0
  38. package/dist/plugins/index.js +161 -0
  39. package/dist/plugins/index.js.map +1 -0
  40. package/dist/plugins/types.d.ts +5 -0
  41. package/dist/plugins/types.d.ts.map +1 -0
  42. package/dist/plugins/types.js +5 -0
  43. package/dist/plugins/types.js.map +1 -0
  44. package/dist/prompts/analyze/code-quality.d.ts +116 -0
  45. package/dist/prompts/analyze/code-quality.d.ts.map +1 -0
  46. package/dist/prompts/analyze/code-quality.js +433 -0
  47. package/dist/prompts/analyze/code-quality.js.map +1 -0
  48. package/dist/prompts/analyze/compare-integration.d.ts +130 -0
  49. package/dist/prompts/analyze/compare-integration.d.ts.map +1 -0
  50. package/dist/prompts/analyze/compare-integration.js +543 -0
  51. package/dist/prompts/analyze/compare-integration.js.map +1 -0
  52. package/dist/prompts/analyze/count-files.d.ts +109 -0
  53. package/dist/prompts/analyze/count-files.d.ts.map +1 -0
  54. package/dist/prompts/analyze/count-files.js +399 -0
  55. package/dist/prompts/analyze/count-files.js.map +1 -0
  56. package/dist/prompts/analyze/database-queries.d.ts +156 -0
  57. package/dist/prompts/analyze/database-queries.d.ts.map +1 -0
  58. package/dist/prompts/analyze/database-queries.js +759 -0
  59. package/dist/prompts/analyze/database-queries.js.map +1 -0
  60. package/dist/prompts/analyze/dependencies.d.ts +97 -0
  61. package/dist/prompts/analyze/dependencies.d.ts.map +1 -0
  62. package/dist/prompts/analyze/dependencies.js +333 -0
  63. package/dist/prompts/analyze/dependencies.js.map +1 -0
  64. package/dist/prompts/analyze/diff-signatures.d.ts +139 -0
  65. package/dist/prompts/analyze/diff-signatures.d.ts.map +1 -0
  66. package/dist/prompts/analyze/diff-signatures.js +702 -0
  67. package/dist/prompts/analyze/diff-signatures.js.map +1 -0
  68. package/dist/prompts/analyze/find-patterns.d.ts +128 -0
  69. package/dist/prompts/analyze/find-patterns.d.ts.map +1 -0
  70. package/dist/prompts/analyze/find-patterns.js +520 -0
  71. package/dist/prompts/analyze/find-patterns.js.map +1 -0
  72. package/dist/prompts/analyze/find-unused-css.d.ts +151 -0
  73. package/dist/prompts/analyze/find-unused-css.d.ts.map +1 -0
  74. package/dist/prompts/analyze/find-unused-css.js +754 -0
  75. package/dist/prompts/analyze/find-unused-css.js.map +1 -0
  76. package/dist/prompts/analyze/n8n-workflow.d.ts +137 -0
  77. package/dist/prompts/analyze/n8n-workflow.d.ts.map +1 -0
  78. package/dist/prompts/analyze/n8n-workflow.js +529 -0
  79. package/dist/prompts/analyze/n8n-workflow.js.map +1 -0
  80. package/dist/prompts/analyze/project-structure.d.ts +126 -0
  81. package/dist/prompts/analyze/project-structure.d.ts.map +1 -0
  82. package/dist/prompts/analyze/project-structure.js +569 -0
  83. package/dist/prompts/analyze/project-structure.js.map +1 -0
  84. package/dist/prompts/analyze/security-audit.d.ts +142 -0
  85. package/dist/prompts/analyze/security-audit.d.ts.map +1 -0
  86. package/dist/prompts/analyze/security-audit.js +637 -0
  87. package/dist/prompts/analyze/security-audit.js.map +1 -0
  88. package/dist/prompts/analyze/single-file.d.ts +162 -0
  89. package/dist/prompts/analyze/single-file.d.ts.map +1 -0
  90. package/dist/prompts/analyze/single-file.js +665 -0
  91. package/dist/prompts/analyze/single-file.js.map +1 -0
  92. package/dist/prompts/analyze/trace-execution.d.ts +126 -0
  93. package/dist/prompts/analyze/trace-execution.d.ts.map +1 -0
  94. package/dist/prompts/analyze/trace-execution.js +609 -0
  95. package/dist/prompts/analyze/trace-execution.js.map +1 -0
  96. package/dist/prompts/analyze/wordpress-plugin-audit.d.ts +116 -0
  97. package/dist/prompts/analyze/wordpress-plugin-audit.d.ts.map +1 -0
  98. package/dist/prompts/analyze/wordpress-plugin-audit.js +454 -0
  99. package/dist/prompts/analyze/wordpress-plugin-audit.js.map +1 -0
  100. package/dist/prompts/analyze/wordpress-security.d.ts +146 -0
  101. package/dist/prompts/analyze/wordpress-security.d.ts.map +1 -0
  102. package/dist/prompts/analyze/wordpress-security.js +698 -0
  103. package/dist/prompts/analyze/wordpress-security.js.map +1 -0
  104. package/dist/prompts/analyze/wordpress-theme-audit.d.ts +114 -0
  105. package/dist/prompts/analyze/wordpress-theme-audit.d.ts.map +1 -0
  106. package/dist/prompts/analyze/wordpress-theme-audit.js +538 -0
  107. package/dist/prompts/analyze/wordpress-theme-audit.js.map +1 -0
  108. package/dist/prompts/custom/custom-prompt.d.ts +135 -0
  109. package/dist/prompts/custom/custom-prompt.d.ts.map +1 -0
  110. package/dist/prompts/custom/custom-prompt.js +419 -0
  111. package/dist/prompts/custom/custom-prompt.js.map +1 -0
  112. package/dist/prompts/fun/arcade-game.d.ts +152 -0
  113. package/dist/prompts/fun/arcade-game.d.ts.map +1 -0
  114. package/dist/prompts/fun/arcade-game.js +653 -0
  115. package/dist/prompts/fun/arcade-game.js.map +1 -0
  116. package/dist/prompts/fun/create_text_adventure.d.ts +100 -0
  117. package/dist/prompts/fun/create_text_adventure.d.ts.map +1 -0
  118. package/dist/prompts/fun/create_text_adventure.js +397 -0
  119. package/dist/prompts/fun/create_text_adventure.js.map +1 -0
  120. package/dist/prompts/fun/css-art-generator.d.ts +168 -0
  121. package/dist/prompts/fun/css-art-generator.d.ts.map +1 -0
  122. package/dist/prompts/fun/css-art-generator.js +827 -0
  123. package/dist/prompts/fun/css-art-generator.js.map +1 -0
  124. package/dist/prompts/generate/project-documentation.d.ts +137 -0
  125. package/dist/prompts/generate/project-documentation.d.ts.map +1 -0
  126. package/dist/prompts/generate/project-documentation.js +666 -0
  127. package/dist/prompts/generate/project-documentation.js.map +1 -0
  128. package/dist/prompts/generate/refactoring.d.ts +164 -0
  129. package/dist/prompts/generate/refactoring.d.ts.map +1 -0
  130. package/dist/prompts/generate/refactoring.js +621 -0
  131. package/dist/prompts/generate/refactoring.js.map +1 -0
  132. package/dist/prompts/generate/responsive-component.d.ts +147 -0
  133. package/dist/prompts/generate/responsive-component.d.ts.map +1 -0
  134. package/dist/prompts/generate/responsive-component.js +955 -0
  135. package/dist/prompts/generate/responsive-component.js.map +1 -0
  136. package/dist/prompts/generate/typescript-conversion.d.ts +144 -0
  137. package/dist/prompts/generate/typescript-conversion.d.ts.map +1 -0
  138. package/dist/prompts/generate/typescript-conversion.js +527 -0
  139. package/dist/prompts/generate/typescript-conversion.js.map +1 -0
  140. package/dist/prompts/generate/unit-tests.d.ts +139 -0
  141. package/dist/prompts/generate/unit-tests.d.ts.map +1 -0
  142. package/dist/prompts/generate/unit-tests.js +578 -0
  143. package/dist/prompts/generate/unit-tests.js.map +1 -0
  144. package/dist/prompts/generate/wordpress-plugin.d.ts +179 -0
  145. package/dist/prompts/generate/wordpress-plugin.d.ts.map +1 -0
  146. package/dist/prompts/generate/wordpress-plugin.js +763 -0
  147. package/dist/prompts/generate/wordpress-plugin.js.map +1 -0
  148. package/dist/prompts/generate/wordpress-theme-from-static.d.ts +177 -0
  149. package/dist/prompts/generate/wordpress-theme-from-static.d.ts.map +1 -0
  150. package/dist/prompts/generate/wordpress-theme-from-static.js +695 -0
  151. package/dist/prompts/generate/wordpress-theme-from-static.js.map +1 -0
  152. package/dist/prompts/shared/cache-manager.d.ts +45 -0
  153. package/dist/prompts/shared/cache-manager.d.ts.map +1 -0
  154. package/dist/prompts/shared/cache-manager.js +129 -0
  155. package/dist/prompts/shared/cache-manager.js.map +1 -0
  156. package/dist/prompts/shared/helpers.d.ts +39 -0
  157. package/dist/prompts/shared/helpers.d.ts.map +1 -0
  158. package/dist/prompts/shared/helpers.js +151 -0
  159. package/dist/prompts/shared/helpers.js.map +1 -0
  160. package/dist/prompts/shared/templates.d.ts +35 -0
  161. package/dist/prompts/shared/templates.d.ts.map +1 -0
  162. package/dist/prompts/shared/templates.js +77 -0
  163. package/dist/prompts/shared/templates.js.map +1 -0
  164. package/dist/prompts/shared/types.d.ts +112 -0
  165. package/dist/prompts/shared/types.d.ts.map +1 -0
  166. package/dist/prompts/shared/types.js +5 -0
  167. package/dist/prompts/shared/types.js.map +1 -0
  168. package/dist/prompts/system/find-unused-files.d.ts +106 -0
  169. package/dist/prompts/system/find-unused-files.d.ts.map +1 -0
  170. package/dist/prompts/system/find-unused-files.js +353 -0
  171. package/dist/prompts/system/find-unused-files.js.map +1 -0
  172. package/dist/security/index.d.ts +39 -0
  173. package/dist/security/index.d.ts.map +1 -0
  174. package/dist/security/index.js +46 -0
  175. package/dist/security/index.js.map +1 -0
  176. package/dist/security/integration-helpers.d.ts +121 -0
  177. package/dist/security/integration-helpers.d.ts.map +1 -0
  178. package/dist/security/integration-helpers.js +190 -0
  179. package/dist/security/integration-helpers.js.map +1 -0
  180. package/dist/security/output-encoder.d.ts +94 -0
  181. package/dist/security/output-encoder.d.ts.map +1 -0
  182. package/dist/security/output-encoder.js +295 -0
  183. package/dist/security/output-encoder.js.map +1 -0
  184. package/dist/security/prompt-injection-guard.d.ts +59 -0
  185. package/dist/security/prompt-injection-guard.d.ts.map +1 -0
  186. package/dist/security/prompt-injection-guard.js +249 -0
  187. package/dist/security/prompt-injection-guard.js.map +1 -0
  188. package/dist/security/sanitisation.d.ts +67 -0
  189. package/dist/security/sanitisation.d.ts.map +1 -0
  190. package/dist/security/sanitisation.js +398 -0
  191. package/dist/security/sanitisation.js.map +1 -0
  192. package/dist/security/security-service.d.ts +103 -0
  193. package/dist/security/security-service.d.ts.map +1 -0
  194. package/dist/security/security-service.js +303 -0
  195. package/dist/security/security-service.js.map +1 -0
  196. package/dist/security-config.d.ts +45 -0
  197. package/dist/security-config.d.ts.map +1 -0
  198. package/dist/security-config.js +63 -0
  199. package/dist/security-config.js.map +1 -0
  200. package/dist/system/function-list.d.ts +61 -0
  201. package/dist/system/function-list.d.ts.map +1 -0
  202. package/dist/system/function-list.js +111 -0
  203. package/dist/system/function-list.js.map +1 -0
  204. package/dist/system/function-registry.d.ts +23 -0
  205. package/dist/system/function-registry.d.ts.map +1 -0
  206. package/dist/system/function-registry.js +136 -0
  207. package/dist/system/function-registry.js.map +1 -0
  208. package/dist/system/health-check.d.ts +33 -0
  209. package/dist/system/health-check.d.ts.map +1 -0
  210. package/dist/system/health-check.js +98 -0
  211. package/dist/system/health-check.js.map +1 -0
  212. package/dist/system/path-resolver.d.ts +55 -0
  213. package/dist/system/path-resolver.d.ts.map +1 -0
  214. package/dist/system/path-resolver.js +90 -0
  215. package/dist/system/path-resolver.js.map +1 -0
  216. package/dist/templates/plugin-template.d.ts +121 -0
  217. package/dist/templates/plugin-template.d.ts.map +1 -0
  218. package/dist/templates/plugin-template.js +450 -0
  219. package/dist/templates/plugin-template.js.map +1 -0
  220. package/dist/types/chunking-types.d.ts +88 -0
  221. package/dist/types/chunking-types.d.ts.map +1 -0
  222. package/dist/types/chunking-types.js +18 -0
  223. package/dist/types/chunking-types.js.map +1 -0
  224. package/dist/types/prompt-stages.d.ts +42 -0
  225. package/dist/types/prompt-stages.d.ts.map +1 -0
  226. package/dist/types/prompt-stages.js +6 -0
  227. package/dist/types/prompt-stages.js.map +1 -0
  228. package/dist/types.d.ts +46 -0
  229. package/dist/types.d.ts.map +1 -0
  230. package/dist/types.js +6 -0
  231. package/dist/types.js.map +1 -0
  232. package/dist/utils/css-parser.d.ts +26 -0
  233. package/dist/utils/css-parser.d.ts.map +1 -0
  234. package/dist/utils/css-parser.js +117 -0
  235. package/dist/utils/css-parser.js.map +1 -0
  236. package/dist/utils/path-resolver.d.ts +13 -0
  237. package/dist/utils/path-resolver.d.ts.map +1 -0
  238. package/dist/utils/path-resolver.js +78 -0
  239. package/dist/utils/path-resolver.js.map +1 -0
  240. package/dist/utils/plugin-utilities.d.ts +171 -0
  241. package/dist/utils/plugin-utilities.d.ts.map +1 -0
  242. package/dist/utils/plugin-utilities.js +221 -0
  243. package/dist/utils/plugin-utilities.js.map +1 -0
  244. package/dist/utils/streamHandler.d.ts +3 -0
  245. package/dist/utils/streamHandler.d.ts.map +1 -0
  246. package/dist/utils/streamHandler.js +137 -0
  247. package/dist/utils/streamHandler.js.map +1 -0
  248. package/dist/validation/output-validator.d.ts +136 -0
  249. package/dist/validation/output-validator.d.ts.map +1 -0
  250. package/dist/validation/output-validator.js +262 -0
  251. package/dist/validation/output-validator.js.map +1 -0
  252. package/dist/validation/response-factory.d.ts +44 -0
  253. package/dist/validation/response-factory.d.ts.map +1 -0
  254. package/dist/validation/response-factory.js +202 -0
  255. package/dist/validation/response-factory.js.map +1 -0
  256. package/dist/validation/schemas.d.ts +519 -0
  257. package/dist/validation/schemas.d.ts.map +1 -0
  258. package/dist/validation/schemas.js +6 -0
  259. package/dist/validation/schemas.js.map +1 -0
  260. package/package.json +72 -0
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Plugin Execution Utilities - Modern v4.2
3
+ *
4
+ * Shared utilities to reduce code duplication across plugins
5
+ * Common patterns for model setup, token calculation, and response processing
6
+ */
7
+ import { ResponseFactory } from '../validation/response-factory.js';
8
+ import { promises as fs } from 'fs';
9
+ import { join, extname } from 'path';
10
+ /**
11
+ * Model setup and validation utility
12
+ * Handles common model loading and context length detection
13
+ */
14
+ export class ModelSetup {
15
+ static async getReadyModel(llmClient) {
16
+ const models = await llmClient.llm.listLoaded();
17
+ if (models.length === 0) {
18
+ throw new Error('No model loaded in LM Studio. Please load a model first.');
19
+ }
20
+ const model = models[0];
21
+ const contextLength = await model.getContextLength() || 23832;
22
+ return { model, contextLength };
23
+ }
24
+ }
25
+ /**
26
+ * Dynamic token calculation utility
27
+ * Calculates optimal maxTokens based on content size and context window
28
+ */
29
+ export class TokenCalculator {
30
+ /**
31
+ * Calculate optimal maxTokens for single-stage execution
32
+ */
33
+ static calculateForDirect(stages, contextLength, options = {}) {
34
+ const { minTokens = 1000, maxTokens = Math.floor(contextLength * 0.4), bufferTokens = 500 } = options;
35
+ const estimatedInputTokens = Math.floor((stages.systemAndContext.length + stages.dataPayload.length + stages.outputInstructions.length) / 4);
36
+ const calculatedMaxTokens = Math.min(Math.max(minTokens, contextLength - estimatedInputTokens - bufferTokens), maxTokens);
37
+ return calculatedMaxTokens;
38
+ }
39
+ /**
40
+ * Calculate optimal maxTokens for chunked execution
41
+ */
42
+ static calculateForChunked(messages, contextLength, options = {}) {
43
+ const { minTokens = 1500, maxTokens = Math.floor(contextLength * 0.5), bufferTokens = 1000 } = options;
44
+ const totalContent = messages.map(m => m.content).join(' ');
45
+ const estimatedInputTokens = Math.floor(totalContent.length / 4);
46
+ const calculatedMaxTokens = Math.min(Math.max(minTokens, contextLength - estimatedInputTokens - bufferTokens), maxTokens);
47
+ return calculatedMaxTokens;
48
+ }
49
+ /**
50
+ * Calculate optimal maxTokens for multi-file analysis
51
+ */
52
+ static calculateForMultiFile(messages, contextLength, options = {}) {
53
+ const { minTokens = 2000, maxTokens = Math.floor(contextLength * 0.6), bufferTokens = 1000 } = options;
54
+ const totalContent = messages.map(m => m.content).join(' ');
55
+ const estimatedInputTokens = Math.floor(totalContent.length / 4);
56
+ const calculatedMaxTokens = Math.min(Math.max(minTokens, contextLength - estimatedInputTokens - bufferTokens), maxTokens);
57
+ return calculatedMaxTokens;
58
+ }
59
+ }
60
+ /**
61
+ * LM Studio response processing utility
62
+ * Handles streaming response collection with consistent patterns
63
+ */
64
+ export class ResponseProcessor {
65
+ /**
66
+ * Stream and collect response from LM Studio model
67
+ */
68
+ static async collectStreamingResponse(prediction) {
69
+ let response = '';
70
+ for await (const chunk of prediction) {
71
+ if (chunk.content) {
72
+ response += chunk.content;
73
+ }
74
+ }
75
+ return response;
76
+ }
77
+ /**
78
+ * Execute direct model call with standard settings
79
+ */
80
+ static async executeDirect(stages, model, contextLength, functionName, options = {}) {
81
+ const { temperature = 0.1, tokenOptions = {} } = options;
82
+ const messages = [
83
+ { role: 'system', content: stages.systemAndContext },
84
+ { role: 'user', content: stages.dataPayload },
85
+ { role: 'user', content: stages.outputInstructions }
86
+ ];
87
+ const maxTokens = TokenCalculator.calculateForDirect(stages, contextLength, tokenOptions);
88
+ const prediction = model.respond(messages, {
89
+ temperature,
90
+ maxTokens
91
+ });
92
+ const response = await this.collectStreamingResponse(prediction);
93
+ ResponseFactory.setStartTime();
94
+ return ResponseFactory.parseAndCreateResponse(functionName, response, model.identifier || 'unknown');
95
+ }
96
+ /**
97
+ * Execute chunked model call with standard settings
98
+ */
99
+ static async executeChunked(messages, model, contextLength, functionName, analysisType = 'single', options = {}) {
100
+ const { temperature = 0.1, tokenOptions = {} } = options;
101
+ const maxTokens = analysisType === 'multifile'
102
+ ? TokenCalculator.calculateForMultiFile(messages, contextLength, tokenOptions)
103
+ : TokenCalculator.calculateForChunked(messages, contextLength, tokenOptions);
104
+ const prediction = model.respond(messages, {
105
+ temperature,
106
+ maxTokens
107
+ });
108
+ const response = await this.collectStreamingResponse(prediction);
109
+ ResponseFactory.setStartTime();
110
+ return ResponseFactory.parseAndCreateResponse(functionName, response, model.identifier || 'unknown');
111
+ }
112
+ }
113
+ /**
114
+ * Common parameter validation utility
115
+ * Standard validation patterns used across plugins
116
+ */
117
+ export class ParameterValidator {
118
+ /**
119
+ * Validate code/filePath parameter pattern
120
+ */
121
+ static validateCodeOrFile(params, parameterName = 'code/filePath') {
122
+ if (!params.code && !params.filePath) {
123
+ throw new Error(`Either code or filePath must be provided for ${parameterName}`);
124
+ }
125
+ }
126
+ /**
127
+ * Validate project path for multi-file operations
128
+ */
129
+ static validateProjectPath(params) {
130
+ if (!params.projectPath && !params.files) {
131
+ throw new Error('Either projectPath or files array must be provided');
132
+ }
133
+ }
134
+ /**
135
+ * Validate depth parameter range
136
+ */
137
+ static validateDepth(params, min = 1, max = 5) {
138
+ if (params.maxDepth && (params.maxDepth < min || params.maxDepth > max)) {
139
+ throw new Error(`maxDepth must be between ${min} and ${max}`);
140
+ }
141
+ }
142
+ /**
143
+ * Validate enum parameter
144
+ */
145
+ static validateEnum(params, paramName, allowedValues) {
146
+ if (params[paramName] && !allowedValues.includes(params[paramName])) {
147
+ throw new Error(`${paramName} must be one of: ${allowedValues.join(', ')}`);
148
+ }
149
+ }
150
+ }
151
+ /**
152
+ * Error response utility
153
+ * Consistent error handling patterns
154
+ */
155
+ export class ErrorHandler {
156
+ /**
157
+ * Create standardized error response
158
+ */
159
+ static createExecutionError(functionName, error, operation = 'execute') {
160
+ return ResponseFactory.createErrorResponse(functionName, 'EXECUTION_ERROR', `Failed to ${operation}: ${error.message}`, { originalError: error.message }, 'unknown');
161
+ }
162
+ /**
163
+ * Create parameter validation error response
164
+ */
165
+ static createValidationError(functionName, error) {
166
+ return ResponseFactory.createErrorResponse(functionName, 'VALIDATION_ERROR', `Parameter validation failed: ${error.message}`, { originalError: error.message }, 'unknown');
167
+ }
168
+ /**
169
+ * Create model error response
170
+ */
171
+ static createModelError(functionName, error) {
172
+ return ResponseFactory.createErrorResponse(functionName, 'MODEL_ERROR', `Model execution failed: ${error.message}`, { originalError: error.message }, 'unknown');
173
+ }
174
+ }
175
+ /**
176
+ * Multi-file analysis utility
177
+ * Handles file discovery, batching, and processing for cross-file analysis
178
+ */
179
+ export class MultiFileAnalysis {
180
+ /**
181
+ * Discover files in a project directory with filtering
182
+ */
183
+ async discoverFiles(projectPath, extensions, maxDepth = 3) {
184
+ const files = [];
185
+ async function scanDirectory(dir, currentDepth) {
186
+ if (currentDepth > maxDepth)
187
+ return;
188
+ try {
189
+ const entries = await fs.readdir(dir, { withFileTypes: true });
190
+ for (const entry of entries) {
191
+ const fullPath = join(dir, entry.name);
192
+ if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
193
+ await scanDirectory(fullPath, currentDepth + 1);
194
+ }
195
+ else if (entry.isFile() && extensions.includes(extname(entry.name))) {
196
+ files.push(fullPath);
197
+ }
198
+ }
199
+ }
200
+ catch (error) {
201
+ // Skip inaccessible directories
202
+ }
203
+ }
204
+ await scanDirectory(projectPath, 0);
205
+ return files;
206
+ }
207
+ /**
208
+ * Process files in batches with a callback function
209
+ */
210
+ async analyzeBatch(files, analyzeFunction, contextLength, batchSize = 10) {
211
+ const results = [];
212
+ // Process in batches to avoid overwhelming the system
213
+ for (let i = 0; i < files.length; i += batchSize) {
214
+ const batch = files.slice(i, i + batchSize);
215
+ const batchResults = await Promise.all(batch.map(file => analyzeFunction(file)));
216
+ results.push(...batchResults);
217
+ }
218
+ return results;
219
+ }
220
+ }
221
+ //# sourceMappingURL=plugin-utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-utilities.js","sourceRoot":"","sources":["../../src/utils/plugin-utilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEpE,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAErC;;;GAGG;AACH,MAAM,OAAO,UAAU;IACrB,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,SAAc;QAIvC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;QAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAC9E,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,gBAAgB,EAAE,IAAI,KAAK,CAAC;QAE9D,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAClC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,eAAe;IAC1B;;OAEG;IACH,MAAM,CAAC,kBAAkB,CACvB,MAAoB,EACpB,aAAqB,EACrB,UAII,EAAE;QAEN,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,GAAG,CAAC,EAAE,YAAY,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;QAEtG,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CACrC,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC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,CAAC,CAAC,CAAC;oBAClD,CAAC;yBAAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;wBACtE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;oBACvB,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,gCAAgC;YAClC,CAAC;QACH,CAAC;QAED,MAAM,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAChB,KAAe,EACf,eAA6C,EAC7C,aAAqB,EACrB,YAAoB,EAAE;QAEtB,MAAM,OAAO,GAAQ,EAAE,CAAC;QAExB,sDAAsD;QACtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC;YAC5C,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CACzC,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export declare function handleLLMResponse(prediction: AsyncIterable<any>): Promise<string>;
2
+ export declare function formatWithSchema(response: string, schema?: any): any;
3
+ //# sourceMappingURL=streamHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamHandler.d.ts","sourceRoot":"","sources":["../../src/utils/streamHandler.ts"],"names":[],"mappings":"AAGA,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CA0CvF;AAGD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,GAAG,CAkCpE"}
@@ -0,0 +1,137 @@
1
+ // Fixed streaming response handler for Houtini LM MCP
2
+ // This fixes the [object Object] issue when streaming from LM Studio
3
+ export async function handleLLMResponse(prediction) {
4
+ let response = '';
5
+ try {
6
+ for await (const chunk of prediction) {
7
+ // Handle different chunk types
8
+ if (typeof chunk === 'string') {
9
+ response += chunk;
10
+ }
11
+ else if (chunk && typeof chunk === 'object') {
12
+ // If it's an object with content property (common in streaming)
13
+ if ('content' in chunk) {
14
+ response += chunk.content;
15
+ }
16
+ else if ('text' in chunk) {
17
+ response += chunk.text;
18
+ }
19
+ else if ('choices' in chunk && Array.isArray(chunk.choices)) {
20
+ // Handle OpenAI-style streaming format
21
+ for (const choice of chunk.choices) {
22
+ if (choice.delta?.content) {
23
+ response += choice.delta.content;
24
+ }
25
+ else if (choice.text) {
26
+ response += choice.text;
27
+ }
28
+ }
29
+ }
30
+ else {
31
+ // Try to stringify if it's a plain object
32
+ try {
33
+ const str = JSON.stringify(chunk);
34
+ if (str !== '[object Object]') {
35
+ response += str;
36
+ }
37
+ }
38
+ catch {
39
+ console.warn('Skipping non-serializable chunk:', chunk);
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ catch (error) {
46
+ console.error('Error processing streaming response:', error);
47
+ throw error;
48
+ }
49
+ return response;
50
+ }
51
+ // Enhanced response formatter with schema enforcement
52
+ export function formatWithSchema(response, schema) {
53
+ // First, try to extract JSON from the response
54
+ let jsonData = null;
55
+ // Try direct JSON parse
56
+ try {
57
+ jsonData = JSON.parse(response);
58
+ }
59
+ catch {
60
+ // Try to extract JSON from markdown code blocks
61
+ const jsonMatch = response.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
62
+ if (jsonMatch) {
63
+ try {
64
+ jsonData = JSON.parse(jsonMatch[1]);
65
+ }
66
+ catch {
67
+ // Continue with text processing
68
+ }
69
+ }
70
+ }
71
+ // If we have a schema and JSON data, validate and structure it
72
+ if (schema && jsonData) {
73
+ return enforceSchema(jsonData, schema);
74
+ }
75
+ // Otherwise, return structured text response
76
+ return {
77
+ summary: extractSummary(response),
78
+ content: response,
79
+ confidence: 0.85,
80
+ metadata: {
81
+ format: jsonData ? 'json' : 'text',
82
+ length: response.length
83
+ }
84
+ };
85
+ }
86
+ function enforceSchema(data, schema) {
87
+ const result = {};
88
+ if (schema.type === 'object' && schema.properties) {
89
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
90
+ const prop = propSchema;
91
+ if (data[key] !== undefined) {
92
+ if (prop.type === 'string') {
93
+ result[key] = String(data[key]);
94
+ }
95
+ else if (prop.type === 'number' || prop.type === 'integer') {
96
+ result[key] = Number(data[key]) || 0;
97
+ }
98
+ else if (prop.type === 'boolean') {
99
+ result[key] = Boolean(data[key]);
100
+ }
101
+ else if (prop.type === 'array') {
102
+ result[key] = Array.isArray(data[key]) ? data[key] : [];
103
+ }
104
+ else if (prop.type === 'object') {
105
+ result[key] = typeof data[key] === 'object' ? data[key] : {};
106
+ }
107
+ else {
108
+ result[key] = data[key];
109
+ }
110
+ }
111
+ else if (schema.required?.includes(key)) {
112
+ // Provide default for required fields
113
+ if (prop.type === 'string')
114
+ result[key] = '';
115
+ else if (prop.type === 'number' || prop.type === 'integer')
116
+ result[key] = 0;
117
+ else if (prop.type === 'boolean')
118
+ result[key] = false;
119
+ else if (prop.type === 'array')
120
+ result[key] = [];
121
+ else if (prop.type === 'object')
122
+ result[key] = {};
123
+ }
124
+ }
125
+ }
126
+ return result;
127
+ }
128
+ function extractSummary(text) {
129
+ // Extract first meaningful line or paragraph
130
+ const lines = text.split('\n').filter(line => line.trim());
131
+ if (lines.length > 0) {
132
+ // Remove markdown headers
133
+ return lines[0].replace(/^#+\s*/, '').trim();
134
+ }
135
+ return 'Analysis complete';
136
+ }
137
+ //# sourceMappingURL=streamHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamHandler.js","sourceRoot":"","sources":["../../src/utils/streamHandler.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,qEAAqE;AAErE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAA8B;IACpE,IAAI,QAAQ,GAAG,EAAE,CAAC;IAElB,IAAI,CAAC;QACH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;YACrC,+BAA+B;YAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,QAAQ,IAAI,KAAK,CAAC;YACpB,CAAC;iBAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9C,gEAAgE;gBAChE,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;oBACvB,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC;gBAC5B,CAAC;qBAAM,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;oBAC3B,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC;gBACzB,CAAC;qBAAM,IAAI,SAAS,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC9D,uCAAuC;oBACvC,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;wBACnC,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;4BAC1B,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;wBACnC,CAAC;6BAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;4BACvB,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC;wBAC1B,CAAC;oBACH,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,0CAA0C;oBAC1C,IAAI,CAAC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CAAC,CAAC;IAC3D,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,0BAA0B;QAC1B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Output Validation System for Houtini LM MCP
3
+ * Centralized validation and formatting for all function outputs
4
+ * Based on Functional Specification v4.0
5
+ */
6
+ export interface BaseResponse {
7
+ success: boolean;
8
+ timestamp: string;
9
+ modelUsed: string;
10
+ executionTimeMs: number;
11
+ error?: {
12
+ code: string;
13
+ message: string;
14
+ details?: any;
15
+ };
16
+ }
17
+ export interface AnalyzeResponse extends BaseResponse {
18
+ data: {
19
+ summary: string;
20
+ findings: Finding[];
21
+ suggestions: string[];
22
+ metadata?: Record<string, any>;
23
+ };
24
+ }
25
+ export interface GenerateResponse extends BaseResponse {
26
+ data: {
27
+ content: string;
28
+ metadata: {
29
+ type: string;
30
+ language?: string;
31
+ framework?: string;
32
+ [key: string]: any;
33
+ };
34
+ statistics: {
35
+ linesGenerated: number;
36
+ tokensUsed?: number;
37
+ [key: string]: any;
38
+ };
39
+ };
40
+ }
41
+ export interface MultiFileResponse extends BaseResponse {
42
+ data: {
43
+ filesAnalyzed: string[];
44
+ summary: string;
45
+ results: any[];
46
+ insights: string[];
47
+ };
48
+ }
49
+ export interface SystemResponse extends BaseResponse {
50
+ data: {
51
+ status: string;
52
+ details: Record<string, any>;
53
+ };
54
+ }
55
+ export interface Finding {
56
+ type: "issue" | "suggestion" | "info" | "warning" | "error";
57
+ severity: "critical" | "high" | "medium" | "low";
58
+ message: string;
59
+ location?: {
60
+ file?: string;
61
+ line?: number;
62
+ column?: number;
63
+ code?: string;
64
+ };
65
+ recommendation?: string;
66
+ }
67
+ /**
68
+ * Central Output Validator Class
69
+ * All functions should use this to ensure consistent output format
70
+ */
71
+ export declare class OutputValidator {
72
+ private static startTime;
73
+ /**
74
+ * Create a successful analysis response
75
+ */
76
+ static createAnalyzeResponse(data: Omit<AnalyzeResponse['data'], never>, modelUsed: string, executionTimeMs?: number): AnalyzeResponse;
77
+ /**
78
+ * Create a successful generation response
79
+ */
80
+ static createGenerateResponse(data: Omit<GenerateResponse['data'], never>, modelUsed: string, executionTimeMs?: number): GenerateResponse;
81
+ /**
82
+ * Create a successful multi-file response
83
+ */
84
+ static createMultiFileResponse(data: Omit<MultiFileResponse['data'], never>, modelUsed: string, executionTimeMs?: number): MultiFileResponse;
85
+ /**
86
+ * Create a successful system response
87
+ */
88
+ static createSystemResponse(data: Omit<SystemResponse['data'], never>, modelUsed?: string, executionTimeMs?: number): SystemResponse;
89
+ /**
90
+ * Create an error response (for any function type)
91
+ */
92
+ static createErrorResponse(errorCode: string, errorMessage: string, details?: any, modelUsed?: string, executionTimeMs?: number): BaseResponse;
93
+ /**
94
+ * Validate that a response matches the expected schema
95
+ */
96
+ static validateResponse(response: any, expectedType: 'analyze' | 'generate' | 'multifile' | 'system'): boolean;
97
+ /**
98
+ * Set execution start time for timing calculations
99
+ */
100
+ static setStartTime(): void;
101
+ /**
102
+ * Get execution time since start
103
+ */
104
+ static getExecutionTime(): number;
105
+ /**
106
+ * Standardize error codes
107
+ */
108
+ static ErrorCodes: {
109
+ readonly INVALID_INPUT: "INVALID_INPUT";
110
+ readonly FILE_NOT_FOUND: "FILE_NOT_FOUND";
111
+ readonly MODEL_ERROR: "MODEL_ERROR";
112
+ readonly PARSING_ERROR: "PARSING_ERROR";
113
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
114
+ readonly TIMEOUT: "TIMEOUT";
115
+ readonly SYSTEM_ERROR: "SYSTEM_ERROR";
116
+ };
117
+ }
118
+ export declare class AnalysisOutputParser {
119
+ /**
120
+ * Parse LLM response into structured analysis data
121
+ */
122
+ static parseAnalysisResponse(llmResponse: string, functionName: string): AnalyzeResponse['data'];
123
+ private static validateAndNormalizeAnalysis;
124
+ private static parseStructuredText;
125
+ private static normalizeFinding;
126
+ private static extractFindings;
127
+ private static extractSuggestions;
128
+ }
129
+ export declare class GenerationOutputParser {
130
+ /**
131
+ * Parse LLM response into structured generation data
132
+ */
133
+ static parseGenerationResponse(llmResponse: string, functionName: string, language?: string): GenerateResponse['data'];
134
+ private static getContentType;
135
+ }
136
+ //# sourceMappingURL=output-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-validator.d.ts","sourceRoot":"","sources":["../../src/validation/output-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,CAAC;KACf,CAAC;CACH;AAGD,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACnD,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,OAAO,EAAE,CAAC;QACpB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,CAAC;CACH;AAGD,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;SACpB,CAAC;QACF,UAAU,EAAE;YACV,cAAc,EAAE,MAAM,CAAC;YACv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