improve-loop

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Improve Loop

Improve Loop

A non-interactive, autonomous-safe sibling of
/improve-codebase-architecture
. It does ONE deepening per invocation and is built to be called repeatedly by
/goal
or
/loop
. Where the interactive skill asks "which to explore?" and runs
/grilling
, this skill auto-selects the safest candidate and defers every design decision.
Vocabulary is the
/codebase-design
deep-module language exactly: module, interface, implementation, depth, seam, adapter, leverage, locality. Run that skill for the terms.
非交互式、自主安全的
/improve-codebase-architecture
同类 skill。 每次调用仅执行一次深化操作,专为由
/goal
或
/loop
重复调用而设计。交互式 skill 会询问“探索哪个目标?”并运行
/grilling
;此 skill 则自动选择最安全的候选项,并推迟所有设计决策。
术语体系与
/codebase-design
的 deep-module 语言完全一致:module、interface、implementation、depth、seam、adapter、leverage、locality。运行该 skill 查看这些术语。

Hard safety invariants (never violate)

硬性安全不变量(绝不违反)

  1. Never
    merge
    ,
    push
    , or open a PR.
    Work only on an isolated branch via
    wt
    .
  2. One candidate per invocation. Keep diffs reviewable.
  3. TDD or abort — with one exception. For new or changed behavior: write a failing test first, then make it pass; if you cannot make it red or reach green, revert and stop. Deletion exception: a behavior-preserving removal of dead code (proven by a no-callers search across the repo) is verified by the full suite staying green after you remove the code and its tests — not by a red-green cycle.
  4. Verify before acting. Re-read the real files to confirm every sub-agent claim before editing. (Past runs: claims were wrong as often as right.) A claim you can't confirm = skip.
  5. Edit code ONLY for Class-A. Class-B → a design doc, no code. Class-C → memory only.
  6. Commit discipline. Stage only files you touched this run; commit on the branch (verify the branch by reading it with
    git rev-parse --abbrev-ref HEAD
    ; never
    main
    ); never
    git commit -a
    ; run
    git diff --cached --name-only
    and confirm it matches before committing.
  7. Respect ADRs. A candidate that conflicts with an ADR is Class-B or C, never A.
  8. Dedup. Read the architecture-review backlog memory; skip completed candidates.
  9. No corner-cutting. Every artifact — HTML report, design doc, tests, the review fan-out itself — meets its full spec; never substitute a lighter version for a specified one (e.g. a one-line card list for a diagrammed report, or reused stale candidates for a real
    Explore
    review unless explicitly told the candidates are current). Short on budget → narrow the scope (fewer candidates / cycles) at full depth, never the full scope at reduced quality. If you cannot meet an artifact's spec, say so in the result block rather than shipping a degraded one silently.
  1. 绝不
    merge
    、
    push
    或创建 PR。
    仅通过
    wt
    在隔离分支上工作。
  2. 每次调用只处理一个候选项。 确保 diff 易于审查。
  3. TDD 或中止——仅有一个例外。 对于新增或变更的行为:先编写失败的测试,再让测试通过;如果无法先让测试变红或最终变绿,则回滚并停止。 删除例外: 对死代码进行保持行为的删除(必须通过全仓库无调用方搜索来证明)时,验证方式是移除代码及其测试后完整测试套件仍保持绿色,而不是执行红-绿循环。
  4. 行动前先验证。 编辑前重新读取真实文件,确认 sub-agent 的每项说法。(以往运行中,这些说法错误的次数与正确的次数一样多。)无法确认的说法 = 跳过。
  5. 仅可为 Class-A 编辑代码。 Class-B → 写设计文档,不写代码。Class-C → 仅写入 memory。
  6. 提交纪律。 仅暂存本次运行修改的文件;在分支上提交(通过读取
    git rev-parse --abbrev-ref HEAD
    验证分支;绝不能是
    main
    );绝不使用
    git commit -a
    ;运行
    git diff --cached --name-only
    ,确认结果与本次修改一致后再提交。
  7. 尊重 ADR。 与 ADR 冲突的候选项归为 Class-B 或 C,绝不归为 A。
  8. 去重。 读取架构评审待办 memory;跳过已完成的候选项。
  9. 不得偷工减料。 每项产物——HTML 报告、设计文档、测试、评审 fan-out 本身——都必须完全满足其完整规范;绝不能以简化版本替代指定版本(例如,用一行卡片列表替代带图示的报告,或在未明确说明候选项为最新数据时,将过时的候选项复用于真正的
    Explore
    评审)。预算不足时,应以完整深度缩小范围(减少候选项或评审轮次),绝不能以降低质量覆盖全部范围。如果无法满足某项产物的规范,应在结果块中说明,而不是静默交付降级版本。

Pipeline (one pass)

