Files
aigc-home/docs/hel-892/zimage-reverse-document-evidence/source_closure.py
T
2026-10-31 09:44:19 +08:00

61 lines
1.9 KiB
Python

"List source texts and their identity/permission evidence, without self hashing."
import hashlib
import json
from build_definition import OUT, REF, REPO
def main():
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
paths = {REF / "sources.json"}
for e in rows:
paths.add((REF / e["local_file"]).resolve())
if not e["license_file"].startswith("未知"):
paths.add((REF / e["license_file"]).resolve())
if e["id"] == "llama-unavailable":
continue
if "artifact_sha256" in e:
paths.update(
(REF / (e["id"] + suffix)).resolve()
for suffix in ["-package.json", "-registry.json"]
)
continue
base = REF / e["identity_root"]
paths.update(
(base / (e["identity_key"] + suffix)).resolve()
for suffix in ["-commit.txt", "-tag.txt", "-tag.json", "-tree.json"]
)
result = []
for p in sorted(paths):
raw = p.read_bytes()
result.append(
dict(
path=str(p.relative_to(REPO)),
sha256=hashlib.sha256(raw).hexdigest(),
purpose="准确来源原文、许可或Git对象绑定;静态读取未执行",
)
)
(OUT / "source-closure.json").write_text(
json.dumps(
dict(
files=result,
count=len(result),
upstream_executed=False,
note=(
"commit/tag字节和选定blob已重算;tree列表非完整树对象"
"重哈希。整包SHA来自准确包采集记录,成员重哈希;包到Git未知,未安"
"装。"
),
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print("PASS source closure", len(result))
if __name__ == "__main__":
main()