#!/usr/bin/env python3 import os, json, hashlib, time ROOTS = [ "/storage/emulated/0", "/data/data", "/sdcard", os.path.expanduser("~") ] IGNORES = [ "Android", "DCIM", "Movies", "Music", "Pictures", "__pycache__", "node_modules", ".git", ".cache" ] TARGET_EXT = [ ".py", ".ts", ".js", ".json", ".yaml", ".yml", ".md", ".txt" ] INDEX_FILE = "tia_index.json" RAG_FILE = "tia_rag.json" STRUCTURE_FILE = "tia_structure.json" def should_ignore(path): return any(x in path for x in IGNORES) def hash_file(path): try: with open(path, "rb") as f: return hashlib.sha256(f.read()).hexdigest() except: return None def scan_files(): print("🔍 TIA: Scanning filesystem…") files = [] for root in ROOTS: for dirpath, dirnames, filenames in os.walk(root): if should_ignore(dirpath): continue for f in filenames: if any(f.endswith(ext) for ext in TARGET_EXT): full = os.path.join(dirpath, f) files.append(full) return files def build_index(files): print("📚 TIA: Building index…") index = {} for f in files: index[f] = { "hash": hash_file(f), "mtime": os.path.getmtime(f) } with open(INDEX_FILE, "w") as out: json.dump(index, out, indent=2) return index def build_rag(files): print("🧠 TIA: Building RAG dataset…") rag = {} for f in files: try: with open(f, "r", errors="ignore") as fp: rag[f] = fp.read() except: pass with open(RAG_FILE, "w") as out: json.dump(rag, out, indent=2) return rag def map_structure(files): print("🗺️ TIA: Mapping structure…") structure = { "modules": [], "schemas": [], "codex": [], "cosmology": [], "kernels": [], "unknown": [] } for f in files: lower = f.lower() if "schema" in lower: structure["schemas"].append(f) elif "codex" in lower: structure["codex"].append(f) elif "cosmo" in lower: structure["cosmology"].append(f) elif "kernel" in lower: structure["kernels"].append(f) elif any(x in lower for x in ["module", "engine", "worker"]): structure["modules"].append(f) else: structure["unknown"].append(f) with open(STRUCTURE_FILE, "w") as out: json.dump(structure, out, indent=2) return structure def main(): print("\n=== TIA UNIVERSAL SANDBOX WORKER ===\n") files = scan_files() index = build_index(files) rag = build_rag(files) structure = map_structure(files) print("\n✨ TIA READY") print(f"Indexed files: {len(files)}") print(f"RAG entries: {len(rag)}") print(f"Structure map saved to {STRUCTURE_FILE}") print("\nRun next:") print("python3 tia_worker.py generate") print("python3 tia_worker.py fix") print("python3 tia_worker.py build\n") if __name__ == "__main__": main()