Deadworks relay

From deadlock-mod-manager/deadlock-mod-manager · View interactive version

Deadworks relay is an AI agent skill from the GitHub repository deadlock-mod-manager/deadlock-mod-manager. Update the Deadlock Mod Manager server browser implementation to match the latest Deadworks Relay Mesh Protocol v1 spec at ../deadworks-relay/spec/PROTOCOL.md. Use when the user asks to "sync server browser with relay spec", "update relay protocol", "match deadworks-relay spec", "update required_mod

How to use this skill

Skill file

Sync Server Browser With Deadworks Relay Spec

Bring the DMM server browser stack (relay client, API service, desktop UI) into compliance with the latest Deadworks Relay Mesh Protocol v1 defined at ../deadworks-relay/spec/PROTOCOL.md and the canonical TypeScript types at ../deadworks-relay/packages/protocol/src/index.ts.

The reference spec lives outside this monorepo. Always re-read it before making changes — it evolves independently.

Authoritative Spec Sources

Treat these as the single source of truth, in priority order:

  1. ../deadworks-relay/packages/protocol/src/index.ts — canonical TS types (ModRequirement, ServerListItem, RegistrationPayload, HeartbeatPayload, AuthConfig, PendingChallenge, etc.).
  2. ../deadworks-relay/spec/PROTOCOL.md — formal protocol prose (endpoints, error codes, gossip rules, auth flow, visibility semantics).
  3. ../deadworks-relay/relays.json — bootstrap manifest example (verifies RelaysManifest shape).
  4. ../deadworks-relay/apps/relay-server/ — reference relay implementation. Use as a sanity check, never as spec.

If protocol/src/index.ts and PROTOCOL.md disagree, prefer the TS file but flag the discrepancy to the user.

Files Owned By This Skill

These are the files the protocol shape flows through. Update them together:

| Layer | File | Role |

| -------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |

| Relay client | packages/relay-client/src/schemas.ts | Zod schemas mirroring spec response shapes |

| Relay client | packages/relay-client/src/client.ts | HTTP calls to /api/v1/servers, /api/v1/servers/{id}, /api/v1/relays, relays.json |

| Relay client | packages/relay-client/src/index.ts | Re-exports |

| Shared schemas | packages/shared/src/schemas/server-browser.schemas.ts | DMM-facing schemas (with aggregation extras like source_relay) |

| API aggregator | apps/api/src/services/server-browser.ts | Fans out across relays, dedupes, paginates |

| API resolver | apps/api/src/services/server-mods-resolver.ts | Maps required_mods entries to local DMM mods |

| API discovery | apps/api/src/services/relay-discovery.ts | Loads relays.json, tracks per-relay health |

| API router | apps/api/src/routers/v2/servers.ts | oRPC routes that expose the schemas |

| Desktop API | apps/desktop/src/lib/api.ts | Client wrappers used by the UI |

| Desktop hooks | apps/desktop/src/hooks/use-server-browser-data.ts, use-server-join.ts | React Query hooks |

| Desktop UI | apps/desktop/src/components/server-browser/** | Server table, detail panel, join dialog, mods section |

Step 1: Read the Current Spec

Before any edits, read in this order:

  1. ../deadworks-relay/packages/protocol/src/index.ts (full file)
  2. ../deadworks-relay/spec/PROTOCOL.md (sections 1–12 and the auth + gossip prose)
  3. The current DMM relay-client and shared schemas listed above

Compare each TS interface in protocol/src/index.ts to the matching Zod schema in DMM. Build a mental delta table before touching code.

Step 2: Build the Delta Table

For every protocol type, classify it:

| Classification | Action |

| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| Identical shape | No change |

| New optional field | Add to schema with .optional() (and .default(...) only when the spec mandates a default for absent values) |

| New required field | Add as required, propagate through aggregator/UI, plan migration for cached payloads |

| Renamed field | Update schema + every consumer in one pass; do not leave shims unless explicitly requested |

| Removed field | Remove from schema and every consumer; check for stale UI references (grep for the old name) |

| Changed type/enum | Update schema; check .catch(...) fallbacks in zod (e.g. VisibilitySchema.catch("public") is intentional — preserve unknown-value tolerance unless the spec narrows it) |

Present the delta table to the user before making non-trivial changes.

Step 3: Known Recurring Drift Points

These are the fields most likely to be out of sync — check them every run:

`required_mods[]` shape (highest churn)

Spec (ModRequirement in protocol/src/index.ts):

{ id: string; provider: "gamebanana" | "custom"; url: string; version?: string }

If the DMM ModRequirementSchema in packages/relay-client/src/schemas.ts and packages/shared/src/schemas/server-browser.schemas.ts does not match, update both. Then audit:

`auth_config` flattening

The spec sends auth as a nested auth_config object on registration but flattens it on the public list/get response (auth_required, auth_providers, auth_public_key, auth_prompt_message, auth_prompt_url). DMM consumes only the flattened form. Verify this is still true on each spec sync.

`gateway_url`

Top-level on both registration and list responses. DMM already honors this in server-join/join-action.ts (opens externally, takes precedence over connect code). Do not regress that ordering.

Visibility enum

Spec set: public, unlisted, private, password. Server lists only return public and password (per §5). DMM keeps the full enum since getServer(id) may return unlisted. Preserve .catch("public") to tolerate future additions from older clients.

`relays.json`

Schema is { version: 1, relays: [{ url, region? }] }. RelaysManifestSchema must use z.literal(1) for the version field.

Step 4: Apply Changes In Layers

Work outside-in. Do not start from the UI; types must flow downward.

  1. Relay client schemas (packages/relay-client/src/schemas.ts)
  1. Relay client transport (packages/relay-client/src/client.ts)
  1. Shared schemas (packages/shared/src/schemas/server-browser.schemas.ts)
  1. API services (apps/api/src/services/*.ts)
  1. API router (apps/api/src/routers/v2/servers.ts)
  1. Desktop API client (apps/desktop/src/lib/api.ts)
  1. Desktop hooks and components

Step 5: Cache & Compatibility

The API aggregator caches list/detail responses in Redis (CACHE_TTL.SERVERS_LIST, CACHE_TTL.SERVER_DETAIL, CACHE_TTL.SERVERS_FACETS). When response shape changes:

Step 6: Verify

Run each of these and fix issues before stopping:

pnpm --filter @deadlock-mods/relay-client check-types
pnpm --filter @deadlock-mods/shared check-types
pnpm --filter @deadlock-mods/api check-types
pnpm --filter @deadlock-mods/desktop check-types
pnpm lint:fix
pnpm format:fix

Then exercise the path manually if changes are user-visible:

  1. Start the local relay sim per ../deadworks-relay/README.md:

```bash

cd ../deadworks-relay && bun install && bun run sim:dev

```

  1. Point DMM API at it (RELAYS_JSON_URL=http://127.0.0.1:3000/relays.json or the local seed file).
  2. Open the server browser tab in the desktop app and confirm:

If the relay sim is not available, at minimum write a Vitest case that parses a fixture payload generated from ../deadworks-relay/packages/protocol/src/index.ts types.

Step 7: Changeset

Follow changeset for any user-visible change. Use a minor bump if the public DMM API client surface changes; patch otherwise.

Example body:

Sync relay client and server browser with Deadworks Relay protocol v1
spec at <commit-or-date>. Updates `required_mods` shape to
`{ id, provider, url, version }` and adjusts the resolver to parse
GameBanana IDs from `url` instead of `name`. Bumps server browser
cache keys to invalidate stale Redis payloads.

Hard Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.