"""Reuse the sealed Activity capsule mechanics; Food scopes are separate tools."""
from pathlib import Path
root=Path(__file__).parent
old=root.parent/'parallel-store-activity-crud4-20261011'/'repaired-new-fixture'
for name in ('launcher.php','init.php','index.php','resource.php','cleanup-source.php'):
    s=(old/name).read_text()
    for a,b in [('cdx-store-activity-fixed-20261011','cdx-store-food-crud3-20261011'),('ACT_LANE','FOOD_LANE'),('ACT_ROOT','FOOD_ROOT'),('ACT_BUDGET','FOOD_BUDGET'),('ACT_OBSERVER','FOOD_OBSERVER'),('ActivityGate','FoodGate'),('ActStatement','FoodStatement'),('ActPDO','FoodPDO'),('CDXACT11W2','CDXFOOD11W1'),('18993','18995'),('18994','18996')]:s=s.replace(a,b)
    if name=='launcher.php':
        s=s.replace("['preflight','auth','launch','step','finish','cleanup','puregate','tap-proof']", "['preflight','auth','launch','step','finish','cleanup','puregate','tap-proof']")
    if name=='init.php':
        s=s.replace("define('RUNTIME_PATH',__DIR__.'/runtime/');require $root.'/external_stubs.php';", "define('RUNTIME_PATH',__DIR__.'/runtime/');require __DIR__.'/ExternalBoundary.php';if($lane==='B'){define('FOOD_TCHEF_PROCESS_ISOLATION',true);require __DIR__.'/TchefProcessConfig.php';}")
    if name=='index.php':
        s=s.replace('$before=$source();',"$before=$source($case['own_id']??null);")
        a=s.index("try{$record['after']=$source();")
        s=s[:a]+'''$record['transport_spy']=$GLOBALS['FOOD_TRANSPORT_SPY']??[];$record['notification_spy']=$GLOBALS['FOOD_NOTIFICATION_SPY']??[];$record['tchef_config_isolation_calls']=$GLOBALS['FOOD_TCHEF_CONFIG_ISOLATION_CALLS']??[];
try{$id=$case['own_id']??FoodGate::$generatedId;$record['after']=$source($id);$guard($before,$record['after']);$record['protected_equal']=true;$record['observer']=$GLOBALS['FOOD_OBSERVER'];}catch(Throwable $e){$record['observer_error']=['class'=>get_class($e),'message'=>$e->getMessage()];$record['observer']=$GLOBALS['FOOD_OBSERVER'];}restore_error_handler();$save('wire-'.$case['label'].'.json',$record);
'''
    (root/name).write_text(s)
print('Reused capsule mechanics only; no DB/HTTP')
