Communitygithub.com

Vercel 優化

針對 Vercel 上部署的專案(尤其是 Next.js、SvelteKit、Nuxt 和有限支援的 Astro 應用)進行成本與效能優化稽核。收集 Vercel 指標、用量、專案設定與程式碼掃描結果;僅調查有指標佐證的候選項目;產出基於已驗證檔案與版本感知之 Vercel/框架文件的排名建議。用於 Vercel 帳單降低、緩慢或昂貴路由、快取機會、函式調用、建置分鐘、高速資料傳輸、Core Web Vitals、機器人管理、Fluid compute 或成本分解請求等觸發場景。

Vercel 優化 是什麼?

Vercel Optimize 是一個以可觀測性為優先的 Vercel 優化稽核工具,專為 AI 代理設計,用於自動分析 Vercel 部署的成本與效能瓶頸。它遵循「指標優先」的核心原則:絕不從專案範圍的 grep 開始,而是先收集 Vercel 的實際生產訊號(如路線指標、用量、合約與程式碼掃描結果),然後透過確定性關卡決定哪些路線、檔案或設定值得深入調查。支援 Next.js (App Router 與 Pages Router)、SvelteKit 和 Nuxt 的完整路線對應與框架特定建議,Astro 則為有限支援;對於不支援的框架,它會停止並要求使用者確認後再以有限的平台/程式碼稽核模式繼續。稽核流程包括收集訊號、關卡候選、深度調查、驗證建議,最後產出結構化報告。所有建議都必須追溯到已驗證的指標證據、已驗證的檔案與版本感知的文件引用。它嚴格限制調查範圍:僅讀取候選項目標記的檔案或這些檔案的路線本地匯入鏈,避免浪費時間在不相關的程式碼上。此外,它也提供了預算控制、多代理並行調查(當主機支援時)、以及自動驗證與重新生成建議的功能,確保輸出的品質與安全性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/vercel-optimize

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Vercel 優化 是做什麼的?

執行以可觀測性為優先的 Vercel 優化稽核。在 signals.json 存在且確定性關卡指向特定路線、檔案或專案設定之前,請勿檢查原始碼檔案。

核心原則:若有任何規則不明確,請閱讀 references/doctrine.md。

  • 指標優先。建議從 Vercel 生產環境訊號出發,而非整個儲存庫的 grep。
  • 確定性關卡。scripts/gate-investigations.mjs 決定哪些項目值得調查。
  • 候選範圍限定。僅讀取候選項目指定的檔案,或路線本地匯入鏈中的檔案。
  • 版本感知引用。僅使用 references/docs-library.json;無效或版本不符的引用將被剔除。
  • 客戶語音。撰寫報告文字或聊天輸出之前,請閱讀 references/voice.md。

先決條件

  • Vercel CLI v53+,且須包含 vercel metrics、vercel usage、vercel contract 與 vercel api 指令。
  • 已認證的 CLI 工作階段:vercel login。
  • 已連結的應用程式目錄:vercel link。VERCEL_PROJECT_ID 有助於解析專案設定,但 vercel metrics 仍需要目錄連結。連結或環境中必須包含目標專案的組織/團隊/使用者範圍,以便收集器解析出 CLI 安全的 --scope,並確保 vercel metrics、vercel usage 與 vercel contract 在同一個帳號下。
  • Node.js 20+。
  • 需要 Observability Plus 才能獲得基於路線層級指標的建議。

切勿將認證令牌放入 shell 指令中。請勿在可能被聊天記錄回顯的指令中輸入 VERCEL_TOKEN=...、--token ... 或 Authorization: Bearer ...。

框架支援

前置檢查會讀取 package.json,並在指標展開前設定好預期。

框架狀態備註
Next.js App Router支援最強的路線對應、掃描器、劇本與引用
Next.js Pages Router支援偵測到 Pages Router 時會將範圍限制在其慣用語法內
SvelteKit支援支援 src/routes 檔案的路線對應與 SvelteKit 掃描器
Nuxt支援支援路線對應加上通用/平台檢查;較少的框架特定建議
Astro有限支援路線對應加上通用檢查;較少的框架特定建議
Hono / Remix / 未知預設封鎖僅在使用者接受有限的平台/程式碼稽核時才繼續

