#!/usr/bin/env python3 import sys import os import json import argparse from pathlib import Path # Ensure modernization_scout directory is in sys.path to import scout helpers SCOUT_DIR = os.path.expanduser("/Users/dave/warezfactory/config/sidecar_tools/modernization_scout") if SCOUT_DIR not in sys.path: sys.path.insert(0, SCOUT_DIR) from scout import FACTORY_HOME, REGISTRY_PATH, find_owning_agent, parse_build_settings def main(): parser = argparse.ArgumentParser(description="Fleet Xcode Status Audit Script") parser.add_argument("--scope", choices=["active_apps", "all_registered"], default="active_apps", help="Audit scope: active_apps or all_registered") args = parser.parse_args() if not os.path.exists(REGISTRY_PATH): print(f"❌ Error: Registry not found at {REGISTRY_PATH}") sys.exit(1) with open(REGISTRY_PATH, 'r', encoding='utf-8') as f: registry = json.load(f) projects = registry.get("projects", {}) agents = registry.get("agents", {}) # Determine visible agent project IDs and workspace UUIDs visible_project_ids = set() visible_workspace_uuids = set() for _, agent in agents.items(): if agent.get("isVisible", False): for pid in agent.get("projects", {}).keys(): visible_project_ids.add(pid) proj = projects.get(pid, {}) if proj.get("workspace_uuid"): visible_workspace_uuids.add(proj.get("workspace_uuid")) # Gather matching projects candidate_projects = [] for pid, proj in projects.items(): p_type = proj.get("type", "unknown") owner = find_owning_agent(registry, pid, proj.get("workspace_uuid")) is_visible_owner = bool(owner) if args.scope == "active_apps": # Include projects where type == "app" and the project has a visible owner # (or lives inside a workspace shared with a visible agent's app, excluding type == "framework") if p_type == "app" and (is_visible_owner or pid in visible_project_ids or proj.get("workspace_uuid") in visible_workspace_uuids): candidate_projects.append((pid, proj, owner)) else: # all_registered: include all registered projects where type is "app", "framework", or "xcode" if p_type in ("app", "framework", "xcode"): candidate_projects.append((pid, proj, owner)) # Deduplicate projects by normalized path (preferring the entry that has a visible owner) path_map = {} for pid, proj, owner in candidate_projects: raw_path = proj.get("project_path") or proj.get("stored_project_path", "") expanded_path = os.path.normpath(raw_path.replace("$FACTORY_HOME", FACTORY_HOME)) if expanded_path not in path_map: path_map[expanded_path] = (pid, proj, owner) else: existing_pid, existing_proj, existing_owner = path_map[expanded_path] # Prefer visible owner over None/Monorepo if owner and not existing_owner: path_map[expanded_path] = (pid, proj, owner) unique_projects = list(path_map.values()) # Audit results storage results = [] counts = { "JSON": 0, "PLIST": 0, "MISSING": 0, "ALIGNED_27_2": 0, "SWIFT_5_MASKS": 0, "TOTAL": len(unique_projects) } for pid, proj, owner in unique_projects: name = proj.get("name", pid) raw_path = proj.get("project_path") or proj.get("stored_project_path", "") expanded_path = raw_path.replace("$FACTORY_HOME", FACTORY_HOME) format_str = "MISSING" deploy_str = "—" swift_str = "—" actor_str = "—" owner_str = owner if owner else ("Monorepo" if proj.get("workspace_uuid") else "—") proj_deploy_list = [] target_deploy_list = [] has_swift_5_mask = False is_27_2_aligned = False if os.path.exists(expanded_path): bs_result, _ = parse_build_settings(expanded_path) if bs_result: format_raw = bs_result.get("format", "") if "JSON" in format_raw: format_str = "JSON" counts["JSON"] += 1 else: format_str = "PLIST" counts["PLIST"] += 1 project_settings = bs_result.get("project_settings", {}) target_settings = bs_result.get("target_settings", {}) # Deployment Target p_deploy = project_settings.get("MACOSX_DEPLOYMENT_TARGET") if p_deploy: proj_deploy_list.append(p_deploy) for t_name, t_settings in target_settings.items(): t_deploy = t_settings.get("MACOSX_DEPLOYMENT_TARGET") if t_deploy: target_deploy_list.append(t_deploy) p_dep_val = p_deploy if p_deploy else (proj_deploy_list[0] if proj_deploy_list else None) t_dep_val = target_deploy_list[0] if target_deploy_list else p_dep_val if p_dep_val and t_dep_val: if p_dep_val == t_dep_val: deploy_str = p_dep_val if p_dep_val == "27.2": is_27_2_aligned = True else: deploy_str = f"P:{p_dep_val} / T:{t_dep_val}" elif p_dep_val: deploy_str = p_dep_val if p_dep_val == "27.2": is_27_2_aligned = True else: deploy_str = "—" # Check Swift Version swift_versions_found = set() s_ver_proj = project_settings.get("SWIFT_VERSION") if s_ver_proj: swift_versions_found.add(s_ver_proj) try: if float(s_ver_proj) < 6.0: has_swift_5_mask = True except: if "5." in s_ver_proj: has_swift_5_mask = True for t_name, t_settings in target_settings.items(): s_ver_t = t_settings.get("SWIFT_VERSION") if s_ver_t: swift_versions_found.add(s_ver_t) try: if float(s_ver_t) < 6.0: has_swift_5_mask = True except: if "5." in s_ver_t: has_swift_5_mask = True if has_swift_5_mask: swift_str = "⚠️ 5.0" counts["SWIFT_5_MASKS"] += 1 elif "6.0" in swift_versions_found or any("6." in v for v in swift_versions_found): swift_str = "6.0" elif bs_result.get("has_factory_consumer"): swift_str = "Swift 6 (xcconfig)" else: swift_str = "—" # Isolation if project_settings.get("SWIFT_DEFAULT_ACTOR_ISOLATION") == "MainActor" or any(ts.get("SWIFT_DEFAULT_ACTOR_ISOLATION") == "MainActor" for ts in target_settings.values()): actor_str = "MainActor" else: counts["MISSING"] += 1 else: counts["MISSING"] += 1 if is_27_2_aligned: counts["ALIGNED_27_2"] += 1 results.append({ "name": name, "format": format_str, "deploy": deploy_str, "swift": swift_str, "actor": actor_str, "owner": owner_str }) # Sort results: PLIST first (migration targets jump right off the screen), then JSON, then MISSING, then alphabetically by name results.sort(key=lambda x: (0 if x["format"] == "PLIST" else (1 if x["format"] == "JSON" else 2), x["name"])) # Print clean report print(f"=== FLEET XCODE STATUS AUDIT (Scope: {args.scope}) ===") print(f"{'PROJECT':<22} | {'FORMAT':<6} | {'DEPLOYMENT TARGET':<16} | {'SWIFT VERSION':<18} | {'ISOLATION':<10} | {'OWNER':<14}") print("-" * 95) for r in results: print(f"{r['name']:<22} | {r['format']:<6} | {r['deploy']:<16} | {r['swift']:<18} | {r['actor']:<10} | {r['owner']:<14}") print("-" * 95) print("SUMMARY FOOTER:") print(f"• Total Projects Audited: {counts['TOTAL']}") print(f"• JSON Format (project.xcproj): {counts['JSON']}") print(f"• PLIST Format (project.pbxproj): {counts['PLIST']}") print(f"• 27.2 Aligned Deployment Targets: {counts['ALIGNED_27_2']}") print(f"• Swift 5 Masks Detected: {counts['SWIFT_5_MASKS']}") if counts['MISSING'] > 0: print(f"• Missing/Unresolvable Paths: {counts['MISSING']}") print("==================================================") if __name__ == "__main__": main()