Files
WoW-Hybrid-gateway/ops/octo_guild_bank_capture.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

72 lines
4.3 KiB
Python

#!/usr/bin/env python3
"""Read only our bank observer's SavedVariables table, never execute client Lua.
Payloads remain private local evidence. Public summaries contain message verbs
and counts, not guild logs, member names, bank contents or account identifiers.
"""
import argparse,collections,hashlib,json,os,re
from pathlib import Path
from console_report import parse
ROOT=Path(__file__).resolve().parents[1]
FIELD=re.compile(r'^\s*\["WoWHybridGuildBankCapture"\]\s*=\s*\{',re.M)
LEX=re.compile(r'"(?:\\.|[^"\\])*"|--[^\n]*|[{}]|[^"{}-]+|-(?!--)',re.S)
def extract(raw):
if not isinstance(raw,str)or len(raw)>32*1024*1024:raise ValueError('Bounded official-client saved data required')
matches=list(FIELD.finditer(raw))
if len(matches)!=1:raise ValueError('Exactly one saved bank observer table required; reload must save it first')
start=matches[0].end()-1;position=start;depth=0;parts=[]
while position<len(raw):
token=LEX.match(raw,position)
if not token:raise ValueError('Unsupported saved-data syntax')
value=token.group();position=token.end()
if value.startswith('--'):continue
parts.append(value)
if value=='{':depth+=1
elif value=='}':
depth-=1
if depth==0:break
if position-start>1900000:raise ValueError('Saved capture exceeds reviewed parser size')
else:raise ValueError('Truncated bank capture')
capture=parse('GatewayDiagnosticsSaved = '+''.join(parts),max_tokens=500000)
rows=capture.get('rows')
if rows=={}:rows=[];capture['rows']=rows
if capture.get('schema')!=1 or not isinstance(rows,list)or len(rows)>8192:raise ValueError('Unknown bank observer schema')
for row in rows:
if (not isinstance(row,dict)or row.get('direction')not in('incoming-event','outgoing-api','outgoing-chat-api','marker')
or not isinstance(row.get('prefix'),str)or len(row['prefix'])>64 or 'bank'not in row['prefix'].lower()
or not isinstance(row.get('payload'),str)or len(row['payload'])>8192):raise ValueError('Invalid bank-only capture row')
if type(capture.get('dropped'))is not int or capture['dropped']<0:raise ValueError('Missing capture loss count')
return capture
def summarize(capture):
counts=collections.Counter()
for row in capture['rows']:
if row['direction']=='marker':continue
verb=re.match(r'[A-Za-z][A-Za-z0-9_]{0,63}(?=[:\t ]|$)',row['payload'])
counts[(row['direction'],row['prefix'],verb.group()if verb else '<unclassified>')]+=1
return dict(kind='official-octo-bank-addon-observation',rows=len(capture['rows']),dropped=capture['dropped'],
messages=[dict(direction=d,prefix=p,verb=v,count=n)for(d,p,v),n in sorted(counts.items())],
raw_wire_capture=False,server_acceptance_verified=False,local_tortoise_parity_verified=False,
limits=['Outgoing API calls show attempted sends; incoming events contain the observed server/addon data.',
'Transactions require matched responses/state and local replay tests; counts alone are not acceptance.',
'Raw bank data is private; public summary omits member names, item contents and transaction amounts.'])
def main():
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--input',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args()
official=Path.home()/'Games/octo/drive_c/Octowow/WTF'
path=a.input.resolve();output=a.output.resolve()
if a.input.is_symlink()or not path.is_relative_to(official)or path.name!='pfUI.lua':p.error('Explicit official-client pfUI saved data required')
if not output.is_relative_to(ROOT/'runtime')or output.exists():p.error('Fresh private runtime output required')
if path.stat().st_size>32*1024*1024:p.error('Saved data size bound')
raw=path.read_text();capture=extract(raw);summary=summarize(capture)
summary['source_sha256']=hashlib.sha256(raw.encode()).hexdigest()
output.mkdir(parents=True,mode=0o700)
for name,data in [('capture.json',capture),('summary.json',summary)]:
fd=os.open(output/name,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
with os.fdopen(fd,'w')as stream:json.dump(data,stream,indent=2);stream.write('\n')
print('Saved bank observation:',summary['rows'],'rows;',summary['dropped'],'dropped. No wire/transaction acceptance claim.')
if __name__=='__main__':main()