AGENT SKILL

大规模代码重构流水线

refactor-pipeline

以三个独立通道——生产者(producer)、打包者(packager)和牧羊人(shepherd)——运行大规模的机械式重构(crate 或 package 拆分、模块提取、API 迁移、死代码删除),这些通道仅通过 git 和 PR 栈进行协调。它会推送分支并创建 PR,因此仅在 `/lever refactor` 或明确要求(“拆分此 crate”“拆分这个单体”“这个模块太大了,把它精简一下”“迁移所有调用方”)时运行。

使用场景代码实现
License 许可
MIT
所属仓库
github/lever
最近更新
2026-11-06
Stars
★ 292
Forks
15

01 前言 Front Matter

name
refactor-pipeline
description
Runs a huge, mechanical refactor (crate or package splits, module extraction, API migrations, dead-code removal) as three independent lanes, producer, packager and shepherd, that coordinate only through git and a PR stack. It pushes branches and opens PRs, so it runs only on `/lever refactor` or an explicit ask ("split this crate", "break up this monolith", "this module is huge, cut it down", "migrate every caller").
user-invocable
false

03 SKILL.md 正文

Refactor pipeline

Some refactors matter a lot and nobody wants to do them: splitting a crate that has grown to half a million lines, extracting modules, migrating every caller of an API. The work is mechanical but long. It's too big to review as one PR, and too tedious to babysit for a week.

This skill runs it as three lanes that never talk to each other. Each lane has one job and its own cadence. Git is the message bus, and the PR stack is the shared state.

PRODUCER  ──push every commit──▶  source branch  ──▶  PACKAGER  ──adds PRs──▶  PR stack  ◀──  SHEPHERD
(one split per commit,                               (rebase, test,                        (conflicts, CI,
 reports vs a fixed baseline)                         reviewable PRs)                       review threads)
                    ▲                                                                           │
                    └──────── daily: rebase onto what landed, drop merged commits ◀─────────────┘

You set the target, merge what's green, and route context between lanes when one of them needs to know something the others learned. The lanes do the rest.

When to use

  • The target is measurable and mechanical, for example "cut non-test LoC of core by 50%", "no file in src/legacy imports old_client", or "zero callers of v1::fetch".
  • The change splits naturally into many small, independently correct units.
  • The result has to land as reviewable PRs, not one giant diff.

Don't use it for:

The three lanes

Run each lane in its own session, such as its own Copilot CLI process, app session or cloud session. Separate processes keep their context small and let one lane die without taking the others down.

1. Producer: does the work

A long-running goal with a measurable target and a heartbeat. The whole kickoff fits in one paragraph. It needs one sentence each for:

Part Example
Target "bring the non-test LoC of this crate down by 50%"
Unit of work "one logical split per commit"
Baseline "measure the baseline now"
Heartbeat "report every 30 min against the goal, in absolute LoC and %"
Validation "run the tests for the affected crates before each commit"
Constraint "don't make other crates significantly bigger"

Rules the producer must follow:

  • Push after every commit. This one rule is what lets the packager consume work while the producer keeps going.
  • The baseline never moves. After each daily rebase, report against the original baseline. No shifting the goalposts.
  • Never manufacture progress. Don't delete, weaken or reclassify tests. Don't change what's counted. Don't leave backward-compatibility wrappers behind just to keep callers compiling.
  • Move tests with the code. Move whole test modules and their fixtures to the new owner, not only the code under test.
  • Daily rebase: rebase onto the latest landed state, drop commits that have already merged, and re-measure.

2. Packager: makes it reviewable

