ycodium-acp-executor 0.2.5912 → 0.2.5939
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_private/ycodium-executor-common/mcpToolIdentity.d.ts +10 -0
- package/dist/_private/ycodium-executor-common/mcpToolIdentity.js +21 -0
- package/dist/adapter-support.d.ts.map +1 -1
- package/dist/adapter-support.js +12 -3
- package/dist/adapter-support.js.map +1 -1
- package/dist/approvals.d.ts +1 -0
- package/dist/approvals.d.ts.map +1 -1
- package/dist/approvals.js.map +1 -1
- package/dist/events.d.ts +18 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +226 -40
- package/dist/events.js.map +1 -1
- package/dist/executor/requests.d.ts +12 -1
- package/dist/executor/requests.d.ts.map +1 -1
- package/dist/executor/requests.js +341 -45
- package/dist/executor/requests.js.map +1 -1
- package/dist/executor/updates.d.ts +14 -2
- package/dist/executor/updates.d.ts.map +1 -1
- package/dist/executor/updates.js +65 -10
- package/dist/executor/updates.js.map +1 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +16 -13
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime-model.d.ts.map +1 -1
- package/dist/runtime-model.js +54 -10
- package/dist/runtime-model.js.map +1 -1
- package/dist/source/_private/ycodium-executor-common/mcpToolIdentity.ts +38 -0
- package/dist/source/adapter-support.ts +15 -3
- package/dist/source/approvals.ts +1 -0
- package/dist/source/events.ts +277 -41
- package/dist/source/executor/requests.ts +372 -45
- package/dist/source/executor/updates.ts +98 -12
- package/dist/source/executor.ts +25 -20
- package/dist/source/index.ts +4 -1
- package/dist/source/runtime-model.ts +75 -10
- package/dist/source/tool-call-state.ts +187 -5
- package/dist/source/types.ts +6 -1
- package/dist/source/vendor-hooks.ts +19 -0
- package/dist/tool-call-state.d.ts +27 -0
- package/dist/tool-call-state.d.ts.map +1 -1
- package/dist/tool-call-state.js +128 -5
- package/dist/tool-call-state.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/vendor-hooks.d.ts +18 -0
- package/dist/vendor-hooks.d.ts.map +1 -1
- package/dist/vendor-hooks.js.map +1 -1
- package/package.json +4 -4
package/dist/source/executor.ts
CHANGED
|
@@ -274,6 +274,27 @@ export function createAcpExecutor(options: AcpExecutorOptions): AcpExecutor {
|
|
|
274
274
|
promptMutex,
|
|
275
275
|
shared,
|
|
276
276
|
});
|
|
277
|
+
const {
|
|
278
|
+
settleAllApprovals,
|
|
279
|
+
settleAllUserInputs,
|
|
280
|
+
makeExtensionContext,
|
|
281
|
+
handlePermissionRequest,
|
|
282
|
+
respondToRequest,
|
|
283
|
+
respondToUserInput,
|
|
284
|
+
supersedePermissionTrackedState,
|
|
285
|
+
runWithCommittedPermissionBaseline,
|
|
286
|
+
} = createExecutorRequests({
|
|
287
|
+
emit,
|
|
288
|
+
stamp,
|
|
289
|
+
options,
|
|
290
|
+
approvals,
|
|
291
|
+
pendingUserInputs,
|
|
292
|
+
failIfDisposed,
|
|
293
|
+
randomId,
|
|
294
|
+
hooks,
|
|
295
|
+
shared,
|
|
296
|
+
toolCalls,
|
|
297
|
+
});
|
|
277
298
|
const {
|
|
278
299
|
emitCompactionState,
|
|
279
300
|
receiveSessionUpdate,
|
|
@@ -294,25 +315,8 @@ export function createAcpExecutor(options: AcpExecutorOptions): AcpExecutor {
|
|
|
294
315
|
closeActiveAssistantSegment,
|
|
295
316
|
ensureActiveAssistantSegment,
|
|
296
317
|
shared,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
settleAllApprovals,
|
|
300
|
-
settleAllUserInputs,
|
|
301
|
-
makeExtensionContext,
|
|
302
|
-
handlePermissionRequest,
|
|
303
|
-
respondToRequest,
|
|
304
|
-
respondToUserInput,
|
|
305
|
-
} = createExecutorRequests({
|
|
306
|
-
emit,
|
|
307
|
-
stamp,
|
|
308
|
-
options,
|
|
309
|
-
approvals,
|
|
310
|
-
pendingUserInputs,
|
|
311
|
-
failIfDisposed,
|
|
312
|
-
randomId,
|
|
313
|
-
hooks,
|
|
314
|
-
shared,
|
|
315
|
-
toolCalls,
|
|
318
|
+
supersedePermissionTrackedState,
|
|
319
|
+
runWithCommittedPermissionBaseline,
|
|
316
320
|
});
|
|
317
321
|
const { rememberSettledPromptKey, abortPendingSettlement, settleFromNotification } =
|
|
318
322
|
createExecutorSettlement({ hooks, shared });
|
|
@@ -351,10 +355,11 @@ export function createAcpExecutor(options: AcpExecutorOptions): AcpExecutor {
|
|
|
351
355
|
onNotification: (notification: AcpIncomingNotification) => {
|
|
352
356
|
if (notification.method === "session/update") {
|
|
353
357
|
const params = notification.params as SessionNotification;
|
|
358
|
+
const rawUpdate = (params as { readonly update?: unknown }).update;
|
|
354
359
|
const transformed = hooks.transformSessionUpdate
|
|
355
360
|
? hooks.transformSessionUpdate(params)
|
|
356
361
|
: params;
|
|
357
|
-
if (transformed !== undefined) receiveSessionUpdate(transformed);
|
|
362
|
+
if (transformed !== undefined) receiveSessionUpdate(transformed, rawUpdate);
|
|
358
363
|
return;
|
|
359
364
|
}
|
|
360
365
|
if (settleFromNotification(notification.method, notification.params)) return;
|
package/dist/source/index.ts
CHANGED
|
@@ -97,7 +97,10 @@ export {
|
|
|
97
97
|
makeAcpRequestOpenedEvent,
|
|
98
98
|
makeAcpRequestResolvedEvent,
|
|
99
99
|
makeAcpToolCallEvent,
|
|
100
|
+
markAcpDiffTooLarge,
|
|
101
|
+
readAcpDiffTooLarge,
|
|
100
102
|
} from "./events.ts";
|
|
103
|
+
export type { AcpClippedDiffStats } from "./events.ts";
|
|
101
104
|
export {
|
|
102
105
|
acpCommandsToSlashCommands,
|
|
103
106
|
decideToolCallUpdateEmission,
|
|
@@ -159,7 +162,7 @@ export type {
|
|
|
159
162
|
ExecutorEvent,
|
|
160
163
|
ExecutorEventType,
|
|
161
164
|
} from "./types.ts";
|
|
162
|
-
export { boundTailText } from "./tool-call-state.ts";
|
|
165
|
+
export { boundTailText, readToolCallIdentityFields } from "./tool-call-state.ts";
|
|
163
166
|
export { createToolSubagentTracker } from "./tool-subagents.ts";
|
|
164
167
|
export type {
|
|
165
168
|
AcpToolSubagentFacts,
|
|
@@ -5,7 +5,12 @@ import type { SessionNotification } from "./protocol.ts";
|
|
|
5
5
|
|
|
6
6
|
import { findConfigOptionEntry } from "./config-options.ts";
|
|
7
7
|
import { isRecord, readAcpText } from "./util.ts";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
makeToolCallState,
|
|
10
|
+
readToolCallIdentityFields,
|
|
11
|
+
toolCallIdentityChanged,
|
|
12
|
+
type AcpToolCallState,
|
|
13
|
+
} from "./tool-call-state.ts";
|
|
9
14
|
|
|
10
15
|
export { decideToolCallUpdateEmission, mergeToolCallState } from "./tool-call-state.ts";
|
|
11
16
|
export type { AcpToolCallEmitDecision, AcpToolCallState } from "./tool-call-state.ts";
|
|
@@ -330,20 +335,76 @@ export function parsePermissionRequest(
|
|
|
330
335
|
known?: { readonly state: AcpToolCallState; readonly rawTitle: string | undefined },
|
|
331
336
|
): AcpPermissionRequest {
|
|
332
337
|
const request = params.toolCall;
|
|
338
|
+
const requestFields = request as {
|
|
339
|
+
readonly name?: unknown;
|
|
340
|
+
readonly mcpServer?: unknown;
|
|
341
|
+
readonly mcpTool?: unknown;
|
|
342
|
+
};
|
|
333
343
|
const earlier = known?.state.data;
|
|
344
|
+
const identityChanged =
|
|
345
|
+
known !== undefined &&
|
|
346
|
+
toolCallIdentityChanged(
|
|
347
|
+
{
|
|
348
|
+
name: earlier?.["name"],
|
|
349
|
+
kind: known.state.kind,
|
|
350
|
+
mcpServer: earlier?.["mcpServer"],
|
|
351
|
+
mcpTool: earlier?.["mcpTool"],
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: requestFields.name,
|
|
355
|
+
kind: request.kind,
|
|
356
|
+
mcpServer: requestFields.mcpServer,
|
|
357
|
+
mcpTool: requestFields.mcpTool,
|
|
358
|
+
},
|
|
359
|
+
);
|
|
360
|
+
const prior = identityChanged ? undefined : known;
|
|
361
|
+
const priorData = identityChanged ? undefined : earlier;
|
|
362
|
+
const priorNegativeMcp =
|
|
363
|
+
prior !== undefined ? readToolCallIdentityFields(prior.state).negativeMcp : false;
|
|
364
|
+
const reqMeta = (request as { readonly _meta?: unknown })._meta;
|
|
365
|
+
const parentMeta = (params as { readonly _meta?: unknown })._meta;
|
|
366
|
+
const requestNegativeMcp =
|
|
367
|
+
requestFields.mcpServer === null ||
|
|
368
|
+
requestFields.mcpTool === null ||
|
|
369
|
+
(isRecord(reqMeta) && reqMeta["is_mcp_tool_call"] === false) ||
|
|
370
|
+
(isRecord(parentMeta) && parentMeta["is_mcp_tool_call"] === false);
|
|
371
|
+
const allowPriorMcpFields =
|
|
372
|
+
!priorNegativeMcp && !requestNegativeMcp && requestFields.name === undefined;
|
|
373
|
+
const inheritedRawTitle =
|
|
374
|
+
prior?.rawTitle !== undefined &&
|
|
375
|
+
!(
|
|
376
|
+
(priorNegativeMcp || requestNegativeMcp) &&
|
|
377
|
+
/^(?:(?:Running|Run)\s+)?mcp_/u.test(prior.rawTitle.trim())
|
|
378
|
+
)
|
|
379
|
+
? prior.rawTitle
|
|
380
|
+
: undefined;
|
|
334
381
|
const toolCall = makeToolCallState(
|
|
335
382
|
{
|
|
336
383
|
toolCallId: request.toolCallId,
|
|
337
|
-
name:
|
|
338
|
-
|
|
339
|
-
|
|
384
|
+
name: requestFields.name !== undefined ? requestFields.name : priorData?.["name"],
|
|
385
|
+
mcpServer:
|
|
386
|
+
requestFields.mcpServer !== undefined
|
|
387
|
+
? requestFields.mcpServer
|
|
388
|
+
: allowPriorMcpFields
|
|
389
|
+
? priorData?.["mcpServer"]
|
|
390
|
+
: undefined,
|
|
391
|
+
mcpTool:
|
|
392
|
+
requestFields.mcpTool !== undefined
|
|
393
|
+
? requestFields.mcpTool
|
|
394
|
+
: allowPriorMcpFields
|
|
395
|
+
? priorData?.["mcpTool"]
|
|
396
|
+
: undefined,
|
|
397
|
+
title: request.title ?? inheritedRawTitle,
|
|
398
|
+
kind: request.kind ?? priorData?.["kind"],
|
|
340
399
|
status: request.status ?? known?.state.status,
|
|
341
|
-
rawInput: request.rawInput !== undefined ? request.rawInput :
|
|
342
|
-
rawOutput: request.rawOutput !== undefined ? request.rawOutput :
|
|
343
|
-
content: request.content !== undefined ? request.content :
|
|
344
|
-
locations: request.locations !== undefined ? request.locations :
|
|
400
|
+
rawInput: request.rawInput !== undefined ? request.rawInput : priorData?.["rawInput"],
|
|
401
|
+
rawOutput: request.rawOutput !== undefined ? request.rawOutput : priorData?.["rawOutput"],
|
|
402
|
+
content: request.content !== undefined ? request.content : priorData?.["content"],
|
|
403
|
+
locations: request.locations !== undefined ? request.locations : priorData?.["locations"],
|
|
404
|
+
_meta: reqMeta,
|
|
405
|
+
parentMeta,
|
|
345
406
|
},
|
|
346
|
-
{ fallbackStatus: "pending" },
|
|
407
|
+
{ fallbackStatus: "pending", ...(priorNegativeMcp ? { inheritedNegativeMcp: true } : {}) },
|
|
347
408
|
);
|
|
348
409
|
const kind = toolCall?.kind ?? "unknown";
|
|
349
410
|
const content = toolCall?.data["content"];
|
|
@@ -357,7 +418,7 @@ export function parsePermissionRequest(
|
|
|
357
418
|
: [];
|
|
358
419
|
})[0]
|
|
359
420
|
: undefined;
|
|
360
|
-
const originalTitle = (request.title ??
|
|
421
|
+
const originalTitle = (request.title ?? inheritedRawTitle)?.trim() || undefined;
|
|
361
422
|
const detail = toolCall?.command ?? firstText ?? originalTitle;
|
|
362
423
|
return {
|
|
363
424
|
kind,
|
|
@@ -479,6 +540,8 @@ export function parseSessionUpdateEvent(params: SessionNotification): {
|
|
|
479
540
|
{
|
|
480
541
|
toolCallId: upd["toolCallId"],
|
|
481
542
|
name: upd["name"],
|
|
543
|
+
mcpServer: upd["mcpServer"],
|
|
544
|
+
mcpTool: upd["mcpTool"],
|
|
482
545
|
title: typeof upd["title"] === "string" ? upd["title"] : undefined,
|
|
483
546
|
kind: upd["kind"],
|
|
484
547
|
status: upd["status"],
|
|
@@ -486,6 +549,8 @@ export function parseSessionUpdateEvent(params: SessionNotification): {
|
|
|
486
549
|
rawOutput: upd["rawOutput"],
|
|
487
550
|
content: upd["content"],
|
|
488
551
|
locations: upd["locations"],
|
|
552
|
+
_meta: upd["_meta"],
|
|
553
|
+
parentMeta: (params as { readonly _meta?: unknown })._meta,
|
|
489
554
|
},
|
|
490
555
|
kind === "tool_call" ? { fallbackStatus: "pending" } : undefined,
|
|
491
556
|
);
|
|
@@ -18,6 +18,38 @@ export interface AcpToolCallState {
|
|
|
18
18
|
readonly data: Record<string, unknown>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
interface ClearedToolCallIdentityFields {
|
|
22
|
+
readonly name?: null;
|
|
23
|
+
readonly mcpServer?: null;
|
|
24
|
+
readonly mcpTool?: null;
|
|
25
|
+
readonly negativeMcp?: true;
|
|
26
|
+
readonly positiveMcp?: true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const clearedIdentityFields = new WeakMap<AcpToolCallState, ClearedToolCallIdentityFields>();
|
|
30
|
+
const fallbackTitleStates = new WeakSet<AcpToolCallState>();
|
|
31
|
+
|
|
32
|
+
/** 读取用于判定身份变化的字段,保留规范化层用 `null` 显式抹掉的身份/MCP 清除信号与负向 MCP 标记。 */
|
|
33
|
+
export function readToolCallIdentityFields(
|
|
34
|
+
state: AcpToolCallState,
|
|
35
|
+
options?: { readonly kindFromData?: boolean },
|
|
36
|
+
): {
|
|
37
|
+
readonly name: unknown;
|
|
38
|
+
readonly kind: unknown;
|
|
39
|
+
readonly mcpServer: unknown;
|
|
40
|
+
readonly mcpTool: unknown;
|
|
41
|
+
readonly negativeMcp: boolean;
|
|
42
|
+
} {
|
|
43
|
+
const cleared = clearedIdentityFields.get(state);
|
|
44
|
+
return {
|
|
45
|
+
name: cleared?.name === null ? null : state.data["name"],
|
|
46
|
+
kind: options?.kindFromData ? state.data["kind"] : state.kind,
|
|
47
|
+
mcpServer: cleared?.mcpServer === null ? null : state.data["mcpServer"],
|
|
48
|
+
mcpTool: cleared?.mcpTool === null ? null : state.data["mcpTool"],
|
|
49
|
+
negativeMcp: cleared?.negativeMcp === true,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
21
53
|
function normalizeToolCallStatus(
|
|
22
54
|
raw: unknown,
|
|
23
55
|
fallback?: "pending" | "inProgress" | "completed" | "failed",
|
|
@@ -176,6 +208,9 @@ export function makeToolCallState(
|
|
|
176
208
|
readonly toolCallId: unknown;
|
|
177
209
|
/** ACP 扩展字段,常只有首条 tool_call 带;落进 `data` 由 `mergeToolCallState` 沿用,后到的覆盖旧的。 */
|
|
178
210
|
readonly name?: unknown;
|
|
211
|
+
/** 由 adapter 在归一化前缀前确立的 MCP server 与工具名,防下游按较小配置表重新拆错。 */
|
|
212
|
+
readonly mcpServer?: unknown;
|
|
213
|
+
readonly mcpTool?: unknown;
|
|
179
214
|
readonly title?: string | null | undefined;
|
|
180
215
|
readonly kind?: unknown;
|
|
181
216
|
readonly status?: unknown;
|
|
@@ -183,15 +218,42 @@ export function makeToolCallState(
|
|
|
183
218
|
readonly rawOutput?: unknown;
|
|
184
219
|
readonly content?: unknown;
|
|
185
220
|
readonly locations?: unknown;
|
|
221
|
+
readonly _meta?: unknown;
|
|
222
|
+
readonly parentMeta?: unknown;
|
|
186
223
|
},
|
|
187
224
|
options?: {
|
|
188
225
|
readonly fallbackStatus?: "pending" | "inProgress" | "completed" | "failed";
|
|
226
|
+
readonly inheritedNegativeMcp?: boolean;
|
|
189
227
|
},
|
|
190
228
|
): AcpToolCallState | undefined {
|
|
191
229
|
const toolCallId = typeof input.toolCallId === "string" ? input.toolCallId.trim() : "";
|
|
192
230
|
if (!toolCallId) {
|
|
193
231
|
return undefined;
|
|
194
232
|
}
|
|
233
|
+
const explicitNullMcp = input.mcpServer === null || input.mcpTool === null;
|
|
234
|
+
const reqMetaFlag =
|
|
235
|
+
isRecord(input._meta) && typeof input._meta["is_mcp_tool_call"] === "boolean"
|
|
236
|
+
? input._meta["is_mcp_tool_call"]
|
|
237
|
+
: undefined;
|
|
238
|
+
const parentMetaFlag =
|
|
239
|
+
isRecord(input.parentMeta) && typeof input.parentMeta["is_mcp_tool_call"] === "boolean"
|
|
240
|
+
? input.parentMeta["is_mcp_tool_call"]
|
|
241
|
+
: undefined;
|
|
242
|
+
const metaFlag =
|
|
243
|
+
reqMetaFlag === false || parentMetaFlag === false
|
|
244
|
+
? false
|
|
245
|
+
: reqMetaFlag === true || parentMetaFlag === true
|
|
246
|
+
? true
|
|
247
|
+
: undefined;
|
|
248
|
+
const explicitPositiveMcp =
|
|
249
|
+
!explicitNullMcp &&
|
|
250
|
+
metaFlag !== false &&
|
|
251
|
+
(metaFlag === true ||
|
|
252
|
+
(readAcpText(input, "mcpServer") !== undefined &&
|
|
253
|
+
readAcpText(input, "mcpTool") !== undefined));
|
|
254
|
+
const explicitNegativeMcp = explicitNullMcp || metaFlag === false;
|
|
255
|
+
const negativeMcp =
|
|
256
|
+
explicitNegativeMcp || (!explicitPositiveMcp && options?.inheritedNegativeMcp === true);
|
|
195
257
|
const title = typeof input.title === "string" ? input.title.trim() || undefined : undefined;
|
|
196
258
|
const command = extractToolCallCommand(input.rawInput, title);
|
|
197
259
|
const extractedContent = extractTextContentFromToolCallContent(input.content);
|
|
@@ -208,6 +270,12 @@ export function makeToolCallState(
|
|
|
208
270
|
const name = readAcpText(input, "name");
|
|
209
271
|
if (name) {
|
|
210
272
|
data["name"] = name;
|
|
273
|
+
const mcpServer = readAcpText(input, "mcpServer");
|
|
274
|
+
const mcpTool = readAcpText(input, "mcpTool");
|
|
275
|
+
if (!negativeMcp && mcpServer !== undefined && mcpTool !== undefined) {
|
|
276
|
+
data["mcpServer"] = mcpServer;
|
|
277
|
+
data["mcpTool"] = mcpTool;
|
|
278
|
+
}
|
|
211
279
|
}
|
|
212
280
|
if (command) {
|
|
213
281
|
data["command"] = command;
|
|
@@ -241,7 +309,7 @@ export function makeToolCallState(
|
|
|
241
309
|
})
|
|
242
310
|
: undefined;
|
|
243
311
|
const status = normalizeToolCallStatus(input.status, options?.fallbackStatus);
|
|
244
|
-
|
|
312
|
+
const state: AcpToolCallState = {
|
|
245
313
|
toolCallId,
|
|
246
314
|
...(kind ? { kind } : {}),
|
|
247
315
|
...(presentation?.summary ? { title: presentation.summary } : {}),
|
|
@@ -251,21 +319,122 @@ export function makeToolCallState(
|
|
|
251
319
|
...(textContent ? { contentText: textContent } : {}),
|
|
252
320
|
data,
|
|
253
321
|
};
|
|
322
|
+
if (title === undefined && presentation?.summary === "Tool") {
|
|
323
|
+
fallbackTitleStates.add(state);
|
|
324
|
+
}
|
|
325
|
+
if (
|
|
326
|
+
input.name === null ||
|
|
327
|
+
input.mcpServer === null ||
|
|
328
|
+
input.mcpTool === null ||
|
|
329
|
+
negativeMcp ||
|
|
330
|
+
explicitPositiveMcp
|
|
331
|
+
) {
|
|
332
|
+
clearedIdentityFields.set(state, {
|
|
333
|
+
...(input.name === null ? { name: null } : {}),
|
|
334
|
+
...(input.mcpServer === null ? { mcpServer: null } : {}),
|
|
335
|
+
...(input.mcpTool === null ? { mcpTool: null } : {}),
|
|
336
|
+
...(negativeMcp ? { negativeMcp: true } : {}),
|
|
337
|
+
...(explicitPositiveMcp ? { positiveMcp: true } : {}),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return state;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function toolCallIdentityChanged(
|
|
344
|
+
previous: {
|
|
345
|
+
readonly name?: unknown;
|
|
346
|
+
readonly kind?: unknown;
|
|
347
|
+
readonly mcpServer?: unknown;
|
|
348
|
+
readonly mcpTool?: unknown;
|
|
349
|
+
},
|
|
350
|
+
next: {
|
|
351
|
+
readonly name?: unknown;
|
|
352
|
+
readonly kind?: unknown;
|
|
353
|
+
readonly mcpServer?: unknown;
|
|
354
|
+
readonly mcpTool?: unknown;
|
|
355
|
+
},
|
|
356
|
+
): boolean {
|
|
357
|
+
const prevName = readAcpText(previous, "name");
|
|
358
|
+
const nextName = readAcpText(next, "name");
|
|
359
|
+
const prevKind = normalizeToolKind(previous.kind);
|
|
360
|
+
const nextKind = normalizeToolKind(next.kind);
|
|
361
|
+
const prevServer = readAcpText(previous, "mcpServer");
|
|
362
|
+
const nextServer = readAcpText(next, "mcpServer");
|
|
363
|
+
const prevTool = readAcpText(previous, "mcpTool");
|
|
364
|
+
const nextTool = readAcpText(next, "mcpTool");
|
|
365
|
+
const clearedName = prevName !== undefined && next.name === null;
|
|
366
|
+
const clearedServer = prevServer !== undefined && next.mcpServer === null;
|
|
367
|
+
const clearedTool = prevTool !== undefined && next.mcpTool === null;
|
|
368
|
+
return (
|
|
369
|
+
clearedName ||
|
|
370
|
+
clearedServer ||
|
|
371
|
+
clearedTool ||
|
|
372
|
+
(prevName !== undefined && nextName !== undefined && prevName !== nextName) ||
|
|
373
|
+
(prevKind !== undefined && nextKind !== undefined && prevKind !== nextKind) ||
|
|
374
|
+
(prevServer !== undefined && nextServer !== undefined && prevServer !== nextServer) ||
|
|
375
|
+
(prevTool !== undefined && nextTool !== undefined && prevTool !== nextTool)
|
|
376
|
+
);
|
|
254
377
|
}
|
|
255
378
|
|
|
256
379
|
export function mergeToolCallState(
|
|
257
380
|
previous: AcpToolCallState | undefined,
|
|
258
381
|
next: AcpToolCallState,
|
|
259
382
|
): AcpToolCallState {
|
|
383
|
+
if (
|
|
384
|
+
previous !== undefined &&
|
|
385
|
+
toolCallIdentityChanged(
|
|
386
|
+
{
|
|
387
|
+
name: previous.data["name"],
|
|
388
|
+
kind: previous.kind,
|
|
389
|
+
mcpServer: previous.data["mcpServer"],
|
|
390
|
+
mcpTool: previous.data["mcpTool"],
|
|
391
|
+
},
|
|
392
|
+
readToolCallIdentityFields(next, { kindFromData: true }),
|
|
393
|
+
)
|
|
394
|
+
) {
|
|
395
|
+
const status = next.status ?? previous.status;
|
|
396
|
+
if (status === undefined || status === next.status) {
|
|
397
|
+
return next;
|
|
398
|
+
}
|
|
399
|
+
const replaced: AcpToolCallState = { ...next, status };
|
|
400
|
+
const nextCleared = clearedIdentityFields.get(next);
|
|
401
|
+
if (nextCleared !== undefined) clearedIdentityFields.set(replaced, nextCleared);
|
|
402
|
+
if (fallbackTitleStates.has(next)) fallbackTitleStates.add(replaced);
|
|
403
|
+
return replaced;
|
|
404
|
+
}
|
|
260
405
|
const nextKind = typeof next.data["kind"] === "string" ? next.data["kind"] : undefined;
|
|
261
406
|
const kind = nextKind ?? previous?.kind;
|
|
262
|
-
const
|
|
407
|
+
const nextIsFallbackTitle = fallbackTitleStates.has(next);
|
|
408
|
+
const title = nextIsFallbackTitle
|
|
409
|
+
? (previous?.title ?? next.title)
|
|
410
|
+
: (next.title ?? previous?.title);
|
|
263
411
|
const status = next.status ?? previous?.status;
|
|
264
412
|
const command = next.command ?? previous?.command;
|
|
265
413
|
const detail = next.detail ?? previous?.detail;
|
|
266
414
|
// 这一帧带了 content(哪怕是空的)就以它为准;没带才沿用上一帧的文本。
|
|
267
415
|
const contentText = "content" in next.data ? next.contentText : previous?.contentText;
|
|
268
|
-
|
|
416
|
+
const prevCleared = previous === undefined ? undefined : clearedIdentityFields.get(previous);
|
|
417
|
+
const nextCleared = clearedIdentityFields.get(next);
|
|
418
|
+
const nextPositiveMcp =
|
|
419
|
+
(typeof next.data["mcpServer"] === "string" && typeof next.data["mcpTool"] === "string") ||
|
|
420
|
+
nextCleared?.positiveMcp === true;
|
|
421
|
+
const mergedNegativeMcp =
|
|
422
|
+
nextCleared?.negativeMcp === true || (!nextPositiveMcp && prevCleared?.negativeMcp === true);
|
|
423
|
+
const clearPreviousMcp =
|
|
424
|
+
previous !== undefined &&
|
|
425
|
+
(mergedNegativeMcp ||
|
|
426
|
+
(next.data["name"] !== undefined && next.data["mcpServer"] === undefined));
|
|
427
|
+
const previousData = clearPreviousMcp
|
|
428
|
+
? Object.fromEntries(
|
|
429
|
+
Object.entries(previous.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool"),
|
|
430
|
+
)
|
|
431
|
+
: previous?.data;
|
|
432
|
+
const nextData = mergedNegativeMcp
|
|
433
|
+
? Object.fromEntries(
|
|
434
|
+
Object.entries(next.data).filter(([key]) => key !== "mcpServer" && key !== "mcpTool"),
|
|
435
|
+
)
|
|
436
|
+
: next.data;
|
|
437
|
+
const merged: AcpToolCallState = {
|
|
269
438
|
toolCallId: next.toolCallId,
|
|
270
439
|
...(kind ? { kind } : {}),
|
|
271
440
|
...(title ? { title } : {}),
|
|
@@ -274,10 +443,23 @@ export function mergeToolCallState(
|
|
|
274
443
|
...(detail ? { detail } : {}),
|
|
275
444
|
...(contentText ? { contentText } : {}),
|
|
276
445
|
data: {
|
|
277
|
-
...
|
|
278
|
-
...
|
|
446
|
+
...previousData,
|
|
447
|
+
...nextData,
|
|
279
448
|
},
|
|
280
449
|
};
|
|
450
|
+
if (mergedNegativeMcp) {
|
|
451
|
+
clearedIdentityFields.set(merged, { negativeMcp: true });
|
|
452
|
+
} else if (nextPositiveMcp || prevCleared?.positiveMcp === true) {
|
|
453
|
+
clearedIdentityFields.set(merged, { positiveMcp: true });
|
|
454
|
+
}
|
|
455
|
+
if (
|
|
456
|
+
title === "Tool" &&
|
|
457
|
+
nextIsFallbackTitle &&
|
|
458
|
+
(previous === undefined || fallbackTitleStates.has(previous))
|
|
459
|
+
) {
|
|
460
|
+
fallbackTitleStates.add(merged);
|
|
461
|
+
}
|
|
462
|
+
return merged;
|
|
281
463
|
}
|
|
282
464
|
|
|
283
465
|
const TOOL_CALL_UPDATE_MIN_DETAIL_GROWTH_CHARS = 256;
|
package/dist/source/types.ts
CHANGED
|
@@ -40,6 +40,8 @@ export type AcpFileChange =
|
|
|
40
40
|
| {
|
|
41
41
|
readonly path: string;
|
|
42
42
|
readonly changeKind: "add" | "modify";
|
|
43
|
+
readonly additions?: number;
|
|
44
|
+
readonly deletions?: number;
|
|
43
45
|
readonly content: {
|
|
44
46
|
readonly kind: "replace";
|
|
45
47
|
readonly oldText?: string;
|
|
@@ -48,7 +50,10 @@ export type AcpFileChange =
|
|
|
48
50
|
}
|
|
49
51
|
| {
|
|
50
52
|
readonly path: string;
|
|
51
|
-
readonly
|
|
53
|
+
readonly changeKind?: "add" | "modify";
|
|
54
|
+
readonly additions?: number;
|
|
55
|
+
readonly deletions?: number;
|
|
56
|
+
readonly omitted: "unavailable" | "too-large";
|
|
52
57
|
};
|
|
53
58
|
|
|
54
59
|
export type AcpUsageSnapshot = {
|
|
@@ -122,6 +122,25 @@ export type AcpVendorHooks = {
|
|
|
122
122
|
readonly transformSessionUpdate?: (
|
|
123
123
|
notification: SessionNotification,
|
|
124
124
|
) => SessionNotification | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* 每条 `session/request_permission` 进通用机之前先过这里。
|
|
127
|
+
* 用于按当前会话的 `mcpServers` 把厂商自定义工具名规范成 `mcp__<server>__<tool>`,
|
|
128
|
+
* 避免单下划线前缀在审批与 UI 中撞上内置 `ycodium` 服务器。
|
|
129
|
+
*/
|
|
130
|
+
readonly transformPermissionRequest?: (
|
|
131
|
+
params: unknown,
|
|
132
|
+
context?: { readonly requestId?: string },
|
|
133
|
+
) => unknown;
|
|
134
|
+
/**
|
|
135
|
+
* 当某条权限请求以非批准方式收口(decline / cancel / dispose 清场)时触发,
|
|
136
|
+
* 供厂商规范化器撤销仅由该未过审请求写入的会话记忆。
|
|
137
|
+
*/
|
|
138
|
+
readonly onPermissionRequestSettled?: (input: {
|
|
139
|
+
readonly sessionId: string;
|
|
140
|
+
readonly toolCallId: string;
|
|
141
|
+
readonly accepted: boolean;
|
|
142
|
+
readonly requestId?: string;
|
|
143
|
+
}) => void;
|
|
125
144
|
/** 这一轮可能被 RPC 应答之外的信号收口(Grok)。留空 = 只等应答。 */
|
|
126
145
|
readonly promptSettlement?: AcpPromptSettlementHooks;
|
|
127
146
|
readonly resolveRequestedModelId?: (model: string | null | undefined) => string | undefined;
|
|
@@ -9,12 +9,25 @@ export interface AcpToolCallState {
|
|
|
9
9
|
readonly contentText?: string;
|
|
10
10
|
readonly data: Record<string, unknown>;
|
|
11
11
|
}
|
|
12
|
+
/** 读取用于判定身份变化的字段,保留规范化层用 `null` 显式抹掉的身份/MCP 清除信号与负向 MCP 标记。 */
|
|
13
|
+
export declare function readToolCallIdentityFields(state: AcpToolCallState, options?: {
|
|
14
|
+
readonly kindFromData?: boolean;
|
|
15
|
+
}): {
|
|
16
|
+
readonly name: unknown;
|
|
17
|
+
readonly kind: unknown;
|
|
18
|
+
readonly mcpServer: unknown;
|
|
19
|
+
readonly mcpTool: unknown;
|
|
20
|
+
readonly negativeMcp: boolean;
|
|
21
|
+
};
|
|
12
22
|
/** 超长文本只留末尾 `limit` 个字符并在前面标出被截断。 */
|
|
13
23
|
export declare function boundTailText(text: string, limit?: number): string;
|
|
14
24
|
export declare function makeToolCallState(input: {
|
|
15
25
|
readonly toolCallId: unknown;
|
|
16
26
|
/** ACP 扩展字段,常只有首条 tool_call 带;落进 `data` 由 `mergeToolCallState` 沿用,后到的覆盖旧的。 */
|
|
17
27
|
readonly name?: unknown;
|
|
28
|
+
/** 由 adapter 在归一化前缀前确立的 MCP server 与工具名,防下游按较小配置表重新拆错。 */
|
|
29
|
+
readonly mcpServer?: unknown;
|
|
30
|
+
readonly mcpTool?: unknown;
|
|
18
31
|
readonly title?: string | null | undefined;
|
|
19
32
|
readonly kind?: unknown;
|
|
20
33
|
readonly status?: unknown;
|
|
@@ -22,9 +35,23 @@ export declare function makeToolCallState(input: {
|
|
|
22
35
|
readonly rawOutput?: unknown;
|
|
23
36
|
readonly content?: unknown;
|
|
24
37
|
readonly locations?: unknown;
|
|
38
|
+
readonly _meta?: unknown;
|
|
39
|
+
readonly parentMeta?: unknown;
|
|
25
40
|
}, options?: {
|
|
26
41
|
readonly fallbackStatus?: "pending" | "inProgress" | "completed" | "failed";
|
|
42
|
+
readonly inheritedNegativeMcp?: boolean;
|
|
27
43
|
}): AcpToolCallState | undefined;
|
|
44
|
+
export declare function toolCallIdentityChanged(previous: {
|
|
45
|
+
readonly name?: unknown;
|
|
46
|
+
readonly kind?: unknown;
|
|
47
|
+
readonly mcpServer?: unknown;
|
|
48
|
+
readonly mcpTool?: unknown;
|
|
49
|
+
}, next: {
|
|
50
|
+
readonly name?: unknown;
|
|
51
|
+
readonly kind?: unknown;
|
|
52
|
+
readonly mcpServer?: unknown;
|
|
53
|
+
readonly mcpTool?: unknown;
|
|
54
|
+
}): boolean;
|
|
28
55
|
export declare function mergeToolCallState(previous: AcpToolCallState | undefined, next: AcpToolCallState): AcpToolCallState;
|
|
29
56
|
export interface AcpToolCallEmitDecisionInput {
|
|
30
57
|
readonly previous: AcpToolCallState | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-call-state.d.ts","sourceRoot":"","sources":["source/tool-call-state.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,WAAW,GAAG,QAAQ,CAAC;IACpE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAsED,qCAAqC;AACrC,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAA8B,GAAG,MAAM,CAMvF;AA8ED,wBAAgB,i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