@khalilgharbaoui/opencode-claude-code-plugin 0.15.3 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +34 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2511,7 +2511,7 @@ function compactConversationHistory(prompt, opts = {}) {
|
|
|
2511
2511
|
return buildCompactionHistory(prompt);
|
|
2512
2512
|
}
|
|
2513
2513
|
const conversationMessages = prompt.filter(
|
|
2514
|
-
(m) => m.role === "user" || m.role === "assistant"
|
|
2514
|
+
(m) => m.role === "user" || m.role === "assistant" || m.role === "tool"
|
|
2515
2515
|
);
|
|
2516
2516
|
if (conversationMessages.length <= 1) {
|
|
2517
2517
|
return null;
|
|
@@ -2519,28 +2519,8 @@ function compactConversationHistory(prompt, opts = {}) {
|
|
|
2519
2519
|
const historyParts = [];
|
|
2520
2520
|
for (let i = 0; i < conversationMessages.length - 1; i++) {
|
|
2521
2521
|
const msg = conversationMessages[i];
|
|
2522
|
-
const role = msg.role === "user" ? "User" : "Assistant";
|
|
2523
|
-
|
|
2524
|
-
if (typeof msg.content === "string") {
|
|
2525
|
-
text = msg.content;
|
|
2526
|
-
} else if (Array.isArray(msg.content)) {
|
|
2527
|
-
const textParts = msg.content.filter((p) => p.type === "text" && p.text).map((p) => p.text);
|
|
2528
|
-
text = textParts.join("\n");
|
|
2529
|
-
const toolCalls = msg.content.filter(
|
|
2530
|
-
(p) => p.type === "tool-call"
|
|
2531
|
-
);
|
|
2532
|
-
const toolResults = msg.content.filter(
|
|
2533
|
-
(p) => p.type === "tool-result"
|
|
2534
|
-
);
|
|
2535
|
-
if (toolCalls.length > 0) {
|
|
2536
|
-
text += `
|
|
2537
|
-
[Called ${toolCalls.length} tool(s): ${toolCalls.map((t) => t.toolName).join(", ")}]`;
|
|
2538
|
-
}
|
|
2539
|
-
if (toolResults.length > 0) {
|
|
2540
|
-
text += `
|
|
2541
|
-
[Received ${toolResults.length} tool result(s)]`;
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2522
|
+
const role = msg.role === "user" ? "User" : msg.role === "assistant" ? "Assistant" : "Tool";
|
|
2523
|
+
const { text } = renderMessageContentForCompaction(msg);
|
|
2544
2524
|
if (text.trim()) {
|
|
2545
2525
|
const truncated = text.length > 2e3 ? text.slice(0, 2e3) + "..." : text;
|
|
2546
2526
|
historyParts.push(`${role}: ${truncated}`);
|
|
@@ -2583,7 +2563,27 @@ function buildCompactionHistory(prompt) {
|
|
|
2583
2563
|
}
|
|
2584
2564
|
function getClaudeUserMessage(prompt, includeHistoryContext = false, opts = {}) {
|
|
2585
2565
|
const compactionMode = opts.compactionMode === true;
|
|
2566
|
+
const cliToolCallIds = opts.cliToolCallIds;
|
|
2586
2567
|
const content = [];
|
|
2568
|
+
const pushToolResult = (part) => {
|
|
2569
|
+
const id = part.toolCallId;
|
|
2570
|
+
const text = getToolResultText(part);
|
|
2571
|
+
if (!cliToolCallIds || cliToolCallIds.has(id)) {
|
|
2572
|
+
content.push({ type: "tool_result", tool_use_id: id, content: text });
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2575
|
+
log.info("rendering opencode-side tool result as text", {
|
|
2576
|
+
toolCallId: id,
|
|
2577
|
+
toolName: part.toolName,
|
|
2578
|
+
chars: text.length
|
|
2579
|
+
});
|
|
2580
|
+
content.push({
|
|
2581
|
+
type: "text",
|
|
2582
|
+
text: `<opencode_tool_result tool="${part.toolName ?? "unknown"}">
|
|
2583
|
+
${text}
|
|
2584
|
+
</opencode_tool_result>`
|
|
2585
|
+
});
|
|
2586
|
+
};
|
|
2587
2587
|
if (compactionMode) {
|
|
2588
2588
|
const transcript = compactConversationHistory(prompt, {
|
|
2589
2589
|
mode: "compaction"
|
|
@@ -2653,12 +2653,7 @@ Now continuing with the current message:
|
|
|
2653
2653
|
});
|
|
2654
2654
|
}
|
|
2655
2655
|
} else if (part.type === "tool-result") {
|
|
2656
|
-
|
|
2657
|
-
content.push({
|
|
2658
|
-
type: "tool_result",
|
|
2659
|
-
tool_use_id: p.toolCallId,
|
|
2660
|
-
content: getToolResultText(p)
|
|
2661
|
-
});
|
|
2656
|
+
pushToolResult(part);
|
|
2662
2657
|
}
|
|
2663
2658
|
}
|
|
2664
2659
|
}
|
|
@@ -2666,12 +2661,7 @@ Now continuing with the current message:
|
|
|
2666
2661
|
if (Array.isArray(msg.content)) {
|
|
2667
2662
|
for (const part of msg.content) {
|
|
2668
2663
|
if (part?.type === "tool-result") {
|
|
2669
|
-
|
|
2670
|
-
content.push({
|
|
2671
|
-
type: "tool_result",
|
|
2672
|
-
tool_use_id: p.toolCallId,
|
|
2673
|
-
content: getToolResultText(p)
|
|
2674
|
-
});
|
|
2664
|
+
pushToolResult(part);
|
|
2675
2665
|
}
|
|
2676
2666
|
}
|
|
2677
2667
|
}
|
|
@@ -5058,7 +5048,12 @@ var ClaudeCodeLanguageModel = class {
|
|
|
5058
5048
|
}
|
|
5059
5049
|
const hasExistingSession = !!getClaudeSessionId(sk);
|
|
5060
5050
|
const includeHistoryContext = !hasExistingSession && hasPriorConversation;
|
|
5061
|
-
const userMsg = consumeExitPlanModeQuestionResult(sk, options.prompt) ??
|
|
5051
|
+
const userMsg = consumeExitPlanModeQuestionResult(sk, options.prompt) ?? // doGenerate has no proxy wiring, so this process issued no tool calls
|
|
5052
|
+
// at all: every tool result reaching it belongs to opencode and must be
|
|
5053
|
+
// rendered as text rather than an orphaned `tool_result` (issue #29).
|
|
5054
|
+
getClaudeUserMessage(options.prompt, includeHistoryContext, {
|
|
5055
|
+
cliToolCallIds: /* @__PURE__ */ new Set()
|
|
5056
|
+
});
|
|
5062
5057
|
const [runtimeStatus, cliVersion, planModeQuestionActive] = await Promise.all([
|
|
5063
5058
|
getRuntimeMcpStatus(),
|
|
5064
5059
|
detectCliVersion(this.config.cliPath),
|
|
@@ -5514,8 +5509,10 @@ ${plan}
|
|
|
5514
5509
|
if (exitPlanModeQuestionResult) {
|
|
5515
5510
|
log.info("sending plan approval decision to claude", { sk });
|
|
5516
5511
|
}
|
|
5512
|
+
const previousPendingProxyCalls = compactionMode ? [] : getPendingProxyCalls(sk);
|
|
5517
5513
|
const userMsg = exitPlanModeQuestionResult ?? getClaudeUserMessage(options.prompt, includeHistoryContext, {
|
|
5518
|
-
compactionMode
|
|
5514
|
+
compactionMode,
|
|
5515
|
+
cliToolCallIds: new Set(previousPendingProxyCalls.map((c) => c.toolCallId))
|
|
5519
5516
|
});
|
|
5520
5517
|
const resolvedProxy = compactionMode ? null : this.resolvedProxyTools();
|
|
5521
5518
|
const loadLiveToolInfo = this.createLiveToolInfoLoader();
|
|
@@ -5524,7 +5521,6 @@ ${plan}
|
|
|
5524
5521
|
loadLiveToolInfo
|
|
5525
5522
|
);
|
|
5526
5523
|
const self = this;
|
|
5527
|
-
const previousPendingProxyCalls = compactionMode ? [] : getPendingProxyCalls(sk);
|
|
5528
5524
|
const previousPendingProxyMatches = previousPendingProxyCalls.map((call) => ({
|
|
5529
5525
|
call,
|
|
5530
5526
|
result: this.extractPendingProxyResult(options.prompt, call.toolCallId)
|