@perf-engineer/web 0.1.1 → 0.2.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 (3) hide show
  1. package/README.md +53 -147
  2. package/dist/cli.js +180 -65
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -5,112 +5,37 @@
5
5
  [![npm version](https://img.shields.io/npm/v/@perf-engineer/web)](https://www.npmjs.com/package/@perf-engineer/web)
6
6
  [![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)
7
7
  [![Node.js](https://img.shields.io/badge/node-%3E%3D22.13.0-brightgreen)](#requirements)
8
- [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
9
8
 
10
- A read-only MCP server for diagnosing initial page-load performance in AI coding clients such as Antigravity, Cursor, Claude Code, Codex, and VS Code. It combines repeated measurements from real Chrome and Lighthouse 12 with source-code analysis to produce a diagnostic report (`report.md`) and an optimization task list (`perf-tasks.md`) for developers or AI assistants to work through.
11
-
12
- ## Features
13
-
14
- - Repeated Chrome and Lighthouse 12 measurements, using median values to identify resource, image, script, and API bottlenecks that affect initial loading
15
- - Read-only diagnostic tools that do not modify application source code or run builds, dependency installation, or Git commands
16
- - Checks linking deployed artifacts to local source code, with separate tasks for production operations, deployment, and local code changes when versions differ
17
- - A built-in diagnostic guide covering six areas of initial page-load performance, with support for team-specific guidance
18
- - Retests using the same device, network, and login conditions after changes are deployed, with before-and-after metric comparisons
9
+ Perf Engineer is a read-only MCP server for investigating slow initial page loads. It runs Lighthouse 12 in local Chrome and gives your coding assistant the measurements to check against the source. A completed diagnosis produces a report and a list of proposed fixes.
19
10
 
20
11
  ## Requirements
21
12
 
22
- - [Node.js](https://nodejs.org/) `>= 22.13.0`
23
- - Chrome or Chromium installed locally
13
+ Install [Node.js](https://nodejs.org/) 22.13.0 or later and Chrome or Chromium. Pages that require login also need a graphical desktop.
24
14
 
25
15
  ## Quick start
26
16
 
27
- Add the following configuration to an MCP-compatible client. You do not need to clone the repository:
28
-
29
- ```json
30
- {
31
- "mcpServers": {
32
- "perf-engineer": {
33
- "command": "npx",
34
- "args": ["-y", "@perf-engineer/web"]
35
- }
36
- }
37
- }
38
- ```
39
-
40
- You can also use the built-in installers to add client configuration and, where supported, read-only rules:
41
-
42
- <details>
43
- <summary>Antigravity (includes a hook to prevent accidental writes)</summary>
44
-
45
- ```bash
46
- npx -y @perf-engineer/web install antigravity
47
- ```
17
+ Register `@perf-engineer/web` once in your AI coding client. No files need to be added to the repository you are diagnosing, and the MCP server sends read-only diagnostic instructions automatically on connect.
48
18
 
49
- The installer writes the plugin to `~/.gemini/config/plugins/perf-engineer`. Restart or reload the Antigravity plugin to apply it.
19
+ ### Native client setup (recommended)
50
20
 
51
- </details>
21
+ **Codex**
52
22
 
53
- <details>
54
- <summary>Cursor</summary>
55
-
56
- Run this command from the root of the project you want to diagnose:
57
-
58
- ```bash
59
- npx -y @perf-engineer/web install cursor
23
+ ```sh
24
+ codex mcp add perf-engineer -- npx -y @perf-engineer/web
60
25
  ```
61
26
 
62
- The installer merges the MCP configuration into `.cursor/mcp.json`, preserving existing settings, and writes `.cursor/rules/perf-engineer.mdc`. Add `--global` to install the MCP configuration in `~/.cursor/mcp.json`.
63
-
64
- </details>
27
+ **Claude Code**
65
28
 
66
- <details>
67
- <summary>Claude Code</summary>
68
-
69
- Use the Claude CLI to add the MCP server:
70
-
71
- ```bash
72
- claude mcp add perf-engineer -- npx -y @perf-engineer/web
29
+ ```sh
30
+ claude mcp add -s user perf-engineer -- npx -y @perf-engineer/web
73
31
  ```
74
32
 
75
- Alternatively, run `npx -y @perf-engineer/web install claude-code` from the project root to generate `.mcp.json`.
76
-
77
- </details>
78
-
79
- <details>
80
- <summary>Codex</summary>
81
-
82
- Run this command from the project root:
83
-
84
- ```bash
85
- npx -y @perf-engineer/web install codex
86
- ```
87
-
88
- For a global configuration in `~/.codex/config.toml`, add:
89
-
90
- ```toml
91
- [mcp_servers.perf-engineer]
92
- command = "npx"
93
- args = ["-y", "@perf-engineer/web"]
94
- ```
95
-
96
- </details>
97
-
98
- <details>
99
- <summary>VS Code</summary>
100
-
101
- Run this command from the project root:
102
-
103
- ```bash
104
- npx -y @perf-engineer/web install vscode
105
- ```
106
-
107
- Or configure `.vscode/mcp.json` manually:
33
+ **Cursor, VS Code, and other `mcpServers` JSON clients**
108
34
 
109
35
  ```json
110
36
  {
111
- "servers": {
37
+ "mcpServers": {
112
38
  "perf-engineer": {
113
- "type": "stdio",
114
39
  "command": "npx",
115
40
  "args": ["-y", "@perf-engineer/web"]
116
41
  }
@@ -118,94 +43,75 @@ Or configure `.vscode/mcp.json` manually:
118
43
  }
119
44
  ```
120
45
 
121
- </details>
46
+ ### One-command global installer (includes Skill / Antigravity Hook)
122
47
 
123
- ## Usage
48
+ To also install the built-in `perf-diagnose` skill (Codex / Claude Code) or the Antigravity `PreToolUse` read-only hook, run the installer from anywhere. It writes to your user-level client directory by default and does not touch your project repository.
124
49
 
125
- ### Diagnose a public page
126
-
127
- > Use perf-engineer to diagnose `https://shop.example.com/`. The local repository is at `/path/to/storefront`. No login is required.
50
+ ```sh
51
+ npx -y @perf-engineer/web install codex
52
+ ```
128
53
 
129
- ### Diagnose a page that requires login
54
+ | Client | Name | Default user-level install (never modifies your repo) |
55
+ | --- | --- | --- |
56
+ | Antigravity | `antigravity` | Installs the full plugin in `~/.gemini/config/plugins/perf-engineer` with a `PreToolUse` hook that blocks repository writes and repo-scoped shell calls during an active run. Reload the plugin after installing. |
57
+ | Codex | `codex` | Merges `[mcp_servers.perf-engineer]` into `~/.codex/config.toml` and installs the skill at `~/.agents/skills/perf-diagnose/SKILL.md`. |
58
+ | Claude Code | `claude-code` | Merges the server into `~/.claude.json` and installs the skill at `~/.claude/skills/perf-diagnose/SKILL.md`. |
59
+ | Cursor | `cursor` | Merges the server into `~/.cursor/mcp.json`. |
60
+ | VS Code | `vscode` | Merges the server into your user-level VS Code `mcp.json` (e.g. `~/Library/Application Support/Code/User/mcp.json` on macOS). |
130
61
 
131
- > Use perf-engineer to diagnose `https://app.example.com/dashboard`. The local repository is at `/path/to/app`. Login is required.
62
+ Use `--dry-run` to preview changes. To intentionally share config inside a repository, pass `--project` (optionally with `--dir <path>`).
132
63
 
133
- At the login step, Perf Engineer opens an isolated Chrome window for you to sign in manually, including QR codes, verification codes, or two-factor authentication. Once you are signed in, ask the AI assistant to continue measuring. The diagnostic tools do not read or record passwords, cookies, local storage, or tokens.
64
+ ## Usage
134
65
 
135
- ### Work through the task list
66
+ Give your coding assistant the URL, local repository path and whether the page needs a login.
136
67
 
137
- When diagnosis finishes, Perf Engineer returns the path to `perf-tasks.md`. You can work through the tasks in priority order or pass the file to an AI assistant:
68
+ > Use perf-engineer to diagnose `https://shop.example.com/`. The code is in `/path/to/storefront`. The page is public.
138
69
 
139
- > Complete the optimizations in this `perf-tasks.md` one at a time. Run each task's acceptance checks after completing it.
70
+ Use a trusted HTTP or HTTPS URL. The target check rejects `localhost` and common private IP addresses. If the page needs a login, sign in when Perf Engineer opens Chrome with a temporary browser profile, then tell the assistant to continue.
140
71
 
141
- ### Retest after deployment
72
+ The default is a desktop viewport with simulated 4G and a cold cache. Perf Engineer aims for three successful Lighthouse samples in up to five attempts. It reports medians from the available samples and needs at least three to assess stability.
142
73
 
143
- After deploying the changes, repeat the measurements under the same conditions and compare the results:
74
+ The assistant checks whether the deployed assets match the local checkout. The report records the result, including when there is too little evidence to tell. Perf Engineer verifies that cited files are inside the repository and checks their hashes and quoted lines before accepting source findings.
144
75
 
145
- > Use perf-engineer to retest `https://shop.example.com/` and compare it with the previous diagnosis.
76
+ Review the report and use the task list for proposed changes and their acceptance checks. After deployment, ask the assistant to retest using the baseline run ID. Perf Engineer reuses the baseline settings and compares the medians from the two runs.
146
77
 
147
78
  ## Output files
148
79
 
149
- Each run writes its results to `~/.perf-engineer/data/runs/<run-id>/`:
80
+ A completed diagnosis publishes its files to `~/.perf-engineer/data/runs/<run-id>/` by default. To change the data directory, set `PERF_ENGINEER_DATA_DIR` to a path outside the repository you are diagnosing.
150
81
 
151
82
  ```text
152
83
  ~/.perf-engineer/data/runs/<run-id>/
153
- ├── report.md # Findings, measurements, production/local issues, and analysis coverage
154
- ├── perf-tasks.md # Change scope, implementation steps, acceptance checks, and rollback guidance
155
- ├── manifest.json # Run metadata
156
- └── evidence/ # Initial viewport screenshot, network requests, and Lighthouse diagnostics
84
+ ├── report.md
85
+ ├── perf-tasks.md
86
+ ├── manifest.json
87
+ └── evidence/
88
+ ├── measurement-summary.json
89
+ ├── network.json
90
+ ├── diagnostics.json
91
+ └── screenshot.png # If Lighthouse captures one
157
92
  ```
158
93
 
159
- The following results come from a real storefront homepage diagnosis, with identifying details removed. The full report and task list are available in `examples/`:
160
-
161
- | Metric | Measured median | Reference threshold | Status |
162
- | --- | ---: | ---: | --- |
163
- | Performance score | 42 | ≥ 85 | ❌ Low |
164
- | First Contentful Paint (FCP) | 1.5 s | ≤ 1.8 s | ✅ Within threshold |
165
- | Largest Contentful Paint (LCP) | 12.2 s | ≤ 2.5 s | ❌ Slow |
166
- | Speed Index | 9.8 s | ≤ 3.4 s | ❌ Very slow |
167
- | Total Blocking Time (TBT) | 429 ms | ≤ 200 ms | ⚠️ High |
168
- | Cumulative Layout Shift (CLS) | 0.01 | ≤ 0.10 | ✅ Within threshold |
169
-
170
- - [Full diagnostic report example (Chinese)](examples/storefront-report.md)
171
- - [Full optimization task list example (Chinese)](examples/storefront-tasks.md)
94
+ The storefront example had a median LCP of 12.2 seconds over three desktop measurements. The [example report](examples/storefront-report.md) and [task list](examples/storefront-tasks.md) are in Chinese.
172
95
 
173
- ## Diagnostic coverage and customization
96
+ ## Read-only access
174
97
 
175
- The built-in guide covers six areas of initial page-load performance and does not require an external skill library:
98
+ The MCP tools read the target repository and publish reports outside it. Run builds, dependency installs, Git commands and deployments outside the diagnosis. The Cursor and Codex rules guide the assistant. The report records the protection level based on the client's configured capabilities.
176
99
 
177
- | Area | What the guide covers |
178
- | --- | --- |
179
- | Bundle size and code splitting | On-demand UI and utility imports, moving heavy dependencies out of the initial bundle, duplicate libraries, and legacy polyfills |
180
- | Network resource scheduling | Critical cross-origin `preconnect` and `dns-prefetch`, incorrect `preload` or `prefetch` usage, and duplicate downloads |
181
- | Images | CDN resizing and WebP/AVIF conversion, `loading="lazy"` for below-the-fold images and inactive carousel slides, and compression of large local images |
182
- | Rendering and execution timing | Eagerly mounted hidden dialogs, lazy loading lower sections of long pages, deferred analytics and payment SDKs, and animations that delay initial content visibility |
183
- | Caching and delivery | Long-lived caching for hashed assets, cache revalidation for entry HTML, `br`/`gzip`/`zstd` compression, and HTTP/2 |
184
- | API waterfalls and main-thread work | Duplicate startup requests, sequential API chains, request fan-out, and excessive DOM size |
185
-
186
- To add team-specific guidance, edit [the initial page-load diagnostic guide](packages/guidance/playbooks/first-screen-sop.md) and rebuild the package.
187
-
188
- ## Security and scope
189
-
190
- - Diagnostic tools do not modify files in the target repository or run build, installation, or Git commands against it.
191
- - They do not read, record, or request browser cookies, `localStorage`/`sessionStorage`, passwords, or tokens.
192
- - An initial read-only diagnosis does not claim that performance has improved. Before-and-after comparisons require a subsequent retest under the same conditions after changes are deployed.
100
+ Chrome manages the login session in its temporary profile. The server masks known sensitive headers and query parameters in the network evidence. Screenshots can include account data shown on the page. See the [security policy](SECURITY.md) for details.
193
101
 
194
102
  ## Local development
195
103
 
196
- ```bash
197
- git clone https://github.com/perf-engineer/perf-engineer.git
198
- cd perf-engineer
199
- npm install
104
+ Run these commands from a checkout of this repository.
105
+
106
+ ```sh
107
+ npm ci
200
108
  npm run build
201
- npm run build:web
202
109
  npm run check
110
+ npm run check:plugins
111
+ npm run build:web
203
112
  npm test
204
113
  ```
205
114
 
206
- ## Documentation and license
115
+ `check:plugins` checks the generated client bundles against their sources. `build:web` builds the npm package in `packages/web`. To change the built-in checks for JavaScript, images, caching or other page-load issues, edit the [diagnostic playbook](packages/guidance/playbooks/first-screen-sop.md) and rerun `npm run build:web`.
207
116
 
208
- - [Architecture (Chinese)](docs/ARCHITECTURE.md)
209
- - [Contributing](CONTRIBUTING.md)
210
- - [Security policy](SECURITY.md)
211
- - Released under the [MIT License](LICENSE)
117
+ [Architecture (Chinese)](docs/ARCHITECTURE.md) · [Contributing](CONTRIBUTING.md) · [MIT license](LICENSE)
package/dist/cli.js CHANGED
@@ -3736,11 +3736,27 @@ var MCP_TOOLS = [
3736
3736
  var MCP_TOOL_BY_NAME = new Map(MCP_TOOLS.map((tool) => [tool.name, tool]));
3737
3737
 
3738
3738
  // ../mcp-server/src/server.ts
3739
+ var PERF_ENGINEER_MCP_INSTRUCTIONS = [
3740
+ "Perf Engineer is a strictly read-only web performance diagnostic MCP server.",
3741
+ "Read-only rules during any diagnostic run:",
3742
+ "- Never write, edit, create, or delete files inside the diagnosed repository.",
3743
+ "- Never run shell, build, test, dependency-install, Git, deployment, or patch commands against the diagnosed repository.",
3744
+ "- Never inspect, log, or request browser cookies, localStorage/sessionStorage values, passwords, or auth tokens.",
3745
+ "- Never claim performance improved during an initial diagnosis; only a separate comparable retest can establish improvement.",
3746
+ "Diagnostic workflow:",
3747
+ "1. Collect target URL, local repository path, and whether login is required.",
3748
+ "2. Call perf_create_run -> perf_confirm_scenario -> (if login required: perf_begin_login -> perf_confirm_login) -> perf_start_measurement -> poll perf_get_operation.",
3749
+ "3. Call perf_claim_source_phase, then perf_get_sop, perf_get_evidence, and perf_read_anchor before calling perf_submit_claims.",
3750
+ "4. Call perf_claim_task_phase -> perf_submit_tasks -> perf_compile_artifacts, then stop and report the published artifact paths."
3751
+ ].join("\n");
3739
3752
  function createPerfEngineerMcpServer(options) {
3740
3753
  const maxResponseBytes = options.maxResponseBytes ?? DEFAULT_MAX_MCP_RESPONSE_BYTES;
3741
3754
  const server = new Server(
3742
3755
  { name: "perf-engineer", version: PROTOCOL_VERSION },
3743
- { capabilities: { tools: {} } }
3756
+ {
3757
+ capabilities: { tools: {} },
3758
+ instructions: PERF_ENGINEER_MCP_INSTRUCTIONS
3759
+ }
3744
3760
  );
3745
3761
  const operationProgressTokens = /* @__PURE__ */ new Map();
3746
3762
  const getClientInfo = () => {
@@ -6066,14 +6082,22 @@ import { homedir } from "node:os";
6066
6082
  import { dirname as dirname4, join as join10, resolve as resolve9 } from "node:path";
6067
6083
  import { fileURLToPath as fileURLToPath2 } from "node:url";
6068
6084
  var SUPPORTED_CLIENTS = ["antigravity", "cursor", "codex", "vscode", "claude-code"];
6069
- var CODEX_RULES_START = "<!-- perf-engineer-readonly-rules:start -->";
6070
- var CODEX_RULES_END = "<!-- perf-engineer-readonly-rules:end -->";
6071
6085
  function isSupportedClient(value) {
6072
6086
  return SUPPORTED_CLIENTS.includes(value);
6073
6087
  }
6074
6088
  function resolveDefaultTemplatesRoot() {
6075
6089
  return resolve9(dirname4(fileURLToPath2(import.meta.url)), "../templates");
6076
6090
  }
6091
+ function resolveVscodeUserDir(home, platform, appDataDir) {
6092
+ if (platform === "darwin") {
6093
+ return join10(home, "Library", "Application Support", "Code", "User");
6094
+ }
6095
+ if (platform === "win32") {
6096
+ return join10(appDataDir ?? process.env.APPDATA ?? join10(home, "AppData", "Roaming"), "Code", "User");
6097
+ }
6098
+ const xdgConfigHome = process.env.XDG_CONFIG_HOME;
6099
+ return join10(xdgConfigHome ? xdgConfigHome : join10(home, ".config"), "Code", "User");
6100
+ }
6077
6101
  async function ensureTextWrite(filePath, content, dryRun) {
6078
6102
  if (dryRun) return;
6079
6103
  await mkdir8(dirname4(filePath), { recursive: true });
@@ -6110,28 +6134,117 @@ function mergeNamedRecord(root, containerKey, entryKey, entryValue) {
6110
6134
  [containerKey]: container
6111
6135
  };
6112
6136
  }
6113
- function upsertMarkedSection(existingContent, markedBlock) {
6114
- const startIdx = existingContent.indexOf(CODEX_RULES_START);
6115
- const endIdx = existingContent.indexOf(CODEX_RULES_END);
6116
- if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
6117
- const before = existingContent.slice(0, startIdx).trimEnd();
6118
- const after = existingContent.slice(endIdx + CODEX_RULES_END.length).trimStart();
6119
- return [before, markedBlock, after].filter(Boolean).join("\n\n") + "\n";
6137
+ function normalizeTomlTableKey(headerContent) {
6138
+ const segments = [];
6139
+ let current = "";
6140
+ let inQuote = null;
6141
+ for (let i = 0; i < headerContent.length; i += 1) {
6142
+ const ch = headerContent[i];
6143
+ if (inQuote) {
6144
+ if (ch === "\\" && inQuote === '"' && i + 1 < headerContent.length) {
6145
+ current += headerContent[i + 1];
6146
+ i += 1;
6147
+ } else if (ch === inQuote) {
6148
+ inQuote = null;
6149
+ } else {
6150
+ current += ch;
6151
+ }
6152
+ } else if (ch === '"' || ch === "'") {
6153
+ inQuote = ch;
6154
+ } else if (ch === ".") {
6155
+ segments.push(current.trim());
6156
+ current = "";
6157
+ } else {
6158
+ current += ch;
6159
+ }
6160
+ }
6161
+ segments.push(current.trim());
6162
+ return segments.join(".");
6163
+ }
6164
+ function upsertCodexTomlServer(existingContent, serverBlock) {
6165
+ const normalizedBlock = serverBlock.trim();
6166
+ const trimmedExisting = existingContent.trim();
6167
+ if (!trimmedExisting) {
6168
+ return `${normalizedBlock}
6169
+ `;
6170
+ }
6171
+ const lines = existingContent.replace(/\r\n/g, "\n").split("\n");
6172
+ const keptLines = [];
6173
+ let skippingPerfEngineerSection = false;
6174
+ let insertionIndex = null;
6175
+ for (const line of lines) {
6176
+ if (/^\s*\[\[/.test(line)) {
6177
+ skippingPerfEngineerSection = false;
6178
+ keptLines.push(line);
6179
+ continue;
6180
+ }
6181
+ const tableMatch = line.match(/^\s*\[([^\[\]]+)\]\s*(?:#.*)?$/);
6182
+ if (tableMatch) {
6183
+ const normalized = normalizeTomlTableKey(tableMatch[1].trim());
6184
+ const isPerfEngineerTable = normalized === "mcp_servers.perf-engineer" || normalized.startsWith("mcp_servers.perf-engineer.");
6185
+ if (isPerfEngineerTable) {
6186
+ if (insertionIndex === null) {
6187
+ insertionIndex = keptLines.length;
6188
+ }
6189
+ skippingPerfEngineerSection = true;
6190
+ continue;
6191
+ }
6192
+ skippingPerfEngineerSection = false;
6193
+ }
6194
+ if (!skippingPerfEngineerSection) {
6195
+ keptLines.push(line);
6196
+ }
6120
6197
  }
6121
- const trimmed = existingContent.trimEnd();
6122
- return trimmed ? `${trimmed}
6198
+ if (insertionIndex !== null) {
6199
+ const before2 = keptLines.slice(0, insertionIndex).join("\n").trimEnd();
6200
+ const after = keptLines.slice(insertionIndex).join("\n").trim();
6201
+ return [before2, normalizedBlock, after].filter(Boolean).join("\n\n") + "\n";
6202
+ }
6203
+ const before = keptLines.join("\n").trimEnd();
6204
+ return before ? `${before}
6123
6205
 
6124
- ${markedBlock}
6125
- ` : `${markedBlock}
6206
+ ${normalizedBlock}
6207
+ ` : `${normalizedBlock}
6126
6208
  `;
6127
6209
  }
6210
+ function buildCodexServerTomlBlock(capabilitiesJson) {
6211
+ return [
6212
+ "[mcp_servers.perf-engineer]",
6213
+ 'command = "npx"',
6214
+ 'args = ["-y", "@perf-engineer/web"]',
6215
+ "",
6216
+ "[mcp_servers.perf-engineer.env]",
6217
+ `PERF_ENGINEER_HOST_CAPABILITIES = '${capabilitiesJson}'`
6218
+ ].join("\n");
6219
+ }
6220
+ function resolveInstallScope(client, options) {
6221
+ if (options.project && options.global) {
6222
+ throw new Error("--project \u4E0E --global \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\u3002");
6223
+ }
6224
+ if (client === "antigravity") {
6225
+ if (options.project) {
6226
+ throw new Error("Antigravity \u63D2\u4EF6\u4EC5\u652F\u6301\u7528\u6237\u5168\u5C40\u76EE\u5F55\uFF08\u6216\u901A\u8FC7 --dir \u6307\u5B9A\u63D2\u4EF6\u76EE\u5F55\uFF09\uFF0C\u4E0D\u652F\u6301 --project\u3002");
6227
+ }
6228
+ return "global";
6229
+ }
6230
+ if (options.project) {
6231
+ return "project";
6232
+ }
6233
+ if (options.targetDir && !options.global) {
6234
+ return "project";
6235
+ }
6236
+ return "global";
6237
+ }
6128
6238
  async function installForClient(client, options = {}) {
6129
6239
  const templatesRoot = options.templatesRoot ?? resolveDefaultTemplatesRoot();
6130
6240
  const dryRun = Boolean(options.dryRun);
6241
+ const home = options.homeDir ?? homedir();
6242
+ const platform = options.platform ?? process.platform;
6243
+ const scope = resolveInstallScope(client, options);
6131
6244
  const writtenFiles = [];
6132
6245
  if (client === "antigravity") {
6133
6246
  const srcDir = join10(templatesRoot, "antigravity");
6134
- const targetRoot = options.targetDir ?? join10(homedir(), ".gemini", "config", "plugins", "perf-engineer");
6247
+ const targetRoot = options.targetDir ?? join10(home, ".gemini", "config", "plugins", "perf-engineer");
6135
6248
  if (!existsSync5(srcDir)) {
6136
6249
  throw new Error(`\u672A\u627E\u5230\u5185\u7F6E\u63D2\u4EF6\u6A21\u677F\u76EE\u5F55\uFF1A${srcDir}\uFF0C\u8BF7\u5148\u8FD0\u884C npm run build:web\u3002`);
6137
6250
  }
@@ -6156,19 +6269,21 @@ async function installForClient(client, options = {}) {
6156
6269
  writtenFiles.push(...expectedFiles);
6157
6270
  return {
6158
6271
  client,
6272
+ scope,
6159
6273
  targetRoot,
6160
6274
  writtenFiles,
6161
6275
  dryRun,
6162
6276
  nextSteps: [
6163
- "1. \u91CD\u542F\u6216\u91CD\u8F7D Antigravity \u63D2\u4EF6\uFF0C\u5373\u53EF\u542F\u7528 perf-engineer \u5B50\u4EE3\u7406\u4E0E /perf-diagnose \u6280\u80FD\u3002",
6277
+ "1. \u91CD\u542F\u6216\u91CD\u8F7D Antigravity \u63D2\u4EF6\uFF0C\u5373\u53EF\u542F\u7528 perf-engineer \u5B50\u4EE3\u7406\u3001PreToolUse \u53EA\u8BFB\u94A9\u5B50\u4E0E /perf-diagnose \u6280\u80FD\u3002",
6164
6278
  "2. \u76F4\u63A5\u5728\u5BF9\u8BDD\u91CC\u53D1\u4E00\u53E5\u8BDD\u5F00\u59CB\u8BCA\u65AD\uFF0C\u4F8B\u5982\uFF1A\u7528 perf-engineer \u8BCA\u65AD https://example.com \uFF0C\u672C\u5730\u4ED3\u5E93 /path/to/repo\u3002"
6165
6279
  ]
6166
6280
  };
6167
6281
  }
6168
6282
  if (client === "cursor") {
6169
- const baseDir2 = options.global ? join10(homedir(), ".cursor") : options.targetDir ?? process.cwd();
6170
- const mcpPath2 = options.global ? join10(baseDir2, "mcp.json") : join10(baseDir2, ".cursor", "mcp.json");
6171
- const cursorCaps = JSON.stringify({ hostName: "cursor", preToolUseHook: false, readOnlyRules: true });
6283
+ const isProject2 = scope === "project";
6284
+ const baseDir2 = isProject2 ? options.targetDir ?? process.cwd() : join10(home, ".cursor");
6285
+ const mcpPath2 = isProject2 ? join10(baseDir2, ".cursor", "mcp.json") : join10(baseDir2, "mcp.json");
6286
+ const cursorCaps = JSON.stringify({ hostName: "cursor", preToolUseHook: false, readOnlyRules: isProject2 });
6172
6287
  await mergeJsonConfig(
6173
6288
  mcpPath2,
6174
6289
  (current) => mergeNamedRecord(current, "mcpServers", "perf-engineer", {
@@ -6179,7 +6294,7 @@ async function installForClient(client, options = {}) {
6179
6294
  dryRun
6180
6295
  );
6181
6296
  writtenFiles.push(mcpPath2);
6182
- if (!options.global) {
6297
+ if (isProject2) {
6183
6298
  const ruleSrc = join10(templatesRoot, "cursor", ".cursor", "rules", "perf-engineer.mdc");
6184
6299
  const ruleDst = join10(baseDir2, ".cursor", "rules", "perf-engineer.mdc");
6185
6300
  const ruleContent = await readFile6(ruleSrc, "utf8");
@@ -6188,59 +6303,45 @@ async function installForClient(client, options = {}) {
6188
6303
  }
6189
6304
  return {
6190
6305
  client,
6306
+ scope,
6191
6307
  targetRoot: baseDir2,
6192
6308
  writtenFiles,
6193
6309
  dryRun,
6194
6310
  nextSteps: [
6195
6311
  "1. \u5728 Cursor \u8BBE\u7F6E\u7684 MCP \u9762\u677F\u786E\u8BA4 perf-engineer \u5DF2\u5F00\u542F\uFF08\u5982\u6709\u9700\u8981\u70B9\u4E00\u6B21 Refresh\uFF09\u3002",
6196
- options.global ? "2. \u82E5\u9700\u53EA\u8BFB\u89C4\u5219\u4FDD\u62A4\uFF0C\u53EF\u5728\u9879\u76EE\u6839\u76EE\u5F55\u518D\u8FD0\u884C\u4E00\u6B21\u4E0D\u5E26 --global \u7684\u5B89\u88C5\u547D\u4EE4\u3002" : "2. \u5DF2\u5B89\u5168\u5408\u5165 .cursor/mcp.json \u5E76\u5199\u5165\u53EA\u8BFB\u89C4\u5219 .cursor/rules/perf-engineer.mdc\u3002"
6312
+ isProject2 ? "2. \u5DF2\u5B89\u5168\u5408\u5165\u9879\u76EE\u7EA7 .cursor/mcp.json \u5E76\u5199\u5165\u53EA\u8BFB\u89C4\u5219 .cursor/rules/perf-engineer.mdc\u3002" : "2. \u5DF2\u5B89\u88C5\u5230\u7528\u6237\u5168\u5C40 ~/.cursor/mcp.json\uFF08\u672A\u4FEE\u6539\u5F53\u524D\u4E1A\u52A1\u4ED3\u5E93\uFF09\uFF1BMCP \u670D\u52A1\u672C\u8EAB\u5DF2\u5185\u7F6E\u53EA\u8BFB\u534F\u8BAE\u8BF4\u660E\u3002"
6197
6313
  ]
6198
6314
  };
6199
6315
  }
6200
6316
  if (client === "codex") {
6201
- const baseDir2 = options.targetDir ?? process.cwd();
6202
- const mcpPath2 = join10(baseDir2, "mcp-config.json");
6317
+ const isProject2 = scope === "project";
6318
+ const baseDir2 = isProject2 ? options.targetDir ?? process.cwd() : home;
6319
+ const configPath = isProject2 ? join10(baseDir2, ".codex", "config.toml") : join10(home, ".codex", "config.toml");
6320
+ const skillDst2 = isProject2 ? join10(baseDir2, ".agents", "skills", "perf-diagnose", "SKILL.md") : join10(home, ".agents", "skills", "perf-diagnose", "SKILL.md");
6203
6321
  const codexCaps = JSON.stringify({ hostName: "codex", preToolUseHook: false, readOnlyRules: true });
6204
- await mergeJsonConfig(
6205
- mcpPath2,
6206
- (current) => mergeNamedRecord(current, "mcpServers", "perf-engineer", {
6207
- command: "npx",
6208
- args: ["-y", "@perf-engineer/web"],
6209
- env: { PERF_ENGINEER_HOST_CAPABILITIES: codexCaps }
6210
- }),
6211
- dryRun
6212
- );
6213
- writtenFiles.push(mcpPath2);
6214
- const skillSrc = join10(templatesRoot, "codex", "skills", "perf-diagnose", "SKILL.md");
6215
- const skillDst = join10(baseDir2, "skills", "perf-diagnose", "SKILL.md");
6216
- await ensureTextWrite(skillDst, await readFile6(skillSrc, "utf8"), dryRun);
6217
- writtenFiles.push(skillDst);
6218
- const agentsSrc = join10(templatesRoot, "codex", "AGENTS.md");
6219
- const agentsDst = join10(baseDir2, "AGENTS.md");
6220
- const rawAgents = (await readFile6(agentsSrc, "utf8")).trim();
6221
- const markedBlock = `${CODEX_RULES_START}
6222
- ${rawAgents}
6223
- ${CODEX_RULES_END}`;
6224
- const existingAgents = existsSync5(agentsDst) ? await readFile6(agentsDst, "utf8") : "";
6225
- await ensureTextWrite(agentsDst, upsertMarkedSection(existingAgents, markedBlock), dryRun);
6226
- writtenFiles.push(agentsDst);
6322
+ const existingToml = existsSync5(configPath) ? await readFile6(configPath, "utf8") : "";
6323
+ const updatedToml = upsertCodexTomlServer(existingToml, buildCodexServerTomlBlock(codexCaps));
6324
+ await ensureTextWrite(configPath, updatedToml, dryRun);
6325
+ writtenFiles.push(configPath);
6326
+ const skillSrc2 = join10(templatesRoot, "codex", "skills", "perf-diagnose", "SKILL.md");
6327
+ await ensureTextWrite(skillDst2, await readFile6(skillSrc2, "utf8"), dryRun);
6328
+ writtenFiles.push(skillDst2);
6227
6329
  return {
6228
6330
  client,
6331
+ scope,
6229
6332
  targetRoot: baseDir2,
6230
6333
  writtenFiles,
6231
6334
  dryRun,
6232
6335
  nextSteps: [
6233
- "1. \u5982\u4F7F\u7528\u5168\u5C40 ~/.codex/config.toml\uFF0C\u8BF7\u6DFB\u52A0\uFF1A",
6234
- " [mcp_servers.perf-engineer]",
6235
- ' command = "npx"',
6236
- ' args = ["-y", "@perf-engineer/web"]',
6237
- "2. \u5DF2\u751F\u6210\u53EA\u8BFB\u89C4\u5219\u5757\u81F3 AGENTS.md\uFF08\u91CD\u590D\u5B89\u88C5\u4F1A\u81EA\u52A8\u66F4\u65B0\u8BE5\u533A\u5757\uFF0C\u4E0D\u5F71\u54CD\u5176\u4ED6\u5185\u5BB9\uFF09\u3002"
6336
+ isProject2 ? "1. \u5DF2\u5408\u5165\u9879\u76EE\u7EA7 .codex/config.toml \u5E76\u5199\u5165 .agents/skills/perf-diagnose/SKILL.md\u3002" : "1. \u5DF2\u5408\u5165\u5168\u5C40 ~/.codex/config.toml \u5E76\u5B89\u88C5\u6280\u80FD\u81F3 ~/.agents/skills/perf-diagnose/SKILL.md\uFF08\u672A\u4FEE\u6539\u5F53\u524D\u4E1A\u52A1\u4ED3\u5E93\uFF09\u3002",
6337
+ "2. \u91CD\u542F Codex \u4F1A\u8BDD\u540E\uFF0C\u5373\u53EF\u76F4\u63A5\u8C03\u7528 perf-engineer MCP \u5DE5\u5177\u4E0E perf-diagnose \u6280\u80FD\u3002"
6238
6338
  ]
6239
6339
  };
6240
6340
  }
6241
6341
  if (client === "vscode") {
6242
- const baseDir2 = options.targetDir ?? process.cwd();
6243
- const mcpPath2 = join10(baseDir2, ".vscode", "mcp.json");
6342
+ const isProject2 = scope === "project";
6343
+ const baseDir2 = isProject2 ? options.targetDir ?? process.cwd() : resolveVscodeUserDir(home, platform, options.appDataDir);
6344
+ const mcpPath2 = isProject2 ? join10(baseDir2, ".vscode", "mcp.json") : join10(baseDir2, "mcp.json");
6244
6345
  const vscodeCaps = JSON.stringify({ hostName: "vscode", preToolUseHook: false, readOnlyRules: false });
6245
6346
  await mergeJsonConfig(
6246
6347
  mcpPath2,
@@ -6255,34 +6356,43 @@ ${CODEX_RULES_END}`;
6255
6356
  writtenFiles.push(mcpPath2);
6256
6357
  return {
6257
6358
  client,
6359
+ scope,
6258
6360
  targetRoot: baseDir2,
6259
6361
  writtenFiles,
6260
6362
  dryRun,
6261
6363
  nextSteps: [
6262
- "1. \u6253\u5F00 VS Code \u804A\u5929\u9762\u677F\uFF08Agent \u6A21\u5F0F\uFF09\uFF0C\u786E\u8BA4\u5DF2\u542F\u7528 .vscode/mcp.json \u4E2D\u7684 perf-engineer \u670D\u52A1\u3002",
6364
+ isProject2 ? "1. \u6253\u5F00 VS Code \u804A\u5929\u9762\u677F\uFF08Agent \u6A21\u5F0F\uFF09\uFF0C\u786E\u8BA4\u5DF2\u542F\u7528\u9879\u76EE\u7EA7 .vscode/mcp.json \u4E2D\u7684 perf-engineer \u670D\u52A1\u3002" : "1. \u6253\u5F00 VS Code \u804A\u5929\u9762\u677F\uFF08Agent \u6A21\u5F0F\uFF09\uFF0C\u786E\u8BA4\u5DF2\u542F\u7528\u7528\u6237\u7EA7 mcp.json \u4E2D\u7684 perf-engineer \u670D\u52A1\uFF08\u672A\u4FEE\u6539\u5F53\u524D\u4E1A\u52A1\u4ED3\u5E93\uFF09\u3002",
6263
6365
  "2. \u82E5\u63D0\u793A\u4FE1\u4EFB MCP \u670D\u52A1\u5668\uFF0C\u786E\u8BA4\u542F\u7528\u5373\u53EF\u5F00\u59CB\u8BCA\u65AD\u3002"
6264
6366
  ]
6265
6367
  };
6266
6368
  }
6267
- const baseDir = options.targetDir ?? process.cwd();
6268
- const mcpPath = join10(baseDir, ".mcp.json");
6369
+ const isProject = scope === "project";
6370
+ const baseDir = isProject ? options.targetDir ?? process.cwd() : home;
6371
+ const mcpPath = isProject ? join10(baseDir, ".mcp.json") : join10(home, ".claude.json");
6372
+ const skillDst = isProject ? join10(baseDir, ".claude", "skills", "perf-diagnose", "SKILL.md") : join10(home, ".claude", "skills", "perf-diagnose", "SKILL.md");
6373
+ const claudeCaps = JSON.stringify({ hostName: "claude-code", preToolUseHook: false, readOnlyRules: true });
6269
6374
  await mergeJsonConfig(
6270
6375
  mcpPath,
6271
6376
  (current) => mergeNamedRecord(current, "mcpServers", "perf-engineer", {
6272
6377
  command: "npx",
6273
- args: ["-y", "@perf-engineer/web"]
6378
+ args: ["-y", "@perf-engineer/web"],
6379
+ env: { PERF_ENGINEER_HOST_CAPABILITIES: claudeCaps }
6274
6380
  }),
6275
6381
  dryRun
6276
6382
  );
6277
6383
  writtenFiles.push(mcpPath);
6384
+ const skillSrc = join10(templatesRoot, "codex", "skills", "perf-diagnose", "SKILL.md");
6385
+ await ensureTextWrite(skillDst, await readFile6(skillSrc, "utf8"), dryRun);
6386
+ writtenFiles.push(skillDst);
6278
6387
  return {
6279
6388
  client,
6389
+ scope,
6280
6390
  targetRoot: baseDir,
6281
6391
  writtenFiles,
6282
6392
  dryRun,
6283
6393
  nextSteps: [
6284
- "1. \u5DF2\u5C06 perf-engineer \u5199\u5165\u5F53\u524D\u76EE\u5F55 .mcp.json\uFF08\u9879\u76EE\u7EA7\u5171\u4EAB\uFF09\u3002",
6285
- "2. \u5982\u5E0C\u671B\u5168\u5C40\u5B89\u88C5\u5230\u4E2A\u4EBA Claude Code\uFF0C\u4E5F\u53EF\u76F4\u63A5\u8FD0\u884C\uFF1Aclaude mcp add perf-engineer -- npx -y @perf-engineer/web"
6394
+ isProject ? "1. \u5DF2\u5408\u5165\u9879\u76EE\u7EA7 .mcp.json \u5E76\u5199\u5165 .claude/skills/perf-diagnose/SKILL.md\u3002" : "1. \u5DF2\u5408\u5165\u7528\u6237\u7EA7 ~/.claude.json \u5E76\u5B89\u88C5\u6280\u80FD\u81F3 ~/.claude/skills/perf-diagnose/SKILL.md\uFF08\u672A\u4FEE\u6539\u5F53\u524D\u4E1A\u52A1\u4ED3\u5E93\uFF09\u3002",
6395
+ "2. \u91CD\u542F Claude Code \u4F1A\u8BDD\u540E\uFF0C\u5373\u53EF\u4F7F\u7528 perf-engineer MCP \u5DE5\u5177\u4E0E /perf-diagnose \u6280\u80FD\u3002"
6286
6396
  ]
6287
6397
  };
6288
6398
  }
@@ -6294,14 +6404,15 @@ function printHelp() {
6294
6404
 
6295
6405
  \u7528\u6CD5:
6296
6406
  npx -y @perf-engineer/web \u542F\u52A8 Stdio MCP \u670D\u52A1\uFF08\u4F9B AI \u5BA2\u6237\u7AEF\u8FDE\u63A5\uFF09
6297
- npx -y @perf-engineer/web install <client> \u4E00\u952E\u5B89\u88C5\u5230\u6307\u5B9A AI \u5BA2\u6237\u7AEF
6407
+ npx -y @perf-engineer/web install <client> \u4E00\u952E\u5B89\u88C5\u5230\u6307\u5B9A AI \u5BA2\u6237\u7AEF\uFF08\u9ED8\u8BA4\u7528\u6237\u5168\u5C40\uFF0C\u4E0D\u4FEE\u6539\u5F53\u524D\u4ED3\u5E93\uFF09
6298
6408
 
6299
6409
  \u652F\u6301\u7684\u5BA2\u6237\u7AEF (<client>):
6300
6410
  ${SUPPORTED_CLIENTS.join(" | ")}
6301
6411
 
6302
6412
  install \u53EF\u9009\u53C2\u6570:
6303
- --dir <path> \u6307\u5B9A\u76EE\u6807\u9879\u76EE\u6216\u63D2\u4EF6\u76EE\u5F55\uFF08\u9ED8\u8BA4\uFF1AAntigravity \u5199\u5165 ~/.gemini/config/plugins/perf-engineer\uFF0C\u5176\u4F59\u5199\u5165\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF09
6304
- --global \u5B89\u88C5\u5230\u7528\u6237\u5168\u5C40\u76EE\u5F55\uFF08\u76EE\u524D\u652F\u6301 cursor\uFF09
6413
+ --project \u5B89\u88C5\u5230\u5F53\u524D\u9879\u76EE\u76EE\u5F55\uFF08\u5199\u5165\u4ED3\u5E93\u5185\u9690\u85CF\u914D\u7F6E\u76EE\u5F55\uFF0C\u9002\u7528\u4E8E\u56E2\u961F\u5171\u4EAB\uFF09
6414
+ --dir <path> \u6307\u5B9A\u76EE\u6807\u9879\u76EE\u76EE\u5F55\uFF08\u914D\u5408 --project\uFF09\u6216 Antigravity \u63D2\u4EF6\u76EE\u5F55
6415
+ --global \u5B89\u88C5\u5230\u7528\u6237\u5168\u5C40\u76EE\u5F55\uFF08\u5DF2\u662F\u9ED8\u8BA4\u884C\u4E3A\uFF0C\u4FDD\u7559\u7528\u4E8E\u517C\u5BB9\uFF09
6305
6416
  --dry-run \u4EC5\u9884\u89C8\u5C06\u5199\u5165\u7684\u6587\u4EF6\u548C\u540E\u7EED\u6B65\u9AA4\uFF0C\u4E0D\u5B9E\u9645\u5199\u76D8
6306
6417
 
6307
6418
  \u5176\u4ED6\u53C2\u6570:
@@ -6311,11 +6422,14 @@ install \u53EF\u9009\u53C2\u6570:
6311
6422
  }
6312
6423
  function parseInstallFlags(args) {
6313
6424
  let targetDir;
6425
+ let project = false;
6314
6426
  let global = false;
6315
6427
  let dryRun = false;
6316
6428
  for (let i = 0; i < args.length; i += 1) {
6317
6429
  const arg = args[i];
6318
- if (arg === "--global") {
6430
+ if (arg === "--project") {
6431
+ project = true;
6432
+ } else if (arg === "--global") {
6319
6433
  global = true;
6320
6434
  } else if (arg === "--dry-run") {
6321
6435
  dryRun = true;
@@ -6334,7 +6448,7 @@ function parseInstallFlags(args) {
6334
6448
  throw new Error(`\u672A\u77E5\u53C2\u6570\uFF1A${arg}`);
6335
6449
  }
6336
6450
  }
6337
- return { ...targetDir ? { targetDir } : {}, global, dryRun };
6451
+ return { ...targetDir ? { targetDir } : {}, project, global, dryRun };
6338
6452
  }
6339
6453
  async function resolveGuidanceLock() {
6340
6454
  const candidates = [
@@ -6412,7 +6526,8 @@ async function main() {
6412
6526
  const options = parseInstallFlags(args.slice(2));
6413
6527
  const result = await installForClient(clientArg, options);
6414
6528
  const prefix = result.dryRun ? "[dry-run \u9884\u89C8] " : "";
6415
- process.stdout.write(`${prefix}\u5DF2\u5B8C\u6210 ${result.client} \u5B89\u88C5\uFF08\u76EE\u5F55\uFF1A${result.targetRoot}\uFF09
6529
+ const scopeLabel = result.scope === "project" ? "\u9879\u76EE\u7EA7" : "\u7528\u6237\u5168\u5C40";
6530
+ process.stdout.write(`${prefix}\u5DF2\u5B8C\u6210 ${result.client} ${scopeLabel}\u5B89\u88C5\uFF08\u76EE\u5F55\uFF1A${result.targetRoot}\uFF09
6416
6531
 
6417
6532
  \u5199\u5165\u6587\u4EF6\uFF1A
6418
6533
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perf-engineer/web",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Strictly read-only web performance diagnosis and task planning MCP server & installer for AI coding hosts.",
@@ -45,5 +45,6 @@
45
45
  "@modelcontextprotocol/sdk": "^1.12.1",
46
46
  "chrome-launcher": "^1.1.2",
47
47
  "lighthouse": "^12.6.0"
48
- }
48
+ },
49
+ "mcpName": "io.github.perf-engineer/perf-engineer"
49
50
  }