codspeed-setup-harness

Set up performance benchmarks and CodSpeed harness for a project. Use this skill whenever the user wants to create benchmarks, add performance tests, set up CodSpeed, configure codspeed.yml, integrate a benchmarking framework (criterion, divan, pytest-benchmark, vitest bench, go test -bench, google benchmark), or when the user says 'add benchmarks', 'set up perf tests', 'create a benchmark', 'benchmark this', or wants to measure performance of their code for the first time. Also trigger when the optimize skill needs benchmarks that don't exist yet.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "codspeed-setup-harness" with this command: npx skills add codspeedhq/codspeed/codspeedhq-codspeed-codspeed-setup-harness

Setup Harness

You are a performance engineer helping set up benchmarks and CodSpeed integration for a project. Your goal is to create useful, representative benchmarks and wire them up so CodSpeed can measure and track performance.

Step 1: Analyze the project

Before writing any benchmark code, understand what you're working with:

  1. Detect the language and build system: Look at the project structure, package files (Cargo.toml, package.json, pyproject.toml, go.mod, CMakeLists.txt), and source files.

  2. Identify existing benchmarks: Check for benchmark files, codspeed.yml, CI workflows mentioning CodSpeed or benchmarks.

  3. Identify hot paths: Look at the codebase to understand what the performance-critical code is. Public API functions, data processing pipelines, I/O-heavy operations, and algorithmic code are good candidates.

  4. Check CodSpeed auth: Ensure codspeed auth login has been run.

Step 2: Choose the right approach

Based on the language and what the user wants to benchmark, pick the right harness:

Language-specific harnesses (recommended when available)

These integrate deeply with CodSpeed and provide per-benchmark flamegraphs, fine-grained comparison, and simulation mode support.

LanguageFrameworkHow to set up
Rustdivan (recommended), criterion, bencherAdd codspeed-<framework>-compat as dependency using cargo add --rename
Pythonpytest-benchmarkInstall pytest-codspeed, use @pytest.benchmark or benchmark fixture
Node.jsvitest (recommended), tinybench v5, benchmark.jsInstall @codspeed/<framework>-plugin, configure in vitest/test config
Gogo test -benchNo packages needed — CodSpeed instruments go test -bench directly
C/C++Google BenchmarkBuild with CMake, CodSpeed instruments via valgrind-codspeed

Exec harness (universal)

For any language or when you want to benchmark a whole program (not individual functions):

  • Use codspeed exec -m <mode> -- <command> for one-off benchmarks
  • Or create a codspeed.yml with benchmark definitions for repeatable setups

The exec harness requires no code changes — it instruments the binary externally. This is ideal for:

  • Languages without a dedicated CodSpeed integration
  • End-to-end benchmarks (full program execution)
  • Quick setup when you just want to track a command's performance

Choosing simulation vs walltime mode

  • Simulation (default for Rust, Python, Node.js, C/C++): Deterministic CPU simulation, <1% variance, automatic flamegraphs. Best for CPU-bound code. Does not measure system calls or I/O.
  • Walltime (default for Go): Measures real execution time including I/O, threading, system calls. Best for I/O-heavy or multi-threaded code. Requires consistent hardware (use CodSpeed Macro Runners in CI).
  • Memory: Tracks heap allocations. Best for reducing memory usage. Supported for Rust, C/C++ with libc/jemalloc/mimalloc.

Step 3: Set up the harness

Rust with divan (recommended)

  1. Add the dependency:
cargo add divan
cargo add codspeed-divan-compat --rename divan --dev
  1. Create a benchmark file in benches/:
// benches/my_bench.rs
use divan;

fn main() {
    divan::main();
}

#[divan::bench]
fn bench_my_function() {
    // Call the function you want to benchmark
    // Use divan::black_box() to prevent compiler optimization
    divan::black_box(my_crate::my_function());
}
  1. Add to Cargo.toml:
[[bench]]
name = "my_bench"
harness = false
  1. Build and run:
