diff --git a/electron/coding-runtime/pi/release-proof.ts b/electron/coding-runtime/pi/release-proof.ts index 31476cd..a4716a7 100644 --- a/electron/coding-runtime/pi/release-proof.ts +++ b/electron/coding-runtime/pi/release-proof.ts @@ -405,8 +405,16 @@ function respondWithHoldingBashCall(response: ServerResponse, model: string): vo response.end('data: [DONE]\n\n'); } -function requestContains(body: Record, marker: string): boolean { - return JSON.stringify(body.messages ?? []).includes(marker); +function latestUserMessageContains(body: Record, marker: string): boolean { + if (!Array.isArray(body.messages)) return false; + for (let index = body.messages.length - 1; index >= 0; index -= 1) { + const message = body.messages[index]; + if (!message || typeof message !== 'object' || Array.isArray(message)) continue; + const record = message as { role?: unknown; content?: unknown }; + if (record.role !== 'user') continue; + return JSON.stringify(record.content ?? '').includes(marker); + } + return false; } async function startLocalProofProvider(mode: ProofProviderMode): Promise { @@ -434,18 +442,26 @@ async function startLocalProofProvider(mode: ProofProviderMode): Promise held.delete(entry)); + return; + } + if (latestUserMessageContains(body, 'RESILIENCE_TARGET_ACTIVE')) { + respondWithSubagentCall(response, model, 'coding'); + return; + } response.writeHead(200, { 'content-type': 'text/event-stream' }); writeChunk(response, model, { role: 'assistant', content: 'RESILIENCE_ACTIVE' }, null); const entry = { role, response };