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.
Files changed (263) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +280 -0
  3. package/dist/causal/builder.d.ts +34 -0
  4. package/dist/causal/builder.d.ts.map +1 -0
  5. package/dist/causal/builder.js +132 -0
  6. package/dist/causal/builder.js.map +1 -0
  7. package/dist/causal/index.d.ts +11 -0
  8. package/dist/causal/index.d.ts.map +1 -0
  9. package/dist/causal/index.js +10 -0
  10. package/dist/causal/index.js.map +1 -0
  11. package/dist/causal/rules/js.d.ts +49 -0
  12. package/dist/causal/rules/js.d.ts.map +1 -0
  13. package/dist/causal/rules/js.js +209 -0
  14. package/dist/causal/rules/js.js.map +1 -0
  15. package/dist/causal/rules/layout.d.ts +39 -0
  16. package/dist/causal/rules/layout.d.ts.map +1 -0
  17. package/dist/causal/rules/layout.js +169 -0
  18. package/dist/causal/rules/layout.js.map +1 -0
  19. package/dist/causal/rules/lcp.d.ts +49 -0
  20. package/dist/causal/rules/lcp.d.ts.map +1 -0
  21. package/dist/causal/rules/lcp.js +250 -0
  22. package/dist/causal/rules/lcp.js.map +1 -0
  23. package/dist/causal/rules/network.d.ts +39 -0
  24. package/dist/causal/rules/network.d.ts.map +1 -0
  25. package/dist/causal/rules/network.js +140 -0
  26. package/dist/causal/rules/network.js.map +1 -0
  27. package/dist/causal/types.d.ts +142 -0
  28. package/dist/causal/types.d.ts.map +1 -0
  29. package/dist/causal/types.js +88 -0
  30. package/dist/causal/types.js.map +1 -0
  31. package/dist/cli/analyze.d.ts +33 -0
  32. package/dist/cli/analyze.d.ts.map +1 -0
  33. package/dist/cli/analyze.js +137 -0
  34. package/dist/cli/analyze.js.map +1 -0
  35. package/dist/cli/collect.d.ts +28 -0
  36. package/dist/cli/collect.d.ts.map +1 -0
  37. package/dist/cli/collect.js +125 -0
  38. package/dist/cli/collect.js.map +1 -0
  39. package/dist/cli/extract.d.ts +31 -0
  40. package/dist/cli/extract.d.ts.map +1 -0
  41. package/dist/cli/extract.js +135 -0
  42. package/dist/cli/extract.js.map +1 -0
  43. package/dist/cli/mcp.d.ts +14 -0
  44. package/dist/cli/mcp.d.ts.map +1 -0
  45. package/dist/cli/mcp.js +53 -0
  46. package/dist/cli/mcp.js.map +1 -0
  47. package/dist/cli/normalize.d.ts +58 -0
  48. package/dist/cli/normalize.d.ts.map +1 -0
  49. package/dist/cli/normalize.js +179 -0
  50. package/dist/cli/normalize.js.map +1 -0
  51. package/dist/cli/report.d.ts +33 -0
  52. package/dist/cli/report.d.ts.map +1 -0
  53. package/dist/cli/report.js +137 -0
  54. package/dist/cli/report.js.map +1 -0
  55. package/dist/cli/run.d.ts +49 -0
  56. package/dist/cli/run.d.ts.map +1 -0
  57. package/dist/cli/run.js +243 -0
  58. package/dist/cli/run.js.map +1 -0
  59. package/dist/collect/buffer-monitor.d.ts +25 -0
  60. package/dist/collect/buffer-monitor.d.ts.map +1 -0
  61. package/dist/collect/buffer-monitor.js +69 -0
  62. package/dist/collect/buffer-monitor.js.map +1 -0
  63. package/dist/collect/console.d.ts +25 -0
  64. package/dist/collect/console.d.ts.map +1 -0
  65. package/dist/collect/console.js +82 -0
  66. package/dist/collect/console.js.map +1 -0
  67. package/dist/collect/coverage.d.ts +26 -0
  68. package/dist/collect/coverage.d.ts.map +1 -0
  69. package/dist/collect/coverage.js +99 -0
  70. package/dist/collect/coverage.js.map +1 -0
  71. package/dist/collect/dom.d.ts +37 -0
  72. package/dist/collect/dom.d.ts.map +1 -0
  73. package/dist/collect/dom.js +118 -0
  74. package/dist/collect/dom.js.map +1 -0
  75. package/dist/collect/lighthouse.d.ts +41 -0
  76. package/dist/collect/lighthouse.d.ts.map +1 -0
  77. package/dist/collect/lighthouse.js +111 -0
  78. package/dist/collect/lighthouse.js.map +1 -0
  79. package/dist/collect/network.d.ts +32 -0
  80. package/dist/collect/network.d.ts.map +1 -0
  81. package/dist/collect/network.js +236 -0
  82. package/dist/collect/network.js.map +1 -0
  83. package/dist/collect/orchestrator.d.ts +23 -0
  84. package/dist/collect/orchestrator.d.ts.map +1 -0
  85. package/dist/collect/orchestrator.js +350 -0
  86. package/dist/collect/orchestrator.js.map +1 -0
  87. package/dist/collect/performance.d.ts +28 -0
  88. package/dist/collect/performance.d.ts.map +1 -0
  89. package/dist/collect/performance.js +108 -0
  90. package/dist/collect/performance.js.map +1 -0
  91. package/dist/collect/runtime.d.ts +26 -0
  92. package/dist/collect/runtime.d.ts.map +1 -0
  93. package/dist/collect/runtime.js +81 -0
  94. package/dist/collect/runtime.js.map +1 -0
  95. package/dist/collect/session.d.ts +58 -0
  96. package/dist/collect/session.d.ts.map +1 -0
  97. package/dist/collect/session.js +162 -0
  98. package/dist/collect/session.js.map +1 -0
  99. package/dist/collect/trace.d.ts +40 -0
  100. package/dist/collect/trace.d.ts.map +1 -0
  101. package/dist/collect/trace.js +127 -0
  102. package/dist/collect/trace.js.map +1 -0
  103. package/dist/collect/types.d.ts +317 -0
  104. package/dist/collect/types.d.ts.map +1 -0
  105. package/dist/collect/types.js +12 -0
  106. package/dist/collect/types.js.map +1 -0
  107. package/dist/distill/insights.d.ts +67 -0
  108. package/dist/distill/insights.d.ts.map +1 -0
  109. package/dist/distill/insights.js +317 -0
  110. package/dist/distill/insights.js.map +1 -0
  111. package/dist/distill/summaries.d.ts +71 -0
  112. package/dist/distill/summaries.d.ts.map +1 -0
  113. package/dist/distill/summaries.js +165 -0
  114. package/dist/distill/summaries.js.map +1 -0
  115. package/dist/extract/critical-path.d.ts +17 -0
  116. package/dist/extract/critical-path.d.ts.map +1 -0
  117. package/dist/extract/critical-path.js +95 -0
  118. package/dist/extract/critical-path.js.map +1 -0
  119. package/dist/extract/index.d.ts +16 -0
  120. package/dist/extract/index.d.ts.map +1 -0
  121. package/dist/extract/index.js +32 -0
  122. package/dist/extract/index.js.map +1 -0
  123. package/dist/extract/js-hotspots.d.ts +15 -0
  124. package/dist/extract/js-hotspots.d.ts.map +1 -0
  125. package/dist/extract/js-hotspots.js +22 -0
  126. package/dist/extract/js-hotspots.js.map +1 -0
  127. package/dist/extract/layout-shifts.d.ts +19 -0
  128. package/dist/extract/layout-shifts.d.ts.map +1 -0
  129. package/dist/extract/layout-shifts.js +47 -0
  130. package/dist/extract/layout-shifts.js.map +1 -0
  131. package/dist/extract/lcp-breakdown.d.ts +19 -0
  132. package/dist/extract/lcp-breakdown.d.ts.map +1 -0
  133. package/dist/extract/lcp-breakdown.js +110 -0
  134. package/dist/extract/lcp-breakdown.js.map +1 -0
  135. package/dist/extract/main-thread.d.ts +16 -0
  136. package/dist/extract/main-thread.d.ts.map +1 -0
  137. package/dist/extract/main-thread.js +41 -0
  138. package/dist/extract/main-thread.js.map +1 -0
  139. package/dist/extract/render-blocking.d.ts +16 -0
  140. package/dist/extract/render-blocking.d.ts.map +1 -0
  141. package/dist/extract/render-blocking.js +79 -0
  142. package/dist/extract/render-blocking.js.map +1 -0
  143. package/dist/extract/third-party.d.ts +15 -0
  144. package/dist/extract/third-party.d.ts.map +1 -0
  145. package/dist/extract/third-party.js +127 -0
  146. package/dist/extract/third-party.js.map +1 -0
  147. package/dist/extract/types.d.ts +183 -0
  148. package/dist/extract/types.d.ts.map +1 -0
  149. package/dist/extract/types.js +118 -0
  150. package/dist/extract/types.js.map +1 -0
  151. package/dist/index.d.ts +20 -0
  152. package/dist/index.d.ts.map +1 -0
  153. package/dist/index.js +188 -0
  154. package/dist/index.js.map +1 -0
  155. package/dist/mcp/handlers.d.ts +72 -0
  156. package/dist/mcp/handlers.d.ts.map +1 -0
  157. package/dist/mcp/handlers.js +285 -0
  158. package/dist/mcp/handlers.js.map +1 -0
  159. package/dist/mcp/progress.d.ts +37 -0
  160. package/dist/mcp/progress.d.ts.map +1 -0
  161. package/dist/mcp/progress.js +51 -0
  162. package/dist/mcp/progress.js.map +1 -0
  163. package/dist/mcp/prompts.d.ts +57 -0
  164. package/dist/mcp/prompts.d.ts.map +1 -0
  165. package/dist/mcp/prompts.js +225 -0
  166. package/dist/mcp/prompts.js.map +1 -0
  167. package/dist/mcp/resources.d.ts +48 -0
  168. package/dist/mcp/resources.d.ts.map +1 -0
  169. package/dist/mcp/resources.js +149 -0
  170. package/dist/mcp/resources.js.map +1 -0
  171. package/dist/mcp/server.d.ts +34 -0
  172. package/dist/mcp/server.d.ts.map +1 -0
  173. package/dist/mcp/server.js +452 -0
  174. package/dist/mcp/server.js.map +1 -0
  175. package/dist/mcp/types.d.ts +47 -0
  176. package/dist/mcp/types.d.ts.map +1 -0
  177. package/dist/mcp/types.js +67 -0
  178. package/dist/mcp/types.js.map +1 -0
  179. package/dist/normalize/clock.d.ts +40 -0
  180. package/dist/normalize/clock.d.ts.map +1 -0
  181. package/dist/normalize/clock.js +96 -0
  182. package/dist/normalize/clock.js.map +1 -0
  183. package/dist/normalize/dom-ir.d.ts +16 -0
  184. package/dist/normalize/dom-ir.d.ts.map +1 -0
  185. package/dist/normalize/dom-ir.js +48 -0
  186. package/dist/normalize/dom-ir.js.map +1 -0
  187. package/dist/normalize/index.d.ts +23 -0
  188. package/dist/normalize/index.d.ts.map +1 -0
  189. package/dist/normalize/index.js +118 -0
  190. package/dist/normalize/index.js.map +1 -0
  191. package/dist/normalize/lighthouse-insights.d.ts +27 -0
  192. package/dist/normalize/lighthouse-insights.d.ts.map +1 -0
  193. package/dist/normalize/lighthouse-insights.js +318 -0
  194. package/dist/normalize/lighthouse-insights.js.map +1 -0
  195. package/dist/normalize/lighthouse-ir.d.ts +25 -0
  196. package/dist/normalize/lighthouse-ir.d.ts.map +1 -0
  197. package/dist/normalize/lighthouse-ir.js +151 -0
  198. package/dist/normalize/lighthouse-ir.js.map +1 -0
  199. package/dist/normalize/network-ir.d.ts +23 -0
  200. package/dist/normalize/network-ir.d.ts.map +1 -0
  201. package/dist/normalize/network-ir.js +180 -0
  202. package/dist/normalize/network-ir.js.map +1 -0
  203. package/dist/normalize/runtime-ir.d.ts +18 -0
  204. package/dist/normalize/runtime-ir.d.ts.map +1 -0
  205. package/dist/normalize/runtime-ir.js +114 -0
  206. package/dist/normalize/runtime-ir.js.map +1 -0
  207. package/dist/normalize/trace-ir.d.ts +20 -0
  208. package/dist/normalize/trace-ir.d.ts.map +1 -0
  209. package/dist/normalize/trace-ir.js +224 -0
  210. package/dist/normalize/trace-ir.js.map +1 -0
  211. package/dist/normalize/types.d.ts +536 -0
  212. package/dist/normalize/types.d.ts.map +1 -0
  213. package/dist/normalize/types.js +242 -0
  214. package/dist/normalize/types.js.map +1 -0
  215. package/dist/output/manifest.d.ts +44 -0
  216. package/dist/output/manifest.d.ts.map +1 -0
  217. package/dist/output/manifest.js +232 -0
  218. package/dist/output/manifest.js.map +1 -0
  219. package/dist/output/toon.d.ts +19 -0
  220. package/dist/output/toon.d.ts.map +1 -0
  221. package/dist/output/toon.js +22 -0
  222. package/dist/output/toon.js.map +1 -0
  223. package/dist/output/writer.d.ts +31 -0
  224. package/dist/output/writer.d.ts.map +1 -0
  225. package/dist/output/writer.js +51 -0
  226. package/dist/output/writer.js.map +1 -0
  227. package/dist/report/analyzer.d.ts +29 -0
  228. package/dist/report/analyzer.d.ts.map +1 -0
  229. package/dist/report/analyzer.js +330 -0
  230. package/dist/report/analyzer.js.map +1 -0
  231. package/dist/report/index.d.ts +13 -0
  232. package/dist/report/index.d.ts.map +1 -0
  233. package/dist/report/index.js +12 -0
  234. package/dist/report/index.js.map +1 -0
  235. package/dist/report/markdown.d.ts +21 -0
  236. package/dist/report/markdown.d.ts.map +1 -0
  237. package/dist/report/markdown.js +182 -0
  238. package/dist/report/markdown.js.map +1 -0
  239. package/dist/report/remediations.d.ts +42 -0
  240. package/dist/report/remediations.d.ts.map +1 -0
  241. package/dist/report/remediations.js +179 -0
  242. package/dist/report/remediations.js.map +1 -0
  243. package/dist/report/scorer.d.ts +35 -0
  244. package/dist/report/scorer.d.ts.map +1 -0
  245. package/dist/report/scorer.js +72 -0
  246. package/dist/report/scorer.js.map +1 -0
  247. package/dist/report/types.d.ts +201 -0
  248. package/dist/report/types.d.ts.map +1 -0
  249. package/dist/report/types.js +149 -0
  250. package/dist/report/types.js.map +1 -0
  251. package/dist/shared/fs-utils.d.ts +12 -0
  252. package/dist/shared/fs-utils.d.ts.map +1 -0
  253. package/dist/shared/fs-utils.js +44 -0
  254. package/dist/shared/fs-utils.js.map +1 -0
  255. package/dist/shared/types.d.ts +69 -0
  256. package/dist/shared/types.d.ts.map +1 -0
  257. package/dist/shared/types.js +18 -0
  258. package/dist/shared/types.js.map +1 -0
  259. package/dist/shared/utils.d.ts +6 -0
  260. package/dist/shared/utils.d.ts.map +1 -0
  261. package/dist/shared/utils.js +9 -0
  262. package/dist/shared/utils.js.map +1 -0
  263. package/package.json +67 -0