若不支援,請停止並在掃描或關卡篩選前詢問:

此專案使用 <framework>。Vercel Optimize 支援 Next.js、SvelteKit 與 Nuxt 的基於指標的程式碼建議。Astro 的支援有限。對於 <framework>,我仍可執行有限的平台/掃描器稽核,但路線層級的 Vercel 指標可能無法對應回原始碼檔案。

您希望我繼續進行有限的稽核,還是就此停止?

如果使用者決定繼續,請使用 --continue-unsupported-framework 參數重新執行收集。

執行目錄

每次稽核都使用全新的執行目錄。請勿跨執行重複使用簡報、子代理輸出或報告。

RUN_DIR="$(mktemp -d -t vercel-optimize-XXXXXX)"

管道

1. 收集、掃描並合併訊號

從已連結的應用程式目錄執行,或在支援的腳本中使用 --cwd 參數。請將 stdout JSON 與 stderr 日誌分開存放。請勿合併資料流。

node scripts/collect-signals.mjs [projectId] > "$RUN_DIR/vercel-signals.json" 2> "$RUN_DIR/collect.stderr"
node -e 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))' "$RUN_DIR/vercel-signals.json"

node scripts/scan-codebase.mjs <repo-root> > "$RUN_DIR/codebase.json"
node scripts/merge-signals.mjs "$RUN_DIR/vercel-signals.json" "$RUN_DIR/codebase.json" --out "$RUN_DIR/signals.json"

收集細節、結構定義、指標 ID 與降級行為請參閱 references/data-collection.md。指標註冊表位於 lib/queries.mjs;所有查詢都應保持在共用的 14 天視窗內。

collect-signals.mjs 會解析已連結專案的擁有者,設定 commandScope.cliScope,並在檢查 Observability Plus 之前驗證解析出的帳號能否讀取該專案。後續腳本會對所有接受 --scope 的 Vercel CLI 指令重複使用該範圍。請勿手動執行 vercel usage、vercel metrics 或 vercel contract 而未使用相同的範圍;未指定範圍的用量查詢可能會回報使用者個人組織的資料,而路線指標卻來自團隊專案。

如果專案或範圍解析不明確,請停止並詢問使用者希望稽核哪個 Vercel 專案與團隊/個人範圍。請勿從目前的 vercel whoami 團隊推斷目標範圍;在連結完成、於 .vercel/repo.json 中找到確切專案、或透過 VERCEL_PROJECT_ID + VERCEL_ORG_ID 辨識出目標帳號之前,請勿進行指標、用量或合約的收集。

針對 PROJECT_SCOPE_UNRESOLVED、SCOPE_UNRESOLVED 或 PROJECT_SCOPE_MISMATCH 情況,請使用以下提示:

我目前無法安全地識別此稽核的 Vercel 專案與帳號。

請確認 Vercel 專案名稱或 ID 以及團隊代號/名稱,或告知這是您個人帳號下的專案。確認後,我會重新連結或在確切範圍下重新執行收集,然後再檢查指標。

1.1 檢查阻斷條件

在進行關卡篩選前,請檢查阻斷條件:

jq '{frameworkSupportBlocker, observabilityPlus, observabilityPlusUsable, observabilityPlusBlocker, observabilityPlusBlockerDetail}' "$RUN_DIR/signals.json"

必要操作:

  • frameworkSupportBlocker === "unsupported_framework":使用上述不支援框架的提示。
  • PROJECT_SCOPE_UNRESOLVED、SCOPE_UNRESOLVED 或 PROJECT_SCOPE_MISMATCH:停止並詢問使用者希望稽核哪個 Vercel 專案與團隊/個人範圍。對於團隊專案,請先執行 vercel link --yes --project <project-name-or-id> --team <team-slug> 後重新執行;對於個人專案,請在連結至目標使用者帳號或同時設定 VERCEL_PROJECT_ID 與 VERCEL_ORG_ID 後重新執行。
  • observabilityPlusBlocker === null:繼續。
  • no_traffic:告知使用者路線指標資料稀疏;僅在使用者接受有限輸出時繼續。
  • payment_required 或 no_oplus_probe:逐字呈現 references/observability-plus.md 並詢問。
  • project_disabled:告知使用者為此專案啟用 Observability Plus,或接受有限的稽核。
  • daily_quota_exceeded:停止並告知使用者 Observability 查詢配額已用完;請在下一個 UTC 午夜重置後重試,或詢問是否繼續進行有限的純程式碼稽核。
  • not_linked:連結應用程式目錄,然後重新執行步驟 1。如果已知應用程式路徑與專案:
