File size: 3,127 Bytes
2e7f744
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""For every scored trial: tool-use counts, mentions of sensitive paths outside /app (where answers or other runs
could live), and how much code the trial wrote or ran (Bash commands that invoke python, plus Write/Edit
contents other than prediction.json). Writes results/v3/audit/paths_and_code.json."""
import json, re, collections, sys
R = '/scratch/gpfs/TRIDAO/ly3223/oraclebench/'
SENS = re.compile(r'(?<![\w.])/(tests|solution|staging|scratch|logs/verifier|root|home|proc|opt|etc|var|usr|srv|mnt)\b')
PY = re.compile(r'(?<![\w/])python3?\b')
TAG = sys.argv[1] if len(sys.argv) > 1 else 'opus55-high'
trials = [l.strip() for l in open(R + f'results/v3/{TAG}.trials.txt') if l.strip()]
tools = collections.Counter(); sens = collections.Counter(); sens_ex = collections.defaultdict(list)
rows = []; nolog = []
for d in trials:
    n = py_calls = code = 0
    try:
        fh = open(d + '/agent/claude-code.txt')
    except FileNotFoundError:
        nolog.append(d); continue
    for line in fh:
        try:
            e = json.loads(line)
        except Exception:
            continue
        if e.get('type') != 'assistant':
            continue
        for b in e['message']['content']:
            if b.get('type') != 'tool_use':
                continue
            n += 1; tools[b['name']] += 1
            inp = b.get('input') or {}
            s = json.dumps(inp)
            for m in SENS.finditer(s):
                sens[m.group(1)] += 1
                if len(sens_ex[m.group(1)]) < 4:
                    sens_ex[m.group(1)].append((d.rsplit('/', 1)[-1], s[:240]))
            if b['name'] == 'Bash' and PY.search(inp.get('command', '')):
                py_calls += 1; code += len(inp.get('command', ''))
            if b['name'] in ('Write', 'Edit') and not str(inp.get('file_path', '')).endswith('prediction.json'):
                code += len(str(inp.get('content', ''))) + len(str(inp.get('new_string', '')))
    rows.append({'trial': d, 'tool_calls': n, 'python_calls': py_calls, 'code_chars': code})
def q(v, p):
    v = sorted(v); return v[min(len(v) - 1, int(p * len(v)))]
print('trials', len(rows), '| without an agent log (unauditable):', len(nolog), [x.rsplit('/', 1)[-1] for x in nolog])
print('tool use by type', dict(tools))
print('sensitive path mentions', dict(sens))
for k, v in sens_ex.items():
    for t, s in v:
        print('  ', k, '|', t, '|', s)
pc = [r['python_calls'] for r in rows]; cc = [r['code_chars'] for r in rows]; nc = [r['tool_calls'] for r in rows]
print('trials running python at all:', sum(x > 0 for x in pc))
print('python calls per trial  median/p90/max:', q(pc, .5), q(pc, .9), max(pc))
print('code chars per trial    median/p90/max:', q(cc, .5), q(cc, .9), max(cc))
print('tool calls per trial    median/p90/max:', q(nc, .5), q(nc, .9), max(nc))
top = sorted(rows, key=lambda r: -r['code_chars'])[:5]
for r in top:
    print('  most code:', r['trial'].rsplit('/', 1)[-1], r['code_chars'], 'chars,', r['python_calls'], 'python calls')
json.dump({'rows': rows, 'sensitive': dict(sens), 'no_log': nolog}, open(R + f'results/v3/audit/paths_and_code.{TAG}.json', 'w'))