/ server / types.ts
types.ts
 1  import type { ChildProcess } from 'child_process'
 2  import { z } from 'zod/v4'
 3  import { lazySchema } from '../utils/lazySchema.js'
 4  
 5  export const connectResponseSchema = lazySchema(() =>
 6    z.object({
 7      session_id: z.string(),
 8      ws_url: z.string(),
 9      work_dir: z.string().optional(),
10    }),
11  )
12  
13  export type ServerConfig = {
14    port: number
15    host: string
16    authToken: string
17    unix?: string
18    /** Idle timeout for detached sessions (ms). 0 = never expire. */
19    idleTimeoutMs?: number
20    /** Maximum number of concurrent sessions. */
21    maxSessions?: number
22    /** Default workspace directory for sessions that don't specify cwd. */
23    workspace?: string
24  }
25  
26  export type SessionState =
27    | 'starting'
28    | 'running'
29    | 'detached'
30    | 'stopping'
31    | 'stopped'
32  
33  export type SessionInfo = {
34    id: string
35    status: SessionState
36    createdAt: number
37    workDir: string
38    process: ChildProcess | null
39    sessionKey?: string
40  }
41  
42  /**
43   * Stable session key → session metadata. Persisted to ~/.claude/server-sessions.json
44   * so sessions can be resumed across server restarts.
45   */
46  export type SessionIndexEntry = {
47    /** Server-assigned session ID (matches the subprocess's claude session). */
48    sessionId: string
49    /** The claude transcript session ID for --resume. Same as sessionId for direct sessions. */
50    transcriptSessionId: string
51    cwd: string
52    permissionMode?: string
53    createdAt: number
54    lastActiveAt: number
55  }
56  
57  export type SessionIndex = Record<string, SessionIndexEntry>