@sayknow-cli/coding-agent 0.7.12 → 0.7.13

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.7.13] - 2026-10-26
6
+
7
+ ### Fixed
8
+
9
+ - A transient failure (e.g. `The socket connection was closed unexpectedly`) that cut off a tool call before it ran no longer ends the step with only a failed tool row. When the attempt streamed no answer text, automatic retry, `/retry`, and restart resume drop the cut-off call with its placeholder error result and ask the same model again; the call is never executed or replayed. When answer text was already shown, the step still stops, and a warning now says it was not resumed automatically.
10
+
5
11
  ## [0.7.12] - 2026-10-24
6
12
 
7
13
  ### Added
@@ -1293,7 +1293,8 @@ export declare class AgentSession {
1293
1293
  * left by a non-graceful process exit after the user/custom/tool-result message
1294
1294
  * was persisted but before the agent emitted a terminal assistant response.
1295
1295
  * Removes only a failed/aborted assistant tail with no visible output or tool
1296
- * calls, then re-attempts with a fresh retry budget.
1296
+ * calls, or a failed tail whose cut-off tool calls never ran (with their placeholder
1297
+ * results), then re-attempts with a fresh retry budget.
1297
1298
  * @returns false when the agent is busy, no retryable tail exists, the tail shows
1298
1299
  * output or tool calls, a persisted recovery is unresolved, or the step dispatched
1299
1300
  * unobservable remote work; true when a retry/resume was scheduled.
@@ -40,6 +40,11 @@ export interface AutoResumeMarker {
40
40
  * recovery drops it and asks the same model again instead of stopping.
41
41
  */
42
42
  export declare function isThinkingOnlyFailure(message: AgentMessage | undefined): boolean;
43
+ /**
44
+ * The transcript before its trailing unexecuted tool-call failure, without the error
45
+ * placeholder results paired with its calls; undefined when the tail is anything else.
46
+ */
47
+ export declare function dropUnexecutedToolCallFailure(messages: readonly AgentMessage[]): AgentMessage[] | undefined;
43
48
  /**
44
49
  * Restart-safe means: an instance of a built-in read-only tool class (seen through
45
50
  * extension/hook interception wrappers) whose wire name is unique among the selected
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@sayknow-cli/coding-agent",
4
- "version": "0.7.12",
4
+ "version": "0.7.13",
5
5
  "description": "Sayknow-CLI CLI with read, bash, edit, write tools and session management",
6
6
  "homepage": "https://sayknow-cli.com",
7
7
  "author": "jaybeyond",
@@ -54,12 +54,12 @@
54
54
  "@agentclientprotocol/sdk": "1.3.0",
55
55
  "@babel/parser": "^7.29.3",
56
56
  "@mozilla/readability": "^0.6.0",
57
- "@sayknow-cli/stats": "0.7.12",
58
- "@sayknow-cli/agent-core": "0.7.12",
59
- "@sayknow-cli/ai": "0.7.12",
60
- "@sayknow-cli/natives": "0.7.12",
61
- "@sayknow-cli/tui": "0.7.12",
62
- "@sayknow-cli/utils": "0.7.12",
57
+ "@sayknow-cli/stats": "0.7.13",
58
+ "@sayknow-cli/agent-core": "0.7.13",
59
+ "@sayknow-cli/ai": "0.7.13",
60
+ "@sayknow-cli/natives": "0.7.13",
61
+ "@sayknow-cli/tui": "0.7.13",
62
+ "@sayknow-cli/utils": "0.7.13",
63
63
  "@puppeteer/browsers": "^2.13.0",
64
64
  "@types/turndown": "5.0.6",
65
65
  "@xterm/headless": "^6.0.0",
@@ -410,6 +410,7 @@ import {
410
410
  type AutoResumeMarker,
411
411
  type AutoResumeMode,
412
412
  type AutoResumeTrigger,
413
+ dropUnexecutedToolCallFailure,
413
414
  hasAutoResumeMarkerSinceLastUser,
414
415
  hasVisibleFailedPrefix,
415
416
  INTERRUPTED_TOOL_RESULT_TEXT,
@@ -14888,14 +14889,20 @@ export class AgentSession {
14888
14889
  // only reasoning holds no answer and its signed blocks cannot be replayed: it
14889
14890
  // is dropped and retried like a failure that showed nothing.
14890
14891
  const thinkingOnlyFailure = !managedOutcome && isThinkingOnlyFailure(message);
14891
- const visibleFailure =
14892
- !managedOutcome && !thinkingOnlyFailure && assistantMessageHasVisibleOrToolContent(message);
14892
+ // Tool calls cut off by the failure never ran (see #withoutUnexecutedToolCallFailure):
14893
+ // without answer text the attempt is dropped like a reasoning-only failure.
14894
+ const unexecutedToolCallFailure =
14895
+ !managedOutcome &&
14896
+ this.agent.state.messages.findLast(item => item.role === "assistant") === message &&
14897
+ this.#withoutUnexecutedToolCallFailure() !== undefined;
14898
+ const answerlessFailure = thinkingOnlyFailure || unexecutedToolCallFailure;
14899
+ const visibleFailure = !managedOutcome && !answerlessFailure && assistantMessageHasVisibleOrToolContent(message);
14893
14900
  const visibleContinuation = visibleFailure && this.#canContinueVisibleFailure(message);
14894
14901
  if (visibleFailure && !visibleContinuation) return false;
14895
14902
  // Bare defaults admit only clean canonical stream watchdog failures, plus a
14896
- // transient server failure that streamed only reasoning (e.g. an SSE
14897
- // overloaded_error after thinking_delta): the provider's own pre-content
14898
- // retry cannot cover it, and it has no answer to preserve. Completed tool
14903
+ // transient server failure that streamed only reasoning or never-run tool calls
14904
+ // (e.g. an SSE overloaded_error after thinking_delta): the provider's own
14905
+ // pre-content retry cannot cover it, and it has no answer to preserve. Completed tool
14899
14906
  // pairs and preserved visible output stay in the transcript and are never
14900
14907
  // re-executed; only hooks/commands/user shell/abort make the run unsafe.
14901
14908
  if (!managedFallback && !legacyRetryConfigured) {
@@ -14903,8 +14910,8 @@ export class AgentSession {
14903
14910
  !hasBareDefaultRetryDisqualifyingFacts(message) &&
14904
14911
  (classification === "transient" || classification === "first_event_timeout") &&
14905
14912
  BARE_DEFAULT_WATCHDOG_ERROR.test(message.errorMessage ?? "");
14906
- const bareThinkingOnly =
14907
- thinkingOnlyFailure &&
14913
+ const bareAnswerless =
14914
+ answerlessFailure &&
14908
14915
  classification === "transient" &&
14909
14916
  message.errorKind === undefined &&
14910
14917
  !BARE_DEFAULT_THROTTLE_ERROR.test(message.errorMessage ?? "") &&
@@ -14919,7 +14926,7 @@ export class AgentSession {
14919
14926
  classification === "transient" &&
14920
14927
  !hasBareDefaultRetryDisqualifyingFacts(message) &&
14921
14928
  isUnexpectedSocketCloseMessage(message.errorMessage ?? "");
14922
- if (!(bareWatchdog || bareThinkingOnly || bareSocketClose) || !this.#hasCleanContinuationSafety) {
14929
+ if (!(bareWatchdog || bareAnswerless || bareSocketClose) || !this.#hasCleanContinuationSafety) {
14923
14930
  return false;
14924
14931
  }
14925
14932
  }
@@ -15116,7 +15123,10 @@ export class AgentSession {
15116
15123
  // after the backoff instead (see below).
15117
15124
  if (!visibleContinuation) {
15118
15125
  const messages = this.agent.state.messages;
15119
- if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
15126
+ const withoutAttempt = unexecutedToolCallFailure ? this.#withoutUnexecutedToolCallFailure() : undefined;
15127
+ if (withoutAttempt) {
15128
+ this.agent.replaceMessages(withoutAttempt);
15129
+ } else if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
15120
15130
  this.agent.replaceMessages(messages.slice(0, -1));
15121
15131
  }
15122
15132
  }
@@ -15676,6 +15686,18 @@ export class AgentSession {
15676
15686
  logger.debug("auto_resume_paused", { trigger, reason: decision.reason });
15677
15687
  if (decision.reason === "already_resumed") {
15678
15688
  this.emitNotice("info", "Automatic resume was already used for this request.", "retry");
15689
+ } else if (
15690
+ trigger === "interrupted" &&
15691
+ decision.reason !== "disabled" &&
15692
+ decision.reason !== "not_interrupted" &&
15693
+ decision.reason !== "user_input_pending"
15694
+ ) {
15695
+ // Otherwise the step just stops: a failed tool-call tail renders only as a tool error.
15696
+ this.emitNotice(
15697
+ "warning",
15698
+ "The interrupted step was not resumed automatically. Send a message to continue.",
15699
+ "retry",
15700
+ );
15679
15701
  }
15680
15702
  return false;
15681
15703
  }
@@ -15719,10 +15741,14 @@ export class AgentSession {
15719
15741
  logger.warn("auto_resume_abandoned", { trigger, reason: "state changed while the marker was written" });
15720
15742
  return false;
15721
15743
  }
15722
- // A failed attempt that showed nothing, or only private reasoning, is not part of the
15723
- // answer; resending it only adds an empty assistant turn (the same rule manual retry applies).
15744
+ // A failed attempt that showed nothing, only private reasoning, or tool calls that
15745
+ // never ran is not part of the answer; resending it only adds an empty assistant
15746
+ // turn (the same rule manual retry applies).
15747
+ const withoutAttempt = this.#withoutUnexecutedToolCallFailure();
15724
15748
  const tailMessage = this.agent.state.messages.at(-1);
15725
- if (
15749
+ if (placeholders.length === 0 && withoutAttempt) {
15750
+ this.agent.replaceMessages(withoutAttempt);
15751
+ } else if (
15726
15752
  placeholders.length === 0 &&
15727
15753
  tailMessage?.role === "assistant" &&
15728
15754
  (tailMessage.stopReason === "error" || tailMessage.stopReason === "aborted") &&
@@ -15896,12 +15922,28 @@ export class AgentSession {
15896
15922
  );
15897
15923
  }
15898
15924
 
15925
+ /**
15926
+ * The transcript without a trailing failed attempt whose only public content is tool
15927
+ * calls cut off before they could run: the loop executes tools only after a completed
15928
+ * stream and pairs a failed stream's calls with placeholder results. Opaque transports
15929
+ * execute calls remotely, so their attempts are never dropped.
15930
+ */
15931
+ #withoutUnexecutedToolCallFailure(): AgentMessage[] | undefined {
15932
+ const messages = this.agent.state.messages;
15933
+ const failed = messages.findLast(message => message.role === "assistant");
15934
+ if (failed?.role !== "assistant" || failed.api === "cursor-agent" || this.model?.transport === "pi-native") {
15935
+ return undefined;
15936
+ }
15937
+ return dropUnexecutedToolCallFailure(messages);
15938
+ }
15939
+
15899
15940
  /**
15900
15941
  * Manually retry the last failed assistant turn, or resume an interrupted tail
15901
15942
  * left by a non-graceful process exit after the user/custom/tool-result message
15902
15943
  * was persisted but before the agent emitted a terminal assistant response.
15903
15944
  * Removes only a failed/aborted assistant tail with no visible output or tool
15904
- * calls, then re-attempts with a fresh retry budget.
15945
+ * calls, or a failed tail whose cut-off tool calls never ran (with their placeholder
15946
+ * results), then re-attempts with a fresh retry budget.
15905
15947
  * @returns false when the agent is busy, no retryable tail exists, the tail shows
15906
15948
  * output or tool calls, a persisted recovery is unresolved, or the step dispatched
15907
15949
  * unobservable remote work; true when a retry/resume was scheduled.
@@ -15919,7 +15961,9 @@ export class AgentSession {
15919
15961
  const lastMsg = messages[messages.length - 1];
15920
15962
  if (!lastMsg) return false;
15921
15963
 
15922
- if (lastMsg.role !== "assistant") {
15964
+ const withoutAttempt = this.#withoutUnexecutedToolCallFailure();
15965
+
15966
+ if (lastMsg.role !== "assistant" && !withoutAttempt) {
15923
15967
  if (!this.#isInterruptedRetryTail(lastMsg)) return false;
15924
15968
  this.#retryAttempt = 0;
15925
15969
  this.#endStepRecoveryBudget();
@@ -15927,15 +15971,21 @@ export class AgentSession {
15927
15971
  return true;
15928
15972
  }
15929
15973
 
15930
- const assistantMsg = lastMsg as AssistantMessage;
15931
- // Explicit retry does not establish the outcome of an interrupted operation
15932
- // and is never permission to erase a prefix already shown to the user. A failure
15933
- // that streamed only reasoning holds no answer and is dropped like an empty one.
15934
- if (!isThinkingOnlyFailure(assistantMsg) && assistantMessageHasVisibleOrToolContent(assistantMsg)) return false;
15935
- if (assistantMsg.stopReason !== "error" && assistantMsg.stopReason !== "aborted") return false;
15974
+ if (withoutAttempt) {
15975
+ // Cut-off tool calls that never ran are dropped with their placeholder results.
15976
+ this.agent.replaceMessages(withoutAttempt);
15977
+ } else {
15978
+ const assistantMsg = lastMsg as AssistantMessage;
15979
+ // Explicit retry does not establish the outcome of an interrupted operation
15980
+ // and is never permission to erase a prefix already shown to the user. A failure
15981
+ // that streamed only reasoning holds no answer and is dropped like an empty one.
15982
+ if (!isThinkingOnlyFailure(assistantMsg) && assistantMessageHasVisibleOrToolContent(assistantMsg))
15983
+ return false;
15984
+ if (assistantMsg.stopReason !== "error" && assistantMsg.stopReason !== "aborted") return false;
15936
15985
 
15937
- // Remove the empty failed/aborted assistant message before re-attempting.
15938
- this.agent.replaceMessages(messages.slice(0, -1));
15986
+ // Remove the empty failed/aborted assistant message before re-attempting.
15987
+ this.agent.replaceMessages(messages.slice(0, -1));
15988
+ }
15939
15989
 
15940
15990
  // Reset retry budget for a fresh attempt: a manual retry is a new invocation.
15941
15991
  this.#retryAttempt = 0;
@@ -72,6 +72,38 @@ export function isThinkingOnlyFailure(message: AgentMessage | undefined): boolea
72
72
  return thinking;
73
73
  }
74
74
 
75
+ /**
76
+ * A failed attempt cut off before any answer text whose only public content is tool
77
+ * calls: the loop runs tools only after a stream completes, so these calls never ran
78
+ * and only got placeholder results. Like a reasoning-only failure it holds no answer;
79
+ * recovery drops it with those placeholders and asks the same model again.
80
+ */
81
+ function isUnexecutedToolCallFailure(message: AgentMessage): boolean {
82
+ if (message.role !== "assistant" || message.stopReason !== "error") return false;
83
+ let toolCall = false;
84
+ for (const block of message.content) {
85
+ if (block.type === "toolCall") toolCall = true;
86
+ else if (block.type === "text" && block.text.trim().length > 0) return false;
87
+ }
88
+ return toolCall;
89
+ }
90
+
91
+ /**
92
+ * The transcript before its trailing unexecuted tool-call failure, without the error
93
+ * placeholder results paired with its calls; undefined when the tail is anything else.
94
+ */
95
+ export function dropUnexecutedToolCallFailure(messages: readonly AgentMessage[]): AgentMessage[] | undefined {
96
+ const index = messages.findLastIndex(message => message.role === "assistant");
97
+ if (index === -1) return undefined;
98
+ const failed = messages[index];
99
+ if (failed.role !== "assistant" || !isUnexecutedToolCallFailure(failed)) return undefined;
100
+ const callIds = new Set(failed.content.flatMap(block => (block.type === "toolCall" ? [block.id] : [])));
101
+ for (const message of messages.slice(index + 1)) {
102
+ if (message.role !== "toolResult" || !message.isError || !callIds.has(message.toolCallId)) return undefined;
103
+ }
104
+ return messages.slice(0, index);
105
+ }
106
+
75
107
  /** Built-in tools whose execution has no side effects and may run again after a restart. */
76
108
  const RESTART_SAFE_TOOL_CLASSES = [ReadTool, SearchTool, FindTool, AstGrepTool, LocateTool] as const;
77
109
 
@@ -129,7 +161,8 @@ export function findInterruptedToolCalls(messages: readonly AgentMessage[]): Too
129
161
  * Tails that cannot be resumed safely: a failed step holding private signed reasoning
130
162
  * next to an answer or tool calls (possibly cut off mid-arguments), a call without an
131
163
  * id, or unanswered calls whose results could no longer be placed directly after their
132
- * assistant. A failure that streamed only reasoning is dropped before resuming instead.
164
+ * assistant. A failure that streamed only reasoning, or tool calls that never ran, is
165
+ * dropped before resuming instead.
133
166
  */
134
167
  function hasUnsafeAssistantTail(messages: readonly AgentMessage[]): boolean {
135
168
  const assistantIndex = messages.findLastIndex(message => message.role === "assistant");
@@ -194,14 +227,18 @@ export function resolveAutoResumePolicy(input: AutoResumePolicyInput): AutoResum
194
227
  if (input.userInputPending) return { type: "pause", reason: "user_input_pending" };
195
228
  if (!input.selectorAvailable) return { type: "pause", reason: "selector_unavailable" };
196
229
  if (!input.budgetAdmits) return { type: "pause", reason: "budget_exhausted" };
197
- if (hasUnsafeAssistantTail(input.messages)) return { type: "pause", reason: "unsafe_tail" };
198
- if (hasVisibleFailedPrefix(input.messages) && !input.prefixReplayable)
199
- return { type: "pause", reason: "unsafe_tail" };
200
- const tail = input.messages.at(-1);
230
+ // Tool calls cut off by the failure never ran: the attempt is dropped before resuming,
231
+ // so only the transcript before it is judged.
232
+ const withoutAttempt = dropUnexecutedToolCallFailure(input.messages);
233
+ const messages = withoutAttempt ?? input.messages;
234
+ if (hasUnsafeAssistantTail(messages)) return { type: "pause", reason: "unsafe_tail" };
235
+ if (hasVisibleFailedPrefix(messages) && !input.prefixReplayable) return { type: "pause", reason: "unsafe_tail" };
236
+ const tail = messages.at(-1);
201
237
  if (!tail) return { type: "pause", reason: "not_interrupted" };
202
- // Only a restart can find a user message whose request never settled.
238
+ // Only a restart can find a user message whose request never settled, unless the
239
+ // failed attempt answering it was just dropped.
203
240
  if (tail.role === "user") {
204
- return input.trigger === "restart"
241
+ return input.trigger === "restart" || withoutAttempt
205
242
  ? { type: "resume", mode: "full", interruptedCalls: [] }
206
243
  : { type: "pause", reason: "not_interrupted" };
207
244
  }
@@ -210,7 +247,7 @@ export function resolveAutoResumePolicy(input: AutoResumePolicyInput): AutoResum
210
247
  const settled = !tail.content.some(block => block.type === "toolCall");
211
248
  if (settled) return { type: "pause", reason: "not_interrupted" };
212
249
  }
213
- const interruptedCalls = findInterruptedToolCalls(input.messages);
250
+ const interruptedCalls = findInterruptedToolCalls(messages);
214
251
  if (interruptedCalls.length === 0) return { type: "resume", mode: "full", interruptedCalls };
215
252
  if (!input.selectedTools.some(tool => isRestartSafeTool(tool, input.selectedTools))) {
216
253
  return { type: "pause", reason: "no_restart_safe_tools" };