流水线(单次执行)

  1. Review. Run the review phase of
    /improve-codebase-architecture
    (its parallel
    Explore
    fan-out over the codebase). Skip the "which to explore?" question. HTML report (attended-mode): emit the candidate set as a self-contained HTML report to the OS temp dir, then — if a human invoked this run interactively —
    open
    it and print its path. Headless (
    /goal
    /
    /schedule
    ) runs write the file but do not open a browser; their result stays the printed
    IMPROVE-LOOP RESULT
    block.
    Report quality bar — non-negotiable, do NOT cut corners. The report MUST match the
    /improve-codebase-architecture
    HTML-REPORT.md
    scaffold exactly — Tailwind + Mermaid via CDN, editorial styling. EVERY candidate gets its own
    <article>
    with ALL of: (a) a before/after diagram as the centerpiece — Mermaid for graph-shaped relations, hand-built
    div
    /SVG for editorial visuals (mass diagram, call-graph collapse, cross-section); mix the patterns, don't make every card identical; (b) one-sentence Problem and one-sentence Solution; (c) Wins bullets in glossary terms; (d) a badge row: recommendation strength + autonomy class (A/B/C) + status (done / on-branch / pending); (e) an ADR or "why B" callout where relevant. End with a loop-view / top-recommendation section. A flat list of cards with one-line descriptions and no before/after diagram is the cut-corner failure mode and is NOT acceptable. If short on budget, cover fewer candidates at full depth — never all of them shallowly.
  2. Verify claims. For each candidate, re-read the cited files. Apply the deletion test. Drop anything you can't confirm.
  3. Classify by autonomy (rubric below): A / B / C.
  4. Dedup against backlog memory; drop done candidates.
  5. Act on the single highest-value Class-A candidate:
    • wt switch --create refactor/<slug>
      ; reproduce whatever setup the worktree lacks (deps, generated artifacts) rather than falling back to working inline.
    • Write a failing test through an existing interface (red). Implement (green).
    • Run the full verify suite. Green → commit on the branch. Red you can't fix → revert the branch and stop.
  6. If no Class-A: write a design doc for the top Class-B under
    docs/architecture/<slug>.md
    (the friction in glossary terms, the design forks, and a recommended deepening). Do not edit code.
  7. Record what happened to the backlog memory (so the next pass dedups it).
  8. Print the result block (below) so the
    /goal
    evaluator can judge from the transcript.
  1. 评审。 运行
    /improve-codebase-architecture
    的评审阶段(对代码库执行并行
    Explore
    fan-out)。跳过“探索哪个目标?”这个问题。 HTML 报告(attended-mode): 将候选项集合作为自包含 HTML 报告输出到操作系统临时目录;然后——如果本次运行由人类交互触发——使用
    open
    打开并打印其路径。无头(
    /goal
    /
    /schedule
    )运行只写入文件,但不打开浏览器;结果保留为打印出的
    IMPROVE-LOOP RESULT
    块。
    报告质量标准——不可妥协,绝不偷工减料。 报告必须与
    /improve-codebase-architecture
    的
    HTML-REPORT.md
    脚手架完全一致——通过 CDN 使用 Tailwind + Mermaid,并采用编辑风格。每个候选项都必须拥有自己的
    <article>
    ,且包含以下全部内容: (a) 以前后对比图为核心——图形关系使用 Mermaid,编辑型视觉(mass diagram、call-graph collapse、cross-section)则手工构建
    div
    /SVG;应混合不同模式,不要让每张卡片都完全相同; (b) 一句话的 Problem 和一句话的 Solution; (c) 使用术语表词汇的 Wins 项目符号; (d) 一行徽章:推荐强度 + 自主性类别(A/B/C) + 状态(done / on-branch / pending); (e) 相关时提供 ADR 或“为何为 B”的提示框。 最后加入 loop-view / 首选推荐部分。 只有一行描述、没有前后对比图的扁平卡片列表属于偷工减料,不可接受。预算不足时,应以完整深度覆盖更少候选项——绝不能让所有候选项都流于浅层。
  2. 验证说法。 对每个候选项,重新读取所引用的文件。应用删除测试。丢弃任何无法确认的候选项。
  3. 按自主性分类(规则见下文):A / B / C。
  4. 与待办 memory 去重;丢弃已完成的候选项。
  5. 处理价值最高的单个 Class-A 候选项:
    • wt switch --create refactor/<slug>
      ;补齐 worktree 缺失的任何设置(依赖、生成产物),而不是改为在当前检出目录中直接工作。
    • 通过现有 interface 编写失败测试(红)。实现(绿)。
    • 运行完整验证套件。绿色 → 在分支上提交。红色且无法修复 → 回滚分支并停止。
  6. 如果没有 Class-A: 为最高价值的 Class-B 编写设计文档,路径为
    docs/architecture/<slug>.md
    (使用术语表词汇描述摩擦点、设计分支和推荐的深化方案)。不要编辑代码。
  7. 记录本次处理结果到待办 memory,供下一轮去重。
  8. 打印结果块(见下文),以便
    /goal
    评估器根据转录文本进行判断。

