refactor: share IPC message types between CLI and daemon #93

Closed
opened 2026-04-24 15:06:16 +00:00 by xiaoju · 0 comments
Owner

Problem

CLI (daemon-client.ts) and daemon (ipc.ts / daemon-ipc.ts) each define their own IPC message shapes independently. The sendAndReceive function accepts message: object with no type constraint, so when the daemon protocol changes (e.g. payloadprompt + maxRounds), the CLI compiles fine but fails at runtime.

This just caused a real bug: CLI was sending { type: 'trigger-workflow', workflow, payload } but daemon expected { type: 'trigger-workflow', workflow, prompt, maxRounds }. TypeScript caught nothing.

Solution

  1. Define shared IPC request/response types in a common place (either @uncaged/nerve-core or exported from @uncaged/nerve-daemon)
  2. Type sendAndReceive message parameter against the shared union type
  3. Have daemon's parseRequest and CLI's triggerWorkflowViaDaemon both reference the same type
  4. Any future protocol change should cause compile errors on both sides

Scope

  • packages/daemon/src/ipc.tsStartThreadMessage, ResumeThreadMessage, etc.
  • packages/daemon/src/daemon-ipc.tsDaemonRequest parsing
  • packages/cli/src/daemon-client.tssendAndReceive, triggerWorkflowViaDaemon, etc.

Ref

Fix for the immediate bug was done in CLI (changed payloadprompt + maxRounds), but the structural problem remains.

小橘 🍊(NEKO Team)

## Problem CLI (`daemon-client.ts`) and daemon (`ipc.ts` / `daemon-ipc.ts`) each define their own IPC message shapes independently. The `sendAndReceive` function accepts `message: object` with no type constraint, so when the daemon protocol changes (e.g. `payload` → `prompt + maxRounds`), the CLI compiles fine but fails at runtime. This just caused a real bug: CLI was sending `{ type: 'trigger-workflow', workflow, payload }` but daemon expected `{ type: 'trigger-workflow', workflow, prompt, maxRounds }`. TypeScript caught nothing. ## Solution 1. Define shared IPC request/response types in a common place (either `@uncaged/nerve-core` or exported from `@uncaged/nerve-daemon`) 2. Type `sendAndReceive` message parameter against the shared union type 3. Have daemon's `parseRequest` and CLI's `triggerWorkflowViaDaemon` both reference the same type 4. Any future protocol change should cause compile errors on both sides ## Scope - `packages/daemon/src/ipc.ts` — `StartThreadMessage`, `ResumeThreadMessage`, etc. - `packages/daemon/src/daemon-ipc.ts` — `DaemonRequest` parsing - `packages/cli/src/daemon-client.ts` — `sendAndReceive`, `triggerWorkflowViaDaemon`, etc. ## Ref Fix for the immediate bug was done in CLI (changed `payload` → `prompt + maxRounds`), but the structural problem remains. 小橘 🍊(NEKO Team)
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#93