tachibot-mcp 2.0.2
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.
- package/.env.example +260 -0
- package/CHANGELOG.md +54 -0
- package/CODE_OF_CONDUCT.md +56 -0
- package/CONTRIBUTING.md +54 -0
- package/Dockerfile +36 -0
- package/LICENSE +644 -0
- package/README.md +201 -0
- package/SECURITY.md +95 -0
- package/dist/personality/komaai-expressions.js +12 -0
- package/dist/profiles/balanced.json +33 -0
- package/dist/profiles/code_focus.json +33 -0
- package/dist/profiles/full.json +33 -0
- package/dist/profiles/minimal.json +33 -0
- package/dist/profiles/research_power.json +33 -0
- package/dist/scripts/build-profiles.js +46 -0
- package/dist/src/application/services/focus/FocusModeRegistry.js +46 -0
- package/dist/src/application/services/focus/FocusTool.service.js +109 -0
- package/dist/src/application/services/focus/ModeRegistry.js +46 -0
- package/dist/src/application/services/focus/modes/focus-deep.mode.js +27 -0
- package/dist/src/application/services/focus/modes/status.mode.js +50 -0
- package/dist/src/application/services/focus/modes/tachibot-status.mode.js +50 -0
- package/dist/src/collaborative-orchestrator.js +391 -0
- package/dist/src/config/model-constants.js +188 -0
- package/dist/src/config/model-defaults.js +57 -0
- package/dist/src/config/model-preferences.js +382 -0
- package/dist/src/config/timeout-config.js +130 -0
- package/dist/src/config.js +173 -0
- package/dist/src/domain/interfaces/IFocusMode.js +5 -0
- package/dist/src/domain/interfaces/IProvider.js +6 -0
- package/dist/src/domain/interfaces/ITool.js +5 -0
- package/dist/src/focus-deep.js +245 -0
- package/dist/src/infrastructure/ascii/art/robots.ascii.js +16 -0
- package/dist/src/mcp-client.js +90 -0
- package/dist/src/memory/index.js +17 -0
- package/dist/src/memory/memory-config.js +135 -0
- package/dist/src/memory/memory-interface.js +174 -0
- package/dist/src/memory/memory-manager.js +383 -0
- package/dist/src/memory/providers/devlog-provider.js +385 -0
- package/dist/src/memory/providers/hybrid-provider.js +399 -0
- package/dist/src/memory/providers/local-provider.js +388 -0
- package/dist/src/memory/providers/mem0-provider.js +337 -0
- package/dist/src/modes/architect.js +477 -0
- package/dist/src/modes/auditor.js +362 -0
- package/dist/src/modes/challenger.js +841 -0
- package/dist/src/modes/code-reviewer.js +382 -0
- package/dist/src/modes/commit-guardian.js +424 -0
- package/dist/src/modes/documentation-writer.js +572 -0
- package/dist/src/modes/scout.js +587 -0
- package/dist/src/modes/shared/helpers/challenger-helpers.js +454 -0
- package/dist/src/modes/shared/helpers/index.js +17 -0
- package/dist/src/modes/shared/helpers/scout-helpers.js +270 -0
- package/dist/src/modes/shared/helpers/verifier-helpers.js +332 -0
- package/dist/src/modes/test-architect.js +767 -0
- package/dist/src/modes/verifier.js +378 -0
- package/dist/src/monitoring/performance-monitor.js +435 -0
- package/dist/src/optimization/batch-executor.js +121 -0
- package/dist/src/optimization/context-pruner.js +196 -0
- package/dist/src/optimization/cost-monitor.js +338 -0
- package/dist/src/optimization/index.js +65 -0
- package/dist/src/optimization/model-router.js +264 -0
- package/dist/src/optimization/result-cache.js +114 -0
- package/dist/src/optimization/token-optimizer.js +257 -0
- package/dist/src/optimization/token-tracker.js +118 -0
- package/dist/src/orchestrator-instructions.js +128 -0
- package/dist/src/orchestrator-lite.js +139 -0
- package/dist/src/orchestrator.js +191 -0
- package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionEngine.js +1 -0
- package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionStrategy.js +5 -0
- package/dist/src/orchestrators/collaborative/interfaces/IVisualizationRenderer.js +1 -0
- package/dist/src/orchestrators/collaborative/registries/ModelProviderRegistry.js +95 -0
- package/dist/src/orchestrators/collaborative/registries/ToolAdapterRegistry.js +64 -0
- package/dist/src/orchestrators/collaborative/services/tool-execution/ToolExecutionService.js +502 -0
- package/dist/src/orchestrators/collaborative/services/visualization/VisualizationService.js +206 -0
- package/dist/src/orchestrators/collaborative/types/session-types.js +5 -0
- package/dist/src/profiles/balanced.js +37 -0
- package/dist/src/profiles/code_focus.js +37 -0
- package/dist/src/profiles/debug_intensive.js +59 -0
- package/dist/src/profiles/full.js +37 -0
- package/dist/src/profiles/minimal.js +37 -0
- package/dist/src/profiles/research_code.js +59 -0
- package/dist/src/profiles/research_power.js +37 -0
- package/dist/src/profiles/types.js +5 -0
- package/dist/src/profiles/workflow_builder.js +53 -0
- package/dist/src/prompt-engineer-lite.js +78 -0
- package/dist/src/prompt-engineer.js +399 -0
- package/dist/src/reasoning-chain.js +508 -0
- package/dist/src/sequential-thinking.js +291 -0
- package/dist/src/server-diagnostic.js +74 -0
- package/dist/src/server-raw.js +158 -0
- package/dist/src/server-simple.js +58 -0
- package/dist/src/server.js +514 -0
- package/dist/src/session/session-logger.js +617 -0
- package/dist/src/session/session-manager.js +571 -0
- package/dist/src/session/session-tools.js +400 -0
- package/dist/src/tools/advanced-modes.js +200 -0
- package/dist/src/tools/claude-integration.js +356 -0
- package/dist/src/tools/consolidated/ai-router.js +174 -0
- package/dist/src/tools/consolidated/ai-tool.js +48 -0
- package/dist/src/tools/consolidated/brainstorm-tool.js +87 -0
- package/dist/src/tools/consolidated/environment-detector.js +80 -0
- package/dist/src/tools/consolidated/index.js +50 -0
- package/dist/src/tools/consolidated/search-tool.js +110 -0
- package/dist/src/tools/consolidated/workflow-tool.js +238 -0
- package/dist/src/tools/gemini-tools.js +329 -0
- package/dist/src/tools/grok-enhanced.js +376 -0
- package/dist/src/tools/grok-tools.js +299 -0
- package/dist/src/tools/lmstudio-tools.js +223 -0
- package/dist/src/tools/openai-tools.js +498 -0
- package/dist/src/tools/openrouter-tools.js +317 -0
- package/dist/src/tools/optimized-wrapper.js +204 -0
- package/dist/src/tools/perplexity-tools.js +294 -0
- package/dist/src/tools/pingpong-tool.js +343 -0
- package/dist/src/tools/qwen-wrapper.js +74 -0
- package/dist/src/tools/tool-router.js +444 -0
- package/dist/src/tools/unified-ai-provider.js +260 -0
- package/dist/src/tools/workflow-runner.js +425 -0
- package/dist/src/tools/workflow-validator-tool.js +107 -0
- package/dist/src/types.js +23 -0
- package/dist/src/utils/input-validator.js +130 -0
- package/dist/src/utils/model-router.js +91 -0
- package/dist/src/utils/progress-stream.js +255 -0
- package/dist/src/utils/provider-router.js +88 -0
- package/dist/src/utils/smart-api-client.js +146 -0
- package/dist/src/utils/table-builder.js +218 -0
- package/dist/src/utils/timestamp-formatter.js +134 -0
- package/dist/src/utils/tool-compressor.js +257 -0
- package/dist/src/utils/tool-config.js +201 -0
- package/dist/src/validators/dependency-graph-validator.js +147 -0
- package/dist/src/validators/interpolation-validator.js +222 -0
- package/dist/src/validators/output-usage-validator.js +151 -0
- package/dist/src/validators/syntax-validator.js +102 -0
- package/dist/src/validators/tool-registry-validator.js +123 -0
- package/dist/src/validators/tool-types.js +97 -0
- package/dist/src/validators/types.js +8 -0
- package/dist/src/validators/workflow-validator.js +134 -0
- package/dist/src/visualizer-lite.js +42 -0
- package/dist/src/visualizer.js +179 -0
- package/dist/src/workflows/circuit-breaker.js +199 -0
- package/dist/src/workflows/custom-workflows.js +451 -0
- package/dist/src/workflows/engine/AutoSynthesizer.js +97 -0
- package/dist/src/workflows/engine/StepParameterResolver.js +74 -0
- package/dist/src/workflows/engine/VariableInterpolator.js +123 -0
- package/dist/src/workflows/engine/WorkflowDiscovery.js +125 -0
- package/dist/src/workflows/engine/WorkflowExecutionEngine.js +485 -0
- package/dist/src/workflows/engine/WorkflowExecutor.js +113 -0
- package/dist/src/workflows/engine/WorkflowFileManager.js +244 -0
- package/dist/src/workflows/engine/WorkflowHelpers.js +114 -0
- package/dist/src/workflows/engine/WorkflowOutputFormatter.js +83 -0
- package/dist/src/workflows/engine/events/WorkflowEventBus.js +132 -0
- package/dist/src/workflows/engine/events/interfaces/IEventBus.js +5 -0
- package/dist/src/workflows/engine/handlers/ErrorRecoveryHandler.js +162 -0
- package/dist/src/workflows/engine/handlers/PromptEnhancementHandler.js +115 -0
- package/dist/src/workflows/engine/handlers/SessionPersistenceHandler.js +167 -0
- package/dist/src/workflows/engine/handlers/StepExecutionHandler.js +231 -0
- package/dist/src/workflows/engine/handlers/ToolInvocationHandler.js +46 -0
- package/dist/src/workflows/engine/interfaces/IAutoSynthesizer.js +5 -0
- package/dist/src/workflows/engine/interfaces/IStepParameterResolver.js +5 -0
- package/dist/src/workflows/engine/interfaces/IVariableInterpolator.js +5 -0
- package/dist/src/workflows/engine/interfaces/IWorkflowDiscovery.js +4 -0
- package/dist/src/workflows/engine/interfaces/IWorkflowFileManager.js +5 -0
- package/dist/src/workflows/engine/interfaces/IWorkflowOutputFormatter.js +5 -0
- package/dist/src/workflows/engine/state/WorkflowStateMachine.js +194 -0
- package/dist/src/workflows/engine/state/interfaces/IStateMachine.js +17 -0
- package/dist/src/workflows/fallback-strategies.js +373 -0
- package/dist/src/workflows/message-queue.js +455 -0
- package/dist/src/workflows/model-router.js +189 -0
- package/dist/src/workflows/orchestrator-examples.js +174 -0
- package/dist/src/workflows/orchestrator-integration.js +200 -0
- package/dist/src/workflows/self-healing.js +524 -0
- package/dist/src/workflows/tool-mapper.js +407 -0
- package/dist/src/workflows/tool-orchestrator.js +796 -0
- package/dist/src/workflows/workflow-engine.js +573 -0
- package/dist/src/workflows/workflow-parser.js +283 -0
- package/dist/src/workflows/workflow-types.js +95 -0
- package/dist/src/workflows.js +568 -0
- package/dist/test-workflow-file-output.js +93 -0
- package/docs/API_KEYS.md +570 -0
- package/docs/CLAUDE_CODE_SETUP.md +181 -0
- package/docs/CLAUDE_DESKTOP_MANUAL.md +127 -0
- package/docs/CONFIGURATION.md +745 -0
- package/docs/FOCUS_MODES.md +240 -0
- package/docs/INSTALLATION_BOTH.md +145 -0
- package/docs/TERMS.md +352 -0
- package/docs/TOOLS_REFERENCE.md +1622 -0
- package/docs/TOOL_PARAMETERS.md +496 -0
- package/docs/TOOL_PROFILES.md +236 -0
- package/docs/WORKFLOWS.md +987 -0
- package/docs/WORKFLOW_OUTPUT.md +198 -0
- package/docs/WORKFLOW_PROGRESS_TRACKING.md +305 -0
- package/docs/workflows/design-brainstorm.md +335 -0
- package/package.json +97 -0
- package/profiles/balanced.json +37 -0
- package/profiles/code_focus.json +37 -0
- package/profiles/debug_intensive.json +34 -0
- package/profiles/full.json +37 -0
- package/profiles/minimal.json +37 -0
- package/profiles/research_power.json +37 -0
- package/profiles/workflow_builder.json +37 -0
- package/smithery.yaml +66 -0
- package/start.sh +8 -0
- package/tools.config.json +81 -0
- package/tsconfig.json +18 -0
- package/workflows/accessibility-code-audit.yaml +92 -0
- package/workflows/code-architecture-review.yaml +202 -0
- package/workflows/code-review.yaml +142 -0
- package/workflows/core/iterative-problem-solver.yaml +283 -0
- package/workflows/creative-brainstorm-yaml.yaml +215 -0
- package/workflows/pingpong.yaml +141 -0
- package/workflows/system/README.md +412 -0
- package/workflows/system/challenger.yaml +175 -0
- package/workflows/system/scout.yaml +164 -0
- package/workflows/system/verifier.yaml +133 -0
- package/workflows/ultra-creative-brainstorm.yaml +318 -0
- package/workflows/ux-research-flow.yaml +92 -0
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
export class DocumentationWriter {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.defaultModel = 'gemini-2.5-flash';
|
|
4
|
+
this.defaultMaxTokens = 3000;
|
|
5
|
+
this.defaultStyle = 'narrative';
|
|
6
|
+
}
|
|
7
|
+
async generateDocs(code, options = {}) {
|
|
8
|
+
const model = options.model || this.defaultModel;
|
|
9
|
+
const maxTokens = options.maxTokens || this.defaultMaxTokens;
|
|
10
|
+
const style = options.style || this.defaultStyle;
|
|
11
|
+
const includeExamples = options.includeExamples !== false; // default true
|
|
12
|
+
const format = options.format || 'markdown';
|
|
13
|
+
// Extract code structure
|
|
14
|
+
const codeStructure = await this.analyzeCodeStructure(code);
|
|
15
|
+
// Generate README
|
|
16
|
+
const readme = await this.generateReadme(codeStructure, style || 'narrative', includeExamples);
|
|
17
|
+
// Generate API documentation
|
|
18
|
+
const apiDocs = await this.generateApiDocs(codeStructure, includeExamples);
|
|
19
|
+
// Generate inline comments
|
|
20
|
+
const inlineComments = await this.generateInlineComments(code, style || 'narrative');
|
|
21
|
+
// Generate changelog
|
|
22
|
+
const changelog = await this.generateChangelog(codeStructure);
|
|
23
|
+
// Generate narrative documentation if requested
|
|
24
|
+
let narrativeDoc;
|
|
25
|
+
if (style === 'narrative') {
|
|
26
|
+
narrativeDoc = await this.generateNarrativeDoc(codeStructure, code);
|
|
27
|
+
}
|
|
28
|
+
// Create synthesis
|
|
29
|
+
const synthesis = this.synthesizeDocumentation(readme, apiDocs, inlineComments, changelog, narrativeDoc);
|
|
30
|
+
return {
|
|
31
|
+
readme,
|
|
32
|
+
apiDocs,
|
|
33
|
+
inlineComments,
|
|
34
|
+
changelog,
|
|
35
|
+
narrativeDoc,
|
|
36
|
+
synthesis
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async analyzeCodeStructure(code) {
|
|
40
|
+
const structure = {
|
|
41
|
+
functions: this.extractFunctions(code),
|
|
42
|
+
classes: this.extractClasses(code),
|
|
43
|
+
interfaces: this.extractInterfaces(code),
|
|
44
|
+
constants: this.extractConstants(code),
|
|
45
|
+
imports: this.extractImports(code),
|
|
46
|
+
exports: this.extractExports(code),
|
|
47
|
+
comments: this.extractExistingComments(code),
|
|
48
|
+
complexity: this.assessCodeComplexity(code),
|
|
49
|
+
purpose: this.inferPurpose(code)
|
|
50
|
+
};
|
|
51
|
+
return structure;
|
|
52
|
+
}
|
|
53
|
+
extractFunctions(code) {
|
|
54
|
+
const functions = [];
|
|
55
|
+
// Match function declarations and expressions
|
|
56
|
+
const functionPatterns = [
|
|
57
|
+
/(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*(?::\s*([^{]+))?\s*\{/g,
|
|
58
|
+
/(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?\(([^)]*)\)\s*=>\s*\{/g,
|
|
59
|
+
/(\w+)\s*:\s*(?:async\s+)?\(([^)]*)\)\s*=>\s*\{/g
|
|
60
|
+
];
|
|
61
|
+
functionPatterns.forEach(pattern => {
|
|
62
|
+
let match;
|
|
63
|
+
while ((match = pattern.exec(code)) !== null) {
|
|
64
|
+
const [, name, params, returnType] = match;
|
|
65
|
+
functions.push({
|
|
66
|
+
name,
|
|
67
|
+
parameters: this.parseParameters(params),
|
|
68
|
+
returnType: returnType?.trim(),
|
|
69
|
+
line: this.getLineNumber(code, match.index),
|
|
70
|
+
isAsync: match[0].includes('async'),
|
|
71
|
+
isExported: match[0].includes('export')
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return functions;
|
|
76
|
+
}
|
|
77
|
+
extractClasses(code) {
|
|
78
|
+
const classes = [];
|
|
79
|
+
const classPattern = /(?:export\s+)?class\s+(\w+)(?:\s+extends\s+(\w+))?\s*\{/g;
|
|
80
|
+
let match;
|
|
81
|
+
while ((match = classPattern.exec(code)) !== null) {
|
|
82
|
+
const [, name, extends_] = match;
|
|
83
|
+
classes.push({
|
|
84
|
+
name,
|
|
85
|
+
extends: extends_,
|
|
86
|
+
line: this.getLineNumber(code, match.index),
|
|
87
|
+
isExported: match[0].includes('export'),
|
|
88
|
+
methods: this.extractClassMethods(code, name),
|
|
89
|
+
properties: this.extractClassProperties(code, name)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return classes;
|
|
93
|
+
}
|
|
94
|
+
extractInterfaces(code) {
|
|
95
|
+
const interfaces = [];
|
|
96
|
+
const interfacePattern = /(?:export\s+)?interface\s+(\w+)(?:\s+extends\s+([^{]+))?\s*\{([^}]+)\}/g;
|
|
97
|
+
let match;
|
|
98
|
+
while ((match = interfacePattern.exec(code)) !== null) {
|
|
99
|
+
const [, name, extends_, body] = match;
|
|
100
|
+
interfaces.push({
|
|
101
|
+
name,
|
|
102
|
+
extends: extends_?.trim(),
|
|
103
|
+
properties: this.parseInterfaceProperties(body),
|
|
104
|
+
line: this.getLineNumber(code, match.index),
|
|
105
|
+
isExported: match[0].includes('export')
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return interfaces;
|
|
109
|
+
}
|
|
110
|
+
extractConstants(code) {
|
|
111
|
+
const constants = [];
|
|
112
|
+
const constPattern = /(?:export\s+)?const\s+(\w+)(?:\s*:\s*([^=]+))?\s*=\s*([^;]+);?/g;
|
|
113
|
+
let match;
|
|
114
|
+
while ((match = constPattern.exec(code)) !== null) {
|
|
115
|
+
const [, name, type, value] = match;
|
|
116
|
+
constants.push({
|
|
117
|
+
name,
|
|
118
|
+
type: type?.trim(),
|
|
119
|
+
value: value?.trim(),
|
|
120
|
+
line: this.getLineNumber(code, match.index),
|
|
121
|
+
isExported: match[0].includes('export')
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return constants;
|
|
125
|
+
}
|
|
126
|
+
extractImports(code) {
|
|
127
|
+
const imports = [];
|
|
128
|
+
const importPattern = /import\s+.*?from\s+['"]([^'"]+)['"]/g;
|
|
129
|
+
let match;
|
|
130
|
+
while ((match = importPattern.exec(code)) !== null) {
|
|
131
|
+
imports.push(match[1]);
|
|
132
|
+
}
|
|
133
|
+
return imports;
|
|
134
|
+
}
|
|
135
|
+
extractExports(code) {
|
|
136
|
+
const exports = [];
|
|
137
|
+
const exportPattern = /export\s+(?:default\s+)?(?:class|function|const|let|var|interface)\s+(\w+)/g;
|
|
138
|
+
let match;
|
|
139
|
+
while ((match = exportPattern.exec(code)) !== null) {
|
|
140
|
+
exports.push(match[1]);
|
|
141
|
+
}
|
|
142
|
+
return exports;
|
|
143
|
+
}
|
|
144
|
+
extractExistingComments(code) {
|
|
145
|
+
const comments = [];
|
|
146
|
+
const lines = code.split('\n');
|
|
147
|
+
lines.forEach((line, index) => {
|
|
148
|
+
const trimmed = line.trim();
|
|
149
|
+
if (trimmed.startsWith('//') || trimmed.startsWith('*')) {
|
|
150
|
+
comments.push({
|
|
151
|
+
line: index + 1,
|
|
152
|
+
comment: trimmed.replace(/^(\/\/|\*)\s*/, ''),
|
|
153
|
+
type: 'existing'
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return comments;
|
|
158
|
+
}
|
|
159
|
+
getLineNumber(code, index) {
|
|
160
|
+
return code.substring(0, index).split('\n').length;
|
|
161
|
+
}
|
|
162
|
+
parseParameters(paramString) {
|
|
163
|
+
if (!paramString.trim())
|
|
164
|
+
return [];
|
|
165
|
+
return paramString.split(',').map(param => {
|
|
166
|
+
const trimmed = param.trim();
|
|
167
|
+
const [nameAndType, defaultValue] = trimmed.split('=');
|
|
168
|
+
const [name, type] = nameAndType.includes(':')
|
|
169
|
+
? nameAndType.split(':').map(s => s.trim())
|
|
170
|
+
: [nameAndType.trim(), 'any'];
|
|
171
|
+
return {
|
|
172
|
+
name,
|
|
173
|
+
type: type || 'any',
|
|
174
|
+
required: !defaultValue,
|
|
175
|
+
description: `Parameter ${name}`,
|
|
176
|
+
defaultValue: defaultValue?.trim()
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
extractClassMethods(code, className) {
|
|
181
|
+
// Simplified method extraction - in practice you'd need more robust parsing
|
|
182
|
+
const methods = [];
|
|
183
|
+
const methodPattern = new RegExp(`class\\s+${className}[^}]*?(\\w+)\\s*\\([^)]*\\)\\s*\\{`, 'g');
|
|
184
|
+
let match;
|
|
185
|
+
while ((match = methodPattern.exec(code)) !== null) {
|
|
186
|
+
methods.push({
|
|
187
|
+
name: match[1],
|
|
188
|
+
line: this.getLineNumber(code, match.index)
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return methods;
|
|
192
|
+
}
|
|
193
|
+
extractClassProperties(code, className) {
|
|
194
|
+
// Simplified property extraction
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
parseInterfaceProperties(body) {
|
|
198
|
+
const properties = [];
|
|
199
|
+
const lines = body.split('\n');
|
|
200
|
+
lines.forEach(line => {
|
|
201
|
+
const trimmed = line.trim().replace(/[;,]$/, '');
|
|
202
|
+
if (trimmed && !trimmed.startsWith('//')) {
|
|
203
|
+
const [name, type] = trimmed.split(':').map(s => s.trim());
|
|
204
|
+
if (name && type) {
|
|
205
|
+
properties.push({
|
|
206
|
+
name,
|
|
207
|
+
type,
|
|
208
|
+
description: `Property ${name}`
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return properties;
|
|
214
|
+
}
|
|
215
|
+
assessCodeComplexity(code) {
|
|
216
|
+
const lines = code.split('\n').length;
|
|
217
|
+
const functions = (code.match(/function/g) || []).length;
|
|
218
|
+
const classes = (code.match(/class/g) || []).length;
|
|
219
|
+
const complexity = lines + functions * 5 + classes * 10;
|
|
220
|
+
return complexity > 500 ? 'high' : complexity > 200 ? 'medium' : 'low';
|
|
221
|
+
}
|
|
222
|
+
inferPurpose(code) {
|
|
223
|
+
// Simple heuristics to infer code purpose
|
|
224
|
+
if (code.includes('express') || code.includes('app.get'))
|
|
225
|
+
return 'Web Server/API';
|
|
226
|
+
if (code.includes('React') || code.includes('useState'))
|
|
227
|
+
return 'React Component';
|
|
228
|
+
if (code.includes('test(') || code.includes('describe('))
|
|
229
|
+
return 'Test Suite';
|
|
230
|
+
if (code.includes('class') && code.includes('extends'))
|
|
231
|
+
return 'Object-Oriented Module';
|
|
232
|
+
if (code.includes('export') && code.includes('function'))
|
|
233
|
+
return 'Utility Library';
|
|
234
|
+
return 'General Purpose Module';
|
|
235
|
+
}
|
|
236
|
+
async generateReadme(structure, style, includeExamples) {
|
|
237
|
+
let readme = '';
|
|
238
|
+
// Title and description
|
|
239
|
+
const title = structure.exports[0] || 'Code Module';
|
|
240
|
+
readme += `# ${title}\n\n`;
|
|
241
|
+
if (style === 'narrative') {
|
|
242
|
+
readme += this.generateNarrativeIntro(structure);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
readme += `## Overview\n\nThis ${structure.purpose.toLowerCase()} provides functionality for:\n\n`;
|
|
246
|
+
structure.functions.slice(0, 3).forEach((func) => {
|
|
247
|
+
readme += `- ${func.name}: Handles ${func.name.toLowerCase()} operations\n`;
|
|
248
|
+
});
|
|
249
|
+
readme += '\n';
|
|
250
|
+
}
|
|
251
|
+
// Installation (if it's a module)
|
|
252
|
+
if (structure.exports.length > 0) {
|
|
253
|
+
readme += `## Installation\n\n\`\`\`bash\nnpm install ${title.toLowerCase()}\n\`\`\`\n\n`;
|
|
254
|
+
}
|
|
255
|
+
// Usage section
|
|
256
|
+
readme += `## Usage\n\n`;
|
|
257
|
+
if (includeExamples && structure.functions.length > 0) {
|
|
258
|
+
const mainFunction = structure.functions[0];
|
|
259
|
+
readme += `\`\`\`typescript\nimport { ${mainFunction.name} } from './${title.toLowerCase()}';\n\n`;
|
|
260
|
+
readme += `// ${this.generateUsageExample(mainFunction)}\n`;
|
|
261
|
+
readme += `const result = ${mainFunction.name}(${this.generateExampleParams(mainFunction.parameters)});\n`;
|
|
262
|
+
readme += `console.error(result);\n\`\`\`\n\n`;
|
|
263
|
+
}
|
|
264
|
+
// API Reference
|
|
265
|
+
if (structure.functions.length > 0) {
|
|
266
|
+
readme += `## API Reference\n\n`;
|
|
267
|
+
structure.functions.slice(0, 5).forEach((func) => {
|
|
268
|
+
readme += `### ${func.name}\n\n`;
|
|
269
|
+
readme += `${this.generateFunctionDescription(func)}\n\n`;
|
|
270
|
+
readme += `**Parameters:**\n`;
|
|
271
|
+
func.parameters.forEach((param) => {
|
|
272
|
+
readme += `- \`${param.name}\` (${param.type}${param.required ? '' : '?'}): ${param.description}\n`;
|
|
273
|
+
});
|
|
274
|
+
readme += '\n';
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
// Contributing
|
|
278
|
+
readme += `## Contributing\n\nPull requests are welcome! Please read the contributing guidelines before submitting.\n\n`;
|
|
279
|
+
// License
|
|
280
|
+
readme += `## License\n\nMIT\n`;
|
|
281
|
+
return readme;
|
|
282
|
+
}
|
|
283
|
+
generateNarrativeIntro(structure) {
|
|
284
|
+
return `Welcome to the epic journey of the ${structure.purpose}! 🚀
|
|
285
|
+
|
|
286
|
+
This isn't just another piece of code - it's a carefully crafted solution that transforms complex problems into elegant solutions.
|
|
287
|
+
|
|
288
|
+
**The Story Begins Here...**
|
|
289
|
+
|
|
290
|
+
Our code embarks on its mission with ${structure.functions.length} powerful functions, each playing a crucial role in the greater narrative. Like characters in an epic tale, each function has its own personality and purpose:
|
|
291
|
+
|
|
292
|
+
${structure.functions.slice(0, 3).map((func, index) => `${index + 1}. **${func.name}**: The ${this.getFunctionPersonality(func.name)} that ${this.generateFunctionStory(func)}`).join('\n')}
|
|
293
|
+
|
|
294
|
+
Ready to join this adventure? Let's dive in! ⚡
|
|
295
|
+
|
|
296
|
+
`;
|
|
297
|
+
}
|
|
298
|
+
getFunctionPersonality(name) {
|
|
299
|
+
const personalities = [
|
|
300
|
+
'wise guardian', 'swift messenger', 'powerful wizard', 'clever strategist',
|
|
301
|
+
'reliable companion', 'mysterious oracle', 'brave warrior', 'skilled craftsman'
|
|
302
|
+
];
|
|
303
|
+
return personalities[name.length % personalities.length];
|
|
304
|
+
}
|
|
305
|
+
generateFunctionStory(func) {
|
|
306
|
+
const actions = ['transforms data into wisdom', 'guards against errors', 'unlocks hidden potential',
|
|
307
|
+
'weaves magic through algorithms', 'builds bridges between components'];
|
|
308
|
+
return actions[func.name.length % actions.length];
|
|
309
|
+
}
|
|
310
|
+
generateUsageExample(func) {
|
|
311
|
+
return `Example: Using ${func.name} to ${func.name.toLowerCase().replace(/([A-Z])/g, ' $1').trim()}`;
|
|
312
|
+
}
|
|
313
|
+
generateExampleParams(params) {
|
|
314
|
+
return params.map(param => {
|
|
315
|
+
if (param.type.includes('string'))
|
|
316
|
+
return `"example"`;
|
|
317
|
+
if (param.type.includes('number'))
|
|
318
|
+
return `42`;
|
|
319
|
+
if (param.type.includes('boolean'))
|
|
320
|
+
return `true`;
|
|
321
|
+
if (param.type.includes('array') || param.type.includes('[]'))
|
|
322
|
+
return `[]`;
|
|
323
|
+
if (param.type.includes('object') || param.type.includes('{'))
|
|
324
|
+
return `{}`;
|
|
325
|
+
return `null`;
|
|
326
|
+
}).join(', ');
|
|
327
|
+
}
|
|
328
|
+
generateFunctionDescription(func) {
|
|
329
|
+
const descriptions = {
|
|
330
|
+
'create': 'Creates a new instance with the specified parameters',
|
|
331
|
+
'get': 'Retrieves data based on the provided criteria',
|
|
332
|
+
'set': 'Updates or sets values with validation',
|
|
333
|
+
'delete': 'Safely removes items with proper cleanup',
|
|
334
|
+
'update': 'Modifies existing data with merge capabilities',
|
|
335
|
+
'parse': 'Transforms raw input into structured data',
|
|
336
|
+
'validate': 'Ensures data integrity and format compliance',
|
|
337
|
+
'calculate': 'Performs complex calculations and returns results',
|
|
338
|
+
'process': 'Handles data transformation and processing workflows',
|
|
339
|
+
'handle': 'Manages events and requests with error handling'
|
|
340
|
+
};
|
|
341
|
+
const funcName = func.name.toLowerCase();
|
|
342
|
+
for (const [prefix, description] of Object.entries(descriptions)) {
|
|
343
|
+
if (funcName.startsWith(prefix))
|
|
344
|
+
return description;
|
|
345
|
+
}
|
|
346
|
+
return `Performs ${funcName} operations with the provided parameters`;
|
|
347
|
+
}
|
|
348
|
+
async generateApiDocs(structure, includeExamples) {
|
|
349
|
+
const apiDocs = [];
|
|
350
|
+
// Document functions
|
|
351
|
+
structure.functions.forEach((func) => {
|
|
352
|
+
apiDocs.push({
|
|
353
|
+
name: func.name,
|
|
354
|
+
type: 'function',
|
|
355
|
+
description: this.generateFunctionDescription(func),
|
|
356
|
+
parameters: func.parameters,
|
|
357
|
+
returns: {
|
|
358
|
+
type: func.returnType || 'any',
|
|
359
|
+
description: `Result of ${func.name} operation`
|
|
360
|
+
},
|
|
361
|
+
examples: includeExamples ? [
|
|
362
|
+
`${func.name}(${this.generateExampleParams(func.parameters)})`
|
|
363
|
+
] : [],
|
|
364
|
+
seeAlso: this.generateSeeAlso(func, structure),
|
|
365
|
+
tags: this.generateTags(func)
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
// Document classes
|
|
369
|
+
structure.classes.forEach((cls) => {
|
|
370
|
+
apiDocs.push({
|
|
371
|
+
name: cls.name,
|
|
372
|
+
type: 'class',
|
|
373
|
+
description: `Class representing ${cls.name.toLowerCase().replace(/([A-Z])/g, ' $1').trim()}`,
|
|
374
|
+
examples: includeExamples ? [
|
|
375
|
+
`const instance = new ${cls.name}();`
|
|
376
|
+
] : [],
|
|
377
|
+
seeAlso: [],
|
|
378
|
+
tags: ['class', 'object-oriented']
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
return apiDocs;
|
|
382
|
+
}
|
|
383
|
+
generateSeeAlso(func, structure) {
|
|
384
|
+
const related = structure.functions
|
|
385
|
+
.filter((f) => f.name !== func.name && f.name.toLowerCase().includes(func.name.toLowerCase().substring(0, 3)))
|
|
386
|
+
.map((f) => f.name)
|
|
387
|
+
.slice(0, 3);
|
|
388
|
+
return related;
|
|
389
|
+
}
|
|
390
|
+
generateTags(func) {
|
|
391
|
+
const tags = ['function'];
|
|
392
|
+
if (func.isAsync)
|
|
393
|
+
tags.push('async');
|
|
394
|
+
if (func.isExported)
|
|
395
|
+
tags.push('exported');
|
|
396
|
+
if (func.parameters.length === 0)
|
|
397
|
+
tags.push('no-params');
|
|
398
|
+
if (func.parameters.length > 3)
|
|
399
|
+
tags.push('many-params');
|
|
400
|
+
return tags;
|
|
401
|
+
}
|
|
402
|
+
async generateInlineComments(code, style) {
|
|
403
|
+
const comments = [];
|
|
404
|
+
const lines = code.split('\n');
|
|
405
|
+
lines.forEach((line, index) => {
|
|
406
|
+
const trimmed = line.trim();
|
|
407
|
+
// Add comments for complex lines
|
|
408
|
+
if (this.isComplexLine(trimmed)) {
|
|
409
|
+
comments.push({
|
|
410
|
+
line: index + 1,
|
|
411
|
+
type: 'explanation',
|
|
412
|
+
comment: this.generateLineComment(trimmed, style),
|
|
413
|
+
complexity: 'high'
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
// Add warnings for potentially problematic patterns
|
|
417
|
+
if (this.isPotentiallyProblematic(trimmed)) {
|
|
418
|
+
comments.push({
|
|
419
|
+
line: index + 1,
|
|
420
|
+
type: 'warning',
|
|
421
|
+
comment: this.generateWarningComment(trimmed),
|
|
422
|
+
complexity: 'medium'
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
// Add TODOs for incomplete patterns
|
|
426
|
+
if (this.needsImprovement(trimmed)) {
|
|
427
|
+
comments.push({
|
|
428
|
+
line: index + 1,
|
|
429
|
+
type: 'todo',
|
|
430
|
+
comment: this.generateTodoComment(trimmed),
|
|
431
|
+
complexity: 'low'
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
return comments;
|
|
436
|
+
}
|
|
437
|
+
isComplexLine(line) {
|
|
438
|
+
return line.length > 80 ||
|
|
439
|
+
(line.match(/[{}()]/g) || []).length > 4 ||
|
|
440
|
+
line.includes('?') && line.includes(':') ||
|
|
441
|
+
line.includes('&&') || line.includes('||');
|
|
442
|
+
}
|
|
443
|
+
isPotentiallyProblematic(line) {
|
|
444
|
+
return line.includes('eval(') ||
|
|
445
|
+
line.includes('innerHTML') ||
|
|
446
|
+
line.includes('document.write') ||
|
|
447
|
+
line.includes('==') && !line.includes('===');
|
|
448
|
+
}
|
|
449
|
+
needsImprovement(line) {
|
|
450
|
+
return line.includes('TODO') ||
|
|
451
|
+
line.includes('FIXME') ||
|
|
452
|
+
line.includes('HACK') ||
|
|
453
|
+
line.trim().startsWith('//') && line.toLowerCase().includes('temp');
|
|
454
|
+
}
|
|
455
|
+
generateLineComment(line, style) {
|
|
456
|
+
if (style === 'narrative') {
|
|
457
|
+
return `// 📖 This line orchestrates ${this.describeLineAction(line)}`;
|
|
458
|
+
}
|
|
459
|
+
return `// ${this.describeLineAction(line)}`;
|
|
460
|
+
}
|
|
461
|
+
describeLineAction(line) {
|
|
462
|
+
if (line.includes('return'))
|
|
463
|
+
return 'the final result delivery';
|
|
464
|
+
if (line.includes('if'))
|
|
465
|
+
return 'conditional logic branching';
|
|
466
|
+
if (line.includes('for') || line.includes('while'))
|
|
467
|
+
return 'iterative processing';
|
|
468
|
+
if (line.includes('try'))
|
|
469
|
+
return 'error-safe operation';
|
|
470
|
+
if (line.includes('await'))
|
|
471
|
+
return 'asynchronous operation waiting';
|
|
472
|
+
return 'a complex operation';
|
|
473
|
+
}
|
|
474
|
+
generateWarningComment(line) {
|
|
475
|
+
return `// ⚠️ Security/Performance concern: Review this pattern`;
|
|
476
|
+
}
|
|
477
|
+
generateTodoComment(line) {
|
|
478
|
+
return `// TODO: Consider refactoring or completing this implementation`;
|
|
479
|
+
}
|
|
480
|
+
async generateChangelog(structure) {
|
|
481
|
+
const changelog = `# Changelog
|
|
482
|
+
|
|
483
|
+
## [1.0.0] - ${new Date().toISOString().split('T')[0]}
|
|
484
|
+
|
|
485
|
+
### Added
|
|
486
|
+
${structure.functions.map((func) => `- \`${func.name}\` function for enhanced functionality`).join('\n')}
|
|
487
|
+
${structure.classes.map((cls) => `- \`${cls.name}\` class for object-oriented operations`).join('\n')}
|
|
488
|
+
|
|
489
|
+
### Features
|
|
490
|
+
- Comprehensive API with ${structure.functions.length} functions
|
|
491
|
+
- ${structure.interfaces.length} well-defined interfaces
|
|
492
|
+
- Full TypeScript support
|
|
493
|
+
- Extensive documentation
|
|
494
|
+
|
|
495
|
+
### Technical Details
|
|
496
|
+
- Code complexity: ${structure.complexity}
|
|
497
|
+
- Total exports: ${structure.exports.length}
|
|
498
|
+
- Dependencies: ${structure.imports.length}
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
*This changelog follows [Semantic Versioning](https://semver.org/) guidelines.*
|
|
503
|
+
`;
|
|
504
|
+
return changelog;
|
|
505
|
+
}
|
|
506
|
+
async generateNarrativeDoc(structure, code) {
|
|
507
|
+
return `# The Epic Tale of Our Code 📚
|
|
508
|
+
|
|
509
|
+
## Chapter 1: The Origin Story
|
|
510
|
+
|
|
511
|
+
Once upon a time, in the mystical realm of software development, there lived a ${structure.purpose}. This wasn't just any ordinary piece of code - it was destined for greatness!
|
|
512
|
+
|
|
513
|
+
Our story begins with ${structure.functions.length} mighty functions, each with their own unique powers and responsibilities...
|
|
514
|
+
|
|
515
|
+
## Chapter 2: The Heroes
|
|
516
|
+
|
|
517
|
+
${structure.functions.slice(0, 3).map((func, index) => `
|
|
518
|
+
### ${func.name} - The ${this.getFunctionPersonality(func.name)}
|
|
519
|
+
|
|
520
|
+
*"I shall ${this.generateFunctionStory(func)}!"*
|
|
521
|
+
|
|
522
|
+
With ${func.parameters.length} trusty parameters by their side, ${func.name} stands ready to face any challenge. Their journey began on line ${func.line}, where they first declared their noble purpose.
|
|
523
|
+
`).join('')}
|
|
524
|
+
|
|
525
|
+
## Chapter 3: The Architecture
|
|
526
|
+
|
|
527
|
+
The grand design of our system follows the sacred patterns:
|
|
528
|
+
|
|
529
|
+
- **Modularity**: Each piece serves a specific purpose
|
|
530
|
+
- **Maintainability**: Future heroes can easily understand and extend
|
|
531
|
+
- **Reliability**: Built with error handling and validation
|
|
532
|
+
|
|
533
|
+
## Chapter 4: The Quest Continues...
|
|
534
|
+
|
|
535
|
+
As our code evolves, new chapters will be written. Each commit tells a story, each function solves a problem, and each bug fix makes our code stronger.
|
|
536
|
+
|
|
537
|
+
*To be continued...*
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
**Moral of the Story**: Great code is like a great book - it tells a story, has memorable characters (functions), and leaves the reader (developer) satisfied and enlightened.
|
|
542
|
+
`;
|
|
543
|
+
}
|
|
544
|
+
synthesizeDocumentation(readme, apiDocs, inlineComments, changelog, narrativeDoc) {
|
|
545
|
+
let synthesis = `## Documentation Generation Summary\n\n`;
|
|
546
|
+
synthesis += `**Generated Documentation:**\n`;
|
|
547
|
+
synthesis += `- README.md: ${readme.split('\n').length} lines\n`;
|
|
548
|
+
synthesis += `- API Documentation: ${apiDocs.length} items\n`;
|
|
549
|
+
synthesis += `- Inline Comments: ${inlineComments.length} suggestions\n`;
|
|
550
|
+
synthesis += `- Changelog: Generated with version history\n`;
|
|
551
|
+
if (narrativeDoc) {
|
|
552
|
+
synthesis += `- Narrative Documentation: Epic storytelling format\n`;
|
|
553
|
+
}
|
|
554
|
+
synthesis += `\n**Documentation Quality:**\n`;
|
|
555
|
+
const hasExamples = apiDocs.some(doc => doc.examples.length > 0);
|
|
556
|
+
const hasParameters = apiDocs.some(doc => doc.parameters && doc.parameters.length > 0);
|
|
557
|
+
const hasWarnings = inlineComments.some(comment => comment.type === 'warning');
|
|
558
|
+
synthesis += `- Examples included: ${hasExamples ? '✅' : '❌'}\n`;
|
|
559
|
+
synthesis += `- Parameter documentation: ${hasParameters ? '✅' : '❌'}\n`;
|
|
560
|
+
synthesis += `- Code warnings identified: ${hasWarnings ? '✅' : '❌'}\n`;
|
|
561
|
+
const complexComments = inlineComments.filter(c => c.complexity === 'high').length;
|
|
562
|
+
if (complexComments > 0) {
|
|
563
|
+
synthesis += `- Complex code sections documented: ${complexComments}\n`;
|
|
564
|
+
}
|
|
565
|
+
synthesis += `\n**Next Steps:**\n`;
|
|
566
|
+
synthesis += `1. Review generated README and customize as needed\n`;
|
|
567
|
+
synthesis += `2. Add generated inline comments to source files\n`;
|
|
568
|
+
synthesis += `3. Update changelog with actual version information\n`;
|
|
569
|
+
synthesis += `4. Consider generating additional documentation for complex APIs\n`;
|
|
570
|
+
return synthesis;
|
|
571
|
+
}
|
|
572
|
+
}
|