@myrobotaxi/contracts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,67 @@
1
+ # Contributing to @myrobotaxi/contracts
2
+
3
+ This package is the canonical wire-protocol surface for the MyRoboTaxi platform. Changes here affect downstream consumers across the TypeScript SDK, the Go telemetry server, and (eventually) the Swift SDK.
4
+
5
+ ## Schema-authoring policy
6
+
7
+ Schemas in this repo are currently **vendored** from `myrobotaxi/telemetry/docs/contracts/schemas/`. The telemetry repo is the active authoring home.
8
+
9
+ This means any schema change requires:
10
+
11
+ 1. Open a PR in [`myrobotaxi/telemetry`](https://github.com/myrobotaxi/telemetry) that edits the source `.schema.json` file under `docs/contracts/schemas/`. Get it reviewed and merged.
12
+ 2. Open a paired PR in this repo that:
13
+ - Copies the new schema file from the telemetry repo into `schemas/`
14
+ - Runs `npm run codegen` to regenerate `src/generated/`
15
+ - Commits the regenerated `.ts` files
16
+ - Bumps the version per the [versioning policy](#versioning-policy)
17
+
18
+ Until [Phase 2](#phase-2-migration-authoring-home) ships, this paired-PR convention is enforced by review (no automation).
19
+
20
+ ## Versioning policy
21
+
22
+ Per `NFR-3.37` (telemetry repo contracts/README.md):
23
+
24
+ - **Major version bump** (`v1.0.0` → `v2.0.0`) — any breaking wire change: removing a field, narrowing a type, tightening a `required` array, removing an enum member.
25
+ - **Minor version bump** (`v1.0.0` → `v1.1.0`) — additive, backwards-compatible: new optional field, new message type, new enum member on an append-only enum.
26
+ - **Patch version bump** (`v1.0.0` → `v1.0.1`) — documentation/annotation changes that don't alter the generated TypeScript surface.
27
+
28
+ The contracts package is currently pre-1.0 (`v0.x.y`), so all changes may be minor or patch. The first wire-stable cut will be tagged `v1.0.0`.
29
+
30
+ ## Custom JSON Schema annotations
31
+
32
+ The MyRoboTaxi schemas use these non-standard keywords:
33
+
34
+ | Keyword | Purpose |
35
+ |---|---|
36
+ | `x-classification` | P0/P1 data classification per `data-classification.md` |
37
+ | `x-atomic-group` | Marks a field as part of an atomic-delivery group |
38
+ | `x-atomic-groups` | Root-level definition of all atomic groups |
39
+ | `x-unit` | Physical unit for numeric fields (`mph`, `degrees`, `percent`, etc.) |
40
+ | `x-encrypted` / `x-encrypted-at-rest` | AES-256-GCM at rest |
41
+ | `x-tesla-proto-field` | Source Tesla protobuf field number |
42
+
43
+ The codegen pipeline (`scripts/codegen.mjs`) **folds these into TSDoc comments** at generation time, so they survive into the consumer's editor as `@classification "P0"` annotations.
44
+
45
+ If you add a new `x-*` keyword to a schema, add it to the `ANNOTATIONS` array in `scripts/codegen.mjs` and re-run `npm run codegen`.
46
+
47
+ ## Release process
48
+
49
+ 1. Land your PR on `main` (CI green: lint + typecheck + test + codegen-drift + build).
50
+ 2. Bump `package.json` `version` per the [versioning policy](#versioning-policy).
51
+ 3. Tag: `git tag v0.1.X && git push --tags`.
52
+ 4. The `release.yml` workflow publishes to npm with `provenance: true` via GitHub Actions OIDC.
53
+
54
+ ## Phase 2 migration (authoring home)
55
+
56
+ A planned follow-up issue (filed after MYR-49 ships) moves the schema authoring home from `telemetry/docs/contracts/schemas/` into this repo. After that lands:
57
+
58
+ - The telemetry repo's Go contract-tester will consume `@myrobotaxi/contracts` (either via vendored JSON or a Go submodule).
59
+ - The paired-PR convention drops out — schemas have a single home.
60
+ - This file will be updated to reflect the new workflow.
61
+
62
+ ## Code style
63
+
64
+ - TypeScript strict mode; `verbatimModuleSyntax` on.
65
+ - `import type` for type-only imports.
66
+ - Generated code in `src/generated/` is excluded from lint (it's auto-emitted).
67
+ - Manual edits in `src/` must pass `npm run lint && npm run typecheck && npm run test`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thomas Nandola
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @myrobotaxi/contracts
2
+
3
+ Canonical wire-protocol schemas for the MyRoboTaxi platform.
4
+
5
+ - **JSON Schema (draft-2020-12)** under `schemas/` — the language-neutral source of truth.
6
+ - **Pre-generated TypeScript types** under `dist/` (via the `./types` subpath) — produced by `json-schema-to-typescript` and committed to `src/generated/` for diff review.
7
+
8
+ Consumed by [@myrobotaxi/sdk](https://github.com/myrobotaxi/typescript-sdk), the Go [telemetry server](https://github.com/myrobotaxi/telemetry), and the [react-frontend](https://github.com/myrobotaxi/react-frontend) Next.js app.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @myrobotaxi/contracts
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Type-only import (no runtime payload, tree-shakes to zero bytes):
19
+
20
+ ```ts
21
+ import type { VehicleState, WebSocketEnvelope } from '@myrobotaxi/contracts/types';
22
+ ```
23
+
24
+ Runtime schemas for Ajv / runtime validation:
25
+
26
+ ```ts
27
+ import { schemas } from '@myrobotaxi/contracts';
28
+ // schemas.vehicleState, schemas.wsMessages, schemas.wsEnvelope
29
+ ```
30
+
31
+ Raw JSON for non-JS consumers (Go, Swift):
32
+
33
+ ```
34
+ ./node_modules/@myrobotaxi/contracts/schemas/vehicle-state.schema.json
35
+ ./node_modules/@myrobotaxi/contracts/schemas/ws-messages.schema.json
36
+ ./node_modules/@myrobotaxi/contracts/schemas/ws-envelope.schema.json
37
+ ```
38
+
39
+ ## What's in the generated TypeScript
40
+
41
+ Custom JSON Schema annotations from the source schemas — `x-classification`, `x-atomic-group`, `x-unit`, `x-encrypted`, `x-tesla-proto-field` — are folded into the generated TSDoc comments at codegen time. This means consumers can `grep '@classification "P1"'` inside their `node_modules` to find every sensitive field without leaving their editor.
42
+
43
+ ```ts
44
+ /**
45
+ * GPS latitude. Encrypted at rest (AES-256-GCM) per FR-11.1.
46
+ *
47
+ * @classification "P1"
48
+ * @atomic-group "gps"
49
+ * @encrypted true
50
+ */
51
+ latitude: number;
52
+ ```
53
+
54
+ ## Tool choice: `json-schema-to-typescript`
55
+
56
+ We picked `json-schema-to-typescript` v15+ over `quicktype` for three reasons:
57
+
58
+ 1. **Matches the telemetry repo's existing convention.** The Go-side [`vehicle-state-schema.md` §6.1](https://github.com/myrobotaxi/telemetry/blob/main/docs/contracts/vehicle-state-schema.md) already documents `json-schema-to-typescript` as the TS-side tool. Picking the same one in the contracts package guarantees zero drift between the docs and the actual output.
59
+ 2. **Pure JS (no Rust binary).** Easier to vendor into CI, no platform-specific install issues.
60
+ 3. **TSDoc-preserving.** The `description` field on each JSON Schema property is copied verbatim into the generated TSDoc comment. `quicktype` produces leaner runtime helpers (parsers / serializers) but does not preserve descriptions as cleanly, and we don't need its runtime artifacts here.
61
+
62
+ The trade-off is that `quicktype`'s discriminated-union handling for `oneOf` payloads is more idiomatic. The current schemas use a nullable-enum-with-explicit-null pattern instead of `oneOf`, so this doesn't bite us yet. If the schema set grows to need true discriminated unions, we may revisit.
63
+
64
+ ## Schema-authoring policy
65
+
66
+ Schemas in this repo are **vendored** from [`myrobotaxi/telemetry/docs/contracts/schemas/`](https://github.com/myrobotaxi/telemetry/tree/main/docs/contracts/schemas) — that repo is the current authoring home.
67
+
68
+ Until [Phase 2](#phase-2-migration) ships, schema changes require a **paired PR** to this repo (mirroring the change here, re-running codegen, bumping the version).
69
+
70
+ ## Phase 2 migration
71
+
72
+ A planned follow-up moves the schema authoring home from `telemetry/docs/contracts/schemas/` into this repo, eliminating the paired-PR requirement. After Phase 2, the telemetry server's Go contract-tester will consume the published `@myrobotaxi/contracts` package directly.
73
+
74
+ ## Versioning policy
75
+
76
+ - **Major version bump** required for any wire-incompatible change (per NFR-3.37 in the telemetry docs).
77
+ - **Minor version bump** for additive, backwards-compatible additions (new optional fields, new message types, new enum members on append-only enums).
78
+ - **Patch version bump** for documentation / annotation changes that don't alter the generated TypeScript surface.
79
+
80
+ ## Development
81
+
82
+ ```bash
83
+ npm install
84
+ npm run codegen # regenerate src/generated/ from schemas/
85
+ npm run typecheck
86
+ npm run test
87
+ npm run build # tsup → dist/
88
+ ```
89
+
90
+ CI runs `codegen` and fails if `src/generated/` drifts from the schemas — every schema bump must be paired with a regenerate-and-commit.
91
+
92
+ ## License
93
+
94
+ MIT