"""Local immutable evidence objects; production registry remains an adapter boundary.""" import json import re from src.modules.skill.domain.models import canonical, digest, SkillError class ArtifactCatalog: def __init__(self, repository): self.repository = repository def record(self, tenant, run_id, body): if not re.fullmatch(r'run-[a-f0-9]{32}', run_id): raise SkillError('INVALID_RUN_ID', '非法任务标识。') value = dict(body, run_id=run_id) key = digest(value) self.repository.put(tenant, run_id, key, canonical(value)) return {'digest': key, 'manifest': value} def read(self, tenant, run_id, key): value = self.repository.get(tenant, run_id, key) if value is None: raise SkillError('ARTIFACT_NOT_FOUND', '证据不存在或不可见。', 404) body = json.loads(value) if digest(body) != key: raise SkillError('ARTIFACT_DIGEST_MISMATCH', '证据损坏。', 409) return body