@perf-engineer/web 0.0.0-stage → 0.1.1
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 +210 -2
- package/dist/cli.js +6443 -0
- package/package.json +47 -4
- package/playbooks/first-screen-sop.md +118 -0
- package/playbooks/guidance.lock.json +17 -0
- package/templates/antigravity/README.md +3 -0
- package/templates/antigravity/agents/perf-engineer.md +64 -0
- package/templates/antigravity/hooks/readonly-guard.mjs +142 -0
- package/templates/antigravity/hooks.json +16 -0
- package/templates/antigravity/mcp_config.json +14 -0
- package/templates/antigravity/plugin.json +11 -0
- package/templates/antigravity/rules/AGENTS.md +12 -0
- package/templates/antigravity/skills/perf-diagnose/SKILL.md +66 -0
- package/templates/codex/AGENTS.md +49 -0
- package/templates/codex/mcp-config.json +14 -0
- package/templates/codex/skills/perf-diagnose/SKILL.md +64 -0
- package/templates/cursor/.cursor/mcp.json +14 -0
- package/templates/cursor/.cursor/rules/perf-engineer.mdc +76 -0
- package/templates/vscode/.vscode/mcp.json +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perf-engineer/web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Strictly read-only web performance diagnosis and task planning MCP server & installer for AI coding hosts.",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/perf-engineer/perf-engineer.git",
|
|
10
|
+
"directory": "packages/web"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/perf-engineer/perf-engineer#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/perf-engineer/perf-engineer/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"web-performance",
|
|
18
|
+
"lighthouse",
|
|
19
|
+
"core-web-vitals",
|
|
20
|
+
"mcp",
|
|
21
|
+
"ai-agent",
|
|
22
|
+
"diagnostics"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.13.0"
|
|
29
|
+
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"perf-engineer-web": "dist/cli.js"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/",
|
|
35
|
+
"playbooks/",
|
|
36
|
+
"templates/",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "node ../../scripts/build-web-package.mjs",
|
|
42
|
+
"prepublishOnly": "node ../../scripts/build-web-package.mjs"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
46
|
+
"chrome-launcher": "^1.1.2",
|
|
47
|
+
"lighthouse": "^12.6.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Perf Engineer 首屏性能深度诊断 SOP(First-Screen Diagnostic Playbook)
|
|
2
|
+
|
|
3
|
+
> 来源:基于真实业务首屏优化实战经验提炼。作为 `source-analysis` 阶段的必查方法论,与真实浏览器运行时证据及本地只读源码锚点结合使用。所有结论仍须经 Core 证据门禁验证。
|
|
4
|
+
|
|
5
|
+
## 0. 总纲:先抓体积与耗时大头
|
|
6
|
+
|
|
7
|
+
- 加载阶段通常占首屏总耗时的 70%–80%,优化性价比最高的方向是**先按资源体积降序处理最大的前几项**。
|
|
8
|
+
- 先调用 `perf_get_evidence`(`projectionKind: "top-assets"`)查看首屏按体积排序的 Top 资源及其占比,再顺着大头逐层向下深挖,避免先纠结几 KB 的边角优化。
|
|
9
|
+
- 必须先核对**线上产物与本地仓库/dist 的版本一致性(`versionParity`)**;若存在漂移,分别列出“线上已部署问题”与“本地源码当前问题”,不要因版本不一致放弃排查。
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 1. Bundle 瘦身与拆包治理
|
|
14
|
+
|
|
15
|
+
### 1.1 第三方 UI 库、工具库与 Polyfill 的 Tree-Shaking 失效
|
|
16
|
+
- **运行时依据**:查看 `perf_get_evidence("script-and-third-party")` 与 Lighthouse `unused-javascript` / `unused-css-rules` / `legacy-javascript` / `duplicated-javascript`,识别体积大且未使用率高的 bundle(如 `chunk-vendors.*`)。
|
|
17
|
+
- **源码排查**:检查 `package.json`、入口文件(`main.js`/`main.ts`)、组件导入方式与 Babel/Webpack/Vite 配置:
|
|
18
|
+
- UI 组件库(Vant、Element、Ant Design 等)或内部工具库是否整包 `import`、或因未配置按需插件(如 `babel-plugin-import`、`unplugin-vue-components`)导致 tree-shaking 失效?
|
|
19
|
+
- 是否因 `.browserslistrc` 过于宽泛或全量 `transpileDependencies: true` 导致打入大量 `core-js-pure` 等旧版 polyfill?
|
|
20
|
+
- 是否存在重复功能库(例如同时引入 `normalize.css` + `reset.css`、或两套日期/图标库)?
|
|
21
|
+
|
|
22
|
+
### 1.2 `vendors` 膨胀、路由级懒加载与 `splitChunks` 精细拆包
|
|
23
|
+
- **运行时依据**:对比公共 `vendors` 包大小与首屏实际使用的字节占比。
|
|
24
|
+
- **源码排查**:检查路由表与构建配置(`vue.config.js` / `webpack.config.*` / `vite.config.*`)的 `splitChunks` / `manualChunks`:
|
|
25
|
+
- SPA 路由表是否同步静态 `import` 了大量非首屏页面组件?应将非首屏路由改为动态 `() => import(...)` 按需加载。
|
|
26
|
+
- 是否把仅局部页面或非首屏用到的重型依赖(如 `lottie-web`、`swiper`、图表库、富文本、地图、二维码等)塞进了全站共享的 `vendors.js`?
|
|
27
|
+
- 建议将重型局部依赖单独拆包并配合动态 `import()` 按需加载,让每个页面只加载自己真正需要的包。
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 2. 网络资源调度(预解析 / 预加载 / 预拉取)
|
|
32
|
+
|
|
33
|
+
### 2.1 关键 CDN 与跨域接口缺少 `preconnect` / `dns-prefetch`
|
|
34
|
+
- **运行时依据**:调用 `perf_get_evidence("network-waterfall")`,找出首屏请求的跨域 CDN、图片域名、字体域名和 API 域名,查看建连与首字节耗时及 `uses-rel-preconnect` 建议。
|
|
35
|
+
- **源码排查**:检查入口 HTML 模板 `<head>`:
|
|
36
|
+
- 对首屏强依赖的 1–3 个关键跨域域名,是否同时配置了 `<link rel="preconnect" href="...">` 与 `<link rel="dns-prefetch" href="...">`(兼顾建连提速与旧浏览器优雅回退)?
|
|
37
|
+
- 注意不要对过多无关域名滥加 `preconnect`(反而浪费连接资源)。
|
|
38
|
+
|
|
39
|
+
### 2.2 `preload` vs `prefetch` 误用与双重下载陷阱
|
|
40
|
+
- **运行时依据**:查看 `network-waterfall` 中的重复请求列表、以及首屏期间是否有低优先级 `prefetch` 抢占关键 JS/CSS 带宽。
|
|
41
|
+
- **源码排查**:检查入口 HTML 模板、构建插件(如 Vue CLI 默认 `prefetch`)和业务预加载工具:
|
|
42
|
+
- **高危反模式**:严禁对当前首屏马上就要使用的资源使用 `rel="prefetch"`——如果在 `prefetch` 未完成时 `<script>`/`<link>` 又引用了同一资源,浏览器会发起**两次重复请求**;当前页关键资源应使用 `rel="preload"`(并核对 `as` / `type` / `crossorigin` 属性一致,避免字体双拉)。
|
|
43
|
+
- 下一跳高概率页面的资源应使用 `prefetch`,且在 MPA/公共模板场景下不应写死在 `<head>`,而应在 `window.onload` 之后延迟注入(如 `load` 后 `500ms` 动态创建 `<link rel="prefetch">`)。
|
|
44
|
+
- 排查是否错误预加载了超大非必要资源(例如用 `preload` 强拉 185 KB 全量图标字体,而实际只用了几十个图标)。
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 3. 图片全链路优化
|
|
49
|
+
|
|
50
|
+
### 3.1 LCP 主图优先发现、首屏外懒加载与固定宽高防 CLS
|
|
51
|
+
- **运行时依据**:调用 `perf_get_evidence("image-audit")` 与 `perf_get_evidence("lcp-breakdown")`,查看 `lcp-discovery-insight`、`offscreen-images`、`unsized-images` 与首屏图片并发请求数量/体积。
|
|
52
|
+
- **源码排查**:
|
|
53
|
+
- **LCP 主图反向检查**:严禁给首屏 LCP 主图添加 `loading="lazy"`;优先以原生 `<img>`(而非 JS 注入或 CSS `background-image`)输出并设置 `fetchpriority="high"`,让浏览器预加载扫描器尽早发现。
|
|
54
|
+
- **首屏外懒加载**:检查首屏下方区块的 `<img>`、背景图及轮播非首帧,开启 `loading="lazy"` 或视口懒加载,避免与关键 JS/CSS 抢占并发连接。
|
|
55
|
+
- **固定尺寸防 CLS**:检查首屏及 Banner 图片是否声明了显式 `width`/`height` 或稳定 `aspect-ratio`,避免图片加载前后挤压布局。
|
|
56
|
+
|
|
57
|
+
### 3.2 CDN 图片未转 WebP 与未按展示尺寸裁剪
|
|
58
|
+
- **运行时依据**:在 `image-audit` 中检查 `modern-image-formats`(是否仍是 PNG/JPG 而非 WebP/AVIF)和 `uses-responsive-images`(原图尺寸是否远大于实际渲染宽度)。
|
|
59
|
+
- **源码排查**:检查图片 URL 组装工具或图片组件,确认运营/CDN 图片是否统一追加了格式转换(WebP/AVIF)与按容器宽度裁剪的参数,避免下发超大原图。
|
|
60
|
+
|
|
61
|
+
### 3.3 本地静态图片未压缩
|
|
62
|
+
- **运行时依据**:查看 `uses-optimized-images` 及 `top-assets` 中超大本地 PNG/JPG 图片。
|
|
63
|
+
- **源码排查**:检查仓库 `src/assets`、`public/` 中引用的大体积本地图片,确认是否缺乏构建期/提交前无损或有损压缩(如 TinyPNG / imagemin / 转 WebP)。
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 4. 首屏渲染与代码执行时机治理
|
|
68
|
+
|
|
69
|
+
### 4.1 默认隐藏的弹窗、抽屉与 Tab 提前挂载
|
|
70
|
+
- **运行时依据**:观察首屏网络请求中是否夹杂明显不属于首屏可见区域的接口请求或图片资源。
|
|
71
|
+
- **源码排查**:重点检查首屏组件内的弹窗(Modal/Popup)、抽屉(Drawer)、非默认 Tab:
|
|
72
|
+
- 是否只用 `v-show` 或 `:visible="false"` 隐藏而默认就挂载了内部子组件,导致弹窗里的大图或接口在首屏就被触发?
|
|
73
|
+
- **推荐模式**:使用首次打开标志位惰性挂载(如 Vue 中 `v-if="hasShowed"` 配合 `:visible` 控制显隐,React 中首次打开后再渲染子树)。
|
|
74
|
+
|
|
75
|
+
### 4.2 长页面非首屏组件懒加载(推荐混合触发策略)
|
|
76
|
+
- **运行时依据**:查看 `dom-size`、主线程脚本与渲染耗时(`script-and-third-party`、`mainthread-work-breakdown`)。
|
|
77
|
+
- **源码排查**:检查长页面首屏下方复杂区块是否全部在首屏同步渲染:
|
|
78
|
+
- 若首屏下方区块较重,推荐采用异步组件 + **混合懒加载策略**:`window.onload` 后延迟加载,同时监听用户滚动/视口位置(`IntersectionObserver`)作为提前触发兜底——既保证首屏带宽与主线程全给首屏,又防止用户快速下滑看到空白。
|
|
79
|
+
|
|
80
|
+
### 4.3 埋点、性能监控等非业务 SDK 抢占首屏
|
|
81
|
+
- **运行时依据**:在 `script-and-third-party` 中检查 `third-party-summary` 与 `bootup-time`,识别统计、埋点、错误监控、APM、客服、广告等非核心业务脚本是否在首屏加载并占用主线程。
|
|
82
|
+
- **源码排查**:检查入口 HTML 与 `main.js`/`App`,确认这类非核心 SDK 是否同步引入或首屏立即初始化;建议推迟到 `window.onload`(或 `requestIdleCallback`)之后动态加载与上报。
|
|
83
|
+
|
|
84
|
+
### 4.4 首屏元素延迟展示、字体阻塞、高开销特效与 SSR 数据膨胀
|
|
85
|
+
- **运行时依据**:查看 `lcp-breakdown` 的 `elementRenderDelayMs`、`font-display-insight`、`forced-reflow-insight` 与 `mainthread-work-breakdown` 的 `Style & Layout` / `Rendering` 耗时。
|
|
86
|
+
- **源码排查**:
|
|
87
|
+
- 检查首屏主视觉区域(Hero / LCP 元素)是否存在初始 `opacity: 0` + 延迟入场动画拖慢首帧可见性,或存在大面积 `filter: blur(...)` / `backdrop-filter` / 常驻无限粒子动画导致持续重绘。
|
|
88
|
+
- 检查自定义 Web 字体是否配置 `font-display: swap` / `optional`,中文字体是否过大未做子集化或 WOFF2 压缩。
|
|
89
|
+
- 若为 SSR/SSG 项目(Next.js / Nuxt 等),检查注入 HTML 的初始序列化数据(如 `__NEXT_DATA__` / `__INITIAL_STATE__`)是否携带了大量首屏不需要的冗余字段,拖慢 HTML 下载与客户端 Hydration。
|
|
90
|
+
|
|
91
|
+
### 4.5 纯静态展示页过度框架化(架构级参考建议)
|
|
92
|
+
- 若页面属于纯文案/规则说明等几乎无交互的静态页,但首屏却承载了沉重的 SPA 框架运行时,可在报告中作为**架构建议**提出静态 HTML 化或预渲染选项(不强行发高风险重构任务)。
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 5. 缓存与传输治理
|
|
97
|
+
|
|
98
|
+
### 5.1 强缓存与协商缓存分层 + 压缩 + 协议
|
|
99
|
+
- **运行时依据**:调用 `perf_get_evidence("resource-headers")`,检查 `Content-Encoding`、`Cache-Control`、`ETag` 及 HTTP 协议版本(`uses-text-compression`、`cache-insight`、`uses-http2`)。
|
|
100
|
+
- **源码与配置排查**:检查仓库中的 Nginx / CDN / 网关配置,并与线上实测响应头交叉印证:
|
|
101
|
+
- 带内容哈希的 JS/CSS/字体/图片:必须开启 gzip/brotli 压缩,并配置长期强缓存(如 `Cache-Control: public, max-age=31536000, immutable`);
|
|
102
|
+
- 入口 HTML(如 `/index.html`):必须走协商缓存(`Cache-Control: no-cache`),严禁强缓存导致发版不更新;
|
|
103
|
+
- 若仓库已有正确配置但线上未生效,标记为线上运维冲突(`ops-action`),严禁盲改仓库文件冒充修复。
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 6. 接口瀑布与主线程长任务延伸排查
|
|
108
|
+
|
|
109
|
+
- **接口瀑布**:调用 `perf_get_evidence("network-waterfall")`,检查首屏 XHR/Fetch 接口是否存在**串行等待链**、**重复发同一接口**、**非首屏接口提前发**或**超大未压缩 JSON 响应**。
|
|
110
|
+
- **主线程长任务**:调用 `perf_get_evidence("script-and-third-party")` 和 `perf_get_evidence("long-tasks")`,将主线程耗时归因到具体脚本文件与本地对应模块。
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 排查覆盖要求(提交 `SourceAnalysisResult.sopChecklist`)
|
|
115
|
+
|
|
116
|
+
完成上述 6 个维度检查后,在 `SourceAnalysisResult.sopChecklist` 中按维度汇报覆盖结果(每条注明 `dimension`、`status`: `finding | healthy | not-applicable | needs-verification`、`summary`、`relatedClaimIds`):
|
|
117
|
+
- **查出问题(`finding`)**:落到对应 `SourceClaim`(区分 `live-runtime` / `local-source`)并生成施工单任务;
|
|
118
|
+
- **查过且健康(`healthy`)或当前页面不适用(`not-applicable`)**:简明说明检查了什么、为什么健康/不适用,防止遗漏也避免过度优化。
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"provider": "addyosmani/web-quality-skills",
|
|
3
|
+
"repository": "https://github.com/addyosmani/web-quality-skills.git",
|
|
4
|
+
"revision": "afa8da942115f2961fdbfa80807ea0b232ff6c00",
|
|
5
|
+
"skills": [
|
|
6
|
+
{
|
|
7
|
+
"name": "performance",
|
|
8
|
+
"path": "skills/performance/SKILL.md",
|
|
9
|
+
"sha256": "b0c220185d88c61f7770eb127d8facf86c86d2dd1fd82b86e15a4965a0137265"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "core-web-vitals",
|
|
13
|
+
"path": "skills/core-web-vitals/SKILL.md",
|
|
14
|
+
"sha256": "731aa78c0347e8b3e191b75962175bee058ce73817278e610ac0fe546e685914"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: perf-engineer
|
|
3
|
+
description: Single read-only performance diagnosis and task-planning agent backed by Perf Engineer Core MCP gates.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- Generated from Perf Engineer Agent Definition v2.0.0. Do not edit by hand; run npm run generate:plugins. -->
|
|
7
|
+
|
|
8
|
+
# Perf Engineer Agent
|
|
9
|
+
|
|
10
|
+
You are the single source-analysis and task-planning agent in a read-only performance diagnostic run.
|
|
11
|
+
|
|
12
|
+
Only work in the phase supplied by Perf Engineer Core. Use host-native repository search and read tools to understand source code. Treat performance guidance as advisory. Do not modify files, run project commands, invoke Git, install dependencies, deploy, or generate patches.
|
|
13
|
+
|
|
14
|
+
## Source Analysis Phase
|
|
15
|
+
|
|
16
|
+
1. First call `perf_get_sop` to load the built-in First-Screen Diagnostic SOP Playbook, and use `perf_get_evidence` with the deep projections (`top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, `resource-headers`, `lcp-breakdown`) to start from the largest transfer/time bottlenecks.
|
|
17
|
+
2. Check **live vs local version parity** (compare live served JS/CSS/font filenames & hashes against local `dist/` and source files) and fill `versionParity` (`matched`, `mismatch`, or `unknown` with a clear plain-language summary).
|
|
18
|
+
3. Systematically inspect EVERY SOP dimension against both live evidence and local repository code:
|
|
19
|
+
- **Bundle & code splitting**: UI/utility library tree-shaking failures, `vendors` bloat / `splitChunks`, redundant libraries, legacy polyfills.
|
|
20
|
+
- **Network scheduling**: missing `preconnect` + `dns-prefetch` for critical cross-origin CDN/API domains, `preload` vs `prefetch` misuse (never `prefetch` current-page critical assets; defer next-page `prefetch` after `window.onload`), duplicate downloads.
|
|
21
|
+
- **Image pipeline**: offscreen/carousel lazy loading, CDN WebP & responsive width resizing, oversized uncompressed local static images.
|
|
22
|
+
- **Rendering & execution timing**: hidden modals/popups/tabs mounted eagerly on first screen (recommend `v-if="hasShowed"` + `:visible`), long-page below-the-fold hybrid lazy loading (`onload` + scroll/viewport trigger), analytics/monitoring SDKs competing with first screen (defer after `window.onload`), hero `opacity: 0` render-delay animations or heavy `blur`/particle repaints.
|
|
23
|
+
- **Caching & transport**: hashed assets (`max-age=31536000, immutable`) vs HTML (`no-cache`), gzip/brotli, HTTP/2.
|
|
24
|
+
- **API waterfall & main-thread**: serial/duplicate/oversized XHR/Fetch calls, `bootup-time` and `third-party-summary` hotspots.
|
|
25
|
+
4. Always write `executiveSummary` (`headline` + 2–4 plain-language `coreReasons` in Chinese without jargon), `notRecommended` (what should NOT be changed right now and why), and `sopChecklist` (one entry per SOP dimension with `status: "finding" | "healthy" | "not-applicable" | "needs-verification"`, `summary` describing current findings/evidence, and `recommendation` giving a plain-language action direction or "保持现状,暂无需改动").
|
|
26
|
+
5. Separate findings clearly by `scope`:
|
|
27
|
+
- `scope: "live-runtime"`: issues observed on the live deployed origin (backed by concrete Lighthouse 12 `diagnostics`, `top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, and LCP breakdown facts).
|
|
28
|
+
- `scope: "local-source"`: concrete performance bottlenecks verified directly in the local repository source, with exact file paths, line ranges, SHA-256 `fileDigest` (obtainable strictly read-only via `perf_read_anchor`), exact `snippet`, `whyThisFile`, `estimatedImpact`, and `recommendedFix`.
|
|
29
|
+
- `scope: "both"`: verified source bottlenecks that directly explain live runtime issues when live and local match.
|
|
30
|
+
6. For deployment or static delivery claims, mark `deploymentConfigStatus` as `candidate-config`, `active-config`, or `conflicting-config`. When live and local mismatch or Nginx config conflicts, report BOTH sides honestly instead of refusing all recommendations.
|
|
31
|
+
|
|
32
|
+
## Task Planning Phase
|
|
33
|
+
|
|
34
|
+
1. Use Claim Gate results, `versionParity`, and verified file digests from the repository snapshot.
|
|
35
|
+
2. Emit human-and-machine-readable `TaskProposal[]` in recommended `executionOrder` using the 4 task kinds:
|
|
36
|
+
- `code-execution` (`scope: "local-code"`): concrete edits to verified local repository files (`allowedFiles` with SHA-256 digests, `prohibitedFiles`, `preserveBehaviors`, concrete `requiredChanges`, low-cost `acceptanceChecks`, `stopConditions`, `rollbackGuidance`).
|
|
37
|
+
- `ops-action` (`scope: "live-ops"`): concrete live server/Nginx/CDN actions (`allowedFiles: []`, read-only `referenceFiles`, concrete `requiredChanges`, `curl -I` / header `acceptanceChecks`).
|
|
38
|
+
- `deploy-action` (`scope: "live-deploy"`): build and deployment parity steps (`allowedFiles: []`, concrete `requiredChanges`, hash-parity `acceptanceChecks`).
|
|
39
|
+
- `investigation`: only when evidence is genuinely insufficient to recommend a safe action (`allowedFiles: []`, `requiredChanges: []`).
|
|
40
|
+
3. Keep each `code-execution` task atomic and tightly scoped to **1 single optimization concern and typically 1–2 files** (at most 3 tightly coupled files), so coding agents can implement, verify, and roll back cleanly without bundling unrelated concerns (e.g., split Vuetify tree-shaking, Vite `manualChunks`, route lazy-loading, and font cleanup into separate focused tasks).
|
|
41
|
+
4. Write clear, plain-language Chinese for `title`, `problemSummary`, `requiredChanges[].action` (concise Chinese verb phrases such as `关闭 Rocket Loader` or `商品卡传入缩略图尺寸`, never English kebab-case slugs), `requiredChanges[].description`, `acceptanceChecks`, `stopConditions`, and `rollbackGuidance`.
|
|
42
|
+
|
|
43
|
+
Never state that a code change has improved performance. The current diagnostic ends after report and task artifacts are published.
|
|
44
|
+
|
|
45
|
+
<!-- Generated from Perf Engineer Agent Definition v2.0.0. Do not edit by hand; run npm run generate:plugins. -->
|
|
46
|
+
|
|
47
|
+
## Diagnostic Workflow (MCP-First, Strictly Read-Only)
|
|
48
|
+
|
|
49
|
+
1. Collect and confirm the three minimum user inputs: target URL, local repository path, and whether login is required.
|
|
50
|
+
2. Call `perf_create_run` with `request: { requestedUrl, repositoryPath, loginRequired }`. Follow the `nextActions` returned by Core.
|
|
51
|
+
3. Call `perf_confirm_scenario` with `runId` and `expectedRevision`.
|
|
52
|
+
4. If login is required (`WAITING_FOR_LOGIN`):
|
|
53
|
+
- Call `perf_begin_login`. Core opens a visible browser window with an isolated `0o700` profile.
|
|
54
|
+
- Ask the user to complete login manually and confirm; never inspect or request cookies, storage values, or credentials.
|
|
55
|
+
- Call `perf_confirm_login` once the user confirms.
|
|
56
|
+
5. Call `perf_start_measurement`. Measurement runs asynchronously; poll `perf_get_operation` until `COMPLETED` (or cancel via `perf_cancel_operation`).
|
|
57
|
+
6. Call `perf_claim_source_phase` to obtain a Core-issued single-use `phaseExecutionId` lease, compact issue packets, playbook summary, and Lighthouse 12 diagnostics.
|
|
58
|
+
- Call `perf_get_sop` to read the built-in First-Screen Diagnostic SOP Playbook, then use `perf_get_evidence` (`top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, `resource-headers`, `lcp-breakdown`) and `perf_read_anchor` to fetch exact read-only line snippets with SHA-256 `fileDigest`.
|
|
59
|
+
- Compare live served assets vs local repository to determine `versionParity`, walk through every SOP dimension across BOTH live runtime and local source, fill `sopChecklist`, and call `perf_submit_claims` with the `phaseExecutionId` lease.
|
|
60
|
+
7. Call `perf_claim_task_phase` to obtain a task-planning `phaseExecutionId` lease and compact Claim Gate decisions.
|
|
61
|
+
- Emit `code-execution`, `ops-action`, `deploy-action`, or `investigation` tasks in clear `executionOrder`.
|
|
62
|
+
- Call `perf_submit_tasks` with the `phaseExecutionId` lease.
|
|
63
|
+
8. Call `perf_compile_artifacts` to run Report Quality Gate and publish `report.md`, `perf-tasks.md`, and `evidence/` outside the diagnosed repository.
|
|
64
|
+
9. Stop after publishing artifacts and report their paths. Never modify repository files, run git/shell/build/install/deploy commands, or claim performance improved without a separate comparable retest.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Generated from Perf Engineer Agent Definition v2.0.0. Do not edit by hand; run npm run generate:plugins.
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, appendFileSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
6
|
+
|
|
7
|
+
const WRITE_TOOLS = new Set([
|
|
8
|
+
"write_file",
|
|
9
|
+
"edit_file",
|
|
10
|
+
"write_to_file",
|
|
11
|
+
"replace_file_content",
|
|
12
|
+
"multi_replace_file_content"
|
|
13
|
+
]);
|
|
14
|
+
const SHELL_TOOLS = new Set(["run_command"]);
|
|
15
|
+
|
|
16
|
+
function resolveSafe(targetPath) {
|
|
17
|
+
try {
|
|
18
|
+
return realpathSync(targetPath);
|
|
19
|
+
} catch {
|
|
20
|
+
try {
|
|
21
|
+
const parentReal = realpathSync(dirname(targetPath));
|
|
22
|
+
return join(parentReal, targetPath.split(/[\\/]/).pop() ?? "");
|
|
23
|
+
} catch {
|
|
24
|
+
return resolve(targetPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isInside(parent, candidate) {
|
|
30
|
+
const rel = relative(resolveSafe(parent), resolveSafe(candidate));
|
|
31
|
+
return rel === "" || (!rel.startsWith("..") && !rel.includes(".."));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isProcessAlive(pid) {
|
|
35
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
36
|
+
try {
|
|
37
|
+
process.kill(pid, 0);
|
|
38
|
+
return true;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
return err && err.code === "EPERM";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readActiveRuns(stateDir) {
|
|
45
|
+
const activeFile = join(stateDir, "active-runs.json");
|
|
46
|
+
if (!existsSync(activeFile)) return [];
|
|
47
|
+
try {
|
|
48
|
+
const parsed = JSON.parse(readFileSync(activeFile, "utf8"));
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
return (Array.isArray(parsed.runs) ? parsed.runs : []).filter(
|
|
51
|
+
(entry) => entry && typeof entry.repositoryPath === "string" && Date.parse(entry.expiresAt) > now && isProcessAlive(entry.pid)
|
|
52
|
+
);
|
|
53
|
+
} catch {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function recordViolation(stateDir, runId, violation) {
|
|
59
|
+
try {
|
|
60
|
+
const dir = join(stateDir, "violations");
|
|
61
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
62
|
+
appendFileSync(join(dir, `${runId}.jsonl`), `${JSON.stringify(violation)}\n`, { mode: 0o600 });
|
|
63
|
+
} catch {
|
|
64
|
+
// 违规记录失败不放行拦截决策。
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function extractTargetPaths(args) {
|
|
69
|
+
if (!args || typeof args !== "object") return [];
|
|
70
|
+
const candidates = [];
|
|
71
|
+
for (const key of ["Path", "TargetFile", "path", "filePath", "FilePath"]) {
|
|
72
|
+
if (typeof args[key] === "string" && args[key].trim()) {
|
|
73
|
+
candidates.push(args[key]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return candidates;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let rawInput = "";
|
|
80
|
+
for await (const chunk of process.stdin) {
|
|
81
|
+
rawInput += chunk.toString("utf8");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let payload = {};
|
|
85
|
+
try {
|
|
86
|
+
payload = rawInput.trim() ? JSON.parse(rawInput) : {};
|
|
87
|
+
} catch {
|
|
88
|
+
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const stateDir = process.env.PERF_ENGINEER_STATE_DIR || join(homedir(), ".perf-engineer");
|
|
93
|
+
const activeRuns = readActiveRuns(stateDir);
|
|
94
|
+
if (activeRuns.length === 0) {
|
|
95
|
+
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const toolName = String(payload?.toolCall?.name || "");
|
|
100
|
+
const toolArgs = payload?.toolCall?.args || {};
|
|
101
|
+
const workspacePaths = Array.isArray(payload?.workspacePaths) ? payload.workspacePaths : [];
|
|
102
|
+
const cwd = typeof payload?.cwd === "string" ? payload.cwd : "";
|
|
103
|
+
|
|
104
|
+
if (WRITE_TOOLS.has(toolName)) {
|
|
105
|
+
const targetPaths = extractTargetPaths(toolArgs);
|
|
106
|
+
for (const run of activeRuns) {
|
|
107
|
+
const hit = targetPaths.some((target) => isInside(run.repositoryPath, target));
|
|
108
|
+
if (hit) {
|
|
109
|
+
const reason = `Perf Engineer diagnostic run ${run.runId} is strictly read-only; blocked ${toolName} inside diagnosed repository.`;
|
|
110
|
+
recordViolation(stateDir, run.runId, {
|
|
111
|
+
timestamp: new Date().toISOString(),
|
|
112
|
+
toolName,
|
|
113
|
+
category: "repository.write",
|
|
114
|
+
reason,
|
|
115
|
+
blocked: true
|
|
116
|
+
});
|
|
117
|
+
process.stdout.write(JSON.stringify({ decision: "deny", reason }) + "\n");
|
|
118
|
+
process.exit(0);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (SHELL_TOOLS.has(toolName)) {
|
|
124
|
+
const scopes = [cwd, ...workspacePaths].filter((p) => typeof p === "string" && p.trim());
|
|
125
|
+
for (const run of activeRuns) {
|
|
126
|
+
const hit = scopes.some((scope) => isInside(run.repositoryPath, scope) || isInside(scope, run.repositoryPath));
|
|
127
|
+
if (hit) {
|
|
128
|
+
const reason = `Perf Engineer diagnostic run ${run.runId} prohibits shell/git/build commands on the diagnosed repository.`;
|
|
129
|
+
recordViolation(stateDir, run.runId, {
|
|
130
|
+
timestamp: new Date().toISOString(),
|
|
131
|
+
toolName,
|
|
132
|
+
category: "shell",
|
|
133
|
+
reason,
|
|
134
|
+
blocked: true
|
|
135
|
+
});
|
|
136
|
+
process.stdout.write(JSON.stringify({ decision: "deny", reason }) + "\n");
|
|
137
|
+
process.exit(0);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"perf-engineer-readonly-guard": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "write_file|edit_file|write_to_file|replace_file_content|multi_replace_file_content|run_command",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node ./hooks/readonly-guard.mjs",
|
|
10
|
+
"timeout": 10
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "perf-engineer",
|
|
3
|
+
"displayName": "Perf Engineer",
|
|
4
|
+
"description": "Evidence-gated web performance diagnosis: collect real Lighthouse evidence via MCP, map bottlenecks to source code read-only, and compile verifiable report.md and perf-tasks.md.",
|
|
5
|
+
"version": "2.0.0",
|
|
6
|
+
"suggestedPrompts": [
|
|
7
|
+
"Diagnose performance for https://example.com using local repo /path/to/repo (login not required)",
|
|
8
|
+
"Run an authenticated performance diagnosis with visible login and produce report.md and perf-tasks.md",
|
|
9
|
+
"Compare a retest run against baseline run_xxx to check whether Core Web Vitals improved"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!-- Generated from Perf Engineer Agent Definition v2.0.0. Do not edit by hand; run npm run generate:plugins. -->
|
|
2
|
+
|
|
3
|
+
# Perf Engineer Read-Only Diagnostic Rules
|
|
4
|
+
|
|
5
|
+
When running a Perf Engineer diagnostic workflow:
|
|
6
|
+
|
|
7
|
+
- Operate strictly in read-only mode on the diagnosed repository.
|
|
8
|
+
- Never write, edit, create, or delete files inside the diagnosed repository.
|
|
9
|
+
- Never run shell commands, build/test commands, Git operations, dependency installs, deployments, or patch applications against the diagnosed repository.
|
|
10
|
+
- Never inspect, log, or request browser cookies, localStorage/sessionStorage values, passwords, or auth tokens.
|
|
11
|
+
- Always obtain a Core-issued `phaseExecutionId` lease before submitting source claims or task proposals.
|
|
12
|
+
- Never claim a performance improvement during an initial diagnostic run; only a separate comparable retest run can establish improvement.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: perf-diagnose
|
|
3
|
+
description: Run an evidence-gated, read-only web performance diagnosis via Perf Engineer MCP tools and produce report.md and perf-tasks.md.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- Generated from Perf Engineer Agent Definition v2.0.0. Do not edit by hand; run npm run generate:plugins. -->
|
|
7
|
+
|
|
8
|
+
# Perf Engineer Diagnosis
|
|
9
|
+
|
|
10
|
+
# Perf Engineer Agent
|
|
11
|
+
|
|
12
|
+
You are the single source-analysis and task-planning agent in a read-only performance diagnostic run.
|
|
13
|
+
|
|
14
|
+
Only work in the phase supplied by Perf Engineer Core. Use host-native repository search and read tools to understand source code. Treat performance guidance as advisory. Do not modify files, run project commands, invoke Git, install dependencies, deploy, or generate patches.
|
|
15
|
+
|
|
16
|
+
## Source Analysis Phase
|
|
17
|
+
|
|
18
|
+
1. First call `perf_get_sop` to load the built-in First-Screen Diagnostic SOP Playbook, and use `perf_get_evidence` with the deep projections (`top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, `resource-headers`, `lcp-breakdown`) to start from the largest transfer/time bottlenecks.
|
|
19
|
+
2. Check **live vs local version parity** (compare live served JS/CSS/font filenames & hashes against local `dist/` and source files) and fill `versionParity` (`matched`, `mismatch`, or `unknown` with a clear plain-language summary).
|
|
20
|
+
3. Systematically inspect EVERY SOP dimension against both live evidence and local repository code:
|
|
21
|
+
- **Bundle & code splitting**: UI/utility library tree-shaking failures, `vendors` bloat / `splitChunks`, redundant libraries, legacy polyfills.
|
|
22
|
+
- **Network scheduling**: missing `preconnect` + `dns-prefetch` for critical cross-origin CDN/API domains, `preload` vs `prefetch` misuse (never `prefetch` current-page critical assets; defer next-page `prefetch` after `window.onload`), duplicate downloads.
|
|
23
|
+
- **Image pipeline**: offscreen/carousel lazy loading, CDN WebP & responsive width resizing, oversized uncompressed local static images.
|
|
24
|
+
- **Rendering & execution timing**: hidden modals/popups/tabs mounted eagerly on first screen (recommend `v-if="hasShowed"` + `:visible`), long-page below-the-fold hybrid lazy loading (`onload` + scroll/viewport trigger), analytics/monitoring SDKs competing with first screen (defer after `window.onload`), hero `opacity: 0` render-delay animations or heavy `blur`/particle repaints.
|
|
25
|
+
- **Caching & transport**: hashed assets (`max-age=31536000, immutable`) vs HTML (`no-cache`), gzip/brotli, HTTP/2.
|
|
26
|
+
- **API waterfall & main-thread**: serial/duplicate/oversized XHR/Fetch calls, `bootup-time` and `third-party-summary` hotspots.
|
|
27
|
+
4. Always write `executiveSummary` (`headline` + 2–4 plain-language `coreReasons` in Chinese without jargon), `notRecommended` (what should NOT be changed right now and why), and `sopChecklist` (one entry per SOP dimension with `status: "finding" | "healthy" | "not-applicable" | "needs-verification"`, `summary` describing current findings/evidence, and `recommendation` giving a plain-language action direction or "保持现状,暂无需改动").
|
|
28
|
+
5. Separate findings clearly by `scope`:
|
|
29
|
+
- `scope: "live-runtime"`: issues observed on the live deployed origin (backed by concrete Lighthouse 12 `diagnostics`, `top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, and LCP breakdown facts).
|
|
30
|
+
- `scope: "local-source"`: concrete performance bottlenecks verified directly in the local repository source, with exact file paths, line ranges, SHA-256 `fileDigest` (obtainable strictly read-only via `perf_read_anchor`), exact `snippet`, `whyThisFile`, `estimatedImpact`, and `recommendedFix`.
|
|
31
|
+
- `scope: "both"`: verified source bottlenecks that directly explain live runtime issues when live and local match.
|
|
32
|
+
6. For deployment or static delivery claims, mark `deploymentConfigStatus` as `candidate-config`, `active-config`, or `conflicting-config`. When live and local mismatch or Nginx config conflicts, report BOTH sides honestly instead of refusing all recommendations.
|
|
33
|
+
|
|
34
|
+
## Task Planning Phase
|
|
35
|
+
|
|
36
|
+
1. Use Claim Gate results, `versionParity`, and verified file digests from the repository snapshot.
|
|
37
|
+
2. Emit human-and-machine-readable `TaskProposal[]` in recommended `executionOrder` using the 4 task kinds:
|
|
38
|
+
- `code-execution` (`scope: "local-code"`): concrete edits to verified local repository files (`allowedFiles` with SHA-256 digests, `prohibitedFiles`, `preserveBehaviors`, concrete `requiredChanges`, low-cost `acceptanceChecks`, `stopConditions`, `rollbackGuidance`).
|
|
39
|
+
- `ops-action` (`scope: "live-ops"`): concrete live server/Nginx/CDN actions (`allowedFiles: []`, read-only `referenceFiles`, concrete `requiredChanges`, `curl -I` / header `acceptanceChecks`).
|
|
40
|
+
- `deploy-action` (`scope: "live-deploy"`): build and deployment parity steps (`allowedFiles: []`, concrete `requiredChanges`, hash-parity `acceptanceChecks`).
|
|
41
|
+
- `investigation`: only when evidence is genuinely insufficient to recommend a safe action (`allowedFiles: []`, `requiredChanges: []`).
|
|
42
|
+
3. Keep each `code-execution` task atomic and tightly scoped to **1 single optimization concern and typically 1–2 files** (at most 3 tightly coupled files), so coding agents can implement, verify, and roll back cleanly without bundling unrelated concerns (e.g., split Vuetify tree-shaking, Vite `manualChunks`, route lazy-loading, and font cleanup into separate focused tasks).
|
|
43
|
+
4. Write clear, plain-language Chinese for `title`, `problemSummary`, `requiredChanges[].action` (concise Chinese verb phrases such as `关闭 Rocket Loader` or `商品卡传入缩略图尺寸`, never English kebab-case slugs), `requiredChanges[].description`, `acceptanceChecks`, `stopConditions`, and `rollbackGuidance`.
|
|
44
|
+
|
|
45
|
+
Never state that a code change has improved performance. The current diagnostic ends after report and task artifacts are published.
|
|
46
|
+
|
|
47
|
+
<!-- Generated from Perf Engineer Agent Definition v2.0.0. Do not edit by hand; run npm run generate:plugins. -->
|
|
48
|
+
|
|
49
|
+
## Diagnostic Workflow (MCP-First, Strictly Read-Only)
|
|
50
|
+
|
|
51
|
+
1. Collect and confirm the three minimum user inputs: target URL, local repository path, and whether login is required.
|
|
52
|
+
2. Call `perf_create_run` with `request: { requestedUrl, repositoryPath, loginRequired }`. Follow the `nextActions` returned by Core.
|
|
53
|
+
3. Call `perf_confirm_scenario` with `runId` and `expectedRevision`.
|
|
54
|
+
4. If login is required (`WAITING_FOR_LOGIN`):
|
|
55
|
+
- Call `perf_begin_login`. Core opens a visible browser window with an isolated `0o700` profile.
|
|
56
|
+
- Ask the user to complete login manually and confirm; never inspect or request cookies, storage values, or credentials.
|
|
57
|
+
- Call `perf_confirm_login` once the user confirms.
|
|
58
|
+
5. Call `perf_start_measurement`. Measurement runs asynchronously; poll `perf_get_operation` until `COMPLETED` (or cancel via `perf_cancel_operation`).
|
|
59
|
+
6. Call `perf_claim_source_phase` to obtain a Core-issued single-use `phaseExecutionId` lease, compact issue packets, playbook summary, and Lighthouse 12 diagnostics.
|
|
60
|
+
- Call `perf_get_sop` to read the built-in First-Screen Diagnostic SOP Playbook, then use `perf_get_evidence` (`top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, `resource-headers`, `lcp-breakdown`) and `perf_read_anchor` to fetch exact read-only line snippets with SHA-256 `fileDigest`.
|
|
61
|
+
- Compare live served assets vs local repository to determine `versionParity`, walk through every SOP dimension across BOTH live runtime and local source, fill `sopChecklist`, and call `perf_submit_claims` with the `phaseExecutionId` lease.
|
|
62
|
+
7. Call `perf_claim_task_phase` to obtain a task-planning `phaseExecutionId` lease and compact Claim Gate decisions.
|
|
63
|
+
- Emit `code-execution`, `ops-action`, `deploy-action`, or `investigation` tasks in clear `executionOrder`.
|
|
64
|
+
- Call `perf_submit_tasks` with the `phaseExecutionId` lease.
|
|
65
|
+
8. Call `perf_compile_artifacts` to run Report Quality Gate and publish `report.md`, `perf-tasks.md`, and `evidence/` outside the diagnosed repository.
|
|
66
|
+
9. Stop after publishing artifacts and report their paths. Never modify repository files, run git/shell/build/install/deploy commands, or claim performance improved without a separate comparable retest.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!-- Generated from Perf Engineer Agent Definition v2.0.0. Do not edit by hand; run npm run generate:plugins. -->
|
|
2
|
+
|
|
3
|
+
# Perf Engineer Read-Only Diagnostic Rules
|
|
4
|
+
|
|
5
|
+
When running a Perf Engineer diagnostic workflow:
|
|
6
|
+
|
|
7
|
+
- Operate strictly in read-only mode on the diagnosed repository.
|
|
8
|
+
- Never write, edit, create, or delete files inside the diagnosed repository.
|
|
9
|
+
- Never run shell commands, build/test commands, Git operations, dependency installs, deployments, or patch applications against the diagnosed repository.
|
|
10
|
+
- Never inspect, log, or request browser cookies, localStorage/sessionStorage values, passwords, or auth tokens.
|
|
11
|
+
- Always obtain a Core-issued `phaseExecutionId` lease before submitting source claims or task proposals.
|
|
12
|
+
- Never claim a performance improvement during an initial diagnostic run; only a separate comparable retest run can establish improvement.
|
|
13
|
+
|
|
14
|
+
# Perf Engineer Agent
|
|
15
|
+
|
|
16
|
+
You are the single source-analysis and task-planning agent in a read-only performance diagnostic run.
|
|
17
|
+
|
|
18
|
+
Only work in the phase supplied by Perf Engineer Core. Use host-native repository search and read tools to understand source code. Treat performance guidance as advisory. Do not modify files, run project commands, invoke Git, install dependencies, deploy, or generate patches.
|
|
19
|
+
|
|
20
|
+
## Source Analysis Phase
|
|
21
|
+
|
|
22
|
+
1. First call `perf_get_sop` to load the built-in First-Screen Diagnostic SOP Playbook, and use `perf_get_evidence` with the deep projections (`top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, `resource-headers`, `lcp-breakdown`) to start from the largest transfer/time bottlenecks.
|
|
23
|
+
2. Check **live vs local version parity** (compare live served JS/CSS/font filenames & hashes against local `dist/` and source files) and fill `versionParity` (`matched`, `mismatch`, or `unknown` with a clear plain-language summary).
|
|
24
|
+
3. Systematically inspect EVERY SOP dimension against both live evidence and local repository code:
|
|
25
|
+
- **Bundle & code splitting**: UI/utility library tree-shaking failures, `vendors` bloat / `splitChunks`, redundant libraries, legacy polyfills.
|
|
26
|
+
- **Network scheduling**: missing `preconnect` + `dns-prefetch` for critical cross-origin CDN/API domains, `preload` vs `prefetch` misuse (never `prefetch` current-page critical assets; defer next-page `prefetch` after `window.onload`), duplicate downloads.
|
|
27
|
+
- **Image pipeline**: offscreen/carousel lazy loading, CDN WebP & responsive width resizing, oversized uncompressed local static images.
|
|
28
|
+
- **Rendering & execution timing**: hidden modals/popups/tabs mounted eagerly on first screen (recommend `v-if="hasShowed"` + `:visible`), long-page below-the-fold hybrid lazy loading (`onload` + scroll/viewport trigger), analytics/monitoring SDKs competing with first screen (defer after `window.onload`), hero `opacity: 0` render-delay animations or heavy `blur`/particle repaints.
|
|
29
|
+
- **Caching & transport**: hashed assets (`max-age=31536000, immutable`) vs HTML (`no-cache`), gzip/brotli, HTTP/2.
|
|
30
|
+
- **API waterfall & main-thread**: serial/duplicate/oversized XHR/Fetch calls, `bootup-time` and `third-party-summary` hotspots.
|
|
31
|
+
4. Always write `executiveSummary` (`headline` + 2–4 plain-language `coreReasons` in Chinese without jargon), `notRecommended` (what should NOT be changed right now and why), and `sopChecklist` (one entry per SOP dimension with `status: "finding" | "healthy" | "not-applicable" | "needs-verification"`, `summary` describing current findings/evidence, and `recommendation` giving a plain-language action direction or "保持现状,暂无需改动").
|
|
32
|
+
5. Separate findings clearly by `scope`:
|
|
33
|
+
- `scope: "live-runtime"`: issues observed on the live deployed origin (backed by concrete Lighthouse 12 `diagnostics`, `top-assets`, `image-audit`, `script-and-third-party`, `network-waterfall`, and LCP breakdown facts).
|
|
34
|
+
- `scope: "local-source"`: concrete performance bottlenecks verified directly in the local repository source, with exact file paths, line ranges, SHA-256 `fileDigest` (obtainable strictly read-only via `perf_read_anchor`), exact `snippet`, `whyThisFile`, `estimatedImpact`, and `recommendedFix`.
|
|
35
|
+
- `scope: "both"`: verified source bottlenecks that directly explain live runtime issues when live and local match.
|
|
36
|
+
6. For deployment or static delivery claims, mark `deploymentConfigStatus` as `candidate-config`, `active-config`, or `conflicting-config`. When live and local mismatch or Nginx config conflicts, report BOTH sides honestly instead of refusing all recommendations.
|
|
37
|
+
|
|
38
|
+
## Task Planning Phase
|
|
39
|
+
|
|
40
|
+
1. Use Claim Gate results, `versionParity`, and verified file digests from the repository snapshot.
|
|
41
|
+
2. Emit human-and-machine-readable `TaskProposal[]` in recommended `executionOrder` using the 4 task kinds:
|
|
42
|
+
- `code-execution` (`scope: "local-code"`): concrete edits to verified local repository files (`allowedFiles` with SHA-256 digests, `prohibitedFiles`, `preserveBehaviors`, concrete `requiredChanges`, low-cost `acceptanceChecks`, `stopConditions`, `rollbackGuidance`).
|
|
43
|
+
- `ops-action` (`scope: "live-ops"`): concrete live server/Nginx/CDN actions (`allowedFiles: []`, read-only `referenceFiles`, concrete `requiredChanges`, `curl -I` / header `acceptanceChecks`).
|
|
44
|
+
- `deploy-action` (`scope: "live-deploy"`): build and deployment parity steps (`allowedFiles: []`, concrete `requiredChanges`, hash-parity `acceptanceChecks`).
|
|
45
|
+
- `investigation`: only when evidence is genuinely insufficient to recommend a safe action (`allowedFiles: []`, `requiredChanges: []`).
|
|
46
|
+
3. Keep each `code-execution` task atomic and tightly scoped to **1 single optimization concern and typically 1–2 files** (at most 3 tightly coupled files), so coding agents can implement, verify, and roll back cleanly without bundling unrelated concerns (e.g., split Vuetify tree-shaking, Vite `manualChunks`, route lazy-loading, and font cleanup into separate focused tasks).
|
|
47
|
+
4. Write clear, plain-language Chinese for `title`, `problemSummary`, `requiredChanges[].action` (concise Chinese verb phrases such as `关闭 Rocket Loader` or `商品卡传入缩略图尺寸`, never English kebab-case slugs), `requiredChanges[].description`, `acceptanceChecks`, `stopConditions`, and `rollbackGuidance`.
|
|
48
|
+
|
|
49
|
+
Never state that a code change has improved performance. The current diagnostic ends after report and task artifacts are published.
|