@a2f0/agent-tool 0.1.73 → 0.1.75
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.
- package/README.md +8 -7
- package/package.json +1 -1
- package/skills/optimize-ci/SKILL.md +98 -0
- package/skills/optimize-ci/agents/openai.yaml +4 -0
- package/skills/optimize-ci/references/lessons.md +30 -0
- package/skills/performance-pass/SKILL.md +1 -1
- package/skills/take-screenshots/SKILL.md +103 -0
- package/skills/take-screenshots/agents/openai.yaml +4 -0
- package/skills/take-screenshots/references/adding-capture.md +121 -0
- package/src/ci/command.ts +96 -0
- package/src/ci/timings.ts +174 -0
- package/src/cli.ts +15 -2
- package/src/perf/graph.ts +13 -3
- package/src/permissions/catalog.ts +3 -1
- package/src/screenshots/build.ts +4 -3
- package/src/screenshots/store/capture.ts +317 -0
- package/src/screenshots/store/clones.ts +145 -0
- package/src/screenshots/store/command.ts +317 -0
- package/src/screenshots/store/git.ts +14 -0
- package/src/screenshots/store/link.ts +201 -0
- package/src/screenshots/store/lock.ts +94 -0
- package/src/screenshots/store/namespace.ts +311 -0
- package/src/screenshots/store/record.ts +157 -0
- package/src/screenshots/store/store.ts +47 -0
- package/src/screenshots/store/targets.ts +68 -0
- package/src/skills/bundled.ts +11 -1
- package/src/system/checkouts.ts +29 -7
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@ agent-tool is a command-line tool and a set of portable skills for repositories
|
|
|
4
4
|
where Claude Code, Codex, OpenCode, or Hermes make the changes. It provides shared Git,
|
|
5
5
|
GitHub, review, validation, and release workflows: independent agent reviews of
|
|
6
6
|
a committed branch, guarded pushes and squash merges of the exact reviewed
|
|
7
|
-
commit, package versioning, brand image rendering, screenshot
|
|
8
|
-
framework-free gallery, safe disk
|
|
9
|
-
|
|
10
|
-
stays in `agent-tool.json`; the
|
|
11
|
-
reviewed changes.
|
|
7
|
+
commit, package versioning, brand image rendering, screenshot capture into a
|
|
8
|
+
store every clone shares and staging with a framework-free gallery, safe disk
|
|
9
|
+
cleanup, page-load measurement, a live SEO probe for websites, and compact
|
|
10
|
+
output for noisy commands. Repository policy stays in `agent-tool.json`; the
|
|
11
|
+
portable skills coordinate independently reviewed changes.
|
|
12
12
|
|
|
13
13
|
## Quick start
|
|
14
14
|
|
|
@@ -89,8 +89,9 @@ validation suite, and release procedures.
|
|
|
89
89
|
- [Development](docs/development.md): setup, source layout, validation, and release
|
|
90
90
|
procedures for this package.
|
|
91
91
|
- [Images](docs/images.md): declarative brand sources and generated outputs.
|
|
92
|
-
- [Screenshots](docs/screenshots.md):
|
|
93
|
-
website, and the gallery and carousel web
|
|
92
|
+
- [Screenshots](docs/screenshots.md): the shared capture store, staging
|
|
93
|
+
captured screenshots into a website, and the gallery and carousel web
|
|
94
|
+
components that show them.
|
|
94
95
|
- [Permissions](docs/permissions.md): which commands run without approval in
|
|
95
96
|
Claude Code and Codex, and the dependency commands that enforce it.
|
|
96
97
|
- [Dependency maintenance](docs/dependency-upgrades.md): active compatibility
|
package/package.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: optimize-ci
|
|
3
|
+
description: Cut a repository's CI wall-clock time in measured rounds - find the job that holds the critical path across recent runs, then split, parallelize, cache, or gate it without checking less, shipping each change through ship-pr. Use when the user asks to speed up CI, a pipeline, or required checks; not for making individual tests faster, production performance, or page loads (performance-pass).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Optimize CI
|
|
7
|
+
|
|
8
|
+
A CI pass makes developers wait less for the same verdict. Every test, check,
|
|
9
|
+
and required job that ran before still runs; what changes is where and when it
|
|
10
|
+
runs and what is reused. A faster pipeline that checks less is a regression,
|
|
11
|
+
not a win.
|
|
12
|
+
|
|
13
|
+
## Measuring
|
|
14
|
+
|
|
15
|
+
`agent-tool ci timings` reads GitHub Actions through `gh` and changes nothing.
|
|
16
|
+
|
|
17
|
+
| Command | Shows |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `ci timings --workflow <file> --gate <job> [--event pull_request] [--limit 80]` | Over the latest successful first-attempt runs: wall clock (median, p90), the lane that finished last in each run, and every job's duration, how often it took at least `--threshold` minutes (did real work rather than replay a cache), and how long it waited to start |
|
|
20
|
+
| `ci timings --run <id>` | One run's jobs, longest first, with their steps |
|
|
21
|
+
| `ci timings --job <id>` | One job's log: which Turbo tasks executed and which replayed from cache, and Bun test files ranked by summed case time |
|
|
22
|
+
|
|
23
|
+
A lane is a job name without shard counters, so `Test (api 1/3)` and
|
|
24
|
+
`Test (api 2/3)` both count as `Test (api)`.
|
|
25
|
+
|
|
26
|
+
## Procedure
|
|
27
|
+
|
|
28
|
+
1. Scope. Read the repository's guidance and CI policy: required checks, any
|
|
29
|
+
aggregate gate job, path filters, cache bridges, and merge rules. The target
|
|
30
|
+
is the wall clock developers wait on: the median and p90 of pull-request
|
|
31
|
+
runs, measured to the gate job.
|
|
32
|
+
2. Baseline. Run `ci timings` over 50 to 80 runs, pull requests and the default
|
|
33
|
+
branch separately. Record wall median and p90, `lastToFinish`, the top jobs'
|
|
34
|
+
medians, and `overThresholdShare`. A scheduled uncached run, where the
|
|
35
|
+
repository has one, shows each job's cost without cache replay.
|
|
36
|
+
3. Find the critical path. The lane that finishes last in most runs is the
|
|
37
|
+
target; break it down with `--run` (which step) and `--job` (which task or
|
|
38
|
+
test file). Then name the next two or three lanes: removing the first exposes
|
|
39
|
+
them, so plan a round that brings all of them under the target.
|
|
40
|
+
4. Choose levers, safest first:
|
|
41
|
+
- Split serial work across runners. A long suite hidden in a catch-all job
|
|
42
|
+
sets that job's length; give it its own matrix entries. Balance shards by
|
|
43
|
+
measured time, not file count (Bun's `--shard` with `--timings`,
|
|
44
|
+
Playwright's `--shard` from spec durations): a count split of uneven files
|
|
45
|
+
is lopsided. No shard is shorter than its longest file, so split that file
|
|
46
|
+
when its cases are independent.
|
|
47
|
+
- Use the cores the runner has. Check effective parallelism: test runners'
|
|
48
|
+
CI defaults (Playwright uses half the cores), tool flags (TLC
|
|
49
|
+
`-workers 1`), and pool sizes. Raise them only with measured memory
|
|
50
|
+
headroom, and keep timing-sensitive end-to-end suites on their own runners
|
|
51
|
+
rather than crowding one.
|
|
52
|
+
- Schedule longest first in any pool, so a long item never starts last.
|
|
53
|
+
- Cache what every run rebuilds: toolchains, browsers, package stores,
|
|
54
|
+
compiler output (Xcode DerivedData and SwiftPM, Gradle), and task results.
|
|
55
|
+
Key each cache on exactly what its output depends on.
|
|
56
|
+
- Keep cache keys and path filters narrow. A file every pull request touches
|
|
57
|
+
(a lockfile that version bumps rewrite, version fields, embedded build
|
|
58
|
+
versions) silently defeats both. A job with a high `overThresholdShare`
|
|
59
|
+
that should usually be cached points to one.
|
|
60
|
+
- Remove duplicate work, such as one task in two jobs racing to fill the
|
|
61
|
+
same cache entry.
|
|
62
|
+
- Never delete or skip tests, loosen assertions or timeouts, drop a backend,
|
|
63
|
+
make a required check optional, or let a cache hit stand in for a check
|
|
64
|
+
whose inputs it does not cover.
|
|
65
|
+
5. Prove each change. Ship one lever per PR with `ship-pr`. A task cache can
|
|
66
|
+
hide the change, so measure on a run that executes the lane: changed task
|
|
67
|
+
arguments or inputs miss on their own; otherwise dispatch an uncached run.
|
|
68
|
+
Give baseline and after numbers with run ids in the PR body. Keep a policy
|
|
69
|
+
test beside the workflow that fails when a shard or gated job goes missing.
|
|
70
|
+
6. Re-measure after merging, with the same command over runs created after the
|
|
71
|
+
merge, and report the change in median and p90 wall clock. Start the next
|
|
72
|
+
round from step 3 with the new top lane.
|
|
73
|
+
7. Learn. Repository-specific findings go in that repository's guidance.
|
|
74
|
+
Cross-repository lessons go in [references/lessons.md](references/lessons.md)
|
|
75
|
+
here, by PR.
|
|
76
|
+
|
|
77
|
+
## Pitfalls
|
|
78
|
+
|
|
79
|
+
- GitHub Actions caches are scoped. A pull request reads entries from its own
|
|
80
|
+
ref and the default branch, never another pull request's, and one that starts
|
|
81
|
+
before the default branch's run finishes misses the entries that run is still
|
|
82
|
+
writing. Check timing before calling a miss a key bug.
|
|
83
|
+
- Turbo and Nx hash task arguments, so shards cache independently only when the
|
|
84
|
+
shard argument reaches the task.
|
|
85
|
+
- A cached job still costs a runner, its setup, and a concurrency slot.
|
|
86
|
+
Account limits, macOS especially, queue jobs as shards multiply: compare
|
|
87
|
+
`startLagSeconds` p90 before and after, and let path filters skip lanes a
|
|
88
|
+
change cannot affect.
|
|
89
|
+
- A re-run attempt mixes timestamps from several attempts; `ci timings` leaves
|
|
90
|
+
re-runs out, and manual analysis should too.
|
|
91
|
+
- Turbo buffers a task's output until it ends, so log timestamps show
|
|
92
|
+
completion, not progress. Use the test runner's own case durations.
|
|
93
|
+
- Turning a job into a matrix renames its check (`Web E2E` becomes
|
|
94
|
+
`Web E2E (1/3)`). Update branch protection, rulesets, and the merge helper's
|
|
95
|
+
required checks together, or require an aggregate gate job instead.
|
|
96
|
+
- Changing a shard count reshuffles which files share a worker; with test
|
|
97
|
+
isolation off, that can surface leaks between files. Run every new shard
|
|
98
|
+
composition before pushing.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
interface:
|
|
2
|
+
display_name: "Optimize CI"
|
|
3
|
+
short_description: "Cut CI wall-clock time in measured rounds without checking less"
|
|
4
|
+
default_prompt: "Use $optimize-ci to make this repository's CI faster: measure which job holds the wall clock, change one lever, prove it on CI, and ship."
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# CI lessons
|
|
2
|
+
|
|
3
|
+
Cross-repository findings from CI passes, newest first. Each names the
|
|
4
|
+
repository and PR it came from; recheck before relying on one.
|
|
5
|
+
|
|
6
|
+
## A catch-all job can hide the whole critical path
|
|
7
|
+
|
|
8
|
+
tearleads (a2f0/tearleads, baseline 2026-11-26) ran its long suites in their own
|
|
9
|
+
sharded jobs, but the job holding "the remaining package tests" finished last
|
|
10
|
+
in 60 of 80 runs at a median of 18.6 minutes. `ci timings --job` showed why: one
|
|
11
|
+
package's end-to-end suite ran 1158 s of serial files inside it, while every
|
|
12
|
+
sharded job finished in under 9 minutes. Look inside the slowest job before
|
|
13
|
+
adding shards elsewhere.
|
|
14
|
+
|
|
15
|
+
## Version bumps defeat path filters and task caches
|
|
16
|
+
|
|
17
|
+
The same repository bumps every changed package's version and refreshes its
|
|
18
|
+
lockfile in every pull request. Its path classifier treated any lockfile change
|
|
19
|
+
as touching everything, so lanes meant to run only for native or
|
|
20
|
+
infrastructure changes ran in 72 to 74 of 80 runs, and a browser suite whose
|
|
21
|
+
inputs included every package manifest executed in 95% of runs. When a lane
|
|
22
|
+
that should be rare has a high `overThresholdShare`, look for a file that every
|
|
23
|
+
pull request rewrites.
|
|
24
|
+
|
|
25
|
+
## Tool defaults leave runner cores idle
|
|
26
|
+
|
|
27
|
+
On 4-vCPU runners, Playwright's CI default of half the cores ran 282 tests on 2
|
|
28
|
+
workers, and the TLC model checker ran each model with `-workers 1`, two models
|
|
29
|
+
at a time. Read the effective parallelism of every long step before buying
|
|
30
|
+
bigger runners.
|
|
@@ -24,7 +24,7 @@ predates the command, run `bunx --bun @a2f0/agent-tool@latest perf`.
|
|
|
24
24
|
| Command | Does |
|
|
25
25
|
| --- | --- |
|
|
26
26
|
| `serve <dir> [--port N] [--http1]` | Serves a production build over HTTP/2 with gzip (compressed before the first request) and ETag revalidation, as a CDN does, never following links out of the directory. Start it with `agent-tool proc start --label serve -- node_modules/.bin/agent-tool perf serve <dir>` and stop it with `agent-tool proc stop`. |
|
|
27
|
-
| `measure <url> --ready <js>` | Cold, cache-disabled loads timed from the start of navigation (it waits only for the commit, never the `load` event); prints the median time until the `--ready` expression is true, requests, bytes, when the finished requests ended, and how many were still pending. `--waterfall` lists requests; `--profile` adds
|
|
27
|
+
| `measure <url> --ready <js>` | Cold, cache-disabled loads timed from the start of navigation (it waits only for the commit, never the `load` event); prints the median time until the `--ready` expression is true, requests, bytes, when the finished requests ended, and how many were still pending. `--waterfall` lists requests; `--profile` adds CPU self and inclusive times from an extra, unsampled run; `--json` prints the report as JSON. |
|
|
28
28
|
| `shot <url> --ready <js> --out <png>` | Screenshot of the ready state with a seeded `Math.random`, for fidelity diffs. `--eval <js>` runs an interaction first (switch a mode on); `--hide <css>` hides random decoration, reaching into open shadow roots. |
|
|
29
29
|
| `diff <a.png> <b.png>` | Counts differing pixels, and the busiest 50-pixel cells, without a browser; exits 1 on any. |
|
|
30
30
|
| `graph <dir> <entry...> [--out <file>]` | Relative static and dynamic import closure of ES modules, as JSON. |
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: take-screenshots
|
|
3
|
+
description: Capture a repository's app screenshots once into the shared matrix-artifacts store, so every clone builds and deploys the newest captures, and check a capture's provenance before a deploy. Use when asked to take, refresh, or check screenshots, before deploying a site or store listing that shows them, or when adding screenshot capture to a repository.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Take Screenshots
|
|
7
|
+
|
|
8
|
+
Screenshots are captured once, in any clone, into the shared store's
|
|
9
|
+
`matrix-artifacts/<project>/screenshots`, beside the matrix workspace (or
|
|
10
|
+
beside the clone outside one). Every clone of the repository links its
|
|
11
|
+
gitignored `.screenshots` there, so a website deploy or
|
|
12
|
+
store upload in another clone publishes the same, newest captures without
|
|
13
|
+
recapturing. Brand images are not part of this: they render from
|
|
14
|
+
`assets/brand/*.svg` in each clone.
|
|
15
|
+
|
|
16
|
+
## Run it
|
|
17
|
+
|
|
18
|
+
`agent-tool screenshots status|link|capture` does the work; run the
|
|
19
|
+
repository's pinned agent-tool (`bun run agent-tool screenshots ...` or
|
|
20
|
+
`node_modules/.bin/agent-tool screenshots ...`). `link` and `capture` are dry
|
|
21
|
+
runs until `--apply`; `--json` gives agents the report.
|
|
22
|
+
|
|
23
|
+
- From any clone: `agent-tool screenshots <command>` covers that repository.
|
|
24
|
+
- From a matrix workspace: `agent-tool screenshots <command> [checkout...]`;
|
|
25
|
+
with no names it covers every checkout that captures.
|
|
26
|
+
- If the pinned agent-tool predates these commands, run
|
|
27
|
+
`bunx --bun @a2f0/agent-tool@latest screenshots <command>`.
|
|
28
|
+
|
|
29
|
+
| Command | Does |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `status [repo...] [--all]` | Link state of each clone and its newest capture relative to HEAD |
|
|
32
|
+
| `link [repo...] [--all] [--apply] [--supersede]` | Point `.screenshots` at the store; moves an existing capture into an empty store, or with `--supersede` to `<project>/superseded/` |
|
|
33
|
+
| `capture [repo] [--apply] [--allow-dirty] [-- args...]` | Once its checks pass, link every clone of the store's projects that has no `.screenshots`, then run the repository's `screenshots` package script under the project lock and record `capture.json` |
|
|
34
|
+
|
|
35
|
+
`--all` selects every clone on this machine whose project the store already
|
|
36
|
+
holds, beside the store or in a matrix workspace's checkouts, worktrees
|
|
37
|
+
included: `link --all --apply` links them all in one run.
|
|
38
|
+
|
|
39
|
+
`MATRIX_ARTIFACTS_DIR` overrides the store location, and `--project <name>`
|
|
40
|
+
names the namespace of a repository without a GitHub origin. `status` exits 1
|
|
41
|
+
while a selected clone is not linked, `link` while one is blocked, and an
|
|
42
|
+
applied `capture` when it did not finish `complete`; each exits 2 when it
|
|
43
|
+
cannot run at all.
|
|
44
|
+
|
|
45
|
+
## Procedure
|
|
46
|
+
|
|
47
|
+
1. `status` first. If the clone is not `linked`, run `link`, then
|
|
48
|
+
`link --apply`; `capture` links a clone with no `.screenshots` itself, and
|
|
49
|
+
`status --all` or `link --all` covers every clone on this machine. A
|
|
50
|
+
`blocked` result names what a person must decide (two
|
|
51
|
+
different captures: compare their dates and commits, and if the store's is
|
|
52
|
+
newer rerun with `--supersede`, a link that points elsewhere, a `.screenshots/` ignore
|
|
53
|
+
pattern that needs its trailing slash removed in a PR).
|
|
54
|
+
2. Decide whether to capture. If the newest capture is `complete`, `merged`,
|
|
55
|
+
and no screens changed since its commit, reuse it: that is the point of the
|
|
56
|
+
store. Recapture after UI, seed data, or capture-code changes, after a
|
|
57
|
+
`failed` capture, or when asked.
|
|
58
|
+
3. Commit first: capture refuses a dirty tree, because the shared store would
|
|
59
|
+
publish uncommitted work. `--allow-dirty` is for a local-only look: it marks the
|
|
60
|
+
capture `dirty`, which builds refuse, so recapture from a commit before
|
|
61
|
+
anyone deploys.
|
|
62
|
+
4. Read the repository's capture docs for prerequisites (simulators, Maestro,
|
|
63
|
+
Playwright browsers, seed data, mise-pinned tools). Maestro drives one
|
|
64
|
+
device at a time on this machine: check for a running `maestro` first.
|
|
65
|
+
5. Run `capture` as a dry run, then with `--apply` through output capture
|
|
66
|
+
(`agent-tool run --label screenshots -- agent-tool screenshots capture
|
|
67
|
+
--apply`, with the repository's pinned agent-tool for both). Captures take
|
|
68
|
+
minutes; run them in the background and do not start a second one for the
|
|
69
|
+
same project (the lock refuses it).
|
|
70
|
+
6. Verify the result, not just the exit code: `status` shows `complete` at your
|
|
71
|
+
commit, and spot-check a few images (open them; check light and dark, each
|
|
72
|
+
layout, and the expected dimensions).
|
|
73
|
+
7. Report the capture's commit, whether it was partial (`args`), and which
|
|
74
|
+
clones see it. Before a deploy, quote `status` for the deploying clone.
|
|
75
|
+
|
|
76
|
+
## Rules
|
|
77
|
+
|
|
78
|
+
- Never run a repository's `screenshots` package script directly for a shared
|
|
79
|
+
capture; the lock and `capture.json` keep clones from publishing a partial
|
|
80
|
+
or concurrent capture.
|
|
81
|
+
- Never commit screenshots, copy them into a repository, or delete the store.
|
|
82
|
+
Never remove `.screenshots` itself; capture code clears files inside it.
|
|
83
|
+
- Builds and deploys never capture. `agent-tool screenshots build`, which
|
|
84
|
+
stages screenshots into a website, reads `.screenshots/capture.json` before
|
|
85
|
+
and after copying, and refuses `running`, `failed`, `incomplete`, or `dirty`
|
|
86
|
+
captures and a record that changed meanwhile.
|
|
87
|
+
- Before a deploy that publishes screenshots, run `status` and report the
|
|
88
|
+
capture's commit; recapture only when the screens it shows changed since.
|
|
89
|
+
|
|
90
|
+
## Adding capture to a repository
|
|
91
|
+
|
|
92
|
+
Follow `references/adding-capture.md`: the package script, ignore pattern, and
|
|
93
|
+
output layout every repository shares, and the Playwright (web) and Maestro
|
|
94
|
+
(native) patterns tearleads and nc use. In a matrix workspace, its audit checks
|
|
95
|
+
it with `bun run audit --rule screenshots-store`.
|
|
96
|
+
|
|
97
|
+
## Ownership
|
|
98
|
+
|
|
99
|
+
agent-tool (`a2f0/agent-tool`) owns this skill at `skills/take-screenshots/`
|
|
100
|
+
and the commands at `src/screenshots/store/`, with their tests beside them;
|
|
101
|
+
`agent-tool skills install --apply` installs it in each adopting repository.
|
|
102
|
+
The store's layout and record are described in its `docs/screenshots.md`.
|
|
103
|
+
Change them there, never in an installed copy.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
interface:
|
|
2
|
+
display_name: "Take Screenshots"
|
|
3
|
+
short_description: "Capture app screenshots once into the shared matrix-artifacts store"
|
|
4
|
+
default_prompt: "Use $take-screenshots to check this repository's screenshots and capture them into the shared store if they are stale."
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Adding screenshot capture to a repository
|
|
2
|
+
|
|
3
|
+
Every repository that captures screenshots follows one contract, so
|
|
4
|
+
`agent-tool screenshots capture`, the shared store, and the matrix audit work
|
|
5
|
+
the same way everywhere. The capture code itself stays in the repository: it knows the
|
|
6
|
+
app's routes, seed data, and devices.
|
|
7
|
+
|
|
8
|
+
## Contract
|
|
9
|
+
|
|
10
|
+
- Root package script `screenshots` runs the whole capture and forwards extra
|
|
11
|
+
arguments (a layout or project filter) to the runner.
|
|
12
|
+
- It writes below `<root>/.screenshots/`, resolved from the repository root,
|
|
13
|
+
never from the current directory. Honor `SCREENSHOT_OUTPUT_DIR` when the
|
|
14
|
+
runner already supports it, defaulting to `.screenshots`.
|
|
15
|
+
- The root `.gitignore` lists `.screenshots` with no trailing slash, so the
|
|
16
|
+
symlink to the store is ignored too.
|
|
17
|
+
- Capture code removes or replaces files inside `.screenshots`, never
|
|
18
|
+
`.screenshots` itself, and leaves `capture.json` alone.
|
|
19
|
+
- Builds never capture. A `build:*` or deploy script reads `.screenshots`
|
|
20
|
+
only. A build that publishes screenshots checks `.screenshots/capture.json`
|
|
21
|
+
before and after copying and prints the capture's commit (see
|
|
22
|
+
[deploy guard and gallery](#deploy-guard-and-gallery)).
|
|
23
|
+
- Browser phone layouts are captured at the full 390x844 screen, so framed
|
|
24
|
+
phones keep a real phone's proportions; native store captures keep each
|
|
25
|
+
device's required size.
|
|
26
|
+
- Build caches stay honest: a cached task that copies screenshots hashes them
|
|
27
|
+
through the link, or runs uncached (see [build caches](#build-caches)).
|
|
28
|
+
- Document the prerequisites and output layout in the repository's own docs,
|
|
29
|
+
and point agents at this skill from `AGENTS.md` in one sentence.
|
|
30
|
+
|
|
31
|
+
## Layout
|
|
32
|
+
|
|
33
|
+
Use one of two shapes, named by what consumes them:
|
|
34
|
+
|
|
35
|
+
| Consumer | Layout | Example |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| Website gallery or docs | `<layout>/<theme>/<screen>.png`, layouts `web`, `ipad`, `mobile`, themes `light`, `dark` | tearleads `.screenshots/mobile/dark/home.png` |
|
|
38
|
+
| Store listings (fastlane) | `<platform>/<device>/<NN-screen>[-dark].png` | nc `.screenshots/ios/iphone/01-home.png` |
|
|
39
|
+
|
|
40
|
+
Screen names are kebab-case and stable: a website keeps an allowlist and order
|
|
41
|
+
of them, so renaming one is a change to both.
|
|
42
|
+
|
|
43
|
+
## Web capture with Playwright
|
|
44
|
+
|
|
45
|
+
The pattern tearleads uses (`packages/app-web/playwright.screenshots.config.ts`
|
|
46
|
+
and `packages/app-web/screenshots/`):
|
|
47
|
+
|
|
48
|
+
- A separate Playwright config, so capture never runs in the e2e suite:
|
|
49
|
+
`workers: 1`, `retries: 0`, a long test timeout, fixed `locale` and
|
|
50
|
+
`timezoneId`.
|
|
51
|
+
- One project per layout:
|
|
52
|
+
- `web`: `viewport: { width: 1440, height: 900 }`, `deviceScaleFactor: 2`;
|
|
53
|
+
- `ipad`: `...devices["iPad Pro 11"]`;
|
|
54
|
+
- `mobile`: `...devices["iPhone 13"]` with `viewport` and `screen` set to
|
|
55
|
+
`{ width: 390, height: 844 }`, the full phone screen of an installed app
|
|
56
|
+
(1170x2532 PNGs). The profile's own 390x664 viewport is Safari's visible
|
|
57
|
+
area and makes framed phones look too wide;
|
|
58
|
+
- `browserName: "chromium"` for all three, so output does not depend on
|
|
59
|
+
WebKit; the device profiles still give touch input, viewport, and scale.
|
|
60
|
+
- Its own `webServer` entries on fixed, repository-specific ports with
|
|
61
|
+
`reuseExistingServer: false`, against deterministic seed data or in-memory
|
|
62
|
+
backends, never staging or production.
|
|
63
|
+
- Each theme is pinned through the app's stored preference and a reload, then
|
|
64
|
+
verified (for example on `data-theme`) before capturing.
|
|
65
|
+
- Animations disabled with injected CSS after every navigation; wait for real
|
|
66
|
+
readiness (data rendered, images decoded) instead of fixed sleeps.
|
|
67
|
+
- `page.screenshot({ path })` for routed layouts, or an element screenshot for
|
|
68
|
+
a windowed desktop app; `mkdir` the theme directory first.
|
|
69
|
+
|
|
70
|
+
## Native capture with Maestro
|
|
71
|
+
|
|
72
|
+
The pattern nc uses (`scripts/testing/takeIosScreenshots.sh`,
|
|
73
|
+
`takeAndroidScreenshots.sh`, `maestro/screenshots/`):
|
|
74
|
+
|
|
75
|
+
- Dedicated, named simulators and emulators created on demand, so captures
|
|
76
|
+
never depend on a day-to-day device's state; shut them down on exit.
|
|
77
|
+
- Status bar overridden to 9:41, full signal, battery discharging at 100%
|
|
78
|
+
(`xcrun simctl status_bar ... override`; Android demo mode).
|
|
79
|
+
- Appearance set per capture (`xcrun simctl ui <udid> appearance dark`), with a
|
|
80
|
+
short settle before the screenshot.
|
|
81
|
+
- Maestro flows only navigate; the shell script takes the screenshot
|
|
82
|
+
(`xcrun simctl io <udid> screenshot --mask=ignored`, `adb exec-out screencap`).
|
|
83
|
+
- Validate every file: the exact store size for the device, and no alpha
|
|
84
|
+
channel, which App Store Connect and Play reject.
|
|
85
|
+
- Maestro's driver uses port 7001 for every device, so one Maestro run drives
|
|
86
|
+
this machine at a time: check for a running `maestro` before starting.
|
|
87
|
+
|
|
88
|
+
## Deploy guard and gallery
|
|
89
|
+
|
|
90
|
+
A website that publishes screenshots stages them with
|
|
91
|
+
`agent-tool screenshots build <target>` from the pinned `@a2f0/agent-tool`
|
|
92
|
+
(0.1.32 or later), configured in the `screenshots` section of
|
|
93
|
+
`agent-tool.json`, rather than its own copy script. It copies the allowlisted
|
|
94
|
+
`<project>/<theme>/<screen>.png` files with content-hashed URLs and writes a
|
|
95
|
+
manifest, and it checks `.screenshots/capture.json` before and after copying.
|
|
96
|
+
Every capture writes a `running` record before it touches an image, so an
|
|
97
|
+
unchanged `complete` record on both sides proves no capture overlapped the
|
|
98
|
+
copy. It refuses a capture that is not complete, names no commit, is
|
|
99
|
+
dirty, or changed meanwhile, and a linked, non-empty store with no record
|
|
100
|
+
(its images have no known commit, as after `link` moves an older capture into
|
|
101
|
+
the store). A missing or plain `.screenshots` (CI, an unlinked clone) builds
|
|
102
|
+
with what it holds, or an empty manifest.
|
|
103
|
+
|
|
104
|
+
Pages render that manifest with the package's framework-free elements from
|
|
105
|
+
`@a2f0/agent-tool/screenshots/gallery` and its stylesheet:
|
|
106
|
+
`<screenshot-gallery>` for a `/screenshots/[...slug]` route (deep links per
|
|
107
|
+
project and screen, a scrolling stage, a filmstrip, phone bezels) and
|
|
108
|
+
`<screenshot-carousel>` for a looping row of every phone screen on a home
|
|
109
|
+
page. Sites theme them with `--shots-*` custom properties. The package's
|
|
110
|
+
`docs/screenshots.md` has the configuration, attributes, and an Astro example;
|
|
111
|
+
tearleads and balebase are the references.
|
|
112
|
+
|
|
113
|
+
A non-website consumer (a store upload) that copies captures itself must apply
|
|
114
|
+
the same before-and-after record check.
|
|
115
|
+
|
|
116
|
+
## Build caches
|
|
117
|
+
|
|
118
|
+
Turbo and similar caches hash declared inputs. A task that stages screenshots
|
|
119
|
+
must see changes made through the link: confirm that its input globs follow
|
|
120
|
+
the `.screenshots` symlink (recapture one screen and check the task misses its
|
|
121
|
+
cache), or mark the staging task `cache: false`.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** `agent-tool ci timings`: read-only GitHub Actions timing reports; CI_TIMINGS_USAGE lists the modes. */
|
|
2
|
+
import { writeSync } from "node:fs";
|
|
3
|
+
import { runRead } from "../git/prContext";
|
|
4
|
+
import { assert, json, option, output, repository } from "../workflows/core";
|
|
5
|
+
import { parseJobLog, runSteps, summarizeRuns, type TimedJob, type TimedRun } from "./timings";
|
|
6
|
+
|
|
7
|
+
export const CI_TIMINGS_USAGE = `Usage: agent-tool ci timings [--workflow <file|name|id>] [--branch <name>] [--event <event>] [--limit <n>] [--gate <job>] [--threshold <minutes>]
|
|
8
|
+
agent-tool ci timings --run <run-id> [--min-seconds <n>]
|
|
9
|
+
agent-tool ci timings --job <job-id> [--top <n>]
|
|
10
|
+
|
|
11
|
+
Without --run or --job, summarizes the latest successful first-attempt runs
|
|
12
|
+
(default 50, at most 200): wall clock, the lane that finished last, and each
|
|
13
|
+
job's duration, how often it took at least --threshold minutes (default 2),
|
|
14
|
+
and how long it waited to start. --run lists one run's jobs and their steps
|
|
15
|
+
of at least --min-seconds (default 10). --job reads one job's log: Turbo task
|
|
16
|
+
cache results and Bun test files ranked by summed case time (--top, default 25).
|
|
17
|
+
Prints JSON; reads GitHub through gh and changes nothing.`;
|
|
18
|
+
|
|
19
|
+
const JOB_FIELDS = "id, name, conclusion, startedAt: .started_at, completedAt: .completed_at";
|
|
20
|
+
const STEP_FIELDS = "steps: [(.steps // [])[] | {name, conclusion, startedAt: .started_at, completedAt: .completed_at}]";
|
|
21
|
+
|
|
22
|
+
function integer(value: string | undefined, name: string, fallback: number, min: number, max: number): number {
|
|
23
|
+
const parsed = value === undefined ? fallback : Number(value);
|
|
24
|
+
assert(Number.isSafeInteger(parsed) && parsed >= min && parsed <= max, `${name} must be an integer from ${min} to ${max}.`);
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function id(value: string, name: string): string {
|
|
29
|
+
assert(/^\d+$/.test(value), `${name} must be a numeric id.`);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function jobs(repo: string, runId: number | string, steps: boolean): TimedJob[] {
|
|
34
|
+
const fields = steps ? `${JOB_FIELDS}, ${STEP_FIELDS}` : JOB_FIELDS;
|
|
35
|
+
return runRead("gh", ["api", "--paginate", `repos/${repo}/actions/runs/${runId}/jobs?per_page=100`, "--jq", `.jobs[] | {${fields}}`])
|
|
36
|
+
.split("\n").filter(Boolean).map(line => JSON.parse(line) as TimedJob);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Successful runs, newest first, a page of up to 100 at a time until `limit`; `read` is gh's JSON reader, replaced in tests. */
|
|
40
|
+
export function listRuns(repo: string, filters: { workflow?: string; branch?: string; event?: string }, limit: number, read: <T>(args: string[]) => T = json): Omit<TimedRun, "jobs">[] {
|
|
41
|
+
const base = filters.workflow ? `repos/${repo}/actions/workflows/${encodeURIComponent(filters.workflow)}/runs` : `repos/${repo}/actions/runs`;
|
|
42
|
+
const query = new URLSearchParams({ status: "success", per_page: String(Math.min(limit, 100)) });
|
|
43
|
+
if (filters.branch) query.set("branch", filters.branch);
|
|
44
|
+
if (filters.event) query.set("event", filters.event);
|
|
45
|
+
const runs: Omit<TimedRun, "jobs">[] = [];
|
|
46
|
+
for (let page = 1; runs.length < limit; page++) {
|
|
47
|
+
query.set("page", String(page));
|
|
48
|
+
const batch = read<Omit<TimedRun, "jobs">[]>(["api", `${base}?${query}`, "--jq", "[.workflow_runs[] | {id, event, attempt: .run_attempt, createdAt: .created_at}]"]);
|
|
49
|
+
assert(Array.isArray(batch), "Could not list workflow runs.");
|
|
50
|
+
runs.push(...batch);
|
|
51
|
+
if (batch.length < Math.min(limit, 100)) break;
|
|
52
|
+
}
|
|
53
|
+
return runs.slice(0, limit);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Run one `ci timings` mode and print its JSON report. */
|
|
57
|
+
export function ciTimingsCommand(argv: string[]): number {
|
|
58
|
+
const args = [...argv];
|
|
59
|
+
if (args.includes("--help") || args.includes("-h")) { writeSync(1, `${CI_TIMINGS_USAGE}\n`); return 0; }
|
|
60
|
+
const run = option(args, "--run"), job = option(args, "--job");
|
|
61
|
+
const workflow = option(args, "--workflow"), branch = option(args, "--branch"), event = option(args, "--event"), gate = option(args, "--gate");
|
|
62
|
+
const limit = option(args, "--limit"), threshold = option(args, "--threshold"), minSeconds = option(args, "--min-seconds"), top = option(args, "--top");
|
|
63
|
+
assert(!args.length, `Unexpected ci timings argument '${args[0]}'.\n\n${CI_TIMINGS_USAGE}`);
|
|
64
|
+
assert(!(run && job), "Pass --run or --job, not both.");
|
|
65
|
+
const summaryOnly = [workflow, branch, event, gate, limit, threshold];
|
|
66
|
+
// Every argument is checked before the first GitHub read.
|
|
67
|
+
if (run !== undefined) {
|
|
68
|
+
assert(summaryOnly.every(value => value === undefined) && top === undefined, "--run takes only --min-seconds.");
|
|
69
|
+
const runId = id(run, "--run");
|
|
70
|
+
const floor = integer(minSeconds, "--min-seconds", 10, 0, 86_400);
|
|
71
|
+
const repo = repository().nameWithOwner;
|
|
72
|
+
const { createdAt } = json<{ createdAt: string }>(["api", `repos/${repo}/actions/runs/${runId}`, "--jq", "{createdAt: .created_at}"]);
|
|
73
|
+
output({ repo, run: Number(runId), jobs: runSteps(createdAt, jobs(repo, runId, true), floor) });
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
if (job !== undefined) {
|
|
77
|
+
assert(summaryOnly.every(value => value === undefined) && minSeconds === undefined, "--job takes only --top.");
|
|
78
|
+
const jobId = id(job, "--job");
|
|
79
|
+
const count = integer(top, "--top", 25, 1, 10_000);
|
|
80
|
+
const repo = repository().nameWithOwner;
|
|
81
|
+
// Bun and Turbo color their output; gh refuses to print escape sequences unless told they are expected.
|
|
82
|
+
const log = parseJobLog(runRead("gh", ["api", "--allow-escape-sequences", `repos/${repo}/actions/jobs/${jobId}/logs`]));
|
|
83
|
+
const misses = log.tasks.filter(task => task.cache !== "hit").map(task => task.task);
|
|
84
|
+
output({ repo, job: Number(jobId), tasks: { total: log.tasks.length, cached: log.tasks.length - misses.length, executed: misses }, files: log.files.slice(0, count), fileCount: log.files.length, casesWithoutDuration: log.casesWithoutDuration });
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
assert(minSeconds === undefined && top === undefined, "--min-seconds belongs to --run and --top to --job.");
|
|
88
|
+
const thresholdMinutes = Number(threshold ?? 2);
|
|
89
|
+
assert(Number.isFinite(thresholdMinutes) && thresholdMinutes > 0, "--threshold must be a positive number of minutes.");
|
|
90
|
+
const count = integer(limit, "--limit", 50, 1, 200);
|
|
91
|
+
const repo = repository().nameWithOwner;
|
|
92
|
+
const runs = listRuns(repo, { workflow, branch, event }, count)
|
|
93
|
+
.map(item => ({ ...item, jobs: item.attempt > 1 ? [] : jobs(repo, item.id, false) }));
|
|
94
|
+
output({ repo, workflow: workflow ?? null, branch: branch ?? null, event: event ?? null, gate: gate ?? null, ...summarizeRuns(runs, { gate, thresholdMinutes }) });
|
|
95
|
+
return 0;
|
|
96
|
+
}
|