Files
Netcatty/electron/cli/cliChatSession.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

65 lines
1.8 KiB
JavaScript

"use strict";
const {
TOOL_CLI_CHAT_SESSION_ENV_VAR,
TOOL_CLI_DISCOVERY_ENV_VAR,
} = require("./discoveryPath.cjs");
function trimId(value) {
return typeof value === "string" ? value.trim() : "";
}
function describeRemovedChatSessionFlag() {
return (
`--chat-session is not a CLI flag. ` +
`The host binds the chat session via ${TOOL_CLI_CHAT_SESSION_ENV_VAR}.`
);
}
function isRemovedChatSessionFlag(arg) {
return arg === "--chat-session" || (typeof arg === "string" && arg.startsWith("--chat-session="));
}
/**
* Resolve the chat-session tenant key from the host-injected env only.
* Each SDK agent process gets its own NETCATTY_CLI_CHAT_SESSION_ID, so
* concurrent chat windows do not share this binding.
*/
function bindChatSessionId(env = process.env) {
const fromEnv = trimId(env?.[TOOL_CLI_CHAT_SESSION_ENV_VAR]);
return fromEnv || null;
}
function describeMissingChatSession(commandLabel) {
return (
`Missing chat session for ${commandLabel}. ` +
`Set ${TOOL_CLI_CHAT_SESSION_ENV_VAR} in the host-launched environment.`
);
}
/**
* Env handed to SDK agent subprocesses for Skills + CLI.
* Always strips a caller-supplied chat-session id, then writes the trusted host id.
*/
function injectCliTransportEnv(env, { discoveryFilePath, chatSessionId } = {}) {
const next = { ...(env && typeof env === "object" ? env : {}) };
delete next[TOOL_CLI_CHAT_SESSION_ENV_VAR];
if (discoveryFilePath) {
next[TOOL_CLI_DISCOVERY_ENV_VAR] = discoveryFilePath;
}
const id = trimId(chatSessionId);
if (id) {
next[TOOL_CLI_CHAT_SESSION_ENV_VAR] = id;
}
return next;
}
module.exports = {
bindChatSessionId,
describeMissingChatSession,
describeRemovedChatSessionFlag,
isRemovedChatSessionFlag,
injectCliTransportEnv,
TOOL_CLI_CHAT_SESSION_ENV_VAR,
};