18 KiB
18 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.2) - Roadmap Status: DEFERRED (Long-Term Inactive — Preserved for Future Reference)
- Default UI Placement Choice: Option 2 — Dedicated
/chat/Subpage Only (site/chat/index.html) + SingleAsk Corpus (/chat/)Header Button on/(Zero Floating Widget Injection on/or Subpages) - 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 RULE-G01.COLLAPSE?" • "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. Review of Pros and Cons of Chatbot Placement on the Homepage (/) vs. Elsewhere & Default Choice (Option 2)
2.1 Baseline for Comparison Prior to Review
- In the Live Codebase (
v2.2.2): No web chatbot GUI exists on any page; the backend Chatbot OpenAPI 3.1.0 REST Adapter (/api/v1/tools/*) and MCP server (/mcpon127.0.0.1:8095) run headlessly while the homepage (/workspace/hyperstitionstudio-core/site/index.html) is a pure, static 6-Card Portal (< 18 KBHTML,0external JS state machines). - In the Initial Draft of This Plan: Originally proposed a Dual-Surface layout injecting a floating dockable widget (
site/assets/hs-chatbot-widget.js) across/,/quant/,/learn/,/engineering/*, and/math/*alongside a dedicated/chat/index.htmlworkbench.
2.2 Pros of Placing the Chatbot on the Homepage (/) Rather Than on Subpages
- Immediate "Concierge / Wayfinder" Discovery for First-Time Visitors: A visitor landing on
https://hyperstitionstud.io/encounters 6 dense domain cards (388graph nodes,22encyclopedia PDFs,ETItier lists,24quant tickers,FREDmacro series,/engineering/,/math/). Having the chatbot accessible from/lets a newcomer ask "Where should I start?" or "What is NVDA's latest price and Dose?" and receive a direct deep-link. - Zero Floating-Drawer Collisions with Subpage Workbenches: The subpages already host dense, specialized interactive overlays in the viewport corners (
/engineering/*and/math/*have the dockable#hsGuileReplDrawerand 5-state#hsPolyglotModeSelector;/quant/has#quantInfoPopoverand the410pxcanvas;/graph/has the full-viewport force/radar explorer). Keeping the chatbot off those subpages prevents overlapping drawers and z-index clutter. - Single-Surface Maintenance & Smaller Subpage Footprint: Avoids injecting chatbot JS/DOM into 16+ subpage HTML templates and multiple Python compilers (
engineering_docs.py,math_docs.py).
2.3 Cons of Placing an Embedded/Floating Chatbot Widget Directly on the Homepage (/) Rather Than on a Dedicated /chat/ Subpage
- Risk to the Homepage's Clean 6-Card Grid & Group 3
90/7/3%Sensory Budget:site/index.htmlis a balanced2 × 3(6-card) grid with zero JavaScript state machines. Adding an embedded chat panel or floating drawer directly onto/would either break the 6-card symmetry or obscure Cards05and06on laptop/mobile screens, consuming part of the strict7%#38bdf8interactive highlight budget on/. - Loss of Context-In-Place When Reading Deep Subpages: If the chatbot only lived as an inline widget on
/, a user reading/quant/or/math/would have to navigate back to/anyway (whereas a dedicated/chat/subpage can be kept open in a companion tab). - Constrained Screen Real Estate for Rich Outputs (
900×1260Stats Cards & Raw JSON/CIDv1 Provenance): A small corner widget on/is far too cramped to comfortably render a900×1260Ticker Stats Card PNG preview, a table of333/666/777archive equations, and an expandable IPLDdag-jsonCIDv1provenance receipt side-by-side.
2.4 Comparison of the 3 Placement Options & Designation of Option 2 as the Default Choice
| Placement Option | Homepage (/) Impact |
Subpage (/quant/, /math/, /engineering/) Impact |
Status |
|---|---|---|---|
Option 1 (Homepage / Widget Only — Collapsed Drawer on /, Zero Subpage Injection) |
Adds a floating drawer/bar to / (site/index.html). |
Zero clutter on subpages (0 collision with #hsGuileReplDrawer or #quantInfoPopover). |
Alternative |
Option 2 (DEFAULT CHOICE: Dedicated /chat/ Subpage Only + Single Header Button on /) |
Keeps / 100% pure static HTML (adds only one Ask Corpus (/chat/) button in <header>). |
Zero clutter on subpages; full-screen split-pane space on /chat/index.html for 900×1260 cards & JSON/CIDv1 receipts. |
DEFAULT |
Option 3 (Initial Draft: Floating Widget on / + All Subpages + /chat/) |
Adds floating widget to / plus /chat/ link. |
High risk of corner-drawer collision with #hsGuileReplDrawer on /engineering/ & /math/ and #quantInfoPopover on /quant/. |
Superseded |
2.5 Specification of the Default Option 2 (/chat/index.html Full-Screen Split-Pane Workbench)
- Accessible at
/chat/index.htmlvia a single34px-height Group 3 Stealth Basalt header button (Ask Corpus (/chat/)) on/workspace/hyperstitionstudio-core/site/index.html(with0floating widget scripts injected into/,/quant/,/learn/,/engineering/*, or/math/*). - 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