@ycodium-ai/agent-kimi 0.2.5891 → 0.2.5921

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.
Files changed (2) hide show
  1. package/dist/index.js +665 -128
  2. 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 = 185;
11
+ var PLUGIN_API_VERSION = 187;
12
12
 
13
13
  // src/index.ts
14
14
  import * as NodeOS6 from "node:os";
@@ -715,6 +715,17 @@ function canonicalItemTypeFromAcpToolKind(kind) {
715
715
  }
716
716
 
717
717
  // ../../packages/ycodium-acp-executor/src/tool-call-state.ts
718
+ var clearedIdentityFields = /* @__PURE__ */ new WeakMap();
719
+ function readToolCallIdentityFields(state, options) {
720
+ const cleared = clearedIdentityFields.get(state);
721
+ return {
722
+ name: cleared?.name === null ? null : state.data["name"],
723
+ kind: options?.kindFromData ? state.data["kind"] : state.kind,
724
+ mcpServer: cleared?.mcpServer === null ? null : state.data["mcpServer"],
725
+ mcpTool: cleared?.mcpTool === null ? null : state.data["mcpTool"],
726
+ negativeMcp: cleared?.negativeMcp === true
727
+ };
728
+ }
718
729
  function normalizeToolCallStatus(raw, fallback) {
719
730
  switch (raw) {
720
731
  case "pending":
@@ -847,6 +858,13 @@ function makeToolCallState(input2, options) {
847
858
  if (!toolCallId) {
848
859
  return void 0;
849
860
  }
861
+ const explicitNullMcp = input2.mcpServer === null || input2.mcpTool === null;
862
+ const reqMetaFlag = isRecord2(input2._meta) && typeof input2._meta["is_mcp_tool_call"] === "boolean" ? input2._meta["is_mcp_tool_call"] : void 0;
863
+ const parentMetaFlag = isRecord2(input2.parentMeta) && typeof input2.parentMeta["is_mcp_tool_call"] === "boolean" ? input2.parentMeta["is_mcp_tool_call"] : void 0;
864
+ const metaFlag = reqMetaFlag === false || parentMetaFlag === false ? false : reqMetaFlag === true || parentMetaFlag === true ? true : void 0;
865
+ const explicitPositiveMcp = !explicitNullMcp && metaFlag !== false && (metaFlag === true || readAcpText(input2, "mcpServer") !== void 0 && readAcpText(input2, "mcpTool") !== void 0);
866
+ const explicitNegativeMcp = explicitNullMcp || metaFlag === false;
867
+ const negativeMcp = explicitNegativeMcp || !explicitPositiveMcp && options?.inheritedNegativeMcp === true;
850
868
  const title = typeof input2.title === "string" ? input2.title.trim() || void 0 : void 0;
851
869
  const command = extractToolCallCommand(input2.rawInput, title);
852
870
  const extractedContent = extractTextContentFromToolCallContent(input2.content);
@@ -860,6 +878,12 @@ function makeToolCallState(input2, options) {
860
878
  const name = readAcpText(input2, "name");
861
879
  if (name) {
862
880
  data["name"] = name;
881
+ const mcpServer = readAcpText(input2, "mcpServer");
882
+ const mcpTool = readAcpText(input2, "mcpTool");
883
+ if (!negativeMcp && mcpServer !== void 0 && mcpTool !== void 0) {
884
+ data["mcpServer"] = mcpServer;
885
+ data["mcpTool"] = mcpTool;
886
+ }
863
887
  }
864
888
  if (command) {
865
889
  data["command"] = command;
@@ -886,7 +910,7 @@ function makeToolCallState(input2, options) {
886
910
  fallbackSummary: title ?? "Tool"
887
911
  }) : void 0;
888
912
  const status = normalizeToolCallStatus(input2.status, options?.fallbackStatus);
889
- return {
913
+ const state = {
890
914
  toolCallId,
891
915
  ...kind ? { kind } : {},
892
916
  ...presentation?.summary ? { title: presentation.summary } : {},
@@ -896,8 +920,50 @@ function makeToolCallState(input2, options) {
896
920
  ...textContent ? { contentText: textContent } : {},
897
921
  data
898
922
  };
923
+ if (input2.name === null || input2.mcpServer === null || input2.mcpTool === null || negativeMcp || explicitPositiveMcp) {
924
+ clearedIdentityFields.set(state, {
925
+ ...input2.name === null ? { name: null } : {},
926
+ ...input2.mcpServer === null ? { mcpServer: null } : {},
927
+ ...input2.mcpTool === null ? { mcpTool: null } : {},
928
+ ...negativeMcp ? { negativeMcp: true } : {},
929
+ ...explicitPositiveMcp ? { positiveMcp: true } : {}
930
+ });
931
+ }
932
+ return state;
933
+ }
934
+ function toolCallIdentityChanged(previous, next) {
935
+ const prevName = readAcpText(previous, "name");
936
+ const nextName = readAcpText(next, "name");
937
+ const prevKind = normalizeToolKind(previous.kind);
938
+ const nextKind = normalizeToolKind(next.kind);
939
+ const prevServer = readAcpText(previous, "mcpServer");
940
+ const nextServer = readAcpText(next, "mcpServer");
941
+ const prevTool = readAcpText(previous, "mcpTool");
942
+ const nextTool = readAcpText(next, "mcpTool");
943
+ const clearedName = prevName !== void 0 && next.name === null;
944
+ const clearedServer = prevServer !== void 0 && next.mcpServer === null;
945
+ const clearedTool = prevTool !== void 0 && next.mcpTool === null;
946
+ 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;
899
947
  }
900
948
  function mergeToolCallState(previous, next) {
949
+ if (previous !== void 0 && toolCallIdentityChanged(
950
+ {
951
+ name: previous.data["name"],
952
+ kind: previous.kind,
953
+ mcpServer: previous.data["mcpServer"],
954
+ mcpTool: previous.data["mcpTool"]
955
+ },
956
+ readToolCallIdentityFields(next, { kindFromData: true })
957
+ )) {
958
+ const status2 = next.status ?? previous.status;
959
+ if (status2 === void 0 || status2 === next.status) {
960
+ return next;
961
+ }
962
+ const replaced = { ...next, status: status2 };
963
+ const nextCleared2 = clearedIdentityFields.get(next);
964
+ if (nextCleared2 !== void 0) clearedIdentityFields.set(replaced, nextCleared2);
965
+ return replaced;
966
+ }
901
967
  const nextKind = typeof next.data["kind"] === "string" ? next.data["kind"] : void 0;
902
968
  const kind = nextKind ?? previous?.kind;
903
969
  const title = next.title ?? previous?.title;
@@ -905,7 +971,18 @@ function mergeToolCallState(previous, next) {
905
971
  const command = next.command ?? previous?.command;
906
972
  const detail = next.detail ?? previous?.detail;
907
973
  const contentText = "content" in next.data ? next.contentText : previous?.contentText;
908
- return {
974
+ const prevCleared = previous === void 0 ? void 0 : clearedIdentityFields.get(previous);
975
+ const nextCleared = clearedIdentityFields.get(next);
976
+ const nextPositiveMcp = typeof next.data["mcpServer"] === "string" && typeof next.data["mcpTool"] === "string" || nextCleared?.positiveMcp === true;
977
+ const mergedNegativeMcp = nextCleared?.negativeMcp === true || !nextPositiveMcp && prevCleared?.negativeMcp === true;
978
+ const clearPreviousMcp = previous !== void 0 && (mergedNegativeMcp || next.data["name"] !== void 0 && next.data["mcpServer"] === void 0);
979
+ const previousData = clearPreviousMcp ? Object.fromEntries(
980
+ Object.entries(previous.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool")
981
+ ) : previous?.data;
982
+ const nextData = mergedNegativeMcp ? Object.fromEntries(
983
+ Object.entries(next.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool")
984
+ ) : next.data;
985
+ const merged = {
909
986
  toolCallId: next.toolCallId,
910
987
  ...kind ? { kind } : {},
911
988
  ...title ? { title } : {},
@@ -914,10 +991,16 @@ function mergeToolCallState(previous, next) {
914
991
  ...detail ? { detail } : {},
915
992
  ...contentText ? { contentText } : {},
916
993
  data: {
917
- ...previous?.data,
918
- ...next.data
994
+ ...previousData,
995
+ ...nextData
919
996
  }
920
997
  };
998
+ if (mergedNegativeMcp) {
999
+ clearedIdentityFields.set(merged, { negativeMcp: true });
1000
+ } else if (nextPositiveMcp || prevCleared?.positiveMcp === true) {
1001
+ clearedIdentityFields.set(merged, { positiveMcp: true });
1002
+ }
1003
+ return merged;
921
1004
  }
922
1005
  var TOOL_CALL_UPDATE_MIN_DETAIL_GROWTH_CHARS = 256;
923
1006
  var TOOL_CALL_UPDATE_COALESCE_LIMIT = 10;
@@ -1072,20 +1155,47 @@ function parseAvailableCommandsUpdate(params) {
1072
1155
  }
1073
1156
  function parsePermissionRequest(params, known) {
1074
1157
  const request = params.toolCall;
1158
+ const requestFields = request;
1075
1159
  const earlier = known?.state.data;
1160
+ const identityChanged = known !== void 0 && toolCallIdentityChanged(
1161
+ {
1162
+ name: earlier?.["name"],
1163
+ kind: known.state.kind,
1164
+ mcpServer: earlier?.["mcpServer"],
1165
+ mcpTool: earlier?.["mcpTool"]
1166
+ },
1167
+ {
1168
+ name: requestFields.name,
1169
+ kind: request.kind,
1170
+ mcpServer: requestFields.mcpServer,
1171
+ mcpTool: requestFields.mcpTool
1172
+ }
1173
+ );
1174
+ const prior = identityChanged ? void 0 : known;
1175
+ const priorData = identityChanged ? void 0 : earlier;
1176
+ const priorNegativeMcp = prior !== void 0 ? readToolCallIdentityFields(prior.state).negativeMcp : false;
1177
+ const reqMeta = request._meta;
1178
+ const parentMeta = params._meta;
1179
+ const requestNegativeMcp = requestFields.mcpServer === null || requestFields.mcpTool === null || isRecord2(reqMeta) && reqMeta["is_mcp_tool_call"] === false || isRecord2(parentMeta) && parentMeta["is_mcp_tool_call"] === false;
1180
+ const allowPriorMcpFields = !priorNegativeMcp && !requestNegativeMcp && requestFields.name === void 0;
1181
+ const inheritedRawTitle = prior?.rawTitle !== void 0 && !((priorNegativeMcp || requestNegativeMcp) && /^(?:(?:Running|Run)\s+)?mcp_/u.test(prior.rawTitle.trim())) ? prior.rawTitle : void 0;
1076
1182
  const toolCall = makeToolCallState(
1077
1183
  {
1078
1184
  toolCallId: request.toolCallId,
1079
- name: earlier?.["name"],
1080
- title: request.title ?? known?.rawTitle,
1081
- kind: request.kind ?? earlier?.["kind"],
1185
+ name: requestFields.name !== void 0 ? requestFields.name : priorData?.["name"],
1186
+ mcpServer: requestFields.mcpServer !== void 0 ? requestFields.mcpServer : allowPriorMcpFields ? priorData?.["mcpServer"] : void 0,
1187
+ mcpTool: requestFields.mcpTool !== void 0 ? requestFields.mcpTool : allowPriorMcpFields ? priorData?.["mcpTool"] : void 0,
1188
+ title: request.title ?? inheritedRawTitle,
1189
+ kind: request.kind ?? priorData?.["kind"],
1082
1190
  status: request.status ?? known?.state.status,
1083
- rawInput: request.rawInput !== void 0 ? request.rawInput : earlier?.["rawInput"],
1084
- rawOutput: request.rawOutput !== void 0 ? request.rawOutput : earlier?.["rawOutput"],
1085
- content: request.content !== void 0 ? request.content : earlier?.["content"],
1086
- locations: request.locations !== void 0 ? request.locations : earlier?.["locations"]
1191
+ rawInput: request.rawInput !== void 0 ? request.rawInput : priorData?.["rawInput"],
1192
+ rawOutput: request.rawOutput !== void 0 ? request.rawOutput : priorData?.["rawOutput"],
1193
+ content: request.content !== void 0 ? request.content : priorData?.["content"],
1194
+ locations: request.locations !== void 0 ? request.locations : priorData?.["locations"],
1195
+ _meta: reqMeta,
1196
+ parentMeta
1087
1197
  },
1088
- { fallbackStatus: "pending" }
1198
+ { fallbackStatus: "pending", ...priorNegativeMcp ? { inheritedNegativeMcp: true } : {} }
1089
1199
  );
1090
1200
  const kind = toolCall?.kind ?? "unknown";
1091
1201
  const content = toolCall?.data["content"];
@@ -1095,7 +1205,7 @@ function parsePermissionRequest(params, known) {
1095
1205
  const block = entry["content"];
1096
1206
  return block["type"] === "text" && typeof block["text"] === "string" && block["text"].trim() ? [block["text"]] : [];
1097
1207
  })[0] : void 0;
1098
- const originalTitle = (request.title ?? known?.rawTitle)?.trim() || void 0;
1208
+ const originalTitle = (request.title ?? inheritedRawTitle)?.trim() || void 0;
1099
1209
  const detail = toolCall?.command ?? firstText ?? originalTitle;
1100
1210
  return {
1101
1211
  kind,
@@ -1166,13 +1276,17 @@ function parseSessionUpdateEvent(params) {
1166
1276
  {
1167
1277
  toolCallId: upd["toolCallId"],
1168
1278
  name: upd["name"],
1279
+ mcpServer: upd["mcpServer"],
1280
+ mcpTool: upd["mcpTool"],
1169
1281
  title: typeof upd["title"] === "string" ? upd["title"] : void 0,
1170
1282
  kind: upd["kind"],
1171
1283
  status: upd["status"],
1172
1284
  rawInput: upd["rawInput"],
1173
1285
  rawOutput: upd["rawOutput"],
1174
1286
  content: upd["content"],
1175
- locations: upd["locations"]
1287
+ locations: upd["locations"],
1288
+ _meta: upd["_meta"],
1289
+ parentMeta: params._meta
1176
1290
  },
1177
1291
  kind === "tool_call" ? { fallbackStatus: "pending" } : void 0
1178
1292
  );
@@ -1281,6 +1395,38 @@ function canonicalRequestTypeFromAcpKind(kind) {
1281
1395
  return "dynamic_tool_call";
1282
1396
  }
1283
1397
  }
1398
+ var MAX_ACP_FILE_CHANGES = 256;
1399
+ var MAX_ACP_FILE_CHANGE_PATH_CHARS = 4096;
1400
+ var MAX_DISPLAY_FILE_CHANGES = 20;
1401
+ var isValidAcpFilePath = (value) => typeof value === "string" && value.trim().length > 0 && value.length <= MAX_ACP_FILE_CHANGE_PATH_CHARS;
1402
+ var isTruncatedFileChangesMarker = (value) => value !== null && typeof value === "object" && value["ycodiumFileChangesTruncated"] === true;
1403
+ var clippedDiffBlocks = /* @__PURE__ */ new WeakMap();
1404
+ function readAcpDiffTooLarge(block) {
1405
+ return block !== null && typeof block === "object" ? clippedDiffBlocks.get(block) : void 0;
1406
+ }
1407
+ function acpFileChangeFromDiffBlock(block, path) {
1408
+ const oldText = typeof block["oldText"] === "string" ? block["oldText"] : void 0;
1409
+ const changeKind = oldText === void 0 ? "add" : "modify";
1410
+ const clipped = readAcpDiffTooLarge(block);
1411
+ if (clipped !== void 0) {
1412
+ return {
1413
+ path,
1414
+ changeKind,
1415
+ additions: clipped.additions,
1416
+ deletions: clipped.deletions,
1417
+ omitted: "too-large"
1418
+ };
1419
+ }
1420
+ return {
1421
+ path,
1422
+ changeKind,
1423
+ content: {
1424
+ kind: "replace",
1425
+ ...oldText !== void 0 ? { oldText } : {},
1426
+ newText: block["newText"]
1427
+ }
1428
+ };
1429
+ }
1284
1430
  function fileChangesFromAcpPermission(permissionRequest) {
1285
1431
  const content = permissionRequest.toolCall?.data["content"];
1286
1432
  const changes = Array.isArray(content) ? content.flatMap((entry) => {
@@ -1288,34 +1434,106 @@ function fileChangesFromAcpPermission(permissionRequest) {
1288
1434
  return [];
1289
1435
  }
1290
1436
  const block = entry;
1291
- if (block["type"] !== "diff" || typeof block["path"] !== "string" || typeof block["newText"] !== "string") {
1437
+ if (block["type"] !== "diff" || !isValidAcpFilePath(block["path"]) || typeof block["newText"] !== "string") {
1292
1438
  return [];
1293
1439
  }
1294
- const oldText = typeof block["oldText"] === "string" ? block["oldText"] : void 0;
1295
- return [
1296
- {
1297
- path: block["path"],
1298
- changeKind: oldText === void 0 ? "add" : "modify",
1299
- content: {
1300
- kind: "replace",
1301
- ...oldText !== void 0 ? { oldText } : {},
1302
- newText: block["newText"]
1303
- }
1304
- }
1305
- ];
1440
+ return [acpFileChangeFromDiffBlock(block, block["path"])];
1306
1441
  }) : [];
1307
- if (changes.length > 0) {
1308
- return changes;
1442
+ const boundedChanges = changes.length > MAX_ACP_FILE_CHANGES ? changes.slice(0, MAX_ACP_FILE_CHANGES) : changes;
1443
+ const requestType = canonicalRequestTypeFromAcpKind(permissionRequest.kind);
1444
+ if (boundedChanges.length > 0 || requestType === "file_change_approval" || requestType === "file_read_approval") {
1445
+ const locations = permissionRequest.toolCall?.data["locations"];
1446
+ const seenPaths = new Set(boundedChanges.map((change) => change.path));
1447
+ if (Array.isArray(locations)) {
1448
+ for (const entry of locations) {
1449
+ if (boundedChanges.length >= MAX_ACP_FILE_CHANGES) break;
1450
+ const rawPath = entry?.["path"];
1451
+ if (!isValidAcpFilePath(rawPath)) continue;
1452
+ if (!seenPaths.has(rawPath)) {
1453
+ seenPaths.add(rawPath);
1454
+ boundedChanges.push({ path: rawPath, omitted: "unavailable" });
1455
+ }
1456
+ }
1457
+ }
1458
+ }
1459
+ return boundedChanges.length > 0 ? boundedChanges : void 0;
1460
+ }
1461
+ function inspectAcpPermissionFileChanges(permissionRequest, inputFileChanges) {
1462
+ const merged = [];
1463
+ let fileChangesTruncated = false;
1464
+ for (const entry of inputFileChanges ?? []) {
1465
+ if (!isValidAcpFilePath(entry.path) || merged.length >= MAX_ACP_FILE_CHANGES) {
1466
+ fileChangesTruncated = true;
1467
+ continue;
1468
+ }
1469
+ merged.push(entry);
1309
1470
  }
1310
- if (canonicalRequestTypeFromAcpKind(permissionRequest.kind) !== "file_change_approval") {
1311
- return void 0;
1471
+ const seenPaths = new Set(merged.map((change) => change.path));
1472
+ const content = permissionRequest.toolCall?.data["content"];
1473
+ if (Array.isArray(content)) {
1474
+ let diffCount = 0;
1475
+ for (const entry of content) {
1476
+ if (isTruncatedFileChangesMarker(entry)) {
1477
+ fileChangesTruncated = true;
1478
+ continue;
1479
+ }
1480
+ if (entry === null || typeof entry !== "object") continue;
1481
+ const block = entry;
1482
+ if (block["type"] !== "diff") continue;
1483
+ diffCount += 1;
1484
+ const diffPath = block["path"];
1485
+ const newText = block["newText"];
1486
+ if (diffCount > MAX_ACP_FILE_CHANGES || !isValidAcpFilePath(diffPath) || typeof newText !== "string") {
1487
+ fileChangesTruncated = true;
1488
+ continue;
1489
+ }
1490
+ if (!seenPaths.has(diffPath)) {
1491
+ if (merged.length >= MAX_ACP_FILE_CHANGES) {
1492
+ fileChangesTruncated = true;
1493
+ continue;
1494
+ }
1495
+ seenPaths.add(diffPath);
1496
+ merged.push(acpFileChangeFromDiffBlock(block, diffPath));
1497
+ }
1498
+ }
1312
1499
  }
1500
+ const requestType = canonicalRequestTypeFromAcpKind(permissionRequest.kind);
1313
1501
  const locations = permissionRequest.toolCall?.data["locations"];
1314
- const paths = Array.isArray(locations) ? locations.flatMap((entry) => {
1315
- const path = entry?.["path"];
1316
- return typeof path === "string" && path.trim().length > 0 ? [path] : [];
1317
- }) : [];
1318
- return paths.length > 0 ? paths.map((path) => ({ path, omitted: "unavailable" })) : void 0;
1502
+ const hasLocationTruncationMarker = Array.isArray(locations) && locations.some(isTruncatedFileChangesMarker);
1503
+ if (Array.isArray(locations) && (merged.length > 0 || requestType === "file_change_approval" || requestType === "file_read_approval" || hasLocationTruncationMarker)) {
1504
+ let locationEntries = 0;
1505
+ for (const entry of locations) {
1506
+ if (isTruncatedFileChangesMarker(entry)) {
1507
+ fileChangesTruncated = true;
1508
+ continue;
1509
+ }
1510
+ locationEntries += 1;
1511
+ if (locationEntries > MAX_ACP_FILE_CHANGES) {
1512
+ fileChangesTruncated = true;
1513
+ continue;
1514
+ }
1515
+ const rawPath = entry !== null && typeof entry === "object" ? entry["path"] : void 0;
1516
+ if (!isValidAcpFilePath(rawPath)) {
1517
+ fileChangesTruncated = true;
1518
+ continue;
1519
+ }
1520
+ if (!seenPaths.has(rawPath)) {
1521
+ if (merged.length >= MAX_ACP_FILE_CHANGES) {
1522
+ fileChangesTruncated = true;
1523
+ continue;
1524
+ }
1525
+ seenPaths.add(rawPath);
1526
+ merged.push({ path: rawPath, omitted: "unavailable" });
1527
+ }
1528
+ }
1529
+ }
1530
+ if (merged.length > MAX_DISPLAY_FILE_CHANGES) {
1531
+ fileChangesTruncated = true;
1532
+ }
1533
+ return {
1534
+ fileChanges: merged.length > 0 ? merged : void 0,
1535
+ fileChangesTruncated
1536
+ };
1319
1537
  }
1320
1538
  function runtimeItemStatusFromAcpToolStatus(status) {
1321
1539
  switch (status) {
@@ -1332,7 +1550,19 @@ function runtimeItemStatusFromAcpToolStatus(status) {
1332
1550
  }
1333
1551
  function makeAcpRequestOpenedEvent(input2) {
1334
1552
  const requestType = canonicalRequestTypeFromAcpKind(input2.permissionRequest.kind);
1335
- const toolName = requestType === "dynamic_tool_call" ? input2.permissionRequest.toolCall?.title : void 0;
1553
+ const isDynamicToolKind = input2.permissionRequest.kind === "other" || input2.permissionRequest.kind === "unknown";
1554
+ const cleared = input2.permissionRequest.toolCall ? readToolCallIdentityFields(input2.permissionRequest.toolCall) : void 0;
1555
+ const rawRecord = input2.rawPayload !== null && typeof input2.rawPayload === "object" ? input2.rawPayload : void 0;
1556
+ const rawToolCall = rawRecord !== void 0 && rawRecord["toolCall"] !== null && typeof rawRecord["toolCall"] === "object" ? rawRecord["toolCall"] : void 0;
1557
+ const rawToolMeta = rawToolCall !== void 0 && rawToolCall["_meta"] !== null && typeof rawToolCall["_meta"] === "object" ? rawToolCall["_meta"] : void 0;
1558
+ const rawParentMeta = rawRecord !== void 0 && rawRecord["_meta"] !== null && typeof rawRecord["_meta"] === "object" ? rawRecord["_meta"] : void 0;
1559
+ 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;
1560
+ const candidateToolName = requestType === "dynamic_tool_call" && isDynamicToolKind && typeof input2.permissionRequest.toolCall?.data["name"] === "string" ? input2.permissionRequest.toolCall.data["name"] : void 0;
1561
+ const toolName = candidateToolName !== void 0 && !(negativeMcp && /^(?:(?:Running|Run)\s+)?mcp_/u.test(candidateToolName.trim())) ? candidateToolName : void 0;
1562
+ const { fileChanges, fileChangesTruncated } = inspectAcpPermissionFileChanges(
1563
+ input2.permissionRequest,
1564
+ input2.fileChanges
1565
+ );
1336
1566
  return {
1337
1567
  type: "request.opened",
1338
1568
  ...input2.stamp,
@@ -1347,7 +1577,8 @@ function makeAcpRequestOpenedEvent(input2) {
1347
1577
  args: input2.args,
1348
1578
  ...input2.statement !== void 0 ? { statement: input2.statement } : {},
1349
1579
  ...input2.options ? { options: input2.options } : {},
1350
- ...input2.fileChanges ? { fileChanges: input2.fileChanges } : {},
1580
+ ...fileChanges ? { fileChanges } : {},
1581
+ ...fileChangesTruncated ? { fileChangesTruncated: true } : {},
1351
1582
  declineReasonRelay: "queued"
1352
1583
  },
1353
1584
  raw: {
@@ -1389,7 +1620,8 @@ function makeAcpPlanUpdatedEvent(input2) {
1389
1620
  }
1390
1621
  function makeAcpToolCallEvent(input2) {
1391
1622
  const runtimeStatus = runtimeItemStatusFromAcpToolStatus(input2.toolCall.status);
1392
- const { data } = input2.toolCall;
1623
+ const rawData = input2.toolCall.data;
1624
+ const data = readToolCallIdentityFields(input2.toolCall).negativeMcp ? { ...rawData, mcpServer: null, mcpTool: null } : rawData;
1393
1625
  return {
1394
1626
  type: input2.toolCall.status === "completed" || input2.toolCall.status === "failed" ? "item.completed" : "item.updated",
1395
1627
  ...input2.stamp,
@@ -1444,29 +1676,45 @@ function makeAcpContentDeltaEvent(input2) {
1444
1676
  }
1445
1677
  };
1446
1678
  }
1679
+ function toolCallTrackingKey(sessionId, toolCallId) {
1680
+ return sessionId === void 0 ? toolCallId : `${sessionId}\0${toolCallId}`;
1681
+ }
1447
1682
  function retainToolCallUpdate(toolCalls, next, seen) {
1448
- const tracked = toolCalls.get(next.toolCallId);
1449
- const previous = tracked?.state;
1683
+ const key = toolCallTrackingKey(seen.sessionId, next.toolCallId);
1684
+ const tracked = toolCalls.get(key);
1685
+ const identityChanged = tracked !== void 0 && toolCallIdentityChanged(
1686
+ {
1687
+ name: tracked.state.data["name"],
1688
+ kind: tracked.state.kind,
1689
+ mcpServer: tracked.state.data["mcpServer"],
1690
+ mcpTool: tracked.state.data["mcpTool"]
1691
+ },
1692
+ readToolCallIdentityFields(next)
1693
+ );
1694
+ const reset = seen.isNewCall === true || identityChanged;
1695
+ const effectiveTracked = reset ? void 0 : tracked;
1696
+ const previous = effectiveTracked?.state;
1450
1697
  const nextToolCall = mergeToolCallState(previous, next);
1451
1698
  const decision = decideToolCallUpdateEmission({
1452
1699
  previous,
1453
1700
  next: nextToolCall,
1454
- lastEmittedDetailLength: tracked?.lastEmittedDetailLength,
1455
- skippedSinceEmit: tracked?.skippedSinceEmit ?? 0
1701
+ lastEmittedDetailLength: effectiveTracked?.lastEmittedDetailLength,
1702
+ skippedSinceEmit: effectiveTracked?.skippedSinceEmit ?? 0
1456
1703
  });
1457
1704
  if (nextToolCall.status === "completed" || nextToolCall.status === "failed") {
1458
- toolCalls.delete(nextToolCall.toolCallId);
1705
+ toolCalls.delete(key);
1459
1706
  } else {
1460
- toolCalls.set(nextToolCall.toolCallId, {
1707
+ toolCalls.set(key, {
1461
1708
  state: nextToolCall,
1462
- lastEmittedDetailLength: decision.emit ? nextToolCall.detail?.length : tracked?.lastEmittedDetailLength,
1709
+ lastEmittedDetailLength: decision.emit ? nextToolCall.detail?.length : effectiveTracked?.lastEmittedDetailLength,
1463
1710
  skippedSinceEmit: decision.skippedSinceEmit,
1464
- turnId: tracked === void 0 ? seen.turnId : tracked.turnId,
1465
- startedAtMs: tracked?.startedAtMs ?? (nextToolCall.status === "inProgress" ? seen.nowMs() : void 0),
1466
- rawTitle: typeof seen.rawTitle === "string" ? seen.rawTitle : tracked?.rawTitle
1711
+ sessionId: seen.sessionId ?? effectiveTracked?.sessionId,
1712
+ turnId: effectiveTracked === void 0 ? seen.turnId : effectiveTracked.turnId,
1713
+ startedAtMs: effectiveTracked?.startedAtMs ?? (nextToolCall.status === "inProgress" ? seen.nowMs() : void 0),
1714
+ 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
1467
1715
  });
1468
1716
  }
1469
- return { nextToolCall, decision };
1717
+ return { nextToolCall, decision, reset };
1470
1718
  }
1471
1719
 
1472
1720
  // ../../packages/ycodium-acp-executor/src/executor/child-sessions.ts
@@ -25753,8 +26001,15 @@ function parseAcpResumeCursor(raw, schemaVersion) {
25753
26001
  function acpPromptSettlementBelongsToContext(input2) {
25754
26002
  return input2.liveAcpSessionId === input2.expectedAcpSessionId && (input2.liveActiveTurnId === input2.turnId || input2.liveSessionActiveTurnId === input2.turnId);
25755
26003
  }
26004
+ function isAcpPermissionOption(value) {
26005
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
26006
+ return false;
26007
+ }
26008
+ const option = value;
26009
+ return typeof option["optionId"] === "string" && typeof option["name"] === "string" && typeof option["kind"] === "string";
26010
+ }
25756
26011
  function isAcpRequestPermissionParams(value) {
25757
- if (typeof value !== "object" || value === null) {
26012
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
25758
26013
  return false;
25759
26014
  }
25760
26015
  const record3 = value;
@@ -25762,13 +26017,13 @@ function isAcpRequestPermissionParams(value) {
25762
26017
  return false;
25763
26018
  }
25764
26019
  const toolCall = record3["toolCall"];
25765
- if (typeof toolCall !== "object" || toolCall === null) {
26020
+ if (typeof toolCall !== "object" || toolCall === null || Array.isArray(toolCall)) {
25766
26021
  return false;
25767
26022
  }
25768
26023
  if (typeof toolCall["toolCallId"] !== "string") {
25769
26024
  return false;
25770
26025
  }
25771
- return Array.isArray(record3["options"]);
26026
+ return Array.isArray(record3["options"]) && record3["options"].every(isAcpPermissionOption);
25772
26027
  }
25773
26028
 
25774
26029
  // ../../packages/ycodium-acp-executor/src/apply-effort.ts
@@ -26694,15 +26949,123 @@ function createExecutorRequests({
26694
26949
  })
26695
26950
  );
26696
26951
  };
26952
+ const permissionMutationsByKey = /* @__PURE__ */ new Map();
26953
+ const trackingKeyByRequestId = /* @__PURE__ */ new Map();
26954
+ let nextSettlementSeq = 0;
26955
+ const readCommittedBaseline = (trackingKey) => {
26956
+ const pendingList = permissionMutationsByKey.get(trackingKey);
26957
+ if (pendingList !== void 0 && pendingList.length > 0) {
26958
+ return pendingList[0].previousTracked;
26959
+ }
26960
+ return toolCalls.get(trackingKey);
26961
+ };
26962
+ const recordPermissionMutation = (entry) => {
26963
+ const list = permissionMutationsByKey.get(entry.trackingKey);
26964
+ if (list !== void 0) list.push(entry);
26965
+ else permissionMutationsByKey.set(entry.trackingKey, [entry]);
26966
+ trackingKeyByRequestId.set(entry.requestId, entry.trackingKey);
26967
+ };
26968
+ const supersedePermissionTrackedState = (trackingKey, supersedeOptions) => {
26969
+ const list = permissionMutationsByKey.get(trackingKey);
26970
+ if (list === void 0) return;
26971
+ if (supersedeOptions?.restoreCommitted && list.length > 0) {
26972
+ restoreTrackedState(trackingKey, list[0].hadPrevious, list[0].previousTracked);
26973
+ }
26974
+ for (const item of list) trackingKeyByRequestId.delete(item.requestId);
26975
+ permissionMutationsByKey.delete(trackingKey);
26976
+ };
26977
+ const restoreTrackedState = (trackingKey, hadPrevious, previousTracked) => {
26978
+ if (hadPrevious && previousTracked !== void 0) {
26979
+ toolCalls.set(trackingKey, previousTracked);
26980
+ } else {
26981
+ toolCalls.delete(trackingKey);
26982
+ }
26983
+ };
26984
+ const runWithCommittedPermissionBaseline = (trackingKey, applyUpdate, passiveNextState, rawTitle) => {
26985
+ const list = permissionMutationsByKey.get(trackingKey);
26986
+ if (list === void 0 || list.length === 0) {
26987
+ return applyUpdate();
26988
+ }
26989
+ const baseEntry = list[0];
26990
+ restoreTrackedState(trackingKey, baseEntry.hadPrevious, baseEntry.previousTracked);
26991
+ const result = applyUpdate();
26992
+ if (result.reset) {
26993
+ for (const item of list) trackingKeyByRequestId.delete(item.requestId);
26994
+ permissionMutationsByKey.delete(trackingKey);
26995
+ return result;
26996
+ }
26997
+ baseEntry.hadPrevious = toolCalls.has(trackingKey);
26998
+ baseEntry.previousTracked = toolCalls.get(trackingKey);
26999
+ for (const item of list) {
27000
+ if (!item.hadApplied || item.appliedTracked === void 0) continue;
27001
+ const mergedApplied = mergeToolCallState(item.appliedTracked.state, passiveNextState);
27002
+ item.appliedTracked = {
27003
+ ...item.appliedTracked,
27004
+ state: mergedApplied,
27005
+ ...typeof rawTitle === "string" ? { rawTitle } : {}
27006
+ };
27007
+ }
27008
+ const tail = list[list.length - 1];
27009
+ restoreTrackedState(trackingKey, tail.hadApplied, tail.appliedTracked);
27010
+ return result;
27011
+ };
27012
+ const releasePermissionTrackedState = (requestId, accepted) => {
27013
+ const trackingKey = trackingKeyByRequestId.get(requestId);
27014
+ trackingKeyByRequestId.delete(requestId);
27015
+ if (trackingKey === void 0) return;
27016
+ const list = permissionMutationsByKey.get(trackingKey);
27017
+ if (list === void 0) return;
27018
+ const idx = list.findIndex((item) => item.requestId === requestId);
27019
+ if (idx < 0) return;
27020
+ if (!accepted || !list[idx].hasOwnMutation) {
27021
+ const [removed] = list.splice(idx, 1);
27022
+ if (removed === void 0) return;
27023
+ if (idx < list.length) {
27024
+ list[idx].hadPrevious = removed.hadPrevious;
27025
+ list[idx].previousTracked = removed.previousTracked;
27026
+ return;
27027
+ }
27028
+ if (list.length === 0) {
27029
+ permissionMutationsByKey.delete(trackingKey);
27030
+ }
27031
+ restoreTrackedState(trackingKey, removed.hadPrevious, removed.previousTracked);
27032
+ return;
27033
+ }
27034
+ const acceptedEntry = list[idx];
27035
+ const committed = list.splice(0, idx + 1);
27036
+ for (const item of committed) trackingKeyByRequestId.delete(item.requestId);
27037
+ if (list.length === 0) {
27038
+ permissionMutationsByKey.delete(trackingKey);
27039
+ restoreTrackedState(trackingKey, acceptedEntry.hadApplied, acceptedEntry.appliedTracked);
27040
+ } else {
27041
+ list[0].hadPrevious = acceptedEntry.hadApplied;
27042
+ list[0].previousTracked = acceptedEntry.appliedTracked;
27043
+ }
27044
+ };
26697
27045
  const settleApproval = (pending, outcome, decision, reason) => {
26698
27046
  if (!approvals.settle(pending, outcome)) {
26699
27047
  return false;
26700
27048
  }
27049
+ const accepted = outcome.outcome === "selected" && (decision === "accept" || decision === "acceptForSession" || decision === "acceptAlways");
27050
+ releasePermissionTrackedState(pending.requestId, accepted);
27051
+ hooks.onPermissionRequestSettled?.({
27052
+ sessionId: pending.request.sessionId,
27053
+ toolCallId: pending.request.toolCall.toolCallId,
27054
+ accepted,
27055
+ ...pending.settlementId === void 0 ? {} : { requestId: pending.settlementId }
27056
+ });
26701
27057
  emitResolved(pending, decision, reason);
26702
27058
  return true;
26703
27059
  };
26704
27060
  const settleAllApprovals = (decision) => {
26705
27061
  for (const entry of approvals.settleAll({ outcome: "cancelled" })) {
27062
+ releasePermissionTrackedState(entry.requestId, false);
27063
+ hooks.onPermissionRequestSettled?.({
27064
+ sessionId: entry.request.sessionId,
27065
+ toolCallId: entry.request.toolCall.toolCallId,
27066
+ accepted: false,
27067
+ ...entry.settlementId === void 0 ? {} : { requestId: entry.settlementId }
27068
+ });
26706
27069
  emitResolved(entry, decision);
26707
27070
  }
26708
27071
  };
@@ -26780,62 +27143,189 @@ function createExecutorRequests({
26780
27143
  outcome: optionId !== void 0 ? { outcome: "selected", optionId } : { outcome: "cancelled" }
26781
27144
  };
26782
27145
  };
26783
- const handlePermissionRequest = async (params) => {
26784
- if (!isAcpRequestPermissionParams(params)) {
27146
+ const handlePermissionRequest = async (rawParams) => {
27147
+ if (!isAcpRequestPermissionParams(rawParams)) {
26785
27148
  throw RequestError.invalidParams({ detail: "Malformed session/request_permission" });
26786
27149
  }
26787
- const userInputOutcome = await handlePermissionAsUserInput(params);
27150
+ const userInputOutcome = await handlePermissionAsUserInput(rawParams);
26788
27151
  if (userInputOutcome !== void 0) return userInputOutcome;
26789
- const tracked = toolCalls.get(params.toolCall.toolCallId);
26790
- const parsed = parsePermissionRequest(params, tracked);
26791
- const overriddenKind = hooks.permissionRequestKind?.({
26792
- title: params.toolCall.title ?? tracked?.rawTitle,
26793
- kind: parsed.kind,
26794
- rawInput: parsed.toolCall?.data["rawInput"]
26795
- });
26796
- const permissionRequest = overriddenKind === void 0 ? parsed : { ...parsed, kind: overriddenKind };
26797
- if (options.autoApprove?.(permissionRequest) === true) {
26798
- const optionId = selectAutoApprovedAcpPermissionOption(params);
26799
- if (optionId !== void 0) {
26800
- return { outcome: { outcome: "selected", optionId } };
26801
- }
27152
+ failIfDisposed();
27153
+ const settlementId = `perm-${++nextSettlementSeq}`;
27154
+ const transformed = hooks.transformPermissionRequest ? hooks.transformPermissionRequest(rawParams, { requestId: settlementId }) : rawParams;
27155
+ if (!isAcpRequestPermissionParams(transformed)) {
27156
+ hooks.onPermissionRequestSettled?.({
27157
+ sessionId: rawParams.sessionId,
27158
+ toolCallId: rawParams.toolCall.toolCallId,
27159
+ accepted: false,
27160
+ requestId: settlementId
27161
+ });
27162
+ throw RequestError.invalidParams({ detail: "Malformed session/request_permission" });
26802
27163
  }
26803
- const permissionContext = {
26804
- request: params,
26805
- permissionRequest,
26806
- previousToolCall: tracked?.state
26807
- };
26808
- const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest);
26809
- const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest);
26810
- const requestId = randomId();
26811
- const outcome = await new Promise((resolve3) => {
26812
- const pending = {
26813
- requestId,
26814
- request: params,
26815
- permissionRequest,
26816
- turnId: shared.activeTurnId,
26817
- settled: false,
26818
- resolve: resolve3
26819
- };
26820
- approvals.add(pending);
26821
- emit(
26822
- makeAcpRequestOpenedEvent({
27164
+ const params = transformed;
27165
+ const trackingKey = toolCallTrackingKey(params.sessionId, params.toolCall.toolCallId);
27166
+ const immediateHadPrevious = toolCalls.has(trackingKey);
27167
+ const immediatePrevious = toolCalls.get(trackingKey);
27168
+ let mutatedToolCall = false;
27169
+ const hasTextField = (record3, key) => typeof record3[key] === "string" && record3[key].trim().length > 0;
27170
+ const rawToolCallRecord = rawParams.toolCall;
27171
+ const rawReqMeta = rawToolCallRecord["_meta"];
27172
+ const rawParentMeta = rawParams["_meta"];
27173
+ const transformedToolCallRecord = params.toolCall;
27174
+ const transformedReqMeta = transformedToolCallRecord["_meta"];
27175
+ const transformedParentMeta = params["_meta"];
27176
+ const hasExplicitNegativeMeta = isRecord2(rawReqMeta) && rawReqMeta["is_mcp_tool_call"] === false || isRecord2(rawParentMeta) && rawParentMeta["is_mcp_tool_call"] === false || isRecord2(transformedReqMeta) && transformedReqMeta["is_mcp_tool_call"] === false || isRecord2(transformedParentMeta) && transformedParentMeta["is_mcp_tool_call"] === false;
27177
+ let hasOwnMutation = false;
27178
+ const prepared = (() => {
27179
+ try {
27180
+ const existingPendingList = permissionMutationsByKey.get(trackingKey);
27181
+ const hasPendingSibling = existingPendingList !== void 0 && existingPendingList.length > 0;
27182
+ const tracked = readCommittedBaseline(trackingKey);
27183
+ const requestFields = params.toolCall;
27184
+ const identityChanged = tracked !== void 0 && toolCallIdentityChanged(
27185
+ {
27186
+ name: tracked.state.data["name"],
27187
+ kind: tracked.state.kind,
27188
+ mcpServer: tracked.state.data["mcpServer"],
27189
+ mcpTool: tracked.state.data["mcpTool"]
27190
+ },
27191
+ {
27192
+ name: requestFields.name,
27193
+ kind: params.toolCall.kind,
27194
+ mcpServer: requestFields.mcpServer,
27195
+ mcpTool: requestFields.mcpTool
27196
+ }
27197
+ );
27198
+ const effectiveTracked = identityChanged ? void 0 : tracked;
27199
+ const parsed = parsePermissionRequest(params, effectiveTracked);
27200
+ const trackedNegativeMcp = tracked !== void 0 && readToolCallIdentityFields(tracked.state).negativeMcp;
27201
+ const parsedNegativeMcp = parsed.toolCall !== void 0 && readToolCallIdentityFields(parsed.toolCall).negativeMcp;
27202
+ 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"];
27203
+ 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;
27204
+ 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;
27205
+ if (hasOwnMutation || !hasPendingSibling) {
27206
+ if (parsed.toolCall === void 0) {
27207
+ if (identityChanged && toolCalls.delete(trackingKey)) {
27208
+ mutatedToolCall = true;
27209
+ }
27210
+ } else {
27211
+ if (parsed.toolCall.status === "completed" || parsed.toolCall.status === "failed") {
27212
+ if (toolCalls.delete(trackingKey)) {
27213
+ mutatedToolCall = true;
27214
+ }
27215
+ } else {
27216
+ mutatedToolCall = true;
27217
+ toolCalls.set(trackingKey, {
27218
+ state: parsed.toolCall,
27219
+ lastEmittedDetailLength: effectiveTracked?.lastEmittedDetailLength,
27220
+ skippedSinceEmit: effectiveTracked?.skippedSinceEmit ?? 0,
27221
+ sessionId: params.sessionId,
27222
+ turnId: effectiveTracked?.turnId ?? shared.activeTurnId,
27223
+ startedAtMs: effectiveTracked?.startedAtMs,
27224
+ rawTitle: retainedRawTitle
27225
+ });
27226
+ }
27227
+ }
27228
+ }
27229
+ const overriddenKind = hooks.permissionRequestKind?.({
27230
+ title: retainedRawTitle,
27231
+ kind: parsed.kind,
27232
+ rawInput: parsed.toolCall?.data["rawInput"]
27233
+ });
27234
+ const permissionRequest2 = overriddenKind === void 0 ? parsed : { ...parsed, kind: overriddenKind };
27235
+ if (options.autoApprove?.(permissionRequest2) === true) {
27236
+ const optionId = selectAutoApprovedAcpPermissionOption(params);
27237
+ if (optionId !== void 0) {
27238
+ if (hasOwnMutation) {
27239
+ supersedePermissionTrackedState(trackingKey);
27240
+ }
27241
+ hooks.onPermissionRequestSettled?.({
27242
+ sessionId: params.sessionId,
27243
+ toolCallId: params.toolCall.toolCallId,
27244
+ accepted: true,
27245
+ requestId: settlementId
27246
+ });
27247
+ return { autoApprovedOptionId: optionId };
27248
+ }
27249
+ }
27250
+ const permissionContext = {
27251
+ request: params,
27252
+ permissionRequest: permissionRequest2,
27253
+ previousToolCall: effectiveTracked?.state
27254
+ };
27255
+ const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest2);
27256
+ const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest2);
27257
+ const requestId2 = randomId();
27258
+ const openedEvent2 = makeAcpRequestOpenedEvent({
26823
27259
  stamp: stamp(),
26824
27260
  provider: options.provider,
26825
27261
  threadId: options.threadId,
26826
27262
  turnId: shared.activeTurnId,
26827
- requestId,
26828
- permissionRequest,
26829
- detail: statement.command ?? permissionRequest.detail,
26830
- args: permissionRequest.toolCall?.data["rawInput"] ?? params.toolCall.rawInput,
27263
+ requestId: requestId2,
27264
+ permissionRequest: permissionRequest2,
27265
+ detail: statement.command ?? permissionRequest2.detail,
27266
+ args: permissionRequest2.toolCall?.data["rawInput"] ?? params.toolCall.rawInput,
26831
27267
  statement,
26832
27268
  options: acpApprovalOptions(params),
26833
27269
  fileChanges,
26834
27270
  source: "acp.jsonrpc",
26835
27271
  method: "session/request_permission",
26836
27272
  rawPayload: params
26837
- })
26838
- );
27273
+ });
27274
+ return { requestId: requestId2, permissionRequest: permissionRequest2, openedEvent: openedEvent2 };
27275
+ } catch (error62) {
27276
+ if (mutatedToolCall) {
27277
+ restoreTrackedState(trackingKey, immediateHadPrevious, immediatePrevious);
27278
+ }
27279
+ hooks.onPermissionRequestSettled?.({
27280
+ sessionId: params.sessionId,
27281
+ toolCallId: params.toolCall.toolCallId,
27282
+ accepted: false,
27283
+ requestId: settlementId
27284
+ });
27285
+ throw error62;
27286
+ }
27287
+ })();
27288
+ if ("autoApprovedOptionId" in prepared) {
27289
+ return { outcome: { outcome: "selected", optionId: prepared.autoApprovedOptionId } };
27290
+ }
27291
+ const hadApplied = toolCalls.has(trackingKey);
27292
+ const appliedTracked = toolCalls.get(trackingKey);
27293
+ const { requestId, permissionRequest, openedEvent } = prepared;
27294
+ const outcome = await new Promise((resolve3, reject) => {
27295
+ const pending = {
27296
+ requestId,
27297
+ settlementId,
27298
+ request: params,
27299
+ permissionRequest,
27300
+ turnId: shared.activeTurnId,
27301
+ settled: false,
27302
+ resolve: resolve3
27303
+ };
27304
+ if (mutatedToolCall) {
27305
+ recordPermissionMutation({
27306
+ requestId,
27307
+ trackingKey,
27308
+ hasOwnMutation,
27309
+ hadPrevious: immediateHadPrevious,
27310
+ previousTracked: immediatePrevious,
27311
+ hadApplied,
27312
+ appliedTracked
27313
+ });
27314
+ }
27315
+ approvals.add(pending);
27316
+ try {
27317
+ emit(openedEvent);
27318
+ } catch (error62) {
27319
+ reject(error62);
27320
+ approvals.settle(pending, { outcome: "cancelled" });
27321
+ releasePermissionTrackedState(requestId, false);
27322
+ hooks.onPermissionRequestSettled?.({
27323
+ sessionId: params.sessionId,
27324
+ toolCallId: params.toolCall.toolCallId,
27325
+ accepted: false,
27326
+ requestId: settlementId
27327
+ });
27328
+ }
26839
27329
  });
26840
27330
  return { outcome };
26841
27331
  };
@@ -26893,7 +27383,9 @@ function createExecutorRequests({
26893
27383
  makeExtensionContext,
26894
27384
  handlePermissionRequest,
26895
27385
  respondToRequest,
26896
- respondToUserInput
27386
+ respondToUserInput,
27387
+ supersedePermissionTrackedState,
27388
+ runWithCommittedPermissionBaseline
26897
27389
  };
26898
27390
  }
26899
27391
 
@@ -27813,7 +28305,9 @@ function createExecutorUpdates({
27813
28305
  emitArtifacts,
27814
28306
  closeActiveAssistantSegment,
27815
28307
  ensureActiveAssistantSegment,
27816
- shared
28308
+ shared,
28309
+ supersedePermissionTrackedState,
28310
+ runWithCommittedPermissionBaseline
27817
28311
  }) {
27818
28312
  const shownToolCallIds = /* @__PURE__ */ new Set();
27819
28313
  const markChildSession = shared.childSessions.mark;
@@ -27954,7 +28448,7 @@ function createExecutorUpdates({
27954
28448
  sessionId: shared.sessionId,
27955
28449
  markChildSession
27956
28450
  });
27957
- const handleSessionUpdate = (params) => {
28451
+ const handleSessionUpdate = (params, rawWireUpdate) => {
27958
28452
  const update = params.update;
27959
28453
  const reportedOptions = update["configOptions"];
27960
28454
  if (update["sessionUpdate"] === "config_option_update" && Array.isArray(reportedOptions)) {
@@ -27990,11 +28484,45 @@ function createExecutorUpdates({
27990
28484
  }
27991
28485
  for (const event2 of parsed.events) {
27992
28486
  if (event2._tag === "ToolCallUpdated") {
27993
- const { nextToolCall, decision } = retainToolCallUpdate(toolCalls, event2.toolCall, {
28487
+ const isNewCall = params.update.sessionUpdate === "tool_call";
28488
+ const shownKey = toolCallTrackingKey(params.sessionId, event2.toolCall.toolCallId);
28489
+ const wireRecord = isRecord2(rawWireUpdate) ? rawWireUpdate : void 0;
28490
+ const wireMeta = wireRecord !== void 0 && isRecord2(wireRecord["_meta"]) ? wireRecord["_meta"] : void 0;
28491
+ const wireParentMeta = isRecord2(params._meta) ? params._meta : void 0;
28492
+ 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);
28493
+ const rawTitle = params.update.title;
28494
+ const supersedesPendingPermission = isNewCall || event2.toolCall.status === "completed" || event2.toolCall.status === "failed" || hasWireIdentity;
28495
+ if (supersedesPendingPermission) {
28496
+ supersedePermissionTrackedState?.(shownKey, { restoreCommitted: true });
28497
+ }
28498
+ const runRetain = () => retainToolCallUpdate(toolCalls, event2.toolCall, {
28499
+ sessionId: params.sessionId,
27994
28500
  turnId: shared.activeTurnId,
27995
- rawTitle: params.update.title,
28501
+ rawTitle,
28502
+ isNewCall,
27996
28503
  nowMs
27997
28504
  });
28505
+ const updateRecord = params.update;
28506
+ const passiveRawTitle = wireRecord !== void 0 ? wireRecord["title"] : updateRecord["title"];
28507
+ const passiveWireState = !supersedesPendingPermission && runWithCommittedPermissionBaseline !== void 0 ? makeToolCallState({
28508
+ toolCallId: event2.toolCall.toolCallId,
28509
+ title: typeof passiveRawTitle === "string" ? passiveRawTitle : void 0,
28510
+ status: updateRecord["status"],
28511
+ rawInput: updateRecord["rawInput"],
28512
+ rawOutput: updateRecord["rawOutput"],
28513
+ content: updateRecord["content"],
28514
+ locations: updateRecord["locations"]
28515
+ }) : void 0;
28516
+ const { nextToolCall, decision, reset } = !supersedesPendingPermission && runWithCommittedPermissionBaseline !== void 0 ? runWithCommittedPermissionBaseline(
28517
+ shownKey,
28518
+ runRetain,
28519
+ passiveWireState ?? event2.toolCall,
28520
+ rawTitle
28521
+ ) : runRetain();
28522
+ if (reset) {
28523
+ supersedePermissionTrackedState?.(shownKey);
28524
+ shownToolCallIds.delete(shownKey);
28525
+ }
27998
28526
  const hasToolHooks = toolSubagents !== void 0 || hooks.onToolCallUpdated !== void 0;
27999
28527
  const toolName = typeof nextToolCall.data["name"] === "string" ? nextToolCall.data["name"] : void 0;
28000
28528
  const call = !hasToolHooks ? void 0 : {
@@ -28020,8 +28548,8 @@ function createExecutorUpdates({
28020
28548
  continue;
28021
28549
  }
28022
28550
  const toolTurnId = (hookResult !== void 0 && "events" in hookResult ? hookResult.turnId : void 0) ?? shared.activeTurnId;
28023
- if (!shownToolCallIds.has(nextToolCall.toolCallId)) {
28024
- rememberShownToolCall(nextToolCall.toolCallId);
28551
+ if (isNewCall || !shownToolCallIds.has(shownKey)) {
28552
+ rememberShownToolCall(shownKey);
28025
28553
  if (toolTurnId === shared.activeTurnId) closeActiveAssistantSegment(shared.activeTurnId);
28026
28554
  }
28027
28555
  emit(
@@ -28117,7 +28645,7 @@ function createExecutorUpdates({
28117
28645
  }
28118
28646
  }
28119
28647
  };
28120
- const receiveSessionUpdate = (params) => {
28648
+ const receiveSessionUpdate = (params, rawWireUpdate) => {
28121
28649
  const foreign = !shared.ownSessionIds.has(params.sessionId) && (shared.childSessions.has(params.sessionId) || shared.sessionOpensInFlight === 0 && shared.ownSessionIds.size > 0);
28122
28650
  emitHookEvents(
28123
28651
  subagentSessions?.observe(params, {
@@ -28132,7 +28660,7 @@ function createExecutorUpdates({
28132
28660
  emitHookEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
28133
28661
  }
28134
28662
  }
28135
- if (!foreign) handleSessionUpdate(params);
28663
+ if (!foreign) handleSessionUpdate(params, rawWireUpdate);
28136
28664
  };
28137
28665
  const receiveExtensionNotification = (method, params) => {
28138
28666
  if (shared.sessionLoadInFlight || !hooks.onExtensionNotification) return;
@@ -28331,6 +28859,27 @@ function createAcpExecutor(options) {
28331
28859
  promptMutex,
28332
28860
  shared
28333
28861
  });
28862
+ const {
28863
+ settleAllApprovals,
28864
+ settleAllUserInputs,
28865
+ makeExtensionContext,
28866
+ handlePermissionRequest,
28867
+ respondToRequest,
28868
+ respondToUserInput,
28869
+ supersedePermissionTrackedState,
28870
+ runWithCommittedPermissionBaseline
28871
+ } = createExecutorRequests({
28872
+ emit,
28873
+ stamp,
28874
+ options,
28875
+ approvals,
28876
+ pendingUserInputs,
28877
+ failIfDisposed,
28878
+ randomId,
28879
+ hooks,
28880
+ shared,
28881
+ toolCalls
28882
+ });
28334
28883
  const {
28335
28884
  emitCompactionState,
28336
28885
  receiveSessionUpdate,
@@ -28350,26 +28899,9 @@ function createAcpExecutor(options) {
28350
28899
  emitArtifacts,
28351
28900
  closeActiveAssistantSegment,
28352
28901
  ensureActiveAssistantSegment,
28353
- shared
28354
- });
28355
- const {
28356
- settleAllApprovals,
28357
- settleAllUserInputs,
28358
- makeExtensionContext,
28359
- handlePermissionRequest,
28360
- respondToRequest,
28361
- respondToUserInput
28362
- } = createExecutorRequests({
28363
- emit,
28364
- stamp,
28365
- options,
28366
- approvals,
28367
- pendingUserInputs,
28368
- failIfDisposed,
28369
- randomId,
28370
- hooks,
28371
28902
  shared,
28372
- toolCalls
28903
+ supersedePermissionTrackedState,
28904
+ runWithCommittedPermissionBaseline
28373
28905
  });
28374
28906
  const { rememberSettledPromptKey, abortPendingSettlement, settleFromNotification } = createExecutorSettlement({ hooks, shared });
28375
28907
  const promptResults = createPromptResults({ options, shared });
@@ -28400,8 +28932,9 @@ function createAcpExecutor(options) {
28400
28932
  onNotification: (notification) => {
28401
28933
  if (notification.method === "session/update") {
28402
28934
  const params = notification.params;
28935
+ const rawUpdate = params.update;
28403
28936
  const transformed = hooks.transformSessionUpdate ? hooks.transformSessionUpdate(params) : params;
28404
- if (transformed !== void 0) receiveSessionUpdate(transformed);
28937
+ if (transformed !== void 0) receiveSessionUpdate(transformed, rawUpdate);
28405
28938
  return;
28406
28939
  }
28407
28940
  if (settleFromNotification(notification.method, notification.params)) return;
@@ -30026,9 +30559,11 @@ var KIMI_NATIVE_MODE_REPORT = {
30026
30559
  };
30027
30560
 
30028
30561
  // src/runtimeModeApproval.ts
30029
- function acpRuntimeModeAutoApproves(runtimeMode, toolKind, toolName, nativeMode = false) {
30562
+ function acpRuntimeModeAutoApproves(runtimeMode, toolKind, toolName, nativeMode = false, negativeMcp = false) {
30030
30563
  if (nativeMode) return false;
30031
- if (runtimeMode === "auto" && toolKind === "other" && toolName?.startsWith("mcp__")) return true;
30564
+ if (runtimeMode === "auto" && !negativeMcp && toolKind === "other" && toolName?.startsWith("mcp__")) {
30565
+ return true;
30566
+ }
30032
30567
  switch (runtimeMode) {
30033
30568
  case "full-access":
30034
30569
  return true;
@@ -30630,11 +31165,13 @@ var createKimiInstance = (config2, host, profileDataDir2) => {
30630
31165
  const hooks = kimiHooks(recipe);
30631
31166
  const autoApprove = (request) => {
30632
31167
  const session = threads.get(input2.threadId)?.session ?? input2;
31168
+ const negativeMcp = request.toolCall !== void 0 && readToolCallIdentityFields(request.toolCall).negativeMcp;
30633
31169
  return acpRuntimeModeAutoApproves(
30634
31170
  session.runtimeMode,
30635
31171
  request.kind,
30636
31172
  request.toolCall?.title,
30637
- session.nativeModeId !== void 0
31173
+ session.nativeModeId !== void 0,
31174
+ negativeMcp
30638
31175
  );
30639
31176
  };
30640
31177
  const executor = createAcpExecutor({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-kimi",
3
- "version": "0.2.5891",
3
+ "version": "0.2.5921",
4
4
  "description": "Kimi Code executor: runs `kimi acp` 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-acp-executor": "0.2.0",
25
- "@ycodium-ai/plugin-api": "0.2.5891",
24
+ "@ycodium-ai/plugin-api": "0.2.5921",
26
25
  "ycodium-executor-testing": "0.0.0",
26
+ "ycodium-acp-executor": "0.2.5921",
27
27
  "ycodium-instance-config": "0.0.0"
28
28
  },
29
29
  "ycodium": {