Files
Netcatty/electron/bridges/aiBridge/sdk/cursorTurnWorker.cjs
T
陈大猫 faeaa238e9 feat: share reversible AI privacy across Catty, agents, and MCP (#3805)
Share opt-in, reversible privacy masking through main-owned policy and conversation maps across Catty, integrated agents, and External MCP. Restore managed arguments before validation, approval, and execution; fail closed on retired policy state. Add shared settings, documentation, boundary and lifecycle regressions.

Validated with deterministic regressions, production desktop smoke, clean Codex review and passing cross-platform CI.

Closes #3620
2026-10-21 01:29:17 +08:00

47 lines
1.5 KiB
JavaScript

"use strict";
const { runCursorTurnInProcess } = require("./cursorDriver.cjs");
const controller = new AbortController();
const emitter = {};
for (const method of [
"text", "reasoning", "reasoningEnd", "toolCall", "toolResult",
"sessionId", "emitDone", "emitError",
]) {
emitter[method] = (...args) => process.parentPort.postMessage({ type: "event", method, args });
}
let started = false;
let pendingPrompt = null;
function getPrompt() {
return new Promise((resolve, reject) => {
if (controller.signal.aborted) {
reject(new Error("Cursor turn was interrupted"));
return;
}
pendingPrompt = { resolve, reject };
process.parentPort.postMessage({ type: "prompt-request" });
});
}
process.parentPort.on("message", ({ data }) => {
if (data?.type === "abort") {
controller.abort();
pendingPrompt?.reject(new Error("Cursor turn was interrupted"));
pendingPrompt = null;
}
if (data?.type === "prompt") {
pendingPrompt?.resolve({ prompt: data.prompt, attachments: data.attachments });
pendingPrompt = null;
}
if (data?.type === "start" && !started) {
started = true;
void runCursorTurnInProcess({
...data.params, emitter, signal: controller.signal,
getPrompt: data.params.deferPrompt ? getPrompt : undefined,
}).then(
(result) => process.parentPort.postMessage({ type: "result", result }),
(error) => process.parentPort.postMessage({ type: "error", message: error?.message || String(error) }),
);
}
});