perfgraph 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +280 -0
- package/dist/causal/builder.d.ts +34 -0
- package/dist/causal/builder.d.ts.map +1 -0
- package/dist/causal/builder.js +132 -0
- package/dist/causal/builder.js.map +1 -0
- package/dist/causal/index.d.ts +11 -0
- package/dist/causal/index.d.ts.map +1 -0
- package/dist/causal/index.js +10 -0
- package/dist/causal/index.js.map +1 -0
- package/dist/causal/rules/js.d.ts +49 -0
- package/dist/causal/rules/js.d.ts.map +1 -0
- package/dist/causal/rules/js.js +209 -0
- package/dist/causal/rules/js.js.map +1 -0
- package/dist/causal/rules/layout.d.ts +39 -0
- package/dist/causal/rules/layout.d.ts.map +1 -0
- package/dist/causal/rules/layout.js +169 -0
- package/dist/causal/rules/layout.js.map +1 -0
- package/dist/causal/rules/lcp.d.ts +49 -0
- package/dist/causal/rules/lcp.d.ts.map +1 -0
- package/dist/causal/rules/lcp.js +250 -0
- package/dist/causal/rules/lcp.js.map +1 -0
- package/dist/causal/rules/network.d.ts +39 -0
- package/dist/causal/rules/network.d.ts.map +1 -0
- package/dist/causal/rules/network.js +140 -0
- package/dist/causal/rules/network.js.map +1 -0
- package/dist/causal/types.d.ts +142 -0
- package/dist/causal/types.d.ts.map +1 -0
- package/dist/causal/types.js +88 -0
- package/dist/causal/types.js.map +1 -0
- package/dist/cli/analyze.d.ts +33 -0
- package/dist/cli/analyze.d.ts.map +1 -0
- package/dist/cli/analyze.js +137 -0
- package/dist/cli/analyze.js.map +1 -0
- package/dist/cli/collect.d.ts +28 -0
- package/dist/cli/collect.d.ts.map +1 -0
- package/dist/cli/collect.js +125 -0
- package/dist/cli/collect.js.map +1 -0
- package/dist/cli/extract.d.ts +31 -0
- package/dist/cli/extract.d.ts.map +1 -0
- package/dist/cli/extract.js +135 -0
- package/dist/cli/extract.js.map +1 -0
- package/dist/cli/mcp.d.ts +14 -0
- package/dist/cli/mcp.d.ts.map +1 -0
- package/dist/cli/mcp.js +53 -0
- package/dist/cli/mcp.js.map +1 -0
- package/dist/cli/normalize.d.ts +58 -0
- package/dist/cli/normalize.d.ts.map +1 -0
- package/dist/cli/normalize.js +179 -0
- package/dist/cli/normalize.js.map +1 -0
- package/dist/cli/report.d.ts +33 -0
- package/dist/cli/report.d.ts.map +1 -0
- package/dist/cli/report.js +137 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/run.d.ts +49 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +243 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/collect/buffer-monitor.d.ts +25 -0
- package/dist/collect/buffer-monitor.d.ts.map +1 -0
- package/dist/collect/buffer-monitor.js +69 -0
- package/dist/collect/buffer-monitor.js.map +1 -0
- package/dist/collect/console.d.ts +25 -0
- package/dist/collect/console.d.ts.map +1 -0
- package/dist/collect/console.js +82 -0
- package/dist/collect/console.js.map +1 -0
- package/dist/collect/coverage.d.ts +26 -0
- package/dist/collect/coverage.d.ts.map +1 -0
- package/dist/collect/coverage.js +99 -0
- package/dist/collect/coverage.js.map +1 -0
- package/dist/collect/dom.d.ts +37 -0
- package/dist/collect/dom.d.ts.map +1 -0
- package/dist/collect/dom.js +118 -0
- package/dist/collect/dom.js.map +1 -0
- package/dist/collect/lighthouse.d.ts +41 -0
- package/dist/collect/lighthouse.d.ts.map +1 -0
- package/dist/collect/lighthouse.js +111 -0
- package/dist/collect/lighthouse.js.map +1 -0
- package/dist/collect/network.d.ts +32 -0
- package/dist/collect/network.d.ts.map +1 -0
- package/dist/collect/network.js +236 -0
- package/dist/collect/network.js.map +1 -0
- package/dist/collect/orchestrator.d.ts +23 -0
- package/dist/collect/orchestrator.d.ts.map +1 -0
- package/dist/collect/orchestrator.js +350 -0
- package/dist/collect/orchestrator.js.map +1 -0
- package/dist/collect/performance.d.ts +28 -0
- package/dist/collect/performance.d.ts.map +1 -0
- package/dist/collect/performance.js +108 -0
- package/dist/collect/performance.js.map +1 -0
- package/dist/collect/runtime.d.ts +26 -0
- package/dist/collect/runtime.d.ts.map +1 -0
- package/dist/collect/runtime.js +81 -0
- package/dist/collect/runtime.js.map +1 -0
- package/dist/collect/session.d.ts +58 -0
- package/dist/collect/session.d.ts.map +1 -0
- package/dist/collect/session.js +162 -0
- package/dist/collect/session.js.map +1 -0
- package/dist/collect/trace.d.ts +40 -0
- package/dist/collect/trace.d.ts.map +1 -0
- package/dist/collect/trace.js +127 -0
- package/dist/collect/trace.js.map +1 -0
- package/dist/collect/types.d.ts +317 -0
- package/dist/collect/types.d.ts.map +1 -0
- package/dist/collect/types.js +12 -0
- package/dist/collect/types.js.map +1 -0
- package/dist/distill/insights.d.ts +67 -0
- package/dist/distill/insights.d.ts.map +1 -0
- package/dist/distill/insights.js +317 -0
- package/dist/distill/insights.js.map +1 -0
- package/dist/distill/summaries.d.ts +71 -0
- package/dist/distill/summaries.d.ts.map +1 -0
- package/dist/distill/summaries.js +165 -0
- package/dist/distill/summaries.js.map +1 -0
- package/dist/extract/critical-path.d.ts +17 -0
- package/dist/extract/critical-path.d.ts.map +1 -0
- package/dist/extract/critical-path.js +95 -0
- package/dist/extract/critical-path.js.map +1 -0
- package/dist/extract/index.d.ts +16 -0
- package/dist/extract/index.d.ts.map +1 -0
- package/dist/extract/index.js +32 -0
- package/dist/extract/index.js.map +1 -0
- package/dist/extract/js-hotspots.d.ts +15 -0
- package/dist/extract/js-hotspots.d.ts.map +1 -0
- package/dist/extract/js-hotspots.js +22 -0
- package/dist/extract/js-hotspots.js.map +1 -0
- package/dist/extract/layout-shifts.d.ts +19 -0
- package/dist/extract/layout-shifts.d.ts.map +1 -0
- package/dist/extract/layout-shifts.js +47 -0
- package/dist/extract/layout-shifts.js.map +1 -0
- package/dist/extract/lcp-breakdown.d.ts +19 -0
- package/dist/extract/lcp-breakdown.d.ts.map +1 -0
- package/dist/extract/lcp-breakdown.js +110 -0
- package/dist/extract/lcp-breakdown.js.map +1 -0
- package/dist/extract/main-thread.d.ts +16 -0
- package/dist/extract/main-thread.d.ts.map +1 -0
- package/dist/extract/main-thread.js +41 -0
- package/dist/extract/main-thread.js.map +1 -0
- package/dist/extract/render-blocking.d.ts +16 -0
- package/dist/extract/render-blocking.d.ts.map +1 -0
- package/dist/extract/render-blocking.js +79 -0
- package/dist/extract/render-blocking.js.map +1 -0
- package/dist/extract/third-party.d.ts +15 -0
- package/dist/extract/third-party.d.ts.map +1 -0
- package/dist/extract/third-party.js +127 -0
- package/dist/extract/third-party.js.map +1 -0
- package/dist/extract/types.d.ts +183 -0
- package/dist/extract/types.d.ts.map +1 -0
- package/dist/extract/types.js +118 -0
- package/dist/extract/types.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +188 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/handlers.d.ts +72 -0
- package/dist/mcp/handlers.d.ts.map +1 -0
- package/dist/mcp/handlers.js +285 -0
- package/dist/mcp/handlers.js.map +1 -0
- package/dist/mcp/progress.d.ts +37 -0
- package/dist/mcp/progress.d.ts.map +1 -0
- package/dist/mcp/progress.js +51 -0
- package/dist/mcp/progress.js.map +1 -0
- package/dist/mcp/prompts.d.ts +57 -0
- package/dist/mcp/prompts.d.ts.map +1 -0
- package/dist/mcp/prompts.js +225 -0
- package/dist/mcp/prompts.js.map +1 -0
- package/dist/mcp/resources.d.ts +48 -0
- package/dist/mcp/resources.d.ts.map +1 -0
- package/dist/mcp/resources.js +149 -0
- package/dist/mcp/resources.js.map +1 -0
- package/dist/mcp/server.d.ts +34 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +452 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/types.d.ts +47 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +67 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/normalize/clock.d.ts +40 -0
- package/dist/normalize/clock.d.ts.map +1 -0
- package/dist/normalize/clock.js +96 -0
- package/dist/normalize/clock.js.map +1 -0
- package/dist/normalize/dom-ir.d.ts +16 -0
- package/dist/normalize/dom-ir.d.ts.map +1 -0
- package/dist/normalize/dom-ir.js +48 -0
- package/dist/normalize/dom-ir.js.map +1 -0
- package/dist/normalize/index.d.ts +23 -0
- package/dist/normalize/index.d.ts.map +1 -0
- package/dist/normalize/index.js +118 -0
- package/dist/normalize/index.js.map +1 -0
- package/dist/normalize/lighthouse-insights.d.ts +27 -0
- package/dist/normalize/lighthouse-insights.d.ts.map +1 -0
- package/dist/normalize/lighthouse-insights.js +318 -0
- package/dist/normalize/lighthouse-insights.js.map +1 -0
- package/dist/normalize/lighthouse-ir.d.ts +25 -0
- package/dist/normalize/lighthouse-ir.d.ts.map +1 -0
- package/dist/normalize/lighthouse-ir.js +151 -0
- package/dist/normalize/lighthouse-ir.js.map +1 -0
- package/dist/normalize/network-ir.d.ts +23 -0
- package/dist/normalize/network-ir.d.ts.map +1 -0
- package/dist/normalize/network-ir.js +180 -0
- package/dist/normalize/network-ir.js.map +1 -0
- package/dist/normalize/runtime-ir.d.ts +18 -0
- package/dist/normalize/runtime-ir.d.ts.map +1 -0
- package/dist/normalize/runtime-ir.js +114 -0
- package/dist/normalize/runtime-ir.js.map +1 -0
- package/dist/normalize/trace-ir.d.ts +20 -0
- package/dist/normalize/trace-ir.d.ts.map +1 -0
- package/dist/normalize/trace-ir.js +224 -0
- package/dist/normalize/trace-ir.js.map +1 -0
- package/dist/normalize/types.d.ts +536 -0
- package/dist/normalize/types.d.ts.map +1 -0
- package/dist/normalize/types.js +242 -0
- package/dist/normalize/types.js.map +1 -0
- package/dist/output/manifest.d.ts +44 -0
- package/dist/output/manifest.d.ts.map +1 -0
- package/dist/output/manifest.js +232 -0
- package/dist/output/manifest.js.map +1 -0
- package/dist/output/toon.d.ts +19 -0
- package/dist/output/toon.d.ts.map +1 -0
- package/dist/output/toon.js +22 -0
- package/dist/output/toon.js.map +1 -0
- package/dist/output/writer.d.ts +31 -0
- package/dist/output/writer.d.ts.map +1 -0
- package/dist/output/writer.js +51 -0
- package/dist/output/writer.js.map +1 -0
- package/dist/report/analyzer.d.ts +29 -0
- package/dist/report/analyzer.d.ts.map +1 -0
- package/dist/report/analyzer.js +330 -0
- package/dist/report/analyzer.js.map +1 -0
- package/dist/report/index.d.ts +13 -0
- package/dist/report/index.d.ts.map +1 -0
- package/dist/report/index.js +12 -0
- package/dist/report/index.js.map +1 -0
- package/dist/report/markdown.d.ts +21 -0
- package/dist/report/markdown.d.ts.map +1 -0
- package/dist/report/markdown.js +182 -0
- package/dist/report/markdown.js.map +1 -0
- package/dist/report/remediations.d.ts +42 -0
- package/dist/report/remediations.d.ts.map +1 -0
- package/dist/report/remediations.js +179 -0
- package/dist/report/remediations.js.map +1 -0
- package/dist/report/scorer.d.ts +35 -0
- package/dist/report/scorer.d.ts.map +1 -0
- package/dist/report/scorer.js +72 -0
- package/dist/report/scorer.js.map +1 -0
- package/dist/report/types.d.ts +201 -0
- package/dist/report/types.d.ts.map +1 -0
- package/dist/report/types.js +149 -0
- package/dist/report/types.js.map +1 -0
- package/dist/shared/fs-utils.d.ts +12 -0
- package/dist/shared/fs-utils.d.ts.map +1 -0
- package/dist/shared/fs-utils.js +44 -0
- package/dist/shared/fs-utils.js.map +1 -0
- package/dist/shared/types.d.ts +69 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +18 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/utils.d.ts +6 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/dist/shared/utils.js +9 -0
- package/dist/shared/utils.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool handler implementations.
|
|
3
|
+
*
|
|
4
|
+
* Each handler corresponds to a registered MCP tool. The primary shortcut
|
|
5
|
+
* `perfgraph_run` runs the full pipeline (collect → normalize → extract →
|
|
6
|
+
* analyze → report) in a single call. Advanced users can call individual
|
|
7
|
+
* pipeline steps via the dedicated tools.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import type { IRBundle } from '../normalize/types.js';
|
|
12
|
+
import type { ProgressReporter } from './progress.js';
|
|
13
|
+
/**
|
|
14
|
+
* Collect raw performance data from a URL.
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleCollect(url: string, outputDir?: string, runs?: number, onProgress?: ProgressReporter | null, mobile?: string): Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
runDir?: string;
|
|
19
|
+
error?: string;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Normalize collected data into an IRBundle.
|
|
23
|
+
*/
|
|
24
|
+
export declare function handleNormalize(runDir: string): Promise<{
|
|
25
|
+
ir: IRBundle;
|
|
26
|
+
irFile: string;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Extract diagnostic features from an IRBundle.
|
|
30
|
+
*/
|
|
31
|
+
export declare function handleExtract(irFile: string): Promise<{
|
|
32
|
+
featuresFile: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Build a causal graph from extracted features.
|
|
36
|
+
*/
|
|
37
|
+
export declare function handleAnalyze(featuresFile: string): Promise<{
|
|
38
|
+
graphFile: string;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Generate a diagnostic report from extracted features.
|
|
42
|
+
*/
|
|
43
|
+
export declare function handleReport(featuresFile: string): Promise<{
|
|
44
|
+
reportFile: string;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Run the full PerfGraph pipeline: collect → normalize → extract → analyze → report.
|
|
48
|
+
*
|
|
49
|
+
* Sends progress notifications and returns structured results suitable for
|
|
50
|
+
* AI agent consumption.
|
|
51
|
+
*/
|
|
52
|
+
export declare function handleRun(url: string, outputDir?: string, runs?: number, onProgress?: ProgressReporter | null, mobile?: string): Promise<{
|
|
53
|
+
url: string;
|
|
54
|
+
outputDir: string;
|
|
55
|
+
files: {
|
|
56
|
+
report: string;
|
|
57
|
+
features: string;
|
|
58
|
+
graph: string;
|
|
59
|
+
insights: string;
|
|
60
|
+
networkSummary: string;
|
|
61
|
+
lighthouseSummary: string;
|
|
62
|
+
coverageSummary: string;
|
|
63
|
+
};
|
|
64
|
+
summary: {
|
|
65
|
+
score: string;
|
|
66
|
+
criticalIssues: number;
|
|
67
|
+
warnings: number;
|
|
68
|
+
infos: number;
|
|
69
|
+
issues: Record<string, string>;
|
|
70
|
+
};
|
|
71
|
+
}>;
|
|
72
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/mcp/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAYH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAetD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAmEtD;;GAEG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,EACpC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAsBD;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,EAAE,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAU3C;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBnC;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAoBhC;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAqBjC;AAMD;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,EACpC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;IACT,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;CACH,CAAC,CA6GD"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool handler implementations.
|
|
3
|
+
*
|
|
4
|
+
* Each handler corresponds to a registered MCP tool. The primary shortcut
|
|
5
|
+
* `perfgraph_run` runs the full pipeline (collect → normalize → extract →
|
|
6
|
+
* analyze → report) in a single call. Advanced users can call individual
|
|
7
|
+
* pipeline steps via the dedicated tools.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
import { writeManifest } from '../output/manifest.js';
|
|
14
|
+
import { run } from '../collect/orchestrator.js';
|
|
15
|
+
import { loadRunDir } from '../shared/fs-utils.js';
|
|
16
|
+
import { DEFAULT_RUN_OPTIONS } from '../shared/types.js';
|
|
17
|
+
import { normalize } from '../normalize/index.js';
|
|
18
|
+
import { extract } from '../extract/index.js';
|
|
19
|
+
import { buildInsights } from '../distill/insights.js';
|
|
20
|
+
import { buildNetworkSummary, buildLighthouseSummary, buildCoverageSummary, } from '../distill/summaries.js';
|
|
21
|
+
import { buildCausalGraph } from '../causal/index.js';
|
|
22
|
+
import { buildReport } from '../report/index.js';
|
|
23
|
+
import { buildReportMarkdown } from '../report/markdown.js';
|
|
24
|
+
import { convertToon } from '../output/toon.js';
|
|
25
|
+
import { severityOrder } from '../shared/utils.js';
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Helpers
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
/** Write a JSON or TOON file and return its path. */
|
|
30
|
+
async function writeJson(dir, filename, data) {
|
|
31
|
+
if (!existsSync(dir)) {
|
|
32
|
+
mkdirSync(dir, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
const filePath = resolve(dir, filename);
|
|
35
|
+
const content = filename.endsWith('.toon')
|
|
36
|
+
? await convertToon(data)
|
|
37
|
+
: JSON.stringify(data, null, 2);
|
|
38
|
+
writeFileSync(filePath, content, 'utf-8');
|
|
39
|
+
return filePath;
|
|
40
|
+
}
|
|
41
|
+
/** Build a compact issues summary map from the report. */
|
|
42
|
+
function buildIssuesMap(issues) {
|
|
43
|
+
const map = {};
|
|
44
|
+
for (const issue of issues) {
|
|
45
|
+
let key;
|
|
46
|
+
if (issue.id.startsWith('rb-')) {
|
|
47
|
+
key = 'renderBlocking';
|
|
48
|
+
}
|
|
49
|
+
else if (issue.id.includes('waterfall') || issue.id === 'cascade-delay') {
|
|
50
|
+
key = 'cascadeDelay';
|
|
51
|
+
}
|
|
52
|
+
else if (issue.id.includes('deep-critical') || issue.id === 'deep-critical-chain') {
|
|
53
|
+
key = 'deepCriticalChain';
|
|
54
|
+
}
|
|
55
|
+
else if (issue.id.includes('lcp')) {
|
|
56
|
+
key = 'lcpIncrease';
|
|
57
|
+
}
|
|
58
|
+
else if (issue.id.includes('layout') || issue.id.includes('cls')) {
|
|
59
|
+
key = 'layoutShifts';
|
|
60
|
+
}
|
|
61
|
+
else if (issue.id.includes('js') ||
|
|
62
|
+
issue.id.includes('long-task') ||
|
|
63
|
+
issue.id.includes('tbt')) {
|
|
64
|
+
key = 'javaScript';
|
|
65
|
+
}
|
|
66
|
+
else if (issue.id.includes('third-party')) {
|
|
67
|
+
key = 'thirdParty';
|
|
68
|
+
}
|
|
69
|
+
else if (issue.id.includes('ttfb')) {
|
|
70
|
+
key = 'ttfb';
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
key = issue.id.replace(/[^a-zA-Z0-9]/g, '');
|
|
74
|
+
}
|
|
75
|
+
// Upgrade severity if we already have a weaker one
|
|
76
|
+
const existing = map[key];
|
|
77
|
+
if (!existing ||
|
|
78
|
+
severityOrder(issue.severity) > severityOrder(existing)) {
|
|
79
|
+
map[key] = issue.severity;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return map;
|
|
83
|
+
}
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Pipeline steps
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
/**
|
|
88
|
+
* Collect raw performance data from a URL.
|
|
89
|
+
*/
|
|
90
|
+
export async function handleCollect(url, outputDir, runs, onProgress, mobile) {
|
|
91
|
+
const options = {
|
|
92
|
+
...DEFAULT_RUN_OPTIONS,
|
|
93
|
+
url,
|
|
94
|
+
output: outputDir ?? DEFAULT_RUN_OPTIONS.output,
|
|
95
|
+
runs: runs ?? 1,
|
|
96
|
+
mobile,
|
|
97
|
+
};
|
|
98
|
+
await onProgress?.report(0, 1, `Collecting data from ${url}...`);
|
|
99
|
+
const results = await run(url, options);
|
|
100
|
+
const successRuns = results.filter((r) => r.success);
|
|
101
|
+
if (successRuns.length === 0) {
|
|
102
|
+
const errors = results
|
|
103
|
+
.map((r) => r.error)
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.join('; ');
|
|
106
|
+
return { success: false, error: errors || 'All collection runs failed' };
|
|
107
|
+
}
|
|
108
|
+
return { success: true, runDir: resolve(successRuns[0].outputDir) };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Normalize collected data into an IRBundle.
|
|
112
|
+
*/
|
|
113
|
+
export async function handleNormalize(runDir) {
|
|
114
|
+
if (!existsSync(runDir)) {
|
|
115
|
+
throw new Error(`Run directory not found: ${runDir}`);
|
|
116
|
+
}
|
|
117
|
+
const raw = loadRunDir(runDir);
|
|
118
|
+
const ir = normalize(raw);
|
|
119
|
+
const irFile = await writeJson(runDir, 'ir.json', ir);
|
|
120
|
+
return { ir, irFile };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Extract diagnostic features from an IRBundle.
|
|
124
|
+
*/
|
|
125
|
+
export async function handleExtract(irFile) {
|
|
126
|
+
if (!existsSync(irFile)) {
|
|
127
|
+
throw new Error(`IR file not found: ${irFile}`);
|
|
128
|
+
}
|
|
129
|
+
let raw;
|
|
130
|
+
try {
|
|
131
|
+
raw = JSON.parse(readFileSync(irFile, 'utf-8'));
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
throw new Error(`Failed to parse IR file: ${err.message}`);
|
|
135
|
+
}
|
|
136
|
+
const ir = raw;
|
|
137
|
+
const features = extract(ir);
|
|
138
|
+
const dir = resolve(irFile, '..');
|
|
139
|
+
const featuresFile = await writeJson(dir, 'features.toon', features);
|
|
140
|
+
return { featuresFile };
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Build a causal graph from extracted features.
|
|
144
|
+
*/
|
|
145
|
+
export async function handleAnalyze(featuresFile) {
|
|
146
|
+
if (!existsSync(featuresFile)) {
|
|
147
|
+
throw new Error(`Features file not found: ${featuresFile}`);
|
|
148
|
+
}
|
|
149
|
+
let raw;
|
|
150
|
+
try {
|
|
151
|
+
raw = JSON.parse(readFileSync(featuresFile, 'utf-8'));
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
throw new Error(`Failed to parse features file: ${err.message}`);
|
|
155
|
+
}
|
|
156
|
+
const features = raw;
|
|
157
|
+
const graph = buildCausalGraph(features);
|
|
158
|
+
const dir = resolve(featuresFile, '..');
|
|
159
|
+
const graphFile = await writeJson(dir, 'graph.toon', graph);
|
|
160
|
+
return { graphFile };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Generate a diagnostic report from extracted features.
|
|
164
|
+
*/
|
|
165
|
+
export async function handleReport(featuresFile) {
|
|
166
|
+
if (!existsSync(featuresFile)) {
|
|
167
|
+
throw new Error(`Features file not found: ${featuresFile}`);
|
|
168
|
+
}
|
|
169
|
+
let raw;
|
|
170
|
+
try {
|
|
171
|
+
raw = JSON.parse(readFileSync(featuresFile, 'utf-8'));
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
throw new Error(`Failed to parse features file: ${err.message}`);
|
|
175
|
+
}
|
|
176
|
+
const features = raw;
|
|
177
|
+
const graph = buildCausalGraph(features);
|
|
178
|
+
const report = buildReport(graph, features);
|
|
179
|
+
const dir = resolve(featuresFile, '..');
|
|
180
|
+
const reportFile = await writeJson(dir, 'report.toon', report);
|
|
181
|
+
return { reportFile };
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
// Primary shortcut: run full pipeline
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
/**
|
|
187
|
+
* Run the full PerfGraph pipeline: collect → normalize → extract → analyze → report.
|
|
188
|
+
*
|
|
189
|
+
* Sends progress notifications and returns structured results suitable for
|
|
190
|
+
* AI agent consumption.
|
|
191
|
+
*/
|
|
192
|
+
export async function handleRun(url, outputDir, runs, onProgress, mobile) {
|
|
193
|
+
const baseOutput = outputDir ?? DEFAULT_RUN_OPTIONS.output;
|
|
194
|
+
const options = {
|
|
195
|
+
...DEFAULT_RUN_OPTIONS,
|
|
196
|
+
url,
|
|
197
|
+
output: baseOutput,
|
|
198
|
+
runs: runs ?? 1,
|
|
199
|
+
mobile,
|
|
200
|
+
};
|
|
201
|
+
await onProgress?.report(1, 5, 'Collecting data...');
|
|
202
|
+
const collectResults = await run(url, options);
|
|
203
|
+
const successRuns = collectResults.filter((r) => r.success);
|
|
204
|
+
if (successRuns.length === 0) {
|
|
205
|
+
const errors = collectResults
|
|
206
|
+
.map((r) => r.error)
|
|
207
|
+
.filter(Boolean)
|
|
208
|
+
.join('; ');
|
|
209
|
+
throw new Error(`All collection runs failed: ${errors || 'unknown error'}`);
|
|
210
|
+
}
|
|
211
|
+
const runDir = resolve(successRuns[0].outputDir);
|
|
212
|
+
// Normalize
|
|
213
|
+
await onProgress?.report(2, 5, 'Normalizing collected data...');
|
|
214
|
+
const raw = loadRunDir(runDir);
|
|
215
|
+
// Write compact summaries of raw data files before normalization
|
|
216
|
+
if (raw.network) {
|
|
217
|
+
const networkSummary = buildNetworkSummary(raw.network);
|
|
218
|
+
await writeJson(runDir, 'network-summary.toon', networkSummary);
|
|
219
|
+
}
|
|
220
|
+
if (raw.lighthouse) {
|
|
221
|
+
const lighthouseSummary = buildLighthouseSummary(raw.lighthouse);
|
|
222
|
+
await writeJson(runDir, 'lighthouse-summary.toon', lighthouseSummary);
|
|
223
|
+
}
|
|
224
|
+
if (raw.coverage) {
|
|
225
|
+
const coverageSummary = buildCoverageSummary(raw.coverage);
|
|
226
|
+
await writeJson(runDir, 'coverage-summary.toon', coverageSummary);
|
|
227
|
+
}
|
|
228
|
+
let ir;
|
|
229
|
+
try {
|
|
230
|
+
ir = normalize(raw);
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
throw new Error(`Normalization failed: ${err.message}`);
|
|
234
|
+
}
|
|
235
|
+
await writeJson(runDir, 'ir.json', ir);
|
|
236
|
+
// Extract features
|
|
237
|
+
await onProgress?.report(3, 5, 'Extracting diagnostic features...');
|
|
238
|
+
const features = extract(ir);
|
|
239
|
+
const featuresFile = await writeJson(runDir, 'features.toon', features);
|
|
240
|
+
// Build insights
|
|
241
|
+
const insights = buildInsights(features, raw.lighthouse ?? {});
|
|
242
|
+
const insightsFile = await writeJson(runDir, 'insights.toon', insights);
|
|
243
|
+
// Build causal graph
|
|
244
|
+
await onProgress?.report(4, 5, 'Building causal degradation graph...');
|
|
245
|
+
const graph = buildCausalGraph(features);
|
|
246
|
+
const graphFile = await writeJson(runDir, 'graph.toon', graph);
|
|
247
|
+
// Generate report (pass Lighthouse performance for score blending)
|
|
248
|
+
await onProgress?.report(5, 5, 'Generating diagnostic report...');
|
|
249
|
+
const lighthousePerf = ir.lighthouse.scores?.performance;
|
|
250
|
+
const report = buildReport(graph, features, lighthousePerf);
|
|
251
|
+
const reportFile = await writeJson(runDir, 'report.toon', report);
|
|
252
|
+
// Write human-readable markdown report
|
|
253
|
+
const reportMarkdown = buildReportMarkdown(report, insights);
|
|
254
|
+
const reportMdFile = resolve(runDir, 'report.md');
|
|
255
|
+
writeFileSync(reportMdFile, reportMarkdown, 'utf-8');
|
|
256
|
+
// Write manifest
|
|
257
|
+
const manifestFile = await writeManifest(runDir);
|
|
258
|
+
// Build light summary for the agent
|
|
259
|
+
const issuesMap = buildIssuesMap(report.issues);
|
|
260
|
+
const result = {
|
|
261
|
+
url,
|
|
262
|
+
outputDir: runDir,
|
|
263
|
+
files: {
|
|
264
|
+
report: reportFile,
|
|
265
|
+
reportMd: reportMdFile,
|
|
266
|
+
features: featuresFile,
|
|
267
|
+
graph: graphFile,
|
|
268
|
+
insights: insightsFile,
|
|
269
|
+
ir: resolve(runDir, 'ir.json'),
|
|
270
|
+
manifest: manifestFile,
|
|
271
|
+
networkSummary: resolve(runDir, 'network-summary.toon'),
|
|
272
|
+
lighthouseSummary: resolve(runDir, 'lighthouse-summary.toon'),
|
|
273
|
+
coverageSummary: resolve(runDir, 'coverage-summary.toon'),
|
|
274
|
+
},
|
|
275
|
+
summary: {
|
|
276
|
+
score: report.summary.score,
|
|
277
|
+
criticalIssues: report.summary.criticalIssues,
|
|
278
|
+
warnings: report.summary.warnings,
|
|
279
|
+
infos: report.summary.infos,
|
|
280
|
+
issues: issuesMap,
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/mcp/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,yBAAyB,CAAC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ACH,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE;YACL,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,YAAY;YACtB,QAAQ,EAAE,YAAY;YACtB,KAAK,EAAE,SAAS;YAChB,QAAQ,EAAE,YAAY;YACtB,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC;YAC9B,QAAQ,EAAE,YAAY;YACtB,cAAc,EAAE,OAAO,CAAC,MAAM,EAAE,sBAAsB,CAAC;YACvD,iBAAiB,EAAE,OAAO,CAAC,MAAM,EAAE,yBAAyB,CAAC;YAC7D,eAAe,EAAE,OAAO,CAAC,MAAM,EAAE,uBAAuB,CAAC;SAC1D;QACD,OAAO,EAAE;YACP,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK;YAC3B,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,cAAc;YAC7C,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ;YACjC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK;YAC3B,MAAM,EAAE,SAAS;SAClB;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP progress notification helper.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed wrapper around `extra.sendNotification` for sending
|
|
5
|
+
* `notifications/progress` updates during long-running tool operations
|
|
6
|
+
* (collect, run-full-pipeline).
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```ts
|
|
10
|
+
* const prog = createProgressReporter(extra.sendNotification, extra._meta?.progressToken);
|
|
11
|
+
* await prog?.report(1, 5, 'Collecting data…');
|
|
12
|
+
* await prog?.report(2, 5, 'Normalizing…');
|
|
13
|
+
* // ...
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Returns `null` when the client did not request progress, so callers
|
|
17
|
+
* can always `await prog?.report(...)` unconditionally.
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
import type { ServerNotification } from '@modelcontextprotocol/sdk/types.js';
|
|
22
|
+
/**
|
|
23
|
+
* Progress reporter — a lightweight function that sends one progress update.
|
|
24
|
+
* Returns `void`; errors are silently caught to avoid crashing the handler.
|
|
25
|
+
*/
|
|
26
|
+
export interface ProgressReporter {
|
|
27
|
+
report(progress: number, total: number, message?: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a ProgressReporter when the client supplied a progressToken.
|
|
31
|
+
*
|
|
32
|
+
* @param sendNotification - The `extra.sendNotification` function from the MCP tool callback.
|
|
33
|
+
* @param progressToken - The `progressToken` from `extra._meta?.progressToken`.
|
|
34
|
+
* @returns A ProgressReporter, or `null` if the client did not request progress.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createProgressReporter(sendNotification: (notification: ServerNotification) => Promise<void>, progressToken: string | number | undefined): ProgressReporter | null;
|
|
37
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/mcp/progress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1E;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,CAAC,YAAY,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,EACrE,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GACzC,gBAAgB,GAAG,IAAI,CAqBzB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP progress notification helper.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed wrapper around `extra.sendNotification` for sending
|
|
5
|
+
* `notifications/progress` updates during long-running tool operations
|
|
6
|
+
* (collect, run-full-pipeline).
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```ts
|
|
10
|
+
* const prog = createProgressReporter(extra.sendNotification, extra._meta?.progressToken);
|
|
11
|
+
* await prog?.report(1, 5, 'Collecting data…');
|
|
12
|
+
* await prog?.report(2, 5, 'Normalizing…');
|
|
13
|
+
* // ...
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Returns `null` when the client did not request progress, so callers
|
|
17
|
+
* can always `await prog?.report(...)` unconditionally.
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Create a ProgressReporter when the client supplied a progressToken.
|
|
23
|
+
*
|
|
24
|
+
* @param sendNotification - The `extra.sendNotification` function from the MCP tool callback.
|
|
25
|
+
* @param progressToken - The `progressToken` from `extra._meta?.progressToken`.
|
|
26
|
+
* @returns A ProgressReporter, or `null` if the client did not request progress.
|
|
27
|
+
*/
|
|
28
|
+
export function createProgressReporter(sendNotification, progressToken) {
|
|
29
|
+
if (progressToken === undefined)
|
|
30
|
+
return null;
|
|
31
|
+
return {
|
|
32
|
+
report: async (progress, total, message) => {
|
|
33
|
+
try {
|
|
34
|
+
await sendNotification({
|
|
35
|
+
method: 'notifications/progress',
|
|
36
|
+
params: {
|
|
37
|
+
progressToken,
|
|
38
|
+
progress,
|
|
39
|
+
total,
|
|
40
|
+
...(message !== undefined ? { message } : {}),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Swallow — progress is advisory; a failing notification must not
|
|
46
|
+
// break the tool response.
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/mcp/progress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAYH;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,gBAAqE,EACrE,aAA0C;IAE1C,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAE7C,OAAO;QACL,MAAM,EAAE,KAAK,EAAE,QAAgB,EAAE,KAAa,EAAE,OAAgB,EAAiB,EAAE;YACjF,IAAI,CAAC;gBACH,MAAM,gBAAgB,CAAC;oBACrB,MAAM,EAAE,wBAAwB;oBAChC,MAAM,EAAE;wBACN,aAAa;wBACb,QAAQ;wBACR,KAAK;wBACL,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC9C;iBACF,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,kEAAkE;gBAClE,2BAA2B;YAC7B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP diagnostic prompt templates.
|
|
3
|
+
*
|
|
4
|
+
* Prompts provide guided starting points for common diagnostic workflows.
|
|
5
|
+
* When an AI client invokes a prompt, it receives structured messages that
|
|
6
|
+
* guide it through the analysis process using PerfGraph tools.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import type { GetPromptResult } from '@modelcontextprotocol/sdk/types.js';
|
|
12
|
+
export declare const LcpAnalysisArgsSchema: z.ZodObject<{
|
|
13
|
+
url: z.ZodString;
|
|
14
|
+
reportUri: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
/**
|
|
17
|
+
* Guided LCP (Largest Contentful Paint) performance analysis.
|
|
18
|
+
*
|
|
19
|
+
* The prompt instructs the AI to run a focused analysis on LCP performance,
|
|
20
|
+
* examining the LCP breakdown (TTFB, resource delay, render delay, element
|
|
21
|
+
* render time) and all contributing factors.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildLcpAnalysisPrompt(args: z.infer<typeof LcpAnalysisArgsSchema>): GetPromptResult;
|
|
24
|
+
export declare const AuditArgsSchema: z.ZodObject<{
|
|
25
|
+
url: z.ZodString;
|
|
26
|
+
runs: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
focus: z.ZodOptional<z.ZodEnum<{
|
|
28
|
+
all: "all";
|
|
29
|
+
network: "network";
|
|
30
|
+
js: "js";
|
|
31
|
+
layout: "layout";
|
|
32
|
+
lcp: "lcp";
|
|
33
|
+
}>>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
/**
|
|
36
|
+
* Comprehensive full-site performance audit.
|
|
37
|
+
*
|
|
38
|
+
* Instructs the AI to perform a thorough analysis across all performance
|
|
39
|
+
* dimensions and produce a complete diagnostic report.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildAuditPrompt(args: z.infer<typeof AuditArgsSchema>): GetPromptResult;
|
|
42
|
+
export declare const SummarizeArgsSchema: z.ZodObject<{
|
|
43
|
+
reportUri: z.ZodString;
|
|
44
|
+
detail: z.ZodOptional<z.ZodEnum<{
|
|
45
|
+
normal: "normal";
|
|
46
|
+
detailed: "detailed";
|
|
47
|
+
brief: "brief";
|
|
48
|
+
}>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
/**
|
|
51
|
+
* Summarize an existing PerfGraph report in natural language.
|
|
52
|
+
*
|
|
53
|
+
* Takes a report resource URI (as returned by perfgraph_run) and produces
|
|
54
|
+
* a human-readable summary of the findings.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildSummarizePrompt(args: z.infer<typeof SummarizeArgsSchema>): GetPromptResult;
|
|
57
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/mcp/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAsC1E,eAAO,MAAM,qBAAqB;;;iBAKhC,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAAG,eAAe,CA6CnG;AAMD,eAAO,MAAM,eAAe;;;;;;;;;;iBAO1B,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,GAAG,eAAe,CAyDvF;AAMD,eAAO,MAAM,mBAAmB;;;;;;;iBAK9B,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,GAAG,eAAe,CAqC/F"}
|