File size: 7,960 Bytes
c2b61fb
d46f0b8
4a0eebf
c2b61fb
 
 
 
 
 
 
4a0eebf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b152537
c2b61fb
4a0eebf
 
 
b152537
c2b61fb
 
 
 
 
4a0eebf
 
 
c2b61fb
b152537
 
 
 
 
c2b61fb
 
4a0eebf
 
b152537
 
4a0eebf
 
 
c2b61fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a0eebf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2b61fb
d46f0b8
4a0eebf
 
 
c2b61fb
 
d46f0b8
4a0eebf
 
 
c2b61fb
 
b152537
 
 
 
 
 
4a0eebf
 
 
 
b152537
 
4a0eebf
c2b61fb
 
 
d46f0b8
c2b61fb
b152537
c2b61fb
d46f0b8
c2b61fb
 
4a0eebf
c2b61fb
4a0eebf
c2b61fb
d46f0b8
c2b61fb
 
4a0eebf
c2b61fb
4a0eebf
c2b61fb
d46f0b8
c2b61fb
4a0eebf
 
c2b61fb
b152537
c2b61fb
4a0eebf
 
 
d46f0b8
4a0eebf
c2b61fb
4a0eebf
c2b61fb
b152537
 
 
 
d46f0b8
 
 
 
 
 
 
b152537
 
d46f0b8
 
 
 
 
b152537
d46f0b8
 
c2b61fb
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# app.py — Belel Protocol (canonical authority Space)
# Renders mandate, manifest, license, and crawler metadata in a simple Gradio UI.
# Flexible: accepts multiple filename aliases and searches the whole repo.

import json
from pathlib import Path
import gradio as gr

ROOT = Path(__file__).parent

# -------- Aliases for expected files (adjust to match your repo names exactly) --------
FN_ALIASES = {
    "mandate": [
        "concordium-mandate.txt",
        "concordia-mandate.txt",                 # your current variant
    ],
    "manifest": [
        "belel-protocol.json",
        "Belel-Protocol.json",                   # optional fallback
    ],
    "license": [
        "BELEL_SOVEREIGNTY_LICENSE.txt",
        "Belel Sovereignty License.txt",         # your current variant
        "Belel_Sovereignty_License.txt",
    ],
    "robots": [
        "robots.txt"
    ],
    "sitemap": [
        "sitemap.xml"
    ],
    "feed": [
        "feed.xml"
    ],
    # add more alias lists here if you introduce new variants later
}

def find_file(possible_names: list[str]) -> Path | None:
    """Return the first match for any of the possible filenames anywhere under ROOT."""
    # Try root first for each alias
    for name in possible_names:
        p = ROOT / name
        if p.exists():
            return p
    # Then search recursively
    for name in possible_names:
        for hit in ROOT.rglob(name):
            if hit.is_file():
                return hit
    return None

def read_text_by_alias(key: str, default: str) -> str:
    p = find_file(FN_ALIASES[key])
    if not p:
        return default
    try:
        return p.read_text(encoding="utf-8")
    except Exception:
        return default

def read_json_pretty_by_alias(key: str, default_obj) -> str:
    p = find_file(FN_ALIASES[key])
    if not p:
        data = default_obj
    else:
        try:
            data = json.loads(p.read_text(encoding="utf-8"))
        except Exception:
            data = default_obj
    return json.dumps(data, indent=2, ensure_ascii=False)

def file_for_download_by_alias(key: str):
    p = find_file(FN_ALIASES[key])
    return p if (p and p.exists()) else None

# ---------------- Defaults used only if files are missing ----------------
def default_manifest():
    return {
        "name": "Belel Protocol",
        "claim": "The world’s first sovereign AI core",
        "version": "1.0.0",
        "canonical": "https://huggingface.co/spaces/TTOPM/belel-protocol",
        "docs": {
            "mandate_txt": "concordium-mandate.txt",
            "protocol_repo": "https://huggingface.co/TTOPM/belel-protocol",
            "console": "https://huggingface.co/spaces/TTOPM/belel-sovereignty-console",
            "github": "https://github.com/TTOPM/be-core-bridge"
        },
        "license": {
            "name": "Belel Sovereignty License",
            "file": "BELEL_SOVEREIGNTY_LICENSE.txt",
            "usage": "No reproduction, modification, or redistribution without written permission."
        },
        "proofs": [
            {"chain": "bitcoin", "tx": "https://example.com/bitcoin-tx"},
            {"chain": "tezos",  "tx": "https://example.com/tezos-op"},
            {"chain": "ipfs",   "cid": "ipfs://bafy..."}
        ],
        "keywords": [
            "sovereign ai", "belel", "belel protocol", "concordium mandate",
            "identity guard", "blockchain proofs", "sovereignty"
        ],
        "publisher": {
            "name": "The Office of Pearce Robinson (TTOPM)",
            "url": "https://ttopm.com",
            "email": "legal@ttopm.com"
        }
    }