A scheduled lane that turns raw commits into a reviewable stack.

  • Checkpoint, don't remember. Save the last source commit you processed, plus a stable identity for every commit you've packaged: its git patch-id --stable, or a Change-Id: trailer if the producer writes one. Every run starts with a diff: "Processed 8 new commits through 5bf1e1f", or "No new commits since d3137f5. Nothing to do." The second answer is silent.
  • Reconcile after the producer's rebase. If the source branch moved non-fast-forward, the old checkpoint may not be an ancestor anymore, and packaged commits have new SHAs. Don't diff from the checkpoint. Match source commits to packaged ones by patch-id or Change-Id, skip what's already packaged, and package only the rest. A commit whose patch changed in the rebase gets flagged, not packaged twice.
  • Rebase new commits onto the top of the stack, run the tests, and fold fixups into commits that aren't in a PR yet. The packager only appends PRs on top. It never rewrites a PR that's already in the stack.
  • Size each PR for a human reviewer, for example under 2,000 changed lines, excluding pure moves. Add PRs to the stack with the repo's stacking tool (for example gh stack).
  • Cadence follows batch size. Start at every few hours. If runs keep finding only a commit or two, slow it down.

3. Shepherd: keeps the stack mergeable

A frequent lane that runs pr-shepherd across every PR in the stack.

  • Rediscover stack membership on every run. Another lane is adding PRs, and merges restack it.
  • The shepherd is the only lane that rewrites the stack. Restacks, conflict rebases and fixups to PRs already in the stack all go through it. The packager sends it a note instead of pushing.
  • Check mergeability against the real target. A stacked PR can say "no conflicts" against its stacked base and still conflict with main once the PRs below it merge. Verify with git merge-tree against the branch it will actually land on.
  • On conflict, push the rebase immediately, then verify. A stale PR that's waiting on local validation blocks everyone above it. CI on the pushed head is the real check.
  • Stay armed, within budget. A green stack is a checkpoint, not a finish line. Keep going until the stack is merged, a human says stop, the budget runs out, or 6 ticks in a row did nothing. Then post one line saying which, and stop the schedule.
  • Rerun a red check only after showing that the stack didn't cause it.

Shared rules

  • One API budget. All three lanes poll the same GitHub quota. Gate each PR to at most one status poll per ~10 minutes, combine queries (one GraphQL call per stack, not one per check), and back off until resetAt on 403 or 429. In one run, this cut a shepherd cycle from 11 GraphQL requests to 3.
  • Merging is the human's call by default. The shepherd keeps PRs green and the human merges whenever they like. Raise the autonomy dial if you want the shepherd to land green PRs itself.
  • Corrections go into the standing order. When you correct a lane ("push immediately, then verify"), the lane rewrites its own recurring prompt to include the rule, so you say it once. See steer-once.
  • The human routes context. You're the only one who sees all three lanes. Tell a lane things like "rebase onto extract-projections, it has most of your work adapted to a later main" or "another job is adding PRs to this stack".

Running it

Copilot CLI: one terminal per lane. Use /goal for the producer's target and /every for each lane's cadence, for example producer report /every 30m, packager /every 3h and shepherd /every 20m. Put the terminals on a machine that stays awake (a dev box or VM), not a laptop that sleeps.

Copilot app: one session per lane. /goal works the same way. There's no /every; give each lane a session automation with the same cadence and prompt instead. It wakes the same session, so the lane keeps its context and checkpoint between runs.

In the cloud: the packager and shepherd are good automate-it candidates. They are scheduled, bounded and repeatable. Keep the producer as a long-running session that you check in on.

Dials

Dial Default Notes
target required metric + direction + amount, measured against a fixed baseline
pr_size < 2,000 changed lines excluding moves what your reviewers can actually read
cadence producer report 30 m · packager 3 h · shepherd 20 m · producer rebase 24 h each lane runs at the speed of what it watches
autonomy shepherd L2 (keeps green, human merges) see docs/autonomy.md
api_budget ≤ 1 poll per PR per 10 min shared across all lanes
spend your tier and budget, from /lever a multi-day run makes thousands of model calls; prompt caching matters a lot

What good looks like

In one real five-day run on a ~564k-line Rust crate, three lanes made 135 splits and cut non-test LoC by about a third. 19 of 20 stacked PRs merged, and one of the slowest CI jobs got about 28% faster as a side effect. The human typed 38 messages, and scheduled runs fired 373 times. Most of those 38 messages were one-line corrections that the lanes wrote into their own standing orders, plus "why did you stop the schedule?"

