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.
Files changed (214) hide show
  1. package/.env.example +260 -0
  2. package/CHANGELOG.md +54 -0
  3. package/CODE_OF_CONDUCT.md +56 -0
  4. package/CONTRIBUTING.md +54 -0
  5. package/Dockerfile +36 -0
  6. package/LICENSE +644 -0
  7. package/README.md +201 -0
  8. package/SECURITY.md +95 -0
  9. package/dist/personality/komaai-expressions.js +12 -0
  10. package/dist/profiles/balanced.json +33 -0
  11. package/dist/profiles/code_focus.json +33 -0
  12. package/dist/profiles/full.json +33 -0
  13. package/dist/profiles/minimal.json +33 -0
  14. package/dist/profiles/research_power.json +33 -0
  15. package/dist/scripts/build-profiles.js +46 -0
  16. package/dist/src/application/services/focus/FocusModeRegistry.js +46 -0
  17. package/dist/src/application/services/focus/FocusTool.service.js +109 -0
  18. package/dist/src/application/services/focus/ModeRegistry.js +46 -0
  19. package/dist/src/application/services/focus/modes/focus-deep.mode.js +27 -0
  20. package/dist/src/application/services/focus/modes/status.mode.js +50 -0
  21. package/dist/src/application/services/focus/modes/tachibot-status.mode.js +50 -0
  22. package/dist/src/collaborative-orchestrator.js +391 -0
  23. package/dist/src/config/model-constants.js +188 -0
  24. package/dist/src/config/model-defaults.js +57 -0
  25. package/dist/src/config/model-preferences.js +382 -0
  26. package/dist/src/config/timeout-config.js +130 -0
  27. package/dist/src/config.js +173 -0
  28. package/dist/src/domain/interfaces/IFocusMode.js +5 -0
  29. package/dist/src/domain/interfaces/IProvider.js +6 -0
  30. package/dist/src/domain/interfaces/ITool.js +5 -0
  31. package/dist/src/focus-deep.js +245 -0
  32. package/dist/src/infrastructure/ascii/art/robots.ascii.js +16 -0
  33. package/dist/src/mcp-client.js +90 -0
  34. package/dist/src/memory/index.js +17 -0
  35. package/dist/src/memory/memory-config.js +135 -0
  36. package/dist/src/memory/memory-interface.js +174 -0
  37. package/dist/src/memory/memory-manager.js +383 -0
  38. package/dist/src/memory/providers/devlog-provider.js +385 -0
  39. package/dist/src/memory/providers/hybrid-provider.js +399 -0
  40. package/dist/src/memory/providers/local-provider.js +388 -0
  41. package/dist/src/memory/providers/mem0-provider.js +337 -0
  42. package/dist/src/modes/architect.js +477 -0
  43. package/dist/src/modes/auditor.js +362 -0
  44. package/dist/src/modes/challenger.js +841 -0
  45. package/dist/src/modes/code-reviewer.js +382 -0
  46. package/dist/src/modes/commit-guardian.js +424 -0
  47. package/dist/src/modes/documentation-writer.js +572 -0
  48. package/dist/src/modes/scout.js +587 -0
  49. package/dist/src/modes/shared/helpers/challenger-helpers.js +454 -0
  50. package/dist/src/modes/shared/helpers/index.js +17 -0
  51. package/dist/src/modes/shared/helpers/scout-helpers.js +270 -0
  52. package/dist/src/modes/shared/helpers/verifier-helpers.js +332 -0
  53. package/dist/src/modes/test-architect.js +767 -0
  54. package/dist/src/modes/verifier.js +378 -0
  55. package/dist/src/monitoring/performance-monitor.js +435 -0
  56. package/dist/src/optimization/batch-executor.js +121 -0
  57. package/dist/src/optimization/context-pruner.js +196 -0
  58. package/dist/src/optimization/cost-monitor.js +338 -0
  59. package/dist/src/optimization/index.js +65 -0
  60. package/dist/src/optimization/model-router.js +264 -0
  61. package/dist/src/optimization/result-cache.js +114 -0
  62. package/dist/src/optimization/token-optimizer.js +257 -0
  63. package/dist/src/optimization/token-tracker.js +118 -0
  64. package/dist/src/orchestrator-instructions.js +128 -0
  65. package/dist/src/orchestrator-lite.js +139 -0
  66. package/dist/src/orchestrator.js +191 -0
  67. package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionEngine.js +1 -0
  68. package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionStrategy.js +5 -0
  69. package/dist/src/orchestrators/collaborative/interfaces/IVisualizationRenderer.js +1 -0
  70. package/dist/src/orchestrators/collaborative/registries/ModelProviderRegistry.js +95 -0
  71. package/dist/src/orchestrators/collaborative/registries/ToolAdapterRegistry.js +64 -0
  72. package/dist/src/orchestrators/collaborative/services/tool-execution/ToolExecutionService.js +502 -0
  73. package/dist/src/orchestrators/collaborative/services/visualization/VisualizationService.js +206 -0
  74. package/dist/src/orchestrators/collaborative/types/session-types.js +5 -0
  75. package/dist/src/profiles/balanced.js +37 -0
  76. package/dist/src/profiles/code_focus.js +37 -0
  77. package/dist/src/profiles/debug_intensive.js +59 -0
  78. package/dist/src/profiles/full.js +37 -0
  79. package/dist/src/profiles/minimal.js +37 -0
  80. package/dist/src/profiles/research_code.js +59 -0
  81. package/dist/src/profiles/research_power.js +37 -0
  82. package/dist/src/profiles/types.js +5 -0
  83. package/dist/src/profiles/workflow_builder.js +53 -0
  84. package/dist/src/prompt-engineer-lite.js +78 -0
  85. package/dist/src/prompt-engineer.js +399 -0
  86. package/dist/src/reasoning-chain.js +508 -0
  87. package/dist/src/sequential-thinking.js +291 -0
  88. package/dist/src/server-diagnostic.js +74 -0
  89. package/dist/src/server-raw.js +158 -0
  90. package/dist/src/server-simple.js +58 -0
  91. package/dist/src/server.js +514 -0
  92. package/dist/src/session/session-logger.js +617 -0
  93. package/dist/src/session/session-manager.js +571 -0
  94. package/dist/src/session/session-tools.js +400 -0
  95. package/dist/src/tools/advanced-modes.js +200 -0
  96. package/dist/src/tools/claude-integration.js +356 -0
  97. package/dist/src/tools/consolidated/ai-router.js +174 -0
  98. package/dist/src/tools/consolidated/ai-tool.js +48 -0
  99. package/dist/src/tools/consolidated/brainstorm-tool.js +87 -0
  100. package/dist/src/tools/consolidated/environment-detector.js +80 -0
  101. package/dist/src/tools/consolidated/index.js +50 -0
  102. package/dist/src/tools/consolidated/search-tool.js +110 -0
  103. package/dist/src/tools/consolidated/workflow-tool.js +238 -0
  104. package/dist/src/tools/gemini-tools.js +329 -0
  105. package/dist/src/tools/grok-enhanced.js +376 -0
  106. package/dist/src/tools/grok-tools.js +299 -0
  107. package/dist/src/tools/lmstudio-tools.js +223 -0
  108. package/dist/src/tools/openai-tools.js +498 -0
  109. package/dist/src/tools/openrouter-tools.js +317 -0
  110. package/dist/src/tools/optimized-wrapper.js +204 -0
  111. package/dist/src/tools/perplexity-tools.js +294 -0
  112. package/dist/src/tools/pingpong-tool.js +343 -0
  113. package/dist/src/tools/qwen-wrapper.js +74 -0
  114. package/dist/src/tools/tool-router.js +444 -0
  115. package/dist/src/tools/unified-ai-provider.js +260 -0
  116. package/dist/src/tools/workflow-runner.js +425 -0
  117. package/dist/src/tools/workflow-validator-tool.js +107 -0
  118. package/dist/src/types.js +23 -0
  119. package/dist/src/utils/input-validator.js +130 -0
  120. package/dist/src/utils/model-router.js +91 -0
  121. package/dist/src/utils/progress-stream.js +255 -0
  122. package/dist/src/utils/provider-router.js +88 -0
  123. package/dist/src/utils/smart-api-client.js +146 -0
  124. package/dist/src/utils/table-builder.js +218 -0
  125. package/dist/src/utils/timestamp-formatter.js +134 -0
  126. package/dist/src/utils/tool-compressor.js +257 -0
  127. package/dist/src/utils/tool-config.js +201 -0
  128. package/dist/src/validators/dependency-graph-validator.js +147 -0
  129. package/dist/src/validators/interpolation-validator.js +222 -0
  130. package/dist/src/validators/output-usage-validator.js +151 -0
  131. package/dist/src/validators/syntax-validator.js +102 -0
  132. package/dist/src/validators/tool-registry-validator.js +123 -0
  133. package/dist/src/validators/tool-types.js +97 -0
  134. package/dist/src/validators/types.js +8 -0
  135. package/dist/src/validators/workflow-validator.js +134 -0
  136. package/dist/src/visualizer-lite.js +42 -0
  137. package/dist/src/visualizer.js +179 -0
  138. package/dist/src/workflows/circuit-breaker.js +199 -0
  139. package/dist/src/workflows/custom-workflows.js +451 -0
  140. package/dist/src/workflows/engine/AutoSynthesizer.js +97 -0
  141. package/dist/src/workflows/engine/StepParameterResolver.js +74 -0
  142. package/dist/src/workflows/engine/VariableInterpolator.js +123 -0
  143. package/dist/src/workflows/engine/WorkflowDiscovery.js +125 -0
  144. package/dist/src/workflows/engine/WorkflowExecutionEngine.js +485 -0
  145. package/dist/src/workflows/engine/WorkflowExecutor.js +113 -0
  146. package/dist/src/workflows/engine/WorkflowFileManager.js +244 -0
  147. package/dist/src/workflows/engine/WorkflowHelpers.js +114 -0
  148. package/dist/src/workflows/engine/WorkflowOutputFormatter.js +83 -0
  149. package/dist/src/workflows/engine/events/WorkflowEventBus.js +132 -0
  150. package/dist/src/workflows/engine/events/interfaces/IEventBus.js +5 -0
  151. package/dist/src/workflows/engine/handlers/ErrorRecoveryHandler.js +162 -0
  152. package/dist/src/workflows/engine/handlers/PromptEnhancementHandler.js +115 -0
  153. package/dist/src/workflows/engine/handlers/SessionPersistenceHandler.js +167 -0
  154. package/dist/src/workflows/engine/handlers/StepExecutionHandler.js +231 -0
  155. package/dist/src/workflows/engine/handlers/ToolInvocationHandler.js +46 -0
  156. package/dist/src/workflows/engine/interfaces/IAutoSynthesizer.js +5 -0
  157. package/dist/src/workflows/engine/interfaces/IStepParameterResolver.js +5 -0
  158. package/dist/src/workflows/engine/interfaces/IVariableInterpolator.js +5 -0
  159. package/dist/src/workflows/engine/interfaces/IWorkflowDiscovery.js +4 -0
  160. package/dist/src/workflows/engine/interfaces/IWorkflowFileManager.js +5 -0
  161. package/dist/src/workflows/engine/interfaces/IWorkflowOutputFormatter.js +5 -0
  162. package/dist/src/workflows/engine/state/WorkflowStateMachine.js +194 -0
  163. package/dist/src/workflows/engine/state/interfaces/IStateMachine.js +17 -0
  164. package/dist/src/workflows/fallback-strategies.js +373 -0
  165. package/dist/src/workflows/message-queue.js +455 -0
  166. package/dist/src/workflows/model-router.js +189 -0
  167. package/dist/src/workflows/orchestrator-examples.js +174 -0
  168. package/dist/src/workflows/orchestrator-integration.js +200 -0
  169. package/dist/src/workflows/self-healing.js +524 -0
  170. package/dist/src/workflows/tool-mapper.js +407 -0
  171. package/dist/src/workflows/tool-orchestrator.js +796 -0
  172. package/dist/src/workflows/workflow-engine.js +573 -0
  173. package/dist/src/workflows/workflow-parser.js +283 -0
  174. package/dist/src/workflows/workflow-types.js +95 -0
  175. package/dist/src/workflows.js +568 -0
  176. package/dist/test-workflow-file-output.js +93 -0
  177. package/docs/API_KEYS.md +570 -0
  178. package/docs/CLAUDE_CODE_SETUP.md +181 -0
  179. package/docs/CLAUDE_DESKTOP_MANUAL.md +127 -0
  180. package/docs/CONFIGURATION.md +745 -0
  181. package/docs/FOCUS_MODES.md +240 -0
  182. package/docs/INSTALLATION_BOTH.md +145 -0
  183. package/docs/TERMS.md +352 -0
  184. package/docs/TOOLS_REFERENCE.md +1622 -0
  185. package/docs/TOOL_PARAMETERS.md +496 -0
  186. package/docs/TOOL_PROFILES.md +236 -0
  187. package/docs/WORKFLOWS.md +987 -0
  188. package/docs/WORKFLOW_OUTPUT.md +198 -0
  189. package/docs/WORKFLOW_PROGRESS_TRACKING.md +305 -0
  190. package/docs/workflows/design-brainstorm.md +335 -0
  191. package/package.json +97 -0
  192. package/profiles/balanced.json +37 -0
  193. package/profiles/code_focus.json +37 -0
  194. package/profiles/debug_intensive.json +34 -0
  195. package/profiles/full.json +37 -0
  196. package/profiles/minimal.json +37 -0
  197. package/profiles/research_power.json +37 -0
  198. package/profiles/workflow_builder.json +37 -0
  199. package/smithery.yaml +66 -0
  200. package/start.sh +8 -0
  201. package/tools.config.json +81 -0
  202. package/tsconfig.json +18 -0
  203. package/workflows/accessibility-code-audit.yaml +92 -0
  204. package/workflows/code-architecture-review.yaml +202 -0
  205. package/workflows/code-review.yaml +142 -0
  206. package/workflows/core/iterative-problem-solver.yaml +283 -0
  207. package/workflows/creative-brainstorm-yaml.yaml +215 -0
  208. package/workflows/pingpong.yaml +141 -0
  209. package/workflows/system/README.md +412 -0
  210. package/workflows/system/challenger.yaml +175 -0
  211. package/workflows/system/scout.yaml +164 -0
  212. package/workflows/system/verifier.yaml +133 -0
  213. package/workflows/ultra-creative-brainstorm.yaml +318 -0
  214. package/workflows/ux-research-flow.yaml +92 -0
