|
| 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. |
0 commit comments