0xray 2.1.2 → 2.1.3
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/.opencode/codex.codex +1 -1
- package/.opencode/commands/dependency-audit.md +3 -3
- package/.opencode/enforcer-config.json +2 -2
- package/AGENTS.md +2 -1
- package/README.md +12 -11
- package/dist/AGENTS.md +2 -1
- package/dist/CHANGELOG.md +26 -0
- package/dist/README.md +12 -11
- package/dist/agents/code-reviewer.js +1 -1
- package/dist/analytics/routing-refiner.js +1 -1
- package/dist/cli/index.js +11 -1
- package/dist/cli/server.js +3 -3
- package/dist/core/activity-logger.d.ts +2 -2
- package/dist/core/activity-logger.js +4 -4
- package/dist/core/boot-orchestrator.d.ts +1 -1
- package/dist/core/boot-orchestrator.js +13 -28
- package/dist/core/bridge.mjs +3 -3
- package/dist/core/codex-formatter.js +2 -2
- package/dist/core/codex-injector.d.ts +0 -1
- package/dist/core/codex-injector.js +2 -3
- package/dist/core/config-loader.d.ts +1 -1
- package/dist/core/config-loader.js +1 -1
- package/dist/core/config-paths.d.ts +0 -2
- package/dist/core/config-paths.js +7 -8
- package/dist/core/context-loader.d.ts +1 -1
- package/dist/core/context-loader.js +1 -1
- package/dist/core/errors.d.ts +3 -0
- package/dist/core/errors.js +10 -0
- package/dist/core/features-config.js +1 -1
- package/dist/core/framework-logger.d.ts +3 -3
- package/dist/core/framework-logger.js +17 -9
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +4 -2
- package/dist/core/logging-config.d.ts +2 -1
- package/dist/core/logging-config.js +7 -7
- package/dist/enforcement/loaders/codex-loader.js +1 -1
- package/dist/execution/opencode-cli-invoker.js +5 -5
- package/dist/governance/governance-service.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/inference/inference-cycle.d.ts +1 -1
- package/dist/inference/inference-cycle.js +10 -10
- package/dist/integrations/base/Integration.js +1 -1
- package/dist/integrations/base/registry.js +19 -19
- package/dist/integrations/grok/grok-cli.js +17 -17
- package/dist/integrations/grok/hooks/pre-tool-use.js +1 -1
- package/dist/integrations/hermes-agent/bridge.mjs +1 -1
- package/dist/integrations/openclaw/api-server.d.ts +0 -1
- package/dist/integrations/openclaw/api-server.js +7 -10
- package/dist/integrations/openclaw/client.d.ts +0 -1
- package/dist/integrations/openclaw/client.js +22 -24
- package/dist/integrations/openclaw/hooks/xray-hooks.d.ts +0 -1
- package/dist/integrations/openclaw/hooks/xray-hooks.js +17 -18
- package/dist/integrations/plugins/plugin-registry.js +5 -5
- package/dist/mcps/architect-tools.server.d.ts +2 -4
- package/dist/mcps/architect-tools.server.js +112 -195
- package/dist/mcps/auto-format.server.d.ts +2 -4
- package/dist/mcps/auto-format.server.js +49 -95
- package/dist/mcps/boot-orchestrator.server.d.ts +2 -4
- package/dist/mcps/boot-orchestrator.server.js +73 -105
- package/dist/mcps/config/server-config-registry.js +3 -3
- package/dist/mcps/enforcer-tools.server.d.ts +2 -4
- package/dist/mcps/enforcer-tools.server.js +202 -285
- package/dist/mcps/estimation.server.d.ts +2 -4
- package/dist/mcps/estimation.server.js +63 -107
- package/dist/mcps/framework-compliance-audit.server.d.ts +2 -4
- package/dist/mcps/framework-compliance-audit.server.js +53 -82
- package/dist/mcps/framework-help.server.d.ts +2 -4
- package/dist/mcps/framework-help.server.js +63 -101
- package/dist/mcps/governance.server.js +2 -2
- package/dist/mcps/knowledge-skills/api-design.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/api-design.server.js +35 -67
- package/dist/mcps/knowledge-skills/architecture-patterns.server.d.ts +2 -10
- package/dist/mcps/knowledge-skills/architecture-patterns.server.js +35 -74
- package/dist/mcps/knowledge-skills/bug-triage-specialist.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/bug-triage-specialist.server.js +143 -162
- package/dist/mcps/knowledge-skills/code-analyzer.server.d.ts +3 -4
- package/dist/mcps/knowledge-skills/code-analyzer.server.js +20 -45
- package/dist/mcps/knowledge-skills/code-review.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/code-review.server.js +109 -143
- package/dist/mcps/knowledge-skills/content-creator.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/content-creator.server.js +205 -226
- package/dist/mcps/knowledge-skills/database-design.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/database-design.server.js +117 -151
- package/dist/mcps/knowledge-skills/devops-deployment.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/devops-deployment.server.js +71 -160
- package/dist/mcps/knowledge-skills/git-workflow.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/git-workflow.server.js +36 -68
- package/dist/mcps/knowledge-skills/growth-strategist.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/growth-strategist.server.js +303 -324
- package/dist/mcps/knowledge-skills/log-monitor.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/log-monitor.server.js +141 -160
- package/dist/mcps/knowledge-skills/mobile-development.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/mobile-development.server.js +92 -209
- package/dist/mcps/knowledge-skills/multimodal-looker.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/multimodal-looker.server.js +123 -159
- package/dist/mcps/knowledge-skills/performance-optimization.server.d.ts +2 -5
- package/dist/mcps/knowledge-skills/performance-optimization.server.js +155 -296
- package/dist/mcps/knowledge-skills/project-analysis.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/project-analysis.server.js +75 -226
- package/dist/mcps/knowledge-skills/refactoring-strategies.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/refactoring-strategies.server.js +63 -156
- package/dist/mcps/knowledge-skills/security-audit.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/security-audit.server.js +102 -136
- package/dist/mcps/knowledge-skills/seo-consultant.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/seo-consultant.server.js +80 -203
- package/dist/mcps/knowledge-skills/session-management.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/session-management.server.js +50 -203
- package/dist/mcps/knowledge-skills/skill-invocation.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/skill-invocation.server.js +168 -347
- package/dist/mcps/knowledge-skills/strategist.server.d.ts +2 -11
- package/dist/mcps/knowledge-skills/strategist.server.js +72 -122
- package/dist/mcps/knowledge-skills/tech-writer.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/tech-writer.server.js +87 -300
- package/dist/mcps/knowledge-skills/testing-best-practices.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/testing-best-practices.server.js +147 -182
- package/dist/mcps/knowledge-skills/testing-strategy.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/testing-strategy.server.js +78 -153
- package/dist/mcps/knowledge-skills/ui-ux-design.server.d.ts +2 -5
- package/dist/mcps/knowledge-skills/ui-ux-design.server.js +90 -399
- package/dist/mcps/lint.server.d.ts +2 -4
- package/dist/mcps/lint.server.js +51 -92
- package/dist/mcps/mcp-client.js +2 -2
- package/dist/mcps/model-health-check.server.d.ts +2 -4
- package/dist/mcps/model-health-check.server.js +32 -60
- package/dist/mcps/performance-analysis.server.d.ts +2 -4
- package/dist/mcps/performance-analysis.server.js +57 -88
- package/dist/mcps/processor-pipeline.server.d.ts +2 -4
- package/dist/mcps/processor-pipeline.server.js +69 -100
- package/dist/mcps/registry.json +1 -1
- package/dist/mcps/researcher.server.d.ts +3 -5
- package/dist/mcps/researcher.server.js +81 -154
- package/dist/mcps/security-scan.server.d.ts +2 -4
- package/dist/mcps/security-scan.server.js +54 -96
- package/dist/mcps/shared/knowledge-skill-base.d.ts +14 -0
- package/dist/mcps/shared/knowledge-skill-base.js +45 -0
- package/dist/{security → mcps/shared}/security-scanner.js +1 -1
- package/dist/mcps/state-manager.server.d.ts +2 -4
- package/dist/mcps/state-manager.server.js +115 -160
- package/dist/orchestrator/orchestrator.d.ts +1 -1
- package/dist/orchestrator/orchestrator.js +1 -1
- package/dist/orchestrator/universal-registry-bridge.js +1 -1
- package/dist/plugin/xray-codex-injection.d.ts +1 -1
- package/dist/plugin/xray-codex-injection.js +1 -1
- package/dist/postprocessor/PostProcessor.d.ts +4 -44
- package/dist/postprocessor/PostProcessor.js +39 -553
- package/dist/postprocessor/analysis/CodeChangeAnalyzer.d.ts +11 -0
- package/dist/postprocessor/analysis/CodeChangeAnalyzer.js +50 -0
- package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.d.ts +11 -0
- package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.js +356 -0
- package/dist/postprocessor/config/ProcessorConfigLoader.d.ts +44 -0
- package/dist/postprocessor/config/ProcessorConfigLoader.js +21 -0
- package/dist/postprocessor/reporting/PostProcessorReporter.d.ts +19 -0
- package/dist/postprocessor/reporting/PostProcessorReporter.js +96 -0
- package/dist/postprocessor/triggers/GitHookTrigger.js +11 -11
- package/dist/processors/implementations/refactoring-logging-processor-wrapper.d.ts +32 -0
- package/dist/processors/implementations/refactoring-logging-processor-wrapper.js +95 -1
- package/dist/processors/processor-manager.js +346 -314
- package/dist/reporting/report-formatter.js +1 -1
- package/dist/security/security-hardener.d.ts +69 -2
- package/dist/security/security-hardener.js +129 -1
- package/dist/skills/registry.json +1 -1
- package/dist/state/index.d.ts +3 -5
- package/dist/state/index.js +1 -7
- package/dist/state/state-manager.d.ts +1 -1
- package/dist/state/state-manager.js +2 -3
- package/package.json +13 -10
- package/scripts/node/universal-version-manager.js +11 -11
- package/src/mcps/architect-tools.server.ts +112 -215
- package/src/mcps/auto-format.server.ts +50 -110
- package/src/mcps/boot-orchestrator.server.ts +75 -121
- package/src/mcps/config/__tests__/server-config-registry.test.ts +21 -12
- package/src/mcps/config/server-config-registry.ts +3 -3
- package/src/mcps/enforcer-tools.server.ts +212 -310
- package/src/mcps/estimation.server.ts +62 -122
- package/src/mcps/framework-compliance-audit.server.ts +52 -97
- package/src/mcps/framework-help.server.ts +64 -114
- package/src/mcps/governance.server.ts +2 -2
- package/src/mcps/knowledge-skills/api-design.server.ts +32 -77
- package/src/mcps/knowledge-skills/architecture-patterns.server.ts +31 -87
- package/src/mcps/knowledge-skills/bug-triage-specialist.server.ts +165 -193
- package/src/mcps/knowledge-skills/code-analyzer.server.ts +20 -55
- package/src/mcps/knowledge-skills/code-review.server.ts +114 -161
- package/src/mcps/knowledge-skills/content-creator.server.ts +218 -255
- package/src/mcps/knowledge-skills/database-design.server.ts +118 -165
- package/src/mcps/knowledge-skills/devops-deployment.server.ts +67 -172
- package/src/mcps/knowledge-skills/git-workflow.server.ts +32 -77
- package/src/mcps/knowledge-skills/growth-strategist.server.ts +324 -361
- package/src/mcps/knowledge-skills/log-monitor.server.ts +160 -187
- package/src/mcps/knowledge-skills/mobile-development.server.ts +89 -223
- package/src/mcps/knowledge-skills/multimodal-looker.server.ts +128 -175
- package/src/mcps/knowledge-skills/performance-optimization.server.ts +156 -329
- package/src/mcps/knowledge-skills/project-analysis.server.ts +72 -248
- package/src/mcps/knowledge-skills/refactoring-strategies.server.ts +59 -171
- package/src/mcps/knowledge-skills/security-audit.server.ts +104 -151
- package/src/mcps/knowledge-skills/seo-consultant.server.ts +80 -220
- package/src/mcps/knowledge-skills/session-management.server.ts +51 -232
- package/src/mcps/knowledge-skills/skill-invocation.server.ts +165 -372
- package/src/mcps/knowledge-skills/strategist.server.ts +72 -143
- package/src/mcps/knowledge-skills/tech-writer.server.ts +85 -350
- package/src/mcps/knowledge-skills/testing-best-practices.server.ts +146 -195
- package/src/mcps/knowledge-skills/testing-strategy.server.ts +75 -161
- package/src/mcps/knowledge-skills/ui-ux-design.server.ts +93 -487
- package/src/mcps/lint.server.ts +53 -107
- package/src/mcps/mcp-client.ts +2 -2
- package/src/mcps/model-health-check.server.ts +34 -71
- package/src/mcps/performance-analysis.server.ts +60 -104
- package/src/mcps/processor-pipeline.server.ts +72 -110
- package/src/mcps/registry.json +1 -1
- package/src/mcps/researcher.server.ts +88 -177
- package/src/mcps/security-scan.server.ts +55 -104
- package/src/mcps/shared/knowledge-skill-base.ts +62 -0
- package/src/mcps/shared/prompt-security-validator.ts +199 -0
- package/src/mcps/shared/security-scanner.ts +599 -0
- package/src/mcps/state-manager.server.ts +117 -175
- package/src/opencode/codex.codex +1 -1
- package/src/opencode/commands/dependency-audit.md +3 -3
- package/src/opencode/enforcer-config.json +2 -2
- package/src/skills/registry.json +1 -1
- package/xray/codex.json +1 -1
- package/xray/config.json +1 -1
- package/xray/features.json +1 -1
- package/xray/integrations.json +3 -3
- package/dist/integrations/hermes-agent/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/conftest.cpython-313-pytest-9.0.2.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/schemas.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313-pytest-9.0.2.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/tools.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/conftest.py +0 -14
- package/dist/integrations/hermes-agent/test_plugin.py +0 -1103
- package/dist/processors/implementations/refactoring-logging-processor.d.ts +0 -31
- package/dist/processors/implementations/refactoring-logging-processor.js +0 -96
- package/dist/processors/implementations/session-capture-processor.d.ts +0 -14
- package/dist/processors/implementations/session-capture-processor.js +0 -37
- package/dist/scripts/activate-kernel-pipeline.d.ts +0 -7
- package/dist/scripts/activate-kernel-pipeline.js +0 -101
- package/dist/security/index.d.ts +0 -13
- package/dist/security/index.js +0 -13
- package/dist/security/security-agent-coordinator.d.ts +0 -72
- package/dist/security/security-agent-coordinator.js +0 -204
- package/dist/security/security-auditor.d.ts +0 -56
- package/dist/security/security-auditor.js +0 -584
- package/dist/security/security-hardening-system.d.ts +0 -239
- package/dist/security/security-hardening-system.js +0 -727
- package/dist/security/security-orchestration-layer.d.ts +0 -119
- package/dist/security/security-orchestration-layer.js +0 -496
- /package/dist/{security → mcps/shared}/prompt-security-validator.d.ts +0 -0
- /package/dist/{security → mcps/shared}/prompt-security-validator.js +0 -0
- /package/dist/{security → mcps/shared}/security-scanner.d.ts +0 -0
|
@@ -5,14 +5,8 @@
|
|
|
5
5
|
* profiling, benchmarking, memory analysis, and Core Web Vitals measurement
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
|
-
import {
|
|
11
|
-
CallToolRequestSchema,
|
|
12
|
-
ListToolsRequestSchema,
|
|
13
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import { XrayKnowledgeSkillBase } from "../shared/knowledge-skill-base.js";
|
|
14
9
|
import { frameworkLogger, generateJobId } from "../../core/framework-logger.js";
|
|
15
|
-
import { createGracefulShutdown } from "../../utils/shutdown-handler.js";
|
|
16
10
|
import fs from "fs";
|
|
17
11
|
import path from "path";
|
|
18
12
|
import os from "os";
|
|
@@ -217,144 +211,101 @@ interface McpToolResponse {
|
|
|
217
211
|
data?: Record<string, unknown>;
|
|
218
212
|
}
|
|
219
213
|
|
|
220
|
-
class XrayPerformanceOptimizationServer {
|
|
221
|
-
private server: Server;
|
|
222
|
-
private startTime: number;
|
|
223
|
-
|
|
214
|
+
class XrayPerformanceOptimizationServer extends XrayKnowledgeSkillBase {
|
|
224
215
|
constructor() {
|
|
225
|
-
|
|
216
|
+
super("performance-optimization", "2.0.1");
|
|
217
|
+
this.tools = [
|
|
226
218
|
{
|
|
227
|
-
name: "
|
|
219
|
+
name: "profile-application",
|
|
220
|
+
description: "Run comprehensive performance profiling on the codebase to identify bottlenecks and hot paths",
|
|
221
|
+
inputSchema: {
|
|
222
|
+
type: "object",
|
|
223
|
+
properties: {
|
|
224
|
+
projectRoot: { type: "string", description: "Path to the project root directory" },
|
|
225
|
+
scope: {
|
|
226
|
+
type: "string",
|
|
227
|
+
enum: ["full", "runtime", "build", "memory"],
|
|
228
|
+
default: "full",
|
|
229
|
+
description: "Scope of profiling analysis"
|
|
230
|
+
},
|
|
231
|
+
duration: { type: "number", default: 30, description: "Profiling duration in seconds" },
|
|
232
|
+
includeHotPaths: { type: "boolean", default: true, description: "Include hot path analysis" }
|
|
233
|
+
},
|
|
234
|
+
required: ["projectRoot"]
|
|
235
|
+
}
|
|
228
236
|
},
|
|
229
237
|
{
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
private setupToolHandlers() {
|
|
241
|
-
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
242
|
-
return {
|
|
243
|
-
tools: [
|
|
244
|
-
{
|
|
245
|
-
name: "profile-application",
|
|
246
|
-
description: "Run comprehensive performance profiling on the codebase to identify bottlenecks and hot paths",
|
|
247
|
-
inputSchema: {
|
|
248
|
-
type: "object",
|
|
249
|
-
properties: {
|
|
250
|
-
projectRoot: { type: "string", description: "Path to the project root directory" },
|
|
251
|
-
scope: {
|
|
252
|
-
type: "string",
|
|
253
|
-
enum: ["full", "runtime", "build", "memory"],
|
|
254
|
-
default: "full",
|
|
255
|
-
description: "Scope of profiling analysis"
|
|
256
|
-
},
|
|
257
|
-
duration: { type: "number", default: 30, description: "Profiling duration in seconds" },
|
|
258
|
-
includeHotPaths: { type: "boolean", default: true, description: "Include hot path analysis" }
|
|
259
|
-
},
|
|
260
|
-
required: ["projectRoot"]
|
|
261
|
-
}
|
|
238
|
+
name: "analyze-memory",
|
|
239
|
+
description: "Perform memory leak detection and heap analysis to identify memory issues",
|
|
240
|
+
inputSchema: {
|
|
241
|
+
type: "object",
|
|
242
|
+
properties: {
|
|
243
|
+
projectRoot: { type: "string", description: "Path to the project root directory" },
|
|
244
|
+
heapSnapshot: { type: "boolean", default: true, description: "Generate heap snapshot analysis" },
|
|
245
|
+
gcAnalysis: { type: "boolean", default: true, description: "Analyze garbage collection patterns" },
|
|
246
|
+
leakDetection: { type: "boolean", default: true, description: "Detect potential memory leaks" }
|
|
262
247
|
},
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
248
|
+
required: ["projectRoot"]
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "benchmark-code",
|
|
253
|
+
description: "Execute and compare benchmark results for code performance measurement",
|
|
254
|
+
inputSchema: {
|
|
255
|
+
type: "object",
|
|
256
|
+
properties: {
|
|
257
|
+
projectRoot: { type: "string", description: "Path to the project root directory" },
|
|
258
|
+
testFile: { type: "string", description: "Specific benchmark test file to run" },
|
|
259
|
+
iterations: { type: "number", default: 100, description: "Number of benchmark iterations" },
|
|
260
|
+
warmupRuns: { type: "number", default: 10, description: "Number of warmup runs" },
|
|
261
|
+
compareBaseline: { type: "boolean", default: false, description: "Compare results against baseline" }
|
|
276
262
|
},
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
263
|
+
required: ["projectRoot"]
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: "suggest-optimizations",
|
|
268
|
+
description: "Generate specific, actionable optimization suggestions based on code analysis",
|
|
269
|
+
inputSchema: {
|
|
270
|
+
type: "object",
|
|
271
|
+
properties: {
|
|
272
|
+
projectRoot: { type: "string", description: "Path to the project root directory" },
|
|
273
|
+
focus: {
|
|
274
|
+
type: "string",
|
|
275
|
+
enum: ["cpu", "memory", "network", "io", "all"],
|
|
276
|
+
default: "all",
|
|
277
|
+
description: "Focus area for optimizations"
|
|
278
|
+
},
|
|
279
|
+
threshold: { type: "number", default: 100, description: "Performance threshold in ms" }
|
|
291
280
|
},
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
required: ["projectRoot"]
|
|
308
|
-
}
|
|
281
|
+
required: ["projectRoot"]
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "measure-core-web-vitals",
|
|
286
|
+
description: "Analyze Core Web Vitals metrics (LCP, INP, CLS) for web application performance",
|
|
287
|
+
inputSchema: {
|
|
288
|
+
type: "object",
|
|
289
|
+
properties: {
|
|
290
|
+
projectRoot: { type: "string", description: "Path to the project root directory" },
|
|
291
|
+
analyzeBundle: { type: "boolean", default: true, description: "Analyze JavaScript bundle" },
|
|
292
|
+
checkAccessibility: { type: "boolean", default: true, description: "Check accessibility factors affecting CLS" },
|
|
293
|
+
measureLCP: { type: "boolean", default: true, description: "Measure Largest Contentful Paint" },
|
|
294
|
+
measureINP: { type: "boolean", default: true, description: "Measure Interaction to Next Paint" },
|
|
295
|
+
measureCLS: { type: "boolean", default: true, description: "Measure Cumulative Layout Shift" }
|
|
309
296
|
},
|
|
310
|
-
|
|
311
|
-
name: "measure-core-web-vitals",
|
|
312
|
-
description: "Analyze Core Web Vitals metrics (LCP, INP, CLS) for web application performance",
|
|
313
|
-
inputSchema: {
|
|
314
|
-
type: "object",
|
|
315
|
-
properties: {
|
|
316
|
-
projectRoot: { type: "string", description: "Path to the project root directory" },
|
|
317
|
-
analyzeBundle: { type: "boolean", default: true, description: "Analyze JavaScript bundle" },
|
|
318
|
-
checkAccessibility: { type: "boolean", default: true, description: "Check accessibility factors affecting CLS" },
|
|
319
|
-
measureLCP: { type: "boolean", default: true, description: "Measure Largest Contentful Paint" },
|
|
320
|
-
measureINP: { type: "boolean", default: true, description: "Measure Interaction to Next Paint" },
|
|
321
|
-
measureCLS: { type: "boolean", default: true, description: "Measure Cumulative Layout Shift" }
|
|
322
|
-
},
|
|
323
|
-
required: ["projectRoot"]
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
]
|
|
327
|
-
};
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
331
|
-
const { name, arguments: args } = request.params;
|
|
332
|
-
|
|
333
|
-
try {
|
|
334
|
-
switch (name) {
|
|
335
|
-
case "profile-application":
|
|
336
|
-
return await this.handleProfileApplication(args as unknown as ProfileApplicationArgs) as never;
|
|
337
|
-
case "analyze-memory":
|
|
338
|
-
return await this.handleAnalyzeMemory(args as unknown as AnalyzeMemoryArgs) as never;
|
|
339
|
-
case "benchmark-code":
|
|
340
|
-
return await this.handleBenchmarkCode(args as unknown as BenchmarkCodeArgs) as never;
|
|
341
|
-
case "suggest-optimizations":
|
|
342
|
-
return await this.handleSuggestOptimizations(args as unknown as SuggestOptimizationsArgs) as never;
|
|
343
|
-
case "measure-core-web-vitals":
|
|
344
|
-
return await this.handleMeasureCoreWebVitals(args as unknown as MeasureCoreWebVitalsArgs) as never;
|
|
345
|
-
default:
|
|
346
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
297
|
+
required: ["projectRoot"]
|
|
347
298
|
}
|
|
348
|
-
} catch (error) {
|
|
349
|
-
frameworkLogger.log("mcp/performance-optimization", "tool-handler", "error", { tool: name, error: String(error) });
|
|
350
|
-
return {
|
|
351
|
-
content: [{
|
|
352
|
-
type: "text",
|
|
353
|
-
text: `Error executing tool "${name}": ${error instanceof Error ? error.message : String(error)}`
|
|
354
|
-
}]
|
|
355
|
-
};
|
|
356
299
|
}
|
|
357
|
-
|
|
300
|
+
];
|
|
301
|
+
this.handlers = {
|
|
302
|
+
"profile-application": async (args) => this.handleProfileApplication(args as unknown as ProfileApplicationArgs),
|
|
303
|
+
"analyze-memory": async (args) => this.handleAnalyzeMemory(args as unknown as AnalyzeMemoryArgs),
|
|
304
|
+
"benchmark-code": async (args) => this.handleBenchmarkCode(args as unknown as BenchmarkCodeArgs),
|
|
305
|
+
"suggest-optimizations": async (args) => this.handleSuggestOptimizations(args as unknown as SuggestOptimizationsArgs),
|
|
306
|
+
"measure-core-web-vitals": async (args) => this.handleMeasureCoreWebVitals(args as unknown as MeasureCoreWebVitalsArgs),
|
|
307
|
+
};
|
|
308
|
+
this.setupToolHandlers();
|
|
358
309
|
}
|
|
359
310
|
|
|
360
311
|
private async handleProfileApplication(args: ProfileApplicationArgs): Promise<McpToolResponse> {
|
|
@@ -616,32 +567,24 @@ class XrayPerformanceOptimizationServer {
|
|
|
616
567
|
}
|
|
617
568
|
|
|
618
569
|
private formatProfilingResult(result: ProfilingResult): string {
|
|
619
|
-
|
|
570
|
+
const { metrics, hotPaths, functionCallCounts, bottlenecks, recommendations } = result;
|
|
571
|
+
return `📊 Performance Profiling
|
|
620
572
|
|
|
621
|
-
**
|
|
622
|
-
- Total Functions Analyzed: ${result.metrics.totalFunctions}
|
|
623
|
-
- Hot Functions (>1000 calls): ${result.metrics.hotFunctions}
|
|
624
|
-
- Average Execution Time: ${result.metrics.avgExecutionTime}ms
|
|
625
|
-
- Peak Memory: ${result.metrics.peakMemory}MB
|
|
626
|
-
- GC Pauses: ${result.metrics.gcPauses}
|
|
573
|
+
**METRICS** Functions:${metrics.totalFunctions} Hot:${metrics.hotFunctions} Avg:${metrics.avgExecutionTime}ms Mem:${metrics.peakMemory}MB GC:${metrics.gcPauses}
|
|
627
574
|
|
|
628
|
-
**HOT PATHS** (${
|
|
629
|
-
${
|
|
575
|
+
**HOT PATHS** (${hotPaths.length})
|
|
576
|
+
${hotPaths.slice(0, 10).map(p => ` 🔥 ${p}`).join("\n") || " None"}
|
|
630
577
|
|
|
631
|
-
**TOP FUNCTIONS
|
|
632
|
-
${Object.entries(
|
|
633
|
-
.sort(([, a], [, b]) => b - a)
|
|
634
|
-
.slice(0, 5)
|
|
635
|
-
.map(([name, count]) => `• ${name}: ${count.toLocaleString()} calls`)
|
|
636
|
-
.join("\n") || "None"}
|
|
578
|
+
**TOP FUNCTIONS**
|
|
579
|
+
${Object.entries(functionCallCounts).sort(([, a], [, b]) => b - a).slice(0, 5).map(([n, c]) => ` ${n}: ${c.toLocaleString()} calls`).join("\n") || " None"}
|
|
637
580
|
|
|
638
|
-
**BOTTLENECKS** (${
|
|
639
|
-
${
|
|
581
|
+
**BOTTLENECKS** (${bottlenecks.length})
|
|
582
|
+
${bottlenecks.slice(0, 5).map(b => ` 🚧 ${b}`).join("\n") || " None"}
|
|
640
583
|
|
|
641
584
|
**RECOMMENDATIONS**
|
|
642
|
-
${
|
|
585
|
+
${recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n") || " None"}
|
|
643
586
|
|
|
644
|
-
**Status
|
|
587
|
+
**Status** ${metrics.hotFunctions > 10 ? "❌ HIGH OPTIMIZATION NEEDED" : metrics.hotFunctions > 5 ? "⚠️ MODERATE OPTIMIZATION NEEDED" : "✅ ACCEPTABLE"}`;
|
|
645
588
|
}
|
|
646
589
|
|
|
647
590
|
private async handleAnalyzeMemory(args: AnalyzeMemoryArgs): Promise<McpToolResponse> {
|
|
@@ -800,18 +743,16 @@ ${result.recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n")
|
|
|
800
743
|
}
|
|
801
744
|
|
|
802
745
|
private analyzeGCActivity(heapUsedMB: number): GCEvent[] {
|
|
746
|
+
const count = Math.min(Math.floor(heapUsedMB / 100), 5);
|
|
803
747
|
const events: GCEvent[] = [];
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
for (let i = 0; i < Math.min(eventCount, 10); i++) {
|
|
748
|
+
for (let i = 0; i < count; i++) {
|
|
807
749
|
events.push({
|
|
808
|
-
type: heapUsedMB > 200
|
|
809
|
-
duration:
|
|
810
|
-
timestamp: Date.now() - (
|
|
811
|
-
reclaimedBytes:
|
|
750
|
+
type: heapUsedMB > 200 && i % 3 === 0 ? "major" : "minor",
|
|
751
|
+
duration: 3 + i * 2,
|
|
752
|
+
timestamp: Date.now() - (count - i) * 60000,
|
|
753
|
+
reclaimedBytes: 512 * 1024
|
|
812
754
|
});
|
|
813
755
|
}
|
|
814
|
-
|
|
815
756
|
return events;
|
|
816
757
|
}
|
|
817
758
|
|
|
@@ -986,43 +927,25 @@ ${result.recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n")
|
|
|
986
927
|
}
|
|
987
928
|
|
|
988
929
|
private formatMemoryAnalysis(result: MemoryAnalysisResult): string {
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
- Closures: ${(result.heapBreakdown.closures / 1024).toFixed(1)}KB
|
|
1004
|
-
|
|
1005
|
-
**MEMORY LEAKS** (${result.memoryLeaks.length} detected)
|
|
1006
|
-
${result.memoryLeaks.slice(0, 5).map(leak =>
|
|
1007
|
-
`• ${leak.severity === "critical" || leak.severity === "high" ? "🔴" : "🟡"} ${leak.location}\n Cause: ${leak.suspectedCause}\n Fix: ${leak.fixSuggestion}`
|
|
1008
|
-
).join("\n\n") || "None detected"}
|
|
1009
|
-
|
|
1010
|
-
**GC ACTIVITY** (${result.gcEvents.length} events)
|
|
1011
|
-
- Minor GC: ${result.gcEvents.filter(e => e.type === "minor").length}
|
|
1012
|
-
- Major GC: ${result.gcEvents.filter(e => e.type === "major").length}
|
|
1013
|
-
- Full GC: ${result.gcEvents.filter(e => e.type === "full").length}
|
|
1014
|
-
|
|
1015
|
-
**ALLOCATIONS BY TYPE**
|
|
1016
|
-
${Object.entries(result.allocationsByType)
|
|
1017
|
-
.sort(([, a], [, b]) => b - a)
|
|
1018
|
-
.slice(0, 5)
|
|
1019
|
-
.map(([type, count]) => `• ${type}: ${count.toLocaleString()}`)
|
|
1020
|
-
.join("\n")}
|
|
930
|
+
const { heapUsed, heapTotal, external, rss, memoryLeaks, gcEvents, heapBreakdown, allocationsByType, recommendations } = result;
|
|
931
|
+
return `🧠 Memory Analysis
|
|
932
|
+
|
|
933
|
+
**HEAP** Used:${heapUsed}MB Total:${heapTotal}MB Ext:${external}MB RSS:${rss}MB (${(heapUsed / heapTotal * 100).toFixed(1)}%)
|
|
934
|
+
|
|
935
|
+
**BREAKDOWN** Str:${(heapBreakdown.strings / 1024).toFixed(1)}KB Arr:${(heapBreakdown.arrays / 1024).toFixed(1)}KB Obj:${(heapBreakdown.objects / 1024).toFixed(1)}KB Fn:${(heapBreakdown.functions / 1024).toFixed(1)}KB Cls:${(heapBreakdown.closures / 1024).toFixed(1)}KB
|
|
936
|
+
|
|
937
|
+
**LEAKS** (${memoryLeaks.length})
|
|
938
|
+
${memoryLeaks.slice(0, 5).map(l => ` ${l.severity === "critical" || l.severity === "high" ? "🔴" : "🟡"} ${l.location}\n Cause: ${l.suspectedCause}\n Fix: ${l.fixSuggestion}`).join("\n") || " None"}
|
|
939
|
+
|
|
940
|
+
**GC** (${gcEvents.length}) Minor:${gcEvents.filter(e => e.type === "minor").length} Major:${gcEvents.filter(e => e.type === "major").length} Full:${gcEvents.filter(e => e.type === "full").length}
|
|
941
|
+
|
|
942
|
+
**ALLOCATIONS**
|
|
943
|
+
${Object.entries(allocationsByType).sort(([, a], [, b]) => b - a).slice(0, 5).map(([t, c]) => ` ${t}: ${c.toLocaleString()}`).join("\n")}
|
|
1021
944
|
|
|
1022
945
|
**RECOMMENDATIONS**
|
|
1023
|
-
${
|
|
946
|
+
${recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n") || " None"}
|
|
1024
947
|
|
|
1025
|
-
**Status
|
|
948
|
+
**Status** ${memoryLeaks.some(l => l.severity === "critical" || l.severity === "high") ? "❌ CRITICAL" : memoryLeaks.length > 3 ? "⚠️ OPTIMIZATION NEEDED" : "✅ HEALTHY"}`;
|
|
1026
949
|
}
|
|
1027
950
|
|
|
1028
951
|
private async handleBenchmarkCode(args: BenchmarkCodeArgs): Promise<McpToolResponse> {
|
|
@@ -1136,20 +1059,9 @@ ${result.recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n")
|
|
|
1136
1059
|
}
|
|
1137
1060
|
|
|
1138
1061
|
private simulateBenchmarkWorkload(filePath: string): void {
|
|
1139
|
-
|
|
1140
|
-
const iterations = Math.max(10, Math.floor(
|
|
1141
|
-
|
|
1142
|
-
let result = 0;
|
|
1143
|
-
for (let i = 0; i < iterations; i++) {
|
|
1144
|
-
result += Math.sqrt(i) * Math.log(i + 1);
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
const arr = new Array(100).fill(0).map((_, i) => i * 2);
|
|
1148
|
-
arr.sort((a, b) => b - a);
|
|
1149
|
-
|
|
1150
|
-
const obj = { a: 1, b: 2, c: 3, d: 4 };
|
|
1151
|
-
const serialized = JSON.stringify(obj);
|
|
1152
|
-
JSON.parse(serialized);
|
|
1062
|
+
// Stub: synthetic math workload for benchmarking
|
|
1063
|
+
const iterations = Math.max(10, Math.min(100, Math.floor((fs.existsSync(filePath) ? fs.statSync(filePath).size : 1000) / 100)));
|
|
1064
|
+
for (let i = 0; i < iterations; i++) Math.sqrt(i) * Math.log(i + 1);
|
|
1153
1065
|
}
|
|
1154
1066
|
|
|
1155
1067
|
private calculateVariance(values: number[]): number {
|
|
@@ -1180,44 +1092,20 @@ ${result.recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n")
|
|
|
1180
1092
|
}
|
|
1181
1093
|
|
|
1182
1094
|
private formatBenchmarkResult(result: BenchmarkResult): string {
|
|
1183
|
-
|
|
1095
|
+
const { benchmarks, comparison, statistics, recommendations } = result;
|
|
1096
|
+
let text = `⚡ Benchmark Results (${benchmarks.length} benchmarks)
|
|
1184
1097
|
|
|
1185
|
-
**
|
|
1186
|
-
- Total Benchmarks: ${result.statistics.totalBenchmarks}
|
|
1187
|
-
- Fastest: ${result.statistics.fastest}
|
|
1188
|
-
- Slowest: ${result.statistics.slowest}
|
|
1189
|
-
- Average Ops/Sec: ${result.statistics.averageOpsPerSecond.toLocaleString()}
|
|
1190
|
-
- Variance: ${result.statistics.variance.toFixed(2)}
|
|
1098
|
+
**STATS** Total:${statistics.totalBenchmarks} Fastest:${statistics.fastest} Slowest:${statistics.slowest} Avg:${statistics.averageOpsPerSecond.toLocaleString()} ops/s Var:${statistics.variance.toFixed(2)}
|
|
1191
1099
|
|
|
1192
|
-
**
|
|
1193
|
-
`;
|
|
1194
|
-
|
|
1195
|
-
for (const benchmark of result.benchmarks) {
|
|
1196
|
-
text += `
|
|
1197
|
-
📊 ${benchmark.name}
|
|
1198
|
-
- Ops/sec: ${benchmark.opsPerSecond.toLocaleString()}
|
|
1199
|
-
- Mean: ${benchmark.meanMs}ms | Median: ${benchmark.medianMs}ms
|
|
1200
|
-
- Min: ${benchmark.minMs}ms | Max: ${benchmark.maxMs}ms
|
|
1201
|
-
- P95: ${benchmark.p95Ms}ms | P99: ${benchmark.p99Ms}ms
|
|
1202
|
-
- Std Dev: ${benchmark.stdDevMs}ms
|
|
1100
|
+
**DETAILS**
|
|
1203
1101
|
`;
|
|
1102
|
+
for (const b of benchmarks) {
|
|
1103
|
+
text += ` ${b.name} — ${b.opsPerSecond.toLocaleString()} ops/s | Mean:${b.meanMs}ms Med:${b.medianMs}ms Min:${b.minMs}ms Max:${b.maxMs}ms P95:${b.p95Ms}ms P99:${b.p99Ms}ms SD:${b.stdDevMs}ms\n`;
|
|
1204
1104
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
const c = result.comparison;
|
|
1208
|
-
const direction = c.improvement > 0 ? "📈" : "📉";
|
|
1209
|
-
text += `
|
|
1210
|
-
**COMPARISON vs BASELINE**
|
|
1211
|
-
${direction} Change: ${c.improvement > 0 ? "+" : ""}${c.improvement.toFixed(1)}%
|
|
1212
|
-
${c.significant ? "⚠️" : "✓"} Statistically Significant: ${c.significant ? "Yes" : "No"}
|
|
1213
|
-
`;
|
|
1105
|
+
if (comparison) {
|
|
1106
|
+
text += `**vs BASELINE** ${comparison.improvement > 0 ? "📈" : "📉"} ${comparison.improvement > 0 ? "+" : ""}${comparison.improvement.toFixed(1)}% ${comparison.significant ? "⚠️ Significant" : "✓ Not significant"}\n`;
|
|
1214
1107
|
}
|
|
1215
|
-
|
|
1216
|
-
text += `
|
|
1217
|
-
**RECOMMENDATIONS**
|
|
1218
|
-
${result.recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n") || "No specific recommendations"}
|
|
1219
|
-
`;
|
|
1220
|
-
|
|
1108
|
+
text += `**RECOMMENDATIONS**\n${recommendations.slice(0, 5).map((r, i) => ` ${i + 1}. ${r}`).join("\n") || " None"}\n`;
|
|
1221
1109
|
return text;
|
|
1222
1110
|
}
|
|
1223
1111
|
|
|
@@ -1489,36 +1377,25 @@ return {
|
|
|
1489
1377
|
|
|
1490
1378
|
private formatOptimizationSuggestions(suggestions: OptimizationSuggestion[]): string {
|
|
1491
1379
|
const byCategory = suggestions.reduce((acc, s) => {
|
|
1492
|
-
|
|
1493
|
-
acc[s.category]!.push(s);
|
|
1380
|
+
(acc[s.category] ??= []).push(s);
|
|
1494
1381
|
return acc;
|
|
1495
1382
|
}, {} as Record<string, OptimizationSuggestion[]>);
|
|
1496
1383
|
|
|
1497
|
-
|
|
1384
|
+
const critical = suggestions.filter(s => s.impact === "critical").length;
|
|
1385
|
+
const high = suggestions.filter(s => s.impact === "high").length;
|
|
1386
|
+
const medium = suggestions.filter(s => s.impact === "medium").length;
|
|
1387
|
+
const low = suggestions.filter(s => s.impact === "low").length;
|
|
1388
|
+
let text = `💡 Optimization Suggestions (${suggestions.length})
|
|
1498
1389
|
|
|
1499
|
-
**
|
|
1500
|
-
- Critical: ${suggestions.filter(s => s.impact === "critical").length}
|
|
1501
|
-
- High: ${suggestions.filter(s => s.impact === "high").length}
|
|
1502
|
-
- Medium: ${suggestions.filter(s => s.impact === "medium").length}
|
|
1503
|
-
- Low: ${suggestions.filter(s => s.impact === "low").length}
|
|
1390
|
+
**IMPACT** Crit:${critical} High:${high} Med:${medium} Low:${low}
|
|
1504
1391
|
`;
|
|
1505
|
-
|
|
1506
1392
|
for (const [category, items] of Object.entries(byCategory)) {
|
|
1507
|
-
text += `\n## ${category.toUpperCase()}
|
|
1508
|
-
for (const
|
|
1509
|
-
const icon =
|
|
1510
|
-
|
|
1511
|
-
suggestion.impact === "medium" ? "🟡" : "🟢";
|
|
1512
|
-
text += `
|
|
1513
|
-
${icon} **${suggestion.title}** (${suggestion.impact} impact, ${suggestion.effort} effort)
|
|
1514
|
-
${suggestion.description}
|
|
1515
|
-
📁 Files: ${suggestion.files.join(", ")}
|
|
1516
|
-
💡 Fix: ${suggestion.suggestedFix}
|
|
1517
|
-
📈 Expected: ${suggestion.expectedImprovement}
|
|
1518
|
-
`;
|
|
1393
|
+
text += `\n## ${category.toUpperCase()} (${items.length})\n`;
|
|
1394
|
+
for (const s of items.slice(0, 5)) {
|
|
1395
|
+
const icon = s.impact === "critical" ? "🔴" : s.impact === "high" ? "🟠" : s.impact === "medium" ? "🟡" : "🟢";
|
|
1396
|
+
text += `${icon} ${s.title} (${s.impact}, ${s.effort})\n ${s.description} | Fix: ${s.suggestedFix}\n`;
|
|
1519
1397
|
}
|
|
1520
1398
|
}
|
|
1521
|
-
|
|
1522
1399
|
return text;
|
|
1523
1400
|
}
|
|
1524
1401
|
|
|
@@ -1934,65 +1811,28 @@ ${icon} **${suggestion.title}** (${suggestion.impact} impact, ${suggestion.effor
|
|
|
1934
1811
|
}
|
|
1935
1812
|
|
|
1936
1813
|
private formatCoreWebVitalsResult(result: CoreWebVitalsResult): string {
|
|
1937
|
-
const statusIcon = result.status === "good" ? "✅" :
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
let text = `${statusIcon} Core Web Vitals Analysis
|
|
1941
|
-
|
|
1942
|
-
**OVERALL SCORE:** ${result.score}/100 (${result.status.toUpperCase()})
|
|
1943
|
-
`;
|
|
1814
|
+
const statusIcon = result.status === "good" ? "✅" : result.status === "needs-improvement" ? "⚠️" : "❌";
|
|
1815
|
+
let text = `${statusIcon} Core Web Vitals — ${result.score}/100 (${result.status.toUpperCase()})\n`;
|
|
1944
1816
|
|
|
1945
1817
|
if (result.bundleAnalysis) {
|
|
1946
|
-
const
|
|
1947
|
-
text +=
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
- Gzipped Size: ${(bundle.gzippedSize / 1024 / 1024).toFixed(2)}MB
|
|
1951
|
-
- Largest Modules: ${bundle.largestModules.slice(0, 3).map(m => `${m.name} (${m.size}KB)`).join(", ") || "None"}
|
|
1952
|
-
`;
|
|
1818
|
+
const b = result.bundleAnalysis;
|
|
1819
|
+
text += `**BUNDLE** ${(b.totalSize / 1024 / 1024).toFixed(2)}MB (gz:${(b.gzippedSize / 1024 / 1024).toFixed(2)}MB)\n`;
|
|
1820
|
+
const top = b.largestModules.slice(0, 3).map(m => `${m.name} (${m.size}KB)`).join(", ");
|
|
1821
|
+
if (top) text += ` Largest: ${top}\n`;
|
|
1953
1822
|
}
|
|
1954
|
-
|
|
1955
1823
|
if (result.LCP) {
|
|
1956
|
-
const
|
|
1957
|
-
|
|
1958
|
-
text += `
|
|
1959
|
-
**LCP (Largest Contentful Paint)** ${lcpStatus}
|
|
1960
|
-
- Value: ${(lcp.value / 1000).toFixed(2)}s
|
|
1961
|
-
- Score: ${lcp.score}/100
|
|
1962
|
-
- Resource Load: ${(lcp.resourceLoadTime / 1000).toFixed(2)}s
|
|
1963
|
-
- Render Delay: ${(lcp.renderDelay / 1000).toFixed(2)}s
|
|
1964
|
-
`;
|
|
1824
|
+
const l = result.LCP;
|
|
1825
|
+
text += `**LCP** ${l.value <= 2500 ? "✅" : l.value <= 4000 ? "⚠️" : "❌"} ${(l.value / 1000).toFixed(2)}s (score:${l.score}/100 load:${(l.resourceLoadTime / 1000).toFixed(2)}s render:${(l.renderDelay / 1000).toFixed(2)}s)\n`;
|
|
1965
1826
|
}
|
|
1966
|
-
|
|
1967
1827
|
if (result.INP) {
|
|
1968
|
-
const
|
|
1969
|
-
|
|
1970
|
-
text += `
|
|
1971
|
-
**INP (Interaction to Next Paint)** ${inpStatus}
|
|
1972
|
-
- Value: ${inp.value}ms
|
|
1973
|
-
- Score: ${inp.score}/100
|
|
1974
|
-
- Processing Time: ${inp.processingTime}ms
|
|
1975
|
-
- Presentation Delay: ${inp.presentationDelay}ms
|
|
1976
|
-
`;
|
|
1828
|
+
const i = result.INP;
|
|
1829
|
+
text += `**INP** ${i.value <= 200 ? "✅" : i.value <= 500 ? "⚠️" : "❌"} ${i.value}ms (score:${i.score}/100 proc:${i.processingTime}ms delay:${i.presentationDelay}ms)\n`;
|
|
1977
1830
|
}
|
|
1978
|
-
|
|
1979
1831
|
if (result.CLS) {
|
|
1980
|
-
const
|
|
1981
|
-
|
|
1982
|
-
text += `
|
|
1983
|
-
**CLS (Cumulative Layout Shift)** ${clsStatus}
|
|
1984
|
-
- Value: ${cls.value}
|
|
1985
|
-
- Score: ${cls.score}/100
|
|
1986
|
-
- Layout Shifts: ${cls.layoutShifts}
|
|
1987
|
-
- Sources: ${cls.sources.slice(0, 3).join(", ") || "None"}
|
|
1988
|
-
`;
|
|
1832
|
+
const c = result.CLS;
|
|
1833
|
+
text += `**CLS** ${c.value <= 0.1 ? "✅" : c.value <= 0.25 ? "⚠️" : "❌"} ${c.value} (score:${c.score}/100 shifts:${c.layoutShifts} sources:${c.sources.slice(0, 3).join(", ") || "None"})\n`;
|
|
1989
1834
|
}
|
|
1990
|
-
|
|
1991
|
-
text += `
|
|
1992
|
-
**RECOMMENDATIONS**
|
|
1993
|
-
${result.recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n") || "No specific recommendations"}
|
|
1994
|
-
`;
|
|
1995
|
-
|
|
1835
|
+
text += `**RECOMMENDATIONS**\n${result.recommendations.slice(0, 5).map((r, i) => ` ${i + 1}. ${r}`).join("\n") || " None"}\n`;
|
|
1996
1836
|
return text;
|
|
1997
1837
|
}
|
|
1998
1838
|
|
|
@@ -2040,24 +1880,11 @@ ${result.recommendations.slice(0, 5).map((r, i) => `${i + 1}. ${r}`).join("\n")
|
|
|
2040
1880
|
return files.slice(0, 100);
|
|
2041
1881
|
}
|
|
2042
1882
|
|
|
2043
|
-
async run(): Promise<void> {
|
|
2044
|
-
const transport = new StdioServerTransport();
|
|
2045
|
-
await this.server.connect(transport);
|
|
2046
|
-
|
|
2047
|
-
createGracefulShutdown({
|
|
2048
|
-
serverName: "performance-optimization.server",
|
|
2049
|
-
server: this.server,
|
|
2050
|
-
});
|
|
2051
|
-
|
|
2052
|
-
frameworkLogger.log("mcp/performance-optimization", "server-started", "info", {
|
|
2053
|
-
uptime: Date.now() - this.startTime
|
|
2054
|
-
});
|
|
2055
|
-
}
|
|
2056
1883
|
}
|
|
2057
1884
|
|
|
2058
1885
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
2059
1886
|
const server = new XrayPerformanceOptimizationServer();
|
|
2060
|
-
server.run().catch((error) => {
|
|
1887
|
+
server.run("performance-optimization.server").catch((error) => {
|
|
2061
1888
|
frameworkLogger.log("mcp/performance-optimization", "run", "error", { error: String(error) });
|
|
2062
1889
|
});
|
|
2063
1890
|
}
|