prophet-v3 / code /audit /paths_and_code.py
drkylj's picture
Add predictor results (Opus/Sonnet/Haiku 5.5, effort high): forecasts, scores, audits, analyses; launch and audit code
2e7f744 verified
Raw History Blame Contribute Delete
3.13 kB
"""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'))