14 KiB
14 KiB
Plan: Lightweight Local Server-Side Web Chatbot GUI (/chat/ & Dockable Widget) Powered by hyperstition-mcp.service & SQLite FTS5 at Zero (0) LLM Token Cost (v2.2.0)
- Document ID:
PLAN-LOCAL-SERVER-SIDE-WEB-CHATBOT-GUI(v2.2.0) - Roadmap Status: ACTIVE / READY
- Core Architectural & Resource Mandates:
- 100% Local on the Web Host (
0LLM Tokens,0External API Keys,0GPU RAM): Runs entirely inside the existinghyperstition-mcp.servicePython daemon (127.0.0.1:8095) using a deterministic Hybrid Intent Router + SQLite FTS5 BM25 Full-Text Retriever + 15-Tool MCP Orchestrator (src/hyperstitionstud_io/mcp/chatbot.py). Consumes0metered LLM tokens,0external API keys,< 15 msCPU time per query, and< 5 MBRSS memory. - Chatbot REST API Exclusivity (
0New Bespoke REST Routes inrest.py): Exposes the server-side question-answering engine by registeringhs_ask_chatbotinMCP_TOOLS_SCHEMA(src/hyperstitionstud_io/mcp/tools.py). The existing generic tool dispatcher insrc/hyperstitionstud_io/mcp/rest.pyautomatically serves it atGET/POST /api/v1/tools/hs_ask_chatbot(and via MCP JSON-RPCtools/callon/mcp) with0new custom route patterns inrest.py. - Strict Zero-Synthetic-Data &
ProtectSystem=strict(EROFS) Compliance: Every answer is synthesized deterministically from verified server-side registries (glossary-registry.json,encyclopedia-graph.json,quant-timeseries.json,real-macro-indicators.json,daily-brief-latest.json,hyperstition-meta.dbFTS5, and72archive dossiers). Missing/private/holiday fields report"No data available"(null), andhs_ask_chatbotis automatically swept under simulatedProtectSystem=strict(EROFS) bysrc/hyperstitionstud_io/ci/erofs_harness.py. - Two-Script Deployment Invariant Preserved:
All assets, symlinks (
/chat), and tests are wired into/workspace/push-all-to-git-libre-audio.shand/workspace/hyperstitionstudio-core/deploy/sync-vps-repos.shso deployment requires no additional manual operator steps.
- 100% Local on the Web Host (
- Target Modules & Web Surfaces:
/workspace/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/chatbot.py(answer_chatbot_query()8-intent router + SQLite FTS5 BM25 retriever + multi-tool orchestrator)/workspace/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/tools.py(Registershs_ask_chatbotinMCP_TOOLS_SCHEMA)/workspace/hyperstitionstudio-core/site/assets/hs-chatbot-widget.js(Lightweight< 16 KBdockable Group 3 Stealth Basalt chatbot drawer injected across/,/quant/,/learn/,/engineering/*, and/math/*)/workspace/hyperstitionstudio-core/site/chat/index.html(Full-screen split-pane/chat/Corpus & Telemetry Query Workbench with live JSON/CIDv1 & Stats-Card inspector)/workspace/hyperstitionstudio-core/site/assets/hs-group3-basalt-chamfer.css(Group 3 Stealth Basalt styling for#hsChatbotToggleBtn,#hsChatbotDrawer, and/chat/)/workspace/hyperstitionstudio-core/deploy/{sync-vps-repos.sh,test-first-deployment.sh}&/workspace/hyperstitionstudio-core/tests/test_core_suite.py
1. Local Server-Side Question-Answering Architecture (src/hyperstitionstud_io/mcp/chatbot.py)
When the browser sends a user question q to POST /api/v1/tools/hs_ask_chatbot (or GET /api/v1/tools/hs_ask_chatbot?query=...), answer_chatbot_query(query, page_context, lens, include_card) executes a deterministic 3-stage pipeline in < 15 ms:
[User Question q in Browser]
│
▼ POST /api/v1/tools/hs_ask_chatbot (Caddy -> 127.0.0.1:8095 hyperstition-mcp.service)
┌───────────────────────────────────────────────────────────────────────────────────────────────┐
│ Stage 1: Deterministic Intent & Entity Extractor (Regex + Watchlist/Glossary/Coord Matcher) │
│ Extracts: ticker symbols (NVDA..ANTHR-PVT), AQ integers (1..999), FRED slugs (CPI..INDPRO), │
│ quoted phrases ("..."), and intent keywords (price, dose, card, macro, brief, define, aq). │
└───────────────────────────────────────────────┬───────────────────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────────────────────────────────────────┐
│ Stage 2: Server-Side Tool & SQLite FTS5 Orchestration (100% Read-Only under EROFS) │
│ • Intent 1 (Ticker / Price / Dose / Stats Card) -> hs_inspect_quant_timeseries + cards.py │
│ • Intent 2 (Macro / Rates / CPI / M2 / GDP / Brief) -> hs_inspect_macro_indicators + brief │
│ • Intent 3 (Calculate AQ / Ingglish / Prime / Mod-9) -> hs_evaluate_aq_and_ingglish │
│ • Intent 4 (Define Term / S1-S6 / M1-M7 / G1-G6 / ETI) -> hs_search_glossary_encyclopedia │
│ • Intent 5 (Graph Node / Hub / Coordinate aq:N) -> hs_query_knowledge_graph │
│ • Intent 6 (333/666/777 Equations / News Dossier) -> hs_search_archive_equations │
│ • Intent 7 (Guile Scheme / Z-Combinator / Novice Track) -> guile_prelude + /learn/ ladder │
│ • Intent 8 (Open-Ended Question Fallback) -> SQLite FTS5 BM25 search across catalog tables │
└───────────────────────────────────────────────┬───────────────────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────────────────────────────────────────┐
│ Stage 3: Grounded Response Composer (Zero Hallucination, Full Citation & CIDv1 Provenance) │
│ Returns: { answer_markdown, summary_bullets, detected_intent, invoked_tools, │
│ citations: [{label, url}], stats_card_preview, data_available, ipld_cidv1 } │
└───────────────────────────────────────────────────────────────────────────────────────────────┘
1.1 Detailed Behavior of the 8 Server-Side Intent Handlers
| Intent ID | Example User Questions Answered Locally | Server-Side Data Sources Queried | Structured Output Returned to GUI |
|---|---|---|---|
1. ticker_and_card |
• "What is NVDA's latest price and Confluence Dose?" • "Show me the stats card for SOL-USD" • "What is ANTHR-PVT's price?" |
site/quant/quant-timeseries.json + quant/cards.py (35 ms fast-path) |
• Real close ($135.40), change_bps, Vol20d, Dose 0..3+ taxon label, 6 TierZoo base stats, optional inline 900×1260 PNG card preview, and deep links to /quant/ & /graph/.• For ANTHR-PVT: "No market data available (private entity — 0 synthetic bars)." |
2. macro_and_regime_brief |
• "What are the current Fed rates and M2 spread?" • "What is today's Bayesian market regime and key question?" • "What is the latest CPI and PPI?" |
site/quant/real-macro-indicators.json + site/quant/daily-brief-latest.json |
• Live 3-state Bayesian posteriors (R1, R2, R3), active Daily Key Macro Question Q_t, and exact FRED series values (EFFR = 388 bps, SOFR = 398 bps, M2-M1 = $3.37T, GDP, CPI, PPI) with native cadence metadata. |
3. aq_and_ingglish_eval |
• "What is the AQ and Ingglish of 'abstract machine'?" • "Evaluate 'hyperstition'" |
ciphers/aq.py + phonetics/__init__.py (4,943 offline CMUdict + fallback rules) + encyclopedia-graph.json |
• Gen 0 (eng_aq), Gen 1 (ing_aq + Ingglish spelling), phonemic drift \Delta, prime rank \pi(n), mod-9 digital root, and any matching specimens at that AQ coordinate. |
4. glossary_and_zoology |
• "What is Vector G1?" • "Explain The Room Filter" • "What are the S+ Apex builds in the ETI tier list?" |
taxonomy/glossary-registry.json (282 terms, 190 bilingual specimens) + assemblage-builds-tier-list.json |
• Concise definition, ontological division (Div 00–08), verbatim grounded quote, ETI score, and clickable #page=N&search=... deep-link to /zoology/technocapital-singularity-zoology-comprehensive-glossary.pdf. |
5. knowledge_graph_hub |
• "What connects to coordinate 292 or 666?" • "Inspect node aq:333" |
encyclopedia-graph.json (388 nodes, 1,282 edges) |
• Node type, degree centrality, incident G1–G5 edges, guild membership, and [ Open in /graph/?select=aq:N ] deep-link. |
6. archive_equations_and_news |
• "Show me archive equations that equal 333 or 666" • "What is in the latest news dossier?" |
ingglish-aq-archive/01..72-*.md |
• Matching verified Gen 1 [Ingglish] = 333/666/777 equations with dossier numbers and /api/v1/dossiers/{N}?highlight=... links. |
7. guile_scheme_and_curriculum |
• "How does the Z combinator work in Guile Scheme?" • "Where should a novice start?" |
publishing/guile_prelude.scm + engineering-manifest.json + math-manifest.json |
• Explains the Z combinator (z-calculus-scheme) or Novice Prerequisite Ladder, with links to /learn/, /math/, and /engineering/. |
8. sqlite_fts5_fallback |
• Any free-form question across the 6 repositories | .cache/hyperstition-meta.db (sqlite_meta.py FTS5 tables + JSON fallback) |
• Top-ranked corpus matches with verbatim snippets and deep links (or explicit "No matching corpus record found" with 0 hallucination). |
2. Lightweight Group 3 Stealth Basalt Web Chatbot GUI (site/assets/hs-chatbot-widget.js & /chat/index.html)
2.1 Floating Dockable Widget Across All Primary Pages (site/assets/hs-chatbot-widget.js)
- Header & Bottom-Left Launcher (
#hsChatbotToggleBtn):- Styled in Group 3 Stealth Basalt (
10px/4px45°chamfers,34pxheight,#38bdf8interactive border/pip, keyboard shortcutAlt+K). - Does not eclipse or clutter any page: remains a single compact pill (
[ ◈ ASK CORPUS ]) until clicked.
- Styled in Group 3 Stealth Basalt (
- Interactive Drawer (
#hsChatbotDrawer,420 × 540 px):- Context-Aware Quick-Prompt Chips: Displays 5 one-click starter questions tailored to the current page (
/,/quant/,/learn/,/engineering/*,/math/*). - Instant Local Execution Badge: Shows
0 LLM Tokens • Local Server-Side Engine (<15 ms) • CIDv1 Verifiedin the drawer header. - Rich Answer Cards:
- Formatted answer text + bulleted key metrics,
- Clickable deep-link pills (
Open in /quant/,Open in /graph/,Glossary PDF #page=N), - Inline
900×1260.pngStats Card preview whenever a ticker card is queried, - Collapsible
<details>block showing the exact/api/v1/tools/hs_ask_chatbotJSON payload and IPLDCIDv1receipt.
- Context-Aware Quick-Prompt Chips: Displays 5 one-click starter questions tailored to the current page (
2.2 Dedicated Full-Screen /chat/ Workbench (site/chat/index.html)
- Accessible at
/chat/index.html(with a navigation button added tosite/index.htmland the widget header[ Expand Full /chat/ Workbench ↗ ]). - Provides a 2-column Group 3 Stealth Basalt layout:
- Left Column (
60%): Full conversational Q&A history, categorized prompt library across all 8 intents (Watchlist Tickers, FRED Macro & Bayesian Brief, Base-36 & Ingglish Calculator, Glossary & Zoology, Knowledge Graph Hubs, 333/666/777 Archive Equations, Guile Scheme & Z-Calculus, and Novice Onboarding), and exportable.jsontranscript button. - Right Column (
40%): Live Server-Side Telemetry & Provenance Inspector displaying the triggered MCP tool chain, raw JSON response, IPLDdag-jsonCIDv1hash, and any rendered900×1260Ticker Stats Card PNG.
- Left Column (
3. Test-Suite & Deployment Integration (tests/test_core_suite.py, erofs_harness.py, sync-vps-repos.sh)
src/hyperstitionstud_io/ci/erofs_harness.py:- Because
hs_ask_chatbotis registered inMCP_TOOLS_SCHEMA(bringing the total MCP tool count from15to16),run_introspective_erofs_suite()automatically sweepshs_ask_chatbotunder simulatedProtectSystem=strict(EROFS) with zero extra harness code!
- Because
tests/test_core_suite.py:- Test
hs_ask_chatbotacross all 8 intent families viadispatch_rest_v1("GET", "/api/v1/tools/hs_ask_chatbot?query=...")andPOST /api/v1/tools/hs_ask_chatbot:- Verify
NVDAticker query returns real close$135.40anddata_available: True, - Verify
ANTHR-PVTquery returnsdata_available: Falseand"No data available"(0synthetic data), - Verify FRED macro & Bayesian brief query returns
EFFR = 388 bpsand valid posterior simplex sum== 1.0, - Verify AQ/Ingglish query on
"schizoanalysis"returnseng_aq = 264,ing_aq = 292, - Verify glossary query on
"Vector G1"returns a valid/zoology/technocapital-singularity-zoology-comprehensive-glossary.pdf#page=deep-link.
- Verify
- Verify
0new bespoke routes were added torest.py(all chatbot queries flow through/api/v1/tools/hs_ask_chatbotand/mcp).
- Test
deploy/sync-vps-repos.sh&deploy/test-first-deployment.sh:- Add
${LIVE_SUDO} ln -sfn "hyperstitionstudio-core/site/chat" "${LIVE_REPOS}/chat"to Step[3/5]ofdeploy/sync-vps-repos.sh. - Add
/chat/index.htmland/assets/hs-chatbot-widget.jstoROUTES=()indeploy/test-first-deployment.shandhs-public-smokeGateP1/P6.
- Add