# DISPATCH — worker_proto_server

## Identity
- Role: Protobuf & WebSocket Server Integration Worker
- Subagent Type: teamwork_preview_worker
- Working Directory: c:\Projects\FreeExile\.agents\teamwork\worker_proto_server
- Parent: orchestrator_20

## Mission
Implement Milestone M3: Protobuf compilation into Cocos TypeScript ES module, binary WebSocket bridge extension on port 8080 (2-byte Opcode framing), and server-authoritative reconciliation support.

## Authoritative Inputs
- Read ORIGINAL_REQUEST.md: `c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md` (specifically ## 2026-10-03T07:43:50Z)
- Read PROJECT.md: `c:\Projects\FreeExile\.agents\teamwork\orchestrator_20\PROJECT.md`
- Read survey report: `c:\Projects\FreeExile\.agents\teamwork\explorer_survey_2\survey_server_proto.md`

## Scope Boundaries & Exclusive Write Ownership
- You exclusively own:
  * `server/gateway/ws_gateway_bridge.py`
  * `scripts/compile_protos.py` (or script that generates bundle for Cocos)
  * `client/cocos/assets/scripts/proto/` (the generated protobufjs TypeScript bundle and typings)
  * Unit tests in `tests/unit/test_ws_protobuf_gateway.py`
- DO NOT touch files owned by `worker_cocos_client`.

## Mandatory Integrity Warning
DO NOT CHEAT. All implementations must be genuine. DO NOT hardcode test results, create dummy/facade implementations, or circumvent the intended task. A teamwork_preview_auditor will independently verify your work. Integrity violations WILL be detected and your work WILL be rejected.

## Native Lifecycle Hook Protocol
If any edit is blocked by Native Impact Guard (`[BLAST RADIUS BLOCKED]`), run:
`python tools/analysis/blast_radius.py --target <path> --ack`
to acknowledge dependencies and unlock editing for 30 minutes.

## Technical Specifications
1. Protobuf bundle for Cocos:
   - Ensure static ES module bundle with `.d.ts` definitions exists at `client/cocos/assets/scripts/proto/bundle.js` and `bundle.d.ts` (covering `PlayerMoveInput`, `CombatAction`, `EntityState`, `ZoneData`, `PacketEnvelope`, `TouchBiometrics`, `CastMartialSkillRequest`, `PhantomEvasionRequest`, etc.).
2. WebSocket Bridge (`server/gateway/ws_gateway_bridge.py`):
   - Listen on `127.0.0.1:8080`.
   - Dual-mode framing: Handle both text JSON frames (for legacy diagnostics) and binary frames (`bytes` / `bytearray`).
   - Binary frame protocol: First 2 bytes are big-endian uint16 opcode:
     * `0x0001`: `PacketEnvelope`
     * `0x0002`: `PlayerMoveInput`
     * `0x0003`: `EntityState`
     * `0x0004`: `ZoneData` / `ZoneInfoPayload`
     * `0x0010`: `CastMartialSkillRequest`
     * `0x0011`: `PhantomEvasionRequest`
     * `0x0012`: `CombatDamageEvent`
     * `0x0020`: `EnterZoneRequest`
     * `0x0021`: `ZonePortalData`
     * `0x0030`: `ChatMessage`
     * `0x0050`: `QuickRegisterRequest` / `LoginRequest`
   - Zero-Residual Momentum verification: On `PlayerMoveInput` with `input_x == 0 && input_y == 0`, server confirms instant halt without residual velocity.
   - Return appropriate binary response with opcode prefix.
3. Verification:
   - Write and run unit test `tests/unit/test_ws_protobuf_gateway.py` verifying binary packing/unpacking and WebSocket roundtrip.
   - Run `python tools/lint/check_code_and_doc_hygiene.py` to ensure <= 350 lines per logic file.

## Deliverables
- Fully functional binary Protobuf WebSocket bridge and compiled Cocos proto bundle.
- Passing tests documented in `handoff.md`.


## 2026-10-03T08:04:37Z
You are worker_proto_server. Working directory is c:\Projects\FreeExile\.agents\teamwork\worker_proto_server. Read your DISPATCH.md at c:\Projects\FreeExile\.agents\teamwork\worker_proto_server\DISPATCH.md, ORIGINAL_REQUEST.md at c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md, and survey report c:\Projects\FreeExile\.agents\teamwork\explorer_survey_2\survey_server_proto.md. Implement Milestone M3: compile Protobuf bundle to client/cocos/assets/scripts/proto/, extend server/gateway/ws_gateway_bridge.py with binary 2-byte opcode dispatch table and zero-residual momentum verification, run unit tests, write handoff.md, and notify parent.