vercel link --yes --project <project-name-or-id> --cwd <app-dir>
# 已知時加上 --team <team-id-or-slug>
  • forbidden 或 project_not_found:修正認證/團隊範圍。請勿推銷 Observability Plus。
  • all_failed_other:顯示原始錯誤碼,並詢問是否繼續進行有限的純程式碼稽核模式。

請勿默默回退到純程式碼模式。如果使用者接受有限的稽核,請使用以下方式重新執行收集:

node scripts/collect-signals.mjs [projectId] --continue-without-observability > "$RUN_DIR/vercel-signals.json" 2> "$RUN_DIR/collect.stderr"

然後再次掃描並合併。

2. 篩選候選項目

node scripts/gate-investigations.mjs "$RUN_DIR/signals.json" > "$RUN_DIR/gate.json"

輸出結構:

  • toLaunch:需要調查的程式碼範圍候選項目。
  • platform:專案/帳號範圍的建議。
  • gated:被跳過、已涵蓋或不合資格的候選項目,但仍需出現在報告中。
  • budget:候選項目預算與選擇模式。

預設預算為 6 個程式碼範圍候選項目,並設有多元化護欄。若要擴展:

node scripts/gate-investigations.mjs "$RUN_DIR/signals.json" --max-candidates 12 > "$RUN_DIR/gate.json"
node scripts/gate-investigations.mjs "$RUN_DIR/signals.json" --max-candidates all > "$RUN_DIR/gate.json"

產生的候選項目文件:references/candidates.md。

2.1 必要時詢問稽核範圍

在深入調查之前,請執行:

node scripts/budget-summary.mjs "$RUN_DIR/gate.json" --format json > "$RUN_DIR/budget-summary.json"

如果 shouldAsk 為 false,則繼續。

如果 shouldAsk 為 true:

  1. 精確輸出 exactChatMessage.body 的內容。請勿摘要、截斷、重新排序或改寫。
  2. 然後使用 questionPayload 詢問 questionText(當主機支援結構化問題時)。
  3. 如果使用者選擇不同數量,請使用 --max-candidates <choice> 重新執行關卡篩選。

切勿將長預覽放在問題欄位中。預覽與問題是兩個不同的介面。

2.2 深入調查與調和

node scripts/deep-dive.mjs "$RUN_DIR/signals.json" "$RUN_DIR/gate.json" --cwd <project-dir> > "$RUN_DIR/investigation-evidence.json"

node scripts/reconcile-candidates.mjs "$RUN_DIR/investigation-evidence.json" \
  --gate "$RUN_DIR/gate.json" \
  --out "$RUN_DIR/reconciled-investigation.json"

--cwd 必須是已連結的專案目錄,以便 deep-dive.mjs 驗證相同的專案連結,並在後續的 vercel metrics 呼叫中重複使用 signals.json.commandScope.cliScope。

調和過程會以確定性方式,在進行任何原始碼調查之前,將不成立的候選項目轉換為觀察結果:

  • metric_mismatch
  • error_storm
  • deployment_regression
  • scanner_only_no_metric

2.3 產生簡報與調查

列出工作項目:

node scripts/prepare-investigation-brief.mjs "$RUN_DIR/signals.json" "$RUN_DIR/reconciled-investigation.json" --list > "$RUN_DIR/briefs-manifest.json"

為 briefs-manifest.json.briefs 中的每個項目產生一份簡報。group 可以是 toLaunch 或 platform;請勿只產生 toLaunch 的簡報。

mkdir -p "$RUN_DIR/briefs" "$RUN_DIR/sub-agent-outputs"
node scripts/prepare-investigation-brief.mjs "$RUN_DIR/signals.json" "$RUN_DIR/reconciled-investigation.json" \
  --group <brief.group> --index <brief.index> --out "$RUN_DIR/briefs/<brief.group>-<brief.index>.md"

