File size: 2,440 Bytes
89bab68
7717949
89bab68
 
 
 
7717949
 
89bab68
 
 
 
 
 
7717949
89bab68
 
 
 
 
 
7717949
89bab68
7717949
6297b0e
7717949
 
 
 
f7c2b23
89bab68
7717949
89bab68
 
 
7717949
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89bab68
 
7717949
 
 
89bab68
7717949
 
45c8940
7717949
89bab68
7717949
89bab68
7717949
 
 
 
f7c2b23
89bab68
 
 
7717949
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
import gradio as gr

from phases.phase1_ingest import ingest
from phases.phase2_rules import load_rules
from phases.phase3_static import static_scan
from phases.phase4_runtime import runtime_risks
from ci_guard import run_ci


with gr.Blocks(title="SpecGuard AI Lab", theme=gr.themes.Soft()) as app:

    gr.Markdown("## 🧠 SpecGuard AI Lab")
    gr.Markdown("Rulebook ↔ Code Deep Research & Verification System")

    # ── Sidebar ─────────────────────────────────────────
    with gr.Sidebar():
        rulebook_input = gr.Textbox(
            label="πŸ“˜ Rulebook (paste)",
            lines=12,
            placeholder="Paste specification or rulebook text here"
        )

        code_zip = gr.File(label="πŸ“¦ Source Code (ZIP)")

        ci_mode = gr.Checkbox(
            label="πŸ§ͺ CI Mode (Fail on CRITICAL)",
            value=False
        )

        run_btn = gr.Button("πŸš€ Start Deep Research", variant="primary")

    # ── Outputs ─────────────────────────────────────────
    status = gr.Markdown()
    output = gr.Markdown()

    # ── Core runner ─────────────────────────────────────
    def run_all(rulebook, zipfile, ci):
        ingest(rulebook, zipfile)

        rules = load_rules()
        findings = static_scan(rules)
        risks = runtime_risks()

        # CI enforcement
        if ci:
            try:
                run_ci()
            except SystemExit:
                return (
                    "❌ CI FAILED",
                    "Critical rule violation detected. Fix CRITICAL issues to proceed."
                )

        # Build report (THIS is where f-strings belong)
        report = f"""
### βœ… Research Complete

- **Rules Loaded:** {len(rules.get("rules", []))}
- **Static Findings:** {len(findings)}
- **Runtime Risks Identified:** {len(risks)}

πŸ“ Artifacts saved in `/artifacts/`
"""

        return "βœ… Done", report

    # ── Button binding ──────────────────────────────────
    run_btn.click(
        run_all,
        inputs=[rulebook_input, code_zip, ci_mode],
        outputs=[status, output]
    )


if __name__ == "__main__":
    app.launch()