@@ -0,0 +1,424 @@
1
+ export class CommitGuardian {
2
+ constructor() {
3
+ this.defaultModel = 'gemini-2.5-flash';
4
+ this.defaultMaxTokens = 5000;
5
+ this.securityPatterns = [
6
+ { pattern: /api[_-]?key/i, type: 'api_key' },
7
+ { pattern: /password\s*=\s*["'][^"']+["']/i, type: 'hardcoded_password' },
8
+ { pattern: /token\s*=\s*["'][^"']+["']/i, type: 'hardcoded_token' },
9
+ { pattern: /secret\s*=\s*["'][^"']+["']/i, type: 'hardcoded_secret' },
10
+ { pattern: /private[_-]?key/i, type: 'private_key' },
11
+ { pattern: /eval\s*\(/i, type: 'dangerous_eval' },
12
+ { pattern: /exec\s*\(/i, type: 'dangerous_exec' },
13
+ { pattern: /innerHTML\s*=/i, type: 'xss_risk' },
14
+ { pattern: /TODO\s*:?\s*security/i, type: 'security_todo' }
15
+ ];
16
+ this.qualityPatterns = [
17
+ { pattern: /console\.(log|error|warn|debug)/i, type: 'console_log' },
18
+ { pattern: /debugger/i, type: 'debugger_statement' },
19
+ { pattern: /TODO|FIXME|HACK|XXX/i, type: 'todo_comment' },
20
+ { pattern: /^\s*\/\/.*$/gm, type: 'commented_code', count: true },
21
+ { pattern: /\t/, type: 'mixed_indentation' },
22
+ { pattern: /\s+$/gm, type: 'trailing_whitespace' }
23
+ ];
24
+ }
25
+ async validate(context, options = {}) {
26
+ const model = options.model || this.defaultModel;
27
+ const maxTokens = options.maxTokens || this.defaultMaxTokens;
28
+ const strict = options.strict !== false;
29
+ const checks = [];
30
+ const blockers = [];
31
+ const warnings = [];
32
+ const suggestions = [];
33
+ // Run security checks
34
+ if (options.checkSecurity !== false) {
35
+ const securityCheck = await this.runSecurityChecks(context, model, maxTokens * 0.4);
36
+ checks.push(...securityCheck.checks);
37
+ blockers.push(...securityCheck.blockers);
38
+ warnings.push(...securityCheck.warnings);
39
+ }
40
+ // Run quality checks
41
+ if (options.checkQuality !== false) {
42
+ const qualityCheck = await this.runQualityChecks(context, model, maxTokens * 0.3);
43
+ checks.push(...qualityCheck.checks);
44
+ if (strict) {
45
+ blockers.push(...qualityCheck.blockers);
46
+ }
47
+ else {
48
+ warnings.push(...qualityCheck.blockers);
49
+ }
50
+ warnings.push(...qualityCheck.warnings);
51
+ }
52
+ // Run test checks
53
+ if (options.checkTests !== false) {
54
+ const testCheck = await this.runTestChecks(context, maxTokens * 0.2);
55
+ checks.push(...testCheck.checks);
56
+ warnings.push(...testCheck.warnings);
57
+ }
58
+ // Check dependencies
59
+ const depCheck = await this.checkDependencies(context, maxTokens * 0.1);
60
+ checks.push(...depCheck.checks);
61
+ warnings.push(...depCheck.warnings);
62
+ // Generate suggestions
63
+ suggestions.push(...this.generateSuggestions(checks, blockers, warnings));
64
+ // Calculate overall score
65
+ const score = this.calculateScore(checks, blockers, warnings);
66
+ const passed = blockers.length === 0 && score >= (strict ? 80 : 60);
67
+ const readyToCommit = passed && blockers.length === 0;
68
+ // Generate summary
69
+ const summary = this.generateSummary(checks, blockers, warnings, score, readyToCommit);
70
+ return {
71
+ passed,
72
+ score,
73
+ checks,
74
+ blockers,
75
+ warnings,
76
+ suggestions,
77
+ readyToCommit,
78
+ summary
79
+ };
80
+ }
81
+ async runSecurityChecks(context, model, maxTokens) {
82
+ const checks = [];
83
+ const blockers = [];
84
+ const warnings = [];
85
+ const files = this.extractFiles(context);
86
+ for (const file of files) {
87
+ const content = file.content || '';
88
+ // Check for security patterns
89
+ for (const { pattern, type } of this.securityPatterns) {
90
+ const matches = content.match(pattern);
91
+ if (matches) {
92
+ const severity = this.getSecuritySeverity(type);
93
+ const issue = {
94
+ type,
95
+ severity,
96
+ file: file.path,
97
+ description: `Found ${type.replace(/_/g, ' ')}: ${matches[0].substring(0, 50)}...`,
98
+ suggestion: this.getSecuritySuggestion(type)
99
+ };
100
+ if (severity === 'critical') {
101
+ blockers.push(issue);
102
+ }
103
+ else {
104
+ warnings.push(issue);
105
+ }
106
+ checks.push({
107
+ name: `Security: ${type}`,
108
+ category: 'security',
109
+ passed: false,
110
+ severity: severity === 'critical' ? 'blocker' : 'error',
111
+ details: issue.description,
112
+ affectedFiles: [file.path]
113
+ });
114
+ }
115
+ }
116
+ }
117
+ // If no security issues found
118
+ if (checks.length === 0) {
119
+ checks.push({
120
+ name: 'Security Check',
121
+ category: 'security',
122
+ passed: true,
123
+ severity: 'info',
124
+ details: 'No security vulnerabilities detected'
125
+ });
126
+ }
127
+ return { checks, blockers, warnings };
128
+ }
129
+ async runQualityChecks(context, model, maxTokens) {
130
+ const checks = [];
131
+ const blockers = [];
132
+ const warnings = [];
133
+ const files = this.extractFiles(context);
134
+ let totalIssues = 0;
135
+ for (const file of files) {
136
+ const content = file.content || '';
137
+ // Check for quality patterns
138
+ for (const { pattern, type, count } of this.qualityPatterns) {
139
+ const matches = content.match(pattern);
140
+ if (matches && matches.length > 0) {
141
+ const issueCount = count ? matches.length : 1;
142
+ totalIssues += issueCount;
143
+ const severity = this.getQualitySeverity(type, issueCount);
144
+ const issue = {
145
+ type,
146
+ severity,
147
+ file: file.path,
148
+ description: `Found ${issueCount} instance(s) of ${type.replace(/_/g, ' ')}`,
149
+ suggestion: this.getQualitySuggestion(type)
150
+ };
151
+ if (type === 'console_log' || type === 'debugger_statement') {
152
+ blockers.push(issue);
153
+ }
154
+ else {
155
+ warnings.push(issue);
156
+ }
157
+ }
158
+ }
159
+ // Check code complexity
160
+ const complexity = this.calculateComplexity(content);
161
+ if (complexity > 10) {
162
+ warnings.push({
163
+ type: 'high_complexity',
164
+ severity: 'medium',
165
+ file: file.path,
166
+ description: `High cyclomatic complexity: ${complexity}`,
167
+ suggestion: 'Consider refactoring to reduce complexity'
168
+ });
169
+ }
170
+ }
171
+ checks.push({
172
+ name: 'Code Quality',
173
+ category: 'quality',
174
+ passed: totalIssues === 0,
175
+ severity: totalIssues > 10 ? 'error' : totalIssues > 0 ? 'warning' : 'info',
176
+ details: `Found ${totalIssues} quality issues`,
177
+ affectedFiles: files.map(f => f.path)
178
+ });
179
+ return { checks, blockers, warnings };
180
+ }
181
+ async runTestChecks(context, maxTokens) {
182
+ const checks = [];
183
+ const warnings = [];
184
+ const files = this.extractFiles(context);
185
+ const testFiles = files.filter(f => f.path.includes('.test.') ||
186
+ f.path.includes('.spec.') ||
187
+ f.path.includes('__tests__'));
188
+ const modifiedSourceFiles = files.filter(f => !f.path.includes('.test.') &&
189
+ !f.path.includes('.spec.') &&
190
+ (f.path.endsWith('.ts') || f.path.endsWith('.js') || f.path.endsWith('.tsx') || f.path.endsWith('.jsx')));
191
+ // Check test coverage
192
+ if (modifiedSourceFiles.length > 0 && testFiles.length === 0) {
193
+ warnings.push({
194
+ type: 'missing_tests',
195
+ severity: 'medium',
196
+ description: 'Source files modified but no test files included',
197
+ suggestion: 'Consider adding or updating tests for the modified code'
198
+ });
199
+ checks.push({
200
+ name: 'Test Coverage',
201
+ category: 'tests',
202
+ passed: false,
203
+ severity: 'warning',
204
+ details: 'No test files found for modified source files'
205
+ });
206
+ }
207
+ else if (testFiles.length > 0) {
208
+ checks.push({
209
+ name: 'Test Coverage',
210
+ category: 'tests',
211
+ passed: true,
212
+ severity: 'info',
213
+ details: `Found ${testFiles.length} test file(s)`
214
+ });
215
+ }
216
+ // Check for skipped tests
217
+ for (const file of testFiles) {
218
+ const content = file.content || '';
219
+ if (content.includes('.skip(') || content.includes('.only(')) {
220
+ warnings.push({
221
+ type: 'test_modifiers',
222
+ severity: 'medium',
223
+ file: file.path,
224
+ description: 'Found .skip() or .only() in tests',
225
+ suggestion: 'Remove .skip() and .only() before committing'
226
+ });
227
+ }
228
+ }
229
+ return { checks, warnings };
230
+ }
231
+ async checkDependencies(context, maxTokens) {
232
+ const checks = [];
233
+ const warnings = [];
234
+ const files = this.extractFiles(context);
235
+ const packageFiles = files.filter(f => f.path.includes('package.json'));
236
+ for (const file of packageFiles) {
237
+ const content = file.content || '';
238
+ try {
239
+ const pkg = JSON.parse(content);
240
+ // Check for missing dependencies
241
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
242
+ const hasVulnerableDeps = this.checkVulnerableDependencies(deps);
243
+ if (hasVulnerableDeps.length > 0) {
244
+ warnings.push({
245
+ type: 'vulnerable_dependencies',
246
+ severity: 'high',
247
+ file: file.path,
248
+ description: `Found potentially vulnerable dependencies: ${hasVulnerableDeps.join(', ')}`,
249
+ suggestion: 'Update dependencies to latest secure versions'
250
+ });
251
+ }
252
+ checks.push({
253
+ name: 'Dependency Check',
254
+ category: 'dependencies',
255
+ passed: hasVulnerableDeps.length === 0,
256
+ severity: hasVulnerableDeps.length > 0 ? 'warning' : 'info',
257
+ details: hasVulnerableDeps.length > 0 ?
258
+ `${hasVulnerableDeps.length} vulnerable dependencies` :
259
+ 'All dependencies appear secure',
260
+ affectedFiles: [file.path]
261
+ });
262
+ }
263
+ catch (e) {
264
+ // Not a valid JSON
265
+ }
266
+ }
267
+ return { checks, warnings };
268
+ }
269
+ checkVulnerableDependencies(deps) {
270
+ const vulnerable = [];
271
+ // Simple check for known vulnerable versions (would use actual vulnerability DB)
272
+ const knownVulnerable = {
273
+ 'lodash': (version) => version.includes('4.17.11'),
274
+ 'axios': (version) => version.includes('0.21.0'),
275
+ 'minimist': (version) => version.includes('1.2.5')
276
+ };
277
+ for (const [name, version] of Object.entries(deps)) {
278
+ if (knownVulnerable[name] && knownVulnerable[name](version)) {
279
+ vulnerable.push(name);
280
+ }
281
+ }
282
+ return vulnerable;
283
+ }
284
+ generateSuggestions(checks, blockers, warnings) {
285
+ const suggestions = [];
286
+ if (blockers.length > 0) {
287
+ suggestions.push(`Fix ${blockers.length} blocking issue(s) before committing`);
288
+ }
289
+ const securityIssues = blockers.concat(warnings).filter(i => i.type.includes('key') || i.type.includes('password') || i.type.includes('secret'));
290
+ if (securityIssues.length > 0) {
291
+ suggestions.push('Use environment variables for sensitive data');
292
+ suggestions.push('Add sensitive files to .gitignore');
293
+ }
294
+ const qualityIssues = warnings.filter(i => i.type.includes('console') || i.type.includes('debugger'));
295
+ if (qualityIssues.length > 0) {
296
+ suggestions.push('Remove debugging statements before committing');
297
+ }
298
+ const testIssues = checks.filter(c => c.category === 'tests' && !c.passed);
299
+ if (testIssues.length > 0) {
300
+ suggestions.push('Add tests for modified code');
301
+ suggestions.push('Run test suite to ensure all tests pass');
302
+ }
303
+ if (warnings.filter(w => w.type === 'high_complexity').length > 0) {
304
+ suggestions.push('Consider refactoring complex functions');
305
+ }
306
+ return suggestions;
307
+ }
308
+ calculateScore(checks, blockers, warnings) {
309
+ let score = 100;
310
+ // Deduct for blockers
311
+ score -= blockers.length * 20;
312
+ // Deduct for warnings
313
+ score -= warnings.length * 5;
314
+ // Deduct for failed checks
315
+ const failedChecks = checks.filter(c => !c.passed);
316
+ score -= failedChecks.length * 10;
317
+ return Math.max(0, Math.min(100, score));
318
+ }
319
+ generateSummary(checks, blockers, warnings, score, readyToCommit) {
320
+ let summary = '';
321
+ if (readyToCommit) {
322
+ summary = `✅ **Ready to commit!** Score: ${score}/100\n\n`;
323
+ summary += 'All checks passed. Your code is ready for commit.';
324
+ }
325
+ else if (blockers.length > 0) {
326
+ summary = `🚫 **Commit blocked!** Score: ${score}/100\n\n`;
327
+ summary += `Found ${blockers.length} blocking issue(s):\n`;
328
+ blockers.forEach(b => {
329
+ summary += `- ${b.description}\n`;
330
+ });
331
+ }
332
+ else {
333
+ summary = `⚠️ **Review recommended** Score: ${score}/100\n\n`;
334
+ summary += `Found ${warnings.length} warning(s). Consider addressing these before committing:\n`;
335
+ warnings.slice(0, 5).forEach(w => {
336
+ summary += `- ${w.description}\n`;
337
+ });
338
+ }
339
+ summary += `\n\n**Checks Summary:**\n`;
340
+ summary += `- Security: ${checks.filter(c => c.category === 'security' && c.passed).length}/${checks.filter(c => c.category === 'security').length} passed\n`;
341
+ summary += `- Quality: ${checks.filter(c => c.category === 'quality' && c.passed).length}/${checks.filter(c => c.category === 'quality').length} passed\n`;
342
+ summary += `- Tests: ${checks.filter(c => c.category === 'tests' && c.passed).length}/${checks.filter(c => c.category === 'tests').length} passed\n`;
343
+ return summary;
344
+ }
345
+ extractFiles(context) {
346
+ // Simulated file extraction
347
+ if (typeof context === 'string') {
348
+ return [{ path: 'unknown', content: context }];
349
+ }
350
+ if (context.files) {
351
+ return context.files;
352
+ }
353
+ if (context.changes) {
354
+ return context.changes.map((c) => ({ path: c.file, content: c.content }));
355
+ }
356
+ return [];
357
+ }
358
+ getSecuritySeverity(type) {
359
+ const critical = ['api_key', 'private_key', 'hardcoded_password', 'hardcoded_token'];
360
+ const high = ['hardcoded_secret', 'dangerous_eval', 'dangerous_exec'];
361
+ const medium = ['xss_risk'];
362
+ if (critical.includes(type))
363
+ return 'critical';
364
+ if (high.includes(type))
365
+ return 'high';
366
+ if (medium.includes(type))
367
+ return 'medium';
368
+ return 'low';
369
+ }
370
+ getQualitySeverity(type, count) {
371
+ if (type === 'console_log' || type === 'debugger_statement') {
372
+ return count > 5 ? 'high' : 'medium';
373
+ }
374
+ if (type === 'commented_code' && count > 50) {
375
+ return 'medium';
376
+ }
377
+ return 'low';
378
+ }
379
+ getSecuritySuggestion(type) {
380
+ const suggestions = {
381
+ 'api_key': 'Store API keys in environment variables',
382
+ 'hardcoded_password': 'Never hardcode passwords. Use secure credential management',
383
+ 'hardcoded_token': 'Store tokens in environment variables or secure storage',
384
+ 'hardcoded_secret': 'Use environment variables for secrets',
385
+ 'private_key': 'Never commit private keys. Use secure key management',
386
+ 'dangerous_eval': 'Avoid eval(). Use safer alternatives',
387
+ 'dangerous_exec': 'Avoid exec(). Use safer alternatives',
388
+ 'xss_risk': 'Sanitize HTML content to prevent XSS',
389
+ 'security_todo': 'Address security TODOs before committing'
390
+ };
391
+ return suggestions[type] || 'Review and fix security issue';
392
+ }
393
+ getQualitySuggestion(type) {
394
+ const suggestions = {
395
+ 'console_log': 'Remove console.log statements',
396
+ 'debugger_statement': 'Remove debugger statements',
397
+ 'todo_comment': 'Address or document TODOs',
398
+ 'commented_code': 'Remove commented-out code',
399
+ 'mixed_indentation': 'Use consistent indentation (spaces or tabs)',
400
+ 'trailing_whitespace': 'Remove trailing whitespace'
401
+ };
402
+ return suggestions[type] || 'Improve code quality';
403
+ }
404
+ calculateComplexity(code) {
405
+ // Simple cyclomatic complexity calculation
406
+ let complexity = 1;
407
+ const patterns = [
408
+ /if\s*\(/g,
409
+ /else\s+if\s*\(/g,
410
+ /for\s*\(/g,
411
+ /while\s*\(/g,
412
+ /case\s+/g,
413
+ /catch\s*\(/g,
414
+ /\?\s*.*\s*:/g // ternary
415
+ ];
416
+ for (const pattern of patterns) {
417
+ const matches = code.match(pattern);
418
+ if (matches) {
419
+ complexity += matches.length;
420
+ }
421
+ }
422
+ return complexity;
423
+ }
424
+ }