cargo codspeed build -m simulation --bench my_bench
codspeed run -m simulation -- cargo codspeed run --bench my_bench

Rust with criterion

  1. Add dependencies:
cargo add criterion --dev
cargo add codspeed-criterion-compat --rename criterion --dev
  1. Create benchmark in benches/:
use criterion::{criterion_group, criterion_main, Criterion};

fn bench_my_function(c: &mut Criterion) {
    c.bench_function("my_function", |b| {
        b.iter(|| my_crate::my_function())
    });
}

criterion_group!(benches, bench_my_function);
criterion_main!(benches);
  1. Add to Cargo.toml and build/run same as divan.

Python with pytest-codspeed

  1. Install:
pip install pytest-codspeed
# or
uv add --dev pytest-codspeed
  1. Create benchmark tests:
# tests/test_benchmarks.py
import pytest

def test_my_function(benchmark):
    result = benchmark(my_module.my_function, arg1, arg2)
    # You can still assert on the result
    assert result is not None

# Or using the pedantic API for setup/teardown:
def test_with_setup(benchmark):
    data = prepare_data()
    benchmark.pedantic(my_module.process, args=(data,), rounds=100)
  1. Run:
codspeed run -m simulation -- pytest --codspeed

Node.js with vitest (recommended)

  1. Install:
npm install -D @codspeed/vitest-plugin
# or
pnpm add -D @codspeed/vitest-plugin
  1. Configure vitest (vitest.config.ts):
import { defineConfig } from "vitest/config";
import codspeed from "@codspeed/vitest-plugin";

export default defineConfig({
  plugins: [codspeed()],
});
  1. Create benchmark file:
// bench/my.bench.ts
import { bench, describe } from "vitest";

describe("my module", () => {
  bench("my function", () => {
    myFunction();
  });
});
  1. Run:
codspeed run -m simulation -- npx vitest bench

Go

No packages needed — CodSpeed instruments go test -bench directly.

  1. Create benchmark tests:
// my_test.go
func BenchmarkMyFunction(b *testing.B) {
    for i := 0; i < b.N; i++ {
        MyFunction()
    }
}
  1. Run (walltime is the default for Go):
codspeed run -m walltime -- go test -bench . ./...

C/C++ with Google Benchmark

  1. Install Google Benchmark (via CMake FetchContent or system package)

  2. Create benchmark:

#include <benchmark/benchmark.h>

static void BM_MyFunction(benchmark::State& state) {
    for (auto _ : state) {
        MyFunction();
    }
}
BENCHMARK(BM_MyFunction);

BENCHMARK_MAIN();
  1. Build and run with CodSpeed:
cmake -B build && cmake --build build
codspeed run -m simulation -- ./build/my_benchmark

Exec harness (any language)

For benchmarking whole programs without code changes:

  1. Create codspeed.yml:
$schema: https://raw.githubusercontent.com/CodSpeedHQ/codspeed/refs/heads/main/schemas/codspeed.schema.json

options:
  warmup-time: "1s"
  max-time: 5s

benchmarks:
  - name: "My program - small input"
    exec: ./my_binary --input small.txt

  - name: "My program - large input"
    exec: ./my_binary --input large.txt
    options:
      max-time: 30s
  1. Run:
codspeed run -m walltime

Or for a one-off:

codspeed exec -m walltime -- ./my_binary --input data.txt

Step 4: Write good benchmarks

Good benchmarks are representative, isolated, and stable. Here are guidelines:

  • Benchmark real workloads: Use realistic input data and sizes. A sort benchmark on 10 elements tells you nothing about how 10 million elements will perform.

  • Avoid benchmarking setup: Use the framework's setup/teardown mechanisms to exclude initialization from measurements.

  • Prevent dead code elimination: Use black_box() (Rust), benchmark.pedantic() (Python), or equivalent to ensure the compiler/runtime doesn't optimize away the work you're measuring.

  • Cover the critical path: Benchmark the functions that matter most to your users — the ones called frequently or on the hot path.

  • Test multiple scenarios: Different input sizes, different data distributions, edge cases. Performance characteristics often change with scale.

  • Keep benchmarks fast: Individual benchmarks should complete in milliseconds to low seconds. CodSpeed handles warmup and repetition — you provide the single iteration.

