@ycodium-ai/agent-kimi 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.
Files changed (2) hide show
  1. package/dist/index.js +675 -129
  2. package/package.json +5 -5
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 = 186;
11
+ var PLUGIN_API_VERSION = 189;
12
12
 
13
13
  // src/index.ts
14
14
  import * as NodeOS6 from "node:os";
@@ -715,6 +715,18 @@ 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
+ var fallbackTitleStates = /* @__PURE__ */ new WeakSet();
720
+ function readToolCallIdentityFields(state, options) {
721
+ const cleared = clearedIdentityFields.get(state);
722
+ return {
723
+ name: cleared?.name === null ? null : state.data["name"],
724
+ kind: options?.kindFromData ? state.data["kind"] : state.kind,
725
+ mcpServer: cleared?.mcpServer === null ? null : state.data["mcpServer"],
726
+ mcpTool: cleared?.mcpTool === null ? null : state.data["mcpTool"],
727
+ negativeMcp: cleared?.negativeMcp === true
728
+ };
729
+ }
718
730
  function normalizeToolCallStatus(raw, fallback) {
719
731
  switch (raw) {
720
732
  case "pending":
@@ -847,6 +859,13 @@ function makeToolCallState(input2, options) {
847
859
  if (!toolCallId) {
848
860
  return void 0;
849
861
  }
862
+ const explicitNullMcp = input2.mcpServer === null || input2.mcpTool === null;
863
+ const reqMetaFlag = isRecord2(input2._meta) && typeof input2._meta["is_mcp_tool_call"] === "boolean" ? input2._meta["is_mcp_tool_call"] : void 0;
864
+ const parentMetaFlag = isRecord2(input2.parentMeta) && typeof input2.parentMeta["is_mcp_tool_call"] === "boolean" ? input2.parentMeta["is_mcp_tool_call"] : void 0;
865
+ const metaFlag = reqMetaFlag === false || parentMetaFlag === false ? false : reqMetaFlag === true || parentMetaFlag === true ? true : void 0;
866
+ const explicitPositiveMcp = !explicitNullMcp && metaFlag !== false && (metaFlag === true || readAcpText(input2, "mcpServer") !== void 0 && readAcpText(input2, "mcpTool") !== void 0);
867
+ const explicitNegativeMcp = explicitNullMcp || metaFlag === false;
868
+ const negativeMcp = explicitNegativeMcp || !explicitPositiveMcp && options?.inheritedNegativeMcp === true;
850
869
  const title = typeof input2.title === "string" ? input2.title.trim() || void 0 : void 0;
851
870
  const command = extractToolCallCommand(input2.rawInput, title);
852
871
  const extractedContent = extractTextContentFromToolCallContent(input2.content);
@@ -860,6 +879,12 @@ function makeToolCallState(input2, options) {
860
879
  const name = readAcpText(input2, "name");
861
880
  if (name) {
862
881
  data["name"] = name;
882
+ const mcpServer = readAcpText(input2, "mcpServer");
883
+ const mcpTool = readAcpText(input2, "mcpTool");
884
+ if (!negativeMcp && mcpServer !== void 0 && mcpTool !== void 0) {
885
+ data["mcpServer"] = mcpServer;
886
+ data["mcpTool"] = mcpTool;
887
+ }
863
888
  }
864
889
  if (command) {
865
890
  data["command"] = command;
@@ -886,7 +911,7 @@ function makeToolCallState(input2, options) {
886
911
  fallbackSummary: title ?? "Tool"
887
912
  }) : void 0;
888
913
  const status = normalizeToolCallStatus(input2.status, options?.fallbackStatus);
889
- return {
914
+ const state = {
890
915
  toolCallId,
891
916
  ...kind ? { kind } : {},
892
917
  ...presentation?.summary ? { title: presentation.summary } : {},
@@ -896,16 +921,74 @@ function makeToolCallState(input2, options) {
896
921
  ...textContent ? { contentText: textContent } : {},
897
922
  data
898
923
  };
924
+ if (title === void 0 && presentation?.summary === "Tool") {
925
+ fallbackTitleStates.add(state);
926
+ }
927
+ if (input2.name === null || input2.mcpServer === null || input2.mcpTool === null || negativeMcp || explicitPositiveMcp) {
928
+ clearedIdentityFields.set(state, {
929
+ ...input2.name === null ? { name: null } : {},
930
+ ...input2.mcpServer === null ? { mcpServer: null } : {},
931
+ ...input2.mcpTool === null ? { mcpTool: null } : {},
932
+ ...negativeMcp ? { negativeMcp: true } : {},
933
+ ...explicitPositiveMcp ? { positiveMcp: true } : {}
934
+ });
935
+ }
936
+ return state;
937
+ }
938
+ function toolCallIdentityChanged(previous, next) {
939
+ const prevName = readAcpText(previous, "name");
940
+ const nextName = readAcpText(next, "name");
941
+ const prevKind = normalizeToolKind(previous.kind);
942
+ const nextKind = normalizeToolKind(next.kind);
943
+ const prevServer = readAcpText(previous, "mcpServer");
944
+ const nextServer = readAcpText(next, "mcpServer");
945
+ const prevTool = readAcpText(previous, "mcpTool");
946
+ const nextTool = readAcpText(next, "mcpTool");
947
+ const clearedName = prevName !== void 0 && next.name === null;
948
+ const clearedServer = prevServer !== void 0 && next.mcpServer === null;
949
+ const clearedTool = prevTool !== void 0 && next.mcpTool === null;
950
+ 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
951
  }
900
952
  function mergeToolCallState(previous, next) {
953
+ if (previous !== void 0 && toolCallIdentityChanged(
954
+ {
955
+ name: previous.data["name"],
956
+ kind: previous.kind,
957
+ mcpServer: previous.data["mcpServer"],
958
+ mcpTool: previous.data["mcpTool"]
959
+ },
960
+ readToolCallIdentityFields(next, { kindFromData: true })
961
+ )) {
962
+ const status2 = next.status ?? previous.status;
963
+ if (status2 === void 0 || status2 === next.status) {
964
+ return next;
965
+ }
966
+ const replaced = { ...next, status: status2 };
967
+ const nextCleared2 = clearedIdentityFields.get(next);
968
+ if (nextCleared2 !== void 0) clearedIdentityFields.set(replaced, nextCleared2);
969
+ if (fallbackTitleStates.has(next)) fallbackTitleStates.add(replaced);
970
+ return replaced;
971
+ }
901
972
  const nextKind = typeof next.data["kind"] === "string" ? next.data["kind"] : void 0;
902
973
  const kind = nextKind ?? previous?.kind;
903
- const title = next.title ?? previous?.title;
974
+ const nextIsFallbackTitle = fallbackTitleStates.has(next);
975
+ const title = nextIsFallbackTitle ? previous?.title ?? next.title : next.title ?? previous?.title;
904
976
  const status = next.status ?? previous?.status;
905
977
  const command = next.command ?? previous?.command;
906
978
  const detail = next.detail ?? previous?.detail;
907
979
  const contentText = "content" in next.data ? next.contentText : previous?.contentText;
908
- return {
980
+ const prevCleared = previous === void 0 ? void 0 : clearedIdentityFields.get(previous);
981
+ const nextCleared = clearedIdentityFields.get(next);
982
+ const nextPositiveMcp = typeof next.data["mcpServer"] === "string" && typeof next.data["mcpTool"] === "string" || nextCleared?.positiveMcp === true;
983
+ const mergedNegativeMcp = nextCleared?.negativeMcp === true || !nextPositiveMcp && prevCleared?.negativeMcp === true;
984
+ const clearPreviousMcp = previous !== void 0 && (mergedNegativeMcp || next.data["name"] !== void 0 && next.data["mcpServer"] === void 0);
985
+ const previousData = clearPreviousMcp ? Object.fromEntries(
986
+ Object.entries(previous.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool")
987
+ ) : previous?.data;
988
+ const nextData = mergedNegativeMcp ? Object.fromEntries(
989
+ Object.entries(next.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool")
990
+ ) : next.data;
991
+ const merged = {
909
992
  toolCallId: next.toolCallId,
910
993
  ...kind ? { kind } : {},
911
994
  ...title ? { title } : {},
@@ -914,10 +997,19 @@ function mergeToolCallState(previous, next) {
914
997
  ...detail ? { detail } : {},
915
998
  ...contentText ? { contentText } : {},
916
999
  data: {
917
- ...previous?.data,
918
- ...next.data
1000
+ ...previousData,
1001
+ ...nextData
919
1002
  }
920
1003
  };
1004
+ if (mergedNegativeMcp) {
1005
+ clearedIdentityFields.set(merged, { negativeMcp: true });
1006
+ } else if (nextPositiveMcp || prevCleared?.positiveMcp === true) {
1007
+ clearedIdentityFields.set(merged, { positiveMcp: true });
1008
+ }
1009
+ if (title === "Tool" && nextIsFallbackTitle && (previous === void 0 || fallbackTitleStates.has(previous))) {
1010
+ fallbackTitleStates.add(merged);
1011
+ }
1012
+ return merged;
921
1013
  }
922
1014
  var TOOL_CALL_UPDATE_MIN_DETAIL_GROWTH_CHARS = 256;
923
1015
  var TOOL_CALL_UPDATE_COALESCE_LIMIT = 10;
@@ -1072,20 +1164,47 @@ function parseAvailableCommandsUpdate(params) {
1072
1164
  }
1073
1165
  function parsePermissionRequest(params, known) {
1074
1166
  const request = params.toolCall;
1167
+ const requestFields = request;
1075
1168
  const earlier = known?.state.data;
1169
+ const identityChanged = known !== void 0 && toolCallIdentityChanged(
1170
+ {
1171
+ name: earlier?.["name"],
1172
+ kind: known.state.kind,
1173
+ mcpServer: earlier?.["mcpServer"],
1174
+ mcpTool: earlier?.["mcpTool"]
1175
+ },
1176
+ {
1177
+ name: requestFields.name,
1178
+ kind: request.kind,
1179
+ mcpServer: requestFields.mcpServer,
1180
+ mcpTool: requestFields.mcpTool
1181
+ }
1182
+ );
1183
+ const prior = identityChanged ? void 0 : known;
1184
+ const priorData = identityChanged ? void 0 : earlier;
1185
+ const priorNegativeMcp = prior !== void 0 ? readToolCallIdentityFields(prior.state).negativeMcp : false;
1186
+ const reqMeta = request._meta;
1187
+ const parentMeta = params._meta;
1188
+ const requestNegativeMcp = requestFields.mcpServer === null || requestFields.mcpTool === null || isRecord2(reqMeta) && reqMeta["is_mcp_tool_call"] === false || isRecord2(parentMeta) && parentMeta["is_mcp_tool_call"] === false;
1189
+ const allowPriorMcpFields = !priorNegativeMcp && !requestNegativeMcp && requestFields.name === void 0;
1190
+ const inheritedRawTitle = prior?.rawTitle !== void 0 && !((priorNegativeMcp || requestNegativeMcp) && /^(?:(?:Running|Run)\s+)?mcp_/u.test(prior.rawTitle.trim())) ? prior.rawTitle : void 0;
1076
1191
  const toolCall = makeToolCallState(
1077
1192
  {
1078
1193
  toolCallId: request.toolCallId,
1079
- name: earlier?.["name"],
1080
- title: request.title ?? known?.rawTitle,
1081
- kind: request.kind ?? earlier?.["kind"],
1194
+ name: requestFields.name !== void 0 ? requestFields.name : priorData?.["name"],
1195
+ mcpServer: requestFields.mcpServer !== void 0 ? requestFields.mcpServer : allowPriorMcpFields ? priorData?.["mcpServer"] : void 0,
1196
+ mcpTool: requestFields.mcpTool !== void 0 ? requestFields.mcpTool : allowPriorMcpFields ? priorData?.["mcpTool"] : void 0,
1197
+ title: request.title ?? inheritedRawTitle,
1198
+ kind: request.kind ?? priorData?.["kind"],
1082
1199
  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"]
1200
+ rawInput: request.rawInput !== void 0 ? request.rawInput : priorData?.["rawInput"],
1201
+ rawOutput: request.rawOutput !== void 0 ? request.rawOutput : priorData?.["rawOutput"],
1202
+ content: request.content !== void 0 ? request.content : priorData?.["content"],
1203
+ locations: request.locations !== void 0 ? request.locations : priorData?.["locations"],
1204
+ _meta: reqMeta,
1205
+ parentMeta
1087
1206
  },
1088
- { fallbackStatus: "pending" }
1207
+ { fallbackStatus: "pending", ...priorNegativeMcp ? { inheritedNegativeMcp: true } : {} }
1089
1208
  );
1090
1209
  const kind = toolCall?.kind ?? "unknown";
1091
1210
  const content = toolCall?.data["content"];
@@ -1095,7 +1214,7 @@ function parsePermissionRequest(params, known) {
1095
1214
  const block = entry["content"];
1096
1215
  return block["type"] === "text" && typeof block["text"] === "string" && block["text"].trim() ? [block["text"]] : [];
1097
1216
  })[0] : void 0;
1098
- const originalTitle = (request.title ?? known?.rawTitle)?.trim() || void 0;
1217
+ const originalTitle = (request.title ?? inheritedRawTitle)?.trim() || void 0;
1099
1218
  const detail = toolCall?.command ?? firstText ?? originalTitle;
1100
1219
  return {
1101
1220
  kind,
@@ -1166,13 +1285,17 @@ function parseSessionUpdateEvent(params) {
1166
1285
  {
1167
1286
  toolCallId: upd["toolCallId"],
1168
1287
  name: upd["name"],
1288
+ mcpServer: upd["mcpServer"],
1289
+ mcpTool: upd["mcpTool"],
1169
1290
  title: typeof upd["title"] === "string" ? upd["title"] : void 0,
1170
1291
  kind: upd["kind"],
1171
1292
  status: upd["status"],
1172
1293
  rawInput: upd["rawInput"],
1173
1294
  rawOutput: upd["rawOutput"],
1174
1295
  content: upd["content"],
1175
- locations: upd["locations"]
1296
+ locations: upd["locations"],
1297
+ _meta: upd["_meta"],
1298
+ parentMeta: params._meta
1176
1299
  },
1177
1300
  kind === "tool_call" ? { fallbackStatus: "pending" } : void 0
1178
1301
  );
@@ -1281,6 +1404,38 @@ function canonicalRequestTypeFromAcpKind(kind) {
1281
1404
  return "dynamic_tool_call";
1282
1405
  }
1283
1406
  }
1407
+ var MAX_ACP_FILE_CHANGES = 256;
1408
+ var MAX_ACP_FILE_CHANGE_PATH_CHARS = 4096;
1409
+ var MAX_DISPLAY_FILE_CHANGES = 20;
1410
+ var isValidAcpFilePath = (value) => typeof value === "string" && value.trim().length > 0 && value.length <= MAX_ACP_FILE_CHANGE_PATH_CHARS;
1411
+ var isTruncatedFileChangesMarker = (value) => value !== null && typeof value === "object" && value["ycodiumFileChangesTruncated"] === true;
1412
+ var clippedDiffBlocks = /* @__PURE__ */ new WeakMap();
1413
+ function readAcpDiffTooLarge(block) {
1414
+ return block !== null && typeof block === "object" ? clippedDiffBlocks.get(block) : void 0;
1415
+ }
1416
+ function acpFileChangeFromDiffBlock(block, path) {
1417
+ const oldText = typeof block["oldText"] === "string" ? block["oldText"] : void 0;
1418
+ const changeKind = oldText === void 0 ? "add" : "modify";
1419
+ const clipped = readAcpDiffTooLarge(block);
1420
+ if (clipped !== void 0) {
1421
+ return {
1422
+ path,
1423
+ changeKind,
1424
+ additions: clipped.additions,
1425
+ deletions: clipped.deletions,
1426
+ omitted: "too-large"
1427
+ };
1428
+ }
1429
+ return {
1430
+ path,
1431
+ changeKind,
1432
+ content: {
1433
+ kind: "replace",
1434
+ ...oldText !== void 0 ? { oldText } : {},
1435
+ newText: block["newText"]
1436
+ }
1437
+ };
1438
+ }
1284
1439
  function fileChangesFromAcpPermission(permissionRequest) {
1285
1440
  const content = permissionRequest.toolCall?.data["content"];
1286
1441
  const changes = Array.isArray(content) ? content.flatMap((entry) => {
@@ -1288,34 +1443,106 @@ function fileChangesFromAcpPermission(permissionRequest) {
1288
1443
  return [];
1289
1444
  }
1290
1445
  const block = entry;
1291
- if (block["type"] !== "diff" || typeof block["path"] !== "string" || typeof block["newText"] !== "string") {
1446
+ if (block["type"] !== "diff" || !isValidAcpFilePath(block["path"]) || typeof block["newText"] !== "string") {
1292
1447
  return [];
1293
1448
  }
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
- ];
1449
+ return [acpFileChangeFromDiffBlock(block, block["path"])];
1306
1450
  }) : [];
1307
- if (changes.length > 0) {
1308
- return changes;
1451
+ const boundedChanges = changes.length > MAX_ACP_FILE_CHANGES ? changes.slice(0, MAX_ACP_FILE_CHANGES) : changes;
1452
+ const requestType = canonicalRequestTypeFromAcpKind(permissionRequest.kind);
1453
+ if (boundedChanges.length > 0 || requestType === "file_change_approval" || requestType === "file_read_approval") {
1454
+ const locations = permissionRequest.toolCall?.data["locations"];
1455
+ const seenPaths = new Set(boundedChanges.map((change) => change.path));
1456
+ if (Array.isArray(locations)) {
1457
+ for (const entry of locations) {
1458
+ if (boundedChanges.length >= MAX_ACP_FILE_CHANGES) break;
1459
+ const rawPath = entry?.["path"];
1460
+ if (!isValidAcpFilePath(rawPath)) continue;
1461
+ if (!seenPaths.has(rawPath)) {
1462
+ seenPaths.add(rawPath);
1463
+ boundedChanges.push({ path: rawPath, omitted: "unavailable" });
1464
+ }
1465
+ }
1466
+ }
1467
+ }
1468
+ return boundedChanges.length > 0 ? boundedChanges : void 0;
1469
+ }
1470
+ function inspectAcpPermissionFileChanges(permissionRequest, inputFileChanges) {
1471
+ const merged = [];
1472
+ let fileChangesTruncated = false;
1473
+ for (const entry of inputFileChanges ?? []) {
1474
+ if (!isValidAcpFilePath(entry.path) || merged.length >= MAX_ACP_FILE_CHANGES) {
1475
+ fileChangesTruncated = true;
1476
+ continue;
1477
+ }
1478
+ merged.push(entry);
1309
1479
  }
1310
- if (canonicalRequestTypeFromAcpKind(permissionRequest.kind) !== "file_change_approval") {
1311
- return void 0;
1480
+ const seenPaths = new Set(merged.map((change) => change.path));
1481
+ const content = permissionRequest.toolCall?.data["content"];
1482
+ if (Array.isArray(content)) {
1483
+ let diffCount = 0;
1484
+ for (const entry of content) {
1485
+ if (isTruncatedFileChangesMarker(entry)) {
1486
+ fileChangesTruncated = true;
1487
+ continue;
1488
+ }
1489
+ if (entry === null || typeof entry !== "object") continue;
1490
+ const block = entry;
1491
+ if (block["type"] !== "diff") continue;
1492
+ diffCount += 1;
1493
+ const diffPath = block["path"];
1494
+ const newText = block["newText"];
1495
+ if (diffCount > MAX_ACP_FILE_CHANGES || !isValidAcpFilePath(diffPath) || typeof newText !== "string") {
1496
+ fileChangesTruncated = true;
1497
+ continue;
1498
+ }
1499
+ if (!seenPaths.has(diffPath)) {
1500
+ if (merged.length >= MAX_ACP_FILE_CHANGES) {
1501
+ fileChangesTruncated = true;
1502
+ continue;
1503
+ }
1504
+ seenPaths.add(diffPath);
1505
+ merged.push(acpFileChangeFromDiffBlock(block, diffPath));
1506
+ }
1507
+ }
1312
1508
  }
1509
+ const requestType = canonicalRequestTypeFromAcpKind(permissionRequest.kind);
1313
1510
  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;
1511
+ const hasLocationTruncationMarker = Array.isArray(locations) && locations.some(isTruncatedFileChangesMarker);
1512
+ if (Array.isArray(locations) && (merged.length > 0 || requestType === "file_change_approval" || requestType === "file_read_approval" || hasLocationTruncationMarker)) {
1513
+ let locationEntries = 0;
1514
+ for (const entry of locations) {
1515
+ if (isTruncatedFileChangesMarker(entry)) {
1516
+ fileChangesTruncated = true;
1517
+ continue;
1518
+ }
1519
+ locationEntries += 1;
1520
+ if (locationEntries > MAX_ACP_FILE_CHANGES) {
1521
+ fileChangesTruncated = true;
1522
+ continue;
1523
+ }
1524
+ const rawPath = entry !== null && typeof entry === "object" ? entry["path"] : void 0;
1525
+ if (!isValidAcpFilePath(rawPath)) {
1526
+ fileChangesTruncated = true;
1527
+ continue;
1528
+ }
1529
+ if (!seenPaths.has(rawPath)) {
1530
+ if (merged.length >= MAX_ACP_FILE_CHANGES) {
1531
+ fileChangesTruncated = true;
1532
+ continue;
1533
+ }
1534
+ seenPaths.add(rawPath);
1535
+ merged.push({ path: rawPath, omitted: "unavailable" });
1536
+ }
1537
+ }
1538
+ }
1539
+ if (merged.length > MAX_DISPLAY_FILE_CHANGES) {
1540
+ fileChangesTruncated = true;
1541
+ }
1542
+ return {
1543
+ fileChanges: merged.length > 0 ? merged : void 0,
1544
+ fileChangesTruncated
1545
+ };
1319
1546
  }
1320
1547
  function runtimeItemStatusFromAcpToolStatus(status) {
1321
1548
  switch (status) {
@@ -1332,7 +1559,19 @@ function runtimeItemStatusFromAcpToolStatus(status) {
1332
1559
  }
1333
1560
  function makeAcpRequestOpenedEvent(input2) {
1334
1561
  const requestType = canonicalRequestTypeFromAcpKind(input2.permissionRequest.kind);
1335
- const toolName = requestType === "dynamic_tool_call" ? input2.permissionRequest.toolCall?.title : void 0;
1562
+ const isDynamicToolKind = input2.permissionRequest.kind === "other" || input2.permissionRequest.kind === "unknown";
1563
+ const cleared = input2.permissionRequest.toolCall ? readToolCallIdentityFields(input2.permissionRequest.toolCall) : void 0;
1564
+ const rawRecord = input2.rawPayload !== null && typeof input2.rawPayload === "object" ? input2.rawPayload : void 0;
1565
+ const rawToolCall = rawRecord !== void 0 && rawRecord["toolCall"] !== null && typeof rawRecord["toolCall"] === "object" ? rawRecord["toolCall"] : void 0;
1566
+ const rawToolMeta = rawToolCall !== void 0 && rawToolCall["_meta"] !== null && typeof rawToolCall["_meta"] === "object" ? rawToolCall["_meta"] : void 0;
1567
+ const rawParentMeta = rawRecord !== void 0 && rawRecord["_meta"] !== null && typeof rawRecord["_meta"] === "object" ? rawRecord["_meta"] : void 0;
1568
+ 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;
1569
+ const candidateToolName = requestType === "dynamic_tool_call" && isDynamicToolKind && typeof input2.permissionRequest.toolCall?.data["name"] === "string" ? input2.permissionRequest.toolCall.data["name"] : void 0;
1570
+ const toolName = candidateToolName !== void 0 && !(negativeMcp && /^(?:(?:Running|Run)\s+)?mcp_/u.test(candidateToolName.trim())) ? candidateToolName : void 0;
1571
+ const { fileChanges, fileChangesTruncated } = inspectAcpPermissionFileChanges(
1572
+ input2.permissionRequest,
1573
+ input2.fileChanges
1574
+ );
1336
1575
  return {
1337
1576
  type: "request.opened",
1338
1577
  ...input2.stamp,
@@ -1347,7 +1586,8 @@ function makeAcpRequestOpenedEvent(input2) {
1347
1586
  args: input2.args,
1348
1587
  ...input2.statement !== void 0 ? { statement: input2.statement } : {},
1349
1588
  ...input2.options ? { options: input2.options } : {},
1350
- ...input2.fileChanges ? { fileChanges: input2.fileChanges } : {},
1589
+ ...fileChanges ? { fileChanges } : {},
1590
+ ...fileChangesTruncated ? { fileChangesTruncated: true } : {},
1351
1591
  declineReasonRelay: "queued"
1352
1592
  },
1353
1593
  raw: {
@@ -1389,7 +1629,8 @@ function makeAcpPlanUpdatedEvent(input2) {
1389
1629
  }
1390
1630
  function makeAcpToolCallEvent(input2) {
1391
1631
  const runtimeStatus = runtimeItemStatusFromAcpToolStatus(input2.toolCall.status);
1392
- const { data } = input2.toolCall;
1632
+ const rawData = input2.toolCall.data;
1633
+ const data = readToolCallIdentityFields(input2.toolCall).negativeMcp ? { ...rawData, mcpServer: null, mcpTool: null } : rawData;
1393
1634
  return {
1394
1635
  type: input2.toolCall.status === "completed" || input2.toolCall.status === "failed" ? "item.completed" : "item.updated",
1395
1636
  ...input2.stamp,
@@ -1444,29 +1685,45 @@ function makeAcpContentDeltaEvent(input2) {
1444
1685
  }
1445
1686
  };
1446
1687
  }
1688
+ function toolCallTrackingKey(sessionId, toolCallId) {
1689
+ return sessionId === void 0 ? toolCallId : `${sessionId}\0${toolCallId}`;
1690
+ }
1447
1691
  function retainToolCallUpdate(toolCalls, next, seen) {
1448
- const tracked = toolCalls.get(next.toolCallId);
1449
- const previous = tracked?.state;
1692
+ const key = toolCallTrackingKey(seen.sessionId, next.toolCallId);
1693
+ const tracked = toolCalls.get(key);
1694
+ const identityChanged = tracked !== void 0 && toolCallIdentityChanged(
1695
+ {
1696
+ name: tracked.state.data["name"],
1697
+ kind: tracked.state.kind,
1698
+ mcpServer: tracked.state.data["mcpServer"],
1699
+ mcpTool: tracked.state.data["mcpTool"]
1700
+ },
1701
+ readToolCallIdentityFields(next)
1702
+ );
1703
+ const reset = seen.isNewCall === true || identityChanged;
1704
+ const effectiveTracked = reset ? void 0 : tracked;
1705
+ const previous = effectiveTracked?.state;
1450
1706
  const nextToolCall = mergeToolCallState(previous, next);
1451
1707
  const decision = decideToolCallUpdateEmission({
1452
1708
  previous,
1453
1709
  next: nextToolCall,
1454
- lastEmittedDetailLength: tracked?.lastEmittedDetailLength,
1455
- skippedSinceEmit: tracked?.skippedSinceEmit ?? 0
1710
+ lastEmittedDetailLength: effectiveTracked?.lastEmittedDetailLength,
1711
+ skippedSinceEmit: effectiveTracked?.skippedSinceEmit ?? 0
1456
1712
  });
1457
1713
  if (nextToolCall.status === "completed" || nextToolCall.status === "failed") {
1458
- toolCalls.delete(nextToolCall.toolCallId);
1714
+ toolCalls.delete(key);
1459
1715
  } else {
1460
- toolCalls.set(nextToolCall.toolCallId, {
1716
+ toolCalls.set(key, {
1461
1717
  state: nextToolCall,
1462
- lastEmittedDetailLength: decision.emit ? nextToolCall.detail?.length : tracked?.lastEmittedDetailLength,
1718
+ lastEmittedDetailLength: decision.emit ? nextToolCall.detail?.length : effectiveTracked?.lastEmittedDetailLength,
1463
1719
  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
1720
+ sessionId: seen.sessionId ?? effectiveTracked?.sessionId,
1721
+ turnId: effectiveTracked === void 0 ? seen.turnId : effectiveTracked.turnId,
1722
+ startedAtMs: effectiveTracked?.startedAtMs ?? (nextToolCall.status === "inProgress" ? seen.nowMs() : void 0),
1723
+ 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
1724
  });
1468
1725
  }
1469
- return { nextToolCall, decision };
1726
+ return { nextToolCall, decision, reset };
1470
1727
  }
1471
1728
 
1472
1729
  // ../../packages/ycodium-acp-executor/src/executor/child-sessions.ts
@@ -25753,8 +26010,15 @@ function parseAcpResumeCursor(raw, schemaVersion) {
25753
26010
  function acpPromptSettlementBelongsToContext(input2) {
25754
26011
  return input2.liveAcpSessionId === input2.expectedAcpSessionId && (input2.liveActiveTurnId === input2.turnId || input2.liveSessionActiveTurnId === input2.turnId);
25755
26012
  }
26013
+ function isAcpPermissionOption(value) {
26014
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
26015
+ return false;
26016
+ }
26017
+ const option = value;
26018
+ return typeof option["optionId"] === "string" && typeof option["name"] === "string" && typeof option["kind"] === "string";
26019
+ }
25756
26020
  function isAcpRequestPermissionParams(value) {
25757
- if (typeof value !== "object" || value === null) {
26021
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
25758
26022
  return false;
25759
26023
  }
25760
26024
  const record3 = value;
@@ -25762,13 +26026,13 @@ function isAcpRequestPermissionParams(value) {
25762
26026
  return false;
25763
26027
  }
25764
26028
  const toolCall = record3["toolCall"];
25765
- if (typeof toolCall !== "object" || toolCall === null) {
26029
+ if (typeof toolCall !== "object" || toolCall === null || Array.isArray(toolCall)) {
25766
26030
  return false;
25767
26031
  }
25768
26032
  if (typeof toolCall["toolCallId"] !== "string") {
25769
26033
  return false;
25770
26034
  }
25771
- return Array.isArray(record3["options"]);
26035
+ return Array.isArray(record3["options"]) && record3["options"].every(isAcpPermissionOption);
25772
26036
  }
25773
26037
 
25774
26038
  // ../../packages/ycodium-acp-executor/src/apply-effort.ts
@@ -26694,15 +26958,123 @@ function createExecutorRequests({
26694
26958
  })
26695
26959
  );
26696
26960
  };
26961
+ const permissionMutationsByKey = /* @__PURE__ */ new Map();
26962
+ const trackingKeyByRequestId = /* @__PURE__ */ new Map();
26963
+ let nextSettlementSeq = 0;
26964
+ const readCommittedBaseline = (trackingKey) => {
26965
+ const pendingList = permissionMutationsByKey.get(trackingKey);
26966
+ if (pendingList !== void 0 && pendingList.length > 0) {
26967
+ return pendingList[0].previousTracked;
26968
+ }
26969
+ return toolCalls.get(trackingKey);
26970
+ };
26971
+ const recordPermissionMutation = (entry) => {
26972
+ const list = permissionMutationsByKey.get(entry.trackingKey);
26973
+ if (list !== void 0) list.push(entry);
26974
+ else permissionMutationsByKey.set(entry.trackingKey, [entry]);
26975
+ trackingKeyByRequestId.set(entry.requestId, entry.trackingKey);
26976
+ };
26977
+ const supersedePermissionTrackedState = (trackingKey, supersedeOptions) => {
26978
+ const list = permissionMutationsByKey.get(trackingKey);
26979
+ if (list === void 0) return;
26980
+ if (supersedeOptions?.restoreCommitted && list.length > 0) {
26981
+ restoreTrackedState(trackingKey, list[0].hadPrevious, list[0].previousTracked);
26982
+ }
26983
+ for (const item of list) trackingKeyByRequestId.delete(item.requestId);
26984
+ permissionMutationsByKey.delete(trackingKey);
26985
+ };
26986
+ const restoreTrackedState = (trackingKey, hadPrevious, previousTracked) => {
26987
+ if (hadPrevious && previousTracked !== void 0) {
26988
+ toolCalls.set(trackingKey, previousTracked);
26989
+ } else {
26990
+ toolCalls.delete(trackingKey);
26991
+ }
26992
+ };
26993
+ const runWithCommittedPermissionBaseline = (trackingKey, applyUpdate, passiveNextState, rawTitle) => {
26994
+ const list = permissionMutationsByKey.get(trackingKey);
26995
+ if (list === void 0 || list.length === 0) {
26996
+ return applyUpdate();
26997
+ }
26998
+ const baseEntry = list[0];
26999
+ restoreTrackedState(trackingKey, baseEntry.hadPrevious, baseEntry.previousTracked);
27000
+ const result = applyUpdate();
27001
+ if (result.reset) {
27002
+ for (const item of list) trackingKeyByRequestId.delete(item.requestId);
27003
+ permissionMutationsByKey.delete(trackingKey);
27004
+ return result;
27005
+ }
27006
+ baseEntry.hadPrevious = toolCalls.has(trackingKey);
27007
+ baseEntry.previousTracked = toolCalls.get(trackingKey);
27008
+ for (const item of list) {
27009
+ if (!item.hadApplied || item.appliedTracked === void 0) continue;
27010
+ const mergedApplied = mergeToolCallState(item.appliedTracked.state, passiveNextState);
27011
+ item.appliedTracked = {
27012
+ ...item.appliedTracked,
27013
+ state: mergedApplied,
27014
+ ...typeof rawTitle === "string" ? { rawTitle } : {}
27015
+ };
27016
+ }
27017
+ const tail = list[list.length - 1];
27018
+ restoreTrackedState(trackingKey, tail.hadApplied, tail.appliedTracked);
27019
+ return result;
27020
+ };
27021
+ const releasePermissionTrackedState = (requestId, accepted) => {
27022
+ const trackingKey = trackingKeyByRequestId.get(requestId);
27023
+ trackingKeyByRequestId.delete(requestId);
27024
+ if (trackingKey === void 0) return;
27025
+ const list = permissionMutationsByKey.get(trackingKey);
27026
+ if (list === void 0) return;
27027
+ const idx = list.findIndex((item) => item.requestId === requestId);
27028
+ if (idx < 0) return;
27029
+ if (!accepted || !list[idx].hasOwnMutation) {
27030
+ const [removed] = list.splice(idx, 1);
27031
+ if (removed === void 0) return;
27032
+ if (idx < list.length) {
27033
+ list[idx].hadPrevious = removed.hadPrevious;
27034
+ list[idx].previousTracked = removed.previousTracked;
27035
+ return;
27036
+ }
27037
+ if (list.length === 0) {
27038
+ permissionMutationsByKey.delete(trackingKey);
27039
+ }
27040
+ restoreTrackedState(trackingKey, removed.hadPrevious, removed.previousTracked);
27041
+ return;
27042
+ }
27043
+ const acceptedEntry = list[idx];
27044
+ const committed = list.splice(0, idx + 1);
27045
+ for (const item of committed) trackingKeyByRequestId.delete(item.requestId);
27046
+ if (list.length === 0) {
27047
+ permissionMutationsByKey.delete(trackingKey);
27048
+ restoreTrackedState(trackingKey, acceptedEntry.hadApplied, acceptedEntry.appliedTracked);
27049
+ } else {
27050
+ list[0].hadPrevious = acceptedEntry.hadApplied;
27051
+ list[0].previousTracked = acceptedEntry.appliedTracked;
27052
+ }
27053
+ };
26697
27054
  const settleApproval = (pending, outcome, decision, reason) => {
26698
27055
  if (!approvals.settle(pending, outcome)) {
26699
27056
  return false;
26700
27057
  }
27058
+ const accepted = outcome.outcome === "selected" && (decision === "accept" || decision === "acceptForSession" || decision === "acceptAlways");
27059
+ releasePermissionTrackedState(pending.requestId, accepted);
27060
+ hooks.onPermissionRequestSettled?.({
27061
+ sessionId: pending.request.sessionId,
27062
+ toolCallId: pending.request.toolCall.toolCallId,
27063
+ accepted,
27064
+ ...pending.settlementId === void 0 ? {} : { requestId: pending.settlementId }
27065
+ });
26701
27066
  emitResolved(pending, decision, reason);
26702
27067
  return true;
26703
27068
  };
26704
27069
  const settleAllApprovals = (decision) => {
26705
27070
  for (const entry of approvals.settleAll({ outcome: "cancelled" })) {
27071
+ releasePermissionTrackedState(entry.requestId, false);
27072
+ hooks.onPermissionRequestSettled?.({
27073
+ sessionId: entry.request.sessionId,
27074
+ toolCallId: entry.request.toolCall.toolCallId,
27075
+ accepted: false,
27076
+ ...entry.settlementId === void 0 ? {} : { requestId: entry.settlementId }
27077
+ });
26706
27078
  emitResolved(entry, decision);
26707
27079
  }
26708
27080
  };
@@ -26780,62 +27152,189 @@ function createExecutorRequests({
26780
27152
  outcome: optionId !== void 0 ? { outcome: "selected", optionId } : { outcome: "cancelled" }
26781
27153
  };
26782
27154
  };
26783
- const handlePermissionRequest = async (params) => {
26784
- if (!isAcpRequestPermissionParams(params)) {
27155
+ const handlePermissionRequest = async (rawParams) => {
27156
+ if (!isAcpRequestPermissionParams(rawParams)) {
26785
27157
  throw RequestError.invalidParams({ detail: "Malformed session/request_permission" });
26786
27158
  }
26787
- const userInputOutcome = await handlePermissionAsUserInput(params);
27159
+ const userInputOutcome = await handlePermissionAsUserInput(rawParams);
26788
27160
  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
- }
27161
+ failIfDisposed();
27162
+ const settlementId = `perm-${++nextSettlementSeq}`;
27163
+ const transformed = hooks.transformPermissionRequest ? hooks.transformPermissionRequest(rawParams, { requestId: settlementId }) : rawParams;
27164
+ if (!isAcpRequestPermissionParams(transformed)) {
27165
+ hooks.onPermissionRequestSettled?.({
27166
+ sessionId: rawParams.sessionId,
27167
+ toolCallId: rawParams.toolCall.toolCallId,
27168
+ accepted: false,
27169
+ requestId: settlementId
27170
+ });
27171
+ throw RequestError.invalidParams({ detail: "Malformed session/request_permission" });
26802
27172
  }
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({
27173
+ const params = transformed;
27174
+ const trackingKey = toolCallTrackingKey(params.sessionId, params.toolCall.toolCallId);
27175
+ const immediateHadPrevious = toolCalls.has(trackingKey);
27176
+ const immediatePrevious = toolCalls.get(trackingKey);
27177
+ let mutatedToolCall = false;
27178
+ const hasTextField = (record3, key) => typeof record3[key] === "string" && record3[key].trim().length > 0;
27179
+ const rawToolCallRecord = rawParams.toolCall;
27180
+ const rawReqMeta = rawToolCallRecord["_meta"];
27181
+ const rawParentMeta = rawParams["_meta"];
27182
+ const transformedToolCallRecord = params.toolCall;
27183
+ const transformedReqMeta = transformedToolCallRecord["_meta"];
27184
+ const transformedParentMeta = params["_meta"];
27185
+ 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;
27186
+ let hasOwnMutation = false;
27187
+ const prepared = (() => {
27188
+ try {
27189
+ const existingPendingList = permissionMutationsByKey.get(trackingKey);
27190
+ const hasPendingSibling = existingPendingList !== void 0 && existingPendingList.length > 0;
27191
+ const tracked = readCommittedBaseline(trackingKey);
27192
+ const requestFields = params.toolCall;
27193
+ const identityChanged = tracked !== void 0 && toolCallIdentityChanged(
27194
+ {
27195
+ name: tracked.state.data["name"],
27196
+ kind: tracked.state.kind,
27197
+ mcpServer: tracked.state.data["mcpServer"],
27198
+ mcpTool: tracked.state.data["mcpTool"]
27199
+ },
27200
+ {
27201
+ name: requestFields.name,
27202
+ kind: params.toolCall.kind,
27203
+ mcpServer: requestFields.mcpServer,
27204
+ mcpTool: requestFields.mcpTool
27205
+ }
27206
+ );
27207
+ const effectiveTracked = identityChanged ? void 0 : tracked;
27208
+ const parsed = parsePermissionRequest(params, effectiveTracked);
27209
+ const trackedNegativeMcp = tracked !== void 0 && readToolCallIdentityFields(tracked.state).negativeMcp;
27210
+ const parsedNegativeMcp = parsed.toolCall !== void 0 && readToolCallIdentityFields(parsed.toolCall).negativeMcp;
27211
+ 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"];
27212
+ 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;
27213
+ 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;
27214
+ if (hasOwnMutation || !hasPendingSibling) {
27215
+ if (parsed.toolCall === void 0) {
27216
+ if (identityChanged && toolCalls.delete(trackingKey)) {
27217
+ mutatedToolCall = true;
27218
+ }
27219
+ } else {
27220
+ if (parsed.toolCall.status === "completed" || parsed.toolCall.status === "failed") {
27221
+ if (toolCalls.delete(trackingKey)) {
27222
+ mutatedToolCall = true;
27223
+ }
27224
+ } else {
27225
+ mutatedToolCall = true;
27226
+ toolCalls.set(trackingKey, {
27227
+ state: parsed.toolCall,
27228
+ lastEmittedDetailLength: effectiveTracked?.lastEmittedDetailLength,
27229
+ skippedSinceEmit: effectiveTracked?.skippedSinceEmit ?? 0,
27230
+ sessionId: params.sessionId,
27231
+ turnId: effectiveTracked?.turnId ?? shared.activeTurnId,
27232
+ startedAtMs: effectiveTracked?.startedAtMs,
27233
+ rawTitle: retainedRawTitle
27234
+ });
27235
+ }
27236
+ }
27237
+ }
27238
+ const overriddenKind = hooks.permissionRequestKind?.({
27239
+ title: retainedRawTitle,
27240
+ kind: parsed.kind,
27241
+ rawInput: parsed.toolCall?.data["rawInput"]
27242
+ });
27243
+ const permissionRequest2 = overriddenKind === void 0 ? parsed : { ...parsed, kind: overriddenKind };
27244
+ if (options.autoApprove?.(permissionRequest2) === true) {
27245
+ const optionId = selectAutoApprovedAcpPermissionOption(params);
27246
+ if (optionId !== void 0) {
27247
+ if (hasOwnMutation) {
27248
+ supersedePermissionTrackedState(trackingKey);
27249
+ }
27250
+ hooks.onPermissionRequestSettled?.({
27251
+ sessionId: params.sessionId,
27252
+ toolCallId: params.toolCall.toolCallId,
27253
+ accepted: true,
27254
+ requestId: settlementId
27255
+ });
27256
+ return { autoApprovedOptionId: optionId };
27257
+ }
27258
+ }
27259
+ const permissionContext = {
27260
+ request: params,
27261
+ permissionRequest: permissionRequest2,
27262
+ previousToolCall: effectiveTracked?.state
27263
+ };
27264
+ const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest2);
27265
+ const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest2);
27266
+ const requestId2 = randomId();
27267
+ const openedEvent2 = makeAcpRequestOpenedEvent({
26823
27268
  stamp: stamp(),
26824
27269
  provider: options.provider,
26825
27270
  threadId: options.threadId,
26826
27271
  turnId: shared.activeTurnId,
26827
- requestId,
26828
- permissionRequest,
26829
- detail: statement.command ?? permissionRequest.detail,
26830
- args: permissionRequest.toolCall?.data["rawInput"] ?? params.toolCall.rawInput,
27272
+ requestId: requestId2,
27273
+ permissionRequest: permissionRequest2,
27274
+ detail: statement.command ?? permissionRequest2.detail,
27275
+ args: permissionRequest2.toolCall?.data["rawInput"] ?? params.toolCall.rawInput,
26831
27276
  statement,
26832
27277
  options: acpApprovalOptions(params),
26833
27278
  fileChanges,
26834
27279
  source: "acp.jsonrpc",
26835
27280
  method: "session/request_permission",
26836
27281
  rawPayload: params
26837
- })
26838
- );
27282
+ });
27283
+ return { requestId: requestId2, permissionRequest: permissionRequest2, openedEvent: openedEvent2 };
27284
+ } catch (error62) {
27285
+ if (mutatedToolCall) {
27286
+ restoreTrackedState(trackingKey, immediateHadPrevious, immediatePrevious);
27287
+ }
27288
+ hooks.onPermissionRequestSettled?.({
27289
+ sessionId: params.sessionId,
27290
+ toolCallId: params.toolCall.toolCallId,
27291
+ accepted: false,
27292
+ requestId: settlementId
27293
+ });
27294
+ throw error62;
27295
+ }
27296
+ })();
27297
+ if ("autoApprovedOptionId" in prepared) {
27298
+ return { outcome: { outcome: "selected", optionId: prepared.autoApprovedOptionId } };
27299
+ }
27300
+ const hadApplied = toolCalls.has(trackingKey);
27301
+ const appliedTracked = toolCalls.get(trackingKey);
27302
+ const { requestId, permissionRequest, openedEvent } = prepared;
27303
+ const outcome = await new Promise((resolve3, reject) => {
27304
+ const pending = {
27305
+ requestId,
27306
+ settlementId,
27307
+ request: params,
27308
+ permissionRequest,
27309
+ turnId: shared.activeTurnId,
27310
+ settled: false,
27311
+ resolve: resolve3
27312
+ };
27313
+ if (mutatedToolCall) {
27314
+ recordPermissionMutation({
27315
+ requestId,
27316
+ trackingKey,
27317
+ hasOwnMutation,
27318
+ hadPrevious: immediateHadPrevious,
27319
+ previousTracked: immediatePrevious,
27320
+ hadApplied,
27321
+ appliedTracked
27322
+ });
27323
+ }
27324
+ approvals.add(pending);
27325
+ try {
27326
+ emit(openedEvent);
27327
+ } catch (error62) {
27328
+ reject(error62);
27329
+ approvals.settle(pending, { outcome: "cancelled" });
27330
+ releasePermissionTrackedState(requestId, false);
27331
+ hooks.onPermissionRequestSettled?.({
27332
+ sessionId: params.sessionId,
27333
+ toolCallId: params.toolCall.toolCallId,
27334
+ accepted: false,
27335
+ requestId: settlementId
27336
+ });
27337
+ }
26839
27338
  });
26840
27339
  return { outcome };
26841
27340
  };
@@ -26893,7 +27392,9 @@ function createExecutorRequests({
26893
27392
  makeExtensionContext,
26894
27393
  handlePermissionRequest,
26895
27394
  respondToRequest,
26896
- respondToUserInput
27395
+ respondToUserInput,
27396
+ supersedePermissionTrackedState,
27397
+ runWithCommittedPermissionBaseline
26897
27398
  };
26898
27399
  }
26899
27400
 
@@ -27813,7 +28314,9 @@ function createExecutorUpdates({
27813
28314
  emitArtifacts,
27814
28315
  closeActiveAssistantSegment,
27815
28316
  ensureActiveAssistantSegment,
27816
- shared
28317
+ shared,
28318
+ supersedePermissionTrackedState,
28319
+ runWithCommittedPermissionBaseline
27817
28320
  }) {
27818
28321
  const shownToolCallIds = /* @__PURE__ */ new Set();
27819
28322
  const markChildSession = shared.childSessions.mark;
@@ -27954,7 +28457,7 @@ function createExecutorUpdates({
27954
28457
  sessionId: shared.sessionId,
27955
28458
  markChildSession
27956
28459
  });
27957
- const handleSessionUpdate = (params) => {
28460
+ const handleSessionUpdate = (params, rawWireUpdate) => {
27958
28461
  const update = params.update;
27959
28462
  const reportedOptions = update["configOptions"];
27960
28463
  if (update["sessionUpdate"] === "config_option_update" && Array.isArray(reportedOptions)) {
@@ -27990,11 +28493,45 @@ function createExecutorUpdates({
27990
28493
  }
27991
28494
  for (const event2 of parsed.events) {
27992
28495
  if (event2._tag === "ToolCallUpdated") {
27993
- const { nextToolCall, decision } = retainToolCallUpdate(toolCalls, event2.toolCall, {
28496
+ const isNewCall = params.update.sessionUpdate === "tool_call";
28497
+ const shownKey = toolCallTrackingKey(params.sessionId, event2.toolCall.toolCallId);
28498
+ const wireRecord = isRecord2(rawWireUpdate) ? rawWireUpdate : void 0;
28499
+ const wireMeta = wireRecord !== void 0 && isRecord2(wireRecord["_meta"]) ? wireRecord["_meta"] : void 0;
28500
+ const wireParentMeta = isRecord2(params._meta) ? params._meta : void 0;
28501
+ 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);
28502
+ const rawTitle = params.update.title;
28503
+ const supersedesPendingPermission = isNewCall || event2.toolCall.status === "completed" || event2.toolCall.status === "failed" || hasWireIdentity;
28504
+ if (supersedesPendingPermission) {
28505
+ supersedePermissionTrackedState?.(shownKey, { restoreCommitted: true });
28506
+ }
28507
+ const runRetain = () => retainToolCallUpdate(toolCalls, event2.toolCall, {
28508
+ sessionId: params.sessionId,
27994
28509
  turnId: shared.activeTurnId,
27995
- rawTitle: params.update.title,
28510
+ rawTitle,
28511
+ isNewCall,
27996
28512
  nowMs
27997
28513
  });
28514
+ const updateRecord = params.update;
28515
+ const passiveRawTitle = wireRecord !== void 0 ? wireRecord["title"] : updateRecord["title"];
28516
+ const passiveWireState = !supersedesPendingPermission && runWithCommittedPermissionBaseline !== void 0 ? makeToolCallState({
28517
+ toolCallId: event2.toolCall.toolCallId,
28518
+ title: typeof passiveRawTitle === "string" ? passiveRawTitle : void 0,
28519
+ status: updateRecord["status"],
28520
+ rawInput: updateRecord["rawInput"],
28521
+ rawOutput: updateRecord["rawOutput"],
28522
+ content: updateRecord["content"],
28523
+ locations: updateRecord["locations"]
28524
+ }) : void 0;
28525
+ const { nextToolCall, decision, reset } = !supersedesPendingPermission && runWithCommittedPermissionBaseline !== void 0 ? runWithCommittedPermissionBaseline(
28526
+ shownKey,
28527
+ runRetain,
28528
+ passiveWireState ?? event2.toolCall,
28529
+ rawTitle
28530
+ ) : runRetain();
28531
+ if (reset) {
28532
+ supersedePermissionTrackedState?.(shownKey);
28533
+ shownToolCallIds.delete(shownKey);
28534
+ }
27998
28535
  const hasToolHooks = toolSubagents !== void 0 || hooks.onToolCallUpdated !== void 0;
27999
28536
  const toolName = typeof nextToolCall.data["name"] === "string" ? nextToolCall.data["name"] : void 0;
28000
28537
  const call = !hasToolHooks ? void 0 : {
@@ -28020,8 +28557,8 @@ function createExecutorUpdates({
28020
28557
  continue;
28021
28558
  }
28022
28559
  const toolTurnId = (hookResult !== void 0 && "events" in hookResult ? hookResult.turnId : void 0) ?? shared.activeTurnId;
28023
- if (!shownToolCallIds.has(nextToolCall.toolCallId)) {
28024
- rememberShownToolCall(nextToolCall.toolCallId);
28560
+ if (isNewCall || !shownToolCallIds.has(shownKey)) {
28561
+ rememberShownToolCall(shownKey);
28025
28562
  if (toolTurnId === shared.activeTurnId) closeActiveAssistantSegment(shared.activeTurnId);
28026
28563
  }
28027
28564
  emit(
@@ -28117,7 +28654,7 @@ function createExecutorUpdates({
28117
28654
  }
28118
28655
  }
28119
28656
  };
28120
- const receiveSessionUpdate = (params) => {
28657
+ const receiveSessionUpdate = (params, rawWireUpdate) => {
28121
28658
  const foreign = !shared.ownSessionIds.has(params.sessionId) && (shared.childSessions.has(params.sessionId) || shared.sessionOpensInFlight === 0 && shared.ownSessionIds.size > 0);
28122
28659
  emitHookEvents(
28123
28660
  subagentSessions?.observe(params, {
@@ -28132,7 +28669,7 @@ function createExecutorUpdates({
28132
28669
  emitHookEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
28133
28670
  }
28134
28671
  }
28135
- if (!foreign) handleSessionUpdate(params);
28672
+ if (!foreign) handleSessionUpdate(params, rawWireUpdate);
28136
28673
  };
28137
28674
  const receiveExtensionNotification = (method, params) => {
28138
28675
  if (shared.sessionLoadInFlight || !hooks.onExtensionNotification) return;
@@ -28331,6 +28868,27 @@ function createAcpExecutor(options) {
28331
28868
  promptMutex,
28332
28869
  shared
28333
28870
  });
28871
+ const {
28872
+ settleAllApprovals,
28873
+ settleAllUserInputs,
28874
+ makeExtensionContext,
28875
+ handlePermissionRequest,
28876
+ respondToRequest,
28877
+ respondToUserInput,
28878
+ supersedePermissionTrackedState,
28879
+ runWithCommittedPermissionBaseline
28880
+ } = createExecutorRequests({
28881
+ emit,
28882
+ stamp,
28883
+ options,
28884
+ approvals,
28885
+ pendingUserInputs,
28886
+ failIfDisposed,
28887
+ randomId,
28888
+ hooks,
28889
+ shared,
28890
+ toolCalls
28891
+ });
28334
28892
  const {
28335
28893
  emitCompactionState,
28336
28894
  receiveSessionUpdate,
@@ -28350,26 +28908,9 @@ function createAcpExecutor(options) {
28350
28908
  emitArtifacts,
28351
28909
  closeActiveAssistantSegment,
28352
28910
  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
28911
  shared,
28372
- toolCalls
28912
+ supersedePermissionTrackedState,
28913
+ runWithCommittedPermissionBaseline
28373
28914
  });
28374
28915
  const { rememberSettledPromptKey, abortPendingSettlement, settleFromNotification } = createExecutorSettlement({ hooks, shared });
28375
28916
  const promptResults = createPromptResults({ options, shared });
@@ -28400,8 +28941,9 @@ function createAcpExecutor(options) {
28400
28941
  onNotification: (notification) => {
28401
28942
  if (notification.method === "session/update") {
28402
28943
  const params = notification.params;
28944
+ const rawUpdate = params.update;
28403
28945
  const transformed = hooks.transformSessionUpdate ? hooks.transformSessionUpdate(params) : params;
28404
- if (transformed !== void 0) receiveSessionUpdate(transformed);
28946
+ if (transformed !== void 0) receiveSessionUpdate(transformed, rawUpdate);
28405
28947
  return;
28406
28948
  }
28407
28949
  if (settleFromNotification(notification.method, notification.params)) return;
@@ -30026,9 +30568,11 @@ var KIMI_NATIVE_MODE_REPORT = {
30026
30568
  };
30027
30569
 
30028
30570
  // src/runtimeModeApproval.ts
30029
- function acpRuntimeModeAutoApproves(runtimeMode, toolKind, toolName, nativeMode = false) {
30571
+ function acpRuntimeModeAutoApproves(runtimeMode, toolKind, toolName, nativeMode = false, negativeMcp = false) {
30030
30572
  if (nativeMode) return false;
30031
- if (runtimeMode === "auto" && toolKind === "other" && toolName?.startsWith("mcp__")) return true;
30573
+ if (runtimeMode === "auto" && !negativeMcp && toolKind === "other" && toolName?.startsWith("mcp__")) {
30574
+ return true;
30575
+ }
30032
30576
  switch (runtimeMode) {
30033
30577
  case "full-access":
30034
30578
  return true;
@@ -30630,11 +31174,13 @@ var createKimiInstance = (config2, host, profileDataDir2) => {
30630
31174
  const hooks = kimiHooks(recipe);
30631
31175
  const autoApprove = (request) => {
30632
31176
  const session = threads.get(input2.threadId)?.session ?? input2;
31177
+ const negativeMcp = request.toolCall !== void 0 && readToolCallIdentityFields(request.toolCall).negativeMcp;
30633
31178
  return acpRuntimeModeAutoApproves(
30634
31179
  session.runtimeMode,
30635
31180
  request.kind,
30636
31181
  request.toolCall?.title,
30637
- session.nativeModeId !== void 0
31182
+ session.nativeModeId !== void 0,
31183
+ negativeMcp
30638
31184
  );
30639
31185
  };
30640
31186
  const executor = createAcpExecutor({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-kimi",
3
- "version": "0.2.5912",
3
+ "version": "0.2.5939",
4
4
  "description": "Kimi Code executor: runs `kimi acp` over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -21,10 +21,10 @@
21
21
  "@types/node": "24.12.4",
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
- "@ycodium-ai/plugin-api": "0.2.5912",
25
- "ycodium-executor-testing": "0.0.0",
26
- "ycodium-acp-executor": "0.2.5912",
27
- "ycodium-instance-config": "0.0.0"
24
+ "@ycodium-ai/plugin-api": "0.2.5939",
25
+ "ycodium-acp-executor": "0.2.5939",
26
+ "ycodium-instance-config": "0.0.0",
27
+ "ycodium-executor-testing": "0.0.0"
28
28
  },
29
29
  "ycodium": {
30
30
  "plugin": "./dist/index.js",