我用于持续改进代码库的 LLM 提示
发布: (2025年12月14日 GMT+8 02:41)
3 min read
原文: Dev.to
Source: Dev.to

与其让 LLM 生成 大块代码,我更倾向于把它们当作 代码库清洁工:执行小而专注的任务,频繁运行,随着时间的推移产生叠加效应。
下面是我经常使用的 可直接复制粘贴的提示。
Prompts
1. Remove Dead Code
Find unused files, functions, exports, imports, and variables.
Explain why each is safe to remove and note any risk.
2. Improve Naming
Rename variables, functions, and classes to better reflect intent.
Optimize for clarity and readability, not brevity.
3. Reduce Cyclomatic Complexity
Identify overly complex functions and simplify logic.
Prefer early returns, smaller functions, and clearer control flow.
4. Close Coverage Gaps
Scan test coverage output.
Find uncovered lines and write focused unit tests that validate behavior.
5. Document the Why
Add documentation explaining *why* this code exists and what tradeoffs were made.
Do not describe what the code does line‑by‑line.
6. Identify Responsibility Leaks
Find functions or components doing more than one job.
Suggest how to split responsibilities cleanly.
7. Improve Error Handling
Review error handling paths.
Ensure errors are meaningful, actionable, and consistently handled.
8. Normalize Patterns
Identify inconsistent patterns (naming, structure, async handling).
Recommend a single, consistent approach.
9. Flag Hidden Coupling
Detect tight coupling between modules or layers.
Suggest abstractions or boundaries to reduce blast radius.
10. Improve Readability Without Refactors
Improve formatting, ordering, and small structure changes only.
No architectural rewrites.
Why This Works
这些提示具备:
- 小巧
- 可重复
- 低风险
- 高杠杆
它们把 LLM 变成 持续改进的代理,而不是代码生成器。
A Note on Code Review
在生成此类更改时,要频繁提交并保持每次改动都很小。这样可以让审查更容易,限制影响范围,并确保在出现问题时能够随时回滚到已知的良好状态。
Agents with GitHub
GitHub 正在朝着这个方向前进——在其主页直接展示基于代理的工作流,并将其集成到 issue、PR 和代码审查中。
Code Acceleration
开发速度正在加快。为了跟上节奏,我们需要尽可能降低摩擦。随着我们编写和审查的代码量激增,可读性变得不可妥协——这些提示正是帮助强化可读性的利器。