@pentoshi/clai 3.11.4 → 3.11.5

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.
@@ -38,7 +38,7 @@ function safeEngagementActionsForToolCall(call) {
38
38
  }
39
39
  import { availableToolNames, normalizeToolCall, runToolCall, BATCH_SAFE_TOOLS, } from "../tools/registry.js";
40
40
  import { getToolDefinitions, getCompactToolDefinitions, RUNNER_META_TOOL_NAMES, } from "../tools/definitions.js";
41
- import { appendAssistantWithTools, ensureUniqueToolCallIds, appendToolResult, assertValidToolProtocol, fillMissingToolResults, repairToolProtocol, } from "./tool-history.js";
41
+ import { appendAssistantWithTools, ensureUniqueToolCallIds, toolCallIdsInHistory, appendToolResult, assertValidToolProtocol, fillMissingToolResults, repairToolProtocol, } from "./tool-history.js";
42
42
  import { formatViewportHint, registerViewport } from "../ui/output-pane.js";
43
43
  import { compactMessagesWithSummary, shouldApplyAutoCompact, COMPACTION_MEMORY_PREFIX, PLAN_IMPLEMENT_MEMORY_PREFIX, isCompactionMemoryMessage, } from "./context-manager.js";
44
44
  import { buildContextBreakdown, contextBreakdownAuditPayload, describeDominantContextBlock, toolSchemaHash, } from "./context-breakdown.js";
@@ -3632,11 +3632,14 @@ export async function runAgentTurn(prompt, options = {}) {
3632
3632
  writeNotice("info", `native tool call was truncated — salvaged ${lineCount} lines and wrote to ${salvaged.path}`, chalk.cyan(` ℹ native tool call was truncated — salvaged ${lineCount} lines to ${salvaged.path}\n`));
3633
3633
  // Pair assistant tool_calls with synthetic results so the
3634
3634
  // next turn is not orphaned, then nudge for append.
3635
- appendAssistantWithTools(messages, assistantText.visible, nativeToolCalls, completion.reasoningBlock);
3636
- for (const tc of nativeToolCalls) {
3637
- appendToolResult(messages, tc.id, tc.id === writeTc.id
3635
+ const salvageHistoryCalls = ensureUniqueToolCallIds(nativeToolCalls, toolCallIdsInHistory(messages));
3636
+ const salvagedCallIndex = nativeToolCalls.indexOf(writeTc);
3637
+ const salvagedCallId = salvageHistoryCalls[salvagedCallIndex]?.id ?? writeTc.id;
3638
+ appendAssistantWithTools(messages, assistantText.visible, salvageHistoryCalls, completion.reasoningBlock);
3639
+ for (const tc of salvageHistoryCalls) {
3640
+ appendToolResult(messages, tc.id, tc.id === salvagedCallId
3638
3641
  ? `Tool ${tc.name} result (exit=0, ok=true):\nSalvaged partial write: ${lineCount} lines to ${salvaged.path}`
3639
- : `Tool ${tc.name} result (exit=1, ok=false):\nCancelled — sibling write was truncated and salvaged.`, tc.name, tc.id === writeTc.id);
3642
+ : `Tool ${tc.name} result (exit=1, ok=false):\nCancelled — sibling write was truncated and salvaged.`, tc.name, tc.id === salvagedCallId);
3640
3643
  }
3641
3644
  const priorBytes = writeResult.bytesOnDisk;
3642
3645
  const salvagedToolName = salvaged.operation === "append"
@@ -4251,7 +4254,7 @@ export async function runAgentTurn(prompt, options = {}) {
4251
4254
  // assistant toolCalls and role:tool results always share the same id.
4252
4255
  // Mismatched ids make results look orphaned → repair injects placeholders
4253
4256
  // → model thrash-retries tools that already succeeded in the UI.
4254
- const historyNativeCalls = ensureUniqueToolCallIds(bound.map((b) => b.native));
4257
+ const historyNativeCalls = ensureUniqueToolCallIds(bound.map((b) => b.native), toolCallIdsInHistory(messages));
4255
4258
  for (let i = 0; i < bound.length; i++) {
4256
4259
  const fixed = historyNativeCalls[i];
4257
4260
  bound[i] = {