This repository has been archived on 2026-08-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
openclaw/agents/haonan/workspace/dev-workflow/dev_workflow.py
T
starmen1265 3efe98e17d feat: 添加 Cross 模式统计报告功能
- 添加 stats.py 统计模块
- 添加 dev_workflow.py CLI 工具
- 实现 record_event() 记录事件
- 实现 get_stats() 生成报告
- 支持敏感数据自动过滤
- 使用原子写入保证数据安全
- 添加 README 文档
2026-03-09 14:44:04 +08:00

137 lines
3.3 KiB
Python
Raw 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.
#!/usr/bin/env python3
"""
Dev Workflow - 开发工作流工具
提供多种工作模式和统计功能
"""
import sys
import argparse
from pathlib import Path
# 添加当前目录到路径
sys.path.insert(0, str(Path(__file__).parent))
from stats import record_event, get_stats, format_stats_report, clear_stats
def cmd_stats(args):
"""stats 命令处理函数"""
# 记录查看统计的事件
record_event(
"stats_viewed",
mode="cross",
metadata={"filter_mode": args.mode}
)
# 获取统计数据
stats = get_stats(mode=args.mode)
# 输出报告
report = format_stats_report(stats)
print(report)
return 0
def cmd_record(args):
"""record 命令处理函数 - 用于测试"""
success = record_event(
args.event_type,
mode=args.mode,
metadata={"description": args.description} if args.description else None
)
if success:
print(f"✓ 事件已记录: {args.event_type}")
return 0
else:
print("✗ 记录事件失败")
return 1
def cmd_clear(args):
"""clear 命令处理函数"""
if not args.confirm:
print("警告: 此操作将清空所有统计数据!")
print("使用 --confirm 参数确认清空")
return 1
success = clear_stats(confirm=True)
if success:
print("✓ 统计数据已清空")
return 0
else:
print("✗ 清空失败")
return 1
def main():
"""主函数"""
parser = argparse.ArgumentParser(
description="Dev Workflow - 开发工作流工具",
formatter_class=argparse.RawDescriptionHelpFormatter
)
subparsers = parser.add_subparsers(dest="command", help="可用命令")
# stats 命令
stats_parser = subparsers.add_parser("stats", help="显示统计报告")
stats_parser.add_argument(
"--mode", "-m",
help="筛选特定模式(如 cross, normal)"
)
stats_parser.set_defaults(func=cmd_stats)
# record 命令(用于测试)
record_parser = subparsers.add_parser("record", help="记录事件(测试用)")
record_parser.add_argument(
"event_type",
help="事件类型"
)
record_parser.add_argument(
"--mode", "-m",
default="cross",
help="工作模式(默认: cross)"
)
record_parser.add_argument(
"--description", "-d",
help="事件描述"
)
record_parser.set_defaults(func=cmd_record)
# clear 命令
clear_parser = subparsers.add_parser("clear", help="清空统计数据")
clear_parser.add_argument(
"--confirm",
action="store_true",
help="确认清空"
)
clear_parser.set_defaults(func=cmd_clear)
# 解析参数
args = parser.parse_args()
# 如果没有指定命令,默认显示 stats
if not args.command:
args.command = "stats"
args.func = cmd_stats
args.mode = None
# 执行命令
try:
return args.func(args)
except AttributeError:
parser.print_help()
return 1
except KeyboardInterrupt:
print("\n操作已取消")
return 130
except Exception as e:
print(f"错误: {e}", file=sys.stderr)
return 1
if __name__ == "__main__":
sys.exit(main())