Files
Netcatty/electron/capabilities/scope.cjs
T
陈大猫 61a2473a7c feat(capabilities): shared agent capability layer for MCP and CLI (#1616)
* feat(capabilities): add shared agent capability layer for MCP and CLI

Introduce a registry-driven capability foundation so terminal, SFTP, vault,
and port-forward tools can be extended from one policy and surface definition.
Wire mcpServerBridge permission checks and the Skills CLI RPC client through
the shared layer without changing existing AI runtime behavior.

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

* fix(capabilities): restore SFTP cancel gating and home RPC timeout

Match legacy mcpServerBridge behavior by blocking SFTP write RPCs after
chat cancel and treating sftp/home as a long-running operation for timeout
budget calculation.

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

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 13:13:57 +08:00

42 lines
1.3 KiB
JavaScript

"use strict";
/**
* Scope helpers for capability execution boundaries.
*
* Concrete scope implementations (chat-scoped, public-exposure, global) will
* live with their bridges. This module defines shared validation helpers.
*/
function createScopeError(code, message) {
return { ok: false, code, error: message };
}
function validateSessionInList(sessionId, allowedSessionIds) {
if (!sessionId) {
return createScopeError("SESSION_REQUIRED", "sessionId is required.");
}
if (!Array.isArray(allowedSessionIds)) {
return createScopeError("SCOPE_UNAVAILABLE", "Session scope is unavailable.");
}
if (allowedSessionIds.length === 0) {
return createScopeError("SESSION_NOT_IN_SCOPE", "No sessions are available in the current scope.");
}
if (!allowedSessionIds.includes(sessionId)) {
return createScopeError("SESSION_NOT_IN_SCOPE", `Session "${sessionId}" is not in the current scope.`);
}
return { ok: true };
}
function intersectSessionIds(primaryIds, secondaryIds) {
if (!Array.isArray(primaryIds)) return Array.isArray(secondaryIds) ? [...secondaryIds] : null;
if (!Array.isArray(secondaryIds)) return [...primaryIds];
const secondary = new Set(secondaryIds);
return primaryIds.filter((sessionId) => secondary.has(sessionId));
}
module.exports = {
createScopeError,
validateSessionInList,
intersectSessionIds,
};