Files
encyclopedia-knowledge-graph/docs/PLAN-COMPREHENSIVE-MCP-AND-CHATBOT-REST-API-CAPABILITY-EXPOSURE.md
T

96 lines
12 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Plan: Comprehensive Exposure of All Workspace Capabilities, Compilers, Curricula & Documentation via MCP (`/mcp`) and Chatbot REST API (`/api/v1/*`) (`v2.2.1`)
- **Document ID:** `PLAN-COMPREHENSIVE-MCP-AND-CHATBOT-REST-API-CAPABILITY-EXPOSURE` (`v2.2.1`)
- **Roadmap Status:** **ACTIVE / READY**
- **Core Architectural & Governance Mandates:**
1. **100% Capability & Documentation Coverage Across All 6 Repositories:** Every functional capability, quantitative/macro/Bayesian dataset, Guile Scheme `Z`-combinator evaluator, programmatic SemVer/EROFS diagnostic, `/engineering/` (`E0–E5`) and `/math/` (`M0–M5`) explication hub/subpage, Novice Prerequisite Ladder, `/learn/` module, `/quant/` tutorial episode & `ⓘ` popover glossary, Operator's Manual, stakeholder proposal, active/deferred plan, and cold-rotated historical plan (`completed-plans-archive.tar.gz`) must be inspectable and queryable via both **MCP (`/mcp`)** and the **Chatbot OpenAPI 3.1.0 REST Adapter (`/api/v1/tools/*` & `/api/v1/resources/*`)**.
2. **Zero New Bespoke REST Routes in `src/hyperstitionstud_io/mcp/rest.py`:** All new capabilities are registered in `MCP_TOOLS_SCHEMA` (`src/hyperstitionstud_io/mcp/tools.py`), `STATIC_RESOURCES` / `RESOURCE_TEMPLATES` (`src/hyperstitionstud_io/mcp/resources.py`), and `MCP_PROMPTS` (`src/hyperstitionstud_io/mcp/prompts.py`), so the existing generic `/api/v1/tools/{tool_name}`, `/api/v1/resources/{slug}`, and `/api/v1/openapi.json` adapter exposes them automatically (`0` custom route patterns added to `rest.py`).
3. **100% Read-Only & `ProtectSystem=strict` (`EROFS`) Compliant (`0` LLM Tokens):** Cold-rotated plans inside `completed-plans-archive.tar.gz` are extracted strictly in memory via `tarfile` without touching disk, and every new tool is automatically swept under simulated `ProtectSystem=strict` (`EROFS`) by `src/hyperstitionstud_io/ci/erofs_harness.py`.
- **Target Modules & Files:**
- `/workspace/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/tools.py`
- `/workspace/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/resources.py`
- `/workspace/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/prompts.py`
- `/workspace/hyperstitionstudio-core/src/hyperstitionstud_io/ci/erofs_harness.py`
- `/workspace/hyperstitionstudio-core/tests/test_core_suite.py`
---
## 1. Exhaustive Capability & Documentation Gap Audit (`v2.2.1`)
| Capability / Documentation Domain | Current State in `v2.2.1` | Gap Addressed by This Plan |
| :--- | :--- | :--- |
| **1. `/engineering/` (`E0–E5`) & `/math/` (`M0–M5`) Explication Hubs, Subpages & Novice Prerequisite Ladders** | Generated as static HTML/JSON in `site/engineering/` and `site/math/`, but **not** exposed via MCP tools or `/api/v1/*`. | Expose via new MCP tool **`hs_inspect_engineering_and_math_docs`** and static resources `engineering-manifest` & `math-manifest`. |
| **2. Guile Scheme & `Z`-Combinator Pedagogical Lens (`guile_prelude.scm` & S-Expression Evaluation)** | Runs in browser (`hs-guile-scheme-repl.js`), but cannot be evaluated or queried via MCP or Chatbot REST API. | Expose via new MCP tool **`hs_evaluate_guile_scheme_z_calculus`** (supporting exact rationals `p/q`, float conversion, `β-reduction` trace, and cartridge lookup) + resource `guile-prelude`. |
| **3. Operator's Manuals, Deployment Guides, Stakeholder Proposals & Specifications** | Stored as `.md`/`.pdf` files on disk (`OPERATORS-MANUAL-*`, `VPS-AND-GIT-OPERATOR-DEPLOYMENT-GUIDE`, `ONBOARDING-INGGLISH-AQ`, `proposal-*`, `specification-*`), but only `dossier:{01..71}` is readable via MCP. | Expose via new MCP tool **`hs_inspect_documentation_and_manuals`** (with keyword/passage search, full Markdown retrieval, and PDF deep-link URLs) and resource template `urn:io:hyperstitionstud:doc:{doc_slug}`. |
| **4. Cold-Rotated Completed Plans (`completed-plans-archive.tar.gz`) & Active/Deferred Roadmap Plans** | `76` completed `.md`/`.pdf` files in `encyclopedia-knowledge-graph/docs/archive/completed-plans-archive.tar.gz` + `5` in `zoology/docs/archive/` are indexed in `archive-manifest.json` but not queryable via API. | Expose in-memory `.tar.gz` plan listing and full `.md` extraction inside **`hs_inspect_documentation_and_manuals`** (`archive_rotator.py` in-memory `tarfile` reader — `0` disk writes, `EROFS`-safe). |
| **5. Interactive `/learn/` Curriculum (`Modules 1–6`) & `/quant/` Guided Tour (`5` Episodes) + `27` `ⓘ` Glossary Popovers** | Embedded in `site/learn/learn-app.js`, `site/quant/quant-tutorials.js`, and `site/quant/quant-app.js`, but not exposed via `/mcp` or `/api/v1/*`. | Expose structured `/learn/` curriculum modules, `/quant/` 5-episode tutorial scenes, and all `27` `QUANT_TERM_GLOSSARY` `ⓘ` definitions + PDF deep-links via **`hs_inspect_documentation_and_manuals`**. |
| **6. SQLite FTS5 Unified Catalog Search (`hyperstition-meta.db`), Programmatic Version Heuristics (`--explain-bump`) & `EROFS`/Baseline Audit State** | Implemented in `db/sqlite_meta.py`, `version_sync.py`, and `ci/public_regression.py`, but not exposed via MCP tools. | Expose via new MCP tool **`hs_query_workspace_catalog_and_release_state`**. |
| **7. IPLD `dag-json` (`0x0129`) `CIDv1` Registry Map (`hs_compute_ipld_dag_json_cid`)** | `reg_map` in `mcp/tools.py` only lists 7 v1 registries (`glossary-registry` .. `encyclopedia-graph`). | Expand `reg_map` to include `quant-timeseries`, `real-macro-indicators`, `daily-brief-latest`, `engineering-manifest`, `math-manifest`, and `archive-manifest` (`13` named registries total). |
---
## 2. Detailed Specification of the 4 New MCP / Chatbot REST Tools (`MCP_TOOLS_SCHEMA`)
### 2.1 `hs_inspect_engineering_and_math_docs`
- **Endpoint:** `GET/POST /api/v1/tools/hs_inspect_engineering_and_math_docs` & MCP `tools/call`
- **Parameters:**
- `domain` (`"all" | "engineering" | "math"`, default `"all"`): Select `/engineering/` (`E0–E5`), `/math/` (`M0–M5`), or both.
- `unit_filter` (`string`, default `""`): Optional unit ID or subpage slug (`"E0".."E5"`, `"M0".."M5"`, `"ciphers-and-phonetics"`, `"base36-algebra-and-primes"`, etc.).
- `include_guile_cartridges` (`boolean`, default `True`): Include the 3-column Homoiconic Tri-View (`math_view`, `py_view`, `scm_expr`, and `challenge`) for each unit.
- **Returns:**
- Full live-introspected manifests (`engineering-manifest.json` & `math-manifest.json`), algebraic conservation invariants, CLI scripts table, Novice Prerequisite Ladders (`expertise_level`, `prerequisites`, `public_resources`), subpage explication sections, and Guile Scheme cartridges.
### 2.2 `hs_inspect_documentation_and_manuals`
- **Endpoint:** `GET/POST /api/v1/tools/hs_inspect_documentation_and_manuals` & MCP `tools/call`
- **Parameters:**
- `category` (`"all" | "manuals" | "proposals_and_specs" | "active_and_deferred_plans" | "archived_plans" | "learn_and_tutorials" | "quant_glossary_popovers"`, default `"all"`).
- `doc_id` (`string`, default `""`): Optional document slug or plan ID (e.g. `"OPERATORS-MANUAL-LLM-TOKEN-DEPENDENT-DATA-PIPELINES"`, `"VPS-AND-GIT-OPERATOR-DEPLOYMENT-GUIDE"`, `"PLAN-LOCAL-SERVER-SIDE-WEB-CHATBOT-GUI"`, or any cold-archived plan like `"PLAN-HS-PDF-BUILD-DARK-MODE-AND-GLYPH-SANITIZATION"`).
- `search_query` (`string`, default `""`): Optional case-insensitive keyword or phrase to search across all manuals, plans (including inside `completed-plans-archive.tar.gz` in memory!), `/learn/` modules, and `/quant/` tutorial scenes / `ⓘ` popovers.
- `include_full_markdown` (`boolean`, default `False`): When `True` (or when `doc_id` is specified), returns the complete Markdown text of the matching document(s).
- **Returns:**
- Catalog of all documentation artifacts with canonical web PDF routes (`/graph/*.pdf`, `/quant/*.pdf`, `/zoology/*.pdf`, `/ci/*.pdf`), cold-archive manifest metadata (`bundle_sha256`, `member_count`), matched passages with line numbers, `/learn/` modules, `/quant/` tutorial scenes, and `27` `ⓘ` popover definitions.
### 2.3 `hs_evaluate_guile_scheme_z_calculus`
- **Endpoint:** `GET/POST /api/v1/tools/hs_evaluate_guile_scheme_z_calculus` & MCP `tools/call`
- **Parameters:**
- `expression` (`string`, default `'(aq-base36 "LEMUR")'`): S-expression to evaluate against the preloaded `guile_prelude.scm` environment (`Z`, `limit`, `derivative`, `nth-derivative`, `riemann-integral`, `adaptive-simpson`, `aq-base36`, `digital-root-mod9`, `prime-factors`, `variance-pop`, `eti-score`, `confluence-dose`, `bayes-update`, `evaluate-bump-scope`).
- `include_trace` (`boolean`, default `True`): Return step-by-step `β-reduction` call trace.
- `include_prelude_source` (`boolean`, default `False`): Include the full canonical `publishing/guile_prelude.scm` source code.
- **Returns:**
- Exact rational / symbolic result (`formatted`), floating-point approximation (`float_value`), `β-reduction` trace steps, and optional `guile_prelude.scm` source.
### 2.4 `hs_query_workspace_catalog_and_release_state`
- **Endpoint:** `GET/POST /api/v1/tools/hs_query_workspace_catalog_and_release_state` & MCP `tools/call`
- **Parameters:**
- `fts_query` (`string`, default `""`): Optional SQLite FTS5 full-text search query across `glossary_entries`, `kg_nodes`, and `dossiers` in `.cache/hyperstition-meta.db` (with automatic read-only JSON fallback if the `.cache` DB is absent).
- `include_version_bump_heuristics` (`boolean`, default `True`): Include the zero-token `compute_programmatic_version_bump()` (`--explain-bump`) report.
- `include_baseline_and_telemetry` (`boolean`, default `True`): Include the cached `.cache/internal-test-baseline-latest.json` summary (`erofs_protect_system_strict_audit`, canary values, `CIDv1` map) and `get_api_telemetry_summary()`.
---
## 3. Expanded MCP URN Resources (`src/hyperstitionstud_io/mcp/resources.py`)
Add 7 new static URN resources to `STATIC_RESOURCES` (all automatically accessible via `GET /api/v1/resources/{slug}` and MCP `resources/read`):
1. `urn:io:hyperstitionstud:resource:quant-timeseries` (`site/quant/quant-timeseries.json`)
2. `urn:io:hyperstitionstud:resource:macro-indicators` (`site/quant/real-macro-indicators.json`)
3. `urn:io:hyperstitionstud:resource:daily-brief` (`site/quant/daily-brief-latest.json`)
4. `urn:io:hyperstitionstud:resource:engineering-manifest` (`site/engineering/engineering-manifest.json`)
5. `urn:io:hyperstitionstud:resource:math-manifest` (`site/math/math-manifest.json`)
6. `urn:io:hyperstitionstud:resource:archive-manifest` (`encyclopedia-knowledge-graph/docs/archive/archive-manifest.json`)
7. `urn:io:hyperstitionstud:resource:guile-prelude` (`src/hyperstitionstud_io/publishing/guile_prelude.scm`, `text/x-scheme`)
---
## 4. Synergy with `PLAN-LOCAL-SERVER-SIDE-WEB-CHATBOT-GUI` & Verification Gates
- **Seamless Integration with `PLAN-LOCAL-SERVER-SIDE-WEB-CHATBOT-GUI`:**
- When `PLAN-COMPREHENSIVE-MCP-AND-CHATBOT-REST-API-CAPABILITY-EXPOSURE` is implemented first, `chatbot.py` (`hs_ask_chatbot`) can delegate documentation, manual, archived-plan, `/engineering/`, `/math/`, `/learn/`, Guile Scheme `Z`-combinator, and SQLite FTS5 queries directly to these 4 new MCP tools!
- **Automated Verification (`tests/test_core_suite.py` & `ci/erofs_harness.py`):**
- Because `ci/erofs_harness.py` dynamically iterates over `MCP_TOOLS_SCHEMA`, all 4 new tools are automatically tested under simulated `ProtectSystem=strict` (`EROFS`) on every test run.
- Add explicit assertions in `tests/test_core_suite.py` verifying:
- `hs_inspect_engineering_and_math_docs` returns all `E0–E5` and `M0–M5` units, Novice Prerequisite Ladders, and Guile cartridges,
- `hs_inspect_documentation_and_manuals` reads both live Operator's Manuals and cold-rotated `.md` plans from `completed-plans-archive.tar.gz` in memory under `EROFS`,
- `hs_evaluate_guile_scheme_z_calculus` evaluates `Z`-combinator expressions and returns exact rationals + `β-reduction` traces,
- `hs_query_workspace_catalog_and_release_state` returns SQLite FTS5 search hits, `--explain-bump` heuristics, and the `EROFS` baseline receipt, and
- `hs_compute_ipld_dag_json_cid` supports all 13 workspace registries.