@@ -0,0 +1,452 @@
1
+ /**
2
+ * PerfGraph MCP Server.
3
+ *
4
+ * Exposes PerfGraph's full performance diagnostic pipeline through
5
+ * the Model Context Protocol. Primary usage is the `perfgraph_run` tool
6
+ * (one-shot URL → report). Advanced users can invoke individual pipeline
7
+ * steps via dedicated tools.
8
+ *
9
+ * Resources are available at `perfgraph://artifacts/{encoded-path}/{filename}`
10
+ * for reading collected data and generated reports.
11
+ *
12
+ * Usage (AI client config):
13
+ * ```json
14
+ * {
15
+ * "mcpServers": {
16
+ * "perfgraph": {
17
+ * "command": "node",
18
+ * "args": ["dist/index.js", "mcp"]
19
+ * }
20
+ * }
21
+ * }
22
+ * ```
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ import { McpServer, ResourceTemplate, } from '@modelcontextprotocol/sdk/server/mcp.js';
27
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
28
+ import { RunArgsSchema, CollectArgsSchema, NormalizeArgsSchema, ExtractArgsSchema, AnalyzeArgsSchema, ReportArgsSchema, ToonArgsSchema, } from './types.js';
29
+ import { handleRun, handleCollect, handleNormalize, handleExtract, handleAnalyze, handleReport, } from './handlers.js';
30
+ import { readResource, listArtifacts, encodePath, toon as toonResource, } from './resources.js';
31
+ import { createProgressReporter } from './progress.js';
32
+ import { buildLcpAnalysisPrompt, LcpAnalysisArgsSchema, buildAuditPrompt, AuditArgsSchema, buildSummarizePrompt, SummarizeArgsSchema, } from './prompts.js';
33
+ // ---------------------------------------------------------------------------
34
+ // Server entry point
35
+ // ---------------------------------------------------------------------------
36
+ /**
37
+ * Start the MCP stdio server.
38
+ *
39
+ * Registers all tools and resources, then listens for JSON-RPC messages
40
+ * on stdin/stdout. Never resolves — the server runs until the process
41
+ * is killed.
42
+ */
43
+ export async function startMcpServer() {
44
+ const server = new McpServer({
45
+ name: 'perfgraph',
46
+ version: '1.0.0',
47
+ });
48
+ // -----------------------------------------------------------------------
49
+ // Primary shortcut: full pipeline in one call
50
+ // -----------------------------------------------------------------------
51
+ server.registerTool('perfgraph_run', {
52
+ description: `Run the full PerfGraph pipeline on a URL: collect trace data, normalize, extract diagnostic features, build a causal degradation graph, and generate a performance report.
53
+
54
+ Returns a structured result with report file paths, performance score, issue counts, and a severity map of detected problems.
55
+
56
+ After calling this tool, you can read the full report via the perfgraph:// resource URIs returned in the 'files' field.
57
+
58
+ EXAMPLE:
59
+ agent calls perfgraph_run with url = "https://example.com"
60
+ → receives summary + file paths to report.json, features.json, graph.json
61
+ → reads report.json via perfgraph://artifacts/<path>/report.json for full details
62
+
63
+ This is the PRIMARY tool — use this for most performance analysis tasks.`,
64
+ inputSchema: RunArgsSchema,
65
+ }, async (args, extra) => {
66
+ try {
67
+ const progress = createProgressReporter(extra.sendNotification, extra._meta?.progressToken);
68
+ const result = await handleRun(args.url, args.outputDir, args.runs, progress, args.mobile);
69
+ // Enrich result with resource URIs
70
+ const encodedPath = encodePath(result.outputDir);
71
+ const enriched = {
72
+ ...result,
73
+ resourceUris: {
74
+ report: `perfgraph://artifacts/${encodedPath}/report.json`,
75
+ features: `perfgraph://artifacts/${encodedPath}/features.json`,
76
+ graph: `perfgraph://artifacts/${encodedPath}/graph.json`,
77
+ },
78
+ };
79
+ return {
80
+ content: [{ type: 'text', text: JSON.stringify(enriched, null, 2) }],
81
+ };
82
+ }
83
+ catch (err) {
84
+ const message = err.message;
85
+ return {
86
+ content: [
87
+ {
88
+ type: 'text',
89
+ text: JSON.stringify({ error: message }, null, 2),
90
+ },
91
+ ],
92
+ isError: true,
93
+ };
94
+ }
95
+ });
96
+ // -----------------------------------------------------------------------
97
+ // Advanced tools: individual pipeline steps
98
+ // -----------------------------------------------------------------------
99
+ server.registerTool('perfgraph_collect', {
100
+ description: `[Advanced] Collect raw performance data from a URL without running the full pipeline.
101
+
102
+ Use this when you only need the raw CDP data (trace, network, lighthouse, etc.)
103
+ without normalization or analysis. The collected data is written to a local
104
+ output directory.
105
+
106
+ ADVANCED TOOL: For most use cases, prefer perfgraph_run which runs the full pipeline.`,
107
+ inputSchema: CollectArgsSchema,
108
+ }, async (args, extra) => {
109
+ try {
110
+ const progress = createProgressReporter(extra.sendNotification, extra._meta?.progressToken);
111
+ const result = await handleCollect(args.url, args.outputDir, args.runs, progress, args.mobile);
112
+ if (!result.success) {
113
+ return {
114
+ content: [
115
+ {
116
+ type: 'text',
117
+ text: JSON.stringify({ error: result.error }, null, 2),
118
+ },
119
+ ],
120
+ isError: true,
121
+ };
122
+ }
123
+ return {
124
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
125
+ };
126
+ }
127
+ catch (err) {
128
+ return {
129
+ content: [
130
+ {
131
+ type: 'text',
132
+ text: JSON.stringify({ error: err.message }, null, 2),
133
+ },
134
+ ],
135
+ isError: true,
136
+ };
137
+ }
138
+ });
139
+ server.registerTool('perfgraph_normalize', {
140
+ description: `[Advanced] Normalize collected CDP data into a validated Intermediate Representation (IRBundle).
141
+
142
+ Accepts a run directory path (from perfgraph_collect) and produces a typed,
143
+ validated IRBundle with normalized timestamps across all clock domains.
144
+
145
+ ADVANCED TOOL: Usually called automatically by perfgraph_run. Use this when
146
+ you need to inspect or debug the normalization step.`,
147
+ inputSchema: NormalizeArgsSchema,
148
+ }, async (args) => {
149
+ try {
150
+ const result = await handleNormalize(args.runDir);
151
+ return {
152
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
153
+ };
154
+ }
155
+ catch (err) {
156
+ return {
157
+ content: [
158
+ {
159
+ type: 'text',
160
+ text: JSON.stringify({ error: err.message }, null, 2),
161
+ },
162
+ ],
163
+ isError: true,
164
+ };
165
+ }
166
+ });
167
+ server.registerTool('perfgraph_extract', {
168
+ description: `[Advanced] Extract diagnostic features from a normalized IRBundle.
169
+
170
+ Computes 7 feature metrics: LCP breakdown, critical path analysis, main thread
171
+ blocking, JS execution hotspots, layout shifts, third-party overhead, and
172
+ render-blocking resource score.
173
+
174
+ ADVANCED TOOL: Usually called automatically by perfgraph_run. Use this when
175
+ you want to inspect the raw feature set before causal analysis.`,
176
+ inputSchema: ExtractArgsSchema,
177
+ }, async (args) => {
178
+ try {
179
+ const result = await handleExtract(args.irFile);
180
+ return {
181
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
182
+ };
183
+ }
184
+ catch (err) {
185
+ return {
186
+ content: [
187
+ {
188
+ type: 'text',
189
+ text: JSON.stringify({ error: err.message }, null, 2),
190
+ },
191
+ ],
192
+ isError: true,
193
+ };
194
+ }
195
+ });
196
+ server.registerTool('perfgraph_analyze', {
197
+ description: `[Advanced] Build a causal degradation graph from extracted features.
198
+
199
+ Applies 30+ causal rules from 4 rule sets (LCP, JS, Network, Layout) and
200
+ produces a deterministic DAG where each edge has a confidence level
201
+ (strong/medium/weak).
202
+
203
+ ADVANCED TOOL: Usually called automatically by perfgraph_run. Use this when
204
+ you need to inspect the causal graph structure directly.`,
205
+ inputSchema: AnalyzeArgsSchema,
206
+ }, async (args) => {
207
+ try {
208
+ const result = await handleAnalyze(args.featuresFile);
209
+ return {
210
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
211
+ };
212
+ }
213
+ catch (err) {
214
+ return {
215
+ content: [
216
+ {
217
+ type: 'text',
218
+ text: JSON.stringify({ error: err.message }, null, 2),
219
+ },
220
+ ],
221
+ isError: true,
222
+ };
223
+ }
224
+ });
225
+ server.registerTool('perfgraph_report', {
226
+ description: `[Advanced] Generate a comprehensive performance report from extracted features.
227
+
228
+ Produces a self-contained JSON report with: issues sorted by severity, causal
229
+ chains from root cause to impact, prioritized recommendations with remediation
230
+ texts (in Russian), and raw features for cross-referencing.
231
+
232
+ ADVANCED TOOL: Usually called automatically by perfgraph_run. Use this when
233
+ you have already extracted features and want to generate a report separately.`,
234
+ inputSchema: ReportArgsSchema,
235
+ }, async (args) => {
236
+ try {
237
+ const result = await handleReport(args.featuresFile);
238
+ return {
239
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
240
+ };
241
+ }
242
+ catch (err) {
243
+ return {
244
+ content: [
245
+ {
246
+ type: 'text',
247
+ text: JSON.stringify({ error: err.message }, null, 2),
248
+ },
249
+ ],
250
+ isError: true,
251
+ };
252
+ }
253
+ });
254
+ // -----------------------------------------------------------------------
255
+ // TOON format tool
256
+ // -----------------------------------------------------------------------
257
+ server.registerTool('perfgraph_toon', {
258
+ description: `Convert a PerfGraph run's results into TOON (Token-Oriented Object Notation) format.
259
+
260
+ TOON is a compact, human-readable encoding of JSON designed to minimise token
261
+ usage in LLM prompts. It declares array lengths and field headers once, then
262
+ streams row values — making it ideal for AI consumption.
263
+
264
+ Accepts a run directory path (from perfgraph_run or perfgraph_collect) and
265
+ returns the run's report, features, and causal graph encoded as TOON.
266
+
267
+ After calling this tool, you can also access the TOON data via the resource
268
+ URI: webtr://runs/{encoded-runDir}/toon
269
+
270
+ ADVANCED TOOL: Use when you need token-optimised performance data for
271
+ LLM-based analysis or chaining into other AI tools.`,
272
+ inputSchema: ToonArgsSchema,
273
+ }, async (args) => {
274
+ try {
275
+ const uri = `webtr://runs/${encodePath(args.runDir)}/toon`;
276
+ const content = toonResource(uri);
277
+ return {
278
+ content: [{ type: 'text', text: content.text }],
279
+ };
280
+ }
281
+ catch (err) {
282
+ return {
283
+ content: [
284
+ {
285
+ type: 'text',
286
+ text: JSON.stringify({ error: err.message }, null, 2),
287
+ },
288
+ ],
289
+ isError: true,
290
+ };
291
+ }
292
+ });
293
+ // -----------------------------------------------------------------------
294
+ // Resources
295
+ // -----------------------------------------------------------------------
296
+ server.registerResource('perfgraph-artifact', new ResourceTemplate('perfgraph://artifacts/{path}/{filename}', {
297
+ list: async () => {
298
+ return {
299
+ resources: [
300
+ {
301
+ uri: 'perfgraph://artifacts/<run-dir>/report.json',
302
+ name: 'Full Diagnostic Report',
303
+ description: 'Complete performance report with issues, causal chains, and recommendations',
304
+ },
305
+ {
306
+ uri: 'perfgraph://artifacts/<run-dir>/features.json',
307
+ name: 'Extracted Features',
308
+ description: 'Raw diagnostic feature set (LCP, TBT, CLS, critical path, etc.)',
309
+ },
310
+ {
311
+ uri: 'perfgraph://artifacts/<run-dir>/graph.json',
312
+ name: 'Causal Graph',
313
+ description: 'Directed acyclic graph of causal degradation relationships',
314
+ },
315
+ {
316
+ uri: 'perfgraph://artifacts/<run-dir>/ir.json',
317
+ name: 'Intermediate Representation',
318
+ description: 'Normalized IRBundle with all collected performance data',
319
+ },
320
+ ],
321
+ };
322
+ },
323
+ }), {
324
+ title: 'PerfGraph Artifact',
325
+ description: 'Access PerfGraph collected data and generated reports by run directory and filename. ' +
326
+ 'The {path} segment is the filesystem path with separators replaced by underscores. ' +
327
+ 'For example, path "C:_Users_project_perfgraph-output_example" maps to ' +
328
+ '"C:/Users/project/perfgraph-output/example". Use file paths returned by perfgraph_run.',
329
+ mimeType: 'application/json',
330
+ }, async (uri, { path: encodedPath, filename }) => {
331
+ const pathPart = Array.isArray(encodedPath) ? encodedPath.join('_') : (encodedPath ?? '');
332
+ const filePart = Array.isArray(filename) ? filename.join('_') : (filename ?? '');
333
+ const fullUri = `perfgraph://artifacts/${pathPart}/${filePart}`;
334
+ const content = readResource(fullUri);
335
+ return {
336
+ contents: [
337
+ {
338
+ uri: fullUri,
339
+ text: content.text,
340
+ mimeType: content.mimeType,
341
+ },
342
+ ],
343
+ };
344
+ });
345
+ // Register a convenience resource for listing all artifacts in a run dir
346
+ server.registerResource('perfgraph-artifact-list', new ResourceTemplate('perfgraph://artifacts/{path}', {
347
+ list: async () => ({
348
+ resources: [
349
+ {
350
+ uri: 'perfgraph://artifacts/<run-dir>',
351
+ name: 'Run Directory Contents',
352
+ description: 'Lists all available PerfGraph artifacts in a run directory',
353
+ },
354
+ ],
355
+ }),
356
+ }), {
357
+ title: 'PerfGraph Run Directory',
358
+ description: 'List all available artifacts in a PerfGraph run directory',
359
+ mimeType: 'application/json',
360
+ }, async (uri, { path: encodedPath }) => {
361
+ const pathPart = Array.isArray(encodedPath) ? encodedPath.join('/') : (encodedPath ?? '');
362
+ const fullUri = `perfgraph://artifacts/${pathPart}`;
363
+ const artifacts = listArtifacts(fullUri);
364
+ if (artifacts.length === 0) {
365
+ return {
366
+ contents: [
367
+ {
368
+ uri: fullUri,
369
+ text: JSON.stringify({
370
+ error: 'No artifacts found',
371
+ path: pathPart.split('_').join('/'),
372
+ }, null, 2),
373
+ mimeType: 'application/json',
374
+ },
375
+ ],
376
+ };
377
+ }
378
+ const listing = artifacts.map((a) => ({
379
+ uri: a.uri,
380
+ name: a.uri.split('/').pop(),
381
+ mimeType: a.mimeType,
382
+ }));
383
+ return {
384
+ contents: [
385
+ {
386
+ uri: fullUri,
387
+ text: JSON.stringify({ artifacts: listing, count: listing.length }, null, 2),
388
+ mimeType: 'application/json',
389
+ },
390
+ ],
391
+ };
392
+ });
393
+ // -----------------------------------------------------------------------
394
+ // TOON resource
395
+ // -----------------------------------------------------------------------
396
+ server.registerResource('perfgraph-toon', new ResourceTemplate('webtr://runs/{runRef}/toon', {
397
+ list: async () => {
398
+ return {
399
+ resources: [
400
+ {
401
+ uri: 'webtr://runs/<encoded-runDir>/toon',
402
+ name: 'Run Results (TOON)',
403
+ description: 'Token-efficient TOON-encoded run results (report, features, causal graph)',
404
+ },
405
+ ],
406
+ };
407
+ },
408
+ }), {
409
+ title: 'PerfGraph TOON Output',
410
+ description: 'Token-optimised TOON encoding of a PerfGraph run\'s report, features, and causal graph. ' +
411
+ 'The {runRef} segment is the run directory path with path separators replaced by underscores, ' +
412
+ 'matching the encoding used in perfgraph://artifacts/ URIs.',
413
+ mimeType: 'text/plain',
414
+ }, async (uri, { runRef }) => {
415
+ const ref = Array.isArray(runRef) ? runRef.join('_') : (runRef ?? '');
416
+ const fullUri = `webtr://runs/${ref}/toon`;
417
+ const content = toonResource(fullUri);
418
+ return {
419
+ contents: [
420
+ {
421
+ uri: fullUri,
422
+ text: content.text,
423
+ mimeType: content.mimeType,
424
+ },
425
+ ],
426
+ };
427
+ });
428
+ // -----------------------------------------------------------------------
429
+ // Prompts
430
+ // -----------------------------------------------------------------------
431
+ server.registerPrompt('perfgraph_analyze_lcp', {
432
+ title: 'LCP Performance Analysis',
433
+ description: `Run a focused diagnostic analysis of Largest Contentful Paint (LCP) performance for a URL. Analyzes LCP breakdown (TTFB, resource delay, render delay, element render time), render-blocking resources, and causal chains. Provides prioritized remediation steps.`,
434
+ argsSchema: LcpAnalysisArgsSchema.shape,
435
+ }, (args) => buildLcpAnalysisPrompt(args));
436
+ server.registerPrompt('perfgraph_audit', {
437
+ title: 'Full Site Performance Audit',
438
+ description: `Run a comprehensive performance audit covering all diagnostic dimensions: LCP, JavaScript, Network, Layout, and Third-party. Optionally focus on a specific category. Produces a structured report with all issues, causal chains, and prioritized recommendations.`,
439
+ argsSchema: AuditArgsSchema.shape,
440
+ }, (args) => buildAuditPrompt(args));
441
+ server.registerPrompt('perfgraph_summarize_report', {
442
+ title: 'Summarize Performance Report',
443
+ description: `Read an existing PerfGraph report (by resource URI) and produce a natural-language summary. Supports brief, normal, and detailed verbosity levels. Use this when you already have a report and want a human-readable overview.`,
444
+ argsSchema: SummarizeArgsSchema.shape,
445
+ }, (args) => buildSummarizePrompt(args));
446
+ // -----------------------------------------------------------------------
447
+ // Transport
448
+ // -----------------------------------------------------------------------
449
+ const transport = new StdioServerTransport();
450
+ await server.connect(transport);
451
+ }
452
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,SAAS,EACT,gBAAgB,GACjB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,UAAU,EACV,IAAI,IAAI,YAAY,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,0EAA0E;IAC1E,8CAA8C;IAC9C,0EAA0E;IAE1E,MAAM,CAAC,YAAY,CACjB,eAAe,EACf;QACE,WAAW,EAAE;;;;;;;;;;;yEAWsD;QACnE,WAAW,EAAE,aAAa;KAC3B,EACD,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QACpB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,s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,CAAC,CACF,CAAC;IAEF,0EAA0E;IAC1E,UAAU;IACV,0EAA0E;IAE1E,MAAM,CAAC,cAAc,CACnB,uBAAuB,EACvB;QACE,KAAK,EAAE,0BAA0B;QACjC,WAAW,EAAE,oQAAoQ;QACjR,UAAU,EAAE,qBAAqB,CAAC,KAAK;KACxC,EACD,CAAC,IAAI,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,CACvC,CAAC;IAEF,MAAM,CAAC,cAAc,CACnB,iBAAiB,EACjB;QACE,KAAK,EAAE,6BAA6B;QACpC,WAAW,EAAE,qQAAqQ;QAClR,UAAU,EAAE,eAAe,CAAC,KAAK;KAClC,EACD,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CACjC,CAAC;IAEF,MAAM,CAAC,cAAc,CACnB,4BAA4B,EAC5B;QACE,KAAK,EAAE,8BAA8B;QACrC,WAAW,EAAE,gOAAgO;QAC7O,UAAU,EAAE,mBAAmB,CAAC,KAAK;KACtC,EACD,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CACrC,CAAC;IAEF,0EAA0E;IAC1E,YAAY;IACZ,0EAA0E;IAE1E,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * MCP-specific types and Zod schemas.
3
+ *
4
+ * Shared input schemas for MCP tool handlers and result types.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import { z } from 'zod';
9
+ /** Schema for the primary shortcut tool — full pipeline URL→report */
10
+ export declare const RunArgsSchema: z.ZodObject<{
11
+ url: z.ZodString;
12
+ outputDir: z.ZodOptional<z.ZodString>;
13
+ runs: z.ZodOptional<z.ZodNumber>;
14
+ mobile: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strip>;
16
+ /** Schema for the collect tool (advanced) */
17
+ export declare const CollectArgsSchema: z.ZodObject<{
18
+ url: z.ZodString;
19
+ outputDir: z.ZodOptional<z.ZodString>;
20
+ runs: z.ZodOptional<z.ZodNumber>;
21
+ noLighthouse: z.ZodOptional<z.ZodBoolean>;
22
+ noCoverage: z.ZodOptional<z.ZodBoolean>;
23
+ noConsole: z.ZodOptional<z.ZodBoolean>;
24
+ noDom: z.ZodOptional<z.ZodBoolean>;
25
+ mobile: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strip>;
27
+ /** Schema for the normalize tool (advanced) */
28
+ export declare const NormalizeArgsSchema: z.ZodObject<{
29
+ runDir: z.ZodString;
30
+ }, z.core.$strip>;
31
+ /** Schema for the extract tool (advanced) */
32
+ export declare const ExtractArgsSchema: z.ZodObject<{
33
+ irFile: z.ZodString;
34
+ }, z.core.$strip>;
35
+ /** Schema for the analyze tool (advanced) */
36
+ export declare const AnalyzeArgsSchema: z.ZodObject<{
37
+ featuresFile: z.ZodString;
38
+ }, z.core.$strip>;
39
+ /** Schema for the report tool (advanced) */
40
+ export declare const ReportArgsSchema: z.ZodObject<{
41
+ featuresFile: z.ZodString;
42
+ }, z.core.$strip>;
43
+ /** Schema for the toon tool — encodes run results in TOON format */
44
+ export declare const ToonArgsSchema: z.ZodObject<{
45
+ runDir: z.ZodString;
46
+ }, z.core.$strip>;
47
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,sEAAsE;AACtE,eAAO,MAAM,aAAa;;;;;iBASxB,CAAC;AAEH,6CAA6C;AAC7C,eAAO,MAAM,iBAAiB;;;;;;;;;iBAiB5B,CAAC;AAEH,+CAA+C;AAC/C,eAAO,MAAM,mBAAmB;;iBAG9B,CAAC;AAEH,6CAA6C;AAC7C,eAAO,MAAM,iBAAiB;;iBAG5B,CAAC;AAEH,6CAA6C;AAC7C,eAAO,MAAM,iBAAiB;;iBAG5B,CAAC;AAEH,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB;;iBAG3B,CAAC;AAEH,oEAAoE;AACpE,eAAO,MAAM,cAAc;;iBAGzB,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * MCP-specific types and Zod schemas.
3
+ *
4
+ * Shared input schemas for MCP tool handlers and result types.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import { z } from 'zod';
9
+ // ---------------------------------------------------------------------------
10
+ // Tool input schemas
11
+ // ---------------------------------------------------------------------------
12
+ /** Schema for the primary shortcut tool — full pipeline URL→report */
13
+ export const RunArgsSchema = z.object({
14
+ /** Target URL to analyze (required) */
15
+ url: z.string().min(1, 'url is required'),
16
+ /** Base output directory (default: ./perfgraph-output) */
17
+ outputDir: z.string().optional(),
18
+ /** Number of collection runs (default: 1) */
19
+ runs: z.number().int().min(1).max(10).optional(),
20
+ /** Device name for emulation (e.g. "iPhone 13", "Pixel 7"). Empty/omitted = desktop */
21
+ mobile: z.string().optional(),
22
+ });
23
+ /** Schema for the collect tool (advanced) */
24
+ export const CollectArgsSchema = z.object({
25
+ /** Target URL to collect data from (required) */
26
+ url: z.string().min(1, 'url is required'),
27
+ /** Base output directory (default: ./perfgraph-output) */
28
+ outputDir: z.string().optional(),
29
+ /** Number of collection runs (default: 1) */
30
+ runs: z.number().int().min(1).max(10).optional(),
31
+ /** Skip Lighthouse audit */
32
+ noLighthouse: z.boolean().optional(),
33
+ /** Skip JS/CSS coverage */
34
+ noCoverage: z.boolean().optional(),
35
+ /** Skip console log capture */
36
+ noConsole: z.boolean().optional(),
37
+ /** Skip DOM snapshot */
38
+ noDom: z.boolean().optional(),
39
+ /** Device name for emulation (e.g. "iPhone 13", "Pixel 7"). Empty/omitted = desktop */
40
+ mobile: z.string().optional(),
41
+ });
42
+ /** Schema for the normalize tool (advanced) */
43
+ export const NormalizeArgsSchema = z.object({
44
+ /** Path to the run directory containing collected data */
45
+ runDir: z.string().min(1, 'runDir is required'),
46
+ });
47
+ /** Schema for the extract tool (advanced) */
48
+ export const ExtractArgsSchema = z.object({
49
+ /** Path to a normalized IR JSON file */
50
+ irFile: z.string().min(1, 'irFile is required'),
51
+ });
52
+ /** Schema for the analyze tool (advanced) */
53
+ export const AnalyzeArgsSchema = z.object({
54
+ /** Path to a FeatureSet JSON file */
55
+ featuresFile: z.string().min(1, 'featuresFile is required'),
56
+ });
57
+ /** Schema for the report tool (advanced) */
58
+ export const ReportArgsSchema = z.object({
59
+ /** Path to a FeatureSet JSON file */
60
+ featuresFile: z.string().min(1, 'featuresFile is required'),
61
+ });
62
+ /** Schema for the toon tool — encodes run results in TOON format */
63
+ export const ToonArgsSchema = z.object({
64
+ /** Path to the run directory containing perfgraph output files */
65
+ runDir: z.string().min(1, 'runDir is required'),
66
+ });
67
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,uCAAuC;IACvC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,CAAC;IACzC,0DAA0D;IAC1D,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,6CAA6C;IAC7C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;IAChD,uFAAuF;IACvF,MAAM,EAAE,CAAC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AAE,oBAAoB,CAAC;CAChD,CAAC,CAAC;AAEH,6CAA6C;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,qCAAqC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,0BAA0B,CAAC;CAC5D,CAAC,CAAC;AAEH,4CAA4C;AAC5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,qCAAqC;IACrC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,0BAA0B,CAAC;CAC5D,CAAC,CAAC;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,kEAAkE;IAClE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,oBAAoB,CAAC;CAChD,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Clock domain normalization utilities.
3
+ *
4
+ * Raw data from different CDP domains arrives on different clock domains.
5
+ * This module converts all timestamps to a common epoch: milliseconds
6
+ * relative to the navigation start (navigationStart).
7
+ *
8
+ * Supported clock domains:
9
+ * - cdp-monotonic-us : Chromium Tracing microsecond monotonic clock
10
+ * - cdp-monotonic-ms : CDP millisecond monotonic clock
11
+ * - epoch-ms : Standard Unix epoch in milliseconds
12
+ * - epoch-s : Standard Unix epoch in seconds
13
+ * - network-monotonic-s : Network domain monotonic seconds (with wall-time offset)
14
+ * - lighthouse-ms : Lighthouse-reported relative milliseconds
15
+ */
16
+ import type { RawDataBundle } from '../collect/types.js';
17
+ /** The clock domain a raw timestamp originated from */
18
+ export type ClockDomain = 'cdp-monotonic-us' | 'cdp-monotonic-ms' | 'epoch-ms' | 'epoch-s' | 'network-monotonic-s' | 'lighthouse-ms';
19
+ /** Anchors used to convert each clock domain to relative ms */
20
+ export interface ClockAnchor {
21
+ /** navigationStart timestamp in ms epoch (from Performance.getMetrics or trace) */
22
+ navigationStart: number;
23
+ /** Wall time of the first network request (seconds since epoch), used for network clock sync */
24
+ firstRequestWallTime?: number;
25
+ }
26
+ /**
27
+ * Convert a raw timestamp to milliseconds relative to navigationStart.
28
+ *
29
+ * NaN / Infinity guard: if the result is not a finite number, return 0.
30
+ */
31
+ export declare function toRelativeMs(raw: number, domain: ClockDomain, anchor: ClockAnchor): number;
32
+ /**
33
+ * Resolve a ClockAnchor from a RawDataBundle.
34
+ *
35
+ * navigationStart is extracted from the performance metrics (Timestamp metric)
36
+ * or falls back to 0. firstRequestWallTime is taken from the first network
37
+ * request's wallTime field if available.
38
+ */
39
+ export declare function resolveClockAnchor(raw: RawDataBundle): ClockAnchor;
40
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/normalize/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMzD,uDAAuD;AACvD,MAAM,MAAM,WAAW,GACnB,kBAAkB,GAClB,kBAAkB,GAClB,UAAU,GACV,SAAS,GACT,qBAAqB,GACrB,eAAe,CAAC;AAEpB,+DAA+D;AAC/D,MAAM,WAAW,WAAW;IAC1B,mFAAmF;IACnF,eAAe,EAAE,MAAM,CAAC;IACxB,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,WAAW,GAClB,MAAM,CAoDR;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,WAAW,CA8BlE"}