Phase 1c: real kRPC bridge (full protocol + mock mode for development) #4

Merged
Arnike merged 1 commits from phase-1c into main 2026-06-02 20:48:02 +00:00
Owner
  • packages/krpc-client: TypeScript kRPC protocol client

    • connection.ts: varint encoding/decoding, length-prefix framing,
      per-socket read queue (avoids race when multiple read promises
      in flight). Uses multiplication not '<<' for varint shift
      because JS truncates << to 32 bits.
    • schema.ts: hand-written protobufjs schema for kRPC meta-protocol
      (ConnectionRequest, Request, Response, StreamUpdate, Status, etc.)
      • enough to do connection handshake, single procedure calls, and
        stream subscription. Service-specific types (SpaceCenter.Vessel,
        Orbit, CelestialBody) need to be loaded from the kRPC mod's
        .proto files at runtime.
    • client.ts: KRPCClient with connect/invoke/addStream/removeStream/
      onStreamUpdate/close. Tested with hand-rolled mock server.
    • 10 tests (varint round-trips incl. uint64, wire format with raw
      sockets).
  • apps/tools/ksp-bridge: bridge that connects KSP to our API

    • convert.ts: pure kRPC -> UniverseSnapshot conversion
      (situation enum mapping, body id normalization, etc.)
    • bridge.ts: main poll loop with retry + backoff
    • krpc-adapter.ts: KRPCAdapter class that owns the KRPCClient
    • index.ts: entrypoint with MOCK MODE for development (emits
      synthetic state when no KSP is available, so you can verify the
      HTTP pipeline end-to-end)
    • 9 tests (7 conversion + 2 end-to-end bridge)
  • ksp/README.md: full setup guide

    • CKAN install, KSP server start, env vars
    • Hand-rolled KSP calls list (what SpaceCenter methods we need)
    • Roadmap for the remaining .proto-loading work
    • Protocol deep-dive (for the next dev)
  • Bug fixes along the way: protobufjs default import (not namespace),
    varint 32-bit truncation, JavaScript bitwise 32-bit limit,
    handshake status enum comparison (number vs string).

End-to-end verified: API + bridge in mock mode, 2 bodies + 1 vessel
arriving at /api/v1/state, 500ms polling cadence, automatic recovery
on HTTP failures.

- packages/krpc-client: TypeScript kRPC protocol client - connection.ts: varint encoding/decoding, length-prefix framing, per-socket read queue (avoids race when multiple read promises in flight). Uses multiplication not '<<' for varint shift because JS truncates << to 32 bits. - schema.ts: hand-written protobufjs schema for kRPC meta-protocol (ConnectionRequest, Request, Response, StreamUpdate, Status, etc.) - enough to do connection handshake, single procedure calls, and stream subscription. Service-specific types (SpaceCenter.Vessel, Orbit, CelestialBody) need to be loaded from the kRPC mod's .proto files at runtime. - client.ts: KRPCClient with connect/invoke/addStream/removeStream/ onStreamUpdate/close. Tested with hand-rolled mock server. - 10 tests (varint round-trips incl. uint64, wire format with raw sockets). - apps/tools/ksp-bridge: bridge that connects KSP to our API - convert.ts: pure kRPC -> UniverseSnapshot conversion (situation enum mapping, body id normalization, etc.) - bridge.ts: main poll loop with retry + backoff - krpc-adapter.ts: KRPCAdapter class that owns the KRPCClient - index.ts: entrypoint with MOCK MODE for development (emits synthetic state when no KSP is available, so you can verify the HTTP pipeline end-to-end) - 9 tests (7 conversion + 2 end-to-end bridge) - ksp/README.md: full setup guide - CKAN install, KSP server start, env vars - Hand-rolled KSP calls list (what SpaceCenter methods we need) - Roadmap for the remaining .proto-loading work - Protocol deep-dive (for the next dev) - Bug fixes along the way: protobufjs default import (not namespace), varint 32-bit truncation, JavaScript bitwise 32-bit limit, handshake status enum comparison (number vs string). End-to-end verified: API + bridge in mock mode, 2 bodies + 1 vessel arriving at /api/v1/state, 500ms polling cadence, automatic recovery on HTTP failures.
Arnike added 1 commit 2026-06-02 20:47:53 +00:00
Phase 1c: real kRPC bridge (full protocol + mock mode for development)
CI / Lint, typecheck, test, build (pull_request) Failing after 9s
68bc7015fd
- packages/krpc-client: TypeScript kRPC protocol client
  - connection.ts: varint encoding/decoding, length-prefix framing,
    per-socket read queue (avoids race when multiple read promises
    in flight). Uses multiplication not '<<' for varint shift
    because JS truncates << to 32 bits.
  - schema.ts: hand-written protobufjs schema for kRPC meta-protocol
    (ConnectionRequest, Request, Response, StreamUpdate, Status, etc.)
    - enough to do connection handshake, single procedure calls, and
      stream subscription. Service-specific types (SpaceCenter.Vessel,
    Orbit, CelestialBody) need to be loaded from the kRPC mod's
    .proto files at runtime.
  - client.ts: KRPCClient with connect/invoke/addStream/removeStream/
    onStreamUpdate/close. Tested with hand-rolled mock server.
  - 10 tests (varint round-trips incl. uint64, wire format with raw
    sockets).

- apps/tools/ksp-bridge: bridge that connects KSP to our API
  - convert.ts: pure kRPC -> UniverseSnapshot conversion
    (situation enum mapping, body id normalization, etc.)
  - bridge.ts: main poll loop with retry + backoff
  - krpc-adapter.ts: KRPCAdapter class that owns the KRPCClient
  - index.ts: entrypoint with MOCK MODE for development (emits
    synthetic state when no KSP is available, so you can verify the
    HTTP pipeline end-to-end)
  - 9 tests (7 conversion + 2 end-to-end bridge)

- ksp/README.md: full setup guide
  - CKAN install, KSP server start, env vars
  - Hand-rolled KSP calls list (what SpaceCenter methods we need)
  - Roadmap for the remaining .proto-loading work
  - Protocol deep-dive (for the next dev)

- Bug fixes along the way: protobufjs default import (not namespace),
  varint 32-bit truncation, JavaScript bitwise 32-bit limit,
  handshake status enum comparison (number vs string).

End-to-end verified: API + bridge in mock mode, 2 bodies + 1 vessel
arriving at /api/v1/state, 500ms polling cadence, automatic recovery
on HTTP failures.
Arnike merged commit bd1943510e into main 2026-06-02 20:48:02 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Arnike/KSP-MissionControl#4