#!/usr/bin/env python3
"""Authoritative matrix capture: same RPC driver on fresh revision-specific databases."""
import pathlib,subprocess,os,json
r=pathlib.Path('/tmp/lead-33105-r1/evidence-capture-1')
def first(pattern):return str(next(r.glob(pattern)))
env={**os.environ,'T3CODE_DEV_AUTH_TOKEN':os.environ['EVIDENCE_DEV_TOKEN']}
def rpc(d,action='capture'):
 c=json.loads((pathlib.Path(d)/'capture-context.json').read_text());subprocess.run(['node',str(r/'rpc-driver.mjs'),c['worktree'],d,action],check=True,env=env)
def extra(server,label,instance,settings):
 d=subprocess.check_output(['python3',str(r/'add-fixture.py'),first(server),label,instance,json.dumps(settings)],text=True).strip();rpc(d);print(label,d,flush=True)
for pattern in ['final-base-default-*','final-head-default-*','final-head-host-on-*','final-head-host-off-*']:
 d=first(pattern);rpc(d);print('default',d,flush=True)
for server,label,instance,settings in [
 ('final-head-default-*','final-E1-head','0',{}),
 ('final-head-default-*','final-E2-head','1',{}),
 ('final-head-host-off-*','final-E4-head','0',{}),
 ('final-head-host-on-*','final-E5-head','0',{}),
 ('final-head-host-off-*','final-E7-head','1',{}),
 ('final-head-host-on-*','final-E8-head','1',{}),
 ('final-head-default-*','final-S1-head-T3','U',{'env':{'CLAUDE_CODE_ARTIFACT':'1'}}),
]:extra(server,label,instance,settings)
for pattern in ['final-base-default-*','final-head-default-*']:rpc(first(pattern),'title')
