@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,666 @@
1
+ /**
2
+ * Plugin Template - Modern v4.2 (Single Source of Truth)
3
+ *
4
+ * Universal template that intelligently handles both single-file and multi-file analysis
5
+ * Automatically detects analysis type based on provided parameters
6
+ *
7
+ * Copy this template for creating any new plugin - it adapts to your needs
8
+ */
9
+ import { BasePlugin } from '../../plugins/base-plugin.js';
10
+ import { ThreeStagePromptManager } from '../../core/ThreeStagePromptManager.js';
11
+ import { withSecurity } from '../../security/integration-helpers.js';
12
+ import { readFileContent } from '../shared/helpers.js';
13
+ import { ModelSetup, ResponseProcessor, ParameterValidator, ErrorHandler, MultiFileAnalysis } from '../../utils/plugin-utilities.js';
14
+ import { getAnalysisCache } from '../../cache/index.js';
15
+ export class ProjectDocumentationGenerator extends BasePlugin {
16
+ constructor() {
17
+ super();
18
+ this.name = 'generate_project_documentation';
19
+ this.category = 'generate';
20
+ this.description = 'Generate comprehensive project documentation based on codebase analysis with intelligent file discovery and structured output';
21
+ // Universal parameter set - supports both single and multi-file scenarios
22
+ this.parameters = {
23
+ // Single-file parameters
24
+ code: {
25
+ type: 'string',
26
+ description: 'The code to analyze (for single-file analysis)',
27
+ required: false
28
+ },
29
+ filePath: {
30
+ type: 'string',
31
+ description: 'Path to single file to analyze',
32
+ required: false
33
+ },
34
+ // Multi-file parameters
35
+ projectPath: {
36
+ type: 'string',
37
+ description: 'Absolute path to project root directory',
38
+ required: false
39
+ },
40
+ files: {
41
+ type: 'array',
42
+ description: 'Array of specific file paths (for multi-file analysis)',
43
+ required: false,
44
+ items: { type: 'string' }
45
+ },
46
+ maxDepth: {
47
+ type: 'number',
48
+ description: 'Maximum directory depth for discovery (1-5)',
49
+ required: false,
50
+ default: 3
51
+ },
52
+ // Universal parameters
53
+ language: {
54
+ type: 'string',
55
+ description: 'Programming language',
56
+ required: false,
57
+ default: 'javascript'
58
+ },
59
+ analysisDepth: {
60
+ type: 'string',
61
+ description: 'Level of analysis detail',
62
+ enum: ['basic', 'detailed', 'comprehensive'],
63
+ default: 'detailed',
64
+ required: false
65
+ },
66
+ analysisType: {
67
+ type: 'string',
68
+ description: 'Type of analysis to perform',
69
+ enum: ['api', 'architecture', 'comprehensive'],
70
+ default: 'comprehensive',
71
+ required: false
72
+ },
73
+ // Documentation-specific parameters
74
+ docStyle: {
75
+ type: 'string',
76
+ description: 'Documentation style to use',
77
+ enum: ['markdown', 'jsdoc', 'typedoc', 'sphinx'],
78
+ default: 'markdown',
79
+ required: false
80
+ },
81
+ includeExamples: {
82
+ type: 'boolean',
83
+ description: 'Include usage examples in documentation',
84
+ default: true,
85
+ required: false
86
+ },
87
+ focusAreas: {
88
+ type: 'array',
89
+ description: 'Areas to focus on: api, architecture, setup, contributing',
90
+ default: ['api', 'architecture', 'setup'],
91
+ required: false,
92
+ items: { type: 'string' }
93
+ }
94
+ };
95
+ this.analysisCache = getAnalysisCache();
96
+ this.multiFileAnalysis = new MultiFileAnalysis();
97
+ // Cache and analysis utilities are initialized above
98
+ }
99
+ async execute(params, llmClient) {
100
+ return await withSecurity(this, params, llmClient, async (secureParams) => {
101
+ try {
102
+ // 1. Auto-detect analysis mode based on parameters
103
+ const analysisMode = this.detectAnalysisMode(secureParams);
104
+ // 2. Validate parameters based on detected mode
105
+ this.validateParameters(secureParams, analysisMode);
106
+ // 3. Setup model
107
+ const { model, contextLength } = await ModelSetup.getReadyModel(llmClient);
108
+ // 4. Route to appropriate analysis method
109
+ if (analysisMode === 'single-file') {
110
+ return await this.executeSingleFileAnalysis(secureParams, model, contextLength);
111
+ }
112
+ else {
113
+ return await this.executeMultiFileAnalysis(secureParams, model, contextLength);
114
+ }
115
+ }
116
+ catch (error) {
117
+ return ErrorHandler.createExecutionError('generate_project_documentation', error);
118
+ }
119
+ });
120
+ }
121
+ /**
122
+ * Auto-detect whether this is single-file or multi-file analysis
123
+ */
124
+ detectAnalysisMode(params) {
125
+ // Single-file indicators take priority (avoids default parameter issues)
126
+ if (params.code || params.filePath) {
127
+ return 'single-file';
128
+ }
129
+ // Multi-file indicators
130
+ if (params.projectPath || params.files) {
131
+ return 'multi-file';
132
+ }
133
+ // Default to multi-file for project documentation
134
+ return 'multi-file';
135
+ }
136
+ /**
137
+ * Validate parameters based on detected analysis mode
138
+ */
139
+ validateParameters(params, mode) {
140
+ if (mode === 'single-file') {
141
+ ParameterValidator.validateCodeOrFile(params);
142
+ }
143
+ else {
144
+ ParameterValidator.validateProjectPath(params);
145
+ ParameterValidator.validateDepth(params);
146
+ }
147
+ // Universal validations
148
+ ParameterValidator.validateEnum(params, 'analysisType', ['api', 'architecture', 'comprehensive']);
149
+ ParameterValidator.validateEnum(params, 'analysisDepth', ['basic', 'detailed', 'comprehensive']);
150
+ ParameterValidator.validateEnum(params, 'docStyle', ['markdown', 'jsdoc', 'typedoc', 'sphinx']);
151
+ }
152
+ /**
153
+ * Execute single-file analysis
154
+ */
155
+ async executeSingleFileAnalysis(params, model, contextLength) {
156
+ // Process single file input
157
+ let codeToAnalyze = params.code;
158
+ if (params.filePath) {
159
+ codeToAnalyze = await readFileContent(params.filePath);
160
+ }
161
+ // Generate prompt stages for single file
162
+ const promptStages = this.getSingleFilePromptStages({
163
+ ...params,
164
+ code: codeToAnalyze
165
+ });
166
+ // Execute with appropriate method
167
+ const promptManager = new ThreeStagePromptManager(contextLength);
168
+ const needsChunking = promptManager.needsChunking(promptStages);
169
+ if (needsChunking) {
170
+ const conversation = promptManager.createChunkedConversation(promptStages);
171
+ const messages = [
172
+ conversation.systemMessage,
173
+ ...conversation.dataMessages,
174
+ conversation.analysisMessage
175
+ ];
176
+ return await ResponseProcessor.executeChunked(messages, model, contextLength, 'generate_project_documentation', 'single');
177
+ }
178
+ else {
179
+ return await ResponseProcessor.executeDirect(promptStages, model, contextLength, 'generate_project_documentation');
180
+ }
181
+ }
182
+ /**
183
+ * Execute multi-file analysis
184
+ */
185
+ async executeMultiFileAnalysis(params, model, contextLength) {
186
+ // Discover files
187
+ let filesToAnalyze = params.files ||
188
+ await this.discoverRelevantFiles(params.projectPath, params.maxDepth, params.analysisType);
189
+ // Perform multi-file analysis with caching
190
+ const analysisResult = await this.performMultiFileAnalysis(filesToAnalyze, params, model, contextLength);
191
+ // Generate prompt stages for multi-file
192
+ const promptStages = this.getMultiFilePromptStages({
193
+ ...params,
194
+ analysisResult,
195
+ fileCount: filesToAnalyze.length
196
+ });
197
+ // Always use chunking for multi-file
198
+ const promptManager = new ThreeStagePromptManager(contextLength);
199
+ const conversation = promptManager.createChunkedConversation(promptStages);
200
+ const messages = [
201
+ conversation.systemMessage,
202
+ ...conversation.dataMessages,
203
+ conversation.analysisMessage
204
+ ];
205
+ return await ResponseProcessor.executeChunked(messages, model, contextLength, 'generate_project_documentation', 'multifile');
206
+ }
207
+ /**
208
+ * Implement single-file documentation generation
209
+ */
210
+ getSingleFilePromptStages(params) {
211
+ const { code, language, analysisDepth, analysisType, docStyle, includeExamples, focusAreas } = params;
212
+ const systemAndContext = `You are an expert technical writer and documentation specialist with 15+ years of experience creating developer-focused documentation.
213
+
214
+ **YOUR EXPERTISE:**
215
+ - Technical writing for software projects
216
+ - API documentation and developer experience
217
+ - Code analysis and architectural documentation
218
+ - Best practices for ${docStyle} documentation
219
+ - Creating clear, actionable content for developers
220
+
221
+ Analysis Context:
222
+ - Language: ${language}
223
+ - Analysis Depth: ${analysisDepth}
224
+ - Analysis Type: ${analysisType}
225
+ - Documentation Style: ${docStyle}
226
+ - Include Examples: ${includeExamples}
227
+ - Focus Areas: ${focusAreas.join(', ')}
228
+ - Mode: Single File Documentation
229
+
230
+ **DOCUMENTATION PHILOSOPHY:**
231
+ Your documentation should be a developer's best friend - clear, practical, and immediately useful. Think of it as mentoring a fellow developer who needs to understand and use this code effectively.
232
+
233
+ **KEY PRINCIPLES:**
234
+ 1. Lead with practical value - what can the developer accomplish?
235
+ 2. Explain the "why" behind architectural decisions
236
+ 3. Provide runnable examples that actually work
237
+ 4. Anticipate common questions and address them proactively
238
+ 5. Make it scannable with clear hierarchies and formatting`;
239
+ const dataPayload = `File to document:
240
+
241
+ **File Analysis:**
242
+ - Language: ${language}
243
+ - Content Length: ${code.length} characters
244
+ - Lines: ${code.split('\n').length}
245
+
246
+ **Code Content:**
247
+ \`\`\`${language}
248
+ ${code}
249
+ \`\`\``;
250
+ const outputInstructions = `Generate comprehensive ${docStyle} documentation for this file that serves as a complete reference for developers.
251
+
252
+ **REQUIRED DOCUMENTATION STRUCTURE:**
253
+
254
+ ## File Overview
255
+ - **Purpose**: Clear, one-sentence description of what this file does
256
+ - **Key Features**: 3-5 bullet points of main capabilities
257
+ - **Dependencies**: What this file requires to function
258
+ - **Integration Points**: How this file connects to the broader system
259
+
260
+ ## API Reference
261
+ ${includeExamples ?
262
+ `- **Functions/Classes**: Complete signature with parameter types and descriptions
263
+ - **Usage Examples**: Practical, copy-pasteable code examples for each main function
264
+ - **Return Values**: What developers can expect back, including error conditions
265
+ - **Best Practices**: How to use the API effectively and avoid common pitfalls` :
266
+ `- **Functions/Classes**: Method signatures with clear parameter descriptions
267
+ - **Core Concepts**: Key ideas developers need to understand
268
+ - **Integration Guidelines**: How to work with this file's functionality`}
269
+
270
+ ## Implementation Details
271
+ - **Architecture Notes**: Design decisions and their rationale
272
+ - **Performance Considerations**: Important performance implications
273
+ - **Error Handling**: How errors are managed and what to expect
274
+ - **Configuration**: Any configuration options or environment dependencies
275
+
276
+ ## Developer Guide
277
+ ${focusAreas.includes('setup') ? `- **Setup Requirements**: What developers need to get started
278
+ - **Environment Setup**: Step-by-step configuration instructions` : ''}
279
+ ${focusAreas.includes('contributing') ? `- **Contributing**: How to modify or extend this file
280
+ - **Testing**: How to test changes to this file` : ''}
281
+ - **Troubleshooting**: Common issues and their solutions
282
+ - **Related Files**: Other files developers should be aware of
283
+
284
+ **OUTPUT REQUIREMENTS:**
285
+ - Use proper ${docStyle} formatting with clear headers and code blocks
286
+ - Include syntax highlighting for code examples
287
+ - Create scannable content with bullet points and clear hierarchies
288
+ - Make examples practical and immediately useful
289
+ - Ensure content flows logically from overview to implementation details
290
+ - Write in an encouraging, helpful tone that empowers developers`;
291
+ return { systemAndContext, dataPayload, outputInstructions };
292
+ }
293
+ /**
294
+ * Implement multi-file project documentation generation
295
+ */
296
+ getMultiFilePromptStages(params) {
297
+ const { analysisResult, analysisType, analysisDepth, fileCount, docStyle, includeExamples, focusAreas } = params;
298
+ const systemAndContext = `You are a senior technical writer and project documentation specialist with expertise in creating comprehensive project documentation that developers love to use.
299
+
300
+ **YOUR EXPERTISE:**
301
+ - 15+ years creating project documentation for open source and enterprise software
302
+ - Expert in ${docStyle} documentation standards and best practices
303
+ - Specializes in developer onboarding and API documentation
304
+ - Deep understanding of software architecture and project organization
305
+ - Proven track record of creating documentation that reduces support tickets by 80%
306
+
307
+ Analysis Context:
308
+ - Analysis Type: ${analysisType}
309
+ - Analysis Depth: ${analysisDepth}
310
+ - Files Analyzed: ${fileCount}
311
+ - Documentation Style: ${docStyle}
312
+ - Include Examples: ${includeExamples}
313
+ - Focus Areas: ${focusAreas.join(', ')}
314
+ - Mode: Complete Project Documentation
315
+
316
+ **DOCUMENTATION MISSION:**
317
+ Create documentation so clear and helpful that:
318
+ 1. New developers can contribute within their first week
319
+ 2. Existing developers can quickly find what they need
320
+ 3. The project becomes more maintainable and accessible
321
+ 4. Support questions decrease significantly
322
+ 5. The project attracts more contributors and users
323
+
324
+ **CORE PRINCIPLES:**
325
+ - Start with what developers can accomplish (outcomes over features)
326
+ - Provide a clear learning path from beginner to advanced
327
+ - Include real, working examples that solve actual problems
328
+ - Anticipate and answer the questions developers will have
329
+ - Make the documentation as engaging and clear as the best technical books`;
330
+ const dataPayload = `Comprehensive project analysis results:
331
+
332
+ **Project Overview:**
333
+ - Total Files Analyzed: ${fileCount}
334
+ - Analysis Depth: ${analysisDepth}
335
+ - Focus Areas: ${focusAreas.join(', ')}
336
+
337
+ **Detailed Analysis:**
338
+ ${JSON.stringify(analysisResult, null, 2)}`;
339
+ const outputInstructions = `Create comprehensive ${docStyle} project documentation that serves as the definitive guide for this project.
340
+
341
+ **REQUIRED DOCUMENTATION SECTIONS:**
342
+
343
+ ## 🚀 Project Overview
344
+ - **What This Project Does**: Clear, compelling description in plain English
345
+ - **Why It Matters**: The problem this project solves and why developers should care
346
+ - **Key Features**: 5-7 standout capabilities that make this project valuable
347
+ - **Who Should Use This**: Target audience and use cases
348
+ - **Technology Stack**: Core technologies and architectural approach
349
+
350
+ ## ⚡ Quick Start Guide
351
+ ${focusAreas.includes('setup') ?
352
+ `- **Prerequisites**: Exact system requirements and dependencies
353
+ - **Installation**: Step-by-step installation process with verification steps
354
+ - **First Success**: Get developers to a working example in under 10 minutes
355
+ - **Next Steps**: Clear pathway to more advanced usage` :
356
+ `- **Getting Started**: Essential steps to begin using the project
357
+ - **Core Concepts**: Key ideas developers need to understand upfront`}
358
+
359
+ ## 📁 Project Architecture
360
+ ${focusAreas.includes('architecture') ?
361
+ `- **Directory Structure**: What each folder contains and why
362
+ - **Key Components**: Core modules and their responsibilities
363
+ - **Data Flow**: How information moves through the system
364
+ - **Design Decisions**: Architectural choices and their rationale
365
+ - **Extension Points**: Where and how the project can be customized` :
366
+ `- **Project Organization**: How the codebase is structured
367
+ - **Core Components**: Main modules and their purposes`}
368
+
369
+ ## 🔧 API Documentation
370
+ ${focusAreas.includes('api') ?
371
+ `- **Core APIs**: Complete reference for main functions and classes
372
+ - **Authentication**: Security and access patterns
373
+ - **Request/Response Formats**: Data structures and examples
374
+ - **Error Handling**: Common error scenarios and resolutions
375
+ - **Rate Limits & Performance**: Important usage considerations` :
376
+ `- **Main Functions**: Key APIs and their usage
377
+ - **Integration Patterns**: How to work with the project's functionality`}
378
+
379
+ ## 💡 Usage Examples
380
+ ${includeExamples ?
381
+ `- **Common Use Cases**: 5-10 practical scenarios with complete code examples
382
+ - **Integration Examples**: How to use this project with other popular tools
383
+ - **Advanced Patterns**: Sophisticated usage for experienced developers
384
+ - **Best Practices**: Recommended approaches and patterns to avoid
385
+ - **Sample Projects**: Links to complete example implementations` :
386
+ `- **Basic Usage**: Essential usage patterns
387
+ - **Integration Guidelines**: How to incorporate into existing projects
388
+ - **Common Patterns**: Frequently used approaches`}
389
+
390
+ ## 🛠️ Development Guide
391
+ ${focusAreas.includes('contributing') ?
392
+ `- **Development Setup**: Complete environment setup for contributors
393
+ - **Code Style**: Coding standards and conventions
394
+ - **Testing Strategy**: How to run and write tests
395
+ - **Contribution Workflow**: Pull request process and guidelines
396
+ - **Release Process**: How updates are published and versioned` :
397
+ `- **Local Development**: Setting up for project modification
398
+ - **Testing**: How to verify changes work correctly`}
399
+
400
+ ## 🔍 Troubleshooting
401
+ - **Common Issues**: The 10 most frequent problems and their solutions
402
+ - **Debug Mode**: How to get more information when things go wrong
403
+ - **Performance Issues**: Common performance problems and fixes
404
+ - **Environment Problems**: OS-specific issues and resolutions
405
+ - **Getting Help**: Where to find support and ask questions
406
+
407
+ ## 🌟 Advanced Topics
408
+ - **Performance Optimization**: How to get the best performance
409
+ - **Security Considerations**: Important security practices
410
+ - **Monitoring & Observability**: How to monitor the project in production
411
+ - **Scaling Patterns**: Approaches for high-load scenarios
412
+ - **Integration Ecosystem**: Compatible tools and frameworks
413
+
414
+ ## 📚 Resources
415
+ - **Related Projects**: Complementary tools and libraries
416
+ - **Learning Resources**: Tutorials, videos, and educational content
417
+ - **Community**: Where to connect with other users and contributors
418
+ - **Changelog**: Recent updates and version history
419
+ - **Roadmap**: Planned features and project direction
420
+
421
+ **OUTPUT REQUIREMENTS:**
422
+ - Use engaging ${docStyle} formatting with emojis in headers for visual appeal
423
+ - Include practical, runnable code examples with clear explanations
424
+ - Create a logical flow from basic concepts to advanced usage
425
+ - Write in an encouraging, developer-friendly tone
426
+ - Make content highly scannable with clear hierarchies and formatting
427
+ - Include calls-to-action that encourage developers to try the project
428
+ - Ensure examples are realistic and solve real problems developers face
429
+ - Add tips, warnings, and pro-tips using appropriate markdown formatting`;
430
+ return { systemAndContext, dataPayload, outputInstructions };
431
+ }
432
+ /**
433
+ * Implement for backwards compatibility
434
+ * The system still expects this method, so we intelligently route to the appropriate stages
435
+ */
436
+ getPromptStages(params) {
437
+ const mode = this.detectAnalysisMode(params);
438
+ if (mode === 'single-file') {
439
+ return this.getSingleFilePromptStages(params);
440
+ }
441
+ else {
442
+ return this.getMultiFilePromptStages(params);
443
+ }
444
+ }
445
+ // Multi-file helper methods
446
+ async discoverRelevantFiles(projectPath, maxDepth, analysisType) {
447
+ const extensions = this.getFileExtensions(analysisType);
448
+ // If analyzing /src, also include key files from parent directory
449
+ const path = await import('path');
450
+ const parentDir = path.dirname(projectPath);
451
+ const isSourceDir = projectPath.endsWith('src') || projectPath.endsWith('src/');
452
+ let sourceFiles = await this.multiFileAnalysis.discoverFiles(projectPath, extensions, maxDepth);
453
+ if (isSourceDir) {
454
+ // Add key project files from parent directory
455
+ const keyProjectFiles = await this.findKeyProjectFiles(parentDir);
456
+ sourceFiles = [...keyProjectFiles, ...sourceFiles];
457
+ }
458
+ return sourceFiles;
459
+ }
460
+ async findKeyProjectFiles(projectRoot) {
461
+ const fs = await import('fs/promises');
462
+ const path = await import('path');
463
+ const keyFiles = [];
464
+ const keyFileNames = [
465
+ 'package.json', 'composer.json', 'requirements.txt', 'Cargo.toml',
466
+ 'README.md', 'README.rst', 'README.txt', 'CHANGELOG.md',
467
+ 'tsconfig.json', '.env.example', '.gitignore'
468
+ ];
469
+ for (const fileName of keyFileNames) {
470
+ const filePath = path.join(projectRoot, fileName);
471
+ try {
472
+ await fs.access(filePath);
473
+ keyFiles.push(filePath);
474
+ }
475
+ catch {
476
+ // File doesn't exist, skip it
477
+ }
478
+ }
479
+ return keyFiles;
480
+ }
481
+ async performMultiFileAnalysis(files, params, model, contextLength) {
482
+ const cacheKey = this.analysisCache.generateKey('generate_project_documentation', params, files);
483
+ const cached = await this.analysisCache.get(cacheKey);
484
+ if (cached)
485
+ return cached;
486
+ const fileAnalysisResults = await this.multiFileAnalysis.analyzeBatch(files, (file) => this.analyzeIndividualFile(file, params, model), contextLength);
487
+ // Aggregate results into proper analysis result format
488
+ const aggregatedResult = {
489
+ summary: `Project documentation analysis of ${files.length} files`,
490
+ findings: fileAnalysisResults,
491
+ data: {
492
+ fileCount: files.length,
493
+ totalSize: fileAnalysisResults.reduce((sum, result) => sum + (result.size || 0), 0),
494
+ projectStructure: await this.buildProjectStructure(files, fileAnalysisResults),
495
+ keyFiles: this.identifyKeyFiles(fileAnalysisResults),
496
+ projectMetadata: this.extractProjectMetadata(files, fileAnalysisResults)
497
+ }
498
+ };
499
+ await this.analysisCache.cacheAnalysis(cacheKey, aggregatedResult, {
500
+ modelUsed: model.identifier || 'unknown',
501
+ executionTime: Date.now() - Date.now(), // TODO: Track actual execution time
502
+ timestamp: new Date().toISOString()
503
+ });
504
+ return aggregatedResult;
505
+ }
506
+ async analyzeIndividualFile(file, params, model) {
507
+ const content = await import('fs/promises').then(fs => fs.readFile(file, 'utf-8'));
508
+ const path = await import('path');
509
+ const isKeyFile = this.isKeyFile(path.basename(file));
510
+ return {
511
+ filePath: file,
512
+ fileName: path.basename(file),
513
+ extension: path.extname(file),
514
+ size: content.length,
515
+ lines: content.split('\n').length,
516
+ language: this.getLanguageFromExtension(path.extname(file)),
517
+ isKeyFile,
518
+ // Only include content for key files, and limit it
519
+ content: isKeyFile && content.length < 2000 ? content :
520
+ isKeyFile ? content.substring(0, 2000) + '...[truncated]' :
521
+ '[Content excluded - non-key file]'
522
+ };
523
+ }
524
+ getFileExtensions(analysisType) {
525
+ const extensionMap = {
526
+ 'api': ['.js', '.ts', '.jsx', '.tsx', '.php', '.py', '.java', '.json'], // Focus on API-relevant files
527
+ 'architecture': ['.js', '.ts', '.jsx', '.tsx', '.php', '.py', '.java', '.md', '.json', '.yml', '.yaml'], // Include config and docs
528
+ 'comprehensive': ['.js', '.ts', '.jsx', '.tsx', '.php', '.py', '.java', '.cs', '.cpp', '.h', '.css', '.html', '.md', '.json', '.xml', '.yml', '.yaml', '.sql'] // All relevant files
529
+ };
530
+ return extensionMap[analysisType] || extensionMap.comprehensive;
531
+ }
532
+ getLanguageFromExtension(ext) {
533
+ const languageMap = {
534
+ '.js': 'javascript',
535
+ '.ts': 'typescript',
536
+ '.jsx': 'react',
537
+ '.tsx': 'react-typescript',
538
+ '.php': 'php',
539
+ '.py': 'python',
540
+ '.java': 'java',
541
+ '.cs': 'csharp',
542
+ '.cpp': 'cpp',
543
+ '.h': 'c',
544
+ '.css': 'css',
545
+ '.html': 'html',
546
+ '.md': 'markdown',
547
+ '.json': 'json',
548
+ '.yml': 'yaml',
549
+ '.yaml': 'yaml',
550
+ '.sql': 'sql'
551
+ };
552
+ return languageMap[ext.toLowerCase()] || 'other';
553
+ }
554
+ isKeyFile(fileName) {
555
+ const keyFilePatterns = [
556
+ 'package.json', 'composer.json', 'requirements.txt', 'Cargo.toml',
557
+ 'README.md', 'README.rst', 'README.txt', 'CHANGELOG.md',
558
+ 'index.js', 'index.ts', 'main.js', 'main.ts', 'app.js', 'app.ts',
559
+ 'config.js', 'config.ts', 'tsconfig.json', '.env.example'
560
+ ];
561
+ // Exact matches for critical files
562
+ if (keyFilePatterns.includes(fileName.toLowerCase())) {
563
+ return true;
564
+ }
565
+ // Pattern matches for important files
566
+ const importantPatterns = [
567
+ /^index\.(js|ts)$/i,
568
+ /^main\.(js|ts)$/i,
569
+ /^app\.(js|ts)$/i,
570
+ /readme/i,
571
+ /config/i
572
+ ];
573
+ return importantPatterns.some(pattern => pattern.test(fileName));
574
+ }
575
+ async buildProjectStructure(files, analysisResults) {
576
+ const path = await import('path');
577
+ const structure = {};
578
+ files.forEach((file, index) => {
579
+ const parts = file.split(path.sep);
580
+ let current = structure;
581
+ parts.forEach((part, partIndex) => {
582
+ if (!current[part]) {
583
+ current[part] = partIndex === parts.length - 1 ? analysisResults[index] : {};
584
+ }
585
+ if (partIndex < parts.length - 1) {
586
+ current = current[part];
587
+ }
588
+ });
589
+ });
590
+ return structure;
591
+ }
592
+ identifyKeyFiles(analysisResults) {
593
+ return analysisResults
594
+ .filter(result => result.isKeyFile)
595
+ .sort((a, b) => b.size - a.size)
596
+ .slice(0, 10); // Top 10 key files
597
+ }
598
+ extractProjectMetadata(files, analysisResults) {
599
+ const packageJsonFile = analysisResults.find(result => result.fileName === 'package.json');
600
+ if (packageJsonFile) {
601
+ try {
602
+ const packageJson = JSON.parse(packageJsonFile.content);
603
+ return {
604
+ name: packageJson.name || 'Unknown Project',
605
+ version: packageJson.version || '1.0.0',
606
+ description: packageJson.description || '',
607
+ type: this.detectProjectType(packageJson, analysisResults),
608
+ dependencies: Object.keys(packageJson.dependencies || {}),
609
+ scripts: Object.keys(packageJson.scripts || {}),
610
+ author: packageJson.author || '',
611
+ license: packageJson.license || ''
612
+ };
613
+ }
614
+ catch (error) {
615
+ // Fallback if package.json can't be parsed
616
+ }
617
+ }
618
+ // Default metadata
619
+ return {
620
+ name: 'Project Documentation',
621
+ version: '1.0.0',
622
+ description: 'Comprehensive project documentation',
623
+ type: this.detectProjectTypeFromFiles(analysisResults),
624
+ dependencies: [],
625
+ scripts: [],
626
+ author: '',
627
+ license: ''
628
+ };
629
+ }
630
+ detectProjectType(packageJson, analysisResults) {
631
+ if (packageJson.dependencies?.react)
632
+ return 'react-application';
633
+ if (packageJson.dependencies?.vue)
634
+ return 'vue-application';
635
+ if (packageJson.dependencies?.express)
636
+ return 'node-api';
637
+ if (packageJson.dependencies?.next)
638
+ return 'nextjs-application';
639
+ if (analysisResults.some(f => f.fileName.includes('plugin.php')))
640
+ return 'wordpress-plugin';
641
+ if (analysisResults.some(f => f.fileName === 'style.css' && f.content.includes('Theme')))
642
+ return 'wordpress-theme';
643
+ return 'node-project';
644
+ }
645
+ detectProjectTypeFromFiles(analysisResults) {
646
+ const fileNames = analysisResults.map(r => r.fileName);
647
+ if (fileNames.includes('package.json'))
648
+ return 'node-project';
649
+ if (fileNames.includes('composer.json'))
650
+ return 'php-project';
651
+ if (fileNames.includes('requirements.txt'))
652
+ return 'python-project';
653
+ if (fileNames.includes('Cargo.toml'))
654
+ return 'rust-project';
655
+ if (fileNames.some(f => f.endsWith('.csproj')))
656
+ return 'dotnet-project';
657
+ return 'generic-project';
658
+ }
659
+ generateCacheKey(files, params) {
660
+ const fileHash = files.join('|');
661
+ const paramHash = JSON.stringify(params);
662
+ return `${fileHash}_${paramHash}`.substring(0, 64);
663
+ }
664
+ }
665
+ export default ProjectDocumentationGenerator;
666
+ //# sourceMappingURL=project-documentation.js.map