This skill's own feedback loop

  • The producer's heartbeat is the loop. If the metric hasn't moved in three reports, stop and ask the human whether the target or the unit of work is wrong.
  • Every correction you have to type twice is a missing rule. Add it to the lane's standing order and, if it's general, to this file.

04 同仓库更多 Skills

github
github/lever

重复纠正根因修复

steer-once

将你反复重复的纠正转化为持久性修复:挖掘你的各类纠正并分类,选择能够预防这些纠正的最低成本层级(指令、技能、lint/CI 检查、测试、自动化或产品 bug 报告),提交一个带证据块的 PR,然后在 K 天后重新度量,并决定保留、升级或回滚。由于会创建 PR,因此仅在 `/lever steer` 或明确要求(“挖掘我的纠正”“为什么我总跟你说 X”“我不是给过你一个技能来做这个吗”),或当 prompt-mirror 在 3 个及以上会话中报告同一类纠正且你表示同意时才运行。

AI 工程师智能体开发
★ 292
github
github/lever

自动化运行健康审查

run-health-review

停滞监视器与自动化健康审查。拉取近期运行、合并、无操作率、失败、速率限制命中以及卡住的 PR;对每种停滞进行分类;只提出一项变更或“不变更”;并接管被遗弃的工作。当无人值守交付停滞(“为什么一夜之间就卡住了”“N 小时没有合并”“前几天还很快,现在变慢了”)、某个自动化失败或其产出下降、遭遇速率限制或配额用尽,或在 agent 无人值守运行期间按计划执行时使用。

SRE 工程师运维监控与告警
★ 292
github
github/lever

Copilot 提示词习惯分析

prompt-mirror

挖掘本地 Copilot 会话历史,返回一份关于你如何指导智能体的评分卡,并附上三条建议,用你自己的前后对比消息加以说明。由于它读取你的私有历史,因此仅在 `/lever mirror` 或明确请求(“我的提示词水平如何?”、“指导我改进”、“挖掘我的会话”、“我总是在重复什么?”、每周自我复盘)时运行。

软件开发工程师提示词分析与优化
★ 292
github
github/lever

长时任务进度契约跟踪

progress-contract

推动长时间运行或委派的任务进展,让人类无需轮询。它会发布带有 ETA 及各自所需证据的里程碑,仅在发生重大变化时发送报告,为每项声明标注证据等级,记录 ETA 准确性,监控距上次合并的时间,并在宣布“完成”之前依据证据对“完成”状态进行审计。适用于任何委派的、耗时数小时或通宵运行的任务,当任务简报设定了报告契约时,或当用户询问“状态如何?”、“预计何时完成?”、“我们进行到哪了?”、“昨晚发生了什么?”、“逐小时汇报”或“你完成了吗?”时。

项目经理项目进度跟踪与状态报告
★ 292
github
github/lever

PR 落地合并驱动

pr-shepherd

通过事件驱动循环推动开放的拉取请求直至落地。每次唤醒时执行一次批量读取,修复红色必填检查的根本原因,处理每一条审查讨论线程,并按照自主性拨盘设定的级别执行落地。由于它会推送代码并可能执行合并,因此仅在 `/lever shepherd`、来自 lever 协调器的移交、被标记为 shepherding 的 PR,或明确请求(“监控 CI 直至通过”、“推送修复直到通过”、“解决审查讨论线程”、“通过即合并”、“照看这个 PR”、“shepherd”)时运行。

软件开发工程师代码仓库协作管理
★ 292
github
github/lever

Lever 技能统一入口

lever

统一的 lever 命令。`/lever <verb> [args]` 直接运行某个 lever 技能(loop、arms、review、brief、deliver、refactor、backlog、shepherd、land、status、automate、health、mirror、steer、autonomy、spend、setup、help)。`/lever <plain words>` 会为你挑选合适的动词,用一行说明所选动词,然后执行。该技能还会读取和写入 `~/.copilot/lever.yml` 中用户的个人拨盘设置。当用户键入 /lever、询问“我应该使用哪个 lever 技能?”,或想查看或更改其自主性(autonomy)或支出(spend)拨盘时使用。

软件开发工程师插件与技能管理
★ 292