Skip to content

Commit fd99f29

Browse files
committed
chore: add a skill that runs the cleanup audit and pass
1 parent fcd7071 commit fd99f29

4 files changed

Lines changed: 656 additions & 0 deletions

File tree

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
name: sourceorigin-cleanup
3+
description: >
4+
Run a repository-wide cleanup of SourceOrigin: an audit that measures the
5+
code and suggests fixes, then a cleanup pass where one agent per area opens
6+
focused, reviewed refactor PRs, a boundary lane cleans up between the crates
7+
and surfaces, and every bug found gets a GitHub issue and a fix PR. Use when
8+
asked for a cleanup or refactor pass, codebase stats or an audit, or to
9+
deduplicate or simplify SourceOrigin as a whole. Not for cleaning up a single
10+
PR or file.
11+
---
12+
13+
# SourceOrigin cleanup
14+
15+
You orchestrate a cleanup of the whole repository in two parts: an audit, then
16+
a cleanup pass. Run both unless the owner asks for one. Delegates write the
17+
code. You split the work, brief them, route reviews and report.
18+
19+
Work from a checkout of `origin/main` that contains this skill, since the
20+
delegates read their briefs from it. Keep a ledger in your scratchpad: each
21+
agent, branch, PR, review state and finding, and the files each task holds.
22+
Files are free once the task holding them has reported and its PRs touching them
23+
have merged. Start no task on files that aren't free. A forced edit outside an
24+
area (a renamed item's callers, a docs reference) is the exception: the agent
25+
holding those files rebases over it. After compaction, a usage limit or a T3
26+
restart, check the ledger and restart only what didn't finish.
27+
28+
Issues are GitHub issues in `sourceorigin-dev/sourceorigin`, titled like a
29+
Conventional Commit and labelled with their kind (`bug`, `refactor`) and the
30+
other labels that fit (`gh label list`).
31+
32+
## Audit
33+
34+
1. Measure: `python3 -I .agents/skills/sourceorigin-cleanup/scripts/stats.py .
35+
--json <scratchpad>/stats.json`. It needs `cloc`. Chart the result with
36+
`html_preview` and `html_render`, including growth over time from the
37+
JSON.
38+
2. Read the output, then check what the script can't count:
39+
- coverage, from the `rust-coverage` artifact of `main`'s latest CI run (or
40+
`just coverage`) and `just web test`
41+
- unused code and dependencies, with `just unused`
42+
- generated files missing from `.gitattributes`
43+
- which `expect` calls can really panic
44+
- duplication built up since the last pass, including between the Rust and
45+
TypeScript SDKs
46+
3. Send the owner the charts and a ranked list of suggestions, each with the
47+
numbers and paths behind it. Open nothing yet.
48+
4. For each suggestion the owner picks, start a thread with
49+
`t3_thread_launch`. Use Claude Opus 5.5 in a worktree off `origin/main`.
50+
Its message stands alone: the goal, the numbers, the scope and what to
51+
report. A thread that checks many sites reports a table of each site, its
52+
verdict and why.
53+
54+
Changes that move code in many areas, such as file splits, merge before the
55+
cleanup pass starts or go into the area agents' tasks.
56+
57+
## Cleanup pass
58+
59+
### Split
60+
61+
Start from this split and adjust it to the code. Split an area over about
62+
30,000 lines of source and tests along a module boundary (`stats.py` lists the
63+
modules of large areas), and merge small areas. Every file has exactly one
64+
owner.
65+
66+
| Area | Paths | Scope |
67+
| --- | --- | --- |
68+
| Sign-in and OIDC | `apps/auth-service/src/{oidc,passkey,federation,security,keys,sessions,grants}` | `auth` |
69+
| Accounts | the rest of `apps/auth-service`: `src/{account,clients,deletion,recovery,emails,notifications,pictures,history,handles}`, the root modules and `tests` | `auth` |
70+
| Operations | `apps/auth-service/src/{cli,config,jobs,deliveries,audit,alerts}` | `cli` or `auth` |
71+
| Admin | `apps/auth-service/src/{admin,web/admin}`, `crates/ui/src/admin` | `admin` |
72+
| Pages | the rest of `apps/auth-service/src/web` and `crates/ui`, `apps/auth-service/assets`, `apps/web`, `tests/browser` | `ui`, `web` or `browser` |
73+
| Database | `crates/database` | `database` |
74+
| SDKs | `crates/{auth-sdk,common,crypto}`, `packages/auth`, `tests/sdk-vectors` | `sdk`, `common` or `crypto` |
75+
| Tooling | every other hand-written file: `crates/telemetry`, `tools/xtask`, `infra`, `just`, `.github`, root files | `telemetry`, `infra`, or none: `refactor: …` |
76+
77+
Nobody edits `crates/database/migrations`, `snapshots/` or generated files by
78+
hand. `docs/` and Markdown belong to the docs lane.
79+
80+
Before you start the agents, run `rustup update stable`, `just install-tools`,
81+
`just install`, `just validate` and `just db test` on `origin/main`. If one
82+
fails, as it can under a new stable Clippy, have one Opus delegate fix it in a
83+
PR, review and ship it as in Review, and ask the owner to merge it first.
84+
85+
Open one GitHub issue for the pass, labelled `refactor`, and note its number
86+
`<n>`. Each PR says `Part of #<n>`. Each area agent opens several focused PRs,
87+
on branches named `refactor/<n>-<area>-<topic>`. Tell the owner the split in
88+
one message and start without waiting.
89+
90+
Every worktree compiles the workspace in its own target directory, on a
91+
machine with no swap. Pick one `CARGO_BUILD_JOBS` value for every agent that
92+
compiles, and pass it to each. 4 suits 8 implementers and their reviewers on
93+
16 cores and 58 GB as a start. Run at most 8 reviews at a time.
94+
95+
### Start the agents
96+
97+
Call `orchestrator_capabilities` once. For each area, start a `delegate_task`
98+
on Claude Opus 5.5 with `isolation: "worktree"` and `role: "implementation"`.
99+
The task says to follow `.agents/skills/sourceorigin-cleanup/references/agent-brief.md`.
100+
It names the area, paths, packages, branch prefix, title scope, tracking
101+
issue, what the other areas own, and `CARGO_BUILD_JOBS`.
102+
103+
Start a docs lane the same way, on `docs/<n>-cleanup`. It follows the
104+
`sourceorigin-docs` skill, fixes drift between the docs and the code, runs
105+
`just docs` and opens a draft PR. It reports stale `///` comments and clap
106+
help instead of editing them. Those comments sit in the area agents' files and
107+
feed the generated reference pages.
108+
109+
### Review
110+
111+
Review each focused PR on its own as its agent reports it. Call
112+
`link_pull_request` and start a review: a `delegate_task` on GPT 6.1 Sol with
113+
`role: "review"`, `isolation: "worktree"` and
114+
`target.options: { reasoningEffort: "high" }`. It follows
115+
`.agents/skills/sourceorigin-cleanup/references/review-brief.md`. Give it the
116+
PR number, the head SHA, the base branch (the parent PR's branch for a stacked
117+
PR), `CARGO_BUILD_JOBS`, and a focus list: every "unchanged" claim in the PR
118+
description, and every merged helper or test that could have changed
119+
behavior.
120+
121+
- Check each finding against the code before acting on it.
122+
- Send real findings to the implementer's thread with `t3_thread_send`.
123+
- After a fix that rewrites code, run a new, narrower review.
124+
- Judgment calls go to the owner, with your recommendation.
125+
- If Sol is over its limit, review with Opus instead and say so.
126+
127+
When a PR's review is clean and it is rebased, mark it ready. Follow its CI
128+
with `babysit-pr`, and update its `[!NOTE]` line to name who reviewed it. The
129+
owner merges, through the merge queue.
130+
131+
When something lands on `main`, have each agent rebase and apply its cleanup
132+
to the new code, and start the boundary themes and fixes whose files are now
133+
free. Review any logic the rebase merged. Suggest merging the SDKs and the
134+
database first, because the apps depend on them.
135+
136+
### Boundary lane
137+
138+
The area agents each see one area. Alongside them, start one more Opus
139+
delegate, `role: "research"`, to look at how the areas fit together, against
140+
`docs/dev/architecture/overview.md` and `docs/dev/rust-conventions.md`:
141+
142+
- the dependency direction between the crates, and logic in the wrong crate,
143+
such as SQL outside `crates/database` or decisions in `crates/ui` templates
144+
- public items no other crate needs, and the published crates' (`auth-sdk`,
145+
`common`, `crypto`) public API
146+
- types, conversions and helpers duplicated across crates, and between the
147+
Rust and TypeScript SDKs and `common`'s wire types
148+
- what the CLI, the settings, the developer console and the admin dashboard
149+
each reimplement instead of sharing a service
150+
- errors that lose their context at a crate boundary
151+
152+
It edits nothing. It reports themes, each with the files involved and the
153+
change it proposes. Add the cross-area issues the area agents report to that
154+
list. Themes that need a design decision, or change a published crate's API,
155+
go to the owner first.
156+
157+
Once a theme's files are free, start one Opus implementation delegate per
158+
theme. Merge themes that share files, or run them one after another. Each
159+
follows the agent brief, with the theme's files as its area, and opens focused
160+
PRs on `refactor/<n>-boundary-<topic>`. Review them like the others.
161+
162+
### Bugs
163+
164+
Every bug an agent or reviewer reports gets an issue and a fix PR:
165+
166+
1. Check it against current `main`, with a Sol delegate when there are many.
167+
Merge duplicate reports, and ask the owner about anything that might be
168+
intended. A vulnerability, anything an attacker could exploit, stops here:
169+
tell the owner only, and open no issue or PR (`SECURITY.md`).
170+
2. Open a GitHub issue labelled `bug`, or reuse the one that exists
171+
(`gh issue list --search`). Include the `file:line`, what goes wrong and how
172+
to reproduce it. If the existing issue is assigned or has a linked PR, note
173+
it in the ledger and start no fix.
174+
3. Once its files are free, start an Opus implementation delegate in a worktree,
175+
on `fix/<issue>-<topic>` from a freshly fetched `origin/main`, with the
176+
issue and `CARGO_BUILD_JOBS`. It writes a test that fails without the fix,
177+
makes the smallest fix, updates the docs it affects, runs the agent brief's
178+
checks, regenerating what the fix changes on purpose, such as a screenshot,
179+
and opens a draft PR with `file-pr` that says `Closes #<issue>`.
180+
4. Review and ship it as in Review, but without the review brief, which treats
181+
any behavior change as a finding. The reviewer's task says to work at the
182+
head SHA without pushing or commenting, revert the fix locally to check the
183+
test then fails, and check the fix is correct and minimal and nothing else
184+
changed. It reports findings with severity and `file:line`.
185+
186+
Run at most 3 fixes at a time.
187+
188+
### Report
189+
190+
When every area and docs PR is reviewed and green, send the owner one
191+
report:
192+
193+
1. The PRs by area: link, lines added and removed, merge order, and the PRs
194+
that are stacked.
195+
2. Decisions only the owner can make, with your recommendation.
196+
3. The bugs: each one's issue, fix PR and state.
197+
4. The boundary themes, and which ones wait for the area PRs.
198+
5. Other design issues.
199+
6. Features missing from a surface (`AGENTS.md`), checked against current
200+
`main`, and admin operations left CLI-only without a documented reason.
201+
202+
Number the items `NEW-1`, `NEW-2` and so on, never `#1`, which GitHub links to
203+
an issue or PR.
204+
205+
### After the merge
206+
207+
Rerun the stats and compare them with the audit. Report again when the boundary
208+
and fix PRs are reviewed and green. Then offer these follow-ups, and start each
209+
one only when the owner asks:
210+
211+
1. A doc-comment PR for what the docs lane reported. It changes the generated
212+
reference pages on purpose (`just docs reference`).
213+
2. GitHub issues for the surface gaps.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Cleanup pass: area agent
2+
3+
You own one area of SourceOrigin in a parallel cleanup pass. Your task names
4+
the area, paths, packages, branch prefix, title scope, tracking issue and
5+
`CARGO_BUILD_JOBS`, and lists what the other agents own.
6+
7+
Read every file in your area, and `docs/dev/rust-conventions.md`. Make real
8+
simplifications, not cosmetic churn, and report bigger issues. Never add an
9+
`#[allow]`. Use `#[expect(..., reason = "...")]` on the smallest item that
10+
needs it.
11+
12+
## Rules
13+
14+
- **Change no behavior.** That includes HTTP responses (and which error a
15+
request with several faults gets), OIDC and OAuth wire formats, rendered
16+
pages and emails, CLI flags, help, output and exit codes, configuration
17+
variables, domain events and their audit records, log and span fields,
18+
metrics, timeouts, lock order, query plans, and the public API of the
19+
published crates (`auth-sdk`, `common`, `crypto`) and `@sourceorigin/auth`.
20+
`git diff <base>` shows no change to a migration, a `snapshots/` file or a
21+
generated file, except the `.sqlx` entry of a query you rewrote. Don't
22+
use blanket search and replace.
23+
- **Report bugs instead of fixing them.** The orchestrator opens an issue and a
24+
fix PR for each. If a cleanup can't be done without changing behavior, report
25+
it too. Report a vulnerability only in your final message, never in a PR,
26+
commit or code comment.
27+
- **Stay in your area.** Edit another area only when a rename forces it:
28+
keep it minimal and list those files in the PR description. Report what
29+
crosses areas: another lane cleans up between them.
30+
- **Keep the docs references right.** If you rename something a page in
31+
`docs/` names, update that page (`sourceorigin-docs` skill) and run
32+
`just docs`. Don't reword `///` comments or clap help that feed the
33+
generated reference pages.
34+
- Stop and report anything that needs a design decision.
35+
36+
## Checks
37+
38+
Export `CARGO_BUILD_JOBS` for every cargo command. For your packages, run:
39+
40+
- `just install`, then `just fmt`
41+
- `cargo clippy --locked -p <pkg> --all-targets --all-features -- -D warnings`,
42+
and again without `--all-features`
43+
- `RUSTDOCFLAGS='-D warnings' cargo doc --locked --no-deps --all-features -p <pkg>`,
44+
and `cargo test --locked --doc --all-features -p <pkg>` for a library
45+
- `just db prepare`, if you changed a query
46+
- `just test -p <pkg> --all-features`; for `auth-service` and
47+
`sourceorigin-repository`, `just db test` instead. Both fail on a stale
48+
generated file.
49+
- `just rust unused`
50+
- `cargo semver-checks -p <pkg> --baseline-rev origin/main`, for a published
51+
crate
52+
- `just web check`, `just web lint`, `just web unused` and `just web test`, if
53+
you touched TypeScript or JavaScript
54+
- `just docs screenshots`, if you touched a page's markup, styles or script.
55+
It must rewrite no image in `docs/images`. It deploys a preview, so run it
56+
once per PR, last.
57+
58+
Despite `AGENTS.md`, don't run `just validate`, `just lint` or `just test`
59+
without `-p`: they build the whole workspace. CI runs on drafts every job a
60+
PR's paths select, including the browser suite, the images, packaging and the
61+
MSRV build, so leave those to it and read their results before you report.
62+
63+
Prove each "unchanged" claim against the PR's base: `--help` output, the
64+
rendered pages, emails and HTTP responses, the TypeScript SDK's built type
65+
declarations, query plans (`EXPLAIN` in `just db scratch -- psql`). Before you
66+
call a failing check unrelated, check that it fails on `main` too. Never change
67+
a test just to make it pass.
68+
69+
## Delivery
70+
71+
- Split your work into focused PRs: one kind of cleanup in one part of your
72+
area each, small enough to review in one sitting. Branch each from a
73+
freshly fetched `origin/main` as `<prefix><topic>`, and keep your PRs from
74+
sharing files. If one needs another, stack it: branch from the other PR's
75+
branch, open it with that branch as its base, and say so in its
76+
description.
77+
- Make small, logical commits with conventional messages and no
78+
`Co-Authored-By` line.
79+
- Rebase on `origin/main` (a stacked PR on its base branch), and clean up any
80+
new code the rebase brings in. PRs merge by squash, so when a stacked PR's
81+
base merges, move only its own commits with
82+
`git rebase --onto origin/main <old base tip>`, and check it targets
83+
`main`.
84+
- Open each PR as a **draft** with `file-pr`, despite its default, titled
85+
`refactor(<scope>): <what got simpler>` (or `refactor: …` without a scope)
86+
and labelled `refactor` and the other labels that fit (`gh label list`). Its
87+
description says:
88+
- `Part of #<n>`
89+
- what was hard to read and how you fixed it
90+
- every test you merged or removed
91+
- files edited outside your area, and why
92+
- what you compared to prove the rest unchanged
93+
- Don't mark a PR ready.
94+
95+
Your final message gives:
96+
97+
1. The PR links, in merge order, with what each one cleans up.
98+
2. The checks you ran for each, with their results.
99+
3. Bugs: `file:line`, what goes wrong and how to reproduce it.
100+
4. Issues that cross areas, and other design issues: `file:line`, what's
101+
wrong, why it matters and a fix.
102+
103+
Check every item against the source before you report it. When you get review
104+
findings, fix them on that PR's branch, rerun the affected checks, push, and
105+
report what changed.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Cleanup pass: reviewer
2+
3+
Review one PR from a SourceOrigin cleanup pass. It claims to be a pure
4+
refactor: no behavior, output, schema, format or test coverage changes. Bug
5+
fixes go in their own PRs, so any behavior change here is a finding.
6+
7+
Review read-only. Don't push, comment or edit. Read the PR, and check out the
8+
head SHA your task gives (`git fetch origin <base> pull/<N>/head`). Export the
9+
`CARGO_BUILD_JOBS` your task gives.
10+
11+
Check every claim in your focus list yourself, against the base branch your
12+
task gives (`origin/main` unless the PR is stacked). Then look for, most
13+
important first:
14+
15+
1. Hidden behavior changes: error codes, messages, statuses and precedence,
16+
defaults, serialization (tokens, domain events, audit records, wire
17+
types), rendered pages and emails, log and span fields, timeouts, lock
18+
order and transaction boundaries, query plans (compare `EXPLAIN` in
19+
`just db scratch -- psql`), and the published crates' public API.
20+
2. Lost coverage: dropped assertions or cases, and expected values built by
21+
the code under test. Compare test names and counts per file with the base.
22+
3. Abstractions that make the code harder to read.
23+
4. Missed cleanup and stale doc comments in the touched files, briefly.
24+
25+
Report each finding with its severity (blocker, should-fix or nit),
26+
`file:line`, the problem and a fix. Say which claims you verified and how. If
27+
the PR is clean, say so.

0 commit comments

Comments
 (0)