|
@@ -49,11 +49,21 @@ DERIVED_BOARD_VIEWER_ASSETS = frozenset(
|
|
|
"import-report.json",
|
|
"import-report.json",
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
+SELF_REFERENCE_CONTROL_FILES = (
|
|
|
|
|
+ "HANDOFF-INDEX.json",
|
|
|
|
|
+ "SHA256SUMS.txt",
|
|
|
|
|
+ "EXCLUSIONS.txt",
|
|
|
|
|
+ "PACKAGE-PURPOSE.txt",
|
|
|
|
|
+ "START-HERE.zh-CN.md",
|
|
|
|
|
+ "size-budget.json",
|
|
|
|
|
+)
|
|
|
CATEGORY_ORDER = {
|
|
CATEGORY_ORDER = {
|
|
|
"core": 0,
|
|
"core": 0,
|
|
|
|
|
+ "source": 0,
|
|
|
"hardware": 1,
|
|
"hardware": 1,
|
|
|
"td-docs": 2,
|
|
"td-docs": 2,
|
|
|
"evidence": 3,
|
|
"evidence": 3,
|
|
|
|
|
+ "meta": 4,
|
|
|
}
|
|
}
|
|
|
GENERATED_BINARY_SUFFIXES = {
|
|
GENERATED_BINARY_SUFFIXES = {
|
|
|
".bit",
|
|
".bit",
|
|
@@ -453,6 +463,12 @@ def analysis_exclusion_reason(
|
|
|
if not is_dir and handoff.is_under(lower, "tools/board-viewer/generated"):
|
|
if not is_dir and handoff.is_under(lower, "tools/board-viewer/generated"):
|
|
|
if name in handoff.CODE_ONLY_GENERATED_VISUAL_ASSETS:
|
|
if name in handoff.CODE_ONLY_GENERATED_VISUAL_ASSETS:
|
|
|
return "generated_board_viewer_visual_asset"
|
|
return "generated_board_viewer_visual_asset"
|
|
|
|
|
+ if handoff.is_review_profile(profile):
|
|
|
|
|
+ review_reason = handoff.review_exclusion_reason(
|
|
|
|
|
+ relative, is_dir=is_dir, profile=profile
|
|
|
|
|
+ )
|
|
|
|
|
+ if review_reason:
|
|
|
|
|
+ return review_reason
|
|
|
for item in extra_exclusions:
|
|
for item in extra_exclusions:
|
|
|
prefix = str(item.get("path", "")).casefold().strip("/")
|
|
prefix = str(item.get("path", "")).casefold().strip("/")
|
|
|
if prefix and handoff.is_under(lower, prefix):
|
|
if prefix and handoff.is_under(lower, prefix):
|
|
@@ -547,13 +563,21 @@ def analysis_exclusion_reason(
|
|
|
if suffix in RUNTIME_EVIDENCE_SUFFIXES:
|
|
if suffix in RUNTIME_EVIDENCE_SUFFIXES:
|
|
|
return "runtime_evidence_or_waveform"
|
|
return "runtime_evidence_or_waveform"
|
|
|
if suffix in BOARD_DESIGN_SUFFIXES:
|
|
if suffix in BOARD_DESIGN_SUFFIXES:
|
|
|
|
|
+ if handoff.is_board_viewer_fixture_path(relative):
|
|
|
|
|
+ return None
|
|
|
|
|
+ if handoff.is_review_profile(profile):
|
|
|
|
|
+ return "heavy_design_original_not_packaged"
|
|
|
if "reference" in parts:
|
|
if "reference" in parts:
|
|
|
return None
|
|
return None
|
|
|
return "board_design_file"
|
|
return "board_design_file"
|
|
|
if suffix in IMAGE_SUFFIXES:
|
|
if suffix in IMAGE_SUFFIXES:
|
|
|
- if "reference" in parts:
|
|
|
|
|
|
|
+ if name in BOARD_VIEWER_GENERATED_ASSETS or name in DERIVED_BOARD_VIEWER_ASSETS:
|
|
|
return None
|
|
return None
|
|
|
- if name in BOARD_VIEWER_GENERATED_ASSETS:
|
|
|
|
|
|
|
+ if handoff.is_board_viewer_fixture_path(relative):
|
|
|
|
|
+ return None
|
|
|
|
|
+ if handoff.is_review_profile(profile) and suffix == ".pdf":
|
|
|
|
|
+ return "heavy_design_original_not_packaged"
|
|
|
|
|
+ if "reference" in parts:
|
|
|
return None
|
|
return None
|
|
|
return "image_file"
|
|
return "image_file"
|
|
|
if name in STRAY_FILENAMES:
|
|
if name in STRAY_FILENAMES:
|
|
@@ -726,6 +750,63 @@ def _run_git(command: list[str], *, cwd: Path, timeout: int = 300) -> str:
|
|
|
return completed.stdout
|
|
return completed.stdout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _is_evidence_source_path(relative: str) -> bool:
|
|
|
|
|
+ lower = relative.casefold()
|
|
|
|
|
+ if handoff.is_under(lower, "receipts"):
|
|
|
|
|
+ return True
|
|
|
|
|
+ if handoff.is_under(lower, "tools/board-viewer/generated"):
|
|
|
|
|
+ return True
|
|
|
|
|
+ name = lower.rsplit("/", 1)[-1]
|
|
|
|
|
+ if name in DERIVED_BOARD_VIEWER_ASSETS and "board-viewer" in lower:
|
|
|
|
|
+ return True
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _unified_layout_prefix(
|
|
|
|
|
+ *,
|
|
|
|
|
+ source_id: str,
|
|
|
|
|
+ original_relative: str,
|
|
|
|
|
+ profile: str,
|
|
|
|
|
+) -> tuple[str, str]:
|
|
|
|
|
+ """Return (archive_prefix, category) for unified review layouts."""
|
|
|
|
|
+ del profile
|
|
|
|
|
+ if source_id == "board-viewer-generated" or source_id.startswith("board-viewer"):
|
|
|
|
|
+ return "evidence/board-viewer", "evidence"
|
|
|
|
|
+ if source_id != "workspace-current" and source_id != "source":
|
|
|
|
|
+ if _is_evidence_source_path(original_relative):
|
|
|
|
|
+ return f"evidence/external/{source_id}", "evidence"
|
|
|
|
|
+ return f"source/external/{source_id}", "source"
|
|
|
|
|
+ if _is_evidence_source_path(original_relative):
|
|
|
|
|
+ return "evidence", "evidence"
|
|
|
|
|
+ return "source", "source"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _materialize_bytes_items(
|
|
|
|
|
+ payloads: dict[str, bytes],
|
|
|
|
|
+ *,
|
|
|
|
|
+ temp_root: Path,
|
|
|
|
|
+ source_id: str,
|
|
|
|
|
+ category: str,
|
|
|
|
|
+) -> list[PackageItem]:
|
|
|
|
|
+ items: list[PackageItem] = []
|
|
|
|
|
+ root = temp_root / "generated-meta"
|
|
|
|
|
+ root.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ for relative, payload in sorted(payloads.items()):
|
|
|
|
|
+ path = root / Path(*relative.split("/"))
|
|
|
|
|
+ path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ path.write_bytes(payload)
|
|
|
|
|
+ items.append(
|
|
|
|
|
+ make_package_item(
|
|
|
|
|
+ path,
|
|
|
|
|
+ relative=relative,
|
|
|
|
|
+ category=category,
|
|
|
|
|
+ source_id=source_id,
|
|
|
|
|
+ scan_archive=False,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ return items
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _create_git_bundle(
|
|
def _create_git_bundle(
|
|
|
*,
|
|
*,
|
|
|
root: Path,
|
|
root: Path,
|
|
@@ -788,14 +869,22 @@ def collect_analysis_inputs(
|
|
|
temp_root: Path,
|
|
temp_root: Path,
|
|
|
include_git_bundle: bool = True,
|
|
include_git_bundle: bool = True,
|
|
|
profile: str = "full",
|
|
profile: str = "full",
|
|
|
|
|
+ include_sanitized_git_snapshot: bool = False,
|
|
|
|
|
+ package_name: str = "pending",
|
|
|
) -> AnalysisCollection:
|
|
) -> AnalysisCollection:
|
|
|
root = repo_root.resolve(strict=True)
|
|
root = repo_root.resolve(strict=True)
|
|
|
temp_root.mkdir(parents=True, exist_ok=True)
|
|
temp_root.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ if profile not in handoff.HANDOFF_PROFILES:
|
|
|
|
|
+ raise PackagingError(f"unsupported handoff profile: {profile}")
|
|
|
if profile == "full" and not include_git_bundle:
|
|
if profile == "full" and not include_git_bundle:
|
|
|
raise PackagingError(
|
|
raise PackagingError(
|
|
|
"full inclusion-first packages require a git bundle so replay can restore "
|
|
"full inclusion-first packages require a git bundle so replay can restore "
|
|
|
"commit-to-commit source closure comparison"
|
|
"commit-to-commit source closure comparison"
|
|
|
)
|
|
)
|
|
|
|
|
+ unified = handoff.uses_unified_layout(profile)
|
|
|
|
|
+ # review-compact / review-debug never ship a full bundle unless explicitly forced later.
|
|
|
|
|
+ if profile in {"review-compact", "review-debug"}:
|
|
|
|
|
+ include_git_bundle = False
|
|
|
items: list[PackageItem] = []
|
|
items: list[PackageItem] = []
|
|
|
excluded: list[dict[str, str]] = []
|
|
excluded: list[dict[str, str]] = []
|
|
|
warnings: list[dict[str, str]] = []
|
|
warnings: list[dict[str, str]] = []
|
|
@@ -803,28 +892,90 @@ def collect_analysis_inputs(
|
|
|
git_metadata: list[dict[str, object]] = []
|
|
git_metadata: list[dict[str, object]] = []
|
|
|
source_snapshots: list[SourceSnapshot] = []
|
|
source_snapshots: list[SourceSnapshot] = []
|
|
|
|
|
|
|
|
- root_items, root_excluded = _collect_directory_items(
|
|
|
|
|
- root=root,
|
|
|
|
|
- source_id="workspace-current",
|
|
|
|
|
- category="core",
|
|
|
|
|
- prefix="workspace-current",
|
|
|
|
|
- extra_exclusions=config.extra_exclusions,
|
|
|
|
|
- profile=profile,
|
|
|
|
|
- )
|
|
|
|
|
- items.extend(root_items)
|
|
|
|
|
- excluded.extend(root_excluded)
|
|
|
|
|
|
|
+ primary_source_id = "workspace-current"
|
|
|
|
|
+ if unified:
|
|
|
|
|
+ # Collect with a temporary prefix, then remap into source/ or evidence/.
|
|
|
|
|
+ root_items, root_excluded = _collect_directory_items(
|
|
|
|
|
+ root=root,
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
|
|
+ category="source",
|
|
|
|
|
+ prefix="__workspace__",
|
|
|
|
|
+ extra_exclusions=config.extra_exclusions,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ remapped: list[PackageItem] = []
|
|
|
|
|
+ for item in root_items:
|
|
|
|
|
+ original = item.original_path
|
|
|
|
|
+ prefix, category = _unified_layout_prefix(
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
|
|
+ original_relative=original,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ remapped.append(
|
|
|
|
|
+ PackageItem(
|
|
|
|
|
+ candidate=_rebase_candidate(
|
|
|
|
|
+ handoff.Candidate(
|
|
|
|
|
+ absolute=item.candidate.absolute,
|
|
|
|
|
+ relative=original,
|
|
|
|
|
+ size=item.candidate.size,
|
|
|
|
|
+ mtime_ns=item.candidate.mtime_ns,
|
|
|
|
|
+ device=item.candidate.device,
|
|
|
|
|
+ inode=item.candidate.inode,
|
|
|
|
|
+ mode=item.candidate.mode,
|
|
|
|
|
+ ),
|
|
|
|
|
+ prefix,
|
|
|
|
|
+ ),
|
|
|
|
|
+ category=category,
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
|
|
+ original_path=original,
|
|
|
|
|
+ scan_archive=item.scan_archive,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ items.extend(remapped)
|
|
|
|
|
+ for entry in root_excluded:
|
|
|
|
|
+ original_excluded = entry["path"]
|
|
|
|
|
+ if original_excluded.startswith("__workspace__/"):
|
|
|
|
|
+ original_excluded = original_excluded[len("__workspace__/") :]
|
|
|
|
|
+ elif original_excluded == "__workspace__":
|
|
|
|
|
+ original_excluded = "."
|
|
|
|
|
+ prefix, _category = _unified_layout_prefix(
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
|
|
+ original_relative=original_excluded,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ excluded.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "path": (
|
|
|
|
|
+ original_excluded
|
|
|
|
|
+ if original_excluded == "."
|
|
|
|
|
+ else f"{prefix}/{original_excluded}"
|
|
|
|
|
+ ),
|
|
|
|
|
+ "rule": entry["rule"],
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ root_items, root_excluded = _collect_directory_items(
|
|
|
|
|
+ root=root,
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
|
|
+ category="core",
|
|
|
|
|
+ prefix="workspace-current",
|
|
|
|
|
+ extra_exclusions=config.extra_exclusions,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ items.extend(root_items)
|
|
|
|
|
+ excluded.extend(root_excluded)
|
|
|
source_snapshots.append(
|
|
source_snapshots.append(
|
|
|
_source_snapshot(
|
|
_source_snapshot(
|
|
|
root,
|
|
root,
|
|
|
- source_id="workspace-current",
|
|
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
extra_exclusions=config.extra_exclusions,
|
|
extra_exclusions=config.extra_exclusions,
|
|
|
profile=profile,
|
|
profile=profile,
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
sources.append(
|
|
sources.append(
|
|
|
{
|
|
{
|
|
|
- "id": "workspace-current",
|
|
|
|
|
- "category": "core",
|
|
|
|
|
|
|
+ "id": primary_source_id,
|
|
|
|
|
+ "category": "source" if unified else "core",
|
|
|
"kind": "git_worktree",
|
|
"kind": "git_worktree",
|
|
|
"path": str(root),
|
|
"path": str(root),
|
|
|
"status": "pass",
|
|
"status": "pass",
|
|
@@ -833,11 +984,59 @@ def collect_analysis_inputs(
|
|
|
if include_git_bundle:
|
|
if include_git_bundle:
|
|
|
bundle_item, bundle_metadata = _create_git_bundle(
|
|
bundle_item, bundle_metadata = _create_git_bundle(
|
|
|
root=root,
|
|
root=root,
|
|
|
- source_id="workspace-current",
|
|
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
temp_root=temp_root,
|
|
temp_root=temp_root,
|
|
|
)
|
|
)
|
|
|
|
|
+ if unified:
|
|
|
|
|
+ # Keep bundle under meta/git-history for archive-local.
|
|
|
|
|
+ bundle_rel = f"meta/git-history/{primary_source_id}.bundle"
|
|
|
|
|
+ bundle_item = PackageItem(
|
|
|
|
|
+ candidate=handoff.Candidate(
|
|
|
|
|
+ absolute=bundle_item.candidate.absolute,
|
|
|
|
|
+ relative=bundle_rel,
|
|
|
|
|
+ size=bundle_item.candidate.size,
|
|
|
|
|
+ mtime_ns=bundle_item.candidate.mtime_ns,
|
|
|
|
|
+ device=bundle_item.candidate.device,
|
|
|
|
|
+ inode=bundle_item.candidate.inode,
|
|
|
|
|
+ mode=bundle_item.candidate.mode,
|
|
|
|
|
+ ),
|
|
|
|
|
+ category="meta",
|
|
|
|
|
+ source_id=primary_source_id,
|
|
|
|
|
+ original_path=".git",
|
|
|
|
|
+ scan_archive=False,
|
|
|
|
|
+ )
|
|
|
|
|
+ bundle_metadata = {**bundle_metadata, "bundle_path": bundle_rel}
|
|
|
items.append(bundle_item)
|
|
items.append(bundle_item)
|
|
|
git_metadata.append(bundle_metadata)
|
|
git_metadata.append(bundle_metadata)
|
|
|
|
|
+ elif unified:
|
|
|
|
|
+ provenance, provenance_artifacts = handoff.collect_review_git_provenance(
|
|
|
|
|
+ root,
|
|
|
|
|
+ include_sanitized_git_snapshot=include_sanitized_git_snapshot,
|
|
|
|
|
+ meta_prefix="meta/git",
|
|
|
|
|
+ )
|
|
|
|
|
+ binding = handoff.build_td_source_closure_binding_hook(root)
|
|
|
|
|
+ provenance_artifacts["meta/td-source-closure-binding.json"] = handoff.json_bytes(binding)
|
|
|
|
|
+ purpose = handoff.package_purpose_text(profile, package_name=package_name)
|
|
|
|
|
+ provenance_artifacts["meta/PACKAGE-PURPOSE.txt"] = purpose.encode("utf-8")
|
|
|
|
|
+ items.extend(
|
|
|
|
|
+ _materialize_bytes_items(
|
|
|
|
|
+ provenance_artifacts,
|
|
|
|
|
+ temp_root=temp_root,
|
|
|
|
|
+ source_id="meta-generated",
|
|
|
|
|
+ category="meta",
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ git_metadata.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "source_id": primary_source_id,
|
|
|
|
|
+ "status": provenance.get("status"),
|
|
|
|
|
+ "branch": provenance.get("branch"),
|
|
|
|
|
+ "head": provenance.get("head"),
|
|
|
|
|
+ "full_bundle": False,
|
|
|
|
|
+ "provenance": provenance,
|
|
|
|
|
+ "td_source_closure_binding": binding,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
resolved_sources, source_warnings = resolve_external_sources(config.external_sources)
|
|
resolved_sources, source_warnings = resolve_external_sources(config.external_sources)
|
|
|
if profile == "code-only":
|
|
if profile == "code-only":
|
|
@@ -846,47 +1045,127 @@ def collect_analysis_inputs(
|
|
|
]
|
|
]
|
|
|
warnings.extend(source_warnings)
|
|
warnings.extend(source_warnings)
|
|
|
for source in resolved_sources:
|
|
for source in resolved_sources:
|
|
|
- prefix = f"external/{source.id}"
|
|
|
|
|
- if source.kind == "file":
|
|
|
|
|
- candidate = _candidate_from_path(source.path, f"{prefix}/{source.path.name}")
|
|
|
|
|
- items.append(
|
|
|
|
|
- PackageItem(
|
|
|
|
|
- candidate=candidate,
|
|
|
|
|
- category=source.category,
|
|
|
|
|
|
|
+ if unified:
|
|
|
|
|
+ # Prefer derived board-viewer assets under evidence/.
|
|
|
|
|
+ if source.kind == "file":
|
|
|
|
|
+ prefix, category = _unified_layout_prefix(
|
|
|
source_id=source.id,
|
|
source_id=source.id,
|
|
|
- original_path=source.path.name,
|
|
|
|
|
- scan_archive=source.archive_policy == "inspect",
|
|
|
|
|
|
|
+ original_relative=source.path.name,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ candidate = _candidate_from_path(
|
|
|
|
|
+ source.path, f"{prefix}/{source.path.name}"
|
|
|
|
|
+ )
|
|
|
|
|
+ items.append(
|
|
|
|
|
+ PackageItem(
|
|
|
|
|
+ candidate=candidate,
|
|
|
|
|
+ category=category,
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ original_path=source.path.name,
|
|
|
|
|
+ scan_archive=source.archive_policy == "inspect",
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ source_items, source_excluded = _collect_directory_items(
|
|
|
|
|
+ root=source.path,
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ category="evidence",
|
|
|
|
|
+ prefix="__external__",
|
|
|
|
|
+ extra_exclusions=config.extra_exclusions,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ for item in source_items:
|
|
|
|
|
+ original = item.original_path
|
|
|
|
|
+ prefix, category = _unified_layout_prefix(
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ original_relative=original,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ items.append(
|
|
|
|
|
+ PackageItem(
|
|
|
|
|
+ candidate=_rebase_candidate(
|
|
|
|
|
+ handoff.Candidate(
|
|
|
|
|
+ absolute=item.candidate.absolute,
|
|
|
|
|
+ relative=original,
|
|
|
|
|
+ size=item.candidate.size,
|
|
|
|
|
+ mtime_ns=item.candidate.mtime_ns,
|
|
|
|
|
+ device=item.candidate.device,
|
|
|
|
|
+ inode=item.candidate.inode,
|
|
|
|
|
+ mode=item.candidate.mode,
|
|
|
|
|
+ ),
|
|
|
|
|
+ prefix,
|
|
|
|
|
+ ),
|
|
|
|
|
+ category=category,
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ original_path=original,
|
|
|
|
|
+ scan_archive=item.scan_archive,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ for entry in source_excluded:
|
|
|
|
|
+ original_excluded = entry["path"]
|
|
|
|
|
+ if original_excluded.startswith("__external__/"):
|
|
|
|
|
+ original_excluded = original_excluded[len("__external__/") :]
|
|
|
|
|
+ prefix, _category = _unified_layout_prefix(
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ original_relative=original_excluded,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ excluded.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "path": f"{prefix}/{original_excluded}",
|
|
|
|
|
+ "rule": entry["rule"],
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ source_snapshots.append(
|
|
|
|
|
+ _source_snapshot(
|
|
|
|
|
+ source.path,
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ extra_exclusions=config.extra_exclusions,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
)
|
|
)
|
|
|
- )
|
|
|
|
|
else:
|
|
else:
|
|
|
- source_items, source_excluded = _collect_directory_items(
|
|
|
|
|
- root=source.path,
|
|
|
|
|
- source_id=source.id,
|
|
|
|
|
- category=source.category,
|
|
|
|
|
- prefix=prefix,
|
|
|
|
|
- extra_exclusions=config.extra_exclusions,
|
|
|
|
|
- profile=profile,
|
|
|
|
|
- )
|
|
|
|
|
- items.extend(source_items)
|
|
|
|
|
- excluded.extend(source_excluded)
|
|
|
|
|
- source_snapshots.append(
|
|
|
|
|
- _source_snapshot(
|
|
|
|
|
- source.path,
|
|
|
|
|
|
|
+ prefix = f"external/{source.id}"
|
|
|
|
|
+ if source.kind == "file":
|
|
|
|
|
+ candidate = _candidate_from_path(source.path, f"{prefix}/{source.path.name}")
|
|
|
|
|
+ items.append(
|
|
|
|
|
+ PackageItem(
|
|
|
|
|
+ candidate=candidate,
|
|
|
|
|
+ category=source.category,
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ original_path=source.path.name,
|
|
|
|
|
+ scan_archive=source.archive_policy == "inspect",
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ source_items, source_excluded = _collect_directory_items(
|
|
|
|
|
+ root=source.path,
|
|
|
source_id=source.id,
|
|
source_id=source.id,
|
|
|
|
|
+ category=source.category,
|
|
|
|
|
+ prefix=prefix,
|
|
|
extra_exclusions=config.extra_exclusions,
|
|
extra_exclusions=config.extra_exclusions,
|
|
|
profile=profile,
|
|
profile=profile,
|
|
|
)
|
|
)
|
|
|
- )
|
|
|
|
|
|
|
+ items.extend(source_items)
|
|
|
|
|
+ excluded.extend(source_excluded)
|
|
|
|
|
+ source_snapshots.append(
|
|
|
|
|
+ _source_snapshot(
|
|
|
|
|
+ source.path,
|
|
|
|
|
+ source_id=source.id,
|
|
|
|
|
+ extra_exclusions=config.extra_exclusions,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
sources.append(
|
|
sources.append(
|
|
|
{
|
|
{
|
|
|
"id": source.id,
|
|
"id": source.id,
|
|
|
- "category": source.category,
|
|
|
|
|
|
|
+ "category": "evidence" if unified else source.category,
|
|
|
"kind": source.kind,
|
|
"kind": source.kind,
|
|
|
"path": str(source.path),
|
|
"path": str(source.path),
|
|
|
"status": "pass",
|
|
"status": "pass",
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- if source.kind == "git_worktree":
|
|
|
|
|
|
|
+ if source.kind == "git_worktree" and include_git_bundle:
|
|
|
external_bundle, external_git = _create_git_bundle(
|
|
external_bundle, external_git = _create_git_bundle(
|
|
|
root=source.path,
|
|
root=source.path,
|
|
|
source_id=source.id,
|
|
source_id=source.id,
|
|
@@ -1289,6 +1568,7 @@ def _is_board_viewer_generated_path(relative: str) -> bool:
|
|
|
lower = relative.casefold()
|
|
lower = relative.casefold()
|
|
|
return (
|
|
return (
|
|
|
"board-viewer-generated" in lower
|
|
"board-viewer-generated" in lower
|
|
|
|
|
+ or handoff.is_under(lower, "evidence/board-viewer")
|
|
|
or "/tools/board-viewer/generated/" in f"/{lower}/"
|
|
or "/tools/board-viewer/generated/" in f"/{lower}/"
|
|
|
or lower.startswith("tools/board-viewer/generated/")
|
|
or lower.startswith("tools/board-viewer/generated/")
|
|
|
)
|
|
)
|
|
@@ -1889,8 +2169,8 @@ def _assert_source_trees_unchanged(collection: AnalysisCollection, *, profile: s
|
|
|
raise PackagingError("source tree changed during analysis packaging: retry from a stable workspace snapshot")
|
|
raise PackagingError("source tree changed during analysis packaging: retry from a stable workspace snapshot")
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _start_here_text(package_name: str, volume_count: int) -> str:
|
|
|
|
|
- return (
|
|
|
|
|
|
|
+def _start_here_text(package_name: str, volume_count: int, *, profile: str = "full") -> str:
|
|
|
|
|
+ base = (
|
|
|
f"# {package_name} 分析交付包\n\n"
|
|
f"# {package_name} 分析交付包\n\n"
|
|
|
f"本目录包含 {volume_count} 个互相独立的普通 ZIP,以及可选的 `.tar.zst` 同源归档。"
|
|
f"本目录包含 {volume_count} 个互相独立的普通 ZIP,以及可选的 `.tar.zst` 同源归档。"
|
|
|
"请先核对 `SHA256SUMS.txt`,再把所有 ZIP 解压到同一个目录;"
|
|
"请先核对 `SHA256SUMS.txt`,再把所有 ZIP 解压到同一个目录;"
|
|
@@ -1899,11 +2179,42 @@ def _start_here_text(package_name: str, volume_count: int) -> str:
|
|
|
"`EXCLUSIONS.txt` 列出排除路径与规则,"
|
|
"`EXCLUSIONS.txt` 列出排除路径与规则,"
|
|
|
"以及 `excluded`(排除原因)、`derived_evidence`(由原始 BRD 派生的 board-viewer JSON/SVG,"
|
|
"以及 `excluded`(排除原因)、`derived_evidence`(由原始 BRD 派生的 board-viewer JSON/SVG,"
|
|
|
"不是 RTL/TD source closure)和 `content_dedup`(相同大文件只保留一份物理副本时的逻辑归属)。\n"
|
|
"不是 RTL/TD source closure)和 `content_dedup`(相同大文件只保留一份物理副本时的逻辑归属)。\n"
|
|
|
|
|
+ )
|
|
|
|
|
+ if handoff.uses_unified_layout(profile):
|
|
|
|
|
+ return base + (
|
|
|
|
|
+ "本包为统一布局:`source/` + `evidence/` + `meta/`。\n"
|
|
|
|
|
+ "`PACKAGE-PURPOSE.txt` 说明上传意图;`size-budget.json` 列出 ≥256KiB 或 >1% 体积的成员。\n"
|
|
|
|
|
+ "默认 **不含** 完整 Git bundle;`meta/git/` 提供 commit/status/log-20/tree/逐文件 SHA-256 "
|
|
|
|
|
+ "与 TD source-closure 绑定钩子。\n"
|
|
|
|
|
+ "成员计数:`member_count.indexed_files` 对应 ZIP 内业务文件;"
|
|
|
|
|
+ "`self_reference_control_files` 是包目录控制文件(亦列入 SHA256SUMS),"
|
|
|
|
|
+ "不要把控制文件与 ZIP payload 成员重复加总。\n"
|
|
|
|
|
+ )
|
|
|
|
|
+ return base + (
|
|
|
"完整 full 包必须包含 `git-history/*.bundle`,以便在干净提取后用 commit-to-commit "
|
|
"完整 full 包必须包含 `git-history/*.bundle`,以便在干净提取后用 commit-to-commit "
|
|
|
"恢复 source closure 比对。\n"
|
|
"恢复 source closure 比对。\n"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def build_member_count_semantics(
|
|
|
|
|
+ *,
|
|
|
|
|
+ indexed_files: int,
|
|
|
|
|
+ zip_file_entries: int,
|
|
|
|
|
+ control_files: tuple[str, ...] = SELF_REFERENCE_CONTROL_FILES,
|
|
|
|
|
+) -> dict[str, object]:
|
|
|
|
|
+ return {
|
|
|
|
|
+ "indexed_files": indexed_files,
|
|
|
|
|
+ "zip_file_entries": zip_file_entries,
|
|
|
|
|
+ "self_reference_control_files": list(control_files),
|
|
|
|
|
+ "note": (
|
|
|
|
|
+ "indexed_files counts HANDOFF-INDEX files[] (ZIP payload business members). "
|
|
|
|
|
+ "zip_file_entries counts non-directory ZIP entries including VOLUME-MANIFEST. "
|
|
|
|
|
+ "self_reference_control_files live in the package directory and appear in "
|
|
|
|
|
+ "SHA256SUMS; do not add them again to indexed_files."
|
|
|
|
|
+ ),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def write_exclusions_text(excluded: list[dict[str, object]]) -> str:
|
|
def write_exclusions_text(excluded: list[dict[str, object]]) -> str:
|
|
|
"""Render a portable EXCLUSIONS.txt for the package sidecar layout."""
|
|
"""Render a portable EXCLUSIONS.txt for the package sidecar layout."""
|
|
|
lines = [
|
|
lines = [
|
|
@@ -1978,6 +2289,8 @@ def write_package_layout_sidecars(
|
|
|
excluded: list[dict[str, object]],
|
|
excluded: list[dict[str, object]],
|
|
|
package_name: str,
|
|
package_name: str,
|
|
|
include_tar_zst: bool = True,
|
|
include_tar_zst: bool = True,
|
|
|
|
|
+ profile: str = "full",
|
|
|
|
|
+ size_budget: dict[str, object] | None = None,
|
|
|
) -> list[dict[str, object]]:
|
|
) -> list[dict[str, object]]:
|
|
|
"""Write index/checksums/exclusions and optional tar.zst; return checksum rows."""
|
|
"""Write index/checksums/exclusions and optional tar.zst; return checksum rows."""
|
|
|
staging.mkdir(parents=True, exist_ok=True)
|
|
staging.mkdir(parents=True, exist_ok=True)
|
|
@@ -1987,11 +2300,18 @@ def write_package_layout_sidecars(
|
|
|
encoding="utf-8",
|
|
encoding="utf-8",
|
|
|
newline="\n",
|
|
newline="\n",
|
|
|
)
|
|
)
|
|
|
|
|
+ (staging / "PACKAGE-PURPOSE.txt").write_text(
|
|
|
|
|
+ handoff.package_purpose_text(profile, package_name=package_name),
|
|
|
|
|
+ encoding="utf-8",
|
|
|
|
|
+ newline="\n",
|
|
|
|
|
+ )
|
|
|
(staging / "START-HERE.zh-CN.md").write_text(
|
|
(staging / "START-HERE.zh-CN.md").write_text(
|
|
|
- _start_here_text(package_name, len(index.get("volumes", []))),
|
|
|
|
|
|
|
+ _start_here_text(package_name, len(index.get("volumes", [])), profile=profile),
|
|
|
encoding="utf-8",
|
|
encoding="utf-8",
|
|
|
newline="\n",
|
|
newline="\n",
|
|
|
)
|
|
)
|
|
|
|
|
+ if size_budget is not None:
|
|
|
|
|
+ (staging / "size-budget.json").write_bytes(handoff.json_bytes(size_budget))
|
|
|
|
|
|
|
|
checksum_rows: list[dict[str, object]] = []
|
|
checksum_rows: list[dict[str, object]] = []
|
|
|
for info in index.get("volumes", []):
|
|
for info in index.get("volumes", []):
|
|
@@ -2020,7 +2340,15 @@ def write_package_layout_sidecars(
|
|
|
}
|
|
}
|
|
|
(staging / "HANDOFF-INDEX.json").write_bytes(handoff.json_bytes(index))
|
|
(staging / "HANDOFF-INDEX.json").write_bytes(handoff.json_bytes(index))
|
|
|
|
|
|
|
|
- for sidecar in ("HANDOFF-INDEX.json", "EXCLUSIONS.txt", "START-HERE.zh-CN.md"):
|
|
|
|
|
|
|
+ sidecar_names = [
|
|
|
|
|
+ "HANDOFF-INDEX.json",
|
|
|
|
|
+ "EXCLUSIONS.txt",
|
|
|
|
|
+ "PACKAGE-PURPOSE.txt",
|
|
|
|
|
+ "START-HERE.zh-CN.md",
|
|
|
|
|
+ ]
|
|
|
|
|
+ if size_budget is not None:
|
|
|
|
|
+ sidecar_names.append("size-budget.json")
|
|
|
|
|
+ for sidecar in sidecar_names:
|
|
|
checksum_rows.append(
|
|
checksum_rows.append(
|
|
|
{"file": sidecar, "sha256": handoff.sha256_file(staging / sidecar)}
|
|
{"file": sidecar, "sha256": handoff.sha256_file(staging / sidecar)}
|
|
|
)
|
|
)
|
|
@@ -2187,6 +2515,19 @@ def create_analysis_package(
|
|
|
for large_file in large_files:
|
|
for large_file in large_files:
|
|
|
for chunk in large_file["chunks"]:
|
|
for chunk in large_file["chunks"]:
|
|
|
chunk["volume"] = volume_by_path[str(chunk["path"])]
|
|
chunk["volume"] = volume_by_path[str(chunk["path"])]
|
|
|
|
|
+ zip_entry_count = 0
|
|
|
|
|
+ for info in volume_infos:
|
|
|
|
|
+ volume_path = staging / str(info["file"])
|
|
|
|
|
+ with zipfile.ZipFile(volume_path, "r", allowZip64=True) as archive:
|
|
|
|
|
+ zip_entry_count += sum(1 for name in archive.namelist() if not name.endswith("/"))
|
|
|
|
|
+ size_budget = handoff.build_size_budget(
|
|
|
|
|
+ inventory,
|
|
|
|
|
+ zip_total_bytes=sum(int(info["compressed_bytes"]) for info in volume_infos),
|
|
|
|
|
+ )
|
|
|
|
|
+ member_count = build_member_count_semantics(
|
|
|
|
|
+ indexed_files=len(indexed_files),
|
|
|
|
|
+ zip_file_entries=zip_entry_count,
|
|
|
|
|
+ )
|
|
|
index = {
|
|
index = {
|
|
|
"schema": "cpld-agent-analysis-index-v1",
|
|
"schema": "cpld-agent-analysis-index-v1",
|
|
|
"run_id": run_id,
|
|
"run_id": run_id,
|
|
@@ -2194,7 +2535,7 @@ def create_analysis_package(
|
|
|
"package_name": package_name,
|
|
"package_name": package_name,
|
|
|
"status": collection.status,
|
|
"status": collection.status,
|
|
|
"profile": profile,
|
|
"profile": profile,
|
|
|
- "delivery_policy": "code-only" if profile == "code-only" else "inclusion-first",
|
|
|
|
|
|
|
+ "delivery_policy": handoff.delivery_policy_for_profile(profile),
|
|
|
"max_zip_bytes": max_zip_bytes,
|
|
"max_zip_bytes": max_zip_bytes,
|
|
|
"target_zip_bytes": target_zip_bytes,
|
|
"target_zip_bytes": target_zip_bytes,
|
|
|
"sources": list(collection.sources),
|
|
"sources": list(collection.sources),
|
|
@@ -2203,6 +2544,8 @@ def create_analysis_package(
|
|
|
"excluded": package_excluded,
|
|
"excluded": package_excluded,
|
|
|
"content_dedup": content_dedup,
|
|
"content_dedup": content_dedup,
|
|
|
"derived_evidence": derived_evidence,
|
|
"derived_evidence": derived_evidence,
|
|
|
|
|
+ "member_count": member_count,
|
|
|
|
|
+ "size_budget": size_budget,
|
|
|
"volumes": volume_infos,
|
|
"volumes": volume_infos,
|
|
|
"files": indexed_files,
|
|
"files": indexed_files,
|
|
|
"large_files": large_files,
|
|
"large_files": large_files,
|
|
@@ -2225,6 +2568,8 @@ def create_analysis_package(
|
|
|
excluded=package_excluded,
|
|
excluded=package_excluded,
|
|
|
package_name=package_name,
|
|
package_name=package_name,
|
|
|
include_tar_zst=True,
|
|
include_tar_zst=True,
|
|
|
|
|
+ profile=profile,
|
|
|
|
|
+ size_budget=size_budget if handoff.uses_unified_layout(profile) else None,
|
|
|
)
|
|
)
|
|
|
full_inventory_by_path = {str(item["path"]): item for item in full_inventory}
|
|
full_inventory_by_path = {str(item["path"]): item for item in full_inventory}
|
|
|
_assert_items_unchanged(collection.items, full_inventory_by_path)
|
|
_assert_items_unchanged(collection.items, full_inventory_by_path)
|
|
@@ -2244,7 +2589,7 @@ def create_analysis_package(
|
|
|
"status": collection.status,
|
|
"status": collection.status,
|
|
|
"mode": "package",
|
|
"mode": "package",
|
|
|
"profile": profile,
|
|
"profile": profile,
|
|
|
- "delivery_policy": "code-only" if profile == "code-only" else "inclusion-first",
|
|
|
|
|
|
|
+ "delivery_policy": handoff.delivery_policy_for_profile(profile),
|
|
|
"run_id": run_id,
|
|
"run_id": run_id,
|
|
|
"output_dir": str(final_dir),
|
|
"output_dir": str(final_dir),
|
|
|
"volumes": volume_infos,
|
|
"volumes": volume_infos,
|
|
@@ -2255,6 +2600,7 @@ def create_analysis_package(
|
|
|
"excluded_entry_count": len(package_excluded),
|
|
"excluded_entry_count": len(package_excluded),
|
|
|
"content_dedup_groups": len(content_dedup),
|
|
"content_dedup_groups": len(content_dedup),
|
|
|
"derived_evidence_count": len(derived_evidence),
|
|
"derived_evidence_count": len(derived_evidence),
|
|
|
|
|
+ "member_count": member_count,
|
|
|
"warning_count": len(collection.warnings),
|
|
"warning_count": len(collection.warnings),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2449,13 +2795,23 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
parser.add_argument("--package-name", help="portable package directory and ZIP base name")
|
|
parser.add_argument("--package-name", help="portable package directory and ZIP base name")
|
|
|
parser.add_argument("--force-overwrite", action="store_true", help="atomically replace an existing package directory")
|
|
parser.add_argument("--force-overwrite", action="store_true", help="atomically replace an existing package directory")
|
|
|
parser.add_argument("--no-git-bundle", action="store_true", help="omit the git history bundle from the package")
|
|
parser.add_argument("--no-git-bundle", action="store_true", help="omit the git history bundle from the package")
|
|
|
|
|
+ parser.add_argument(
|
|
|
|
|
+ "--include-full-history",
|
|
|
|
|
+ action="store_true",
|
|
|
|
|
+ help="include a full git bundle (archive-local / explicit override; ignored as default for review-compact)",
|
|
|
|
|
+ )
|
|
|
|
|
+ parser.add_argument(
|
|
|
|
|
+ "--include-sanitized-git-snapshot",
|
|
|
|
|
+ action="store_true",
|
|
|
|
|
+ help="request sanitized synthetic git snapshot hook (P2 extension; records reserved status)",
|
|
|
|
|
+ )
|
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
|
"--profile",
|
|
"--profile",
|
|
|
choices=sorted(handoff.HANDOFF_PROFILES),
|
|
choices=sorted(handoff.HANDOFF_PROFILES),
|
|
|
- default="full",
|
|
|
|
|
|
|
+ default=handoff.DEFAULT_HANDOFF_PROFILE,
|
|
|
help=(
|
|
help=(
|
|
|
- "inclusion-first full profile packages source+reference+derived board-viewer evidence "
|
|
|
|
|
- "(core/reference split); code-only excludes reference/ and heavy SVG assets"
|
|
|
|
|
|
|
+ "review-compact (default upload: unified source/evidence/meta, no full git bundle); "
|
|
|
|
|
+ "review-debug; archive-local; legacy full (core/reference split) / code-only"
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
@@ -2500,14 +2856,24 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
seven_zip = find_7z()
|
|
seven_zip = find_7z()
|
|
|
_validate_package_name(package_name)
|
|
_validate_package_name(package_name)
|
|
|
output_root = _validate_output_root(args.output_dir, repo_root=source_root, config=config)
|
|
output_root = _validate_output_root(args.output_dir, repo_root=source_root, config=config)
|
|
|
|
|
+ if args.profile == "archive-local":
|
|
|
|
|
+ include_git_bundle = not args.no_git_bundle or args.include_full_history
|
|
|
|
|
+ if args.include_full_history:
|
|
|
|
|
+ include_git_bundle = True
|
|
|
|
|
+ elif args.profile in {"review-compact", "review-debug"}:
|
|
|
|
|
+ include_git_bundle = False
|
|
|
|
|
+ else:
|
|
|
|
|
+ include_git_bundle = not args.no_git_bundle
|
|
|
with tempfile.TemporaryDirectory(prefix="ca-") as temporary:
|
|
with tempfile.TemporaryDirectory(prefix="ca-") as temporary:
|
|
|
temp_root = Path(temporary)
|
|
temp_root = Path(temporary)
|
|
|
collection = collect_analysis_inputs(
|
|
collection = collect_analysis_inputs(
|
|
|
repo_root=source_root,
|
|
repo_root=source_root,
|
|
|
config=config,
|
|
config=config,
|
|
|
temp_root=temp_root / "inputs",
|
|
temp_root=temp_root / "inputs",
|
|
|
- include_git_bundle=not args.no_git_bundle,
|
|
|
|
|
|
|
+ include_git_bundle=include_git_bundle,
|
|
|
profile=args.profile,
|
|
profile=args.profile,
|
|
|
|
|
+ include_sanitized_git_snapshot=args.include_sanitized_git_snapshot,
|
|
|
|
|
+ package_name=package_name,
|
|
|
)
|
|
)
|
|
|
preparation = prepare_unsupported_archives(
|
|
preparation = prepare_unsupported_archives(
|
|
|
collection.items,
|
|
collection.items,
|
|
@@ -2519,7 +2885,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
if args.audit_only:
|
|
if args.audit_only:
|
|
|
payload = audit_analysis_collection(prepared_collection)
|
|
payload = audit_analysis_collection(prepared_collection)
|
|
|
payload["profile"] = args.profile
|
|
payload["profile"] = args.profile
|
|
|
- elif args.profile == "code-only":
|
|
|
|
|
|
|
+ payload["delivery_policy"] = handoff.delivery_policy_for_profile(args.profile)
|
|
|
|
|
+ elif handoff.uses_unified_layout(args.profile) or args.profile == "code-only":
|
|
|
if not prepared_collection.items:
|
|
if not prepared_collection.items:
|
|
|
raise PackagingError("analysis package has no included files")
|
|
raise PackagingError("analysis package has no included files")
|
|
|
payload = create_analysis_package(
|
|
payload = create_analysis_package(
|
|
@@ -2537,7 +2904,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
)
|
|
)
|
|
|
if not core_collection.items and not reference_collection.items:
|
|
if not core_collection.items and not reference_collection.items:
|
|
|
raise PackagingError("analysis package has no included files")
|
|
raise PackagingError("analysis package has no included files")
|
|
|
- payload: dict[str, object] = {}
|
|
|
|
|
|
|
+ payload = {}
|
|
|
if core_collection.items:
|
|
if core_collection.items:
|
|
|
payload["core"] = create_analysis_package(
|
|
payload["core"] = create_analysis_package(
|
|
|
collection=core_collection,
|
|
collection=core_collection,
|