Communitygithub.com

Vercel 优化

对已部署项目(主要是 Next.js、SvelteKit、Nuxt 及有限的 Astro 应用)进行 Vercel 成本与性能优化。先收集 Vercel 指标、用量、项目配置和代码扫描结果;仅调查有指标支持的候选方案;基于已验证的文件和版本感知的 Vercel/框架文档,生成排序建议。

Vercel 优化 是什么?

该技能通过以可观测性为先的方式,自动审计 Vercel 部署项目,帮助降低成本和提升性能。它支持 Next.js、SvelteKit、Nuxt,以及有限的 Astro 应用。其核心原则是:先收集 Vercel 生产环境指标(如函数调用次数、构建分钟数、数据转移量、Core Web Vitals),然后通过确定性门控决定哪些路由、文件或项目设置值得深入调查。对于被选中的候选对象,它会执行代码扫描、生成调查简报,并基于版本感知的文档库提出排序后的建议。该技能会自动处理障碍和范围冲突,确保仅在验证了指标证据后才进行文件审查,从而避免盲目进行全库搜索。所有收集、门控、深入调查和报告流程均通过一个可重复的流水线进行,该流水线将原始信号、代码扫描结果和最终建议分别保存到单独的 JSON 文件中。

兼容平台~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 Optimize

运行一个以可观测性为先的 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 以及团队 slug/名称,或者告诉我在您的个人账户下。确认后,我会重新链接或针对该确切的范围内重新运行收集,然后再检查指标。

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:停下来告诉用户可观测性查询配额已用尽;在下一个 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,例如 Low cache-hit route on /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 条目,使用一个列出 topFailures 的 Previous attempt failed these checks 部分重新运行相同的简报。仅当验证在不损害引用的情况下得到改善时,才保留重新生成的输出。

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.

相关技能