File size: 2,537 Bytes
53d5811
 
 
 
 
 
 
 
ac88c70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys, os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
UTILS_DIR = os.path.join(BASE_DIR, "utils")

if UTILS_DIR not in sys.path:
    sys.path.insert(0, UTILS_DIR)

import streamlit as st
import sys, os, hashlib

# ─── Ensure utils/ is importable ──────────────────────────────
UTILS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if UTILS_PATH not in sys.path:
    sys.path.append(UTILS_PATH)

from utils.docgen import generate_doc
from utils.summarizer import summarize_text

st.title("📂 Local Script Ingestion")
st.write("Automatically scan and document Omniscient scripts from `/opt/omniscient`.")

# Init state
if "local_scripts" not in st.session_state:
    st.session_state.local_scripts = []

# Directories to scan
SCAN_DIRS = [
    "/opt/omniscient/bin",
    "/opt/omniscient/scripts",
    "/opt/omniscient/ai"
]

def scan_scripts():
    scripts = []
    for d in SCAN_DIRS:
        if os.path.exists(d):
            for root, _, files in os.walk(d):
                for f in files:
                    if f.endswith((".sh", ".py")):
                        path = os.path.join(root, f)
                        try:
                            with open(path, "r", errors="ignore") as fh:
                                content = fh.read()
                            sha1 = hashlib.sha1(content.encode()).hexdigest()
                            doc = generate_doc(f, path, content)
                            summary = summarize_text(content)

                            scripts.append({
                                "name": f,
                                "path": path,
                                "sha1": sha1,
                                "doc": doc,
                                "summary": summary
                            })
                        except Exception as e:
                            st.error(f"⚠️ Error reading {f}: {e}")
    return scripts

# Run scanner
if st.button("🔍 Scan Local Scripts"):
    scripts = scan_scripts()
    if scripts:
        st.session_state.local_scripts = scripts
        st.success(f"✅ Found {len(scripts)} scripts.")
    else:
        st.warning("No scripts found in scan directories.")

# Display results
if st.session_state.local_scripts:
    for s in st.session_state.local_scripts:
        st.subheader(f"📄 {s['name']} ({s['sha1'][:8]})")
        st.markdown(s["doc"])
        st.write("🧠 Summary:", s["summary"])