@ycodium-ai/agent-grok 0.2.5912 → 0.2.5939
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +839 -126
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
9
9
|
|
|
10
10
|
// ../../packages/plugin-api/src/version.ts
|
|
11
|
-
var PLUGIN_API_VERSION =
|
|
11
|
+
var PLUGIN_API_VERSION = 189;
|
|
12
12
|
|
|
13
13
|
// src/index.ts
|
|
14
14
|
import { registerEffectiveHomeCommand } from "@ycodium-ai/plugin-api/instance-config";
|
|
@@ -884,6 +884,18 @@ function canonicalItemTypeFromAcpToolKind(kind) {
|
|
|
884
884
|
}
|
|
885
885
|
|
|
886
886
|
// ../../packages/ycodium-acp-executor/src/tool-call-state.ts
|
|
887
|
+
var clearedIdentityFields = /* @__PURE__ */ new WeakMap();
|
|
888
|
+
var fallbackTitleStates = /* @__PURE__ */ new WeakSet();
|
|
889
|
+
function readToolCallIdentityFields(state, options) {
|
|
890
|
+
const cleared = clearedIdentityFields.get(state);
|
|
891
|
+
return {
|
|
892
|
+
name: cleared?.name === null ? null : state.data["name"],
|
|
893
|
+
kind: options?.kindFromData ? state.data["kind"] : state.kind,
|
|
894
|
+
mcpServer: cleared?.mcpServer === null ? null : state.data["mcpServer"],
|
|
895
|
+
mcpTool: cleared?.mcpTool === null ? null : state.data["mcpTool"],
|
|
896
|
+
negativeMcp: cleared?.negativeMcp === true
|
|
897
|
+
};
|
|
898
|
+
}
|
|
887
899
|
function normalizeToolCallStatus(raw, fallback) {
|
|
888
900
|
switch (raw) {
|
|
889
901
|
case "pending":
|
|
@@ -1016,6 +1028,13 @@ function makeToolCallState(input2, options) {
|
|
|
1016
1028
|
if (!toolCallId) {
|
|
1017
1029
|
return void 0;
|
|
1018
1030
|
}
|
|
1031
|
+
const explicitNullMcp = input2.mcpServer === null || input2.mcpTool === null;
|
|
1032
|
+
const reqMetaFlag = isRecord3(input2._meta) && typeof input2._meta["is_mcp_tool_call"] === "boolean" ? input2._meta["is_mcp_tool_call"] : void 0;
|
|
1033
|
+
const parentMetaFlag = isRecord3(input2.parentMeta) && typeof input2.parentMeta["is_mcp_tool_call"] === "boolean" ? input2.parentMeta["is_mcp_tool_call"] : void 0;
|
|
1034
|
+
const metaFlag = reqMetaFlag === false || parentMetaFlag === false ? false : reqMetaFlag === true || parentMetaFlag === true ? true : void 0;
|
|
1035
|
+
const explicitPositiveMcp = !explicitNullMcp && metaFlag !== false && (metaFlag === true || readAcpText(input2, "mcpServer") !== void 0 && readAcpText(input2, "mcpTool") !== void 0);
|
|
1036
|
+
const explicitNegativeMcp = explicitNullMcp || metaFlag === false;
|
|
1037
|
+
const negativeMcp = explicitNegativeMcp || !explicitPositiveMcp && options?.inheritedNegativeMcp === true;
|
|
1019
1038
|
const title = typeof input2.title === "string" ? input2.title.trim() || void 0 : void 0;
|
|
1020
1039
|
const command = extractToolCallCommand(input2.rawInput, title);
|
|
1021
1040
|
const extractedContent = extractTextContentFromToolCallContent(input2.content);
|
|
@@ -1029,6 +1048,12 @@ function makeToolCallState(input2, options) {
|
|
|
1029
1048
|
const name = readAcpText(input2, "name");
|
|
1030
1049
|
if (name) {
|
|
1031
1050
|
data["name"] = name;
|
|
1051
|
+
const mcpServer = readAcpText(input2, "mcpServer");
|
|
1052
|
+
const mcpTool = readAcpText(input2, "mcpTool");
|
|
1053
|
+
if (!negativeMcp && mcpServer !== void 0 && mcpTool !== void 0) {
|
|
1054
|
+
data["mcpServer"] = mcpServer;
|
|
1055
|
+
data["mcpTool"] = mcpTool;
|
|
1056
|
+
}
|
|
1032
1057
|
}
|
|
1033
1058
|
if (command) {
|
|
1034
1059
|
data["command"] = command;
|
|
@@ -1055,7 +1080,7 @@ function makeToolCallState(input2, options) {
|
|
|
1055
1080
|
fallbackSummary: title ?? "Tool"
|
|
1056
1081
|
}) : void 0;
|
|
1057
1082
|
const status = normalizeToolCallStatus(input2.status, options?.fallbackStatus);
|
|
1058
|
-
|
|
1083
|
+
const state = {
|
|
1059
1084
|
toolCallId,
|
|
1060
1085
|
...kind ? { kind } : {},
|
|
1061
1086
|
...presentation?.summary ? { title: presentation.summary } : {},
|
|
@@ -1065,16 +1090,74 @@ function makeToolCallState(input2, options) {
|
|
|
1065
1090
|
...textContent ? { contentText: textContent } : {},
|
|
1066
1091
|
data
|
|
1067
1092
|
};
|
|
1093
|
+
if (title === void 0 && presentation?.summary === "Tool") {
|
|
1094
|
+
fallbackTitleStates.add(state);
|
|
1095
|
+
}
|
|
1096
|
+
if (input2.name === null || input2.mcpServer === null || input2.mcpTool === null || negativeMcp || explicitPositiveMcp) {
|
|
1097
|
+
clearedIdentityFields.set(state, {
|
|
1098
|
+
...input2.name === null ? { name: null } : {},
|
|
1099
|
+
...input2.mcpServer === null ? { mcpServer: null } : {},
|
|
1100
|
+
...input2.mcpTool === null ? { mcpTool: null } : {},
|
|
1101
|
+
...negativeMcp ? { negativeMcp: true } : {},
|
|
1102
|
+
...explicitPositiveMcp ? { positiveMcp: true } : {}
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
return state;
|
|
1106
|
+
}
|
|
1107
|
+
function toolCallIdentityChanged(previous, next) {
|
|
1108
|
+
const prevName = readAcpText(previous, "name");
|
|
1109
|
+
const nextName = readAcpText(next, "name");
|
|
1110
|
+
const prevKind = normalizeToolKind(previous.kind);
|
|
1111
|
+
const nextKind = normalizeToolKind(next.kind);
|
|
1112
|
+
const prevServer = readAcpText(previous, "mcpServer");
|
|
1113
|
+
const nextServer = readAcpText(next, "mcpServer");
|
|
1114
|
+
const prevTool = readAcpText(previous, "mcpTool");
|
|
1115
|
+
const nextTool = readAcpText(next, "mcpTool");
|
|
1116
|
+
const clearedName = prevName !== void 0 && next.name === null;
|
|
1117
|
+
const clearedServer = prevServer !== void 0 && next.mcpServer === null;
|
|
1118
|
+
const clearedTool = prevTool !== void 0 && next.mcpTool === null;
|
|
1119
|
+
return clearedName || clearedServer || clearedTool || prevName !== void 0 && nextName !== void 0 && prevName !== nextName || prevKind !== void 0 && nextKind !== void 0 && prevKind !== nextKind || prevServer !== void 0 && nextServer !== void 0 && prevServer !== nextServer || prevTool !== void 0 && nextTool !== void 0 && prevTool !== nextTool;
|
|
1068
1120
|
}
|
|
1069
1121
|
function mergeToolCallState(previous, next) {
|
|
1122
|
+
if (previous !== void 0 && toolCallIdentityChanged(
|
|
1123
|
+
{
|
|
1124
|
+
name: previous.data["name"],
|
|
1125
|
+
kind: previous.kind,
|
|
1126
|
+
mcpServer: previous.data["mcpServer"],
|
|
1127
|
+
mcpTool: previous.data["mcpTool"]
|
|
1128
|
+
},
|
|
1129
|
+
readToolCallIdentityFields(next, { kindFromData: true })
|
|
1130
|
+
)) {
|
|
1131
|
+
const status2 = next.status ?? previous.status;
|
|
1132
|
+
if (status2 === void 0 || status2 === next.status) {
|
|
1133
|
+
return next;
|
|
1134
|
+
}
|
|
1135
|
+
const replaced = { ...next, status: status2 };
|
|
1136
|
+
const nextCleared2 = clearedIdentityFields.get(next);
|
|
1137
|
+
if (nextCleared2 !== void 0) clearedIdentityFields.set(replaced, nextCleared2);
|
|
1138
|
+
if (fallbackTitleStates.has(next)) fallbackTitleStates.add(replaced);
|
|
1139
|
+
return replaced;
|
|
1140
|
+
}
|
|
1070
1141
|
const nextKind = typeof next.data["kind"] === "string" ? next.data["kind"] : void 0;
|
|
1071
1142
|
const kind = nextKind ?? previous?.kind;
|
|
1072
|
-
const
|
|
1143
|
+
const nextIsFallbackTitle = fallbackTitleStates.has(next);
|
|
1144
|
+
const title = nextIsFallbackTitle ? previous?.title ?? next.title : next.title ?? previous?.title;
|
|
1073
1145
|
const status = next.status ?? previous?.status;
|
|
1074
1146
|
const command = next.command ?? previous?.command;
|
|
1075
1147
|
const detail = next.detail ?? previous?.detail;
|
|
1076
1148
|
const contentText = "content" in next.data ? next.contentText : previous?.contentText;
|
|
1077
|
-
|
|
1149
|
+
const prevCleared = previous === void 0 ? void 0 : clearedIdentityFields.get(previous);
|
|
1150
|
+
const nextCleared = clearedIdentityFields.get(next);
|
|
1151
|
+
const nextPositiveMcp = typeof next.data["mcpServer"] === "string" && typeof next.data["mcpTool"] === "string" || nextCleared?.positiveMcp === true;
|
|
1152
|
+
const mergedNegativeMcp = nextCleared?.negativeMcp === true || !nextPositiveMcp && prevCleared?.negativeMcp === true;
|
|
1153
|
+
const clearPreviousMcp = previous !== void 0 && (mergedNegativeMcp || next.data["name"] !== void 0 && next.data["mcpServer"] === void 0);
|
|
1154
|
+
const previousData = clearPreviousMcp ? Object.fromEntries(
|
|
1155
|
+
Object.entries(previous.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool")
|
|
1156
|
+
) : previous?.data;
|
|
1157
|
+
const nextData = mergedNegativeMcp ? Object.fromEntries(
|
|
1158
|
+
Object.entries(next.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool")
|
|
1159
|
+
) : next.data;
|
|
1160
|
+
const merged = {
|
|
1078
1161
|
toolCallId: next.toolCallId,
|
|
1079
1162
|
...kind ? { kind } : {},
|
|
1080
1163
|
...title ? { title } : {},
|
|
@@ -1083,10 +1166,19 @@ function mergeToolCallState(previous, next) {
|
|
|
1083
1166
|
...detail ? { detail } : {},
|
|
1084
1167
|
...contentText ? { contentText } : {},
|
|
1085
1168
|
data: {
|
|
1086
|
-
...
|
|
1087
|
-
...
|
|
1169
|
+
...previousData,
|
|
1170
|
+
...nextData
|
|
1088
1171
|
}
|
|
1089
1172
|
};
|
|
1173
|
+
if (mergedNegativeMcp) {
|
|
1174
|
+
clearedIdentityFields.set(merged, { negativeMcp: true });
|
|
1175
|
+
} else if (nextPositiveMcp || prevCleared?.positiveMcp === true) {
|
|
1176
|
+
clearedIdentityFields.set(merged, { positiveMcp: true });
|
|
1177
|
+
}
|
|
1178
|
+
if (title === "Tool" && nextIsFallbackTitle && (previous === void 0 || fallbackTitleStates.has(previous))) {
|
|
1179
|
+
fallbackTitleStates.add(merged);
|
|
1180
|
+
}
|
|
1181
|
+
return merged;
|
|
1090
1182
|
}
|
|
1091
1183
|
var TOOL_CALL_UPDATE_MIN_DETAIL_GROWTH_CHARS = 256;
|
|
1092
1184
|
var TOOL_CALL_UPDATE_COALESCE_LIMIT = 10;
|
|
@@ -1241,20 +1333,47 @@ function parseAvailableCommandsUpdate(params) {
|
|
|
1241
1333
|
}
|
|
1242
1334
|
function parsePermissionRequest(params, known) {
|
|
1243
1335
|
const request = params.toolCall;
|
|
1336
|
+
const requestFields = request;
|
|
1244
1337
|
const earlier = known?.state.data;
|
|
1338
|
+
const identityChanged = known !== void 0 && toolCallIdentityChanged(
|
|
1339
|
+
{
|
|
1340
|
+
name: earlier?.["name"],
|
|
1341
|
+
kind: known.state.kind,
|
|
1342
|
+
mcpServer: earlier?.["mcpServer"],
|
|
1343
|
+
mcpTool: earlier?.["mcpTool"]
|
|
1344
|
+
},
|
|
1345
|
+
{
|
|
1346
|
+
name: requestFields.name,
|
|
1347
|
+
kind: request.kind,
|
|
1348
|
+
mcpServer: requestFields.mcpServer,
|
|
1349
|
+
mcpTool: requestFields.mcpTool
|
|
1350
|
+
}
|
|
1351
|
+
);
|
|
1352
|
+
const prior = identityChanged ? void 0 : known;
|
|
1353
|
+
const priorData = identityChanged ? void 0 : earlier;
|
|
1354
|
+
const priorNegativeMcp = prior !== void 0 ? readToolCallIdentityFields(prior.state).negativeMcp : false;
|
|
1355
|
+
const reqMeta = request._meta;
|
|
1356
|
+
const parentMeta = params._meta;
|
|
1357
|
+
const requestNegativeMcp = requestFields.mcpServer === null || requestFields.mcpTool === null || isRecord3(reqMeta) && reqMeta["is_mcp_tool_call"] === false || isRecord3(parentMeta) && parentMeta["is_mcp_tool_call"] === false;
|
|
1358
|
+
const allowPriorMcpFields = !priorNegativeMcp && !requestNegativeMcp && requestFields.name === void 0;
|
|
1359
|
+
const inheritedRawTitle = prior?.rawTitle !== void 0 && !((priorNegativeMcp || requestNegativeMcp) && /^(?:(?:Running|Run)\s+)?mcp_/u.test(prior.rawTitle.trim())) ? prior.rawTitle : void 0;
|
|
1245
1360
|
const toolCall = makeToolCallState(
|
|
1246
1361
|
{
|
|
1247
1362
|
toolCallId: request.toolCallId,
|
|
1248
|
-
name:
|
|
1249
|
-
|
|
1250
|
-
|
|
1363
|
+
name: requestFields.name !== void 0 ? requestFields.name : priorData?.["name"],
|
|
1364
|
+
mcpServer: requestFields.mcpServer !== void 0 ? requestFields.mcpServer : allowPriorMcpFields ? priorData?.["mcpServer"] : void 0,
|
|
1365
|
+
mcpTool: requestFields.mcpTool !== void 0 ? requestFields.mcpTool : allowPriorMcpFields ? priorData?.["mcpTool"] : void 0,
|
|
1366
|
+
title: request.title ?? inheritedRawTitle,
|
|
1367
|
+
kind: request.kind ?? priorData?.["kind"],
|
|
1251
1368
|
status: request.status ?? known?.state.status,
|
|
1252
|
-
rawInput: request.rawInput !== void 0 ? request.rawInput :
|
|
1253
|
-
rawOutput: request.rawOutput !== void 0 ? request.rawOutput :
|
|
1254
|
-
content: request.content !== void 0 ? request.content :
|
|
1255
|
-
locations: request.locations !== void 0 ? request.locations :
|
|
1369
|
+
rawInput: request.rawInput !== void 0 ? request.rawInput : priorData?.["rawInput"],
|
|
1370
|
+
rawOutput: request.rawOutput !== void 0 ? request.rawOutput : priorData?.["rawOutput"],
|
|
1371
|
+
content: request.content !== void 0 ? request.content : priorData?.["content"],
|
|
1372
|
+
locations: request.locations !== void 0 ? request.locations : priorData?.["locations"],
|
|
1373
|
+
_meta: reqMeta,
|
|
1374
|
+
parentMeta
|
|
1256
1375
|
},
|
|
1257
|
-
{ fallbackStatus: "pending" }
|
|
1376
|
+
{ fallbackStatus: "pending", ...priorNegativeMcp ? { inheritedNegativeMcp: true } : {} }
|
|
1258
1377
|
);
|
|
1259
1378
|
const kind = toolCall?.kind ?? "unknown";
|
|
1260
1379
|
const content = toolCall?.data["content"];
|
|
@@ -1264,7 +1383,7 @@ function parsePermissionRequest(params, known) {
|
|
|
1264
1383
|
const block = entry["content"];
|
|
1265
1384
|
return block["type"] === "text" && typeof block["text"] === "string" && block["text"].trim() ? [block["text"]] : [];
|
|
1266
1385
|
})[0] : void 0;
|
|
1267
|
-
const originalTitle = (request.title ??
|
|
1386
|
+
const originalTitle = (request.title ?? inheritedRawTitle)?.trim() || void 0;
|
|
1268
1387
|
const detail = toolCall?.command ?? firstText ?? originalTitle;
|
|
1269
1388
|
return {
|
|
1270
1389
|
kind,
|
|
@@ -1335,13 +1454,17 @@ function parseSessionUpdateEvent(params) {
|
|
|
1335
1454
|
{
|
|
1336
1455
|
toolCallId: upd["toolCallId"],
|
|
1337
1456
|
name: upd["name"],
|
|
1457
|
+
mcpServer: upd["mcpServer"],
|
|
1458
|
+
mcpTool: upd["mcpTool"],
|
|
1338
1459
|
title: typeof upd["title"] === "string" ? upd["title"] : void 0,
|
|
1339
1460
|
kind: upd["kind"],
|
|
1340
1461
|
status: upd["status"],
|
|
1341
1462
|
rawInput: upd["rawInput"],
|
|
1342
1463
|
rawOutput: upd["rawOutput"],
|
|
1343
1464
|
content: upd["content"],
|
|
1344
|
-
locations: upd["locations"]
|
|
1465
|
+
locations: upd["locations"],
|
|
1466
|
+
_meta: upd["_meta"],
|
|
1467
|
+
parentMeta: params._meta
|
|
1345
1468
|
},
|
|
1346
1469
|
kind === "tool_call" ? { fallbackStatus: "pending" } : void 0
|
|
1347
1470
|
);
|
|
@@ -1450,6 +1573,38 @@ function canonicalRequestTypeFromAcpKind(kind) {
|
|
|
1450
1573
|
return "dynamic_tool_call";
|
|
1451
1574
|
}
|
|
1452
1575
|
}
|
|
1576
|
+
var MAX_ACP_FILE_CHANGES = 256;
|
|
1577
|
+
var MAX_ACP_FILE_CHANGE_PATH_CHARS = 4096;
|
|
1578
|
+
var MAX_DISPLAY_FILE_CHANGES = 20;
|
|
1579
|
+
var isValidAcpFilePath = (value) => typeof value === "string" && value.trim().length > 0 && value.length <= MAX_ACP_FILE_CHANGE_PATH_CHARS;
|
|
1580
|
+
var isTruncatedFileChangesMarker = (value) => value !== null && typeof value === "object" && value["ycodiumFileChangesTruncated"] === true;
|
|
1581
|
+
var clippedDiffBlocks = /* @__PURE__ */ new WeakMap();
|
|
1582
|
+
function readAcpDiffTooLarge(block) {
|
|
1583
|
+
return block !== null && typeof block === "object" ? clippedDiffBlocks.get(block) : void 0;
|
|
1584
|
+
}
|
|
1585
|
+
function acpFileChangeFromDiffBlock(block, path) {
|
|
1586
|
+
const oldText = typeof block["oldText"] === "string" ? block["oldText"] : void 0;
|
|
1587
|
+
const changeKind = oldText === void 0 ? "add" : "modify";
|
|
1588
|
+
const clipped = readAcpDiffTooLarge(block);
|
|
1589
|
+
if (clipped !== void 0) {
|
|
1590
|
+
return {
|
|
1591
|
+
path,
|
|
1592
|
+
changeKind,
|
|
1593
|
+
additions: clipped.additions,
|
|
1594
|
+
deletions: clipped.deletions,
|
|
1595
|
+
omitted: "too-large"
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
return {
|
|
1599
|
+
path,
|
|
1600
|
+
changeKind,
|
|
1601
|
+
content: {
|
|
1602
|
+
kind: "replace",
|
|
1603
|
+
...oldText !== void 0 ? { oldText } : {},
|
|
1604
|
+
newText: block["newText"]
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1453
1608
|
function fileChangesFromAcpPermission(permissionRequest) {
|
|
1454
1609
|
const content = permissionRequest.toolCall?.data["content"];
|
|
1455
1610
|
const changes = Array.isArray(content) ? content.flatMap((entry) => {
|
|
@@ -1457,34 +1612,106 @@ function fileChangesFromAcpPermission(permissionRequest) {
|
|
|
1457
1612
|
return [];
|
|
1458
1613
|
}
|
|
1459
1614
|
const block = entry;
|
|
1460
|
-
if (block["type"] !== "diff" ||
|
|
1615
|
+
if (block["type"] !== "diff" || !isValidAcpFilePath(block["path"]) || typeof block["newText"] !== "string") {
|
|
1461
1616
|
return [];
|
|
1462
1617
|
}
|
|
1463
|
-
|
|
1464
|
-
return [
|
|
1465
|
-
{
|
|
1466
|
-
path: block["path"],
|
|
1467
|
-
changeKind: oldText === void 0 ? "add" : "modify",
|
|
1468
|
-
content: {
|
|
1469
|
-
kind: "replace",
|
|
1470
|
-
...oldText !== void 0 ? { oldText } : {},
|
|
1471
|
-
newText: block["newText"]
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
];
|
|
1618
|
+
return [acpFileChangeFromDiffBlock(block, block["path"])];
|
|
1475
1619
|
}) : [];
|
|
1476
|
-
|
|
1477
|
-
|
|
1620
|
+
const boundedChanges = changes.length > MAX_ACP_FILE_CHANGES ? changes.slice(0, MAX_ACP_FILE_CHANGES) : changes;
|
|
1621
|
+
const requestType = canonicalRequestTypeFromAcpKind(permissionRequest.kind);
|
|
1622
|
+
if (boundedChanges.length > 0 || requestType === "file_change_approval" || requestType === "file_read_approval") {
|
|
1623
|
+
const locations = permissionRequest.toolCall?.data["locations"];
|
|
1624
|
+
const seenPaths = new Set(boundedChanges.map((change) => change.path));
|
|
1625
|
+
if (Array.isArray(locations)) {
|
|
1626
|
+
for (const entry of locations) {
|
|
1627
|
+
if (boundedChanges.length >= MAX_ACP_FILE_CHANGES) break;
|
|
1628
|
+
const rawPath = entry?.["path"];
|
|
1629
|
+
if (!isValidAcpFilePath(rawPath)) continue;
|
|
1630
|
+
if (!seenPaths.has(rawPath)) {
|
|
1631
|
+
seenPaths.add(rawPath);
|
|
1632
|
+
boundedChanges.push({ path: rawPath, omitted: "unavailable" });
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
return boundedChanges.length > 0 ? boundedChanges : void 0;
|
|
1638
|
+
}
|
|
1639
|
+
function inspectAcpPermissionFileChanges(permissionRequest, inputFileChanges) {
|
|
1640
|
+
const merged = [];
|
|
1641
|
+
let fileChangesTruncated = false;
|
|
1642
|
+
for (const entry of inputFileChanges ?? []) {
|
|
1643
|
+
if (!isValidAcpFilePath(entry.path) || merged.length >= MAX_ACP_FILE_CHANGES) {
|
|
1644
|
+
fileChangesTruncated = true;
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
merged.push(entry);
|
|
1478
1648
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1649
|
+
const seenPaths = new Set(merged.map((change) => change.path));
|
|
1650
|
+
const content = permissionRequest.toolCall?.data["content"];
|
|
1651
|
+
if (Array.isArray(content)) {
|
|
1652
|
+
let diffCount = 0;
|
|
1653
|
+
for (const entry of content) {
|
|
1654
|
+
if (isTruncatedFileChangesMarker(entry)) {
|
|
1655
|
+
fileChangesTruncated = true;
|
|
1656
|
+
continue;
|
|
1657
|
+
}
|
|
1658
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
1659
|
+
const block = entry;
|
|
1660
|
+
if (block["type"] !== "diff") continue;
|
|
1661
|
+
diffCount += 1;
|
|
1662
|
+
const diffPath = block["path"];
|
|
1663
|
+
const newText = block["newText"];
|
|
1664
|
+
if (diffCount > MAX_ACP_FILE_CHANGES || !isValidAcpFilePath(diffPath) || typeof newText !== "string") {
|
|
1665
|
+
fileChangesTruncated = true;
|
|
1666
|
+
continue;
|
|
1667
|
+
}
|
|
1668
|
+
if (!seenPaths.has(diffPath)) {
|
|
1669
|
+
if (merged.length >= MAX_ACP_FILE_CHANGES) {
|
|
1670
|
+
fileChangesTruncated = true;
|
|
1671
|
+
continue;
|
|
1672
|
+
}
|
|
1673
|
+
seenPaths.add(diffPath);
|
|
1674
|
+
merged.push(acpFileChangeFromDiffBlock(block, diffPath));
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1481
1677
|
}
|
|
1678
|
+
const requestType = canonicalRequestTypeFromAcpKind(permissionRequest.kind);
|
|
1482
1679
|
const locations = permissionRequest.toolCall?.data["locations"];
|
|
1483
|
-
const
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1680
|
+
const hasLocationTruncationMarker = Array.isArray(locations) && locations.some(isTruncatedFileChangesMarker);
|
|
1681
|
+
if (Array.isArray(locations) && (merged.length > 0 || requestType === "file_change_approval" || requestType === "file_read_approval" || hasLocationTruncationMarker)) {
|
|
1682
|
+
let locationEntries = 0;
|
|
1683
|
+
for (const entry of locations) {
|
|
1684
|
+
if (isTruncatedFileChangesMarker(entry)) {
|
|
1685
|
+
fileChangesTruncated = true;
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
locationEntries += 1;
|
|
1689
|
+
if (locationEntries > MAX_ACP_FILE_CHANGES) {
|
|
1690
|
+
fileChangesTruncated = true;
|
|
1691
|
+
continue;
|
|
1692
|
+
}
|
|
1693
|
+
const rawPath = entry !== null && typeof entry === "object" ? entry["path"] : void 0;
|
|
1694
|
+
if (!isValidAcpFilePath(rawPath)) {
|
|
1695
|
+
fileChangesTruncated = true;
|
|
1696
|
+
continue;
|
|
1697
|
+
}
|
|
1698
|
+
if (!seenPaths.has(rawPath)) {
|
|
1699
|
+
if (merged.length >= MAX_ACP_FILE_CHANGES) {
|
|
1700
|
+
fileChangesTruncated = true;
|
|
1701
|
+
continue;
|
|
1702
|
+
}
|
|
1703
|
+
seenPaths.add(rawPath);
|
|
1704
|
+
merged.push({ path: rawPath, omitted: "unavailable" });
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
if (merged.length > MAX_DISPLAY_FILE_CHANGES) {
|
|
1709
|
+
fileChangesTruncated = true;
|
|
1710
|
+
}
|
|
1711
|
+
return {
|
|
1712
|
+
fileChanges: merged.length > 0 ? merged : void 0,
|
|
1713
|
+
fileChangesTruncated
|
|
1714
|
+
};
|
|
1488
1715
|
}
|
|
1489
1716
|
function runtimeItemStatusFromAcpToolStatus(status) {
|
|
1490
1717
|
switch (status) {
|
|
@@ -1501,7 +1728,19 @@ function runtimeItemStatusFromAcpToolStatus(status) {
|
|
|
1501
1728
|
}
|
|
1502
1729
|
function makeAcpRequestOpenedEvent(input2) {
|
|
1503
1730
|
const requestType = canonicalRequestTypeFromAcpKind(input2.permissionRequest.kind);
|
|
1504
|
-
const
|
|
1731
|
+
const isDynamicToolKind = input2.permissionRequest.kind === "other" || input2.permissionRequest.kind === "unknown";
|
|
1732
|
+
const cleared = input2.permissionRequest.toolCall ? readToolCallIdentityFields(input2.permissionRequest.toolCall) : void 0;
|
|
1733
|
+
const rawRecord = input2.rawPayload !== null && typeof input2.rawPayload === "object" ? input2.rawPayload : void 0;
|
|
1734
|
+
const rawToolCall = rawRecord !== void 0 && rawRecord["toolCall"] !== null && typeof rawRecord["toolCall"] === "object" ? rawRecord["toolCall"] : void 0;
|
|
1735
|
+
const rawToolMeta = rawToolCall !== void 0 && rawToolCall["_meta"] !== null && typeof rawToolCall["_meta"] === "object" ? rawToolCall["_meta"] : void 0;
|
|
1736
|
+
const rawParentMeta = rawRecord !== void 0 && rawRecord["_meta"] !== null && typeof rawRecord["_meta"] === "object" ? rawRecord["_meta"] : void 0;
|
|
1737
|
+
const negativeMcp = cleared?.negativeMcp === true || cleared?.mcpServer === null || cleared?.mcpTool === null || rawToolCall?.["mcpServer"] === null || rawToolCall?.["mcpTool"] === null || rawToolMeta?.["is_mcp_tool_call"] === false || rawParentMeta?.["is_mcp_tool_call"] === false;
|
|
1738
|
+
const candidateToolName = requestType === "dynamic_tool_call" && isDynamicToolKind && typeof input2.permissionRequest.toolCall?.data["name"] === "string" ? input2.permissionRequest.toolCall.data["name"] : void 0;
|
|
1739
|
+
const toolName = candidateToolName !== void 0 && !(negativeMcp && /^(?:(?:Running|Run)\s+)?mcp_/u.test(candidateToolName.trim())) ? candidateToolName : void 0;
|
|
1740
|
+
const { fileChanges, fileChangesTruncated } = inspectAcpPermissionFileChanges(
|
|
1741
|
+
input2.permissionRequest,
|
|
1742
|
+
input2.fileChanges
|
|
1743
|
+
);
|
|
1505
1744
|
return {
|
|
1506
1745
|
type: "request.opened",
|
|
1507
1746
|
...input2.stamp,
|
|
@@ -1516,7 +1755,8 @@ function makeAcpRequestOpenedEvent(input2) {
|
|
|
1516
1755
|
args: input2.args,
|
|
1517
1756
|
...input2.statement !== void 0 ? { statement: input2.statement } : {},
|
|
1518
1757
|
...input2.options ? { options: input2.options } : {},
|
|
1519
|
-
...
|
|
1758
|
+
...fileChanges ? { fileChanges } : {},
|
|
1759
|
+
...fileChangesTruncated ? { fileChangesTruncated: true } : {},
|
|
1520
1760
|
declineReasonRelay: "queued"
|
|
1521
1761
|
},
|
|
1522
1762
|
raw: {
|
|
@@ -1558,7 +1798,8 @@ function makeAcpPlanUpdatedEvent(input2) {
|
|
|
1558
1798
|
}
|
|
1559
1799
|
function makeAcpToolCallEvent(input2) {
|
|
1560
1800
|
const runtimeStatus = runtimeItemStatusFromAcpToolStatus(input2.toolCall.status);
|
|
1561
|
-
const
|
|
1801
|
+
const rawData = input2.toolCall.data;
|
|
1802
|
+
const data = readToolCallIdentityFields(input2.toolCall).negativeMcp ? { ...rawData, mcpServer: null, mcpTool: null } : rawData;
|
|
1562
1803
|
return {
|
|
1563
1804
|
type: input2.toolCall.status === "completed" || input2.toolCall.status === "failed" ? "item.completed" : "item.updated",
|
|
1564
1805
|
...input2.stamp,
|
|
@@ -1613,29 +1854,45 @@ function makeAcpContentDeltaEvent(input2) {
|
|
|
1613
1854
|
}
|
|
1614
1855
|
};
|
|
1615
1856
|
}
|
|
1857
|
+
function toolCallTrackingKey(sessionId, toolCallId) {
|
|
1858
|
+
return sessionId === void 0 ? toolCallId : `${sessionId}\0${toolCallId}`;
|
|
1859
|
+
}
|
|
1616
1860
|
function retainToolCallUpdate(toolCalls, next, seen) {
|
|
1617
|
-
const
|
|
1618
|
-
const
|
|
1861
|
+
const key = toolCallTrackingKey(seen.sessionId, next.toolCallId);
|
|
1862
|
+
const tracked = toolCalls.get(key);
|
|
1863
|
+
const identityChanged = tracked !== void 0 && toolCallIdentityChanged(
|
|
1864
|
+
{
|
|
1865
|
+
name: tracked.state.data["name"],
|
|
1866
|
+
kind: tracked.state.kind,
|
|
1867
|
+
mcpServer: tracked.state.data["mcpServer"],
|
|
1868
|
+
mcpTool: tracked.state.data["mcpTool"]
|
|
1869
|
+
},
|
|
1870
|
+
readToolCallIdentityFields(next)
|
|
1871
|
+
);
|
|
1872
|
+
const reset = seen.isNewCall === true || identityChanged;
|
|
1873
|
+
const effectiveTracked = reset ? void 0 : tracked;
|
|
1874
|
+
const previous = effectiveTracked?.state;
|
|
1619
1875
|
const nextToolCall = mergeToolCallState(previous, next);
|
|
1620
1876
|
const decision = decideToolCallUpdateEmission({
|
|
1621
1877
|
previous,
|
|
1622
1878
|
next: nextToolCall,
|
|
1623
|
-
lastEmittedDetailLength:
|
|
1624
|
-
skippedSinceEmit:
|
|
1879
|
+
lastEmittedDetailLength: effectiveTracked?.lastEmittedDetailLength,
|
|
1880
|
+
skippedSinceEmit: effectiveTracked?.skippedSinceEmit ?? 0
|
|
1625
1881
|
});
|
|
1626
1882
|
if (nextToolCall.status === "completed" || nextToolCall.status === "failed") {
|
|
1627
|
-
toolCalls.delete(
|
|
1883
|
+
toolCalls.delete(key);
|
|
1628
1884
|
} else {
|
|
1629
|
-
toolCalls.set(
|
|
1885
|
+
toolCalls.set(key, {
|
|
1630
1886
|
state: nextToolCall,
|
|
1631
|
-
lastEmittedDetailLength: decision.emit ? nextToolCall.detail?.length :
|
|
1887
|
+
lastEmittedDetailLength: decision.emit ? nextToolCall.detail?.length : effectiveTracked?.lastEmittedDetailLength,
|
|
1632
1888
|
skippedSinceEmit: decision.skippedSinceEmit,
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1889
|
+
sessionId: seen.sessionId ?? effectiveTracked?.sessionId,
|
|
1890
|
+
turnId: effectiveTracked === void 0 ? seen.turnId : effectiveTracked.turnId,
|
|
1891
|
+
startedAtMs: effectiveTracked?.startedAtMs ?? (nextToolCall.status === "inProgress" ? seen.nowMs() : void 0),
|
|
1892
|
+
rawTitle: typeof seen.rawTitle === "string" ? seen.rawTitle : readToolCallIdentityFields(nextToolCall).negativeMcp && effectiveTracked?.rawTitle !== void 0 && /^(?:(?:Running|Run)\s+)?mcp_/u.test(effectiveTracked.rawTitle.trim()) ? void 0 : effectiveTracked?.rawTitle
|
|
1636
1893
|
});
|
|
1637
1894
|
}
|
|
1638
|
-
return { nextToolCall, decision };
|
|
1895
|
+
return { nextToolCall, decision, reset };
|
|
1639
1896
|
}
|
|
1640
1897
|
|
|
1641
1898
|
// ../../packages/ycodium-acp-executor/src/executor/child-sessions.ts
|
|
@@ -25922,8 +26179,15 @@ function parseAcpResumeCursor(raw, schemaVersion) {
|
|
|
25922
26179
|
function acpPromptSettlementBelongsToContext(input2) {
|
|
25923
26180
|
return input2.liveAcpSessionId === input2.expectedAcpSessionId && (input2.liveActiveTurnId === input2.turnId || input2.liveSessionActiveTurnId === input2.turnId);
|
|
25924
26181
|
}
|
|
26182
|
+
function isAcpPermissionOption(value) {
|
|
26183
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
26184
|
+
return false;
|
|
26185
|
+
}
|
|
26186
|
+
const option = value;
|
|
26187
|
+
return typeof option["optionId"] === "string" && typeof option["name"] === "string" && typeof option["kind"] === "string";
|
|
26188
|
+
}
|
|
25925
26189
|
function isAcpRequestPermissionParams(value) {
|
|
25926
|
-
if (typeof value !== "object" || value === null) {
|
|
26190
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
25927
26191
|
return false;
|
|
25928
26192
|
}
|
|
25929
26193
|
const record4 = value;
|
|
@@ -25931,13 +26195,13 @@ function isAcpRequestPermissionParams(value) {
|
|
|
25931
26195
|
return false;
|
|
25932
26196
|
}
|
|
25933
26197
|
const toolCall = record4["toolCall"];
|
|
25934
|
-
if (typeof toolCall !== "object" || toolCall === null) {
|
|
26198
|
+
if (typeof toolCall !== "object" || toolCall === null || Array.isArray(toolCall)) {
|
|
25935
26199
|
return false;
|
|
25936
26200
|
}
|
|
25937
26201
|
if (typeof toolCall["toolCallId"] !== "string") {
|
|
25938
26202
|
return false;
|
|
25939
26203
|
}
|
|
25940
|
-
return Array.isArray(record4["options"]);
|
|
26204
|
+
return Array.isArray(record4["options"]) && record4["options"].every(isAcpPermissionOption);
|
|
25941
26205
|
}
|
|
25942
26206
|
|
|
25943
26207
|
// ../../packages/ycodium-acp-executor/src/apply-effort.ts
|
|
@@ -26863,15 +27127,123 @@ function createExecutorRequests({
|
|
|
26863
27127
|
})
|
|
26864
27128
|
);
|
|
26865
27129
|
};
|
|
27130
|
+
const permissionMutationsByKey = /* @__PURE__ */ new Map();
|
|
27131
|
+
const trackingKeyByRequestId = /* @__PURE__ */ new Map();
|
|
27132
|
+
let nextSettlementSeq = 0;
|
|
27133
|
+
const readCommittedBaseline = (trackingKey) => {
|
|
27134
|
+
const pendingList = permissionMutationsByKey.get(trackingKey);
|
|
27135
|
+
if (pendingList !== void 0 && pendingList.length > 0) {
|
|
27136
|
+
return pendingList[0].previousTracked;
|
|
27137
|
+
}
|
|
27138
|
+
return toolCalls.get(trackingKey);
|
|
27139
|
+
};
|
|
27140
|
+
const recordPermissionMutation = (entry) => {
|
|
27141
|
+
const list = permissionMutationsByKey.get(entry.trackingKey);
|
|
27142
|
+
if (list !== void 0) list.push(entry);
|
|
27143
|
+
else permissionMutationsByKey.set(entry.trackingKey, [entry]);
|
|
27144
|
+
trackingKeyByRequestId.set(entry.requestId, entry.trackingKey);
|
|
27145
|
+
};
|
|
27146
|
+
const supersedePermissionTrackedState = (trackingKey, supersedeOptions) => {
|
|
27147
|
+
const list = permissionMutationsByKey.get(trackingKey);
|
|
27148
|
+
if (list === void 0) return;
|
|
27149
|
+
if (supersedeOptions?.restoreCommitted && list.length > 0) {
|
|
27150
|
+
restoreTrackedState(trackingKey, list[0].hadPrevious, list[0].previousTracked);
|
|
27151
|
+
}
|
|
27152
|
+
for (const item of list) trackingKeyByRequestId.delete(item.requestId);
|
|
27153
|
+
permissionMutationsByKey.delete(trackingKey);
|
|
27154
|
+
};
|
|
27155
|
+
const restoreTrackedState = (trackingKey, hadPrevious, previousTracked) => {
|
|
27156
|
+
if (hadPrevious && previousTracked !== void 0) {
|
|
27157
|
+
toolCalls.set(trackingKey, previousTracked);
|
|
27158
|
+
} else {
|
|
27159
|
+
toolCalls.delete(trackingKey);
|
|
27160
|
+
}
|
|
27161
|
+
};
|
|
27162
|
+
const runWithCommittedPermissionBaseline = (trackingKey, applyUpdate, passiveNextState, rawTitle) => {
|
|
27163
|
+
const list = permissionMutationsByKey.get(trackingKey);
|
|
27164
|
+
if (list === void 0 || list.length === 0) {
|
|
27165
|
+
return applyUpdate();
|
|
27166
|
+
}
|
|
27167
|
+
const baseEntry = list[0];
|
|
27168
|
+
restoreTrackedState(trackingKey, baseEntry.hadPrevious, baseEntry.previousTracked);
|
|
27169
|
+
const result = applyUpdate();
|
|
27170
|
+
if (result.reset) {
|
|
27171
|
+
for (const item of list) trackingKeyByRequestId.delete(item.requestId);
|
|
27172
|
+
permissionMutationsByKey.delete(trackingKey);
|
|
27173
|
+
return result;
|
|
27174
|
+
}
|
|
27175
|
+
baseEntry.hadPrevious = toolCalls.has(trackingKey);
|
|
27176
|
+
baseEntry.previousTracked = toolCalls.get(trackingKey);
|
|
27177
|
+
for (const item of list) {
|
|
27178
|
+
if (!item.hadApplied || item.appliedTracked === void 0) continue;
|
|
27179
|
+
const mergedApplied = mergeToolCallState(item.appliedTracked.state, passiveNextState);
|
|
27180
|
+
item.appliedTracked = {
|
|
27181
|
+
...item.appliedTracked,
|
|
27182
|
+
state: mergedApplied,
|
|
27183
|
+
...typeof rawTitle === "string" ? { rawTitle } : {}
|
|
27184
|
+
};
|
|
27185
|
+
}
|
|
27186
|
+
const tail = list[list.length - 1];
|
|
27187
|
+
restoreTrackedState(trackingKey, tail.hadApplied, tail.appliedTracked);
|
|
27188
|
+
return result;
|
|
27189
|
+
};
|
|
27190
|
+
const releasePermissionTrackedState = (requestId, accepted) => {
|
|
27191
|
+
const trackingKey = trackingKeyByRequestId.get(requestId);
|
|
27192
|
+
trackingKeyByRequestId.delete(requestId);
|
|
27193
|
+
if (trackingKey === void 0) return;
|
|
27194
|
+
const list = permissionMutationsByKey.get(trackingKey);
|
|
27195
|
+
if (list === void 0) return;
|
|
27196
|
+
const idx = list.findIndex((item) => item.requestId === requestId);
|
|
27197
|
+
if (idx < 0) return;
|
|
27198
|
+
if (!accepted || !list[idx].hasOwnMutation) {
|
|
27199
|
+
const [removed] = list.splice(idx, 1);
|
|
27200
|
+
if (removed === void 0) return;
|
|
27201
|
+
if (idx < list.length) {
|
|
27202
|
+
list[idx].hadPrevious = removed.hadPrevious;
|
|
27203
|
+
list[idx].previousTracked = removed.previousTracked;
|
|
27204
|
+
return;
|
|
27205
|
+
}
|
|
27206
|
+
if (list.length === 0) {
|
|
27207
|
+
permissionMutationsByKey.delete(trackingKey);
|
|
27208
|
+
}
|
|
27209
|
+
restoreTrackedState(trackingKey, removed.hadPrevious, removed.previousTracked);
|
|
27210
|
+
return;
|
|
27211
|
+
}
|
|
27212
|
+
const acceptedEntry = list[idx];
|
|
27213
|
+
const committed = list.splice(0, idx + 1);
|
|
27214
|
+
for (const item of committed) trackingKeyByRequestId.delete(item.requestId);
|
|
27215
|
+
if (list.length === 0) {
|
|
27216
|
+
permissionMutationsByKey.delete(trackingKey);
|
|
27217
|
+
restoreTrackedState(trackingKey, acceptedEntry.hadApplied, acceptedEntry.appliedTracked);
|
|
27218
|
+
} else {
|
|
27219
|
+
list[0].hadPrevious = acceptedEntry.hadApplied;
|
|
27220
|
+
list[0].previousTracked = acceptedEntry.appliedTracked;
|
|
27221
|
+
}
|
|
27222
|
+
};
|
|
26866
27223
|
const settleApproval = (pending, outcome, decision, reason) => {
|
|
26867
27224
|
if (!approvals.settle(pending, outcome)) {
|
|
26868
27225
|
return false;
|
|
26869
27226
|
}
|
|
27227
|
+
const accepted = outcome.outcome === "selected" && (decision === "accept" || decision === "acceptForSession" || decision === "acceptAlways");
|
|
27228
|
+
releasePermissionTrackedState(pending.requestId, accepted);
|
|
27229
|
+
hooks.onPermissionRequestSettled?.({
|
|
27230
|
+
sessionId: pending.request.sessionId,
|
|
27231
|
+
toolCallId: pending.request.toolCall.toolCallId,
|
|
27232
|
+
accepted,
|
|
27233
|
+
...pending.settlementId === void 0 ? {} : { requestId: pending.settlementId }
|
|
27234
|
+
});
|
|
26870
27235
|
emitResolved(pending, decision, reason);
|
|
26871
27236
|
return true;
|
|
26872
27237
|
};
|
|
26873
27238
|
const settleAllApprovals = (decision) => {
|
|
26874
27239
|
for (const entry of approvals.settleAll({ outcome: "cancelled" })) {
|
|
27240
|
+
releasePermissionTrackedState(entry.requestId, false);
|
|
27241
|
+
hooks.onPermissionRequestSettled?.({
|
|
27242
|
+
sessionId: entry.request.sessionId,
|
|
27243
|
+
toolCallId: entry.request.toolCall.toolCallId,
|
|
27244
|
+
accepted: false,
|
|
27245
|
+
...entry.settlementId === void 0 ? {} : { requestId: entry.settlementId }
|
|
27246
|
+
});
|
|
26875
27247
|
emitResolved(entry, decision);
|
|
26876
27248
|
}
|
|
26877
27249
|
};
|
|
@@ -26949,62 +27321,189 @@ function createExecutorRequests({
|
|
|
26949
27321
|
outcome: optionId !== void 0 ? { outcome: "selected", optionId } : { outcome: "cancelled" }
|
|
26950
27322
|
};
|
|
26951
27323
|
};
|
|
26952
|
-
const handlePermissionRequest = async (
|
|
26953
|
-
if (!isAcpRequestPermissionParams(
|
|
27324
|
+
const handlePermissionRequest = async (rawParams) => {
|
|
27325
|
+
if (!isAcpRequestPermissionParams(rawParams)) {
|
|
26954
27326
|
throw RequestError.invalidParams({ detail: "Malformed session/request_permission" });
|
|
26955
27327
|
}
|
|
26956
|
-
const userInputOutcome = await handlePermissionAsUserInput(
|
|
27328
|
+
const userInputOutcome = await handlePermissionAsUserInput(rawParams);
|
|
26957
27329
|
if (userInputOutcome !== void 0) return userInputOutcome;
|
|
26958
|
-
|
|
26959
|
-
const
|
|
26960
|
-
const
|
|
26961
|
-
|
|
26962
|
-
|
|
26963
|
-
|
|
26964
|
-
|
|
26965
|
-
|
|
26966
|
-
|
|
26967
|
-
|
|
26968
|
-
|
|
26969
|
-
return { outcome: { outcome: "selected", optionId } };
|
|
26970
|
-
}
|
|
27330
|
+
failIfDisposed();
|
|
27331
|
+
const settlementId = `perm-${++nextSettlementSeq}`;
|
|
27332
|
+
const transformed = hooks.transformPermissionRequest ? hooks.transformPermissionRequest(rawParams, { requestId: settlementId }) : rawParams;
|
|
27333
|
+
if (!isAcpRequestPermissionParams(transformed)) {
|
|
27334
|
+
hooks.onPermissionRequestSettled?.({
|
|
27335
|
+
sessionId: rawParams.sessionId,
|
|
27336
|
+
toolCallId: rawParams.toolCall.toolCallId,
|
|
27337
|
+
accepted: false,
|
|
27338
|
+
requestId: settlementId
|
|
27339
|
+
});
|
|
27340
|
+
throw RequestError.invalidParams({ detail: "Malformed session/request_permission" });
|
|
26971
27341
|
}
|
|
26972
|
-
const
|
|
26973
|
-
|
|
26974
|
-
|
|
26975
|
-
|
|
26976
|
-
|
|
26977
|
-
const
|
|
26978
|
-
const
|
|
26979
|
-
const
|
|
26980
|
-
const
|
|
26981
|
-
|
|
26982
|
-
|
|
26983
|
-
|
|
26984
|
-
|
|
26985
|
-
|
|
26986
|
-
|
|
26987
|
-
|
|
26988
|
-
|
|
26989
|
-
|
|
26990
|
-
|
|
26991
|
-
|
|
27342
|
+
const params = transformed;
|
|
27343
|
+
const trackingKey = toolCallTrackingKey(params.sessionId, params.toolCall.toolCallId);
|
|
27344
|
+
const immediateHadPrevious = toolCalls.has(trackingKey);
|
|
27345
|
+
const immediatePrevious = toolCalls.get(trackingKey);
|
|
27346
|
+
let mutatedToolCall = false;
|
|
27347
|
+
const hasTextField = (record4, key) => typeof record4[key] === "string" && record4[key].trim().length > 0;
|
|
27348
|
+
const rawToolCallRecord = rawParams.toolCall;
|
|
27349
|
+
const rawReqMeta = rawToolCallRecord["_meta"];
|
|
27350
|
+
const rawParentMeta = rawParams["_meta"];
|
|
27351
|
+
const transformedToolCallRecord = params.toolCall;
|
|
27352
|
+
const transformedReqMeta = transformedToolCallRecord["_meta"];
|
|
27353
|
+
const transformedParentMeta = params["_meta"];
|
|
27354
|
+
const hasExplicitNegativeMeta = isRecord3(rawReqMeta) && rawReqMeta["is_mcp_tool_call"] === false || isRecord3(rawParentMeta) && rawParentMeta["is_mcp_tool_call"] === false || isRecord3(transformedReqMeta) && transformedReqMeta["is_mcp_tool_call"] === false || isRecord3(transformedParentMeta) && transformedParentMeta["is_mcp_tool_call"] === false;
|
|
27355
|
+
let hasOwnMutation = false;
|
|
27356
|
+
const prepared = (() => {
|
|
27357
|
+
try {
|
|
27358
|
+
const existingPendingList = permissionMutationsByKey.get(trackingKey);
|
|
27359
|
+
const hasPendingSibling = existingPendingList !== void 0 && existingPendingList.length > 0;
|
|
27360
|
+
const tracked = readCommittedBaseline(trackingKey);
|
|
27361
|
+
const requestFields = params.toolCall;
|
|
27362
|
+
const identityChanged = tracked !== void 0 && toolCallIdentityChanged(
|
|
27363
|
+
{
|
|
27364
|
+
name: tracked.state.data["name"],
|
|
27365
|
+
kind: tracked.state.kind,
|
|
27366
|
+
mcpServer: tracked.state.data["mcpServer"],
|
|
27367
|
+
mcpTool: tracked.state.data["mcpTool"]
|
|
27368
|
+
},
|
|
27369
|
+
{
|
|
27370
|
+
name: requestFields.name,
|
|
27371
|
+
kind: params.toolCall.kind,
|
|
27372
|
+
mcpServer: requestFields.mcpServer,
|
|
27373
|
+
mcpTool: requestFields.mcpTool
|
|
27374
|
+
}
|
|
27375
|
+
);
|
|
27376
|
+
const effectiveTracked = identityChanged ? void 0 : tracked;
|
|
27377
|
+
const parsed = parsePermissionRequest(params, effectiveTracked);
|
|
27378
|
+
const trackedNegativeMcp = tracked !== void 0 && readToolCallIdentityFields(tracked.state).negativeMcp;
|
|
27379
|
+
const parsedNegativeMcp = parsed.toolCall !== void 0 && readToolCallIdentityFields(parsed.toolCall).negativeMcp;
|
|
27380
|
+
const introducedTransformedIdentity = typeof requestFields.name === "string" && requestFields.name.trim().length > 0 && requestFields.name !== tracked?.state.data["name"] || typeof requestFields.mcpServer === "string" && requestFields.mcpServer.trim().length > 0 && requestFields.mcpServer !== tracked?.state.data["mcpServer"] || typeof requestFields.mcpTool === "string" && requestFields.mcpTool.trim().length > 0 && requestFields.mcpTool !== tracked?.state.data["mcpTool"];
|
|
27381
|
+
hasOwnMutation = identityChanged || hasExplicitNegativeMeta || trackedNegativeMcp !== parsedNegativeMcp || introducedTransformedIdentity || hasTextField(rawToolCallRecord, "name") || rawToolCallRecord["name"] === null || requestFields.name === null || hasTextField(rawToolCallRecord, "mcpServer") || rawToolCallRecord["mcpServer"] === null || requestFields.mcpServer === null || hasTextField(rawToolCallRecord, "mcpTool") || rawToolCallRecord["mcpTool"] === null || requestFields.mcpTool === null || hasTextField(rawToolCallRecord, "title") || hasTextField(rawToolCallRecord, "kind") && rawToolCallRecord["kind"].trim() !== "other" || rawToolCallRecord["status"] !== void 0 && rawToolCallRecord["status"] !== null || rawToolCallRecord["rawInput"] !== void 0 || rawToolCallRecord["rawOutput"] !== void 0 || rawToolCallRecord["content"] !== void 0 || rawToolCallRecord["locations"] !== void 0;
|
|
27382
|
+
const retainedRawTitle = typeof params.toolCall.title === "string" ? params.toolCall.title : parsedNegativeMcp && effectiveTracked?.rawTitle !== void 0 && /^(?:(?:Running|Run)\s+)?mcp_/u.test(effectiveTracked.rawTitle.trim()) ? void 0 : effectiveTracked?.rawTitle;
|
|
27383
|
+
if (hasOwnMutation || !hasPendingSibling) {
|
|
27384
|
+
if (parsed.toolCall === void 0) {
|
|
27385
|
+
if (identityChanged && toolCalls.delete(trackingKey)) {
|
|
27386
|
+
mutatedToolCall = true;
|
|
27387
|
+
}
|
|
27388
|
+
} else {
|
|
27389
|
+
if (parsed.toolCall.status === "completed" || parsed.toolCall.status === "failed") {
|
|
27390
|
+
if (toolCalls.delete(trackingKey)) {
|
|
27391
|
+
mutatedToolCall = true;
|
|
27392
|
+
}
|
|
27393
|
+
} else {
|
|
27394
|
+
mutatedToolCall = true;
|
|
27395
|
+
toolCalls.set(trackingKey, {
|
|
27396
|
+
state: parsed.toolCall,
|
|
27397
|
+
lastEmittedDetailLength: effectiveTracked?.lastEmittedDetailLength,
|
|
27398
|
+
skippedSinceEmit: effectiveTracked?.skippedSinceEmit ?? 0,
|
|
27399
|
+
sessionId: params.sessionId,
|
|
27400
|
+
turnId: effectiveTracked?.turnId ?? shared.activeTurnId,
|
|
27401
|
+
startedAtMs: effectiveTracked?.startedAtMs,
|
|
27402
|
+
rawTitle: retainedRawTitle
|
|
27403
|
+
});
|
|
27404
|
+
}
|
|
27405
|
+
}
|
|
27406
|
+
}
|
|
27407
|
+
const overriddenKind = hooks.permissionRequestKind?.({
|
|
27408
|
+
title: retainedRawTitle,
|
|
27409
|
+
kind: parsed.kind,
|
|
27410
|
+
rawInput: parsed.toolCall?.data["rawInput"]
|
|
27411
|
+
});
|
|
27412
|
+
const permissionRequest2 = overriddenKind === void 0 ? parsed : { ...parsed, kind: overriddenKind };
|
|
27413
|
+
if (options.autoApprove?.(permissionRequest2) === true) {
|
|
27414
|
+
const optionId = selectAutoApprovedAcpPermissionOption(params);
|
|
27415
|
+
if (optionId !== void 0) {
|
|
27416
|
+
if (hasOwnMutation) {
|
|
27417
|
+
supersedePermissionTrackedState(trackingKey);
|
|
27418
|
+
}
|
|
27419
|
+
hooks.onPermissionRequestSettled?.({
|
|
27420
|
+
sessionId: params.sessionId,
|
|
27421
|
+
toolCallId: params.toolCall.toolCallId,
|
|
27422
|
+
accepted: true,
|
|
27423
|
+
requestId: settlementId
|
|
27424
|
+
});
|
|
27425
|
+
return { autoApprovedOptionId: optionId };
|
|
27426
|
+
}
|
|
27427
|
+
}
|
|
27428
|
+
const permissionContext = {
|
|
27429
|
+
request: params,
|
|
27430
|
+
permissionRequest: permissionRequest2,
|
|
27431
|
+
previousToolCall: effectiveTracked?.state
|
|
27432
|
+
};
|
|
27433
|
+
const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest2);
|
|
27434
|
+
const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest2);
|
|
27435
|
+
const requestId2 = randomId();
|
|
27436
|
+
const openedEvent2 = makeAcpRequestOpenedEvent({
|
|
26992
27437
|
stamp: stamp(),
|
|
26993
27438
|
provider: options.provider,
|
|
26994
27439
|
threadId: options.threadId,
|
|
26995
27440
|
turnId: shared.activeTurnId,
|
|
26996
|
-
requestId,
|
|
26997
|
-
permissionRequest,
|
|
26998
|
-
detail: statement.command ??
|
|
26999
|
-
args:
|
|
27441
|
+
requestId: requestId2,
|
|
27442
|
+
permissionRequest: permissionRequest2,
|
|
27443
|
+
detail: statement.command ?? permissionRequest2.detail,
|
|
27444
|
+
args: permissionRequest2.toolCall?.data["rawInput"] ?? params.toolCall.rawInput,
|
|
27000
27445
|
statement,
|
|
27001
27446
|
options: acpApprovalOptions(params),
|
|
27002
27447
|
fileChanges,
|
|
27003
27448
|
source: "acp.jsonrpc",
|
|
27004
27449
|
method: "session/request_permission",
|
|
27005
27450
|
rawPayload: params
|
|
27006
|
-
})
|
|
27007
|
-
|
|
27451
|
+
});
|
|
27452
|
+
return { requestId: requestId2, permissionRequest: permissionRequest2, openedEvent: openedEvent2 };
|
|
27453
|
+
} catch (error62) {
|
|
27454
|
+
if (mutatedToolCall) {
|
|
27455
|
+
restoreTrackedState(trackingKey, immediateHadPrevious, immediatePrevious);
|
|
27456
|
+
}
|
|
27457
|
+
hooks.onPermissionRequestSettled?.({
|
|
27458
|
+
sessionId: params.sessionId,
|
|
27459
|
+
toolCallId: params.toolCall.toolCallId,
|
|
27460
|
+
accepted: false,
|
|
27461
|
+
requestId: settlementId
|
|
27462
|
+
});
|
|
27463
|
+
throw error62;
|
|
27464
|
+
}
|
|
27465
|
+
})();
|
|
27466
|
+
if ("autoApprovedOptionId" in prepared) {
|
|
27467
|
+
return { outcome: { outcome: "selected", optionId: prepared.autoApprovedOptionId } };
|
|
27468
|
+
}
|
|
27469
|
+
const hadApplied = toolCalls.has(trackingKey);
|
|
27470
|
+
const appliedTracked = toolCalls.get(trackingKey);
|
|
27471
|
+
const { requestId, permissionRequest, openedEvent } = prepared;
|
|
27472
|
+
const outcome = await new Promise((resolve2, reject) => {
|
|
27473
|
+
const pending = {
|
|
27474
|
+
requestId,
|
|
27475
|
+
settlementId,
|
|
27476
|
+
request: params,
|
|
27477
|
+
permissionRequest,
|
|
27478
|
+
turnId: shared.activeTurnId,
|
|
27479
|
+
settled: false,
|
|
27480
|
+
resolve: resolve2
|
|
27481
|
+
};
|
|
27482
|
+
if (mutatedToolCall) {
|
|
27483
|
+
recordPermissionMutation({
|
|
27484
|
+
requestId,
|
|
27485
|
+
trackingKey,
|
|
27486
|
+
hasOwnMutation,
|
|
27487
|
+
hadPrevious: immediateHadPrevious,
|
|
27488
|
+
previousTracked: immediatePrevious,
|
|
27489
|
+
hadApplied,
|
|
27490
|
+
appliedTracked
|
|
27491
|
+
});
|
|
27492
|
+
}
|
|
27493
|
+
approvals.add(pending);
|
|
27494
|
+
try {
|
|
27495
|
+
emit(openedEvent);
|
|
27496
|
+
} catch (error62) {
|
|
27497
|
+
reject(error62);
|
|
27498
|
+
approvals.settle(pending, { outcome: "cancelled" });
|
|
27499
|
+
releasePermissionTrackedState(requestId, false);
|
|
27500
|
+
hooks.onPermissionRequestSettled?.({
|
|
27501
|
+
sessionId: params.sessionId,
|
|
27502
|
+
toolCallId: params.toolCall.toolCallId,
|
|
27503
|
+
accepted: false,
|
|
27504
|
+
requestId: settlementId
|
|
27505
|
+
});
|
|
27506
|
+
}
|
|
27008
27507
|
});
|
|
27009
27508
|
return { outcome };
|
|
27010
27509
|
};
|
|
@@ -27062,7 +27561,9 @@ function createExecutorRequests({
|
|
|
27062
27561
|
makeExtensionContext,
|
|
27063
27562
|
handlePermissionRequest,
|
|
27064
27563
|
respondToRequest,
|
|
27065
|
-
respondToUserInput
|
|
27564
|
+
respondToUserInput,
|
|
27565
|
+
supersedePermissionTrackedState,
|
|
27566
|
+
runWithCommittedPermissionBaseline
|
|
27066
27567
|
};
|
|
27067
27568
|
}
|
|
27068
27569
|
|
|
@@ -27964,7 +28465,9 @@ function createExecutorUpdates({
|
|
|
27964
28465
|
emitArtifacts,
|
|
27965
28466
|
closeActiveAssistantSegment,
|
|
27966
28467
|
ensureActiveAssistantSegment,
|
|
27967
|
-
shared
|
|
28468
|
+
shared,
|
|
28469
|
+
supersedePermissionTrackedState,
|
|
28470
|
+
runWithCommittedPermissionBaseline
|
|
27968
28471
|
}) {
|
|
27969
28472
|
const shownToolCallIds = /* @__PURE__ */ new Set();
|
|
27970
28473
|
const markChildSession = shared.childSessions.mark;
|
|
@@ -28105,7 +28608,7 @@ function createExecutorUpdates({
|
|
|
28105
28608
|
sessionId: shared.sessionId,
|
|
28106
28609
|
markChildSession
|
|
28107
28610
|
});
|
|
28108
|
-
const handleSessionUpdate = (params) => {
|
|
28611
|
+
const handleSessionUpdate = (params, rawWireUpdate) => {
|
|
28109
28612
|
const update = params.update;
|
|
28110
28613
|
const reportedOptions = update["configOptions"];
|
|
28111
28614
|
if (update["sessionUpdate"] === "config_option_update" && Array.isArray(reportedOptions)) {
|
|
@@ -28141,11 +28644,45 @@ function createExecutorUpdates({
|
|
|
28141
28644
|
}
|
|
28142
28645
|
for (const event of parsed.events) {
|
|
28143
28646
|
if (event._tag === "ToolCallUpdated") {
|
|
28144
|
-
const
|
|
28647
|
+
const isNewCall = params.update.sessionUpdate === "tool_call";
|
|
28648
|
+
const shownKey = toolCallTrackingKey(params.sessionId, event.toolCall.toolCallId);
|
|
28649
|
+
const wireRecord = isRecord3(rawWireUpdate) ? rawWireUpdate : void 0;
|
|
28650
|
+
const wireMeta = wireRecord !== void 0 && isRecord3(wireRecord["_meta"]) ? wireRecord["_meta"] : void 0;
|
|
28651
|
+
const wireParentMeta = isRecord3(params._meta) ? params._meta : void 0;
|
|
28652
|
+
const hasWireIdentity = wireRecord !== void 0 && (typeof wireRecord["name"] === "string" && wireRecord["name"].trim().length > 0 || wireRecord["name"] === null || typeof wireRecord["mcpServer"] === "string" && wireRecord["mcpServer"].trim().length > 0 || wireRecord["mcpServer"] === null || typeof wireRecord["mcpTool"] === "string" && wireRecord["mcpTool"].trim().length > 0 || wireRecord["mcpTool"] === null || typeof wireRecord["kind"] === "string" && wireRecord["kind"].trim().length > 0 && wireRecord["kind"].trim() !== "other" || wireMeta?.["is_mcp_tool_call"] === false || wireParentMeta?.["is_mcp_tool_call"] === false);
|
|
28653
|
+
const rawTitle = params.update.title;
|
|
28654
|
+
const supersedesPendingPermission = isNewCall || event.toolCall.status === "completed" || event.toolCall.status === "failed" || hasWireIdentity;
|
|
28655
|
+
if (supersedesPendingPermission) {
|
|
28656
|
+
supersedePermissionTrackedState?.(shownKey, { restoreCommitted: true });
|
|
28657
|
+
}
|
|
28658
|
+
const runRetain = () => retainToolCallUpdate(toolCalls, event.toolCall, {
|
|
28659
|
+
sessionId: params.sessionId,
|
|
28145
28660
|
turnId: shared.activeTurnId,
|
|
28146
|
-
rawTitle
|
|
28661
|
+
rawTitle,
|
|
28662
|
+
isNewCall,
|
|
28147
28663
|
nowMs
|
|
28148
28664
|
});
|
|
28665
|
+
const updateRecord = params.update;
|
|
28666
|
+
const passiveRawTitle = wireRecord !== void 0 ? wireRecord["title"] : updateRecord["title"];
|
|
28667
|
+
const passiveWireState = !supersedesPendingPermission && runWithCommittedPermissionBaseline !== void 0 ? makeToolCallState({
|
|
28668
|
+
toolCallId: event.toolCall.toolCallId,
|
|
28669
|
+
title: typeof passiveRawTitle === "string" ? passiveRawTitle : void 0,
|
|
28670
|
+
status: updateRecord["status"],
|
|
28671
|
+
rawInput: updateRecord["rawInput"],
|
|
28672
|
+
rawOutput: updateRecord["rawOutput"],
|
|
28673
|
+
content: updateRecord["content"],
|
|
28674
|
+
locations: updateRecord["locations"]
|
|
28675
|
+
}) : void 0;
|
|
28676
|
+
const { nextToolCall, decision, reset } = !supersedesPendingPermission && runWithCommittedPermissionBaseline !== void 0 ? runWithCommittedPermissionBaseline(
|
|
28677
|
+
shownKey,
|
|
28678
|
+
runRetain,
|
|
28679
|
+
passiveWireState ?? event.toolCall,
|
|
28680
|
+
rawTitle
|
|
28681
|
+
) : runRetain();
|
|
28682
|
+
if (reset) {
|
|
28683
|
+
supersedePermissionTrackedState?.(shownKey);
|
|
28684
|
+
shownToolCallIds.delete(shownKey);
|
|
28685
|
+
}
|
|
28149
28686
|
const hasToolHooks = toolSubagents !== void 0 || hooks.onToolCallUpdated !== void 0;
|
|
28150
28687
|
const toolName = typeof nextToolCall.data["name"] === "string" ? nextToolCall.data["name"] : void 0;
|
|
28151
28688
|
const call = !hasToolHooks ? void 0 : {
|
|
@@ -28171,8 +28708,8 @@ function createExecutorUpdates({
|
|
|
28171
28708
|
continue;
|
|
28172
28709
|
}
|
|
28173
28710
|
const toolTurnId = (hookResult !== void 0 && "events" in hookResult ? hookResult.turnId : void 0) ?? shared.activeTurnId;
|
|
28174
|
-
if (!shownToolCallIds.has(
|
|
28175
|
-
rememberShownToolCall(
|
|
28711
|
+
if (isNewCall || !shownToolCallIds.has(shownKey)) {
|
|
28712
|
+
rememberShownToolCall(shownKey);
|
|
28176
28713
|
if (toolTurnId === shared.activeTurnId) closeActiveAssistantSegment(shared.activeTurnId);
|
|
28177
28714
|
}
|
|
28178
28715
|
emit(
|
|
@@ -28268,7 +28805,7 @@ function createExecutorUpdates({
|
|
|
28268
28805
|
}
|
|
28269
28806
|
}
|
|
28270
28807
|
};
|
|
28271
|
-
const receiveSessionUpdate = (params) => {
|
|
28808
|
+
const receiveSessionUpdate = (params, rawWireUpdate) => {
|
|
28272
28809
|
const foreign = !shared.ownSessionIds.has(params.sessionId) && (shared.childSessions.has(params.sessionId) || shared.sessionOpensInFlight === 0 && shared.ownSessionIds.size > 0);
|
|
28273
28810
|
emitHookEvents(
|
|
28274
28811
|
subagentSessions?.observe(params, {
|
|
@@ -28283,7 +28820,7 @@ function createExecutorUpdates({
|
|
|
28283
28820
|
emitHookEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
|
|
28284
28821
|
}
|
|
28285
28822
|
}
|
|
28286
|
-
if (!foreign) handleSessionUpdate(params);
|
|
28823
|
+
if (!foreign) handleSessionUpdate(params, rawWireUpdate);
|
|
28287
28824
|
};
|
|
28288
28825
|
const receiveExtensionNotification = (method, params) => {
|
|
28289
28826
|
if (shared.sessionLoadInFlight || !hooks.onExtensionNotification) return;
|
|
@@ -28482,6 +29019,27 @@ function createAcpExecutor(options) {
|
|
|
28482
29019
|
promptMutex,
|
|
28483
29020
|
shared
|
|
28484
29021
|
});
|
|
29022
|
+
const {
|
|
29023
|
+
settleAllApprovals,
|
|
29024
|
+
settleAllUserInputs,
|
|
29025
|
+
makeExtensionContext,
|
|
29026
|
+
handlePermissionRequest,
|
|
29027
|
+
respondToRequest,
|
|
29028
|
+
respondToUserInput,
|
|
29029
|
+
supersedePermissionTrackedState,
|
|
29030
|
+
runWithCommittedPermissionBaseline
|
|
29031
|
+
} = createExecutorRequests({
|
|
29032
|
+
emit,
|
|
29033
|
+
stamp,
|
|
29034
|
+
options,
|
|
29035
|
+
approvals,
|
|
29036
|
+
pendingUserInputs,
|
|
29037
|
+
failIfDisposed,
|
|
29038
|
+
randomId,
|
|
29039
|
+
hooks,
|
|
29040
|
+
shared,
|
|
29041
|
+
toolCalls
|
|
29042
|
+
});
|
|
28485
29043
|
const {
|
|
28486
29044
|
emitCompactionState,
|
|
28487
29045
|
receiveSessionUpdate,
|
|
@@ -28501,26 +29059,9 @@ function createAcpExecutor(options) {
|
|
|
28501
29059
|
emitArtifacts,
|
|
28502
29060
|
closeActiveAssistantSegment,
|
|
28503
29061
|
ensureActiveAssistantSegment,
|
|
28504
|
-
shared
|
|
28505
|
-
});
|
|
28506
|
-
const {
|
|
28507
|
-
settleAllApprovals,
|
|
28508
|
-
settleAllUserInputs,
|
|
28509
|
-
makeExtensionContext,
|
|
28510
|
-
handlePermissionRequest,
|
|
28511
|
-
respondToRequest,
|
|
28512
|
-
respondToUserInput
|
|
28513
|
-
} = createExecutorRequests({
|
|
28514
|
-
emit,
|
|
28515
|
-
stamp,
|
|
28516
|
-
options,
|
|
28517
|
-
approvals,
|
|
28518
|
-
pendingUserInputs,
|
|
28519
|
-
failIfDisposed,
|
|
28520
|
-
randomId,
|
|
28521
|
-
hooks,
|
|
28522
29062
|
shared,
|
|
28523
|
-
|
|
29063
|
+
supersedePermissionTrackedState,
|
|
29064
|
+
runWithCommittedPermissionBaseline
|
|
28524
29065
|
});
|
|
28525
29066
|
const { rememberSettledPromptKey, abortPendingSettlement, settleFromNotification } = createExecutorSettlement({ hooks, shared });
|
|
28526
29067
|
const promptResults = createPromptResults({ options, shared });
|
|
@@ -28551,8 +29092,9 @@ function createAcpExecutor(options) {
|
|
|
28551
29092
|
onNotification: (notification) => {
|
|
28552
29093
|
if (notification.method === "session/update") {
|
|
28553
29094
|
const params = notification.params;
|
|
29095
|
+
const rawUpdate = params.update;
|
|
28554
29096
|
const transformed = hooks.transformSessionUpdate ? hooks.transformSessionUpdate(params) : params;
|
|
28555
|
-
if (transformed !== void 0) receiveSessionUpdate(transformed);
|
|
29097
|
+
if (transformed !== void 0) receiveSessionUpdate(transformed, rawUpdate);
|
|
28556
29098
|
return;
|
|
28557
29099
|
}
|
|
28558
29100
|
if (settleFromNotification(notification.method, notification.params)) return;
|
|
@@ -30948,6 +31490,175 @@ var grokPermissionStatement = ({
|
|
|
30948
31490
|
};
|
|
30949
31491
|
};
|
|
30950
31492
|
|
|
31493
|
+
// src/grokMcpTools.ts
|
|
31494
|
+
import {
|
|
31495
|
+
canonicalMcpToolPair,
|
|
31496
|
+
MCP_IDENTIFIER_MAX_CHARS,
|
|
31497
|
+
orderedMcpServerNames
|
|
31498
|
+
} from "@ycodium-ai/plugin-api/executor";
|
|
31499
|
+
var MAX_TRACKED_CALLS = 256;
|
|
31500
|
+
var isRecord12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31501
|
+
var isTerminalStatus = (status) => status === "completed" || status === "failed" || status === "cancelled" || status === "canceled";
|
|
31502
|
+
var callKey = (sessionId, toolCallId) => `${typeof sessionId === "string" ? sessionId : ""}\0${toolCallId}`;
|
|
31503
|
+
function splitGrokQualifiedName(rawName, servers) {
|
|
31504
|
+
if (typeof rawName !== "string") return void 0;
|
|
31505
|
+
const rawTrimmed = rawName.trim();
|
|
31506
|
+
if (rawTrimmed.length === 0 || rawTrimmed.length > MCP_IDENTIFIER_MAX_CHARS * 2 + 10) {
|
|
31507
|
+
return void 0;
|
|
31508
|
+
}
|
|
31509
|
+
const trimmed3 = rawTrimmed.startsWith("mcp__") && !servers.includes("mcp") ? rawTrimmed.slice("mcp__".length) : rawTrimmed;
|
|
31510
|
+
for (const server of servers) {
|
|
31511
|
+
const prefix = `${server}__`;
|
|
31512
|
+
if (!trimmed3.startsWith(prefix)) continue;
|
|
31513
|
+
const found = canonicalMcpToolPair(server, trimmed3.slice(prefix.length));
|
|
31514
|
+
if (found !== void 0) return found;
|
|
31515
|
+
}
|
|
31516
|
+
const sep = trimmed3.indexOf("__");
|
|
31517
|
+
if (sep <= 0 || sep + 2 >= trimmed3.length) return void 0;
|
|
31518
|
+
return canonicalMcpToolPair(trimmed3.slice(0, sep), trimmed3.slice(sep + 2));
|
|
31519
|
+
}
|
|
31520
|
+
function resolveFromRawOutput(rawOutput) {
|
|
31521
|
+
if (!isRecord12(rawOutput) || rawOutput["type"] !== "MCP") {
|
|
31522
|
+
return { mcp: void 0, text: void 0, isError: false };
|
|
31523
|
+
}
|
|
31524
|
+
const server = typeof rawOutput["server_name"] === "string" ? rawOutput["server_name"].trim() : "";
|
|
31525
|
+
const tool = typeof rawOutput["tool_name"] === "string" ? rawOutput["tool_name"].trim() : "";
|
|
31526
|
+
const mcp = canonicalMcpToolPair(server, tool);
|
|
31527
|
+
const output2 = isRecord12(rawOutput["output"]) ? rawOutput["output"] : void 0;
|
|
31528
|
+
if (typeof output2?.["OkayOutput"] === "string") {
|
|
31529
|
+
return { mcp, text: output2["OkayOutput"], isError: false };
|
|
31530
|
+
}
|
|
31531
|
+
if (typeof output2?.["ErrOutput"] === "string") {
|
|
31532
|
+
return { mcp, text: output2["ErrOutput"], isError: true };
|
|
31533
|
+
}
|
|
31534
|
+
return { mcp, text: void 0, isError: false };
|
|
31535
|
+
}
|
|
31536
|
+
function xaiToolKind(meta3) {
|
|
31537
|
+
if (!isRecord12(meta3)) return void 0;
|
|
31538
|
+
const xai = meta3["x.ai/tool"];
|
|
31539
|
+
if (!isRecord12(xai) || typeof xai["kind"] !== "string") return void 0;
|
|
31540
|
+
return xai["kind"].trim() || void 0;
|
|
31541
|
+
}
|
|
31542
|
+
function unwrapGrokUseToolRawInput(rawInput) {
|
|
31543
|
+
if (!isRecord12(rawInput)) return rawInput;
|
|
31544
|
+
if (isRecord12(rawInput["tool_input"])) return rawInput["tool_input"];
|
|
31545
|
+
return rawInput;
|
|
31546
|
+
}
|
|
31547
|
+
function createGrokMcpToolHooks(mcpServers) {
|
|
31548
|
+
const servers = orderedMcpServerNames((mcpServers ?? []).map((server) => server.name));
|
|
31549
|
+
const remembered = /* @__PURE__ */ new Map();
|
|
31550
|
+
const pendingApprovalOnly = /* @__PURE__ */ new Map();
|
|
31551
|
+
const remember = (key, value) => {
|
|
31552
|
+
remembered.delete(key);
|
|
31553
|
+
if (remembered.size >= MAX_TRACKED_CALLS) {
|
|
31554
|
+
const oldest = remembered.keys().next().value;
|
|
31555
|
+
if (oldest !== void 0) remembered.delete(oldest);
|
|
31556
|
+
}
|
|
31557
|
+
remembered.set(key, value);
|
|
31558
|
+
};
|
|
31559
|
+
return {
|
|
31560
|
+
transformSessionUpdate: (notification) => {
|
|
31561
|
+
const update = notification.update;
|
|
31562
|
+
const variant = update["sessionUpdate"];
|
|
31563
|
+
if (variant !== "tool_call" && variant !== "tool_call_update") {
|
|
31564
|
+
return notification;
|
|
31565
|
+
}
|
|
31566
|
+
const toolCallId = typeof update["toolCallId"] === "string" ? update["toolCallId"].trim() : "";
|
|
31567
|
+
const key = toolCallId ? callKey(notification.sessionId, toolCallId) : void 0;
|
|
31568
|
+
const isNew = variant === "tool_call";
|
|
31569
|
+
const terminal = isTerminalStatus(update["status"]);
|
|
31570
|
+
const kind = xaiToolKind(update["_meta"]);
|
|
31571
|
+
const fromOutput = resolveFromRawOutput(update["rawOutput"]);
|
|
31572
|
+
if (kind !== void 0 && kind !== "use_tool") {
|
|
31573
|
+
if (key !== void 0) remembered.delete(key);
|
|
31574
|
+
return {
|
|
31575
|
+
...notification,
|
|
31576
|
+
update: {
|
|
31577
|
+
...update,
|
|
31578
|
+
mcpServer: null,
|
|
31579
|
+
mcpTool: null
|
|
31580
|
+
}
|
|
31581
|
+
};
|
|
31582
|
+
}
|
|
31583
|
+
const rawInput = isRecord12(update["rawInput"]) ? update["rawInput"] : void 0;
|
|
31584
|
+
const fromInput = kind === "use_tool" ? splitGrokQualifiedName(rawInput?.["tool_name"] ?? update["title"], servers) : void 0;
|
|
31585
|
+
const inherited = !isNew && key !== void 0 ? remembered.get(key) : void 0;
|
|
31586
|
+
const resolved = fromInput ?? fromOutput.mcp ?? inherited;
|
|
31587
|
+
if (resolved === void 0) {
|
|
31588
|
+
if (terminal && key !== void 0) remembered.delete(key);
|
|
31589
|
+
return notification;
|
|
31590
|
+
}
|
|
31591
|
+
if (key !== void 0) {
|
|
31592
|
+
if (terminal) remembered.delete(key);
|
|
31593
|
+
else remember(key, resolved);
|
|
31594
|
+
}
|
|
31595
|
+
const unwrappedInput = unwrapGrokUseToolRawInput(update["rawInput"]);
|
|
31596
|
+
const nextContent = update["content"] === void 0 && fromOutput.text !== void 0 ? [{ type: "content", content: { type: "text", text: fromOutput.text } }] : update["content"];
|
|
31597
|
+
const nextRawOutput = fromOutput.text !== void 0 ? fromOutput.isError ? { isError: true, content: fromOutput.text } : fromOutput.text : update["rawOutput"];
|
|
31598
|
+
return {
|
|
31599
|
+
...notification,
|
|
31600
|
+
update: {
|
|
31601
|
+
...update,
|
|
31602
|
+
name: resolved.canonicalName,
|
|
31603
|
+
mcpServer: resolved.server,
|
|
31604
|
+
mcpTool: resolved.tool,
|
|
31605
|
+
title: resolved.canonicalName,
|
|
31606
|
+
...unwrappedInput !== void 0 ? { rawInput: unwrappedInput } : {},
|
|
31607
|
+
...nextContent !== void 0 ? { content: nextContent } : {},
|
|
31608
|
+
...nextRawOutput !== void 0 ? { rawOutput: nextRawOutput } : {}
|
|
31609
|
+
}
|
|
31610
|
+
};
|
|
31611
|
+
},
|
|
31612
|
+
transformPermissionRequest: (params, context) => {
|
|
31613
|
+
if (!isRecord12(params) || !isRecord12(params["toolCall"])) return params;
|
|
31614
|
+
const toolCall = params["toolCall"];
|
|
31615
|
+
const toolCallId = typeof toolCall["toolCallId"] === "string" ? toolCall["toolCallId"].trim() : "";
|
|
31616
|
+
const key = toolCallId ? callKey(params["sessionId"], toolCallId) : void 0;
|
|
31617
|
+
const kind = xaiToolKind(toolCall["_meta"]);
|
|
31618
|
+
if (kind !== void 0 && kind !== "use_tool") {
|
|
31619
|
+
return {
|
|
31620
|
+
...params,
|
|
31621
|
+
toolCall: {
|
|
31622
|
+
...toolCall,
|
|
31623
|
+
mcpServer: null,
|
|
31624
|
+
mcpTool: null
|
|
31625
|
+
}
|
|
31626
|
+
};
|
|
31627
|
+
}
|
|
31628
|
+
const rawInput = isRecord12(toolCall["rawInput"]) ? toolCall["rawInput"] : void 0;
|
|
31629
|
+
const fromReq = kind === "use_tool" ? splitGrokQualifiedName(rawInput?.["tool_name"] ?? toolCall["title"], servers) : void 0;
|
|
31630
|
+
const existing = key !== void 0 ? remembered.get(key) : void 0;
|
|
31631
|
+
const resolved = fromReq ?? existing;
|
|
31632
|
+
if (resolved === void 0) return params;
|
|
31633
|
+
if (key !== void 0 && existing === void 0) {
|
|
31634
|
+
remember(key, resolved);
|
|
31635
|
+
if (context?.requestId !== void 0) {
|
|
31636
|
+
pendingApprovalOnly.set(context.requestId, key);
|
|
31637
|
+
}
|
|
31638
|
+
}
|
|
31639
|
+
return {
|
|
31640
|
+
...params,
|
|
31641
|
+
toolCall: {
|
|
31642
|
+
...toolCall,
|
|
31643
|
+
name: resolved.canonicalName,
|
|
31644
|
+
mcpServer: resolved.server,
|
|
31645
|
+
mcpTool: resolved.tool,
|
|
31646
|
+
title: resolved.canonicalName,
|
|
31647
|
+
...toolCall["rawInput"] !== void 0 ? { rawInput: unwrapGrokUseToolRawInput(toolCall["rawInput"]) } : {}
|
|
31648
|
+
}
|
|
31649
|
+
};
|
|
31650
|
+
},
|
|
31651
|
+
onPermissionRequestSettled: ({ accepted, requestId }) => {
|
|
31652
|
+
if (requestId === void 0) return;
|
|
31653
|
+
const key = pendingApprovalOnly.get(requestId);
|
|
31654
|
+
pendingApprovalOnly.delete(requestId);
|
|
31655
|
+
if (!accepted && key !== void 0) {
|
|
31656
|
+
remembered.delete(key);
|
|
31657
|
+
}
|
|
31658
|
+
}
|
|
31659
|
+
};
|
|
31660
|
+
}
|
|
31661
|
+
|
|
30951
31662
|
// src/nativeSessions.ts
|
|
30952
31663
|
import * as NodeFS5 from "node:fs";
|
|
30953
31664
|
import * as NodeFSP from "node:fs/promises";
|
|
@@ -31401,6 +32112,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
31401
32112
|
const backgroundTasks = /* @__PURE__ */ new Map();
|
|
31402
32113
|
const subagents = createGrokSubagents();
|
|
31403
32114
|
const turnUsage = createGrokTurnUsageCollector(grokPromptSettlement);
|
|
32115
|
+
const mcpToolHooks = createGrokMcpToolHooks(input2.mcpServers);
|
|
31404
32116
|
const executor = createAcpExecutor({
|
|
31405
32117
|
readable,
|
|
31406
32118
|
writable,
|
|
@@ -31421,6 +32133,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
31421
32133
|
// 播报的 `authMethods` 说了算(见 resolveGrokAuthMethodId)。
|
|
31422
32134
|
authMethodId: resolveGrokAuthMethodId,
|
|
31423
32135
|
hooks: {
|
|
32136
|
+
...mcpToolHooks,
|
|
31424
32137
|
permissionStatement: grokPermissionStatement,
|
|
31425
32138
|
promptSettlement: turnUsage.settlement,
|
|
31426
32139
|
// 运行中再收到的 prompt 由 grok 自己排队、在下一个工具调用结束时并进这一轮(配合上面写的配置)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-grok",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5939",
|
|
4
4
|
"description": "Grok executor: grok CLI over Agent Client Protocol stdio.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@types/node": "24.12.4",
|
|
22
22
|
"esbuild": "0.28.1",
|
|
23
23
|
"vite-plus": "0.2.2",
|
|
24
|
-
"ycodium-
|
|
24
|
+
"@ycodium-ai/plugin-api": "0.2.5939",
|
|
25
25
|
"ycodium-credential-account": "0.0.0",
|
|
26
|
-
"
|
|
26
|
+
"ycodium-acp-executor": "0.2.5939",
|
|
27
27
|
"ycodium-executor-testing": "0.0.0"
|
|
28
28
|
},
|
|
29
29
|
"ycodium": {
|