|
| 1 | +--- |
| 2 | +name: profile-ci |
| 3 | +description: Run and analyze Elements cold CI performance profiles and propose evidence-backed build, test, lint, and dependency-graph improvements. Use whenever asked to profile or benchmark pnpm run ci, rerun ci:profile, create a CI performance audit, compare CI timings, find bottlenecks or the completion path, investigate a CI performance regression, or recommend measured CI/build optimizations. |
| 4 | +--- |
| 5 | + |
| 6 | +# Profile CI |
| 7 | + |
| 8 | +Produce a repeatable cold-CI profile, explain what controls wall-clock completion, and turn the evidence into prioritized, testable recommendations. |
| 9 | + |
| 10 | +## Required context |
| 11 | + |
| 12 | +1. Read the repository `AGENTS.md`. |
| 13 | +2. Read `projects/internals/BUILD.md`. |
| 14 | +3. Inspect the current root `ci:profile` script and `projects/internals/ci/ci-profile.js`. Treat the script as the profiling source of truth. |
| 15 | +4. Read a project's `DEVELOPMENT.md` before running project-specific commands when that file exists. |
| 16 | + |
| 17 | +Do not copy profiling logic into this skill. Update the repository profiler when its behavior needs to change. |
| 18 | + |
| 19 | +## Choose the workflow |
| 20 | + |
| 21 | +- Run a new profile when the user asks to rerun, benchmark current changes, refresh an audit, or verify an optimization. |
| 22 | +- Analyze existing `.metrics/ci-profile.{json,md}` artifacts without rerunning when the user asks only for interpretation and the artifacts match the intended commit and worktree state. |
| 23 | +- Create recommendations without implementing them unless the user also asks for the changes. |
| 24 | + |
| 25 | +## Profile safely |
| 26 | + |
| 27 | +Run all repository commands through mise. |
| 28 | + |
| 29 | +1. Inspect `git status --short`. |
| 30 | +2. Preview ignored files that reset would delete with `git clean -ndX`. |
| 31 | +3. Stop and ask before profiling if that preview includes user data, local assets, secrets, or other non-reproducible files. The profiler runs `pnpm run ci:reset`, which deletes ignored files and reinstalls dependencies before every sample. |
| 32 | +4. Never stash, commit, discard, or clean tracked changes merely to make the profiler accept the worktree. |
| 33 | +5. Use the clean command when the worktree is clean: |
| 34 | + |
| 35 | +```shell |
| 36 | + mise exec -- pnpm run ci:profile |
| 37 | +``` |
| 38 | + |
| 39 | +6. When the dirty changes are the intentional subject of the audit, preserve them and run: |
| 40 | + |
| 41 | +```shell |
| 42 | + CI_PROFILE_ALLOW_DIRTY=1 mise exec -- pnpm run ci:profile |
| 43 | +``` |
| 44 | + |
| 45 | + Record the dirty-worktree condition in the report. Do not use this override for unrelated or unexplained changes. |
| 46 | + |
| 47 | +Allow all three cold samples to finish. Dependency installation or browser setup can require network access. If a run fails, inspect the copied `.metrics/ci-profile-run-*.log` and reset logs, report the incomplete profile, and do not invent missing samples. |
| 48 | + |
| 49 | +## Verify the artifacts |
| 50 | + |
| 51 | +The profiler writes ignored artifacts under `.metrics/`: |
| 52 | + |
| 53 | +-`ci-profile.json`: structured metadata, run durations, and per-script samples |
| 54 | +-`ci-profile.md`: generated method and top-ten summary |
| 55 | +-`ci-profile-run-{1,2,3}.log`: complete CI logs |
| 56 | +-`ci-profile-reset-{1,2,3}.log`: reset and install logs |
| 57 | + |
| 58 | +Before analysis, confirm: |
| 59 | + |
| 60 | +- all three runs exist; |
| 61 | +- every run has zero incomplete scripts; |
| 62 | +- each ranked script has three samples; |
| 63 | +- commit, dirty state, tool versions, CPU, and memory describe the intended environment; |
| 64 | +- the generated Markdown agrees with the JSON. |
| 65 | + |
| 66 | +Use JSON as the numeric source of truth. Keep full precision during calculations and round only for presentation. |
| 67 | + |
| 68 | +## Analyze wall-clock relevance |
| 69 | + |
| 70 | +The slowest command is not automatically the critical path. |
| 71 | + |
| 72 | +1. Rank leaf scripts by median duration from `ci-profile.json`. |
| 73 | +2. Inspect the end of each run log to identify the scripts that consistently complete last. |
| 74 | +3. Trace those scripts through their Wireit `dependencies` in the relevant `package.json` files. |
| 75 | +4. Separate: |
| 76 | +- final or near-final dependency branches; |
| 77 | +- long parallel work that consumes CPU, memory, filesystem, or browser capacity; |
| 78 | +- upstream work that delays a final branch; |
| 79 | +- composite commands whose phases need separate timing. |
| 80 | +5. Inspect each candidate's command, configuration, file count, output, output consumers, and serialization settings before suggesting a change. |
| 81 | +6. Compare with the existing audit only when its environment and method are compatible. Describe before/after changes as concurrent cold-CI measurements, not isolated causal proof. |
| 82 | + |
| 83 | +Read [the optimization playbook](references/optimization-playbook.md) when generating recommendations or designing follow-up experiments. |
| 84 | + |
| 85 | +## Create the audit |
| 86 | + |
| 87 | +Create or refresh `projects/internals/ci/CI-PERFORMANCE.md`. Use `.metrics/ci-profile.md` as generated evidence, not as the finished audit. |
| 88 | + |
| 89 | +Include: |
| 90 | + |
| 91 | +1. Frontmatter and generation context |
| 92 | +2. Executive summary with median CI time and comparison when available |
| 93 | +3. Method, environment, and all run results |
| 94 | +4. Current top-ten scripts |
| 95 | +5. Completion-path analysis |
| 96 | +6. Numbered open findings |
| 97 | +7. Verified completed changes when a prior audit exists |
| 98 | +8. Recommended experiment order |
| 99 | +9. Raw artifact location |
| 100 | + |
| 101 | +For every finding, provide: |
| 102 | + |
| 103 | +-**Evidence:** measurements plus current configuration or dependency facts |
| 104 | +-**Recommendation:** one bounded change or experiment |
| 105 | +-**Validation:** output-equivalence checks, metrics to compare, and resource checks |
| 106 | +-**Confidence:** confidence in the diagnosis and in the proposed approach |
| 107 | + |
| 108 | +Keep completed work out of the open priority list. Mark an item verified only when the configuration changed and a comparable full profile confirms the result. |
| 109 | + |
| 110 | +## Recommendation guardrails |
| 111 | + |
| 112 | +- Do not add CI-share percentages together; scripts overlap. |
| 113 | +- Do not claim a critical path from rankings alone. |
| 114 | +- Do not recommend more concurrency without checking isolation, shared state, ports, output paths, report merging, memory, and machine-wide contention. |
| 115 | +- Do not remove a quality check unless the same coverage remains in another required workflow. |
| 116 | +- Prefer one-variable experiments and compare at least three samples when variance matters. |
| 117 | +- Distinguish targeted project benchmarks from full concurrent CI results. |
| 118 | +- Treat cache optimization separately from this cold profile because the profiler disables Wireit caching. |
| 119 | +- Label estimates and inferred causes. Do not present them as measurements. |
| 120 | +- Keep dependency upgrades separate from performance changes unless the upgrade is the explicit experiment. |
| 121 | + |
| 122 | +## Check the report |
| 123 | + |
| 124 | +Run: |
| 125 | + |
| 126 | +```shell |
| 127 | +mise exec -- pnpm exec prettier --write projects/internals/ci/CI-PERFORMANCE.md |
| 128 | +mise exec -- pnpm exec vale --config .vale.ini projects/internals/ci/CI-PERFORMANCE.md |
| 129 | +git diff --check |
| 130 | +``` |
| 131 | + |
| 132 | +If `projects/internals/ci/ci-profile.test.js` exists, also run: |
| 133 | + |
| 134 | +```shell |
| 135 | +mise exec -- node --test projects/internals/ci/ci-profile.test.js |
| 136 | +``` |
| 137 | + |
| 138 | +Do not rerun the full CI merely to validate the report: the profiler already completed it three times. Report the median, comparison, top remaining opportunities, artifact paths, and validation results to the user. |
0 commit comments