summaryrefslogtreecommitdiff
path: root/skills/vercel-optimize/scripts
diff options
context:
space:
mode:
authornicdillon <nicholas.dillon@vercel.com>2026-10-28 11:26:14 -0400
committernicdillon <nicholas.dillon@vercel.com>2026-10-28 11:26:14 -0400
commit097f4c396d4d21ab26fef357a8bb07b3b084529a (patch)
tree04d6d4f821c5fc0f45d2bb97fd540b0fc476de21 /skills/vercel-optimize/scripts
parent1a2c79d4e6c4a2283dc2c614b6538cbe1ed5ca62 (diff)
vercel-optimize: add build_machine_oversized gate and build signals collectorvercel-optimize/build-machine-oversized
- lib/build-signals.mjs: collect 14 days of deployments (v7 list) plus, for up to 40 recent builds (v13 detail), duration.timeForBilling, duration.cpuTimeForBilling, resourceConfig.buildMachine (purchaseType, cores, memory, machineSelectionType), buildSkipped, and whether the build came from a Deploy Hook (meta.deployHookName presence). meta.deployHookId is the secret end of the hook URL and is never read or stored. Platform data only; no Observability Plus required. - lib/gates/build-machine-oversized.mjs: account-scoped gate for projects pinned to Enhanced or Turbo. Recommends Elastic; reports the break-even billed duration on the next smaller machine as context, not a savings figure. Median uses successful builds only; skipped, Elastic-sized, and other-machine builds are excluded from the build count; CPU minutes come from cpuTimeForBilling when present; memory-related Elastic resize reasons suppress the gate. - Register the kind in gates/index (GATE_VERSION 1.9.0), deep-dive, display labels, report category, and impact label. - Citations for Managing Builds and build pricing; build-machine-right-sizing support topic; signals schema 1.3 with the new builds field. - SKILL.md and references/observability-plus.md: build-focused requests continue without Observability Plus, since build gates use no route metrics. - lib/grade-recommendation.mjs: grade `<account>` candidates on the account rubric too (keeping the higher of route and account scores), and count builds, vCPUs, and billed/CPU minutes as evidence. Without this the build_machine_oversized rec was held back at quality 0.17. - SKILL.md: the post-blocker rerun now merges with --force; without it the merge failed and gates ran on the blocked collection (no usage or builds). - impact-label: when a written build recommendation omits the gate o11ySignal, re-derive it from signals.json so the report shows the real impact line instead of a placeholder. A scanner-only build_minutes_fanout no longer claims a billing threshold was exceeded. - collect-signals: redact Deploy Hook ids and URLs from the stored project config (link.deployHooks keeps name, ref, createdAt). They are bearer secrets and were previously written to signals.json on every run. - scan-codebase: skip .claude and .agents, where project-installed agent skills live; scanning them flagged this skill's own source as findings. - Tests: 36 new fixture tests (gate, collector, grading, impact label, redaction, scan); full suite 805/805. Validated on a live test project: moving a pinned-Turbo project to Elastic cut CPU minutes 54% over five builds, and the gate stopped firing.
Diffstat (limited to 'skills/vercel-optimize/scripts')
-rwxr-xr-xskills/vercel-optimize/scripts/collect-signals.mjs16
-rw-r--r--skills/vercel-optimize/scripts/render-report.mjs1
-rwxr-xr-xskills/vercel-optimize/scripts/scan-codebase.mjs3
3 files changed, 15 insertions, 5 deletions
diff --git a/skills/vercel-optimize/scripts/collect-signals.mjs b/skills/vercel-optimize/scripts/collect-signals.mjs
index 2831fb9..f365db8 100755
--- a/skills/vercel-optimize/scripts/collect-signals.mjs
+++ b/skills/vercel-optimize/scripts/collect-signals.mjs
@@ -3,6 +3,7 @@
// usage + codebase stack + metric queries. Status → stderr, JSON → stdout.
// Degrades gracefully when capabilities are missing.
+import { collectBuildSignals, redactProjectSecrets } from '../lib/build-signals.mjs';
import {
checkCliVersion,
checkAuth,
@@ -24,7 +25,7 @@ import {
import { classifyFrameworkSupport } from '../lib/framework-support.mjs';
import { QUERIES, TIME_WINDOW, normalizerFor } from '../lib/queries.mjs';
-const SCHEMA_VERSION = '1.2';
+const SCHEMA_VERSION = '1.3';
const log = (...args) => console.error('[collect-signals]', ...args);
@@ -131,7 +132,8 @@ async function main() {
log(`command scope resolved (source=${commandScope.source}; scoped=${scope ? 'yes' : 'no'})`);
log('validating linked project belongs to the resolved scope…');
- const projectCfg = await getProjectConfig(project.projectId, project.orgId);
+ // Deploy Hook ids and URLs are secrets: anyone holding one can trigger builds. Keep only names and refs.
+ const projectCfg = redactProjectSecrets(await getProjectConfig(project.projectId, project.orgId));
const projectScope = validateProjectScope(projectCfg, project);
if (!projectScope.ok) {
throw new Error(`PROJECT_SCOPE_MISMATCH: ${projectScope.detail} Ask the user to confirm the exact Vercel project and team/personal scope, then rerun after \`vercel link --yes --project <project-name-or-id> --team <team-slug>\` or after setting both VERCEL_PROJECT_ID and VERCEL_ORG_ID for the intended scope.`);
@@ -236,12 +238,17 @@ async function main() {
log('continuing after Observability Plus blocker because --continue-without-observability was set');
}
- log('pulling account plan + contract + usage in parallel…');
- const [accountPlan, contract, usageResult] = await Promise.all([
+ log('pulling account plan + contract + usage + builds in parallel…');
+ const [accountPlan, contract, usageResult, builds] = await Promise.all([
getAccountPlan(project.orgId || scope),
getContract(scope),
getUsage({ days: 14, scope }),
+ collectBuildSignals({ projectId: project.projectId, orgId: project.orgId })
+ .catch((err) => ({ ok: false, code: 'BUILD_SIGNALS_FAILED', detail: String(err?.message ?? err) })),
]);
+ log(builds?.ok
+ ? `builds: ${builds.builtCount} built deployments in ${builds.windowDays}d; billing detail for ${builds.detailedCount}${builds.listTruncated ? ' (list truncated)' : ''}`
+ : `builds: unavailable (${builds?.code ?? 'unknown'}) — build gates will skip`);
let usage = null;
let usageContextMismatch = false;
@@ -338,6 +345,7 @@ async function main() {
usageError: usageResult?.ok
? (usageContextMismatch ? 'USAGE_CONTEXT_MISMATCH' : null)
: (usageResult?.code ?? 'UNKNOWN'),
+ builds,
stack,
metrics,
metricsSchema: schema,
diff --git a/skills/vercel-optimize/scripts/render-report.mjs b/skills/vercel-optimize/scripts/render-report.mjs
index 542a992..8f7b481 100644
--- a/skills/vercel-optimize/scripts/render-report.mjs
+++ b/skills/vercel-optimize/scripts/render-report.mjs
@@ -327,6 +327,7 @@ function candidateFamily(kind) {
case 'middleware_heavy':
return 'middleware';
case 'build_minutes_fanout':
+ case 'build_machine_oversized':
return 'build';
default:
return kind || null;
diff --git a/skills/vercel-optimize/scripts/scan-codebase.mjs b/skills/vercel-optimize/scripts/scan-codebase.mjs
index 9d416b5..645e3f7 100755
--- a/skills/vercel-optimize/scripts/scan-codebase.mjs
+++ b/skills/vercel-optimize/scripts/scan-codebase.mjs
@@ -15,7 +15,8 @@ import {
} from '../lib/workspace-resolver.mjs';
const SCHEMA_VERSION = '1.0';
-const SKIP_DIRS = new Set(['node_modules', '.next', '.vercel', 'dist', 'build', '.git', 'coverage', '.turbo', '__tests__', 'cypress']);
+// .claude and .agents hold project-installed agent skills (including this one); scanning them flags the skill's own source.
+const SKIP_DIRS = new Set(['node_modules', '.next', '.vercel', 'dist', 'build', '.git', 'coverage', '.turbo', '__tests__', 'cypress', '.claude', '.agents']);
const SKIP_FILE_PATTERNS = [/\.test\./, /\.spec\./, /\.d\.ts$/];
async function main() {