@cline/agents 0.0.85 → 0.0.86

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.
@@ -74,6 +74,8 @@ export declare class AgentRuntime {
74
74
  private overflowRecoveryAttempted;
75
75
  /** Consecutive output-limit cut-offs recovered this run; see MAX_TOKENS_RECOVERY_LIMIT. */
76
76
  private maxTokensRecoveryCount;
77
+ /** One automatic recovery attempt per run for max-tokens-truncated turns. */
78
+ private maxTokensRecoveryAttempted;
77
79
  private initialization?;
78
80
  private abortController?;
79
81
  private modelSteerController?;
@@ -130,9 +132,18 @@ export declare class AgentRuntime {
130
132
  * visible output or provider tool activity are returned unchanged for the
131
133
  * caller to handle, so this only adds
132
134
  * resilience and never changes behavior for a turn that would otherwise
133
- * succeed. Context-window overflow recovery still runs inside each attempt.
135
+ * succeed. Context-window overflow recovery and max-tokens recovery still
136
+ * run inside each attempt (the latter at most once per run).
134
137
  */
135
138
  private generateAssistantMessageWithProviderRetry;
139
+ /**
140
+ * Run `issue`, re-running it with backoff while it returns a turn that
141
+ * failed with a transient, retryable provider error (see
142
+ * {@link isRetryableProviderErrorTurn}), up to PROVIDER_ERROR_MAX_RETRIES
143
+ * times. `issue` decides what is re-run: the whole prepared turn for an
144
+ * ordinary request, or just the issuing of an already-prepared request.
145
+ */
146
+ private withProviderErrorRetry;
136
147
  /**
137
148
  * True when a turn failed with a transient provider error that a retry
138
149
  * could plausibly recover, and the failed attempt left nothing behind that
@@ -160,15 +171,65 @@ export declare class AgentRuntime {
160
171
  */
161
172
  private abortableDelay;
162
173
  /**
163
- * Run a model turn, recovering once per run from a provider-rejected
164
- * context-window overflow: force a compaction through `prepareTurn` and
165
- * retry the request. Terminal (unrecoverable) overflow states throw with
166
- * an actionable message instead of the raw provider error.
174
+ * Run a model turn, recovering once per run from each of two conditions:
175
+ * a provider-rejected context-window overflow, and a response truncated
176
+ * at the output-token limit on a turn with no tool calls. Both recoveries
177
+ * force a compaction through `prepareTurn` and retry the request.
178
+ * Terminal (unrecoverable) overflow states throw with an actionable
179
+ * message instead of the raw provider error; an unrecoverable truncated
180
+ * turn is returned as-is so the loop surfaces the max-tokens error with
181
+ * the partial content preserved.
167
182
  */
168
183
  private generateAssistantMessageWithOverflowRecovery;
169
184
  private isRecoverableOverflowTurn;
185
+ private isRecoverableMaxTokensTurn;
186
+ /** Provider-executed tool activity is recorded in metadata, not content. */
187
+ private hasModelToolActivity;
188
+ /**
189
+ * A response cut off at the output-token limit is often a symptom of a
190
+ * nearly-full context: local OpenAI-compatible servers (llama.cpp, ollama,
191
+ * LM Studio) cap generation at whatever context remains, regardless of the
192
+ * requested output budget. Compacting the conversation frees that room, so
193
+ * one forced compaction + retry rescues those turns. When compaction has
194
+ * nothing to remove the original turn is returned, so the loop surfaces the
195
+ * max-tokens error with the partial content already persisted.
196
+ *
197
+ * The truncated turn is not yet persisted while this runs (the loop records
198
+ * a turn only after it returns), so whenever the attempt ends without a
199
+ * replacement turn — compaction threw, the retry was aborted, or it errored
200
+ * with nothing for the loop to execute — the truncated turn is recorded
201
+ * first and the failure surfaces afterwards; the partial answer is never
202
+ * lost to the recovery attempt.
203
+ *
204
+ * A retry that does come back is handed to the loop unjudged: the run loop
205
+ * remains the only place that decides whether a turn is acceptable. When
206
+ * compaction cannot help — nothing to remove, the retry truncated again, or
207
+ * the turn was never eligible — the loop's own nudge-and-retry recovery
208
+ * takes over, so this runs first and at most once per run.
209
+ * Telemetry here is purely
210
+ * observational — `started`, then `retried` with the retry's finish reason
211
+ * when the attempt ran, or `failed` when it could not — so it never claims
212
+ * anything about the run outcome and cannot contradict it.
213
+ */
214
+ private retryTruncatedTurnWithCompaction;
215
+ /** Append an assistant turn to the transcript and announce it. */
216
+ private recordAssistantMessage;
170
217
  private generateAssistantMessage;
218
+ /**
219
+ * Issue an already-prepared request as a fresh attempt: turn preparation
220
+ * (compaction, before-model hooks) is not re-run, but the attempt gets its
221
+ * own steer controller and lifecycle timing.
222
+ */
223
+ private issuePreparedRequest;
224
+ /** A model request with turn preparation and before-model hooks applied. */
225
+ private prepareModelRequest;
171
226
  private generateAssistantMessageForRequest;
227
+ /**
228
+ * Issue a prepared request and assemble the assistant turn from its stream.
229
+ * Separate from preparation so a prepared request can be re-issued (e.g.
230
+ * after a transient provider error) without re-running turn preparation.
231
+ */
232
+ private streamPreparedRequest;
172
233
  private openTaskLifecycleStream;
173
234
  private captureTaskLifecycleFailure;
174
235
  private captureTaskLifecycle;
@@ -1 +1 @@
1
- {"version":3,"file":"agent-runtime.d.ts","sourceRoot":"","sources":["../src/agent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,uBAAuB,EAE5B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAIX,YAAY,EAEZ,UAAU,EAKV,cAAc,EACd,iBAAiB,EAEjB,yBAAyB,EAOzB,kBAAkB,IAAI,sBAAsB,EAM5C,MAAM,eAAe,CAAC;AAmDvB;;;;GAIG;AACH,eAAO,MAAM,kDAAkD,sPACgL,CAAC;AAEhP;;;GAGG;AACH,eAAO,MAAM,+CAA+C,0JAC4F,CAAC;AAEzJ;;;GAGG;AACH,eAAO,MAAM,2CAA2C,2JACiG,CAAC;AAuB1J,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,YAAY,EAAE,CAAC;AAC5E,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,2BAA4B,SAAQ,sBAAsB;IAC1E,KAAK,EAAE,UAAU,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,8BAChB,SAAQ,IAAI,CAAC,sBAAsB,EAAE,OAAO,CAAC;IAC7C,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;I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