@ashx-j/lunr 0.2.15 → 0.2.16

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.
Files changed (29) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.d.ts.map +1 -1
  3. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js +6 -2
  4. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js.map +1 -1
  5. package/dist/core/agent-session.d.ts +3 -0
  6. package/dist/core/agent-session.d.ts.map +1 -1
  7. package/dist/core/agent-session.js +50 -4
  8. package/dist/core/agent-session.js.map +1 -1
  9. package/dist/core/compaction/compaction.d.ts.map +1 -1
  10. package/dist/core/compaction/compaction.js +10 -5
  11. package/dist/core/compaction/compaction.js.map +1 -1
  12. package/dist/core/extensions/types.d.ts +2 -2
  13. package/dist/core/extensions/types.d.ts.map +1 -1
  14. package/dist/core/extensions/types.js.map +1 -1
  15. package/dist/modes/interactive/interactive-mode.d.ts +2 -0
  16. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  17. package/dist/modes/interactive/interactive-mode.js +19 -4
  18. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  19. package/docs/compaction.md +5 -3
  20. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  21. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  22. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  23. package/examples/extensions/gondolin/package-lock.json +2 -2
  24. package/examples/extensions/gondolin/package.json +1 -1
  25. package/examples/extensions/sandbox/package-lock.json +2 -2
  26. package/examples/extensions/sandbox/package.json +1 -1
  27. package/examples/extensions/with-deps/package-lock.json +2 -2
  28. package/examples/extensions/with-deps/package.json +1 -1
  29. package/package.json +4 -4
@@ -98,6 +98,7 @@ export class AgentSession {
98
98
  _pendingNextTurnMessages = [];
99
99
  // Compaction state
100
100
  _compactionAbortController = undefined;
101
+ _manualCompactionPromise = undefined;
101
102
  _autoCompactionAbortController = undefined;
102
103
  _overflowRecoveryAttempted = false;
103
104
  // Branch summarization state
@@ -330,7 +331,19 @@ export class AgentSession {
330
331
  : undefined);
331
332
  this.agent.prepareNextTurnWithContext = async (turn, signal) => {
332
333
  const previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal);
333
- const previousContext = previousSnapshot?.context ?? turn.context;
334
+ let previousContext = previousSnapshot?.context ?? turn.context;
335
+ const model = this.model;
336
+ const settings = this.settingsManager.getCompactionSettings();
337
+ if (model?.provider === "openai-codex" &&
338
+ settings.enabled &&
339
+ shouldCompact(estimateContextTokens(previousContext.messages).tokens, model.contextWindow, settings)) {
340
+ const previousCompactionId = getLatestCompactionEntry(this.sessionManager.getBranch())?.id;
341
+ await this._runAutoCompaction("threshold", true);
342
+ const currentCompaction = getLatestCompactionEntry(this.sessionManager.getBranch());
343
+ if (currentCompaction && currentCompaction.id !== previousCompactionId) {
344
+ previousContext = { ...previousContext, messages: this.agent.state.messages.slice() };
345
+ }
346
+ }
334
347
  return {
335
348
  ...previousSnapshot,
336
349
  context: {
@@ -1517,14 +1530,48 @@ export class AgentSession {
1517
1530
  // =========================================================================
1518
1531
  // Compaction
1519
1532
  // =========================================================================
1533
+ _latestCompactionResult() {
1534
+ const pathEntries = this.sessionManager.getBranch();
1535
+ const lastEntry = pathEntries[pathEntries.length - 1];
1536
+ if (lastEntry?.type !== "compaction")
1537
+ return undefined;
1538
+ return {
1539
+ summary: lastEntry.summary,
1540
+ firstKeptEntryId: lastEntry.firstKeptEntryId,
1541
+ tokensBefore: lastEntry.tokensBefore,
1542
+ estimatedTokensAfter: estimateMessagesTokens(this.sessionManager.buildSessionContext().messages),
1543
+ details: lastEntry.details,
1544
+ };
1545
+ }
1520
1546
  /**
1521
1547
  * Manually compact the session context.
1522
1548
  * Aborts current agent operation first.
1523
1549
  * @param customInstructions Optional instructions for the compaction summary
1524
1550
  */
1525
1551
  async compact(customInstructions) {
1552
+ const existing = this._latestCompactionResult();
1553
+ if (existing)
1554
+ return existing;
1555
+ if (this._manualCompactionPromise)
1556
+ return this._manualCompactionPromise;
1557
+ const promise = this._compact(customInstructions);
1558
+ this._manualCompactionPromise = promise;
1559
+ try {
1560
+ return await promise;
1561
+ }
1562
+ finally {
1563
+ if (this._manualCompactionPromise === promise)
1564
+ this._manualCompactionPromise = undefined;
1565
+ }
1566
+ }
1567
+ async _compact(customInstructions) {
1526
1568
  this._disconnectFromAgent();
1527
1569
  await this.abort();
1570
+ const existing = this._latestCompactionResult();
1571
+ if (existing) {
1572
+ this._reconnectToAgent();
1573
+ return existing;
1574
+ }
1528
1575
  this._compactionAbortController = new AbortController();
1529
1576
  this._emit({ type: "compaction_start", reason: "manual" });
1530
1577
  try {
@@ -1743,12 +1790,11 @@ export class AgentSession {
1743
1790
  * Internal: Run auto-compaction with events.
1744
1791
  */
1745
1792
  async _runAutoCompaction(reason, willRetry) {
1793
+ if (!this.model || this._compactionAbortController || this._autoCompactionAbortController)
1794
+ return false;
1746
1795
  const settings = this.settingsManager.getCompactionSettings();
1747
1796
  let started = false;
1748
1797
  try {
1749
- if (!this.model) {
1750
- return false;
1751
- }
1752
1798
  let apiKey;
1753
1799
  let headers;
1754
1800
  let env;