Files
kwcode/kaiwu/builtin_experts/bugfix/scripts/extract_traceback.py
Val-sss 0aeb91b766 feat: upgrade expert system to SKILL.md progressive disclosure format
- Add SKILL.md directory format (YAML frontmatter + Markdown instructions + scripts/)
- 3 pilot experts converted: bugfix/, fastapi/, testgen/ (with scripts)
- expert_loader.py: load_skill_dir() + load_directory() supports both formats
- expert_registry.py: get_instructions() (Level 2) + get_scripts() (Level 3)
- gate.py: uses instructions field for SKILL.md experts
- prompt_optimizer.py: _update_skill_md() appends rules to markdown body
- SKILL.md takes priority over same-name YAML (backward compat preserved)
- 19 new tests (311 total, all passing)

Progressive disclosure architecture:
  Level 1 (Gate): name + keywords only (~100 tokens per expert)
  Level 2 (Generator): full instructions loaded only for matched expert
  Level 3 (on-demand): scripts executed deterministically, never enter LLM context

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-29 19:15:19 +08:00

55 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""从pytest输出中提取关键失败信息。
确定性脚本不进LLM context直接执行返回结构化结果。
"""
import re
import sys
def extract_traceback(pytest_output: str) -> dict:
"""
从pytest输出中提取
- 失败的测试名
- 异常类型和消息
- 出错的文件和行号
返回结构化dict。
"""
result = {
"failed_tests": [],
"exceptions": [],
"error_locations": [],
}
# 提取失败的测试名
failed_pattern = r"FAILED\s+([\w/.:]+)"
for m in re.finditer(failed_pattern, pytest_output):
result["failed_tests"].append(m.group(1))
# 提取异常类型和消息
exc_pattern = r"([\w.]+Error|[\w.]+Exception):\s*(.+)"
for m in re.finditer(exc_pattern, pytest_output):
result["exceptions"].append({
"type": m.group(1),
"message": m.group(2).strip()[:200],
})
# 提取文件:行号
loc_pattern = r'File "([^"]+)", line (\d+)'
for m in re.finditer(loc_pattern, pytest_output):
filepath = m.group(1)
# 跳过标准库和site-packages
if "site-packages" in filepath or "lib/python" in filepath:
continue
result["error_locations"].append({
"file": filepath,
"line": int(m.group(2)),
})
return result
if __name__ == "__main__":
import json
text = sys.stdin.read()
print(json.dumps(extract_traceback(text), ensure_ascii=False, indent=2))