@dreb/coding-agent 2.66.0 → 2.66.2

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.
@@ -15,7 +15,7 @@
15
15
  import { copyFileSync, existsSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
16
16
  import { tmpdir } from "node:os";
17
17
  import { basename, dirname, join, resolve } from "node:path";
18
- import { isContextOverflow, modelsAreEqual, resetApiProviders, supportsMax, supportsXhigh } from "@dreb/ai";
18
+ import { isContextOverflow, isOutputLimitExhaustion, modelsAreEqual, resetApiProviders, supportsMax, supportsXhigh, } from "@dreb/ai";
19
19
  import { getDocsPath } from "../config.js";
20
20
  import { theme } from "../modes/interactive/theme/theme.js";
21
21
  import { sleep } from "../utils/sleep.js";
@@ -1036,8 +1036,7 @@ export class AgentSession {
1036
1036
  type: "length_retry",
1037
1037
  attempt: event.attempt,
1038
1038
  maxAttempts: event.maxAttempts,
1039
- previousMaxTokens: event.previousMaxTokens,
1040
- nextMaxTokens: event.nextMaxTokens,
1039
+ maxTokens: event.maxTokens,
1041
1040
  discardedPartial: event.discardedPartial,
1042
1041
  };
1043
1042
  await this._extensionRunner.emit(extensionEvent);
@@ -1135,6 +1134,10 @@ export class AgentSession {
1135
1134
  get state() {
1136
1135
  return this.agent.state;
1137
1136
  }
1137
+ /** Effective runtime working directory used by tools, resources, and project discovery. */
1138
+ get cwd() {
1139
+ return this._cwd;
1140
+ }
1138
1141
  /** Current session task list (read-only) */
1139
1142
  get tasks() {
1140
1143
  return this._tasks;
@@ -1760,7 +1763,7 @@ export class AgentSession {
1760
1763
  await this.abort();
1761
1764
  this.agent.reset();
1762
1765
  this._dispatchArbiter.clearContext();
1763
- this.sessionManager.newSession({ parentSession: options?.parentSession });
1766
+ this.sessionManager.newSession({ parentSession: options?.parentSession, cwd: this.cwd });
1764
1767
  this.agent.sessionId = this.sessionManager.getSessionId();
1765
1768
  this._steeringMessages = [];
1766
1769
  this._followUpMessages = [];
@@ -2209,8 +2212,14 @@ export class AgentSession {
2209
2212
  if (assistantIsFromBeforeCompaction) {
2210
2213
  return;
2211
2214
  }
2212
- // Case 1: Overflow - LLM returned context overflow error
2213
- if (sameModel && isContextOverflow(assistantMessage, contextWindow)) {
2215
+ // Case 1: Overflow - LLM returned a context error, or exhausted its
2216
+ // configured output limit when that output could not fit beside the request.
2217
+ const estimatedInputTokens = estimateContextTokens(this.agent.state.messages.slice(0, -1)).tokens;
2218
+ if (sameModel &&
2219
+ isContextOverflow(assistantMessage, contextWindow, {
2220
+ maxOutputTokens: this.model?.maxTokens,
2221
+ estimatedInputTokens,
2222
+ })) {
2214
2223
  // K3 auto context tier: an overflow in the 256k tier upgrades to the
2215
2224
  // 1M tier instead of compacting — the Kimi backend grows the prompt
2216
2225
  // cache seamlessly. This runs even when compaction is disabled since
@@ -2247,6 +2256,10 @@ export class AgentSession {
2247
2256
  await this._trackAutoCompaction("overflow", true, requestWillFollow);
2248
2257
  return;
2249
2258
  }
2259
+ // A genuine output-limit exhaustion cannot be fixed by discarding conversation
2260
+ // history. Only the context-constrained case above enters compact-and-retry.
2261
+ if (isOutputLimitExhaustion(assistantMessage))
2262
+ return;
2250
2263
  // Case 2: Threshold - context is getting large
2251
2264
  // For error messages (no usage data), estimate from last successful response.
2252
2265
  // This ensures sessions that hit persistent API errors (e.g. 529) can still compact.
@@ -3260,7 +3273,7 @@ export class AgentSession {
3260
3273
  throw new Error("Cannot fork at this assistant turn: it was interrupted or is still waiting on tool results");
3261
3274
  }
3262
3275
  const { cancelled } = await this._performFork(entryId, () => {
3263
- this.sessionManager.createBranchedSession(entryId);
3276
+ this.sessionManager.createBranchedSession(entryId, this.cwd);
3264
3277
  });
3265
3278
  return { selectedText: "", cancelled };
3266
3279
  }
@@ -3270,10 +3283,10 @@ export class AgentSession {
3270
3283
  // offered as editor pre-fill.
3271
3284
  const { cancelled } = await this._performFork(entryId, (previousSessionFile) => {
3272
3285
  if (!selectedEntry.parentId) {
3273
- this.sessionManager.newSession({ parentSession: previousSessionFile });
3286
+ this.sessionManager.newSession({ parentSession: previousSessionFile, cwd: this.cwd });
3274
3287
  }
3275
3288
  else {
3276
- this.sessionManager.createBranchedSession(selectedEntry.parentId);
3289
+ this.sessionManager.createBranchedSession(selectedEntry.parentId, this.cwd);
3277
3290
  }
3278
3291
  });
3279
3292
  return { selectedText, cancelled };