Loading...
Loading...
Compare original and translation side by side
npx skills add pskoett/pskoett-ai-skills/simplify-and-hardennpx skills add pskoett/pskoett-ai-skills/simplify-and-harden-cinpx skills add pskoett/pskoett-ai-skills/simplify-and-hardennpx skills add pskoett/pskoett-ai-skills/simplify-and-harden-ci| Field | Value |
|---|---|
| Skill ID | |
| Version | 0.1.0 |
| Trigger | Post-completion hook |
| Author | Peter Skøtt Pedersen |
| Category | Code Quality / Security |
| Priority | Recommended |
| 字段 | 值 |
|---|---|
| 技能ID | |
| 版本 | 0.1.0 |
| 触发方式 | 任务完成后钩子 |
| 作者 | Peter Skøtt Pedersen |
| 分类 | 代码质量 / 安全 |
| 优先级 | 推荐使用 |
*.ts*.tsx*.js*.jsx*.py*.go*.rs*.java*.cs*.rb*.php*.swift*.kt*.scala*.sh--no-review*.ts*.tsx*.js*.jsx*.py*.go*.rs*.java*.cs*.rb*.php*.swift*.kt*.scala*.sh--no-reviewbudget_exceededbudget_exceeded"Now that I understand the full solution, is there a simpler way to express this?"
"既然我已经理解了完整的解决方案,有没有更简洁的方式来表达这段逻辑?"
[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]
skip all refactorsflaggedskipped_by_user[simplify-and-harden] 重构建议(1/2):
我想要将handleCreate()和handleUpdate()中重复的验证逻辑合并到共享的validatePayload()函数中。
原因:两个函数用完全相同的规则验证相同的字段。
重复代码是因为我在开发时将handleUpdate复制自handleCreate。
涉及文件:src/api/handler.ts(第34-67行)
预估变更行数:减少22行,增加14行
[批准] [拒绝] [查看差异] [跳过所有重构]
跳过所有重构flaggedskipped_by_user"If someone malicious saw this code, what would they try?"
"如果恶意攻击者看到这段代码,他们会尝试什么攻击方式?"
[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]
[simplify-and-harden] 安全重构建议:
新的/admin/export端点继承了基础身份验证,但没有基于角色的访问检查。任何已认证用户都可以触发全量数据导出。
严重程度:高
攻击向量:权限提升
修复建议:在处理器执行前添加角色守卫,要求用户拥有'admin'角色。这会修改该路由的中间件链。
涉及文件:src/api/routes/admin.ts(第12行)
预估变更行数:增加8行
[批准] [拒绝] [查看差异] [跳过所有安全重构]
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: truereview_followup_requiredtruebudget_exceededtruefalsesimplify_and_harden:
version: "0.1.0"
task_id: "<原始任务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: truebudget_exceededreview_followup_requiredtruefalseself-improvementpattern_keysimplify.dead_codesimplify.namingsimplify.control_flowharden.input_validationharden.authorizationharden.error_handlingsimplify_and_harden.learning_loop.candidatesself-improvement.learnings/LEARNINGS.md>= 3>= 2CLAUDE.mdAGENTS.md.github/copilot-instructions.mdself-improvementself-improvementpattern_keysimplify.dead_codesimplify.namingsimplify.control_flowharden.input_validationharden.authorizationharden.error_handlingsimplify_and_harden.learning_loop.candidatesself-improvement.learnings/LEARNINGS.mdCLAUDE.mdAGENTS.md.github/copilot-instructions.mdself-improvement[approve][reject][show diff][skip all refactors]simplify-and-harden-ci[批准][拒绝][查看差异][跳过所有重构]simplify-and-harden-cireferences/agent-context-snippets.mdreferences/agent-context-snippets.mdagent.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);
}
});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);
}
});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.完成任务后,运行Simplify & Harden审查:
1. 仅审查你修改的文件
2. 简化:默认操作是清理——移除死代码、未使用的导入、优化命名、优化控制流、减少不必要的公共暴露面。直接应用这些修改。重构(合并函数、更改抽象、调整结构)不是默认操作。仅当代码确实错误或改进收益显著时,才提出重构建议。若提出建议,请描述内容并在应用前请求批准。
3. 强化:检查输入验证漏洞、注入风险、认证问题、暴露的密钥和错误处理问题。直接应用简单的补丁。对于涉及结构变更的安全重构,请描述问题及严重程度,并请求批准。
4. 文档:最多添加5条关于非直观决策的注释。
5. 输出总结,说明你修改了什么、标记了什么以及忽略了什么。simplify-and-harden-cisimplify-and-harden-ciundefinedundefinedundefinedundefined