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
- Zero-Drift Schema-Driven Code Generation (
0LLM Tokens):src/hyperstitionstud_io/sdk/generator.py(hs-sdk-build) introspectsMCP_TOOLS_SCHEMA(20tools),STATIC_RESOURCES(14URN resources),RESOURCE_TEMPLATES(6templates),build_openapi_v1_spec(), andsite/schemas/v1/*.schema.jsondirectly in Python (<40 ms,0LLM tokens) to emit synchronized client libraries, type declarations, and/sdk/sdk-manifest.json.- Adding a 21st tool to
MCP_TOOLS_SCHEMAautomatically generates the corresponding typed method across Python, TypeScript, Rust, and Guile Scheme on the nexths-sdk-build --syncpass.
- Offline Local Algebra (
LocalAlgebra) + Remote API Client (HyperstitionClient) Dual Architecture:- Every SDK target ships with two complementary modules:
LocalAlgebra(Offline,0Network 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-256CIDv1(baguqeera...) verification.HyperstitionClient(Typed Remote & In-Process Client): Strongly-typed methods for all20MCP/REST tools,14static URN resources,6URI templates, and4prompts, targetinghttps://hyperstitionstud.ioby default or any custombase_url(includingin_processzero-socket dispatch in Python).
- Every SDK target ships with two complementary modules:
- Strict Zero-Synthetic-Data Contract Preservation:
- SDK response types explicitly model nullable observations (
float | Nonein Python,number | nullin TypeScript,Option<f64>in Rust,#f/'nullin Guile Scheme) alongsidedata_available: boolandstatus: "No data available". The SDK never coerces missing or private-equity observations (ANTHR-PVT, weekend/holiday bars) to0.0or synthetic defaults.
- SDK response types explicitly model nullable observations (
- 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 alllocalhostdeveloper CLI instructions use container-relative/workspace/...paths (Class L). hs-sdk-build --syncis wired into/workspace/push-all-to-git-libre-audio.shand/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/sync-vps-repos.shso the Two-Script Deployment Invariant remains unbroken.
- All public SDK download routes, module imports, and documentation deep-links target
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
- 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_cidis bit-for-bit authentic.
- 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 (
- Explicit
NoDataAvailableHelpers (ZeroSyntheticDataGuard):- The SDK includes helper predicates (
HyperstitionClient.is_observation_available(bar)) that checkbar.get("data_available") is True and bar.get("close_usd") is not Noneand raise a descriptiveSyntheticFallbackForbiddenErrorif user code attempts an unsafe numeric coercion on a"No data available"record without explicit filtering.
- The SDK includes helper predicates (
5. Interactive /sdk/ Documentation Hub & MCP/REST Introspection
- Group 3 Stealth Basalt
/sdk/Hub (site/sdk/index.html):- Renders a Group 3 (
Stealth Basalt Plate & Micro-Pip Signal Ribbon,10px/4px45°chamfers) developer portal athttps://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
20MCP_TOOLS_SCHEMAentries and14STATIC_RESOURCES.
- Direct download links and SHA-256 checksums for all 4 language SDK bundles (
- Navigation buttons to
/sdk/(SDK (/sdk/)) wired into/engineering/index.htmland/math/index.html.
- Renders a Group 3 (
- 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.jsonhttps://hyperstitionstud.io/api/v1/resources/sdk-manifest(urn:io:hyperstitionstud:resource:sdk-manifest)
- Localhost Terminal CLI (
6. Implementation & Verification Gates
- Unit & Cross-Language Parity Gate (
tests/test_core_suite.py):- Verify that Python
HyperstitionClient(transport="in_process")andLocalAlgebraexecute all 20 tool methods and match the TypeScript ESM SDK (/sdk/ts/hyperstition-sdk.mjstested vianode --input-type=module -e ...) onaqBase36("LEMUR") == 114,primeFactors(666) == [2, 3, 3, 37], andcomputeDagJsonCidv1(...). - Verify that
hs-sdk-build --checkdetects zero drift betweenMCP_TOOLS_SCHEMAand/sdk/sdk-manifest.json. - Verify that
run_introspective_erofs_suite()passes with0EROFSescapes whenhs-sdk-buildor SDK tools run under simulatedProtectSystem=strict.
- Verify that Python
- Two-Script Deployment & 6-Gate Public Smoke (
deploy/test-first-deployment.sh):- Wire
/sdksymlink creation and.gz/.brpre-compression intodeploy/sync-vps-repos.shandpush-all-to-git-libre-audio.sh(0/dev/nullredirections). - 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.scmreturnHTTP 200 OK.
- Wire