File size: 5,606 Bytes
dd39fa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import List, Dict
import random

FACTS: List[Dict] = [
    {
        "id": "mindseye_overview",
        "title": "What is MindsEye?",
        "keywords": [
            "what is mindseye",
            "what is minds eye",
            "mindseye os",
            "minds eye os",
            "mindseye overview",
            "os overview",
            "system overview",
        ],
        "answer": (
            "MindsEye is a multi-surface AI operating system being built under "
            "SAGEWORKS AI. It treats data as time-labeled binary flows across "
            "devices, browsers, and cloud services.\n\n"
            "Instead of random scripts everywhere, you get:\n"
            "- A shared sense of **time** for all events\n"
            "- Ledgers that remember what agents did and why\n"
            "- Layers like LAW-N / LAW-T / Workspace / SQL / Cloud Fabric that "
            "cooperate instead of fighting each other."
        ),
    },
    {
        "id": "workspace_layer",
        "title": "Workspace Automation Layer",
        "keywords": [
            "workspace",
            "gmail",
            "docs",
            "sheets",
            "drive",
            "workspace automation",
            "google workspace",
            "apps script",
        ],
        "answer": (
            "The Workspace layer is the front-of-house for MindsEye.\n\n"
            "Gmail, Docs, Sheets, and Drive events land here first. They get:\n"
            "- Labeled with time and context\n"
            "- Routed into flows\n"
            "- Optionally logged into ledgers\n\n"
            "It’s the part that makes MindsEye feel like an assistant living "
            "inside your existing tools, not just another random bot."
        ),
    },
    {
        "id": "ledger_layer",
        "title": "MindsEye Ledger / Time-Labeled Truth",
        "keywords": [
            "ledger",
            "google ledger",
            "time labeled",
            "time-labeled",
            "tlb",
            "binary ledger",
        ],
        "answer": (
            "The ledger layer is where MindsEye becomes ruthless about time.\n\n"
            "Every event, prompt, and response becomes a **time-labeled row**. "
            "Agents can look back and see:\n"
            "- What happened\n"
            "- When it happened\n"
            "- Which node or agent acted\n\n"
            "That lets MindsEye reason over history instead of treating each prompt "
            "like amnesia mode."
        ),
    },
    {
        "id": "law_n_layer",
        "title": "LAW-N — Network-Native Layer",
        "keywords": [
            "law-n",
            "law n",
            "lawn",
            "network layer",
            "network-native",
            "api graph",
            "service graph",
        ],
        "answer": (
            "LAW-N is the network-native layer of MindsEye.\n\n"
            "Instead of hard-coding API calls everywhere, LAW-N treats services, "
            "agents, and tools as a **graph of time-aware nodes**. Each node knows:\n"
            "- What data it consumes\n"
            "- What it outputs\n"
            "- How it fits into the wider flow."
        ),
    },
    {
        "id": "roadmap",
        "title": "MindsEye Roadmap",
        "keywords": [
            "roadmap",
            "what next",
            "next steps",
            "plan",
            "how to scale",
        ],
        "answer": (
            "High-level roadmap:\n\n"
            "1. Sandbox — this Space: local chatbot + flow studio.\n"
            "2. Glue — bridge sandbox into ledgers + Workspace flows.\n"
            "3. Network — orchestrate services via LAW-N.\n"
            "4. Full Stack — OS experience across web, mobile, and cloud."
        ),
    },
]

GENERIC_FALLBACKS = [
    "I don’t have that topic wired into the sandbox brain yet. Try asking about MindsEye, the ledger, LAW-N, the roadmap, or SAGEWORKS.",
    "This version of the bot is intentionally small. If this topic matters, it probably deserves its own node or ledger later.",
]

GREETING_TRIGGERS = [
    "hi", "hello", "hey", "yo", "morning", "afternoon", "evening", "sup", "what's up", "whats up"
]


def normalize(text: str) -> str:
    return text.strip().lower()


def is_greeting(message: str) -> bool:
    msg = normalize(message)
    return any(trigger in msg for trigger in GREETING_TRIGGERS)


def greeting_reply() -> str:
    options = [
        "Yo 👋 This is the MindsEye sandbox brain. No APIs, just local logic.",
        "Hey 👋 You’re talking to the MindsEye sandbox bot — the tiny version before the 21-repo beast shows up.",
        "Hi 👋 This is the clean-slate MindsEye chatbot. Ask about MindsEye, the ledger, LAW-N, or the roadmap.",
    ]
    return random.choice(options)


def find_best_fact(user_message: str) -> str:
    msg = normalize(user_message)

    if is_greeting(msg):
        return greeting_reply()

    # Exact keyword match
    for fact in FACTS:
        for kw in fact["keywords"]:
            if kw in msg:
                return fact["answer"]

    # Soft scoring
    best_fact = None
    best_score = 0
    tokens = set(msg.split())

    for fact in FACTS:
        score = 0
        for kw in fact["keywords"]:
            for token in kw.split():
                if token in tokens:
                    score += 1
        if score > best_score:
            best_score = score
            best_fact = fact

    if best_fact and best_score > 0:
        return best_fact["answer"]

    return random.choice(GENERIC_FALLBACKS)