simplify-and-harden by pskoett/pskoett-ai-skills
npx skills add https://github.com/pskoett/pskoett-ai-skills --skill simplify-and-hardennpx skills add pskoett/pskoett-ai-skills/skills/simplify-and-harden
若仅用于 CI 执行,请使用:
npx skills add pskoett/pskoett-ai-skills/skills/simplify-and-harden-ci
| 字段 | 值 |
|---|---|
| Skill ID | simplify-and-harden |
| 版本 | 0.1.0 |
| 触发条件 | 任务完成后钩子 |
| 作者 | Peter Skøtt Pedersen |
| 类别 | 代码质量 / 安全性 |
| 优先级 | 推荐 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
当编码智能体完成一项任务时,它对该问题、解决方案以及过程中所做的权衡拥有峰值上下文理解。这种上下文会立即衰减——下一个任务将清空状态。Simplify & Harden 利用这个峰值上下文窗口,在智能体继续前进之前,执行两次专注的审查。
大多数智能体解决工单后便停止。此技能将“完成”转变为“高质量完成”。
其运作理念是在继续之前进行一次刻意的“全新视角”自我审查:仔细重读任务中所有新编写的代码和所有修改过的现有代码,努力寻找明显的错误、逻辑混乱、脆弱的假设、命名问题以及错过的加固机会。目标不是扩大范围或重写解决方案——而是利用峰值上下文,在智能体仍记得每次更改意图时,进行一次有纪律的首次审查。
此技能是任务完成后的自我审查,不能替代独立的审查流程。
推荐流程:
如果两者意见不一致,将独立审查的发现视为外部关卡,要么修复,要么明确豁免这些发现。
当所有以下条件为真时,此技能自动激活:
非平凡代码更改定义
当差异满足以下两者时,将其视为非平凡:
*.ts, *.tsx, *.js, *.jsx, *.py, *.go, *.rs, *.java, *.cs, *.rb, *.php, *.swift, *.kt, *.scala, *.sh)。当差异仅为文档、仅为配置、仅为注释、仅为格式化、仅为生成产物或仅为测试时,视为非平凡 = false。
此技能在以下情况下不会激活:
--no-review 或等效标志明确跳过硬性规则:仅触及此任务中修改的代码。
智能体不得:
智能体应该在摘要输出中标记超出范围的关注点,而不是对它们采取行动。
预算限制:
budget_exceeded 标志目标: 减少实现过程中引入的不必要复杂性。
默认姿态:简化,而非重构。 此阶段的主要目标是轻量级清理——消除噪音、收紧命名、删除死代码。智能体应强烈倾向于进行不改变代码结构的表面修复。重构是例外,而非规则。
全新视角开始(强制): 在此阶段进行任何编辑之前,以“全新视角”重读此任务中添加或修改的所有代码,并积极寻找明显的错误、逻辑混乱、脆弱的假设、命名问题以及错过的加固机会。
智能体审查自己的工作并提问:
“既然我理解了完整的解决方案,是否有更简单的方式来表达这个?”
死代码和脚手架 —— 我是否留下了调试日志、注释掉的尝试、未使用的导入或迭代循环中的临时变量?删除它们。
命名清晰度 —— 函数名、变量名和参数名在全新阅读时是否有意义?在实现过程中看似合理的命名,事后往往难以理解。重命名它们。
控制流 —— 可以展平任何嵌套的条件语句吗?可以用提前返回替换深层嵌套吗?是否有可以简化的布尔表达式?收紧它们。
API 表面 —— 我是否暴露了超出必要的内容?任何公共方法/函数可以设为私有吗?减少可见性。
过度抽象 —— 我是否创建了在当前范围内不合理的类、接口或包装函数?智能体倾向于过度设计。标记它,但除非收益显著,否则不要重构。
整合机会 —— 我是否将逻辑分散在多个函数或文件中,而它们本可以放在一个地方?标记它,但仅在重复情况严重且整合清晰时才提议重构。
对于每个发现,智能体将其分类为:
重构停止钩子(强制):
智能体归类为重构的任何更改都会触发交互式提示。智能体必须:
智能体不批量处理重构提议。每个重构都单独呈现,以便人类可以逐个批准、拒绝或修改。
[simplify-and-harden] 重构提议 (1 of 2):
我想将 handleCreate() 和 handleUpdate() 中的重复验证逻辑合并到一个共享的 validatePayload() 函数中。
原因:两个函数使用相同的规则验证相同的字段。
重复是因为我在实现过程中将 handleUpdate 构建为 handleCreate 的副本。
受影响文件:src/api/handler.ts (第 34-67 行)
预计差异:-22 行,+14 行
[approve] [reject] [show diff] [skip all refactors]
如果人类选择 skip all refactors,智能体将跳过剩余的重构提议并进入加固阶段。跳过的重构仍会在输出摘要中显示为 flagged,状态为 skipped_by_user。
表面修复不会触发停止钩子。它们会被静默应用(并在输出摘要中报告)。理由是:删除未使用的导入不是一个判断性问题。而重构代码是。
目标: 在智能体仍理解代码意图时,关闭安全和弹性漏洞。
智能体审查自己的工作并提问:
“如果恶意人员看到这段代码,他们会尝试什么?”
输入验证 —— 所有外部输入(用户输入、API 参数、文件路径、环境变量)在使用前都经过验证了吗?检查类型强制转换问题、缺失的边界检查以及未约束的字符串长度。
错误处理 —— catch 块是否具体?错误是否在记录上下文的同时不泄露敏感数据?是否有任何被吞掉的异常?
注入向量 —— 检查任何从外部输入构建字符串的代码中是否存在 SQL 注入、XSS、命令注入、路径遍历和模板注入。
认证和授权 —— 新的端点或函数是否强制执行认证?权限检查是否存在且正确?是否存在任何权限提升风险?
秘密和凭据 —— 是否有硬编码的秘密、API 密钥、令牌或密码?连接字符串是否参数化?检查日志输出中的凭据。
数据暴露 —— 错误输出、日志记录或 API 响应是否泄露了内部状态、堆栈跟踪、数据库模式或 PII?
依赖风险 —— 智能体是否引入了新的依赖项?如果是,它们是否维护良好、版本正确且没有已知漏洞?
竞态条件和状态 —— 对于并发代码:共享资源是否得到适当同步?是否存在 TOCTOU(检查时间与使用时间)漏洞?
对于每个发现,智能体将其分类为:
来自简化阶段的相同重构停止钩子在此处适用。安全重构会单独呈现,并附带严重性和攻击向量的额外上下文:
[simplify-and-harden] 安全重构提议:
新的 /admin/export 端点继承了基础认证,但没有基于角色的访问检查。任何经过认证的用户都可以触发完整的数据导出。
严重性:高
攻击向量:权限提升
建议修复:在执行处理程序之前,添加需要 'admin' 角色的角色守卫。这将更改此路由的中间件链。
受影响文件:src/api/routes/admin.ts (第 12 行)
预计差异:+8 行
[approve] [reject] [show diff] [skip all security refactors]
当预算紧张时,安全补丁(非重构)优先于简化更改。
目标: 在智能体仍记得原因时,捕获非显而易见的决策。
这特意保持轻量级——不是文档阶段,只是决策捕获。
此技能生成一个结构化摘要,附加到任务输出中:
simplify_and_harden:
version: "0.1.0"
task_id: "<original task ID>"
execution:
mode: "interactive"
mode_source: "auto_detected" # "auto_detected", "config", "env_override"
human_present: true
scope:
files_reviewed: ["src/api/handler.ts", "src/utils/validate.ts"]
original_diff_lines: 142
additional_changes_lines: 18
budget_exceeded: false
simplify:
applied:
- file: "src/api/handler.ts"
line: 45
type: "consolidation"
category: "refactor"
approval: "approved_by_user"
description: "将 handleCreate 和 handleUpdate 中的重复验证逻辑合并到共享的 validatePayload 函数中"
flagged:
- file: "src/utils/validate.ts"
type: "over-abstraction"
category: "refactor"
approval: "skipped_by_user"
description: "ValidationStrategy 接口可能不必要 —— 仅存在一个实现。如果没有计划添加其他策略,请考虑内联。"
confidence: "medium"
cosmetic_applied:
- file: "src/api/handler.ts"
line: 12
type: "dead_code"
description: "移除了未使用的已弃用 AuthHelper 导入"
harden:
applied:
- file: "src/api/handler.ts"
line: 62
type: "input_validation"
severity: "high"
description: "添加了 pageSize 参数的边界检查 —— 之前接受任意整数"
flagged_critical:
- file: "src/api/handler.ts"
type: "authorization"
description: "新的 /admin/export 端点继承了基础认证但没有角色检查 —— 任何经过认证的用户都可以访问。需要人工决定角色策略。"
flagged_advisory:
- file: "src/utils/validate.ts"
type: "error_handling"
description: "第 31 行的 catch 块记录了完整的请求体,其中可能包含生产环境中的 PII"
document:
comments_added: 2
locations:
- file: "src/api/handler.ts"
line: 78
comment: "// 分页使用基于游标的方法而非偏移量 —— 偏移量在页面间删除项目时会失效"
- file: "src/api/handler.ts"
line: 93
comment: "// 变通方法:旧版 API 返回不带时区的日期字符串。在迁移完成前假定为 UTC(见 TICKET-1234)"
learning_loop:
target_skill: "self-improvement"
log_file: ".learnings/LEARNINGS.md"
candidates:
- pattern_key: "simplify.dead_code"
pass: "simplify"
finding_type: "dead_code"
severity: "low"
source_file: "src/api/handler.ts"
source_line: 12
suggested_rule: "在最终确定任务前移除死代码和未使用的导入。"
- pattern_key: "harden.input_validation"
pass: "harden"
finding_type: "input_validation"
severity: "high"
source_file: "src/api/handler.ts"
source_line: 62
suggested_rule: "在使用前验证并边界检查外部输入。"
recurrence_window_days: 30
promotion_threshold:
min_occurrences: 3
min_distinct_tasks: 2
summary:
simplify_applied: 1
simplify_cosmetic_applied: 1
simplify_flagged: 1
simplify_rejected_by_user: 0
simplify_skipped_by_user: 1
harden_applied: 1
harden_flagged_critical: 1
harden_flagged_advisory: 1
harden_rejected_by_user: 0
comments_added: 2
total_additional_lines: 18
budget_utilization: "12.7%"
human_prompts_shown: 3
human_prompts_approved: 1
human_prompts_rejected: 0
human_prompts_skipped: 1
human_prompts_timed_out: 1
learning_candidates: 2
learning_promotions_recommended: 1
review_followup_required: true
当任何未解决的发现(关键/建议标记、跳过或超时的重构提议)仍然存在,或当 budget_exceeded 为 true 时,将 review_followup_required 设置为 true。仅当不需要后续跟进时才将其设置为 false。
Simplify & Harden 将其重复出现的质量/安全发现反馈给 self-improvement 技能,以便重复出现的问题可以成为持久的提示规则。
每次运行后:
pattern_key:
simplify.dead_code, simplify.naming, simplify.control_flowharden.input_validation, harden.authorization, harden.error_handlingsimplify_and_harden.learning_loop.candidates 中发出这些模式候选。self-improvement,后者在 .learnings/LEARNINGS.md 中记录或更新条目(而不是创建重复的一次性笔记)。>= 2 个不同任务出现 >= 3 次。CLAUDE.md, AGENTS.md, .github/copilot-instructions.md 或等效文件),以减少重复问题。这使得 Simplify & Harden 专注于每项任务的清理/加固,而 self-improvement 则负责跨任务记忆和推广。
此技能适用于通用编码智能体会话,其中人类可以即时批准重构。
行为:
[approve], [reject], [show diff] 或 [skip all refactors]对于 CI 管道和无头自动化,请使用 simplify-and-harden-ci。
要激活此技能,请在您的智能体上下文文件中引用它。
特定于智能体的复制粘贴代码片段位于 references/agent-context-snippets.md 中。仅加载您活动智能体的代码片段以保持上下文简洁。
任何智能体集成的核心不变性:
注意事项:某些智能体在高自主模式下可能无法可靠地暂停等待批准。在生产使用前验证此行为。
此技能设计用于任何遵循基于任务工作流的编码智能体。它不绑定于任何特定的智能体框架或产品。
程序化集成(具有技能/钩子 API 的智能体):
基于提示的集成(没有正式技能 API 的基于聊天的智能体):
输出模式是与智能体无关的 YAML。消费工具只需要解析结构化摘要。
此技能与智能体无关。它钩入任何暴露任务完成生命周期事件的编码智能体。以下示例是通用的——请根据您智能体的特定 API 进行调整。
此技能钩入智能体的任务完成生命周期。建议的集成模式:
agent.on('task:complete', async (context) => {
if (context.diff.isNonTrivial() && !context.flags.includes('no-review')) {
const result = await skills.run('simplify-and-harden', {
diff: context.diff,
files: context.modifiedFiles,
budget: { maxLines: context.diff.linesChanged * 0.2, maxTime: 60000 }
});
context.appendOutput(result.summary);
}
});
支持此技能的智能体应实现以下接口:
对于不支持程序化技能钩子的智能体(例如,基于聊天的编码智能体,如 Claude Code、Cursor、Copilot Chat),此技能可以作为任务后提示注入来实现:
完成任务后,运行 Simplify & Harden 审查:
1. 仅审查您修改的文件
2. 简化:您的默认操作是清理 —— 移除死代码、未使用的导入、修复命名、收紧控制流、减少不必要的公共表面。直接应用这些。重构(合并函数、更改抽象、结构调整)**不是**默认操作。仅当代码确实错误或改进巨大时才提议重构。如果您提议一个,请描述它并在应用前请求批准。
3. 加固:检查输入验证漏洞、注入向量、认证问题、暴露的秘密和错误处理问题。直接应用简单的补丁。
对于改变结构的安全重构,描述问题及其严重性并请求批准。
4. 文档记录:添加最多 5 条关于非显而易见决策的注释。
5. 输出您更改了什么、标记了什么以及未处理什么的摘要。
对于 GitHub Actions 或其他 CI/无头使用,运行 simplify-and-harden-ci。
# 示例配置(根据您智能体的配置格式调整路径)
# 例如,.agent/skills.yaml, .claude/skills.yaml, .cursor/skills.yaml
simplify-and-harden:
enabled: true
budget:
max_diff_ratio: 0.2 # 最大额外更改占原始差异的比例
max_time_seconds: 60 # 硬性时间限制
simplify:
enabled: true
auto_apply_cosmetic: true # 表面修复无需提示即可应用
refactor_requires_approval: true # 始终为 true —— 无法禁用
harden:
enabled: true
auto_apply_patches: true # 简单的安全补丁无需提示即可应用
refactor_requires_approval: true # 始终为 true —— 无法禁用
document:
enabled: true
max_comments: 5
stop_hook:
mode: "interactive"
show_diff_preview: true
allow_skip_all: true
timeout_seconds: 300 # 5 分钟 —— 人类在键盘前
timeout_action: "flag" # 假设他们离开了,不要丢弃
skip_patterns: # 从审查中排除的 Glob 模式
- "**/*.test.*"
- "**/*.spec.*"
- "**/migrations/**"
为什么是任务完成后而不是持续进行? 在实现过程中持续审查会创建反馈循环,减慢智能体速度,并可能导致振荡(简化,然后重新复杂化,然后再简化)。任务完成后为智能体提供了一个稳定的代码库进行审查。
为什么是简化优先,而不是重构优先? 智能体喜欢重构。如果允许“改进”代码,它们会重构它。但大多数任务后的改进都是表面的:一个未使用的导入、一个糟糕的命名、一个不必要的深层条件语句。这些占据了 80% 以上的价值,且风险几乎为零。重构则带有真实风险——它可能引入错误、破坏测试并膨胀差异。通过将简化设为默认、重构设为例外,此技能提供了持续的价值,而不会出现意外的重写。重构的标准应该是“这确实是错误的”,而不是“这可以稍微好一点”。
为什么要有预算? 没有约束,智能体会将审查阶段视为无限制重构的许可。20% 规则使此技能保持专注:改进你所构建的,而不是重建它。
为什么将简化与加固分开? 它们需要不同的思维方式。简化问“这是否是我意图最清晰的表达?”,而加固问“这如何被利用?”。将它们混为一谈会导致两者都效果不佳。顺序运行它们也让我们在预算紧张时优先考虑安全修复。
为什么要有文档记录微阶段? 智能体在无提示的情况下非常不擅长记录其推理过程。审查智能体生成代码的人类一致报告,最大的摩擦是理解为什么做出某个选择。五条注释是微不足道的成本,却能极大地节省审查时间。
每周安装数
302
仓库
GitHub 星标数
72
首次出现
2026年2月21日
安全审计
安装于
codex299
github-copilot299
opencode298
gemini-cli298
cursor298
kimi-cli297
npx skills add pskoett/pskoett-ai-skills/skills/simplify-and-harden
For CI-only execution, use:
npx skills add pskoett/pskoett-ai-skills/skills/simplify-and-harden-ci
| Field | Value |
|---|---|
| Skill ID | simplify-and-harden |
| Version | 0.1.0 |
| Trigger | Post-completion hook |
| Author | Peter Skøtt Pedersen |
| Category | Code Quality / Security |
| Priority | Recommended |
When a coding agent completes a task, it holds peak contextual understanding of the problem, the solution, and the tradeoffs it made along the way. This context degrades immediately -- the next task wipes the slate. Simplify & Harden exploits that peak context window to perform two focused review passes before the agent moves on.
Most agents solve the ticket and stop. This skill turns "done" into "done well."
The operating philosophy is a deliberate "fresh eyes" self-review before moving on: carefully re-read all newly written code and all existing code modified in the task, and look hard for obvious bugs, errors, confusing logic, brittle assumptions, naming issues, and missed hardening opportunities. The goal is not to expand scope or rewrite the solution -- it is to use peak context to perform a disciplined first review pass while the agent still remembers the intent behind every change.
This skill is a post-completion self-pass and does not replace an independent review pass.
Recommended flow:
If the two disagree, treat the independent review findings as the external gate and either fix or explicitly waive findings.
The skill activates automatically when ALL of the following are true:
Non-trivial code change definition
Treat a diff as non-trivial when it satisfies BOTH of the following:
*.ts, *.tsx, *.js, *.jsx, *.py, *.go, *.rs, *.java, *.cs, *.rb, *.php, *.swift, , , ).Treat the diff as non-trivial = false when it is docs-only, config-only, comments-only, formatting-only, generated artifacts only, or tests-only.
The skill does NOT activate when:
--no-review or equivalent flagHard rule: Only touch code modified in this task.
The agent MUST NOT:
The agent SHOULD flag out-of-scope concerns in the summary output rather than acting on them.
Budget limits:
budget_exceeded flagObjective: Reduce unnecessary complexity introduced during implementation.
Default posture: simplify, don't restructure. The primary goal of this pass is lightweight cleanup -- removing noise, tightening naming, killing dead code. The agent should bias heavily toward cosmetic fixes that make the code cleaner without changing its structure. Refactoring is the exception, not the rule.
Fresh-eyes start (mandatory): Before making any edits in this pass, re-read all code added or modified in this task with "fresh eyes" and actively look for obvious bugs, errors, confusing logic, brittle assumptions, naming issues, and missed hardening opportunities.
The agent reviews its own work and asks:
"Now that I understand the full solution, is there a simpler way to express this?"
Dead code and scaffolding -- Did I leave behind debug logs, commented-out attempts, unused imports, or temporary variables from my iteration loop? Remove them.
Naming clarity -- Do function names, variables, and parameters make sense when read fresh? Names that made sense mid-implementation often read poorly after the fact. Rename them.
Control flow -- Can any nested conditionals be flattened? Can early returns replace deep nesting? Are there boolean expressions that could be simplified? Tighten them.
API surface -- Did I expose more than necessary? Could any public methods/functions be private? Reduce visibility.
Over-abstraction -- Did I create classes, interfaces, or wrapper functions that aren't justified by the current scope? Agents tend to over-engineer. Flag it, but don't restructure unless the win is significant.
Consolidation opportunities -- Did I spread logic across multiple functions or files when it could live in one place? Flag it, but only propose a refactor if the duplication is egregious and the consolidation is clean.
For each finding, the agent categorizes it as:
Refactor Stop Hook (mandatory):
Any change the agent classifies as a refactor triggers an interactive prompt. The agent MUST:
The agent does not batch refactor proposals. Each refactor is presented individually so the human can approve, reject, or modify on a case-by-case basis.
[simplify-and-harden] Refactor proposal (1 of 2):
I want to merge duplicated validation logic from handleCreate() and
handleUpdate() into a shared validatePayload() function.
Why: Both functions validate the same fields with identical rules.
The duplication was introduced because I built handleUpdate as a
copy of handleCreate during implementation.
Files affected: src/api/handler.ts (lines 34-67)
Estimated diff: -22 lines, +14 lines
[approve] [reject] [show diff] [skip all refactors]
If the human selects skip all refactors, the agent skips remaining refactor proposals and moves to the Harden pass. Skipped refactors still appear in the output summary as flagged with status skipped_by_user.
Cosmetic fixes do not trigger the stop hook. They are applied silently (and reported in the output summary). The rationale: removing an unused import is not a judgment call. Restructuring code is.
Objective: Close security and resilience gaps while the agent still understands the code's intent.
The agent reviews its own work and asks:
"If someone malicious saw this code, what would they try?"
Input validation -- Are all external inputs (user input, API params, file paths, environment variables) validated before use? Check for type coercion issues, missing bounds checks, and unconstrained string lengths.
Error handling -- Are catch blocks specific? Are errors logged with context but without leaking sensitive data? Are there any swallowed exceptions?
Injection vectors -- Check for SQL injection, XSS, command injection, path traversal, and template injection in any code that builds strings from external input.
Authentication and authorization -- Do new endpoints or functions enforce auth? Are permission checks present and correct? Is there any privilege escalation risk?
Secrets and credentials -- Are there hardcoded secrets, API keys, tokens, or passwords? Are connection strings parameterized? Check for credentials in log output.
Data exposure -- Does error output, logging, or API responses leak internal state, stack traces, database schemas, or PII?
Dependency risk -- Did the agent introduce new dependencies? If so, are they well-maintained, properly versioned, and free of known vulnerabilities?
Race conditions and state -- For concurrent code: are shared resources properly synchronized? Are there TOCTOU (time-of-check-to-time-of-use) vulnerabilities?
For each finding, the agent categorizes it as:
The same Refactor Stop Hook from the Simplify pass applies here. Security refactors are presented individually with the added context of severity and attack vector:
[simplify-and-harden] Security refactor proposal:
The new /admin/export endpoint inherits base authentication but has
no role-based access check. Any authenticated user can trigger a
full data export.
Severity: HIGH
Vector: Privilege escalation
Proposed fix: Add role guard requiring 'admin' role before the
handler executes. This changes the middleware chain for this route.
Files affected: src/api/routes/admin.ts (line 12)
Estimated diff: +8 lines
[approve] [reject] [show diff] [skip all security refactors]
Security patches (not refactors) are prioritized over simplification changes when budget is constrained.
Objective: Capture non-obvious decisions while the agent still remembers why it made them.
This is deliberately lightweight -- not a documentation pass, just decision capture.
The skill produces a structured summary appended to the task output:
simplify_and_harden:
version: "0.1.0"
task_id: "<original task ID>"
execution:
mode: "interactive"
mode_source: "auto_detected" # "auto_detected", "config", "env_override"
human_present: true
scope:
files_reviewed: ["src/api/handler.ts", "src/utils/validate.ts"]
original_diff_lines: 142
additional_changes_lines: 18
budget_exceeded: false
simplify:
applied:
- file: "src/api/handler.ts"
line: 45
type: "consolidation"
category: "refactor"
approval: "approved_by_user"
description: "Merged duplicated validation logic from handleCreate and handleUpdate into shared validatePayload function"
flagged:
- file: "src/utils/validate.ts"
type: "over-abstraction"
category: "refactor"
approval: "skipped_by_user"
description: "ValidationStrategy interface may be unnecessary -- only one implementation exists. Consider inlining if no additional strategies are planned."
confidence: "medium"
cosmetic_applied:
- file: "src/api/handler.ts"
line: 12
type: "dead_code"
description: "Removed unused import of deprecated AuthHelper"
harden:
applied:
- file: "src/api/handler.ts"
line: 62
type: "input_validation"
severity: "high"
description: "Added bounds check on pageSize parameter -- previously accepted arbitrary integers"
flagged_critical:
- file: "src/api/handler.ts"
type: "authorization"
description: "New /admin/export endpoint inherits base auth but no role check -- any authenticated user can access it. Requires human decision on role policy."
flagged_advisory:
- file: "src/utils/validate.ts"
type: "error_handling"
description: "Catch block on L31 logs full request body which may contain PII in production"
document:
comments_added: 2
locations:
- file: "src/api/handler.ts"
line: 78
comment: "// Pagination uses cursor-based approach instead of offset -- offset breaks when items are deleted between pages"
- file: "src/api/handler.ts"
line: 93
comment: "// WORKAROUND: Legacy API returns dates as strings without timezone. Assuming UTC until migration completes (see TICKET-1234)"
learning_loop:
target_skill: "self-improvement"
log_file: ".learnings/LEARNINGS.md"
candidates:
- pattern_key: "simplify.dead_code"
pass: "simplify"
finding_type: "dead_code"
severity: "low"
source_file: "src/api/handler.ts"
source_line: 12
suggested_rule: "Remove dead code and unused imports before finalizing a task."
- pattern_key: "harden.input_validation"
pass: "harden"
finding_type: "input_validation"
severity: "high"
source_file: "src/api/handler.ts"
source_line: 62
suggested_rule: "Validate and bound-check external inputs before use."
recurrence_window_days: 30
promotion_threshold:
min_occurrences: 3
min_distinct_tasks: 2
summary:
simplify_applied: 1
simplify_cosmetic_applied: 1
simplify_flagged: 1
simplify_rejected_by_user: 0
simplify_skipped_by_user: 1
harden_applied: 1
harden_flagged_critical: 1
harden_flagged_advisory: 1
harden_rejected_by_user: 0
comments_added: 2
total_additional_lines: 18
budget_utilization: "12.7%"
human_prompts_shown: 3
human_prompts_approved: 1
human_prompts_rejected: 0
human_prompts_skipped: 1
human_prompts_timed_out: 1
learning_candidates: 2
learning_promotions_recommended: 1
review_followup_required: true
Set review_followup_required to true when any unresolved finding remains (critical/advisory flags, skipped or timed-out refactor proposals), or when budget_exceeded is true. Set it to false only when no follow-up is required.
Simplify & Harden feeds its recurring quality/security findings into the self-improvement skill so repeated issues can become durable prompt rules.
After each run:
pattern_key:
simplify.dead_code, simplify.naming, simplify.control_flowharden.input_validation, harden.authorization, harden.error_handlingsimplify_and_harden.learning_loop.candidates.self-improvement, which logs or updates entries in .learnings/LEARNINGS.md (instead of creating duplicate one-off notes).This keeps Simplify & Harden focused on per-task cleanup/hardening while self-improvement owns cross-task memory and promotion.
This skill is for general coding-agent sessions where a human can approve refactors in-line.
Behavior:
[approve], [reject], [show diff], or [skip all refactors]For CI pipelines and headless automation, use simplify-and-harden-ci.
To activate this skill, reference it in your agent context file.
Agent-specific copy-paste snippets are in references/agent-context-snippets.md. Load only the snippet for your active agent to keep context lean.
Core invariants for any agent integration:
Precaution: some agents may not reliably pause for approval in high-autonomy modes. Validate this behavior before production use.
This skill is designed to work with any coding agent that follows a task-based workflow. It is not tied to any specific agent framework or product.
Programmatic integration (agents with skill/hook APIs):
Prompt-based integration (chat-based agents without formal skill APIs):
The output schema is agent-agnostic YAML. Consuming tools only need to parse the structured summary.
This skill is agent-agnostic. It hooks into any coding agent that exposes a task completion lifecycle event. The examples below are generic -- adapt them to your agent's specific API.
The skill hooks into the agent's task completion lifecycle. Suggested integration pattern:
agent.on('task:complete', async (context) => {
if (context.diff.isNonTrivial() && !context.flags.includes('no-review')) {
const result = await skills.run('simplify-and-harden', {
diff: context.diff,
files: context.modifiedFiles,
budget: { maxLines: context.diff.linesChanged * 0.2, maxTime: 60000 }
});
context.appendOutput(result.summary);
}
});
Agents that support this skill should implement the following interface:
For agents that don't support programmatic skill hooks (e.g., chat-based coding agents like Claude Code, Cursor, Copilot Chat), this skill can be implemented as a post-task prompt injection:
After completing the task, run the Simplify & Harden review:
1. Review only the files you modified
2. Simplify: Your default action is cleanup -- remove dead code, unused
imports, fix naming, tighten control flow, reduce unnecessary public
surface. Apply these directly. Refactoring (merging functions, changing
abstractions, restructuring) is NOT the default. Only propose a refactor
when the code is genuinely wrong or the improvement is substantial.
If you propose one, describe it and ask for approval before applying.
3. Harden: Check for input validation gaps, injection vectors, auth issues,
exposed secrets, and error handling problems. Apply simple patches directly.
For security refactors that change structure, describe the issue with
severity and ask for approval.
4. Document: Add up to 5 comments on non-obvious decisions.
5. Output a summary of what you changed, what you flagged, and
what you left alone.
For GitHub Actions or other CI/headless usage, run simplify-and-harden-ci.
# Example configuration (adapt path to your agent's config format)
# e.g., .agent/skills.yaml, .claude/skills.yaml, .cursor/skills.yaml
simplify-and-harden:
enabled: true
budget:
max_diff_ratio: 0.2 # Max additional changes as ratio of original diff
max_time_seconds: 60 # Hard time limit
simplify:
enabled: true
auto_apply_cosmetic: true # Cosmetic fixes applied without prompting
refactor_requires_approval: true # ALWAYS true -- cannot be disabled
harden:
enabled: true
auto_apply_patches: true # Simple security patches applied without prompting
refactor_requires_approval: true # ALWAYS true -- cannot be disabled
document:
enabled: true
max_comments: 5
stop_hook:
mode: "interactive"
show_diff_preview: true
allow_skip_all: true
timeout_seconds: 300 # 5 min -- human is at the keyboard
timeout_action: "flag" # Assume they stepped away, don't discard
skip_patterns: # Glob patterns to exclude from review
- "**/*.test.*"
- "**/*.spec.*"
- "**/migrations/**"
Why post-completion and not continuous? Continuous review during implementation creates feedback loops that slow the agent down and can cause oscillation (simplify, then re-complicate, then re-simplify). Post-completion gives the agent a stable codebase to review against.
Why simplify-first, not refactor-first? Agents love to refactor. Given permission to "improve" code, they will restructure it. But most post-task improvements are cosmetic: a dead import, a bad name, a needlessly deep conditional. These account for 80%+ of the value with near-zero risk. Refactoring carries real risk -- it can introduce bugs, break tests, and bloat diffs. By making simplification the default and refactoring the exception, the skill delivers consistent value without surprise rewrites. The bar for a refactor should be "this is genuinely wrong" not "this could be slightly better."
Why a budget? Without constraints, agents will use review passes as license for unbounded refactoring. The 20% rule keeps the skill focused: improve what you built, don't rebuild it.
Why separate simplify from harden? They require different mindsets. Simplify asks "is this the clearest expression of my intent?" while Harden asks "how could this be exploited?" Conflating them leads to mediocre results on both. Running them sequentially also lets us prioritize security fixes when budget is tight.
Why the document micro-pass? Agents are terrible at documenting their reasoning unprompted. Humans reviewing agent-generated code consistently report that the biggest friction is understanding why a choice was made. Five comments is a trivial cost for enormous review-time savings.
Weekly Installs
302
Repository
GitHub Stars
72
First Seen
Feb 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex299
github-copilot299
opencode298
gemini-cli298
cursor298
kimi-cli297
通过 LiteLLM 代理让 Claude Code 对接 GitHub Copilot 运行 | 高级变通方案指南
22,200 周安装
高端实用极简主义UI架构师 | 文档风格网页设计 | 前端工程指令
3,900 周安装
OKX DEX 市场工具 - 链上价格、K线、盈亏分析与地址追踪
3,600 周安装
编码规范与最佳实践指南:TypeScript/JavaScript 和 React 开发标准
3,600 周安装
深度研究技能:8阶段AI研究流程,交付有引文支持的研究报告 | 199-biotechnologies
3,600 周安装
钱包策略生成器 | 为EVM和Solana钱包创建安全策略规则
3,700 周安装
完整输出强制执行 - AI代码生成完整性保障工具 | 杜绝省略代码
4,100 周安装
*.kt*.scala*.sh>= 3 occurrences across >= 2 distinct tasks in a 30-day window.CLAUDE.md, AGENTS.md, .github/copilot-instructions.md, or equivalent) to reduce repeat issues.