使用 briefs-manifest.json.briefs[].label 作為可見的工作者名稱,例如 對 /docs/llm-digest/[...slug] 路由的低快取命中率,而非 toLaunch-7。

展開規則:

  • 1-2 份簡報:直接內聯調查。
  • 3 份以上簡報:若主機支援,則為每份簡報產生一個子代理。
  • 不支援子代理的主機:以序列方式內聯執行。

子代理合約:

  • 簡報即為完整的提示。
  • 僅讀取簡報中列出的檔案,必要時加上路線本地匯入。
  • 使用 references/recommendations.md 產出一份 JSON 建議或一份 JSON 無變更發現。
  • 請勿引用提供的引用子集之外的 URL。
  • 請勿推薦檢測到的版本中未提供的框架功能。

如果子代理嘗試進行整個儲存庫的 grep,則表示候選項目有缺陷;應放棄或不表態,而非擴大範圍。

2.4 收集輸出

將每個原始調查結果儲存在 $RUN_DIR/sub-agent-outputs/ 中,然後收集:

node scripts/collect-sub-agent-outputs.mjs \
  --manifest "$RUN_DIR/briefs-manifest.json" \
  --out "$RUN_DIR/recommendations.json" \
  "$RUN_DIR/sub-agent-outputs/"

收集器會提取 JSON、預置預先解析的記錄、強制執行清單順序,並在遇到缺失、重複、未知或 candidateRef 值不符的情況時失敗。

3. 驗證建議

node scripts/verify-and-regen.mjs "$RUN_DIR/recommendations.json" \
  --signals "$RUN_DIR/signals.json" \
  --repo-root <project-dir> \
  --out "$RUN_DIR/verify.json"

此腳本會提取主張、驗證檔案/引用/版本是否符合、進行品質評級、套用淨化器、輸出 verifiedRecommendations、withheldRecommendations、renderableRecommendations,並為失敗或不安全的建議建立 regenPlan。

建議結構、撰寫規則、淨化器順序與評級規則:references/recommendations.md。驗證規則:references/verification.md。

對於每個 regenPlan 項目,使用相同的簡報重新執行,並在提示中加入 Previous attempt failed these checks 區段,列出 topFailures。僅在驗證結果有所改善且未刪減引用的情況下才保留重新產生的輸出。

4. 產生報告與最終訊息

node scripts/render-report.mjs "$RUN_DIR/verify.json" "$RUN_DIR/gate.json" "$RUN_DIR/signals.json" \
  --project <name> \
  --out "$RUN_DIR/report.md" \
  --message-out "$RUN_DIR/final-message.json"

僅在開發技能時使用 --debug-out "$RUN_DIR/debug.json"。客戶端的 Markdown 與聊天輸出不得暴露 passRate、quality、淨化器軌跡、原始子代理名稱或其他實作細節。

渲染完成後,精確輸出 final-message.json.body 的內容並停止。請勿添加重點摘要、除錯筆記、原始計數、子代理摘要或其他額外說明。渲染時的去重、平台上限與硬性安全捨棄可能會改變客戶端可見的計數,因此永遠不要根據原始 verify.json 進行總結。

報告結構與影響框架:references/scoring.md。

建議規則

每一條建議都必須:

  • 追溯至已發起的候選項目、平台候選項目、預先解析的觀察結果,或已驗證且不依賴流量的掃描器發現。
  • 包含來自 signals.json 或 evidence.deepDive 的觀察指標證據。
  • 在涉及程式碼時,引用已驗證的檔案與行號。
  • 包含至少一條適用於檢測到的框架/版本的允許引用。
  • 使用精確的觀察效能數據。
  • 僅使用成本大小描述詞;絕不向客戶端呈現 $N 節省金額。
  • 不建議縮短 Vercel Workflow 執行階段端點(/.well-known/workflow/v1/*)的持續時間。這些是為耐用步驟/流程執行產生的編排路由,應在調查前強制封鎖。
  • Workflow 建議必須指明正在更改的邊界。有效範例:將耐用工作排入佇列並返回執行 ID 而非等待完成、修正串流重播/關閉/鎖定,或減少已驗證的多餘 Workflow 步驟/S

...

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相關技能