Add input validation to RPC command handler
The RPC command handler in rpc-mode.ts does not validate incoming JSONL commands before processing them. When a client sends a malformed command (e.g., {"type":"prompt","content":"..."} instead of the required {"type":"prompt","message":"..."}), the undefined field propagates into agent-session.ts and crashes with an opaque error:
Cannot read properties of undefined (reading 'startsWith')
Current Behavior
- No schema validation on incoming RPC commands
- Missing/misspelled fields pass through as
undefined
- Crashes surface as internal JS errors rather than actionable RPC error responses
Proposed Behavior
- Validate required fields before dispatching commands (at minimum:
message on prompt, steer, and follow_up)
- Return a clear RPC error response for invalid commands, e.g.:
{"type":"response","command":"prompt","success":false,"error":"Missing required field 'message' in prompt command"}
- Never let
undefined reach session.prompt()
Relevant Files
packages/coding-agent/src/modes/rpc/rpc-mode.ts — handleCommand() dispatch
packages/coding-agent/src/modes/rpc/rpc-types.ts — RpcCommand type definitions
Context
Discovered via issue 253 — a client sent content instead of message, which crashed the agent instead of returning a validation error. Low priority since the fix is on the client side, but better error messages would save debugging time.
Add input validation to RPC command handler
The RPC command handler in
rpc-mode.tsdoes not validate incoming JSONL commands before processing them. When a client sends a malformed command (e.g.,{"type":"prompt","content":"..."}instead of the required{"type":"prompt","message":"..."}), the undefined field propagates intoagent-session.tsand crashes with an opaque error:Current Behavior
undefinedProposed Behavior
messageonprompt,steer, andfollow_up){"type":"response","command":"prompt","success":false,"error":"Missing required field 'message' in prompt command"}undefinedreachsession.prompt()Relevant Files
packages/coding-agent/src/modes/rpc/rpc-mode.ts—handleCommand()dispatchpackages/coding-agent/src/modes/rpc/rpc-types.ts—RpcCommandtype definitionsContext
Discovered via issue 253 — a client sent
contentinstead ofmessage, which crashed the agent instead of returning a validation error. Low priority since the fix is on the client side, but better error messages would save debugging time.