Phase 1c: real kRPC bridge (full protocol + mock mode for development)
CI / Lint, typecheck, test, build (pull_request) Failing after 9s

- 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.
This commit is contained in:
Mavis
2026-06-02 20:42:54 +00:00
parent 07cc5321d1
commit 68bc7015fd
20 changed files with 2286 additions and 101 deletions
+150
View File
@@ -143,6 +143,28 @@ importers:
specifier: ^2.1.1
version: 2.1.9(@types/node@22.19.19)
apps/tools/ksp-bridge:
dependencies:
'@kerbal-rt/krpc-client':
specifier: workspace:*
version: link:../../../packages/krpc-client
'@kerbal-rt/shared-types':
specifier: workspace:*
version: link:../../../packages/shared-types
devDependencies:
'@types/node':
specifier: ^22.5.0
version: 22.19.19
tsx:
specifier: ^4.19.1
version: 4.22.4
typescript:
specifier: ^5.6.2
version: 5.9.3
vitest:
specifier: ^2.1.1
version: 2.1.9(@types/node@22.19.19)
apps/tools/mock-telemetry:
dependencies:
'@kerbal-rt/orbital-math':
@@ -181,6 +203,22 @@ importers:
specifier: ^2.1.1
version: 2.1.9(@types/node@22.19.19)
packages/krpc-client:
dependencies:
protobufjs:
specifier: ^7.4.0
version: 7.6.2
devDependencies:
'@types/node':
specifier: ^22.5.0
version: 22.19.19
typescript:
specifier: ^5.6.2
version: 5.9.3
vitest:
specifier: ^2.1.1
version: 2.1.9(@types/node@22.19.19)
packages/orbital-math:
dependencies:
'@kerbal-rt/shared-types':
@@ -1084,6 +1122,66 @@ packages:
}
engines: { node: '>=14' }
'@protobufjs/aspromise@1.1.2':
resolution:
{
integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==,
}
'@protobufjs/base64@1.1.2':
resolution:
{
integrity: sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==,
}
'@protobufjs/codegen@2.0.5':
resolution:
{
integrity: sha512-zgXFLzW3Ap33e6d0Wlj4MGIm6Ce8O89n/apUaGNB/jx+hw+ruWEp7EwGUshdLKVRCxZW12fp9r40E1mQrf/34g==,
}
'@protobufjs/eventemitter@1.1.1':
resolution:
{
integrity: sha512-vW1GmwMZNnL+gMRaovlh9yZX74kc+TTU3FObkkurpMaRtBfLP3ldjS9KQWlwZgraRE0+dheEEoAxdzcJQ8eXZg==,
}
'@protobufjs/fetch@1.1.1':
resolution:
{
integrity: sha512-GpptLrs57adMSuHi3VNj0mAF8dwh36LMaYF6XyJ6JMWlVsc+t42tm1HSEDmOs3A8fC9yyeisgLhsTVQokOZ0zw==,
}
'@protobufjs/float@1.0.2':
resolution:
{
integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==,
}
'@protobufjs/inquire@1.1.2':
resolution:
{
integrity: sha512-pa0vFRuws4wkvaXKK1uXZMAwAX4/t8ANaJo45iw/oQHNQ9q5xUzwgFmVJGXiga2BeN+zpX7Vf9vmsiIa2J+MUw==,
}
'@protobufjs/path@1.1.2':
resolution:
{
integrity: sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==,
}
'@protobufjs/pool@1.1.0':
resolution:
{
integrity: sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==,
}
'@protobufjs/utf8@1.1.1':
resolution:
{
integrity: sha512-oOAWABowe8EAbMyWKM0tYDKi8Yaox52D+HWZhAIJqQXbqe0xI/GV7FhLWqlEKreMkfDjshR5FKgi3mnle0h6Eg==,
}
'@rolldown/pluginutils@1.0.0-beta.27':
resolution:
{
@@ -3110,6 +3208,12 @@ packages:
integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==,
}
long@5.3.2:
resolution:
{
integrity: sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==,
}
loose-envify@1.4.0:
resolution:
{
@@ -3456,6 +3560,13 @@ packages:
integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==,
}
protobufjs@7.6.2:
resolution:
{
integrity: sha512-N9EiLovGEQOJSPF26Ij7qUGvahfEnq0eeYZ02aigIedkmz1qZSwjnP9SBITHJuF/6MYbIW4HDN8zdYjsjqJKXQ==,
}
engines: { node: '>=12.0.0' }
punycode@2.3.1:
resolution:
{
@@ -4607,6 +4718,28 @@ snapshots:
'@pkgjs/parseargs@0.11.0':
optional: true
'@protobufjs/aspromise@1.1.2': {}
'@protobufjs/base64@1.1.2': {}
'@protobufjs/codegen@2.0.5': {}
'@protobufjs/eventemitter@1.1.1': {}
'@protobufjs/fetch@1.1.1':
dependencies:
'@protobufjs/aspromise': 1.1.2
'@protobufjs/float@1.0.2': {}
'@protobufjs/inquire@1.1.2': {}
'@protobufjs/path@1.1.2': {}
'@protobufjs/pool@1.1.0': {}
'@protobufjs/utf8@1.1.1': {}
'@rolldown/pluginutils@1.0.0-beta.27': {}
'@rollup/rollup-android-arm-eabi@4.61.0':
@@ -5978,6 +6111,8 @@ snapshots:
lodash.merge@4.6.2: {}
long@5.3.2: {}
loose-envify@1.4.0:
dependencies:
js-tokens: 4.0.0
@@ -6176,6 +6311,21 @@ snapshots:
object-assign: 4.1.1
react-is: 16.13.1
protobufjs@7.6.2:
dependencies:
'@protobufjs/aspromise': 1.1.2
'@protobufjs/base64': 1.1.2
'@protobufjs/codegen': 2.0.5
'@protobufjs/eventemitter': 1.1.1
'@protobufjs/fetch': 1.1.1
'@protobufjs/float': 1.0.2
'@protobufjs/inquire': 1.1.2
'@protobufjs/path': 1.1.2
'@protobufjs/pool': 1.1.0
'@protobufjs/utf8': 1.1.1
'@types/node': 22.19.19
long: 5.3.2
punycode@2.3.1: {}
queue-microtask@1.2.3: {}