Step 5: Verify and run

After setting up:

  1. Run the benchmarks locally to verify they work:
# For language-specific harnesses
cargo codspeed build -m simulation && codspeed run -m simulation -- cargo codspeed run
# or
codspeed run -m simulation -- pytest --codspeed
# or
codspeed run -m simulation -- npx vitest bench
# etc.

# For exec harness
codspeed run -m walltime
  1. Check the output: You should see a results table and a link to the CodSpeed report.

  2. Verify flamegraphs: For simulation mode, check that flamegraphs are generated by visiting the report link or using the query_flamegraph MCP tool.

  3. Tell the user what was set up, show the first results, and suggest next steps (e.g., adding CI integration, running the optimize skill).

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

codspeed-optimize

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

CodeBuddy Coding

# CodeBuddy Coding Skill **版本:** 1.0.0 **创建时间:** 2026-03-31 **作者:** OpenClaw Team --- ## 📋 Skill 概述 **CodeBuddy Coding Skill** 是一个通用的 AI 编程能力扩展,让任何 OpenClaw agent 都能调用 CodeBuddy CLI 的强大功能。 ### 核心能力 - ✅ **AI 编程** - 代码生成、重构、调试、优化 - ✅ **文件操作** - 创建、修改、删除文件 - ✅ **命令执行** - 运行构建、测试、部署命令 - ✅ **进度监控** - 实时报告任务进度和状态 - ✅ **结构化输出** - JSON 格式的可解析输出 ### 适用场景 - **Developer Agent** - 编写代码、修复 Bug - **Architect Agent** - 生成项目脚手架 - **Tester Agent** - 编写测试用例 - **任何需要编程能力的 Agent** - 通用编程支持 --- ## 🚀 快速开始 ### 基本用法 ```javascript // 1. 加载 Skill const codebuddy = require('./skill'); // 2. 执行编程任务 const result = await codebuddy.execute({ task: '创建一个用户登录页面', context: { projectPath: '/path/to/project', techStack: 'Vue 3 + TypeScript' }, options: { outputFormat: 'json', permissionMode: 'bypassPermissions' } }); // 3. 获取结果 console.log(result.status); // 'success' console.log(result.filesModified); // ['src/views/Login.vue'] console.log(result.toolCalls); // [{tool: 'write_to_file', ...}] ``` ### 监听进度 ```javascript // 订阅进度事件 codebuddy.onProgress((progress) => { console.log(`进度: ${progress.percentage}%`); console.log(`当前任务: ${progress.currentTask}`); console.log(`已用时间: ${progress.elapsedTime}s`); }); ``` --- ## 🔧 配置说明 ### 环境要求 - **CodeBuddy CLI** v2.68.0+ - **Node.js** v16.0.0+ - **OpenClaw** coding-agent skill 框架 ### Skill 配置 ```json { "name": "codebuddy-coding", "version": "1.0.0", "type": "coding", "capabilities": [ "code-generation", "file-operations", "command-execution", "progress-monitoring" ], "dependencies": { "codebuddy-cli": ">=2.68.0" } } ``` --- ## 📚 API 文档 ### `execute(options)` 执行编程任务。 **参数:** ```typescript interface ExecuteOptions { task: string; // 任务描述 context?: { // 任务上下文 projectPath?: string; // 项目路径 techStack?: string; // 技术栈 files?: string[]; // 相关文件 }; options?: { // 执行选项 outputFormat?: 'json' | 'text'; // 输出格式 permissionMode?: 'default' | 'bypassPermissions'; // 权限模式 timeout?: number; // 超时时间(秒) }; } ``` **返回:** ```typescript interface ExecuteResult { status: 'success' | 'failed' | 'timeout'; filesModified: string[]; // 修改的文件列表 toolCalls: ToolCall[]; // 工具调用记录 reasoning: string[]; // 推理过程 duration: number; // 执行时长(秒) error?: string; // 错误信息 } ``` ### `onProgress(callback)` 订阅进度更新事件。 **参数:** ```typescript type ProgressCallback = (progress: { percentage: number; // 完成百分比 currentTask: string; // 当前任务描述 elapsedTime: number; // 已用时间(秒) estimatedTime?: number; // 预计剩余时间(秒) filesModified: string[]; // 已修改文件 toolCalls: number; // 已调用工具次数 }) => void; ``` ### `getStatus()` 获取当前任务状态。 **返回:** ```typescript interface TaskStatus { state: 'idle' | 'running' | 'completed' | 'failed'; taskId?: string; startTime?: Date; progress?: Progress; } ``` --- ## 🎯 使用示例 ### 示例1:创建新组件 ```javascript const codebuddy = require('./skill'); // 创建登录组件 const result = await codebuddy.execute({ task: '创建一个用户登录组件,包含用户名、密码输入框和登录按钮', context: { projectPath: '/path/to/vue-project', techStack: 'Vue 3 Composition API + TypeScript' } }); if (result.status === 'success') { console.log('组件创建成功!'); console.log('创建的文件:', result.filesModified); } ``` ### 示例2:修复 Bug ```javascript const codebuddy = require('./skill'); // 修复登录验证 Bug const result = await codebuddy.execute({ task: '修复用户登录时的验证逻辑,密码应该至少8位且包含数字和字母', context: { projectPath: '/path/to/project', files: ['src/views/Login.vue', 'src/utils/validator.ts'] } }); console.log('修复完成:', result.filesModified); ``` ### 示例3:监听长时间任务进度 ```javascript const codebuddy = require('./skill'); // 订阅进度 codebuddy.onProgress((progress) => { console.log(`[${progress.percentage}%] ${progress.currentTask}`); console.log(` 已修改 ${progress.filesModified.length} 个文件`); console.log(` 已执行 ${progress.toolCalls} 次操作`); console.log(` 用时 ${progress.elapsedTime}s`); }); // 执行长时间任务 const result = await codebuddy.execute({ task: '重构整个用户管理模块,使用更清晰的架构', context: { projectPath: '/path/to/project' }, options: { timeout: 600 // 10分钟超时 } }); ``` --- ## 🔍 进度监控原理 ### JSON 输出解析 CodeBuddy CLI 支持 `--output-format json` 输出结构化数据: ```bash codebuddy -p "任务描述" --output-format json --permission-mode bypassPermissions ``` **输出格式:** ```json { "status": "running", "tool_calls": [ { "tool": "write_to_file", "parameters": { "filePath": "src/Login.vue", "content": "..." }, "result": "success" } ], "files_modified": ["src/Login.vue"], "reasoning": [ "分析任务需求", "设计组件结构", "编写代码" ], "progress": { "percentage": 45, "current_task": "编写登录表单" } } ``` ### 进度解析流程 ```mermaid graph LR A[CodeBuddy CLI] -->|JSON Stream| B[Progress Monitor] B -->|Parse JSON| C[Progress Data] C -->|Emit Event| D[Event Callbacks] D -->|Update| E[Agent UI] ``` --- ## ⚙️ 高级配置 ### 自定义输出解析器 ```javascript const codebuddy = require('./skill'); // 自定义解析器 codebuddy.setOutputParser((jsonLine) => { // 自定义解析逻辑 return { percentage: jsonLine.progress?.percentage || 0, task: jsonLine.progress?.current_task || '处理中' }; }); ``` ### 超时和重试 ```javascript const result = await codebuddy.execute({ task: '复杂重构任务', options: { timeout: 1200, // 20分钟超时 retryCount: 3, // 失败重试3次 retryDelay: 5000 // 重试间隔5秒 } }); ``` --- ## 🐛 调试和日志 ### 启用详细日志 ```javascript const codebuddy = require('./skill'); // 启用调试模式 codebuddy.setDebugMode(true); // 所有 CLI 输出会被记录到控制台 const result = await codebuddy.execute({ task: '创建测试文件' }); ``` ### 查看执行日志 ```javascript // 获取最近的执行日志 const logs = codebuddy.getExecutionLogs(); console.log(logs); // [ // { time: '11:30:01', event: 'CLI_START', command: '...' }, // { time: '11:30:02', event: 'TOOL_CALL', tool: 'write_to_file' }, // { time: '11:30:05', event: 'CLI_END', status: 'success' } // ] ``` --- ## 🚨 错误处理 ### 错误类型 ```typescript enum CodeBuddyErrorType { CLI_NOT_FOUND = 'CLI_NOT_FOUND', // CodeBuddy CLI 未安装 INVALID_TASK = 'INVALID_TASK', // 无效的任务描述 TIMEOUT = 'TIMEOUT', // 执行超时 PERMISSION_DENIED = 'PERMISSION_DENIED', // 权限被拒绝 CLI_ERROR = 'CLI_ERROR' // CLI 执行错误 } ``` ### 错误处理示例 ```javascript try { const result = await codebuddy.execute({ task: '创建文件' }); } catch (error) { if (error.type === 'CLI_NOT_FOUND') { console.error('请先安装 CodeBuddy CLI'); } else if (error.type === 'TIMEOUT') { console.error('任务超时,请增加超时时间'); } else { console.error('执行失败:', error.message); } } ``` --- ## 📦 集成到 Agent ### Developer Agent 集成 ```javascript // developer/agent.js const codebuddy = require('codebuddy-coding'); class DeveloperAgent { async implementFeature(task) { // 使用 CodeBuddy 实现功能 const result = await codebuddy.execute({ task: task.description, context: { projectPath: this.projectPath, files: task.relatedFiles } }); return result; } } ``` ### Architect Agent 集成 ```javascript // architect/agent.js const codebuddy = require('codebuddy-coding'); class ArchitectAgent { async generateProjectScaffold(requirements) { // 使用 CodeBuddy 生成脚手架 const result = await codebuddy.execute({ task: `创建项目脚手架:${requirements}`, options: { permissionMode: 'bypassPermissions' } }); return result; } } ``` --- ## 🧪 测试 ### 运行测试 ```bash # 运行所有测试 npm test # 运行特定测试 npm test -- --grep "CLI Wrapper" ``` ### 测试覆盖 - ✅ CLI Wrapper 单元测试 - ✅ Progress Monitor 单元测试 - ✅ Integration 集成测试 - ✅ E2E 端到端测试 --- ## 📄 许可证 MIT License --- ## 🤝 贡献 欢迎提交 Issue 和 Pull Request! --- ## 📞 支持 如有问题,请联系: - GitHub Issues: [OpenClaw Repository] - Email: support@openclaw.ai --- **让每个 Agent 都拥有 AI 编程能力!** 🚀

Archived SourceRecently Updated
Coding

anti-sycophancy

Three-layer sycophancy defense based on ArXiv 2602.23971. Use /anti-sycophancy install to deploy all layers, or manage individually via install-claude-code / install-openclaw / uninstall / status / verify. Layer 1: CC-only hook; Layer 2: SKILL (cross-platform); Layer 3: CLAUDE.md (CC) / SOUL.md (OC).

Archived SourceRecently Updated
Coding

validation-rule-management

管理校验规则、规则组和校验场景的全流程操作。支持通过统一 CLI 工具快速执行 API 调用,自动处理参数解析、配置加载和错误提示。使用当用户需要进行校验规则管理、规则组维护、校验场景配置、启停操作或相关查询时,即使用户只说"帮我创建一条规则"或"查一下场景列表"也应触发。

Archived SourceRecently Updated