Files
encyclopedia-knowledge-graph/docs/plans/inactive/PLAN-HYPERSTITIONSTUDIO-POLYGLOT-SDK-AND-CLIENT-LIBRARIES.md
T

13 KiB

PLAN: HyperstitionStudio Polyglot SDK & Zero-Drift Client Libraries (hs-sdk-build & /sdk/)

Document ID: PLAN-HYPERSTITIONSTUDIO-POLYGLOT-SDK-AND-CLIENT-LIBRARIES Status: DEFERRED (Long-Term Inactive — Preserved for Future Reference) Target Ecosystem Version: v2.4.0 Target Repositories: hyperstitionstudio-core, encyclopedia-knowledge-graph Author: m00t & Hermes Agent Date: 2026-11-30


1. Executive Summary & Architectural Objective

As of v2.3.0, hyperstitionstud.io exposes 20 deterministic MCP & Chatbot REST API tools (/api/v1/tools/* and JSON-RPC 2.0 /mcp), 14 static URN resources (/api/v1/resources/*), 6 parameterized URI templates, 4 guided prompts, 5 JSON Schema Draft 2020-12 contracts (/schemas/v1/*.schema.json), and a 3-language polyglot pedagogical lens (Guile Scheme, TypeScript, and Rust) across /engineering/ and /math/.

This plan specifies the HyperstitionStudio Polyglot Software Development Kit (hs-sdk-build & /sdk/): a zero-LLM-token, schema-driven SDK generator and multi-language client library suite providing ergonomic, strongly-typed programmatic access to hyperstitionstud.io across Python, TypeScript / JavaScript (ESM + .d.ts), Rust, and GNU Guile Scheme.

Core Design Principles

  1. Zero-Drift Schema-Driven Code Generation (0 LLM Tokens):
    • src/hyperstitionstud_io/sdk/generator.py (hs-sdk-build) introspects MCP_TOOLS_SCHEMA (20 tools), STATIC_RESOURCES (14 URN resources), RESOURCE_TEMPLATES (6 templates), build_openapi_v1_spec(), and site/schemas/v1/*.schema.json directly in Python (<40 ms, 0 LLM tokens) to emit synchronized client libraries, type declarations, and /sdk/sdk-manifest.json.
    • Adding a 21st tool to MCP_TOOLS_SCHEMA automatically generates the corresponding typed method across Python, TypeScript, Rust, and Guile Scheme on the next hs-sdk-build --sync pass.
  2. Offline Local Algebra (LocalAlgebra) + Remote API Client (HyperstitionClient) Dual Architecture:
    • Every SDK target ships with two complementary modules:
      • LocalAlgebra (Offline, 0 Network Calls): Pure, deterministic implementations of Base-36 Alphanumeric Qabbala (aq_base36), mod-9 digital root (dr9), trial-division prime factorization (prime_factors), exact/IEEE-754 population variance (variance_pop), Ecological Trophic Index (eti_score), 3-state discrete Bayesian updating (bayes_update), and RFC 8785 JCS + SHA-256 CIDv1 (baguqeera...) verification.
      • HyperstitionClient (Typed Remote & In-Process Client): Strongly-typed methods for all 20 MCP/REST tools, 14 static URN resources, 6 URI templates, and 4 prompts, targeting https://hyperstitionstud.io by default or any custom base_url (including in_process zero-socket dispatch in Python).
  3. Strict Zero-Synthetic-Data Contract Preservation:
    • SDK response types explicitly model nullable observations (float | None in Python, number | null in TypeScript, Option<f64> in Rust, #f / 'null in Guile Scheme) alongside data_available: bool and status: "No data available". The SDK never coerces missing or private-equity observations (ANTHR-PVT, weekend/holiday bars) to 0.0 or synthetic defaults.
  4. Global Zero-Host-Path & Two-Script Deployment Compliance:
    • All public SDK download routes, module imports, and documentation deep-links target https://hyperstitionstud.io/sdk/... (Class W), while all localhost developer CLI instructions use container-relative /workspace/... paths (Class L).
    • hs-sdk-build --sync is wired into /workspace/push-all-to-git-libre-audio.sh and /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/sync-vps-repos.sh so the Two-Script Deployment Invariant remains unbroken.

2. Four Target SDK Languages & Distribution Surfaces

SDK Target Generated Artifact Path (Web Route under https://hyperstitionstud.io/sdk/) Runtime Dependencies Supported Transports Primary Audience & Use Case
1. Python SDK (hyperstitionstud_io.sdk + standalone single-file hyperstition_sdk.py) /sdk/python/hyperstition_sdk.py (also importable via from hyperstitionstud_io.sdk import HyperstitionClient, LocalAlgebra) Zero external deps (Python >=3.10 stdlib urllib.request, dataclasses, fractions.Fraction, hashlib) rest (/api/v1/*), mcp_http (JSON-RPC 2.0 /mcp), and in_process (ReadOnlyIsolationGuard) Quantitative researchers, data pipelines, Jupyter notebooks, and AI agents
2. TypeScript / JavaScript ESM SDK (hyperstition-sdk.mjs + hyperstition-sdk.d.ts) /sdk/ts/hyperstition-sdk.mjs, /sdk/ts/hyperstition-sdk.d.ts, /sdk/ts/package.json Zero external deps (Standard fetch + WebCrypto crypto.subtle.digest) rest (/api/v1/*) & mcp_http (/mcp) in Browser <script type="module">, Node.js >=18, Deno, and Bun Web developers, browser dashboards, TradingView/quant integrations, and TypeScript apps
3. Rust Typed SDK (hyperstition_sdk.rs + Cargo.toml) /sdk/rust/hyperstition_sdk.rs, /sdk/rust/Cargo.toml Pure std for local_algebra; optional serde + serde_json + ureq/reqwest for HTTP transport rest (/api/v1/*) & mcp_http (/mcp) + zero-allocation local_algebra Systems engineers, low-latency quant backtesters, and CLI tool authors
4. GNU Guile Scheme SDK (hyperstition-sdk.scm) /sdk/guile/hyperstition-sdk.scm GNU Guile 3.0+ ((web client), (web uri), (ice-9 match), plus guile_prelude.scm) rest (/api/v1/*), mcp_http (/mcp), & pure functional Z-calculus local-algebra Functional programmers, z-calculus-scheme learners, and symbolic algebra explorers

3. Detailed SDK Architecture & API Specification

3.1 Python SDK (src/hyperstitionstud_io/sdk/client.py & /sdk/python/hyperstition_sdk.py)

The Python SDK provides both a rich multi-transport package inside hyperstitionstudio-core and a self-contained single-file distribution (/sdk/python/hyperstition_sdk.py) that external users can download via curl -sSLO https://hyperstitionstud.io/sdk/python/hyperstition_sdk.py:

from hyperstitionstud_io.sdk import HyperstitionClient, LocalAlgebra

# 1. Offline Local Algebra (0 network calls, exact rational & Base-36 AQ math)
assert LocalAlgebra.aq_base36("LEMUR") == 114
assert LocalAlgebra.prime_factors(666) == [2, 3, 3, 37]
assert LocalAlgebra.variance_pop_exact([272, 276, 286, 290, 292, 336]) == "4634/9"
assert LocalAlgebra.bayes_update_exact(["1/3", "1/3", "1/3"], ["1/10", "3/10", "6/10"]) == ["1/10", "3/10", "3/5"]

# 2. Remote REST / MCP HTTP or Local In-Process Client
client = HyperstitionClient(
    base_url="https://hyperstitionstud.io",  # or transport="in_process" inside /workspace
    transport="rest",                        # "rest" | "mcp_http" | "in_process"
    verify_cidv1=True,                       # Auto-verifies RFC 8785 JCS CIDv1 receipts when present
)

# Strongly-typed methods for all 20 MCP/Chatbot REST tools:
aq_res = client.evaluate_aq_and_ingglish(terms=["schizoanalysis", "abstract machine", "synthetic data"])
nvda_ts = client.inspect_quant_timeseries(symbol="NVDA", lens="fund_manager")
anthr_ts = client.inspect_quant_timeseries(symbol="ANTHR-PVT")
assert anthr_ts["instruments"][0]["data_available"] is False  # Zero-Synthetic-Data preserved

macro_res = client.inspect_macro_indicators(category="all")
brief_res = client.generate_daily_portfolio_brief(refresh=False)
card_res = client.generate_ticker_stats_card(symbol="NVDA", register="fund_manager")
poly_res = client.evaluate_guile_scheme_z_calculus(expression='aq_base36("LEMUR")', lang="rust")

3.2 TypeScript / JavaScript ESM SDK (/sdk/ts/hyperstition-sdk.mjs & /sdk/ts/hyperstition-sdk.d.ts)

Can be imported directly in any browser or Deno/Node.js script from https://hyperstitionstud.io/sdk/ts/hyperstition-sdk.mjs (or locally from /sdk/ts/hyperstition-sdk.mjs):

import { HyperstitionClient, LocalAlgebra } from "https://hyperstitionstud.io/sdk/ts/hyperstition-sdk.mjs";

// Offline deterministic algebra (shared with /engineering/ and /math/ TS lens)
const aq = LocalAlgebra.aqBase36("LEMUR"); // 114
const factors = LocalAlgebra.primeFactors(666); // [2, 3, 3, 37]

// Typed REST + MCP JSON-RPC 2.0 client
const client = new HyperstitionClient({ baseUrl: "https://hyperstitionstud.io", transport: "rest" });
const brief = await client.generateDailyPortfolioBrief({ refresh: false });
const nvdaCard = await client.generateTickerStatsCard({ symbol: "NVDA", register: "fund_manager" });

3.3 Rust SDK (/sdk/rust/hyperstition_sdk.rs & /sdk/rust/Cargo.toml)

Provides zero-allocation local_algebra functions (aq_base36, dr9, prime_factors, variance_pop, eti_score, bayes_update) that compile with rustc --edition=2021 using only the Rust standard library (std), plus typed request/response structs and a HyperstitionClient builder for all 20 tools.

3.4 GNU Guile Scheme SDK (/sdk/guile/hyperstition-sdk.scm)

Integrates guile_prelude.scm (applicative-order Z combinator, exact rational p/q arithmetic, Thomas' Calculus derivative / adaptive-simpson, and aq-base36) with JSON-RPC 2.0 / REST HTTP helpers (hs-call-tool, hs-read-resource, hs-verify-isolation).


4. Cryptographic CIDv1 Verification & Zero-Synthetic-Data Guards

  1. Client-Side RFC 8785 JCS + CIDv1 (baguqeera...) Verification (LocalAlgebra.compute_dag_json_cidv1):
    • Both the Python and TypeScript SDKs include a pure implementation of RFC 8785 JSON Canonicalization Scheme (JCS) + SHA-256 multihash + RFC 4648 lower-case Base32 (baguqeera...) so callers can verify offline that any registry fetched via /api/v1/resources/<name> or /api/v1/tools/hs_compute_ipld_dag_json_cid is bit-for-bit authentic.
  2. Explicit NoDataAvailable Helpers (ZeroSyntheticDataGuard):
    • The SDK includes helper predicates (HyperstitionClient.is_observation_available(bar)) that check bar.get("data_available") is True and bar.get("close_usd") is not None and raise a descriptive SyntheticFallbackForbiddenError if user code attempts an unsafe numeric coercion on a "No data available" record without explicit filtering.

5. Interactive /sdk/ Documentation Hub & MCP/REST Introspection

  1. Group 3 Stealth Basalt /sdk/ Hub (site/sdk/index.html):
    • Renders a Group 3 (Stealth Basalt Plate & Micro-Pip Signal Ribbon, 10px/4px 45° chamfers) developer portal at https://hyperstitionstud.io/sdk/ featuring:
      • Direct download links and SHA-256 checksums for all 4 language SDK bundles (/sdk/python/hyperstition_sdk.py, /sdk/ts/hyperstition-sdk.mjs, /sdk/ts/hyperstition-sdk.d.ts, /sdk/rust/hyperstition_sdk.rs, /sdk/guile/hyperstition-sdk.scm, /sdk/sdk-manifest.json),
      • Synchronized 5-state polyglot code examples (#hsPolyglotModeSelector) showing identical SDK workflows across Python, TypeScript, Rust, and Guile Scheme,
      • Complete method reference table auto-generated from the 20 MCP_TOOLS_SCHEMA entries and 14 STATIC_RESOURCES.
    • Navigation buttons to /sdk/ (SDK (/sdk/)) wired into /engineering/index.html and /math/index.html.
  2. Container-Relative Local CLI & Public Web Invocation:
    • Localhost Terminal CLI (/workspace):
      PYTHONPATH=/workspace/hyperstitionstudio-core/src python3 -m hyperstitionstud_io.sdk.generator --sync
      
    • Public Web & REST Discovery (https://hyperstitionstud.io):
      • https://hyperstitionstud.io/sdk/sdk-manifest.json
      • https://hyperstitionstud.io/api/v1/resources/sdk-manifest (urn:io:hyperstitionstud:resource:sdk-manifest)

6. Implementation & Verification Gates

  1. Unit & Cross-Language Parity Gate (tests/test_core_suite.py):
    • Verify that Python HyperstitionClient(transport="in_process") and LocalAlgebra execute all 20 tool methods and match the TypeScript ESM SDK (/sdk/ts/hyperstition-sdk.mjs tested via node --input-type=module -e ...) on aqBase36("LEMUR") == 114, primeFactors(666) == [2, 3, 3, 37], and computeDagJsonCidv1(...).
    • Verify that hs-sdk-build --check detects zero drift between MCP_TOOLS_SCHEMA and /sdk/sdk-manifest.json.
    • Verify that run_introspective_erofs_suite() passes with 0 EROFS escapes when hs-sdk-build or SDK tools run under simulated ProtectSystem=strict.
  2. Two-Script Deployment & 6-Gate Public Smoke (deploy/test-first-deployment.sh):
    • Wire /sdk symlink creation and .gz/.br pre-compression into deploy/sync-vps-repos.sh and push-all-to-git-libre-audio.sh (0 /dev/null redirections).
    • Verify /sdk/index.html, /sdk/sdk-manifest.json, /sdk/python/hyperstition_sdk.py, /sdk/ts/hyperstition-sdk.mjs, /sdk/ts/hyperstition-sdk.d.ts, /sdk/rust/hyperstition_sdk.rs, and /sdk/guile/hyperstition-sdk.scm return HTTP 200 OK.