用途
该技能实现一个自我改进闭环:增强遥测 → 模式分析 → 技能更新 → 性能提升。它用于分析增强遥测模式并自动改进技能,把可观测性洞察转化为具体的技能更新。
数据来源
主要数据源为 Loki 中的 {job="claude_code_enhanced"},来自 enhanced-telemetry 钩子。
工作流程
1. 收集可观测性洞察
使用 observability-analyzer 配合增强遥测,可查询:
- 会话分析:{job="claude_code_enhanced", event_type="session_end"} | json
- 错误模式:{job="claude_code_enhanced", event_type="tool_result", status="error"} | json
- 工具序列:{job="claude_code_enhanced", event_type="tool_call"} | json
- 提示词模式:{job="claude_code_enhanced", event_type="user_prompt"} | json
2. 运行模式检测
使用 observability-pattern-detector 的操作:
- detect-failures → 按工具分类的错误模式
- detect-tool-sequences → 低效工具链
- detect-conversation-patterns → 用户行为洞察
- detect-context-issues → 上下文管理问题
- detect-waste → 冗余操作
3. 提取可操作模式
从增强遥测中筛选高影响问题。
错误分析示例:
sum by (tool, error_type) (count_over_time({job="claude_code_enhanced", event_type="tool_result", status="error"} | json [7d]))
工具低效示例(重复 Read→Read 模式):
{job="claude_code_enhanced", event_type="tool_call"} | json | previous_tool="Read" and tool_name="Read"
上下文问题示例(自动压缩频率):
count_over_time({job="claude_code_enhanced", event_type="context_compact", trigger="auto"} [7d])
4. 将模式映射到技能
资料给出的映射关系:
- Bash 命令错误 → bash 相关技能 → 添加存在性检查
- 文件未找到 → 文件操作技能 → 添加路径校验
- 重复 Glob→Read → 搜索技能 → 优化文件发现
- 高上下文占用 → 上下文密集型技能 → 添加分块
- 大量调试提示 → 核心技能 → 改进错误消息
5. 生成改进建议
基于增强遥测模式生成结构化建议,示例:
{
"improvement": {
"pattern": "File not found errors",
"occurrences": 45,
"source_query": "{job=\"claude_code_enhanced\", event_type=\"tool_result\", status=\"error\"} | json | error_type=~\".*not found.*\"",
"affected_skills": ["file-operations"],
"recommendation": "Add file existence check before Read/Edit operations",
"implementation": "Add pathlib.Path(file).exists() check",
"priority": "high",
"expected_impact": "Reduce errors by 80%"
}
}
6. 跟踪有效性
改进部署后测量:
# Before vs After error rates
sum(count_over_time({job="claude_code_enhanced", event_type="tool_result", status="error"} | json [7d]))
# Tool success rate improvement
sum(count_over_time({job="claude_code_enhanced", event_type="tool_result", status="success"} | json [7d])) /
sum(count_over_time({job="claude_code_enhanced", event_type="tool_result"} | json [7d]))
改进流程示例
流程 1:错误减少
遥测:tool_result 错误中 "npm not found" 出现 45 次 → 模式:Bash 工具执行 npm 命令失败 → 建议:添加 npm 可用性检查 → skill-updater 应用更改 → 遥测跟踪:部署后 npm 错误 = 0 → 结果:减少 100%。
流程 2:上下文优化
遥测:7 天内触发自动压缩 12 次 → 模式:大文件读取累积 token → 建议:为大文件读取添加分块 → skill-updater 应用更改 → 遥测跟踪:部署后自动压缩 = 2 次 → 结果:减少 83%。
流程 3:工具序列优化
遥测:Glob→Read→Glob→Read 模式出现 89 次 → 模式:冗余文件发现 → 建议:在会话内缓存 glob 结果 → skill-updater 应用更改 → 遥测跟踪:冗余 glob 减少 70% → 结果:文件操作更快。
改进分析关键查询
高影响错误:
topk(10, sum by (tool, error_type) (count_over_time({job="claude_code_enhanced", event_type="tool_result", status="error"} | json [7d])))
会话质量问题:
# High error sessions
{job="claude_code_enhanced", event_type="session_end"} | json | error_count > 5
# Low productivity sessions (high turns, few tool calls)
{job="claude_code_enhanced", event_type="session_end"} | json | turn_count > 20 and tools_used < 5
工具效率:
# Tool usage distribution
sum by (tool) (count_over_time({job="claude_code_enhanced", event_type="tool_call"} | json [7d]))
# Error rate by tool
sum by (tool) (count_over_time({job="claude_code_enhanced", event_type="tool_result", status="error"} | json [7d])) /
sum by (tool) (count_over_time({job="claude_code_enhanced", event_type="tool_result"} | json [7d]))
用户行为洞察:
# Prompt pattern trends
sum by (pattern) (count_over_time({job="claude_code_enhanced", event_type="user_prompt"} | json [7d]))
# Debugging frequency (indicates pain points)
count_over_time({job="claude_code_enhanced", event_type="user_prompt", pattern="debugging"} [7d])
与生态系统的集成
使用现有技能:
- observability-analyzer:查询增强遥测数据
- observability-pattern-detector:检测改进模式
- skill-updater:应用安全改进
- review-multi:验证更改
- skill-tester:回归测试
- enhanced-telemetry:所有可观测性数据的来源
安全分类
可自动应用的安全项:
- 添加存在性检查
- 添加错误处理
- 改进错误消息
- 更新文档
- 添加校验
需要审查的项:
- 更改核心逻辑
- 修改 API
- 移除功能
- 更改数据结构
有效性指标
跟踪改进成功情况:
# Calculate error reduction percentage
(before_errors - after_errors) / before_errors * 100
# Track pattern elimination
count_over_time({job="claude_code_enhanced"} | json | <pattern_filter> [7d])
报告格式:
{
"improvement_id": "file-existence-check",
"deployed": "2025-11-27",
"before_errors": 45,
"after_errors": 2,
"reduction_percent": 95.6,
"status": "successful"
}
适用场景与限制
适用场景:需要基于增强遥测数据持续分析并改进技能、降低错误率、优化上下文使用和工具调用效率的场合。
限制:资料未提供该技能的安装命令、收费方式、支持平台等具体信息,暂未提供。