← Back to Skills Marketplace
534422530

迭代优化器

by 534422530 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
48
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install laosi-iteration-opt
Description
迭代优化器 - 原创技能。自动评估和改进AI生成的代码,通过多轮迭代达到最优结果。适用于代码优化、性能调优、质量提升等场景。
README (SKILL.md)

⚠️ 发布规则

所有发布到ClawHub的技能必须严格测试,确定没有问题再发布


技能测试验证清单

  • frontmatter格式正确
  • 迭代流程完整
  • 评估指标明确
  • 收敛条件清晰
  • 无语法错误

Iteration Optimizer - 迭代优化器

原创技能 | 激活词: 迭代优化 / 改进代码 / 自动调优

核心概念

AI生成的代码通常需要多轮迭代优化:

  • 第一版往往不是最优
  • 需要持续的反馈和调整
  • 迭代是达成高质量的关键

迭代流程

原始代码
    ↓
第1轮评估 → 问题1 + 建议1
    ↓
应用改进
    ↓
第2轮评估 → 问题2 + 建议2
    ↓
...
    ↓
收敛 (达到目标标准)

评估维度

1. 正确性 (Correctness)

CORRECTNESS_METRICS = {
    'compilation': '能否编译通过',
    'test_pass': '测试是否通过',
    'edge_cases': '边界情况处理',
    'error_handling': '错误处理',
}

2. 性能 (Performance)

PERFORMANCE_METRICS = {
    'time_complexity': '时间复杂度',
    'space_complexity': '空间复杂度',
    'response_time': '响应时间',
    'resource_usage': '资源消耗',
}

3. 可读性 (Readability)

READABILITY_METRICS = {
    'naming': '命名是否清晰',
    'comments': '注释是否充分',
    'structure': '结构是否合理',
    'formatting': '格式是否规范',
}

4. 可维护性 (Maintainability)

MAINTAINABILITY_METRICS = {
    'coupling': '耦合度',
    'cohesion': '内聚度',
    'duplication': '重复代码',
    'dependencies': '依赖关系',
}

评分系统

def evaluate_code(code: str, metrics: dict) -> Score:
    scores = {}
    
    for metric_name, metric_func in metrics.items():
        scores[metric_name] = metric_func(code)
    
    # 加权平均
    weights = {
        'correctness': 0.4,
        'performance': 0.3,
        'readability': 0.2,
        'maintainability': 0.1,
    }
    
    final_score = sum(scores[k] * weights[k] for k in weights)
    
    return Score(
        overall=final_score,
        breakdown=scores,
        grade=get_grade(final_score),
    )

def get_grade(score: float) -> str:
    if score >= 0.9: return 'A'
    elif score >= 0.8: return 'B'
    elif score >= 0.7: return 'C'
    elif score >= 0.6: return 'D'
    else: return 'F'

改进建议生成

def generate_improvements(code: str, score: Score) -> list[Improvement]:
    improvements = []
    
    if score.correctness \x3C 0.8:
        improvements.append(Improvement(
            priority='high',
            category='correctness',
            issue='测试未全部通过',
            suggestion='添加边界条件测试',
        ))
    
    if score.performance \x3C 0.7:
        improvements.append(Improvement(
            priority='high',
            category='performance',
            issue='循环嵌套过多',
            suggestion='考虑使用缓存或优化算法',
        ))
    
    if score.readability \x3C 0.6:
        improvements.append(Improvement(
            priority='medium',
            category='readability',
            issue='变量命名不清晰',
            suggestion='使用描述性命名',
        ))
    
    return improvements

迭代控制

最大迭代次数

MAX_ITERATIONS = 5  # 防止无限循环

收敛条件

CONVERGENCE = {
    'score_threshold': 0.9,      # 达到90%就停止
    'improvement_threshold': 0.02,  # 提升小于2%停止
    'max_iterations': 5,         # 最多5轮
    'time_limit': 60,            # 最多60秒
}

终止条件

def should_stop(iterations: int, score: Score, prev_score: Score) -> bool:
    # 达到目标分数
    if score.overall >= 0.9:
        return True
    
    # 提升太小
    improvement = score.overall - prev_score.overall
    if improvement \x3C 0.02 and iterations > 2:
        return True
    
    # 达到最大次数
    if iterations >= 5:
        return True
    
    return False

输出格式

## 迭代优化报告

### 第 3 轮迭代

### 当前评分
- **总分**: 0.85 (B)
- 正确性: 0.90
- 性能: 0.78
- 可读性: 0.82
- 可维护性: 0.85

### 本轮改进
✅ 修复了空指针异常
✅ 优化了循环结构

### 剩余问题
⚠️ [中等] 注释不足
⚠️ [中等] 可以使用更高效的算法

### 建议改进
1. 添加函数文档注释
2. 考虑用字典查找替代线性搜索

### 收敛状态
进度: 3/5 轮
提升: +0.08 (相比第2轮)
状态: 🔄 继续迭代

实际应用示例

场景: 优化排序算法

用户: "帮我优化这个排序函数"

第1轮:
- 评分: 0.65 (D)
- 问题: O(n²) 复杂度太高
- 建议: 使用快速排序

第2轮:
- 评分: 0.78 (C+)
- 问题: 递归栈溢出风险
- 建议: 改用迭代实现

第3轮:
- 评分: 0.88 (B+)
- 问题: 基准选择不合理
- 建议: 使用三数取中法

第4轮:
- 评分: 0.93 (A)
- 状态: ✅ 收敛完成

集成建议

配合技能 效果
workflow-verifier 验证每次迭代结果
hallucination-detector 检测迭代中的幻觉
karpathy-principles 保持代码简洁

原创性声明

本技能为原创,融合了:

  • 代码质量评估模型
  • 迭代优化算法
  • 收敛判断逻辑
  • 多维度评分系统

作者: laosi 创建日期: 2026-04-28

Usage Guidance
This skill appears coherent and low-risk as an instruction-only optimizer. Before using it, ensure the agent's execution environment will safely run any user code (use sandboxing or CI runners), avoid feeding code that contains credentials or secrets, and verify test/benchmark commands the agent will run if you need strict isolation or resource limits.
Capability Analysis
Type: OpenClaw Skill Name: laosi-iteration-opt Version: 1.0.0 The skill is a conceptual framework and set of instructions (SKILL.md) designed to guide an AI agent in performing iterative code optimization. It contains pseudo-code for scoring metrics and convergence logic but lacks any executable scripts, network calls, or requests for sensitive data. The content is entirely aligned with its stated purpose of improving code quality through structured feedback.
Capability Assessment
Purpose & Capability
The name/description (iteration/optimization of code) match the SKILL.md content: metrics, scoring, improvement generation and iteration control. There are no unrelated required binaries, env vars, or config paths that would be disproportionate to a code-optimization helper.
Instruction Scope
SKILL.md contains high-level pseudocode and a clear iterative workflow for evaluating and improving code (correctness, performance, readability, maintainability). It does not instruct reading system files, environment variables, or sending data to external endpoints. Note: the file is conceptual — it doesn't provide concrete sandboxing/execution steps for running tests or benchmarks, so actual runtime behavior depends on how the host agent executes user code (e.g., whether it runs code unsandboxed).
Install Mechanism
No install spec and no code files (instruction-only). This minimizes on-disk risk — nothing is downloaded or executed by default.
Credentials
The skill declares no required environment variables, credentials, or config paths. No requests for unrelated secrets or access are present.
Persistence & Privilege
always is false and the skill does not request persistent system-wide privileges or modify other skills. It is user-invocable and allows model invocation (the platform default) which is expected for this type of skill.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install laosi-iteration-opt
  3. After installation, invoke the skill by name or use /laosi-iteration-opt
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
原创技能 - 多轮迭代优化AI生成代码
Metadata
Slug laosi-iteration-opt
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is 迭代优化器?

迭代优化器 - 原创技能。自动评估和改进AI生成的代码,通过多轮迭代达到最优结果。适用于代码优化、性能调优、质量提升等场景。 It is an AI Agent Skill for Claude Code / OpenClaw, with 48 downloads so far.

How do I install 迭代优化器?

Run "/install laosi-iteration-opt" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is 迭代优化器 free?

Yes, 迭代优化器 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does 迭代优化器 support?

迭代优化器 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created 迭代优化器?

It is built and maintained by 534422530 (@534422530); the current version is v1.0.0.

💬 Comments