---
phase: 01.1-hexagonal-architecture
plan: 02
type: execute
wave: 1
depends_on: []
files_modified: [package.json, src/trpc/router.ts, src/trpc/context.ts, src/trpc/index.ts, src/trpc/router.test.ts]
autonomous: true
---

<objective>
Create tRPC foundation for type-safe CLI-server communication.

Purpose: Establish the tRPC contract that CLI and future WebUI will use to communicate with the server. Same interface for all clients.
Output: Working tRPC router with procedures matching existing HTTP endpoints, fully tested.
</objective>

<execution_context>
@~/.claude/get-shit-done/workflows/execute-plan.md
@~/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/01.1-hexagonal-architecture/1.1-CONTEXT.md

@src/server/index.ts
@src/server/types.ts
@package.json
</context>

<tasks>

<task type="auto">
  <name>Task 1: Install tRPC dependencies and create router foundation</name>
  <files>package.json, src/trpc/router.ts, src/trpc/context.ts, src/trpc/index.ts</files>
  <action>
    Install dependencies:
    - npm install @trpc/server zod
    - npm install -D @trpc/client (for testing)

    Create src/trpc/context.ts:
    - Define TRPCContext type containing:
      - eventBus: EventBus (from src/events - import the interface type)
      - serverStartedAt: Date | null
      - processCount: number
    - Export createContext function that builds context
    - Context will be injected into procedures

    Create src/trpc/router.ts:
    - Initialize tRPC with initTRPC.context<TRPCContext>().create()
    - Create base router and procedure helpers
    - Export router, publicProcedure

    Create src/trpc/index.ts:
    - Export router, context, types
    - Export AppRouter type for client usage

    Note: Don't import actual EventBus implementation yet - just the type.
    This keeps tRPC foundation independent of event bus implementation.
  </action>
  <verify>npm run build succeeds, no import errors</verify>
  <done>tRPC initialized, context defined, router foundation in place</done>
</task>

<task type="auto">
  <name>Task 2: Define procedures matching HTTP endpoints with tests</name>
  <files>src/trpc/router.ts, src/trpc/router.test.ts</files>
  <action>
    Add procedures to src/trpc/router.ts:

    health procedure (query):
    - Input: none
    - Output: { status: 'ok', uptime: number, processCount: number }
    - Uses context.serverStartedAt to calculate uptime
    - Use Zod for output validation

    status procedure (query):
    - Input: none
    - Output: { server: { startedAt: string, uptime: number, pid: number }, processes: Array }
    - More detailed than health
    - Use Zod for output validation

    Create appRouter that combines procedures.
    Export AppRouter type: typeof appRouter

    Create src/trpc/router.test.ts:
    - Use @trpc/server/adapters/standalone for testing (or direct caller)
    - Test health procedure returns correct shape
    - Test status procedure returns correct shape
    - Test with mocked context (no real server needed)
    - Verify Zod validation catches bad outputs

    Testing approach: Use createCallerFactory from tRPC for direct procedure calls without HTTP.
  </action>
  <verify>npm test passes with tRPC router tests green</verify>
  <done>Procedures defined, Zod validation in place, tests pass</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds
- [ ] npm test passes (tRPC router tests)
- [ ] AppRouter type is exported
- [ ] health and status procedures work
- [ ] Zod schemas validate outputs
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- tRPC router ready for HTTP adapter integration
- Type-safe contract established
</success_criteria>

<output>
After completion, create `.planning/phases/01.1-hexagonal-architecture/01.1-02-SUMMARY.md`
</output>
