Initial project source
这个提交包含在:
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read one DataGov session; print timings only, never conversation content."""
|
||||
import argparse
|
||||
import json
|
||||
import math
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
|
||||
def summarize(path, root):
|
||||
project = None
|
||||
completed = {}
|
||||
invalid = 0
|
||||
for line in path.open(encoding='utf-8'):
|
||||
try:
|
||||
row = json.loads(line)
|
||||
data = row.get('payload', {})
|
||||
if not isinstance(data, dict):
|
||||
raise ValueError()
|
||||
if row.get('type') == 'session_meta':
|
||||
project = data.get('cwd')
|
||||
if row.get('type') == 'event_msg' and data.get('type') == 'task_complete':
|
||||
key = data.get('turn_id')
|
||||
ms = data.get('duration_ms')
|
||||
if not isinstance(key, str) or not key or type(ms) not in (int, float) or not math.isfinite(ms) or ms < 0:
|
||||
raise ValueError()
|
||||
completed[key] = {'ended_at': row.get('timestamp'), 'duration_seconds': round(ms / 1000, 3)}
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
invalid += 1
|
||||
if project != str(root):
|
||||
raise ValueError('not a session for this project')
|
||||
if invalid:
|
||||
raise ValueError('malformed session records; no partial result emitted')
|
||||
seconds = sum(item['duration_seconds'] for item in completed.values())
|
||||
return {'completed_turns': len(completed), 'completed_turn_minutes': round(seconds / 60, 3),
|
||||
'turns': list(completed.values()),
|
||||
'limitations': 'Includes tools and waits within completed turns. Excludes unfinished turns and between-turn idle time. Not pure model time or delivery elapsed time; parallel sessions must not be added as elapsed time.'}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('session', type=pathlib.Path, help='one local Codex rollout JSONL file')
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
result = summarize(args.session, pathlib.Path(__file__).resolve().parents[2])
|
||||
except (OSError, ValueError, UnicodeError):
|
||||
print('Timing unavailable: unreadable, malformed, or other-project session.', file=sys.stderr)
|
||||
return 1
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2, allow_nan=False))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
在新工单中引用
屏蔽一个用户