"""Bounded immutable context; references carry no execution authority."""
import json
from src.modules.skill.domain.models import canonical, digest, SkillError
class ContextService:
@staticmethod
def repair_inputs(files, failure_code, diagnostics):
"""Scope compiler repairs and disclose views for list-only API failures.
Complete sources and logs remain in the immutable run. No clipping of
requirements, source files or contracts is used to fit a budget.
"""
java = 'src/main/java/demo/App.java'
text = diagnostics.get('diagnostics', '') if isinstance(diagnostics, dict) else ''
import re
locations = re.findall(r'(?:/input/)?([\w/.-]+\.java):\d+: error:', text)
scoped = (failure_code == 'JAVA_BUILD_FAILED' and locations
and all(path == java for path in locations) and java in files)
selected = {java: files[java]} if scoped else dict(files)
failures=diagnostics.get('failures',[]) if isinstance(diagnostics,dict) else []
if (failure_code=='JAVA_TEST_FAILED' and failures and java in files
and all(isinstance(f,dict) and f.get('path') in {'/health','/api/app/meta','/unknown'} for f in failures)):
return {'previous':{java:files[java]},'repair_scope':{'mode':'exact-edits','files':[java],
'retained_full_sources':{path:digest(content) for path,content in files.items()},
'unchanged_files':{path:digest(content) for path,content in files.items() if path!=java},
'instruction':'Correct only the disclosed platform protocol failure with exact edits. Preserve the website and every business operation.'}}
list_failure=(failure_code=='JAVA_TEST_FAILED' and bool(failures)
and all(isinstance(f,dict) and f.get('path')=='/api/app/list' for f in failures))
if list_failure and 'website/index.html' in files and java in files:
# A successful compilation plus a disclosed list failure: retain
# routing, handlers, serialization and all browser logic. Static
# styling and unrelated initialization/persistence bodies remain in
# the saved patch base, never regenerated or silently clipped.
omitted=[]
def keep_signature(match):
omitted.append({'method':match.group(1),'digest':digest(match.group(0))})
return ' // Unchanged '+match.group(1)+' body retained in saved source.\n'
java_view=re.sub(r'(?ms)^ static void (generateInitialData|persist|handleAction)\([^\n]*\).*?(?=^ (?:static |class )|\Z)',keep_signature,files[java])
page=files['website/index.html']
scripts='\n'.join(re.findall(r'',page,re.S|re.I))
if scripts:
static=page.split('