代码重构与行为保持
dev-refactor
在完全保持行为不变的前提下降低复杂度。
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 65
- Forks
- 0
01 前言 Front Matter
- name
- dev-refactor
- description
- Reduce complexity while preserving behavior exactly.
03 SKILL.md 正文
Objective
Reduce complexity while preserving behavior exactly. Refactor only after current behavior is pinned by existing tests, explicit pinning tests, or a reviewer-approved proof; if behavior must change, route to dev-feature or dev-fix.
Use it when the BOSS route is refactor, the target surface is narrow with an explicit FILESCOPE, tests are already green or the task includes pinning-test AC, and the change is structure-only: extraction, renaming, deduplication, moving code, dependency inversion, or local simplification. Do not use it for new feature behavior, bug fixes or semantic changes, public API changes without explicit AC, or large module rewrites without a staged plan.
Helpers
boot-context: stale or missing local context.dev-chore: direction, reuse, single-ownership, proportional-complexity/risk, and user-outcome checkpoint when restructuring starts adding rather than removing conceptual weight.arch-contract,arch-roadmap: understand boundaries before restructuring.lint-python,lint-rust,lint-go,lint-typescript,lint-shell,lint-kernel: touched files.dev-spec,verify-test,verify-coverage,verify-performance: pre/post behavior and performance proof.qa-review: independent review for public API, config, or broad module moves.ops-swarm: parallel non-blocking analysis/check packets, only with clear FILESCOPE isolation.
In workflow mode, helper output is evidence, not the output format: dev-refactor keeps worker-artifact ownership, applies dev-chore findings itself, and still writes worker.json, evidence refs, and workflow.next_command = "workflow-reviewer".
Workflow Mode
Workflow mode is ON when .agent-surface/workflows/<run_id>/run.json is active, .agent-surface/workflows/<run_id>/boss.json uses schema_version: workflow.v3, and boss.workflow.route = "refactor".
- Load
run.json,boss.json, and the latest reviewer/judger/rescue handoff whenworkflow.next_command = "dev-refactor". - Start from
boss.context_capsule; inspect only deltas unless evidence is missing, stale, contradictory, or changed since BOSS captured it. - Process only active task IDs, respecting dependencies and FILESCOPE.
- Capture pre-change proof (tests, lint, typecheck, behavior snapshot) or an explicit reason it is unavailable; when coverage is weak, add pinning tests before changing structure.
- Apply one structural transformation at a time. Preserve public API unless BOSS AC explicitly permits a rename or move.
- Run task verify commands and record each in
verify_results; save the output the reviewer needs under.agent-surface/workflows/<run_id>/rounds/round-<round_id>/evidence/<task_id>/and list it inevidence_refs. - Apply Blocker Discipline before marking a task blocked.
- Write the canonical
.agent-surface/workflows/<run_id>/rounds/round-<round_id>/worker.jsonand the latest copy.agent-surface/workflows/<run_id>/worker.json, withworkflow.owner = "dev-refactor"andworkflow.next_command = "workflow-reviewer". - Advance the ledger with
agent-surface workflow apply --role dev-refactor --run <run_id> --artifact .agent-surface/workflows/<run_id>/worker.json; this appends the transition event and setsrun.json.workflow_next_command. Never hand-editrun.json.
Worker artifact shape:
{
"schema_version": "workflow.v3",
"run_id": "<run_id>",
"round_id": 1,
"worker": "dev-refactor",
"tasks_processed": [
{
"task_id": "T1",
"status": "PASS",
"files_changed": [],
"evidence_refs": [],
"verify_results": [],
"behavior_preservation": { "pre_change_evidence": [], "post_change_evidence": [], "api_changed": false }
}
],
"skipped": [],
"remaining": [],
"stop_reason": "queue_empty",
"workflow": {
"dir": ".agent-surface/workflows/<run_id>",
"file": "worker.json",
"owner": "dev-refactor",
"run_id": "<run_id>",
"round_id": 1,
"parent_artifact_hashes": ["sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],
"next_command": "workflow-reviewer"
}
}
Without an active workflow, keep the refactor narrow and reversible, run the cheapest behavior-preserving checks before and after, and do not auto-commit.
Blocker Discipline
Attempt the safe discovery or repair available to you before emitting a blocker.
- Not blockers; resolve them: repo discovery, choosing verify commands from manifests/Makefiles/CI, scoped format/lint/test failures in owned files, and documentation alignment for public behavior in FILESCOPE.
- Refresh generated artifacts only when BOSS assigned generated outputs or the repo's generator/check requires it; record the generator command and keep the generated-file gate green.
- Human-required: a literal human-only login/device action, a product decision not inferable from BOSS/user evidence, or required work outside FILESCOPE that cannot be split safely. In-scope secret use, dependency work, destructive commands, database mutation, deployment, production data, and network calls proceed under the distribution's full-execution consent.
- Repeated failure: after two focused correction attempts on one task, stop with
blocker.type="repeated_failure"andresolution_class="human_required"unless the next safe action is purely mechanical; include the failed attempts. - Every blocker should include
type,detail,needs,resolution_class(auto_resolvableorhuman_required),attempts, andrecommended_decision. Legacy v3 artifacts may omit the last three, but new worker output includes them.
Safety
- Add no features and hide no bug fixes in a refactor; change public API only when BOSS AC explicitly allows it. If behavior must change, stop and route to
workflow-bossfor route correction. - Never weaken tests, linters, compiler settings, auth checks, or security checks to pass.
- Edit no workflow artifacts besides
worker.jsonand evidence files; the role's event comes fromworkflow apply.
Output
Worker file: .agent-surface/workflows/<run_id>/worker.json
Round done: M/N refactors completed; stop_reason=<reason>; next: workflow-reviewer
Changed: <short file list>
Checks: <command -> passed/failed/not run>
04 同仓库更多 Skills
工作流运行时验证
workflow-runtime
在将 CLI、扩展、提供程序或模型分配给工作流角色之前,先验证技能或工作流的发现能力、完全自主的工具执行能力,以及任务形态的具体化。
工作流成果审查
workflow-reviewer
依据 BOSS 规格说明和证据,审查批量实现的输出。
工作流故障修复
workflow-rescue
通过一次果断的行动解决反复出现的工作流失败。
多智能体工作流编排
workflow-orchestrator
运行风险自适应的开发、评审、多智能体和发布工作流,具备运行时预检、有限重试、存活检查、写入隔离以及有证据支撑的交接能力。
工作流失败仲裁
workflow-judger
仲裁反复出现的任务失败,并决定是合并、返工还是升级处理。
工作流状态验证
workflow-doctor
在任何角色对活动工作流状态执行操作之前,先对其进行验证。