# All files / src/trpc context.ts

100% Statements 1/1
100% Branches 0/0
100% Functions 1/1
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140

    87x

     /**
     * tRPC Context
     *
     * Defines the context available to all tRPC procedures.
     * Context is injected into each procedure call.
     */

    import type { EventBus, DomainEvent } from '../events/types.js';
    import type { AgentManager } from '../agent/types.js';
    import type { TaskRepository } from '../db/repositories/task-repository.js';
    import type { MessageRepository } from '../db/repositories/message-repository.js';
    import type { InitiativeRepository } from '../db/repositories/initiative-repository.js';
    import type { PhaseRepository } from '../db/repositories/phase-repository.js';
    import type { PageRepository } from '../db/repositories/page-repository.js';
    import type { ProjectRepository } from '../db/repositories/project-repository.js';
    import type { AccountRepository } from '../db/repositories/account-repository.js';
    import type { ChangeSetRepository } from '../db/repositories/change-set-repository.js';
    import type { LogChunkRepository } from '../db/repositories/log-chunk-repository.js';
    import type { ConversationRepository } from '../db/repositories/conversation-repository.js';
    import type { AccountCredentialManager } from '../agent/credentials/types.js';
    import type { DispatchManager, PhaseDispatchManager } from '../dispatch/types.js';
    import type { CoordinationManager } from '../coordination/types.js';
    import type { BranchManager } from '../git/branch-manager.js';
    import type { ExecutionOrchestrator } from '../execution/orchestrator.js';
    import type { PreviewManager } from '../preview/index.js';

    // Re-export for convenience
    export type { EventBus, DomainEvent };

    /**
     * Context available to all tRPC procedures.
     */
    export interface TRPCContext {
      /** Event bus for inter-module communication */
      eventBus: EventBus;
      /** When the server started (null if not yet started) */
      serverStartedAt: Date | null;
      /** Number of managed processes */
      processCount: number;
      /** Agent manager for agent lifecycle operations (optional until server wiring complete) */
      agentManager?: AgentManager;
      /** Task repository for task CRUD operations (optional until server wiring complete) */
      taskRepository?: TaskRepository;
      /** Message repository for agent-user communication (optional until server wiring complete) */
      messageRepository?: MessageRepository;
      /** Dispatch manager for task queue operations (optional until server wiring complete) */
      dispatchManager?: DispatchManager;
      /** Coordination manager for merge queue operations (optional until server wiring complete) */
      coordinationManager?: CoordinationManager;
      /** Initiative repository for initiative CRUD operations (optional until server wiring complete) */
      initiativeRepository?: InitiativeRepository;
      /** Phase repository for phase CRUD operations (optional until server wiring complete) */
      phaseRepository?: PhaseRepository;
      /** Phase dispatch manager for phase queue operations (optional until server wiring complete) */
      phaseDispatchManager?: PhaseDispatchManager;
      /** Page repository for page CRUD operations (optional until server wiring complete) */
      pageRepository?: PageRepository;
      /** Project repository for project CRUD and initiative-project junction operations */
      projectRepository?: ProjectRepository;
      /** Account repository for account CRUD and load balancing */
      accountRepository?: AccountRepository;
      /** Change set repository for agent change set operations */
      changeSetRepository?: ChangeSetRepository;
      /** Log chunk repository for agent output persistence */
      logChunkRepository?: LogChunkRepository;
      /** Credential manager for account OAuth token management */
      credentialManager?: AccountCredentialManager;
      /** Branch manager for git branch operations */
      branchManager?: BranchManager;
      /** Execution orchestrator for phase merge/review workflow */
      executionOrchestrator?: ExecutionOrchestrator;
      /** Preview manager for Docker-based preview deployments */
      previewManager?: PreviewManager;
      /** Conversation repository for inter-agent communication */
      conversationRepository?: ConversationRepository;
      /** Absolute path to the workspace root (.cwrc directory) */
      workspaceRoot?: string;
    }

    /**
     * Options for creating the tRPC context.
     */
    export interface CreateContextOptions {
      eventBus: EventBus;
      serverStartedAt: Date | null;
      processCount: number;
      agentManager?: AgentManager;
      taskRepository?: TaskRepository;
      messageRepository?: MessageRepository;
      dispatchManager?: DispatchManager;
      coordinationManager?: CoordinationManager;
      initiativeRepository?: InitiativeRepository;
      phaseRepository?: PhaseRepository;
      phaseDispatchManager?: PhaseDispatchManager;
      pageRepository?: PageRepository;
      projectRepository?: ProjectRepository;
      accountRepository?: AccountRepository;
      changeSetRepository?: ChangeSetRepository;
      logChunkRepository?: LogChunkRepository;
      credentialManager?: AccountCredentialManager;
      branchManager?: BranchManager;
      executionOrchestrator?: ExecutionOrchestrator;
      previewManager?: PreviewManager;
      conversationRepository?: ConversationRepository;
      workspaceRoot?: string;
    }

    /**
     * Creates the tRPC context for procedure calls.
     *
     * @param options - Context creation options
     * @returns The tRPC context
     */
    export function createContext(options: CreateContextOptions): TRPCContext {
      return {
        eventBus: options.eventBus,
        serverStartedAt: options.serverStartedAt,
        processCount: options.processCount,
        agentManager: options.agentManager,
        taskRepository: options.taskRepository,
        messageRepository: options.messageRepository,
        dispatchManager: options.dispatchManager,
        coordinationManager: options.coordinationManager,
        initiativeRepository: options.initiativeRepository,
        phaseRepository: options.phaseRepository,
        phaseDispatchManager: options.phaseDispatchManager,
        pageRepository: options.pageRepository,
        projectRepository: options.projectRepository,
        accountRepository: options.accountRepository,
        changeSetRepository: options.changeSetRepository,
        logChunkRepository: options.logChunkRepository,
        credentialManager: options.credentialManager,
        branchManager: options.branchManager,
        executionOrchestrator: options.executionOrchestrator,
        previewManager: options.previewManager,
        conversationRepository: options.conversationRepository,
        workspaceRoot: options.workspaceRoot,
      };
    }