File size: 3,141 Bytes
7269ed4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/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()