Files
Netcatty/electron/bridges/aiBridge/sdk/processEnvGate.cjs
T
8017c144fe feat(cli): bind Skills+CLI chat session via host env (#3347)
* feat(workspace): search hosts by tag (#3001)

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(cli): bind Skills+CLI chat session via host env

Hide --chat-session from agents so they cannot spoof another chat tenant.
The host injects NETCATTY_CLI_CHAT_SESSION_ID, and Copilot/CodeBuddy
approval gates reject leftover flags and env-prefix overrides.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): isolate Skills+CLI chat env across concurrent SDK turns

Cursor and OpenCode mutate process.env around spawn. Serialize those
writes so overlapping chats cannot inherit or restore the wrong
NETCATTY_CLI_CHAT_SESSION_ID.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Revert "feat(workspace): search hosts by tag (#3001)"

This reverts commit 4b651a3841.

* fix(ai): preserve chat isolation when cancelling Cursor startup

* fix(ai): isolate Cursor turns in cancellable workers

* fix(ai): contain native Cursor cleanup in a utility process

* fix(ai): report Cursor utility process fatal errors

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
2026-09-12 12:16:57 +08:00

52 lines
1.4 KiB
JavaScript

"use strict";
/**
* Cursor local agents inherit the host process environment (no local.envVars
* API). OpenCode's createOpencode likewise spawns from process.env. Concurrent
* Skills turns in different chats must not overlap those mutations, or a child
* can inherit another chat's NETCATTY_CLI_CHAT_SESSION_ID and the main process
* can retain a stale tenant after restore.
*/
let exclusiveChain = Promise.resolve();
function applyTemporaryProcessEnv(env) {
if (!env || typeof env !== "object") return () => {};
const previous = new Map();
for (const [key, value] of Object.entries(env)) {
if (typeof value !== "string") continue;
previous.set(key, Object.prototype.hasOwnProperty.call(process.env, key) ? process.env[key] : undefined);
process.env[key] = value;
}
return () => {
for (const [key, value] of previous.entries()) {
if (value === undefined) delete process.env[key];
else process.env[key] = value;
}
};
}
function withExclusiveProcessEnv(env, fn) {
const run = exclusiveChain.then(async () => {
const restore = applyTemporaryProcessEnv(env);
try {
return await fn();
} finally {
restore();
}
});
exclusiveChain = run.then(() => {}, () => {});
return run;
}
async function withTemporaryProcessEnv(env, fn) {
return withExclusiveProcessEnv(env, fn);
}
module.exports = {
applyTemporaryProcessEnv,
withExclusiveProcessEnv,
withTemporaryProcessEnv,
};