@infituit/opencode-acp 2.0.0-alpha.6 → 2.0.0-alpha.8
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/commands/context.d.ts.map +1 -1
- package/dist/compress/pipeline.d.ts +2 -0
- package/dist/compress/pipeline.d.ts.map +1 -1
- package/dist/compress/protected-content.d.ts.map +1 -1
- package/dist/compress/range.d.ts.map +1 -1
- package/dist/compress/smart-plan.d.ts.map +1 -1
- package/dist/compress/status.d.ts.map +1 -1
- package/dist/index.js +212 -96
- package/dist/index.js.map +1 -1
- package/dist/message-ids.d.ts.map +1 -1
- package/dist/messages/inject/inject.d.ts.map +1 -1
- package/dist/messages/inject/utils.d.ts +5 -0
- package/dist/messages/inject/utils.d.ts.map +1 -1
- package/dist/messages/prune.d.ts.map +1 -1
- package/dist/messages/query.d.ts +3 -0
- package/dist/messages/query.d.ts.map +1 -1
- package/dist/state/message-types.d.ts +4 -0
- package/dist/state/message-types.d.ts.map +1 -1
- package/dist/state/model-limits.d.ts +6 -11
- package/dist/state/model-limits.d.ts.map +1 -1
- package/dist/state/rebuild.d.ts +3 -3
- package/dist/state/rebuild.d.ts.map +1 -1
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/types.d.ts +2 -0
- package/dist/state/types.d.ts.map +1 -1
- package/dist/ui/notification.d.ts.map +1 -1
- package/dist/v2/messages.d.ts +3 -3
- package/dist/v2/messages.d.ts.map +1 -1
- package/dist/v2/plugin.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2243,6 +2243,15 @@ function isSyntheticMessage(message) {
|
|
|
2243
2243
|
const id = message?.info?.id;
|
|
2244
2244
|
return typeof id === "string" && (id.startsWith("msg_acp_summary_") || id.startsWith("msg_acp_text_") || id.startsWith("msg_acp_recap_"));
|
|
2245
2245
|
}
|
|
2246
|
+
function isHostInput(message) {
|
|
2247
|
+
return isMessageWithInfo(message) && message.info.role === "user" && message.info.hostInput !== void 0;
|
|
2248
|
+
}
|
|
2249
|
+
function isUserPrompt(message) {
|
|
2250
|
+
return isMessageWithInfo(message) && message.info.role === "user" && !isHostInput(message) && !isIgnoredUserMessage(message) && !isSyntheticMessage(message);
|
|
2251
|
+
}
|
|
2252
|
+
function getRequestInput(messages) {
|
|
2253
|
+
return getLastUserMessage(messages) ?? messages.findLast(isHostInput) ?? null;
|
|
2254
|
+
}
|
|
2246
2255
|
var getLastUserMessage = (messages, startIndex) => {
|
|
2247
2256
|
const start = startIndex ?? messages.length - 1;
|
|
2248
2257
|
for (let i = start; i >= 0; i--) {
|
|
@@ -2250,7 +2259,7 @@ var getLastUserMessage = (messages, startIndex) => {
|
|
|
2250
2259
|
if (!isMessageWithInfo(msg)) {
|
|
2251
2260
|
continue;
|
|
2252
2261
|
}
|
|
2253
|
-
if (
|
|
2262
|
+
if (isUserPrompt(msg)) {
|
|
2254
2263
|
return msg;
|
|
2255
2264
|
}
|
|
2256
2265
|
}
|
|
@@ -2398,7 +2407,7 @@ function estimateSystemPromptTokens(messages) {
|
|
|
2398
2407
|
if (firstInput === void 0) return 0;
|
|
2399
2408
|
let firstUserText = "";
|
|
2400
2409
|
for (const msg of messages) {
|
|
2401
|
-
if (msg
|
|
2410
|
+
if (!isUserPrompt(msg)) continue;
|
|
2402
2411
|
const parts = Array.isArray(msg.parts) ? msg.parts : [];
|
|
2403
2412
|
for (const part of parts) {
|
|
2404
2413
|
if (part.type === "text" && typeof part.text === "string") {
|
|
@@ -2410,7 +2419,7 @@ function estimateSystemPromptTokens(messages) {
|
|
|
2410
2419
|
return Math.max(0, firstInput - countTokens(firstUserText));
|
|
2411
2420
|
}
|
|
2412
2421
|
function getCurrentParams(state, messages, logger) {
|
|
2413
|
-
const userMsg =
|
|
2422
|
+
const userMsg = getRequestInput(messages);
|
|
2414
2423
|
if (!userMsg) {
|
|
2415
2424
|
logger.debug("No user message found when determining current params");
|
|
2416
2425
|
return {
|
|
@@ -2751,7 +2760,7 @@ function collectTurnNudgeAnchors(messages) {
|
|
|
2751
2760
|
break;
|
|
2752
2761
|
}
|
|
2753
2762
|
if (message.info.role === "user") {
|
|
2754
|
-
if (
|
|
2763
|
+
if (isUserPrompt(message)) {
|
|
2755
2764
|
pendingUserMessageId = message.info.id;
|
|
2756
2765
|
}
|
|
2757
2766
|
continue;
|
|
@@ -3174,7 +3183,7 @@ function assignMessageRefs(state, messages) {
|
|
|
3174
3183
|
if (isIgnoredUserMessage(message)) {
|
|
3175
3184
|
continue;
|
|
3176
3185
|
}
|
|
3177
|
-
if (state.isSubAgent && !skippedSubAgentPrompt && message
|
|
3186
|
+
if (state.isSubAgent && !skippedSubAgentPrompt && isUserPrompt(message)) {
|
|
3178
3187
|
skippedSubAgentPrompt = true;
|
|
3179
3188
|
continue;
|
|
3180
3189
|
}
|
|
@@ -3208,6 +3217,7 @@ function repairNonMonotonicMessageRefs(state, messages) {
|
|
|
3208
3217
|
let previous = 0;
|
|
3209
3218
|
let corrupted = false;
|
|
3210
3219
|
for (const message of eligible) {
|
|
3220
|
+
if (isHostInput(message)) continue;
|
|
3211
3221
|
const ref = state.messageIds.byRawId.get(message.info.id);
|
|
3212
3222
|
const parsed = ref ? parseMessageRef(ref) : null;
|
|
3213
3223
|
if (parsed === null) continue;
|
|
@@ -3576,9 +3586,11 @@ function createModelLimitCatalog() {
|
|
|
3576
3586
|
async hydrateFromClient(client) {
|
|
3577
3587
|
try {
|
|
3578
3588
|
const v2Client = client;
|
|
3579
|
-
const
|
|
3589
|
+
const response = await v2Client.model.list();
|
|
3590
|
+
if (!Array.isArray(response.data)) return 0;
|
|
3580
3591
|
let recorded = 0;
|
|
3581
|
-
for (const value of
|
|
3592
|
+
for (const value of response.data) {
|
|
3593
|
+
if (!value || typeof value !== "object") continue;
|
|
3582
3594
|
const model = value;
|
|
3583
3595
|
if (typeof model.providerID !== "string" || typeof model.id !== "string" || typeof model.limit?.context !== "number" || model.limit.context <= 0) {
|
|
3584
3596
|
continue;
|
|
@@ -3624,12 +3636,13 @@ function convertToolPart(part) {
|
|
|
3624
3636
|
state: {
|
|
3625
3637
|
status,
|
|
3626
3638
|
input: state?.input ?? part.input,
|
|
3627
|
-
output: textFromContent(output)
|
|
3639
|
+
output: textFromContent(output),
|
|
3640
|
+
...state?.metadata?.acpHostInputRefs === true ? { metadata: { acpHostInputRefs: true } } : {}
|
|
3628
3641
|
}
|
|
3629
3642
|
};
|
|
3630
3643
|
}
|
|
3631
3644
|
function convertParts(message) {
|
|
3632
|
-
if (message.type === "user") {
|
|
3645
|
+
if (message.type === "user" || message.type === "synthetic") {
|
|
3633
3646
|
const parts2 = [];
|
|
3634
3647
|
if (typeof message.text === "string") {
|
|
3635
3648
|
parts2.push({ type: "text", text: message.text });
|
|
@@ -3655,19 +3668,35 @@ function convertParts(message) {
|
|
|
3655
3668
|
}
|
|
3656
3669
|
return parts;
|
|
3657
3670
|
}
|
|
3658
|
-
function
|
|
3671
|
+
function isAcpNotification(message) {
|
|
3672
|
+
return message.metadata?.source === "opencode-acp" || message.metadata?.source === void 0 && (message.description === "ACP" || message.description === "ACP update ready" || message.description?.startsWith("ACP:") === true);
|
|
3673
|
+
}
|
|
3674
|
+
function fromV2SessionMessages(input, sessionID, requestMessages) {
|
|
3659
3675
|
if (!Array.isArray(input)) return [];
|
|
3676
|
+
const requestInputs = /* @__PURE__ */ new Map();
|
|
3677
|
+
for (const value of requestMessages ?? []) {
|
|
3678
|
+
if (!value || typeof value !== "object") continue;
|
|
3679
|
+
const message = value;
|
|
3680
|
+
if (message.role === "user" && typeof message.id === "string") {
|
|
3681
|
+
requestInputs.set(message.id, message);
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3660
3684
|
const result = [];
|
|
3661
3685
|
for (const value of input) {
|
|
3662
3686
|
if (!value || typeof value !== "object") continue;
|
|
3663
3687
|
const message = value;
|
|
3664
|
-
|
|
3688
|
+
const hostInput = message.type === "synthetic";
|
|
3689
|
+
if (!hostInput && message.type !== "user" && message.type !== "assistant") continue;
|
|
3665
3690
|
if (typeof message.id !== "string") continue;
|
|
3666
|
-
const
|
|
3691
|
+
const requestInput = requestInputs.get(message.id);
|
|
3692
|
+
if (hostInput && (isAcpNotification(message) || requestMessages && !requestInput))
|
|
3693
|
+
continue;
|
|
3694
|
+
const role = hostInput ? "user" : message.type;
|
|
3667
3695
|
const info = {
|
|
3668
3696
|
id: message.id,
|
|
3669
3697
|
sessionID,
|
|
3670
3698
|
role,
|
|
3699
|
+
...hostInput ? { hostInput: { metadata: requestInput?.metadata ?? message.metadata } } : {},
|
|
3671
3700
|
time: { created: createdAt(message) },
|
|
3672
3701
|
agent: message.agent ?? "code",
|
|
3673
3702
|
model: {
|
|
@@ -3682,19 +3711,25 @@ function fromV2SessionMessages(input, sessionID) {
|
|
|
3682
3711
|
cost: 0,
|
|
3683
3712
|
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
3684
3713
|
};
|
|
3714
|
+
const projectedContent = hostInput ? requestInput?.content : void 0;
|
|
3715
|
+
const parts = typeof projectedContent === "string" ? [{ type: "text", text: projectedContent }] : Array.isArray(projectedContent) ? projectedContent.map((part) => structuredClone(part)) : convertParts(message);
|
|
3685
3716
|
result.push({
|
|
3686
3717
|
info,
|
|
3687
|
-
parts
|
|
3718
|
+
parts
|
|
3688
3719
|
});
|
|
3689
3720
|
}
|
|
3690
3721
|
return result;
|
|
3691
3722
|
}
|
|
3692
|
-
async function fetchV2SessionMessages(client, sessionID) {
|
|
3723
|
+
async function fetchV2SessionMessages(client, sessionID, requestMessages) {
|
|
3693
3724
|
const runtime = client;
|
|
3694
3725
|
if (typeof runtime.session?.context !== "function") {
|
|
3695
3726
|
return [];
|
|
3696
3727
|
}
|
|
3697
|
-
return fromV2SessionMessages(
|
|
3728
|
+
return fromV2SessionMessages(
|
|
3729
|
+
await runtime.session.context({ sessionID }),
|
|
3730
|
+
sessionID,
|
|
3731
|
+
requestMessages
|
|
3732
|
+
);
|
|
3698
3733
|
}
|
|
3699
3734
|
function toolIdentity(part) {
|
|
3700
3735
|
return {
|
|
@@ -3763,7 +3798,11 @@ function toV2RequestMessages(messages) {
|
|
|
3763
3798
|
continue;
|
|
3764
3799
|
}
|
|
3765
3800
|
if (content.length > 0) {
|
|
3766
|
-
result.push({
|
|
3801
|
+
result.push({
|
|
3802
|
+
role: message.info.role,
|
|
3803
|
+
content,
|
|
3804
|
+
...message.info.role === "user" && message.info.hostInput ? { id: message.info.id, metadata: message.info.hostInput.metadata } : {}
|
|
3805
|
+
});
|
|
3767
3806
|
}
|
|
3768
3807
|
}
|
|
3769
3808
|
return result;
|
|
@@ -4337,8 +4376,7 @@ function appendProtectedUserMessages(summary, selection, searchContext, state, e
|
|
|
4337
4376
|
}
|
|
4338
4377
|
const message = searchContext.rawMessagesById.get(messageId);
|
|
4339
4378
|
if (!message) continue;
|
|
4340
|
-
if (message
|
|
4341
|
-
if (isIgnoredUserMessage(message)) continue;
|
|
4379
|
+
if (!isUserPrompt(message)) continue;
|
|
4342
4380
|
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
4343
4381
|
for (const part of parts) {
|
|
4344
4382
|
if (part.type === "text" && typeof part.text === "string" && part.text.trim()) {
|
|
@@ -4365,8 +4403,7 @@ function appendProtectedPromptInfo(summary, selection, searchContext, state, ena
|
|
|
4365
4403
|
}
|
|
4366
4404
|
const message = searchContext.rawMessagesById.get(messageId);
|
|
4367
4405
|
if (!message) continue;
|
|
4368
|
-
if (message
|
|
4369
|
-
if (isIgnoredUserMessage(message)) continue;
|
|
4406
|
+
if (!isUserPrompt(message)) continue;
|
|
4370
4407
|
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
4371
4408
|
for (const part of parts) {
|
|
4372
4409
|
if (part.type !== "text" || typeof part.text !== "string") continue;
|
|
@@ -4467,9 +4504,7 @@ function filterProtectedToolMessages(selection, searchContext, protectedTools, p
|
|
|
4467
4504
|
if (removedMessageIds.size === 0) {
|
|
4468
4505
|
return selection;
|
|
4469
4506
|
}
|
|
4470
|
-
const filteredMessageIds = selection.messageIds.filter(
|
|
4471
|
-
(id) => !removedMessageIds.has(id)
|
|
4472
|
-
);
|
|
4507
|
+
const filteredMessageIds = selection.messageIds.filter((id) => !removedMessageIds.has(id));
|
|
4473
4508
|
const filteredMessageTokenById = /* @__PURE__ */ new Map();
|
|
4474
4509
|
for (const id of filteredMessageIds) {
|
|
4475
4510
|
const tokens = selection.messageTokenById.get(id);
|
|
@@ -4493,13 +4528,10 @@ function filterLastUserMessage(selection, searchContext, state, compress) {
|
|
|
4493
4528
|
const msg = searchContext.rawMessages[i];
|
|
4494
4529
|
const id = msg?.info?.id;
|
|
4495
4530
|
if (!id || typeof id !== "string") continue;
|
|
4496
|
-
if (
|
|
4497
|
-
if (isIgnoredUserMessage(msg)) continue;
|
|
4531
|
+
if (!isUserPrompt(msg)) continue;
|
|
4498
4532
|
if (state.prune.messages.byMessageId.has(id)) continue;
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
break;
|
|
4502
|
-
}
|
|
4533
|
+
lastUserMessageId = id;
|
|
4534
|
+
break;
|
|
4503
4535
|
}
|
|
4504
4536
|
if (!lastUserMessageId || !selection.messageIds.includes(lastUserMessageId)) {
|
|
4505
4537
|
return selection;
|
|
@@ -4784,7 +4816,8 @@ function collectCompressInvocations(messages) {
|
|
|
4784
4816
|
invocations.push({
|
|
4785
4817
|
messageId: message.info.id,
|
|
4786
4818
|
callId: typeof part.callID === "string" ? part.callID : void 0,
|
|
4787
|
-
input
|
|
4819
|
+
input,
|
|
4820
|
+
hostInputRefs: part.state?.metadata?.acpHostInputRefs === true
|
|
4788
4821
|
});
|
|
4789
4822
|
}
|
|
4790
4823
|
}
|
|
@@ -4869,8 +4902,25 @@ function translateIds(ids, mapped) {
|
|
|
4869
4902
|
}
|
|
4870
4903
|
function restoreForkCompressionState(state, forkMessages, parent, parentMessages, logger) {
|
|
4871
4904
|
if (!parent.prune.messages || !parent.messageIds) return 0;
|
|
4872
|
-
|
|
4873
|
-
|
|
4905
|
+
if (state.messageIds.byRawId.size === 0 && parentMessages.some(
|
|
4906
|
+
(message) => isHostInput(message) && parent.messageIds?.byRawId[message.info.id]
|
|
4907
|
+
)) {
|
|
4908
|
+
return 0;
|
|
4909
|
+
}
|
|
4910
|
+
const forkState = {
|
|
4911
|
+
...state,
|
|
4912
|
+
messageIds: {
|
|
4913
|
+
...state.messageIds,
|
|
4914
|
+
byRawId: new Map(state.messageIds.byRawId),
|
|
4915
|
+
byRef: new Map(state.messageIds.byRef)
|
|
4916
|
+
}
|
|
4917
|
+
};
|
|
4918
|
+
assignMessageRefs(
|
|
4919
|
+
forkState,
|
|
4920
|
+
forkMessages.filter((message) => !isHostInput(message))
|
|
4921
|
+
);
|
|
4922
|
+
assignMessageRefs(forkState, forkMessages);
|
|
4923
|
+
const mapped = mapForkIds(forkState, parent, parentMessages, forkMessages);
|
|
4874
4924
|
if (!mapped) return 0;
|
|
4875
4925
|
const parentBlocks = Object.values(parent.prune.messages.blocksById);
|
|
4876
4926
|
const translatedBlocks = /* @__PURE__ */ new Map();
|
|
@@ -4933,6 +4983,7 @@ function restoreForkCompressionState(state, forkMessages, parent, parentMessages
|
|
|
4933
4983
|
messagesState.nextRunId = parent.prune.messages.nextRunId;
|
|
4934
4984
|
messagesState.membershipsVerified = true;
|
|
4935
4985
|
state.prune.messages = messagesState;
|
|
4986
|
+
state.messageIds = forkState.messageIds;
|
|
4936
4987
|
logger.info("fork: restored compression state from parent", {
|
|
4937
4988
|
blocks: copiedBlockIds.size,
|
|
4938
4989
|
activeBlocks: messagesState.activeBlockIds.size
|
|
@@ -5051,17 +5102,38 @@ function rebuildMessageInvocation(state, input, searchContext, invocation, gcCon
|
|
|
5051
5102
|
return created;
|
|
5052
5103
|
}
|
|
5053
5104
|
function rebuildCompressionState(state, messages, config, logger) {
|
|
5054
|
-
assignMessageRefs(state, messages);
|
|
5055
5105
|
const invocations = collectCompressInvocations(messages);
|
|
5056
5106
|
if (invocations.length === 0) {
|
|
5107
|
+
assignMessageRefs(state, messages);
|
|
5057
5108
|
return 0;
|
|
5058
5109
|
}
|
|
5110
|
+
const existingRefs = new Map(state.messageIds.byRef);
|
|
5111
|
+
const hasHostInputs = messages.some(isHostInput);
|
|
5112
|
+
const legacyMessages = messages.filter((message) => !isHostInput(message));
|
|
5113
|
+
assignMessageRefs(state, legacyMessages);
|
|
5114
|
+
assignMessageRefs(state, messages);
|
|
5059
5115
|
const protectedTools = config.compress.protectedTools;
|
|
5060
5116
|
const protectedFilePatterns = config.protectedFilePatterns;
|
|
5061
5117
|
const gcConfig = config.gc;
|
|
5062
5118
|
let rebuilt = 0;
|
|
5063
5119
|
for (const invocation of invocations) {
|
|
5064
|
-
|
|
5120
|
+
if (invocation.hostInputRefs && hasHostInputs) {
|
|
5121
|
+
const content = invocation.input.content;
|
|
5122
|
+
const hasReliableRefs = existingRefs.size > 0 && Array.isArray(content) && content.every((entry) => {
|
|
5123
|
+
const refs = isRangeInput(invocation.input) ? [entry?.startId, entry?.endId] : [entry?.messageId];
|
|
5124
|
+
return refs.every(
|
|
5125
|
+
(ref) => typeof ref === "string" && (parseMessageRef(ref) === null || existingRefs.has(ref.trim().toLowerCase()))
|
|
5126
|
+
);
|
|
5127
|
+
});
|
|
5128
|
+
if (!hasReliableRefs) {
|
|
5129
|
+
logger.warn("rebuild: host-input aliases unavailable, stopping history replay");
|
|
5130
|
+
break;
|
|
5131
|
+
}
|
|
5132
|
+
}
|
|
5133
|
+
const searchContext = buildSearchContext(
|
|
5134
|
+
state,
|
|
5135
|
+
invocation.hostInputRefs ? messages : legacyMessages
|
|
5136
|
+
);
|
|
5065
5137
|
try {
|
|
5066
5138
|
if (isRangeInput(invocation.input)) {
|
|
5067
5139
|
rebuilt += rebuildRangeInvocation(
|
|
@@ -5264,6 +5336,7 @@ function createSessionState() {
|
|
|
5264
5336
|
}
|
|
5265
5337
|
function resetSessionState(state) {
|
|
5266
5338
|
state.sessionId = null;
|
|
5339
|
+
state.visibleHostInputIds = void 0;
|
|
5267
5340
|
state.isSubAgent = false;
|
|
5268
5341
|
state.compressPermission = void 0;
|
|
5269
5342
|
state.prune = {
|
|
@@ -5515,7 +5588,7 @@ function cacheSystemPromptTokens(state, messages) {
|
|
|
5515
5588
|
}
|
|
5516
5589
|
let firstUserText = "";
|
|
5517
5590
|
for (const msg of messages) {
|
|
5518
|
-
if (
|
|
5591
|
+
if (!isUserPrompt(msg)) {
|
|
5519
5592
|
continue;
|
|
5520
5593
|
}
|
|
5521
5594
|
const parts = Array.isArray(msg.parts) ? msg.parts : [];
|
|
@@ -5738,7 +5811,8 @@ ${message}`);
|
|
|
5738
5811
|
await client.session.synthetic({
|
|
5739
5812
|
sessionID: sessionId,
|
|
5740
5813
|
text: toastMessage,
|
|
5741
|
-
description: "ACP: Compress Notification"
|
|
5814
|
+
description: "ACP: Compress Notification",
|
|
5815
|
+
metadata: { source: "opencode-acp" }
|
|
5742
5816
|
});
|
|
5743
5817
|
return true;
|
|
5744
5818
|
}
|
|
@@ -5747,7 +5821,8 @@ async function sendIgnoredMessage(client, sessionID, text, params, logger) {
|
|
|
5747
5821
|
await client.session.synthetic({
|
|
5748
5822
|
sessionID,
|
|
5749
5823
|
text,
|
|
5750
|
-
description: "ACP"
|
|
5824
|
+
description: "ACP",
|
|
5825
|
+
metadata: { source: "opencode-acp" }
|
|
5751
5826
|
});
|
|
5752
5827
|
} catch (error) {
|
|
5753
5828
|
logger.error("Failed to send notification", { error: error.message });
|
|
@@ -6602,9 +6677,14 @@ function restoreCompressionState(state, snapshot) {
|
|
|
6602
6677
|
state.prune.messages = structuredClone(snapshot.messages);
|
|
6603
6678
|
state.stats = { ...snapshot.stats };
|
|
6604
6679
|
}
|
|
6680
|
+
function filterUnseenHostInputs(state, messages) {
|
|
6681
|
+
return messages.filter(
|
|
6682
|
+
(message) => !isHostInput(message) || state.visibleHostInputIds?.has(message.info.id) === true || (state.prune.messages.byMessageId.get(message.info.id)?.activeBlockIds.length ?? 0) > 0
|
|
6683
|
+
);
|
|
6684
|
+
}
|
|
6605
6685
|
async function prepareSession(ctx, toolCtx, title) {
|
|
6606
6686
|
await ctx.assertPermission(toolCtx.sessionID);
|
|
6607
|
-
|
|
6687
|
+
let rawMessages = await fetchSessionMessages(ctx.client, toolCtx.sessionID);
|
|
6608
6688
|
await ensureSessionInitialized(
|
|
6609
6689
|
ctx.client,
|
|
6610
6690
|
ctx.state,
|
|
@@ -6613,6 +6693,7 @@ async function prepareSession(ctx, toolCtx, title) {
|
|
|
6613
6693
|
rawMessages,
|
|
6614
6694
|
ctx.config
|
|
6615
6695
|
);
|
|
6696
|
+
rawMessages = filterUnseenHostInputs(ctx.state, rawMessages);
|
|
6616
6697
|
assignMessageRefs(ctx.state, rawMessages);
|
|
6617
6698
|
return {
|
|
6618
6699
|
rawMessages,
|
|
@@ -7319,7 +7400,7 @@ function countMessagesAfterIndex(messages, index) {
|
|
|
7319
7400
|
return count;
|
|
7320
7401
|
}
|
|
7321
7402
|
function getModelInfo(messages) {
|
|
7322
|
-
const lastUserMessage =
|
|
7403
|
+
const lastUserMessage = getRequestInput(messages);
|
|
7323
7404
|
if (!lastUserMessage) {
|
|
7324
7405
|
return {
|
|
7325
7406
|
providerId: void 0,
|
|
@@ -7540,7 +7621,7 @@ function collectTurnNudgeAnchors2(state, config, messages) {
|
|
|
7540
7621
|
const targetRole = config.compress.nudgeForce === "strong" ? "user" : "assistant";
|
|
7541
7622
|
for (const message of messages) {
|
|
7542
7623
|
if (!state.nudges.turnNudgeAnchors.has(message.info.id)) continue;
|
|
7543
|
-
if (message.info.role === targetRole) {
|
|
7624
|
+
if (targetRole === "user" ? isUserPrompt(message) : message.info.role === targetRole) {
|
|
7544
7625
|
turnNudgeAnchors.add(message.info.id);
|
|
7545
7626
|
}
|
|
7546
7627
|
}
|
|
@@ -7714,7 +7795,6 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
|
|
|
7714
7795
|
if (isSyntheticMessage(msg)) continue;
|
|
7715
7796
|
const ref = state.messageIds.byRawId.get(msg.info.id);
|
|
7716
7797
|
if (!ref) continue;
|
|
7717
|
-
const rn = parseInt(ref.slice(1), 10);
|
|
7718
7798
|
if ((protectedTools.length > 0 || protectedFilePatterns.length > 0) && messageContainsProtectedTool(msg, protectedTools, protectedFilePatterns)) {
|
|
7719
7799
|
const tokens2 = Math.round(countMessageCharacters(msg) / 4);
|
|
7720
7800
|
const tools = /* @__PURE__ */ new Set();
|
|
@@ -7737,7 +7817,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
|
|
|
7737
7817
|
}
|
|
7738
7818
|
}
|
|
7739
7819
|
}
|
|
7740
|
-
protectedMsgInfo.push({ ref,
|
|
7820
|
+
protectedMsgInfo.push({ ref, rawIndex: mi, tokens: tokens2, tools: [...tools] });
|
|
7741
7821
|
continue;
|
|
7742
7822
|
}
|
|
7743
7823
|
const tokens = Math.round(countMessageCharacters(msg) / 4);
|
|
@@ -7751,18 +7831,18 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
|
|
|
7751
7831
|
hasMeaningfulPart = true;
|
|
7752
7832
|
}
|
|
7753
7833
|
}
|
|
7754
|
-
if (
|
|
7834
|
+
if (isUserPrompt(msg)) {
|
|
7755
7835
|
lastUserRefIdx.length = 0;
|
|
7756
7836
|
lastUserRefIdx.push(msgInfo.length);
|
|
7757
7837
|
}
|
|
7758
7838
|
msgInfo.push({
|
|
7759
7839
|
ref,
|
|
7760
|
-
|
|
7840
|
+
rawIndex: mi,
|
|
7761
7841
|
tokens,
|
|
7762
7842
|
effectiveTokens: 0,
|
|
7763
7843
|
meaningful: hasMeaningfulPart,
|
|
7764
7844
|
isTool,
|
|
7765
|
-
isUser: msg
|
|
7845
|
+
isUser: isUserPrompt(msg)
|
|
7766
7846
|
});
|
|
7767
7847
|
}
|
|
7768
7848
|
const lastUserIdx = lastUserRefIdx.length > 0 ? lastUserRefIdx[0] : -1;
|
|
@@ -7772,26 +7852,28 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
|
|
|
7772
7852
|
}
|
|
7773
7853
|
const groups = [];
|
|
7774
7854
|
let cur = null;
|
|
7775
|
-
let
|
|
7855
|
+
let previousIndex = -2;
|
|
7776
7856
|
for (const info of msgInfo) {
|
|
7777
7857
|
if (protectedZoneRefs?.has(info.ref)) {
|
|
7778
7858
|
if (cur) {
|
|
7779
7859
|
groups.push(cur);
|
|
7780
7860
|
cur = null;
|
|
7781
7861
|
}
|
|
7782
|
-
|
|
7862
|
+
previousIndex = info.rawIndex;
|
|
7783
7863
|
continue;
|
|
7784
7864
|
}
|
|
7785
|
-
const hasGap = info.
|
|
7865
|
+
const hasGap = info.rawIndex !== previousIndex + 1;
|
|
7786
7866
|
if (cur && (info.isUser && cur.count >= 3 || hasGap)) {
|
|
7787
7867
|
groups.push(cur);
|
|
7788
7868
|
cur = null;
|
|
7789
7869
|
}
|
|
7790
|
-
|
|
7870
|
+
previousIndex = info.rawIndex;
|
|
7791
7871
|
if (!cur) {
|
|
7792
7872
|
cur = {
|
|
7793
7873
|
startRef: info.ref,
|
|
7794
7874
|
endRef: info.ref,
|
|
7875
|
+
startIndex: info.rawIndex,
|
|
7876
|
+
endIndex: info.rawIndex,
|
|
7795
7877
|
count: 1,
|
|
7796
7878
|
tokens: info.tokens,
|
|
7797
7879
|
effectiveTokens: info.effectiveTokens,
|
|
@@ -7800,6 +7882,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
|
|
|
7800
7882
|
};
|
|
7801
7883
|
} else {
|
|
7802
7884
|
cur.endRef = info.ref;
|
|
7885
|
+
cur.endIndex = info.rawIndex;
|
|
7803
7886
|
cur.count++;
|
|
7804
7887
|
cur.tokens += info.tokens;
|
|
7805
7888
|
cur.effectiveTokens += info.effectiveTokens;
|
|
@@ -7814,24 +7897,27 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
|
|
|
7814
7897
|
if (cur) groups.push(cur);
|
|
7815
7898
|
const protectedGroups = [];
|
|
7816
7899
|
let pcur = null;
|
|
7817
|
-
let
|
|
7900
|
+
let previousProtectedIndex = -2;
|
|
7818
7901
|
for (const info of protectedMsgInfo) {
|
|
7819
|
-
const hasGap = info.
|
|
7902
|
+
const hasGap = info.rawIndex !== previousProtectedIndex + 1;
|
|
7820
7903
|
if (pcur && hasGap) {
|
|
7821
7904
|
protectedGroups.push(pcur);
|
|
7822
7905
|
pcur = null;
|
|
7823
7906
|
}
|
|
7824
|
-
|
|
7907
|
+
previousProtectedIndex = info.rawIndex;
|
|
7825
7908
|
if (!pcur) {
|
|
7826
7909
|
pcur = {
|
|
7827
7910
|
startRef: info.ref,
|
|
7828
7911
|
endRef: info.ref,
|
|
7912
|
+
startIndex: info.rawIndex,
|
|
7913
|
+
endIndex: info.rawIndex,
|
|
7829
7914
|
count: 1,
|
|
7830
7915
|
tokens: info.tokens,
|
|
7831
7916
|
tools: [...info.tools]
|
|
7832
7917
|
};
|
|
7833
7918
|
} else {
|
|
7834
7919
|
pcur.endRef = info.ref;
|
|
7920
|
+
pcur.endIndex = info.rawIndex;
|
|
7835
7921
|
pcur.count++;
|
|
7836
7922
|
pcur.tokens += info.tokens;
|
|
7837
7923
|
for (const t of info.tools) {
|
|
@@ -7892,8 +7978,8 @@ ${lines2.join("\n")}`;
|
|
|
7892
7978
|
entries.push({
|
|
7893
7979
|
startRef: r.startRef,
|
|
7894
7980
|
endRef: r.endRef,
|
|
7895
|
-
|
|
7896
|
-
|
|
7981
|
+
startIndex: r.startIndex,
|
|
7982
|
+
endIndex: r.endIndex,
|
|
7897
7983
|
count: r.count,
|
|
7898
7984
|
tokens: r.tokens,
|
|
7899
7985
|
toolPct: r.toolPct,
|
|
@@ -7910,8 +7996,8 @@ ${lines2.join("\n")}`;
|
|
|
7910
7996
|
entries.push({
|
|
7911
7997
|
startRef: r.startRef,
|
|
7912
7998
|
endRef: r.endRef,
|
|
7913
|
-
|
|
7914
|
-
|
|
7999
|
+
startIndex: r.startIndex,
|
|
8000
|
+
endIndex: r.endIndex,
|
|
7915
8001
|
count: r.count,
|
|
7916
8002
|
tokens: r.tokens,
|
|
7917
8003
|
toolPct: 0,
|
|
@@ -7924,13 +8010,15 @@ ${lines2.join("\n")}`;
|
|
|
7924
8010
|
dangerous: false
|
|
7925
8011
|
});
|
|
7926
8012
|
}
|
|
7927
|
-
entries.sort(
|
|
8013
|
+
entries.sort(
|
|
8014
|
+
(a, b) => (a.startIndex ?? refNum(a.startRef)) - (b.startIndex ?? refNum(b.startRef))
|
|
8015
|
+
);
|
|
7928
8016
|
const merged = [];
|
|
7929
8017
|
for (const entry of entries) {
|
|
7930
8018
|
const last = merged[merged.length - 1];
|
|
7931
|
-
if (last && entry.
|
|
8019
|
+
if (last && last.endIndex !== void 0 && entry.startIndex === last.endIndex + 1 && last.protectedCount > 0 === entry.protectedCount > 0) {
|
|
7932
8020
|
last.endRef = entry.endRef;
|
|
7933
|
-
last.
|
|
8021
|
+
last.endIndex = entry.endIndex;
|
|
7934
8022
|
last.count += entry.count;
|
|
7935
8023
|
last.tokens += entry.tokens;
|
|
7936
8024
|
last.compressibleTokens += entry.compressibleTokens;
|
|
@@ -7978,7 +8066,7 @@ function computeProtectedRefs(messages, state, compress) {
|
|
|
7978
8066
|
tokens += Math.round(JSON.stringify(part).length / 4);
|
|
7979
8067
|
}
|
|
7980
8068
|
}
|
|
7981
|
-
visible.push({ ref, tokens, isUser: msg
|
|
8069
|
+
visible.push({ ref, tokens, isUser: isUserPrompt(msg) });
|
|
7982
8070
|
}
|
|
7983
8071
|
if (preserveN > 0) {
|
|
7984
8072
|
for (const m of visible.slice(-preserveN)) {
|
|
@@ -8003,15 +8091,15 @@ function excludeProtectedRanges(ranges, protectedRefs) {
|
|
|
8003
8091
|
var SMART_PLAN_TTL_MS = 10 * 60 * 1e3;
|
|
8004
8092
|
var armedPlans = /* @__PURE__ */ new Map();
|
|
8005
8093
|
var visibleMessageIdsBySession = /* @__PURE__ */ new Map();
|
|
8006
|
-
function
|
|
8007
|
-
const value = Number.parseInt(ref.slice(1), 10);
|
|
8008
|
-
return Number.isFinite(value) ? value : -1;
|
|
8009
|
-
}
|
|
8010
|
-
function mergeAdjacentSafeRanges(ranges) {
|
|
8094
|
+
function mergeAdjacentSafeRanges(ranges, searchContext, ctx) {
|
|
8011
8095
|
const merged = [];
|
|
8012
8096
|
for (const range of ranges.filter((candidate) => !candidate.dangerous)) {
|
|
8013
8097
|
const previous = merged.at(-1);
|
|
8014
|
-
|
|
8098
|
+
const startId = ctx.state.messageIds.byRef.get(range.startRef);
|
|
8099
|
+
const previousEndId = previous && ctx.state.messageIds.byRef.get(previous.endRef);
|
|
8100
|
+
const startIndex = startId && searchContext.rawIndexById.get(startId);
|
|
8101
|
+
const previousEndIndex = previousEndId && searchContext.rawIndexById.get(previousEndId);
|
|
8102
|
+
if (previous && typeof startIndex === "number" && typeof previousEndIndex === "number" && startIndex === previousEndIndex + 1) {
|
|
8015
8103
|
const previousEffective = previous.effectiveTokens ?? previous.tokens;
|
|
8016
8104
|
previous.endRef = range.endRef;
|
|
8017
8105
|
previous.count += range.count;
|
|
@@ -8067,7 +8155,7 @@ function filteredSelection(startId, endId, searchContext, ctx) {
|
|
|
8067
8155
|
}
|
|
8068
8156
|
function armBestSmartPlan(sessionID, ranges, searchContext, ctx, visibleMessageIds, now = Date.now(), targetChars = ctx.config.compress.minCompressRange) {
|
|
8069
8157
|
const candidates = [];
|
|
8070
|
-
for (const range of mergeAdjacentSafeRanges(ranges)) {
|
|
8158
|
+
for (const range of mergeAdjacentSafeRanges(ranges, searchContext, ctx)) {
|
|
8071
8159
|
const selection = filteredSelection(range.startRef, range.endRef, searchContext, ctx);
|
|
8072
8160
|
if (!selection || selection.messageIds.length === 0) continue;
|
|
8073
8161
|
if (visibleMessageIds && !selection.messageIds.every((id) => visibleMessageIds.has(id)))
|
|
@@ -8454,6 +8542,7 @@ function createCompressRangeTool(factoryCtx) {
|
|
|
8454
8542
|
\u26A0\uFE0F acknowledgeRisk was ignored: no quality gate rejection was pending, so quality checks ran normally. Only pass it when retrying immediately after a quality gate rejection.
|
|
8455
8543
|
` : "";
|
|
8456
8544
|
return {
|
|
8545
|
+
metadata: { acpHostInputRefs: true },
|
|
8457
8546
|
content: `Compressed ${totalCompressedMessages} messages into ${COMPRESSED_BLOCK_HEADER}.${skippedNote}${ackNote}
|
|
8458
8547
|
IMPORTANT: This was an automatic context compression. You MUST continue your previous task exactly where you left off. Do NOT ask the user what to do next.
|
|
8459
8548
|
\u{1F4A1} Tip: Use acp_search_context('keyword') to find compressed content when you need it later.`
|
|
@@ -8518,7 +8607,7 @@ var filterCompressedRanges = (state, messages) => {
|
|
|
8518
8607
|
}
|
|
8519
8608
|
return false;
|
|
8520
8609
|
});
|
|
8521
|
-
const firstUserIdx = messages.findIndex(
|
|
8610
|
+
const firstUserIdx = messages.findIndex(isUserPrompt);
|
|
8522
8611
|
if (firstUserIdx >= 0) {
|
|
8523
8612
|
survive[firstUserIdx] = true;
|
|
8524
8613
|
}
|
|
@@ -8528,6 +8617,20 @@ var filterCompressedRanges = (state, messages) => {
|
|
|
8528
8617
|
result.push(messages[i]);
|
|
8529
8618
|
}
|
|
8530
8619
|
}
|
|
8620
|
+
if (!result.some((message) => message.info.role === "user")) {
|
|
8621
|
+
const compressedHostInput = messages.find(
|
|
8622
|
+
(message, index) => !survive[index] && isHostInput(message)
|
|
8623
|
+
);
|
|
8624
|
+
if (compressedHostInput) {
|
|
8625
|
+
result.unshift(
|
|
8626
|
+
createSyntheticUserMessage(
|
|
8627
|
+
compressedHostInput,
|
|
8628
|
+
"Earlier host input has been compressed.",
|
|
8629
|
+
"acp-compressed-host-input"
|
|
8630
|
+
)
|
|
8631
|
+
);
|
|
8632
|
+
}
|
|
8633
|
+
}
|
|
8531
8634
|
messages.length = 0;
|
|
8532
8635
|
messages.push(...result);
|
|
8533
8636
|
};
|
|
@@ -9326,9 +9429,7 @@ var injectCompressNudges = (state, config, logger, messages, prompts, compressio
|
|
|
9326
9429
|
modelId,
|
|
9327
9430
|
messages
|
|
9328
9431
|
);
|
|
9329
|
-
const lastUserIdx = messages.findLastIndex(
|
|
9330
|
-
(m) => m.info.role === "user" && !isIgnoredUserMessage(m)
|
|
9331
|
-
);
|
|
9432
|
+
const lastUserIdx = messages.findLastIndex(isUserPrompt);
|
|
9332
9433
|
const currentTurnStart = lastUserIdx >= 0 ? lastUserIdx + 1 : 0;
|
|
9333
9434
|
const currentTurnHasCompress = messages.slice(currentTurnStart).some((m) => m.info.role === "assistant" && messageHasCompressAttempt(m));
|
|
9334
9435
|
if (currentTurnHasCompress) {
|
|
@@ -9408,7 +9509,7 @@ var injectCompressNudges = (state, config, logger, messages, prompts, compressio
|
|
|
9408
9509
|
anchorsChanged = true;
|
|
9409
9510
|
}
|
|
9410
9511
|
if (overMinLimit) {
|
|
9411
|
-
const isLastMessageUser = lastMessage
|
|
9512
|
+
const isLastMessageUser = lastMessage && isUserPrompt(lastMessage.message);
|
|
9412
9513
|
if (isLastMessageUser && lastAssistantMessage) {
|
|
9413
9514
|
const previousSize = state.nudges.turnNudgeAnchors.size;
|
|
9414
9515
|
state.nudges.turnNudgeAnchors.add(lastMessage.message.info.id);
|
|
@@ -11204,7 +11305,10 @@ function createAcpStatusToolV2(factoryCtx) {
|
|
|
11204
11305
|
}
|
|
11205
11306
|
let rawMessages = [];
|
|
11206
11307
|
try {
|
|
11207
|
-
rawMessages =
|
|
11308
|
+
rawMessages = filterUnseenHostInputs(
|
|
11309
|
+
ctx.state,
|
|
11310
|
+
await fetchSessionMessages(ctx.client, toolCtx.sessionID)
|
|
11311
|
+
);
|
|
11208
11312
|
} catch {
|
|
11209
11313
|
if (scope === "uncompressed") return { content: "(unable to fetch messages)" };
|
|
11210
11314
|
}
|
|
@@ -11413,7 +11517,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
|
11413
11517
|
import { join as join5 } from "path";
|
|
11414
11518
|
import { existsSync as existsSync5 } from "fs";
|
|
11415
11519
|
import { homedir as homedir3 } from "os";
|
|
11416
|
-
var LOG_VERSION = true ? "2.0.0-alpha.
|
|
11520
|
+
var LOG_VERSION = true ? "2.0.0-alpha.8" : "dev";
|
|
11417
11521
|
var LEVEL_RANK = {
|
|
11418
11522
|
debug: 10,
|
|
11419
11523
|
info: 20,
|
|
@@ -13211,11 +13315,11 @@ function runBatchCleanup(state, config, logger, messages, prePruneTokens) {
|
|
|
13211
13315
|
// src/v2/hooks/messages.ts
|
|
13212
13316
|
var INTERNAL_AGENT_NAMES = /* @__PURE__ */ new Set(["title", "summary", "compaction"]);
|
|
13213
13317
|
function isInternalAgentRequest(messages) {
|
|
13214
|
-
const
|
|
13215
|
-
if (!
|
|
13318
|
+
const requestInput = getRequestInput(messages);
|
|
13319
|
+
if (!requestInput) {
|
|
13216
13320
|
return false;
|
|
13217
13321
|
}
|
|
13218
|
-
const agent =
|
|
13322
|
+
const agent = requestInput.info.agent;
|
|
13219
13323
|
return typeof agent === "string" && INTERNAL_AGENT_NAMES.has(agent);
|
|
13220
13324
|
}
|
|
13221
13325
|
function createChatMessageTransformHandler(client, registry4, logger, config, prompts, hostPermissions) {
|
|
@@ -13238,19 +13342,19 @@ function createChatMessageTransformHandler(client, registry4, logger, config, pr
|
|
|
13238
13342
|
return;
|
|
13239
13343
|
}
|
|
13240
13344
|
checkpoint("resolveSession");
|
|
13241
|
-
const
|
|
13345
|
+
const requestInput = getRequestInput(messages);
|
|
13242
13346
|
let state;
|
|
13243
|
-
if (!
|
|
13347
|
+
if (!requestInput) {
|
|
13244
13348
|
state = createSessionState();
|
|
13245
13349
|
} else {
|
|
13246
13350
|
state = await registry4.getOrCreate(
|
|
13247
13351
|
client,
|
|
13248
|
-
|
|
13352
|
+
requestInput.info.sessionID,
|
|
13249
13353
|
messages,
|
|
13250
13354
|
config
|
|
13251
13355
|
);
|
|
13252
13356
|
checkpoint("resolveModel");
|
|
13253
|
-
const requestModel =
|
|
13357
|
+
const requestModel = requestInput.info.model;
|
|
13254
13358
|
let requestModelLimit = registry4.resolveModelLimit(
|
|
13255
13359
|
requestModel?.providerID,
|
|
13256
13360
|
requestModel?.modelID
|
|
@@ -13317,7 +13421,7 @@ function createChatMessageTransformHandler(client, registry4, logger, config, pr
|
|
|
13317
13421
|
checkpoint("stripHallucinations");
|
|
13318
13422
|
stripHallucinations(output.messages);
|
|
13319
13423
|
checkpoint("dropReasoning");
|
|
13320
|
-
const dropReasoningModel =
|
|
13424
|
+
const dropReasoningModel = requestInput?.info?.model;
|
|
13321
13425
|
const reasoningConfig = applyCompressOverrides(
|
|
13322
13426
|
config,
|
|
13323
13427
|
dropReasoningModel?.providerID ?? state.modelProviderID,
|
|
@@ -13548,7 +13652,7 @@ function analyzeTokens(state, messages) {
|
|
|
13548
13652
|
const isCompacted = isMessageCompacted(state, msg);
|
|
13549
13653
|
const pruneEntry = state.prune.messages.byMessageId.get(msg.info.id);
|
|
13550
13654
|
const isMessagePruned = !!pruneEntry && pruneEntry.activeBlockIds.length > 0;
|
|
13551
|
-
const
|
|
13655
|
+
const isHumanPrompt = isUserPrompt(msg);
|
|
13552
13656
|
for (const part of parts) {
|
|
13553
13657
|
if (part.type === "tool") {
|
|
13554
13658
|
const toolPart = part;
|
|
@@ -13571,7 +13675,7 @@ function analyzeTokens(state, messages) {
|
|
|
13571
13675
|
toolOutputParts.push(outputStr);
|
|
13572
13676
|
}
|
|
13573
13677
|
}
|
|
13574
|
-
} else if (part.type === "text" &&
|
|
13678
|
+
} else if (part.type === "text" && isHumanPrompt && !isCompacted) {
|
|
13575
13679
|
const textPart = part;
|
|
13576
13680
|
const text = textPart.text || "";
|
|
13577
13681
|
userTextParts.push(text);
|
|
@@ -13580,7 +13684,7 @@ function analyzeTokens(state, messages) {
|
|
|
13580
13684
|
}
|
|
13581
13685
|
}
|
|
13582
13686
|
}
|
|
13583
|
-
if (
|
|
13687
|
+
if (isHumanPrompt && !foundFirstUser) {
|
|
13584
13688
|
foundFirstUser = true;
|
|
13585
13689
|
}
|
|
13586
13690
|
}
|
|
@@ -14348,18 +14452,16 @@ async function notifySession(ctx, title, message) {
|
|
|
14348
14452
|
const sessions = Array.isArray(response) ? response : response.data ?? [];
|
|
14349
14453
|
const sessionID = Array.isArray(sessions) && typeof sessions[0]?.id === "string" ? sessions[0].id : void 0;
|
|
14350
14454
|
if (sessionID) {
|
|
14351
|
-
await ctx.session.synthetic({
|
|
14455
|
+
await ctx.session.synthetic({
|
|
14456
|
+
sessionID,
|
|
14457
|
+
text: message,
|
|
14458
|
+
description: title,
|
|
14459
|
+
metadata: { source: "opencode-acp" }
|
|
14460
|
+
});
|
|
14352
14461
|
}
|
|
14353
14462
|
} catch {
|
|
14354
14463
|
}
|
|
14355
14464
|
}
|
|
14356
|
-
function asV2Model(model) {
|
|
14357
|
-
return {
|
|
14358
|
-
id: model.id,
|
|
14359
|
-
providerID: model.providerID,
|
|
14360
|
-
limit: { context: 0 }
|
|
14361
|
-
};
|
|
14362
|
-
}
|
|
14363
14465
|
async function registerTools(ctx, config, registry4, logger, prompts) {
|
|
14364
14466
|
if (config.compress.permission === "deny") return;
|
|
14365
14467
|
const factoryCtx = {
|
|
@@ -14465,14 +14567,14 @@ var AcpV2Plugin = Plugin.define({
|
|
|
14465
14567
|
await diagnoseContext(logger, event.sessionID, async (diagnostic) => {
|
|
14466
14568
|
const timeline = diagnostic?.timeline("context", "fetchSessionMessages");
|
|
14467
14569
|
const checkpoint = (stage) => timeline?.next(stage);
|
|
14468
|
-
const messages = await fetchV2SessionMessages(ctx, event.sessionID);
|
|
14570
|
+
const messages = await fetchV2SessionMessages(ctx, event.sessionID, event.messages);
|
|
14469
14571
|
checkpoint("prepareMessages");
|
|
14470
14572
|
if (diagnostic) diagnostic.counts.inputMessages = messages.length;
|
|
14471
14573
|
if (messages.length === 0) {
|
|
14472
14574
|
diagnostic?.skip("empty_history");
|
|
14473
14575
|
return;
|
|
14474
14576
|
}
|
|
14475
|
-
const lastUser =
|
|
14577
|
+
const lastUser = getRequestInput(messages);
|
|
14476
14578
|
if (lastUser?.info.role === "user") {
|
|
14477
14579
|
lastUser.info.agent = event.agent;
|
|
14478
14580
|
lastUser.info.model = {
|
|
@@ -14488,6 +14590,12 @@ var AcpV2Plugin = Plugin.define({
|
|
|
14488
14590
|
if (diagnostic) diagnostic.counts.outputMessages = output.messages.length;
|
|
14489
14591
|
checkpoint("convertRequestMessages");
|
|
14490
14592
|
event.messages = toV2RequestMessages(output.messages);
|
|
14593
|
+
const state = registry4.get(event.sessionID);
|
|
14594
|
+
if (state) {
|
|
14595
|
+
state.visibleHostInputIds = new Set(
|
|
14596
|
+
output.messages.filter(isHostInput).map((message) => message.info.id)
|
|
14597
|
+
);
|
|
14598
|
+
}
|
|
14491
14599
|
checkpoint("transformSystem");
|
|
14492
14600
|
const systemOutput = {
|
|
14493
14601
|
system: event.system.map((part) => part.text)
|
|
@@ -14495,7 +14603,15 @@ var AcpV2Plugin = Plugin.define({
|
|
|
14495
14603
|
await transformSystem(
|
|
14496
14604
|
{
|
|
14497
14605
|
sessionID: event.sessionID,
|
|
14498
|
-
model:
|
|
14606
|
+
model: {
|
|
14607
|
+
...event.model,
|
|
14608
|
+
limit: {
|
|
14609
|
+
context: registry4.resolveModelLimit(
|
|
14610
|
+
event.model.providerID,
|
|
14611
|
+
event.model.id
|
|
14612
|
+
) ?? 0
|
|
14613
|
+
}
|
|
14614
|
+
}
|
|
14499
14615
|
},
|
|
14500
14616
|
systemOutput
|
|
14501
14617
|
);
|