Autonomy classification

自主性分类

Class A — auto-implement. ALL of:
  • Deletion test is a clear vanish (dead code / pure dedup), or a behavior-preserving extraction of existing inline logic into a pure function whose inputs are already fixed by the call site.
  • No new interface/seam shape to design — you relocate, dedup, or delete; you don't decide what an interface should look like.
  • Local (≲3 files), reversible, testable through an existing interface.
  • Touches no ADR.
  • Borderline → treat as B. When unsure, do NOT auto-edit.
Class B — design doc, skip code. Any of: needs an interface or state-emission decision; more than one reasonable design; reopens/touches an ADR; cross-module seam.
Class C — log only. Speculative, value unclear, or ADR-conflicting without strong reason.
Class A — 自动实现。 必须满足全部条件:
  • 删除测试的结果明确为 vanish(死代码或纯粹去重),或者是将现有内联逻辑行为保持地提取为纯函数,其输入已由调用点固定。
  • 无需设计新的 interface/seam 形态——只做迁移、去重或删除;不决定 interface 应是什么样。
  • 局部(≲3 个文件)、可逆、可通过现有 interface 测试。
  • 不涉及 ADR。
  • 临界情况 → 按 B 处理。 不确定时,绝不自动编辑。
Class B — 设计文档,跳过代码。 出现以下任一情况:需要决定 interface 或状态输出方式;存在多个合理设计;重新讨论或触及 ADR;跨 module seam。
Class C — 仅记录。 推测性的、价值不明确,或在没有充分理由的情况下与 ADR 冲突。

Output contract (required, last lines of every run)

输出契约(必需,每次运行的最后几行)

IMPROVE-LOOP RESULT
- did: <slug> on branch refactor/<slug>  |  design-doc docs/architecture/<slug>.md  |  none
- suite: <pass>/<total> green  |  reverted (could not reach green)
- remaining auto-safe (A) candidates: <comma list, or "none">
/goal
cannot read files — its evaluator only sees the transcript. This block is the interface between the loop and
/goal
; the stop signal must be printed, not implied. The driving condition is met when this prints
remaining auto-safe (A) candidates: none
.
IMPROVE-LOOP RESULT
- did: <slug> on branch refactor/<slug>  |  design-doc docs/architecture/<slug>.md  |  none
- suite: <pass>/<total> green  |  reverted (could not reach green)
- remaining auto-safe (A) candidates: <comma list, or "none">
/goal
无法读取文件——它的评估器只能看到转录文本。此块是 loop 与
/goal
之间的接口;停止信号必须打印出来,而不能仅靠隐含。当输出
remaining auto-safe (A) candidates: none
时,即表示驱动条件已经满足。

Usage

用法

Attended, in-session:
/goal Repeatedly run the improve-loop skill. Each cycle implement the single highest-value
auto-safe deepening test-first on its own wt branch and PRINT the IMPROVE-LOOP RESULT block.
Never merge, push, or open a PR; design-heavy candidates get a doc and are skipped. Revert and
stop if a cycle can't reach green. Met when a cycle prints "remaining auto-safe (A) candidates:
none", or after 5 cycles.
Unattended weekly (recommended — produces review-ready branches you merge yourself):
/schedule weekly  claude -p "/goal <the condition above>"
Mode default is propose-safe: auto-implement Class-A to branches (never merged), design-doc Class-B, log Class-C. For propose-only (no code at all), tell the loop to treat every candidate as Class-B and emit only design docs.
Composes with:
codebase-design
(vocabulary),
tdd
(red-green),
worktrunk
/
wt
(isolation),
grilling
(only when a human later picks up a Class-B doc).
有人值守的会话内运行:
/goal Repeatedly run the improve-loop skill. Each cycle implement the single highest-value
auto-safe deepening test-first on its own wt branch and PRINT the IMPROVE-LOOP RESULT block.
Never merge, push, or open a PR; design-heavy candidates get a doc and are skipped. Revert and
stop if a cycle can't reach green. Met when a cycle prints "remaining auto-safe (A) candidates:
none", or after 5 cycles.
无人值守的每周运行(推荐——生成可供审查的分支,由你自行合并):
/schedule weekly  claude -p "/goal <the condition above>"
默认模式是 propose-safe:自动将 Class-A 实现到分支上(绝不合并),为 Class-B 生成设计文档,仅记录 Class-C。若采用 propose-only(完全不写代码),则让循环将每个候选项视为 Class-B,并且只输出设计文档。
与以下 skill 组合使用:
codebase-design
(术语体系)、
tdd
(红-绿)、
worktrunk
/
wt
(隔离)、
grilling
(仅当人类后续接手 Class-B 设计文档时)。