一键导入
optimization-workflow
Full code optimization workflow - from analyzing code to running optimization and reviewing results
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Full code optimization workflow - from analyzing code to running optimization and reviewing results
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Inspect and analyze codebases using pygount for LOC counting, language breakdown, and code-vs-comment ratios. Use when asked to check lines of code, repo size, language composition, or codebase stats.
Set up GitHub authentication for the agent using git (universally available) or the gh CLI. Covers HTTPS tokens, SSH keys, credential helpers, and gh auth — with a detection flow to pick the right method automatically.
Production-grade PR review with execution-verified suggestions. Reads repository conventions, history, and security surfaces before reviewing. For every suggested fix, attempts to compile and test it in the sandbox — the comment includes proof. Modelled on GitHub Copilot's agentic architecture with one critical advantage: the sandbox is already running.
Create, manage, triage, and close GitHub issues. Search existing issues, add labels, assign people, and link to PRs. Works with gh CLI or falls back to git + GitHub REST API via curl.
Open and manage GitHub pull requests through Kai MCP tools — propose changes, monitor CI, iterate on failures, and merge. No git tokens are shared to the sandbox; every GitHub operation goes through the backend via the workspace's GitHub App installation.
Clone, create, fork, configure, and manage GitHub repositories. Manage remotes, secrets, releases, and workflows. Works with gh CLI or falls back to git + GitHub REST API via curl.
| name | optimization-workflow |
| description | Full code optimization workflow - from analyzing code to running optimization and reviewing results |
| version | 2.0.0 |
| author | kai-agent |
| metadata | {"kai":{"tags":["kai","optimization","code-quality","performance"]}} |
End-to-end workflow for running AI-powered code optimization through Kai.
Ask the user or infer from context:
browse_repository_files(workspaceId, repoId) → understand structure
read_repository_files(workspaceId, repoId, paths) → read target code
Identify optimization candidates:
Before starting, verify no optimization is already running on the same file:
list_code_optimizations(workspaceId, repoId)
If there's an active run on the same scope, do NOT start another one. Instead:
get_code_optimization_progressabort_code_optimization — the evaluator is brokenCreate a lifecycle action and wait for the user to approve before proceeding:
lifecycle_actions_create(workspaceId, type="evolution", title="Optimize [target]", description="...", priority="high", repoId=repoId)
Wait for the user to execute the action (status changes to in_progress).
Write a Python evaluator yourself — never use create_ai_evaluator. You understand the code and the goal better than an auto-generator.
Self-test before uploading (critical — do not skip):
# Save evaluator to temp file and run it against the target
# In terminal:
python3 -c "
from evaluator import evaluate
result = evaluate('/path/to/target_program.py')
print(result)
assert isinstance(result, dict), 'Must return dict'
assert 'combined_score' in result, 'Must have combined_score'
assert result['combined_score'] > 0, 'Score must be > 0 for the initial program'
print('PASS')
"
If the self-test fails, fix the evaluator before uploading. A broken evaluator wastes hundreds of LLM calls.
The evaluator must define evaluate(program_path) — it receives a file path string, not a module. Must return a dict like {"correctness": 1.0, "performance": score}. Load the evaluator-creation skill for detailed patterns and examples.
create_evaluator_from_code(workspaceId, repoId, code=evaluator_code, name="My Evaluator")
→ returns { evaluatorId }
If the evaluator needs GPU: the default path is Modal via the workspace proxy (zero user setup when MODAL_SERVER_URL is set). Load the kai-evolve/evaluator-creation skill and follow Option A in the GPU Evaluator Pattern. Only fall back to user-hosted GPU infrastructure (Option C) or CPU approximation (Option D) when Modal isn't connected and can't be.
config = {
"llm": {
"models": [{"name": "openai/gpt-4o", "weight": 1.0}],
},
"prompt": {
"systemMessage": "Optimize <target> for <metric>. Keep public API unchanged.",
},
}
scopes = [
{"path": "src/foo.py", "fromLine": 42, "toLine": 87},
]
start_code_optimization(workspaceId, repoId, config, scopes, evaluatorId)
# → returns optimizationId
Field-name pitfalls (use these, not the alternatives on the right):
scopes[].path / fromLine / toLine — not filePath / startLine / endLineconfig.llm.models (array of {name, weight}) — not config.llm.model (string)config.prompt.systemMessage — not config.prompt.goalOptimizations take time (minutes to hours depending on complexity). Set up a cron job to poll progress every 10-15 minutes:
get_code_optimization_progress(optimizationId) → overall status
get_optimization_iterations(optimizationId) → iteration history with fitness scores
Report to team at milestones:
get_optimized_programs(optimizationId) → best solutions found
For each solution:
Use research tools to:
Present to the team: