@dreb/coding-agent 2.64.2 → 2.64.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/README.md CHANGED
@@ -253,7 +253,7 @@ Long sessions can exhaust context windows. Compaction summarizes older messages
253
253
 
254
254
  **Manual:** `/compact` or `/compact <custom instructions>`
255
255
 
256
- **Automatic:** Enabled by default. Triggers on context overflow (recovers and retries) or when approaching the limit (proactive). Configure via `/settings` or `settings.json`. For unattended long-running work, enable **Continue after auto-compaction** (persisted as `compaction.continueAfterAutoCompaction`) to start another model turn after every successful automatic compaction, even with no queued message. It is off by default and never makes manual `/compact` continue.
256
+ **Automatic:** Enabled by default. Triggers on context overflow (recovers and retries) or proactively when approaching the limit, including between LLM requests in a long tool loop. Mid-turn checks wait until every tool call has a matching result, compact the settled context, and continue in the same loop before the next provider request. Configure via `/settings` or `settings.json`. For unattended long-running work, enable **Continue after auto-compaction** (persisted as `compaction.continueAfterAutoCompaction`) to keep pending or interrupted work moving after successful automatic compaction. It is off by default, does not start a fresh turn after a completed assistant answer, and never makes manual `/compact` continue.
257
257
 
258
258
  Compaction is lossy. The full history remains in the JSONL file; use `/tree` to revisit. Customize compaction behavior via [extensions](#extensions). See [docs/compaction.md](docs/compaction.md) for internals.
259
259
 
@@ -202,6 +202,10 @@ export declare class AgentSession {
202
202
  private _pendingNextTurnMessages;
203
203
  private _compactionAbortController;
204
204
  private _autoCompactionAbortController;
205
+ /** The in-flight auto-compaction run (any start path), if any. */
206
+ private _autoCompactionInFlight;
207
+ /** Serializes auto-compaction checks so two never run concurrently. */
208
+ private _autoCompactionChain;
205
209
  private _overflowRecoveryAttempted;
206
210
  private _branchSummaryAbortController;
207
211
  private _retryAbortController;
@@ -289,6 +293,9 @@ export declare class AgentSession {
289
293
  * - Layer D: Turn limiter — restrict parent to N turns while bg agents are running
290
294
  */
291
295
  private _installBackgroundAgentGuardrails;
296
+ /** Install the settled pre-request hook used for mid-turn compaction. */
297
+ private _installMidTurnCompactionHook;
298
+ private _prepareForLlmCall;
292
299
  /**
293
300
  * Reset the background-agent guardrail counter and the pause-notified flag together.
294
301
  * These two fields are one logical unit — they must always reset in lockstep so a new
@@ -628,7 +635,27 @@ export declare class AgentSession {
628
635
  * Cancel in-progress branch summarization.
629
636
  */
630
637
  abortBranchSummary(): void;
638
+ /**
639
+ * Check if compaction is needed and run it.
640
+ * Called after agent_end and before prompt submission.
641
+ *
642
+ * Two cases:
643
+ * 1. Overflow: LLM returned context overflow error, remove error message from agent state, compact, auto-retry
644
+ * 2. Threshold: Context over threshold, compact, NO auto-retry (user continues manually)
645
+ *
646
+ * Checks run on a serialization chain: a check that arrives while another
647
+ * check's compaction is still in flight (e.g. a prompt submitted during an
648
+ * agent_end compaction) waits for it, then evaluates instead of starting a
649
+ * competing compaction. If an earlier queued check compacted or rebuilt
650
+ * context first, the captured message is pre-compaction and the
651
+ * pre-compaction staleness guard inside _doCheckCompaction skips it.
652
+ *
653
+ * @param assistantMessage The assistant message to check
654
+ * @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
655
+ * @param requestWillFollow Whether the caller will issue the next request without agent.continue().
656
+ */
631
657
  private _checkCompaction;
658
+ private _doCheckCompaction;
632
659
  /**
633
660
  * Apply the K3 auto context tier to a model being set on the agent. The
634
661
  * user-facing `k3` model runs on the cheaper `k3-256k` wire model ID until
@@ -644,6 +671,13 @@ export declare class AgentSession {
644
671
  * compacted. Returns true when the upgrade was applied.
645
672
  */
646
673
  private _tryUpgradeK3ContextTier;
674
+ /**
675
+ * Start an auto-compaction while tracking it, so a concurrent check that
676
+ * arrives during the run can await it instead of starting a competing one.
677
+ * The tracking flag clears when this specific run settles (even on error,
678
+ * since _runAutoCompaction swallows its own failures).
679
+ */
680
+ private _trackAutoCompaction;
647
681
  private _runAutoCompaction;
648
682
  /**
649
683
  * Toggle auto-compaction setting.