Skip to content

如果我有一个项目需要重构,loop-engineering 怎么帮助我,来分解todo,然后自动进行,以下流程如何改造,有没有教程? #522

Open

Description

@hufeide

Pattern name

通用工作流如何制造?

Goal (one sentence)

如果我有一个项目需要重构,loop-engineering 怎么帮助我,来分解todo,然后自动进行

先说清楚一个必须理解的前提

"从 L3 层级自动重构整个项目"是一个高风险操作,loop-engineering 的核心哲学恰恰是反对一上来就 L3 全自动重构的。它教你的正确路径是:

从 L1(只报告)→ L2(辅助修复)→ 逐步放权,绝不一上来就 L3 无人值守重构。

所以正确的回答不是"直接 L3 自动重构",而是:用 loop-engineering 的方法论 + 工具,把一个重构项目安全地分解、渐进地自动化。 这本身才是它最有价值的地方。


loop-engineering 帮你重构项目的完整路径

第 1 步:先建立"重构的治理框架"(L1 起步,绝不可跳过)

重构前,先让循环只读地理解你的项目,产出重构计划,而不是直接动手:

# 脚手架(生成 STATE.md、LOOP.md、budget、约束)
npx @cobusgreyling/loop init . --pattern daily-triage --tool grok

# 审计当前就绪度
npx @cobusgreyling/loop audit . --suggest

关键:重构是"多文件、跨模块"的改动,恰恰是 docs/safety.md 里 denylist 的高风险区("Changes touching >N files"需要人类)。所以重构天生不适合无人值守 L3,更适合L2 + 人类把关每个阶段。

第 2 步:用 loop-engineering 的"分解哲学"拆 todo

loop-engineering 没有专门的"重构 pattern",但它有7 个可复用的模式,重构可以拆成几个模式接力:

重构阶段 对应的 loop pattern 作用
摸清现状 daily-triage / issue-triage 扫描代码、列出现状
每个小改动 pr-babysitter 一次一个 PR,改完等审
依赖升级 dependency-sweeper 只改补丁级依赖
合并后清理 post-merge-cleanup 清理遗留

核心思想:把"大重构"拆成大量小 PR,每个 PR 单独走 "implementer → verifier → 人类审" 的闭环。


从 L3 视角看"自动进行":需要满足的前置条件

如果你坚持要达到"自动进行",需要先对照 loop-design-checklist.md 的 L3 要求,逐项补齐(我之前讲过 10 章清单)。重构项目要特别关注这几个 L3 硬门槛:

L3 前置 重构场景下的含义
denylist 明确哪些文件/模块绝不自动改(如核心逻辑、API 契约)
gate.yaml allowlist 只允许自动合并"安全路径"(如测试、文档、纯函数)
verifier 每个改动必须有独立验证(跑测试 + 审 diff)
真实运行记录 先跑几轮 L1/L2,证明循环靠谱,才敢放 L3
预算/日志 限制 token 花费,记录每次改动

一个具体的、可执行的分解示例

假设你要重构一个 Python 项目(比如你那个 website),loop-engineering 帮你的方式是这样:

阶段 0:审计 + 脚手架(L1)
  loop init → loop audit → 生成 STATE.md 记录"重构目标"

阶段 1:让 triage 扫描,产出重构清单(L1 只报告)
  /loop 1d 扫描项目,列出:死代码、重复逻辑、需要拆分的模块、需要加测试的地方
  → 写进 STATE.md 的 High Priority / Watch List

阶段 2:逐项重构(L2,人在场)
  对每个 todo:
    git worktree 隔离 → implementer 改 → verifier 验 → 你审 PR → 合并
  (用 loop-worktree 管理每个 fix 的独立 worktree)

阶段 3:自动化小重构(L2+)
  对"安全"的小改动(重命名、加测试、格式化),允许 verifier 通过后自动开 PR

阶段 4:无人值守(L3,仅当信任建立后)
  只对 allowlist 路径(如纯测试、文档)自动合并
  denylist(核心逻辑、API)永远升级给人类

Tools you need it for

Opencode

Context

……

Activity

  1. cobusgreyling commented on Aug 17, 2026

    @cobusgreyling
    Owner

    Thanks for the detailed write-up — your L1 → L2 → later-L3-only-on-allowlist path is the intended one. There is no dedicated “refactor the whole repo” pattern, and that is deliberate: large multi-file refactors sit in the high-risk zone in docs/safety.md.

    Tutorial path (official docs, not a custom refactor playbook):

    1. Week-one rule: report only. docs/QUICKSTART.md — scaffold, then read what the loop writes before you let it act.
      npx @cobusgreyling/loop init . --pattern daily-triage --tool opencode
      npx @cobusgreyling/loop doctor .
    2. Split the work into existing patterns, one small PR at a time:
    3. If you later want any auto-apply, check L3 gates against docs/loop-design-checklist.md first. Do not jump to unattended L3 on a refactor.

    Your issue body already has a sound staged plan (audit → STATE.md list → L2 worktrees per todo → allowlist-only automation). Use that as the runbook; the links above are the tutorials.

    If a specific step in loop init / OpenCode cron fails, paste the command and the first error and we can debug that.

  2. cobusgreyling commented on Aug 26, 2026

    @cobusgreyling
    Owner

    Follow-up: this now has an official tutorial, not just a pointer at existing patterns.

    English

    Loop engineering does not have a “refactor the whole repo” pattern. That is intentional. The job is to split the rewrite and run each slice through maker → verifier → human.

    New docs (now on main):

    Short version of the path (OpenCode, as you listed):

    npx @cobusgreyling/loop init . --pattern daily-triage --tool opencode
    npx @cobusgreyling/loop doctor .
    1. L1 — daily-triage writes an inventory into STATE.md (no code).
    2. L2 — each High Priority line is one worktree / one PR (pr-babysitter + verifier). You merge.
    3. Only later, and only on an allowlist, anything unattended. Core logic stays denylist.

    If a slice has a hard done-definition, pair it with /goal in goal-engineering instead of stretching daily-triage into a task runner.

    中文

    没有「一键 L3 重构整个仓库」的 pattern,这是故意的。正确做法是把大重构拆成很多小 PR:

    1. L1 只报告:用 daily-triage 把待改项写进 STATE.md
    2. L2 人在场:每一项一个 worktree / 一个 PR,独立 verifier,你来合并
    3. 只有 allowlist 上已经跑稳的路径才考虑自动合并;核心逻辑永远 denylist

    教程:jobs.md · refactor.md

  3. cobusgreyling commented on Aug 28, 2026

    @cobusgreyling
    Owner

    Thanks for writing this up — this is the most common mismatch: people land on loop-engineering wanting a refactor runner, and the seven original patterns are repo-health loops.

    The tutorial now lives in the repo (shipping in #561):

    Short version / 简短结论

    There is no L3 “rewrite the tree overnight” pattern. That is deliberate (docs/safety.md denylist + maxFiles).

    1. npx @cobusgreyling/loop init . --pattern daily-triage --tool claude (or --tool opencode) — week one report only.
    2. Daily Triage writes a High Priority list. Each line must be small enough for one PR.
    3. For each line: worktree → implementer → independent verifier → you merge.
    4. Allowlist auto-merge only for paths you already trust (tests, docs). Core logic stays denylisted.

    把「大重构」拆成大量小 PR,而不是一个无人值守的大循环。完整步骤在 docs/refactor.md。

    If you want a named objective with a done-definition instead of a queue, that is goal-engineering (/goal), used with triage, not instead of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions