跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
浏览器与自动化

gza-log-insights

Analyze gza run logs to find recurring anti-patterns, wasted effort, and suggest AGENTS.md or workflow improvements

mhawthorne · 已有 AI 审核记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add mhawthorne/gza --skill gza-log-insights

技能说明


name: gza-log-insights description: Analyze gza run logs to find recurring anti-patterns, wasted effort, and suggest AGENTS.md or workflow improvements allowed-tools: Read, Bash(uv run python -c:), Bash(wc:), Bash(ls:), Bash(head:), Bash(tail:*) version: 1.0.0 public: false

Gza Log Insights

Analyze gza execution logs to find recurring anti-patterns, wasted compute, and actionable improvements. This skill scans task transcript logs (*.log) and paired ops logs (*.ops.jsonl), aggregates patterns across many runs, and produces recommendations for AGENTS.md updates, prompt improvements, or workflow changes.

Process

Step 1: Locate and inventory logs

Find the log directory and count available logs:

uv run python -c "
from gza.config import load_config
cfg = load_config()
log_dir = cfg.get_log_dir()
print(str(log_dir))
"

Then list and count:

ls <log_dir> | wc -l

If no logs exist, report that and stop.

Step 2: Run the analysis script

Run the following comprehensive analysis across all log files. This script extracts patterns from the JSONL log format (where each line is a JSON entry with types: system, assistant, user, result).

uv run python -c "
import json, os, re, sys
from collections import Counter, defaultdict
from pathlib import Path

from gza.config import load_config
cfg = load_config()
log_dir = cfg.get_log_dir()

log_files = sorted(log_dir.glob('*.log'))
ops_log_files = sorted(log_dir.glob('*.ops.jsonl'))
if not log_files:
    print('No log files found.')
    sys.exit(0)

# --- Counters ---
bare_commands = Counter()          # commands missing 'uv run'
failed_bash = Counter()            # bash commands that failed
git_errors = Counter()             # git-specific errors
tool_distribution = Counter()      # overall tool usage
skill_errors = Counter()           # failed skill executions
import_errors = Counter()          # Python import errors
file_too_large = 0                 # Read tool file-too-large errors
no_module_pytest = 0               # 'No module named pytest'
sqlite_not_found = 0               # sqlite3 not available
worktree_git_errors = 0            # git fails in cleaned-up worktrees
test_runs_per_log = []             # (filename, count) for test-heavy logs
result_subtypes = Counter()        # success vs error_max_turns etc
costs = []                         # per-log costs
high_cost_logs = []                # logs with cost info
repeated_patterns = Counter()      # any command run 5+ times in a single log

BARE_PREFIXES = ['gza ', 'pytest', 'mypy ', 'python ']

for logfile in log_files:
    tool_uses_in_log = {}   # tool_use_id -> command
    test_runs = 0
    bash_cmds_in_log = Counter()
    fname = logfile.name

    with open(logfile) as f:
        for line in f:
            line = line.strip()
            if not line:
                continue
            try:
                entry = json.loads(line)
            except (json.JSONDecodeError, ValueError):
                continue

            etype = entry.get('type', '')

            # --- System init: skip ---

            # --- Assistant messages: extract tool calls ---
            if etype == 'assistant':
                msg = entry.get('message', {})
                for c in msg.get('content', []):
                    if c.get('type') == 'tool_use':
                        tool = c.get('name', '')
                        inp = c.get('input', {})
                        tid = c.get('id', '')
                        tool_distribution[tool] += 1

                        if tool == 'Bash':
                            cmd = inp.get('command', '').strip()
                            tool_uses_in_log[tid] = cmd
                            bash_cmds_in_log[cmd[:80]] += 1

                            # Check bare commands
                            for prefix in BARE_PREFIXES:
                                if cmd.startswith(prefix) and not cmd.startswith('uv run'):
                                    bare_commands[cmd[:100]] += 1

                            # Count test/lint runs
                            if 'pytest' in cmd or 'mypy' in cmd:
                                test_runs += 1

            # --- User messages: extract tool results ---
            if etype == 'user':
                msg = entry.get('message', {})
                for c in msg.get('content', []):
                    if c.get('type') != 'tool_result':
                        continue
                    tid = c.get('tool_use_id', '')
                    is_err = c.get('is_error', False)
                    content = str(c.get('content', ''))

                    # Skill errors — 'Execute skill: X' with is_error=True is NORMAL
                    # in headless mode (skill loaded successfully). Only count as
                    # error if the content indicates a real failure (e.g. 'Unknown skill').
                    if is_err and 'skill' in content.lower():
                        if 'Execute skill' in content:
                            pass  # Normal headless behavior, not an error
                        elif 'Unknown skill' in content:
                            skill_name = content.split('Unknown skill:')[-1].strip()[:40] if 'Unknown skill:' in content else content[:60]
                            skill_errors[skill_name] += 1
                        else:
                            skill_errors[content[:60]] += 1

                    # File too large
                    if 'exceeds maximum allowed' in content:
                        file_too_large += 1

                    # Specific error categories
                    if 'not a git repository' in content:
                        worktree_git_errors += 1
                    if 'sqlite3: command not found' in content:
                        sqlite_not_found += 1
                    if 'No module named pytest' in content:
                        no_module_pytest += 1
                    if 'ImportError' in content:
阅读完整来源 ↗