Files
WoW-Hybrid-gateway/ops/octo_travel_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

138 lines
9.3 KiB
Python

#!/usr/bin/env python3
"""Nonexecuting bounded extraction of our travel table, never full pfUI history."""
import collections
import hashlib
import math
import re
from console_report import parse
from octo_social_capture import LEX
FIELD=re.compile(r'^[ \t]*(?:\["WoWHybridTravelCapture"\]|WoWHybridTravelCapture)[ \t]*=[ \t]*\{',re.M)
MAX_SOURCE=64*1024*1024
MAX_TABLE=1_990_000 # Existing shared data parser hard ceiling is 2,000,000 chars.
EVENTS=set('PLAYER_ENTERING_WORLD ZONE_CHANGED_NEW_AREA ZONE_CHANGED ZONE_CHANGED_INDOORS PLAYER_CONTROL_LOST PLAYER_CONTROL_GAINED PLAYER_TARGET_CHANGED UPDATE_MOUSEOVER_UNIT TAXIMAP_OPENED TAXIMAP_CLOSED PLAYER_AURAS_CHANGED UNIT_FLAGS PLAYER_LOGOUT SPELLCAST_START SPELLCAST_STOP SPELLCAST_FAILED SPELLCAST_INTERRUPTED SPELLCAST_DELAYED SPELLCAST_CHANNEL_START SPELLCAST_CHANNEL_STOP SPELLCAST_CHANNEL_UPDATE'.split())
APIS=set('UnitGUID IsMounted UnitOnTaxi GetPlayerMapPosition GetCurrentMapAreaID GetUnitSpeed GetPlayerBuff GetPlayerBuffTexture GetPlayerBuffTimeLeft GetPlayerBuffApplications'.split())
FIELDS={
'observer-ready':set('revision load cacheBound'.split()),
'travel':set('reason cacheBound zone subzone realZone mapContinent mapZone mapAreaID mapX mapY coordinateScope onTaxi mounted speed'.split()),
'event':{'event'},
'unit':set('unit name guid level creatureType isPlayer modelIDStatus'.split()),
'taxi-map':{'nodeCount','limit'},
'taxi-node':set('index name nodeType x y'.split()),
'stopped':set(),
'spellcast':{'event','argument1','argument2'},
'aura-snapshot':set('reason filter snapshot count'.split()),
'aura':set('slot buffIndex texture stacks timeLeft untilCancelled filter snapshot'.split()),
}
BASE={'kind','nonce','time'}
NONCE=re.compile(r'octo-travel-v[123]:[0-9.eE+-]+:[0-9.eE+-]+:[1-9][0-9]*')
def _counter(v,maximum=2**53):
return type(v)is int and 0<=v<=maximum
def validate(capture):
if not isinstance(capture,dict)or set(capture)-set('schema rows bytes dropped loads eventCounts capabilities latestNonce unsupportedEvents coalesced capturePolicy latestReady latestTravel auraIndexOrigin'.split()):raise ValueError('Unknown travel table fields')
if type(capture.get('schema'))is not int or capture['schema']!=1:raise ValueError('Unknown travel schema')
rows=capture.get('rows')
if rows=={}:rows=[];capture['rows']=rows
if not isinstance(rows,list)or len(rows)>4096:raise ValueError('Travel row bound')
for key,limit in [('bytes',2097152),('dropped',2**53),('loads',2**53)]:
if not _counter(capture.get(key),limit):raise ValueError('Travel counter bound')
nonce=capture.get('latestNonce')
if not isinstance(nonce,str)or len(nonce)>128 or not NONCE.fullmatch(nonce):raise ValueError('Travel latest nonce required')
for key,allowed in [('eventCounts',EVENTS),('capabilities',APIS),('unsupportedEvents',EVENTS)]:
values=capture.get(key,{})
if not isinstance(values,dict)or set(values)-allowed:raise ValueError('Unknown travel metadata keys')
if key=='eventCounts':
if any(not _counter(v)for v in values.values()):raise ValueError('Travel event counter bound')
elif any(type(v)is not bool for v in values.values()):raise ValueError('Travel capability/event Boolean required')
if 'capturePolicy'in capture and capture['capturePolicy']!='v3-prioritized-travel-bounded-latest':raise ValueError('Unknown capture policy')
if 'auraIndexOrigin'in capture and capture['auraIndexOrigin']not in('global-vanilla-negative-one','global-tbc-zero','pfUI.env-vanilla-negative-one','pfUI.env-tbc-zero','unresolved-or-inconsistent-index-origin'):raise ValueError('Unknown aura index origin')
coalesced=capture.get('coalesced',{})
if not isinstance(coalesced,dict)or set(coalesced)-{'travel','unit','eventRows'}or any(not _counter(v)for v in coalesced.values()):raise ValueError('Coalesced counter bound')
extra=[]
for key,kind in [('latestReady','observer-ready'),('latestTravel','travel')]:
if key in capture:
row=capture[key]
if not isinstance(row,dict)or row.get('kind')!=kind:raise ValueError('Bounded latest-record kind required')
extra.append(row)
for row in rows+extra:
if not isinstance(row,dict)or row.get('kind')not in FIELDS:raise ValueError('Unknown travel row kind')
kind=row['kind']
if set(row)-(FIELDS[kind]|BASE):raise ValueError('Unknown travel row fields')
if not isinstance(row.get('nonce'),str)or len(row['nonce'])>128 or not NONCE.fullmatch(row['nonce']):raise ValueError('Travel row nonce required')
if type(row.get('time'))not in(int,float)or not math.isfinite(row['time'])or row['time']<0:raise ValueError('Travel observation time required')
for v in row.values():
if type(v)not in(str,int,float,bool)or isinstance(v,str)and len(v)>256 or type(v)is float and not math.isfinite(v):raise ValueError('Bounded public scalars required')
if kind in('event','spellcast')and row.get('event')not in EVENTS:raise ValueError('Unknown travel event')
if kind=='observer-ready'and row.get('revision')not in('octo-travel-v1','octo-travel-v2','octo-travel-v3'):raise ValueError('Unknown observer revision')
if kind=='unit'and row.get('unit')not in('target','mouseover','npc'):raise ValueError('Unknown unit token')
if kind in('aura','aura-snapshot')and row.get('filter')not in('HELPFUL','HARMFUL'):raise ValueError('Unknown aura filter')
return capture
def extract_saved(raw):
"""Return validated capture and standalone Lua containing ONLY its exact table."""
if not isinstance(raw,str)or len(raw)>MAX_SOURCE:raise ValueError('Saved source size bound')
matches=list(FIELD.finditer(raw))
if len(matches)!=1:raise ValueError('Exactly one travel table required')
start=matches[0].end()-1;position=start;depth=0;parts=[]
while position<len(raw):
match=LEX.match(raw,position)
if not match:raise ValueError('Unsupported saved syntax')
value=match.group();position=match.end()
if position-start>MAX_TABLE:raise ValueError('Travel table parser size bound')
if value.startswith('--'):continue
parts.append(value)
if value=='{':depth+=1
elif value=='}':
depth-=1
if not depth:break
else:raise ValueError('Truncated travel table')
table=''.join(parts)
capture=validate(parse('GatewayDiagnosticsSaved = '+table,max_tokens=500000))
return capture,'WoWHybridTravelCapture = '+table+'\n'
def extract(raw):return extract_saved(raw)[0]
def summary(capture):
validate(capture);rows=capture['rows'];travels=[r for r in rows if r['kind']=='travel']
ready=[r for r in rows if r['kind']=='observer-ready']
latest_ready=capture.get('latestReady')
latest_proof=any(r['nonce']==capture['latestNonce']for r in ready)or bool(latest_ready and latest_ready['nonce']==capture['latestNonce'])
transitions=[];previous=None
for row in travels:
# Missing vanilla UnitOnTaxi/IsMounted values remain unknown, never inferred false.
state=(row.get('zone'),row.get('subzone'),row.get('onTaxi'),row.get('mounted'))
if state!=previous:
transitions.append({k:row[k]for k in('time','nonce','zone','subzone','onTaxi','mounted','reason')if k in row})
previous=state
count=collections.Counter(r['kind']for r in rows)
return {'kind':'official-octo-passive-travel-summary','rows':len(rows),'dropped':capture['dropped'],'loads':capture['loads'],
'latest_nonce':capture['latestNonce'],'ready_revisions':dict(collections.Counter(r['revision']for r in ready)),
'latest_nonce_ready_observed':latest_proof,
'latest_ready':latest_ready,'latest_travel':capture.get('latestTravel'),
'capture_policy':capture.get('capturePolicy'),'coalesced':capture.get('coalesced',{}),'aura_index_origin':capture.get('auraIndexOrigin'),
'row_kinds':dict(sorted(count.items())),'zone_names':sorted({r['zone']for r in travels if r.get('zone')}),
'subzone_names':sorted({r['subzone']for r in travels if r.get('subzone')}),
'taxi_truthy_samples':sum(bool(r.get('onTaxi'))for r in travels),
'mounted_truthy_samples':sum(bool(r.get('mounted'))for r in travels),
'zone_taxi_mount_transitions':transitions,'event_counts':capture.get('eventCounts',{}),
'capabilities':capture.get('capabilities',{}),'unsupported_events':capture.get('unsupportedEvents',{}),
'cast_events':dict(collections.Counter(r['event']for r in rows if r['kind']=='spellcast')),
'aura_rows':count.get('aura',0),'aura_snapshots':count.get('aura-snapshot',0),
'raw_packets_captured':False,'private_chat_in_isolated_table':False,'complete_toy_or_spawn_coverage_claimed':False,
'limits':['Only registered events and available original UI APIs are observed.',
'UnitOnTaxi/IsMounted may return numeric 1 or nil in vanilla; missing values remain absent.',
'Map coordinates retain current-map context and are not server/world XYZ.',
'V1 has no cast/aura detail rows; PLAYER_AURAS_CHANGED counts alone do not identify effects.',
'Raw source pfUI SavedVariables may contain private chat; only the extracted travel table is retained by the revised watcher.',
'Known NPC-name correlation is separate; player/unit names and GUIDs are omitted from this summary.']}
def snapshot(raw):
"""Filtered bytes + provenance; source content/path is never copied to metadata."""
c,isolated=extract_saved(raw);b=isolated.encode('utf-8')
return c,b,{'source_sha256':hashlib.sha256(raw.encode('utf-8')).hexdigest(),
'source_bytes':len(raw.encode('utf-8')),'isolated_table_sha256':hashlib.sha256(b).hexdigest(),
'isolated_table_bytes':len(b),'only_travel_table_saved':True,'unrelated_source_text_copied':False,
'rows':len(c['rows']),'dropped':c['dropped'],'latest_nonce':c['latestNonce']}