()
| 125 | } |
| 126 | |
| 127 | protected async runMainLoop(): Promise<void> { |
| 128 | const session = this.session; |
| 129 | const messageBuffer = this.messageBuffer; |
| 130 | |
| 131 | this.setupAbortHandlers(session.client.rpcHandlerManager, { |
| 132 | onAbort: () => this.handleAbort(), |
| 133 | onSwitch: () => this.handleSwitchRequest() |
| 134 | }); |
| 135 | |
| 136 | const sendReady = () => { |
| 137 | session.sendSessionEvent({ type: 'ready' }); |
| 138 | }; |
| 139 | |
| 140 | let cursorSessionId: string | null = session.sessionId; |
| 141 | if (cursorSessionId) { |
| 142 | session.onSessionFoundWithProtocol(cursorSessionId, 'stream-json'); |
| 143 | } |
| 144 | |
| 145 | while (!this.shouldExit) { |
| 146 | const waitSignal = this.abortController.signal; |
| 147 | const batch = await session.queue.waitForMessagesAndGetAsString(waitSignal); |
| 148 | if (!batch) { |
| 149 | if (waitSignal.aborted && !this.shouldExit) { |
| 150 | continue; |
| 151 | } |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | const { message, mode, isolate: batchIsolated } = batch; |
| 156 | const specialCommand = parseCursorSpecialCommand(message); |
| 157 | |
| 158 | const { mode: agentMode, yolo } = permissionModeToAgentArgs(mode.permissionMode as string); |
| 159 | this.applyDisplayMode(mode.permissionMode as string); |
| 160 | messageBuffer.addMessage(message, 'user'); |
| 161 | |
| 162 | if (specialCommand.type === 'pass-through') { |
| 163 | logger.debug(`[cursor-remote] /${specialCommand.command} — pass-through to agent -p`); |
| 164 | messageBuffer.addMessage(cursorPassThroughStatusMessage(specialCommand.command), 'status'); |
| 165 | } |
| 166 | |
| 167 | const args = buildAgentArgs({ |
| 168 | message, |
| 169 | cwd: session.path, |
| 170 | sessionId: cursorSessionId, |
| 171 | mode: agentMode, |
| 172 | model: mode.model, |
| 173 | yolo |
| 174 | }); |
| 175 | |
| 176 | logger.debug(`[cursor-remote] Spawning agent with args: ${args.join(' ')}`); |
| 177 | |
| 178 | session.onThinkingChange(true); |
| 179 | |
| 180 | try { |
| 181 | const { exitCode, stderr } = await this.runAgentProcess(args, session.path, (event) => { |
| 182 | if (event.type === 'system' && event.subtype === 'init' && event.session_id) { |
| 183 | cursorSessionId = event.session_id; |
| 184 | session.onSessionFoundWithProtocol(event.session_id, 'stream-json'); |
nothing calls this directly
no test coverage detected