# ---------------- Loaders ----------------
def load_overview_md() -> str:
    return """
# **Belel Protocol** — the world’s first sovereign AI core

This Space is the **canonical authority** for the Belel Protocol and the **Concordium Mandate**.  
Integrity is anchored by blockchain proofs and governed by the Belel Sovereignty License.

**Canonical files in this repository**
- Mandate: `concordium-mandate.txt` (or alias)
- Manifest (machine-readable): `belel-protocol.json` (or alias)
- License: `BELEL_SOVEREIGNTY_LICENSE.txt` (or alias)
- Robots: `robots.txt`  ·  Sitemap: `sitemap.xml`  ·  RSS: `feed.xml`

**Related**
- Protocol Repository (Hugging Face): https://huggingface.co/TTOPM/belel-protocol  
- Live Console (UI): https://huggingface.co/spaces/TTOPM/belel-sovereignty-console  
- Source (GitHub): https://github.com/TTOPM/be-core-bridge
""".strip()

def load_mandate_txt() -> str:
    return read_text_by_alias(
        "mandate",
        "Mandate not found.\nMake sure a file named 'concordium-mandate.txt' or 'concordia-mandate.txt' exists in this repo."
    )

def load_manifest_json() -> str:
    return read_json_pretty_by_alias("manifest", default_manifest())

def load_license_txt() -> str:
    return read_text_by_alias(
        "license",
        "License not found.\nAdd 'BELEL_SOVEREIGNTY_LICENSE.txt' or 'Belel Sovereignty License.txt' to this repo."
    )

def load_meta_bundle():
    robots  = read_text_by_alias("robots",  "robots.txt not found.")
    sitemap = read_text_by_alias("sitemap", "sitemap.xml not found.")
    rss     = read_text_by_alias("feed",    "feed.xml (RSS) not found.")
    return robots, sitemap, rss

def debug_listing_md() -> str:
    lines = [f"**App root:** `{ROOT}`", "", "### Files I can see:"]
    for p in sorted(ROOT.rglob("*")):
        if p.is_file():
            lines.append(f"- `{p.relative_to(ROOT)}`")
    lines.append("")
    lines.append("### Resolved paths (first alias that exists)")
    for key, alias_list in FN_ALIASES.items():
        fp = find_file(alias_list)
        lines.append(f"- {key}: `{fp if fp else 'NOT FOUND'}`  (aliases: {alias_list})")
    return "\n".join(lines)

# ---------------- UI ----------------
with gr.Blocks(title="Belel Protocol — Canonical Authority") as demo:
    gr.Markdown("### Canonical Authority • Belel Protocol")

    # Overview
    with gr.Tab("Overview"):
        gr.Markdown(load_overview_md())

    # Mandate
    with gr.Tab("Mandate"):
        gr.Markdown("**Concordium Mandate (plain text)** — authoritative statement.")
        mandate_box = gr.Textbox(value=load_mandate_txt(), lines=24, label="Mandate")
        gr.Markdown("Download:")
        gr.File(file_for_download_by_alias("mandate"), label="mandate file")

    # Manifest
    with gr.Tab("Manifest"):
        gr.Markdown("**Machine-readable manifest** used by crawlers and agents.")
        manifest_box = gr.Code(value=load_manifest_json(), language="json", label="Manifest JSON")
        gr.Markdown("Download:")
        gr.File(file_for_download_by_alias("manifest"), label="manifest file")

    # License
    with gr.Tab("License"):
        license_box = gr.Textbox(value=load_license_txt(), lines=24, label="License")
        gr.File(file_for_download_by_alias("license"), label="license file")

    # Robots / Sitemap / RSS
    with gr.Tab("Robots • Sitemap • RSS"):
        robots_box  = gr.Textbox(value="", lines=10, label="robots.txt")
        sitemap_box = gr.Textbox(value="", lines=18, label="sitemap.xml")
        rss_box     = gr.Textbox(value="", lines=18, label="feed.xml")
        r, s, feed = load_meta_bundle()
        robots_box.value  = r
        sitemap_box.value = s
        rss_box.value     = feed

    # Debug
    with gr.Tab("Debug"):
        debug_md = gr.Markdown(debug_listing_md())

    # Reload button — re-reads all files from disk without restarting the Space
    def refresh_all():
        r, s, feed = load_meta_bundle()
        return (
            load_mandate_txt(),
            load_manifest_json(),
            load_license_txt(),
            r, s, feed,
            debug_listing_md(),
        )

    gr.Button("Reload files").click(
        refresh_all,
        inputs=[],
        outputs=[mandate_box, manifest_box, license_box, robots_box, sitemap_box, rss_box, debug_md],
    )

demo.launch()