(msg)
| 182 | } |
| 183 | |
| 184 | function handleMessage(msg) { |
| 185 | serverMessages.push(msg); |
| 186 | const approvalResponse = buildAppServerApprovalResponse(msg, { decision: approvalDecision }); |
| 187 | if (approvalResponse) { |
| 188 | approvalResponses.push({ |
| 189 | requestId: msg.id, |
| 190 | method: msg.method, |
| 191 | itemId: msg.params?.itemId || null, |
| 192 | decision: approvalResponse.result?.decision || approvalResponse.result, |
| 193 | }); |
| 194 | send(approvalResponse); |
| 195 | return; |
| 196 | } |
| 197 | if (msg.id !== undefined && msg.method) { |
| 198 | unhandledServerRequests.push({ |
| 199 | id: msg.id, |
| 200 | method: msg.method, |
| 201 | }); |
| 202 | } |
| 203 | if (msg.id === 1 && msg.result) { |
| 204 | send({ method: 'initialized', params: {} }); |
| 205 | if (startThread) { |
| 206 | send({ method: 'thread/start', id: 2, params: { cwd: projectRoot } }); |
| 207 | } else { |
| 208 | scheduleFinish('initialize-complete'); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if (msg.id === 2 && msg.result?.thread?.id) { |
| 213 | threadId = msg.result.thread.id; |
| 214 | if (turnText) { |
| 215 | const params = { |
| 216 | threadId, |
| 217 | input: [{ type: 'text', text: turnText }], |
| 218 | }; |
| 219 | if (turnApprovalPolicy) params.approvalPolicy = turnApprovalPolicy; |
| 220 | if (turnSandboxPolicy) params.sandboxPolicy = turnSandboxPolicy; |
| 221 | send({ |
| 222 | method: 'turn/start', |
| 223 | id: 3, |
| 224 | params, |
| 225 | }); |
| 226 | } else { |
| 227 | scheduleFinish('thread-started'); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (turnText && msg.method === 'turn/completed') { |
| 232 | scheduleFinish('turn-completed'); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | proc.stdout.on('data', (chunk) => { |
| 237 | stdoutBuffer += chunk.toString(); |
no test coverage detected