@perf-engineer/web 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Perf Engineer Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,210 @@
1
- # Temporary Holding Version
1
+ # Perf Engineer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@perf-engineer/web)](https://www.npmjs.com/package/@perf-engineer/web)
4
+ [![CI](https://github.com/perf-engineer/perf-engineer/actions/workflows/ci.yml/badge.svg)](https://github.com/perf-engineer/perf-engineer/actions/workflows/ci.yml)
5
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D22.13.0-brightgreen)](#环境要求)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
7
+
8
+ 面向 Antigravity、Cursor、Claude Code、Codex 与 VS Code 等 AI 编程宿主的只读 Web 首屏性能诊断 MCP Server。基于真实 Chrome 与 Lighthouse 12 多次采样并结合只读源码排查,输出面向团队的问题分析报告(`report.md`)与可直接交给人或 AI 逐项执行的优化施工单(`perf-tasks.md`)。
9
+
10
+ ## 特性
11
+
12
+ - 真实 Chrome + Lighthouse 12 多次采样取中位数,优先定位影响首屏的最大资源、图片、脚本与接口瓶颈
13
+ - 诊断过程严格只读,不修改业务仓库代码,不执行构建、依赖安装或 Git 操作
14
+ - 自动核对线上运行产物与本地代码仓库的一致性,存在版本差异时拆分线上运维、线上发版与本地代码任务
15
+ - 内置 6 维首屏排查清单,无需额外依赖即可运行,也支持按团队规范扩展
16
+ - 支持在优化上线后沿用同一设备、网络与登录条件发起复测,以实测中位数对比前后变化
17
+
18
+ ## 环境要求
19
+
20
+ - [Node.js](https://nodejs.org/) `>= 22.13.0`
21
+ - 本机已安装 Chrome 或 Chromium
22
+
23
+ ## 快速开始
24
+
25
+ 在支持 MCP 的客户端中添加如下标准配置即可直接运行(无需克隆源码仓库):
26
+
27
+ ```json
28
+ {
29
+ "mcpServers": {
30
+ "perf-engineer": {
31
+ "command": "npx",
32
+ "args": ["-y", "@perf-engineer/web"]
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ 也可以按具体客户端使用内置安装命令一键写入配置和只读规则:
39
+
40
+ <details>
41
+ <summary>Antigravity(含防误写 Hook 保护)</summary>
42
+
43
+ ```bash
44
+ npx -y @perf-engineer/web install antigravity
45
+ ```
46
+
47
+ 命令会将插件包写入 `~/.gemini/config/plugins/perf-engineer`,重启或重载 Antigravity 插件后生效。
48
+
49
+ </details>
50
+
51
+ <details>
52
+ <summary>Cursor</summary>
53
+
54
+ 在目标项目根目录执行:
55
+
56
+ ```bash
57
+ npx -y @perf-engineer/web install cursor
58
+ ```
59
+
60
+ 会安全合并 `.cursor/mcp.json`(保留已有配置)并写入 `.cursor/rules/perf-engineer.mdc`。加 `--global` 参数可安装到 `~/.cursor/mcp.json`。
61
+
62
+ </details>
63
+
64
+ <details>
65
+ <summary>Claude Code</summary>
66
+
67
+ 使用 Claude CLI 添加全局配置:
68
+
69
+ ```bash
70
+ claude mcp add perf-engineer -- npx -y @perf-engineer/web
71
+ ```
72
+
73
+ 或在目标项目根目录执行 `npx -y @perf-engineer/web install claude-code` 生成 `.mcp.json`。
74
+
75
+ </details>
76
+
77
+ <details>
78
+ <summary>Codex</summary>
79
+
80
+ 在目标项目根目录执行:
81
+
82
+ ```bash
83
+ npx -y @perf-engineer/web install codex
84
+ ```
85
+
86
+ 若配置全局 `~/.codex/config.toml`:
87
+
88
+ ```toml
89
+ [mcp_servers.perf-engineer]
90
+ command = "npx"
91
+ args = ["-y", "@perf-engineer/web"]
92
+ ```
93
+
94
+ </details>
95
+
96
+ <details>
97
+ <summary>VS Code</summary>
98
+
99
+ 在目标项目根目录执行:
100
+
101
+ ```bash
102
+ npx -y @perf-engineer/web install vscode
103
+ ```
104
+
105
+ 或手动配置 `.vscode/mcp.json`:
106
+
107
+ ```json
108
+ {
109
+ "servers": {
110
+ "perf-engineer": {
111
+ "type": "stdio",
112
+ "command": "npx",
113
+ "args": ["-y", "@perf-engineer/web"]
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ </details>
120
+
121
+ ## 使用方式
122
+
123
+ ### 公开页面诊断
124
+
125
+ > 用 perf-engineer 诊断 `https://shop.example.com/`,本地代码仓库在 `/path/to/storefront`,不需要登录。
126
+
127
+ ### 需要登录的页面
128
+
129
+ > 用 perf-engineer 诊断 `https://app.example.com/dashboard`,本地代码仓库在 `/path/to/app`,需要登录。
130
+
131
+ 运行到登录步骤时,会自动打开一个隔离的 Chrome 窗口供你手动登录(支持扫码、验证码或双因素认证);登录完成后通知 AI 继续测速即可,工具不会读取或记录密码、Cookie、本地存储或 Token。
132
+
133
+ ### 执行施工单
134
+
135
+ 诊断结束后会直接返回 `perf-tasks.md` 路径。你可以自己按优先级改,也可以把文件发给 AI 执行:
136
+
137
+ > 按这份 `perf-tasks.md` 逐项完成优化,每完成一项跑一下里面的验收步骤。
138
+
139
+ ### 上线后复测
140
+
141
+ 优化部署完成后,沿用上次的测速条件重跑一次,直接对比前后指标:
142
+
143
+ > 用 perf-engineer 复测 `https://shop.example.com/`,对比上次诊断结果。
144
+
145
+ ## 输出产物
146
+
147
+ 每次运行的结果统一写入 `~/.perf-engineer/data/runs/<run-id>/`:
148
+
149
+ ```text
150
+ ~/.perf-engineer/data/runs/<run-id>/
151
+ ├── report.md # 性能诊断报告(核心结论、实测对比、线上/本地问题与排查覆盖)
152
+ ├── perf-tasks.md # 性能优化施工单(修改范围、具体步骤、低成本验收与回滚方式)
153
+ ├── manifest.json # 场景配置、耗时汇总与审计记录
154
+ └── evidence/ # 首屏截图、网络请求列表与 Lighthouse 诊断原始明细
155
+ ```
156
+
157
+ 以下为一次真实电商首页诊断(已脱敏)的实测汇总,完整报告与施工单见 `examples/`:
158
+
159
+ | 用户体验指标 | 实测中位数 | 参考阈值 | 状态 |
160
+ | --- | ---: | ---: | --- |
161
+ | 综合性能分 | 42 分 | ≥ 85 分 | ❌ 偏低 |
162
+ | 首次内容绘制(FCP) | 1.5 秒 | ≤ 1.8 秒 | ✅ 正常 |
163
+ | 最大内容绘制(LCP) | 12.2 秒 | ≤ 2.5 秒 | ❌ 太慢 |
164
+ | 视觉完成指数(Speed Index) | 9.8 秒 | ≤ 3.4 秒 | ❌ 严重卡顿 |
165
+ | 总阻塞时间(TBT) | 429 毫秒 | ≤ 200 毫秒 | ⚠️ 偏高 |
166
+ | 累积布局偏移(CLS) | 0.01 | ≤ 0.10 | ✅ 正常 |
167
+
168
+ - [完整诊断报告示例(report.md)](examples/storefront-report.md)
169
+ - [完整优化施工单示例(perf-tasks.md)](examples/storefront-tasks.md)
170
+
171
+ ## 排查范围与自定义
172
+
173
+ 内置排查清单覆盖以下 6 个首屏优化方向,不依赖外部技能库即可直接运行:
174
+
175
+ | 排查方向 | 主要检查内容 |
176
+ | --- | --- |
177
+ | Bundle 瘦身与拆包 | UI/工具库按需引入、公共包拆分非首屏重依赖、重复库与旧版 Polyfill |
178
+ | 网络资源调度 | 关键跨域 `preconnect` / `dns-prefetch`、`preload` 与 `prefetch` 误用与双拉问题 |
179
+ | 图片全链路 | CDN 裁剪尺寸与 WebP/AVIF 转换、首屏外与轮播非首帧 `loading="lazy"`、本地大图压缩 |
180
+ | 渲染与执行时机 | 默认隐藏弹窗提前挂载、长页面下方区块懒加载、统计与支付 SDK 延后加载、首屏透明延迟动画 |
181
+ | 缓存与传输策略 | 带哈希静态资源强缓存、入口 HTML 协商缓存、`br`/`gzip`/`zstd` 压缩与 HTTP/2 |
182
+ | 接口瀑布与主线程长任务 | 冷启动重复请求、串行接口链、子请求扇出与过大的 DOM 节点规模 |
183
+
184
+ 如需增加团队内部规范,直接编辑 [packages/guidance/playbooks/first-screen-sop.md](packages/guidance/playbooks/first-screen-sop.md) 后重新构建即可生效。
185
+
186
+ ## 安全与边界
187
+
188
+ - 诊断期间不会修改目标仓库中的任何文件,也不会执行构建、安装或 Git 命令
189
+ - 不会读取、记录或索取浏览器 Cookie、`localStorage`/`sessionStorage`、密码或 Token
190
+ - 初始只读诊断不会宣称性能已经改善,只有在修改部署并完成同场景复测后才会给出对比结论
191
+
192
+ ## 本地开发
193
+
194
+ ```bash
195
+ git clone https://github.com/perf-engineer/perf-engineer.git
196
+ cd perf-engineer
197
+ npm install
198
+ npm run build
199
+ npm run build:web
200
+ npm run check
201
+ npm test
202
+ ```
203
+
204
+ ## 相关文档与许可证
205
+
206
+ - [中文产品需求与架构设计](docs/PRODUCT_REQUIREMENTS.zh-CN.md)
207
+ - [Product Requirements (English)](docs/PRODUCT_REQUIREMENTS.md)
208
+ - [贡献指南](CONTRIBUTING.md)
209
+ - [安全策略](SECURITY.md)
210
+ - 基于 [MIT License](LICENSE) 开源