• Will Chen's avatar
    feat: add context compaction system for local-agent mode (#2515) · d857371a
    Will Chen 提交于
    Automatically compact long conversations when approaching context window
    limits (80% of model context or 180k tokens, whichever is first).
    
    Changes:
    - Add enableContextCompaction setting (default: enabled) in Settings >
    AI
    - Add database fields to track compaction state and backup paths
    - Create compaction handler that generates structured summaries via LLM
    - Store original messages in app data directory before compaction
    - Show visual indicator using dyad-status tag when compaction occurs
    - Integrate compaction checks into local_agent_handler
    <!-- devin-review-badge-begin -->
    
    ---
    
    <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2515"
    target="_blank">
      <picture>
    <source media="(prefers-color-scheme: dark)"
    srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
    <img
    src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
    alt="Open with Devin">
      </picture>
    </a>
    <!-- devin-review-badge-end -->
    
    <!-- CURSOR_SUMMARY -->
    ---
    
    > [!NOTE]
    > **Medium Risk**
    > Touches core `local-agent` chat streaming and adds new
    persistence/migration paths plus LLM-driven summarization, so
    regressions could affect message ordering/history sent to models. Scoped
    behind a setting (default on) with added unit/E2E tests, reducing risk.
    > 
    > **Overview**
    > Adds **automatic context compaction** for `local-agent` chats: when
    token usage crosses a threshold, the chat is marked for compaction and
    the next turn generates an LLM summary, stores an XML transcript backup
    under `.dyad/chats/<id>/compaction-*.md`, and inserts a
    `is_compaction_summary` assistant message with a new `<dyad-compaction>`
    indicator.
    > 
    > Introduces a user-facing toggle `enableContextCompaction` (default on)
    wired into settings schema/defaults/search and Settings UI, plus new DB
    fields on `chats` (`pending_compaction`, `compacted_at`,
    `compaction_backup_path`) and `messages` (`is_compaction_summary`).
    Updates local-agent streaming to (a) run pending compaction before
    processing, (b) send only post-compaction history to the LLM, and (c)
    update the correct placeholder message by ID to avoid overwriting the
    compaction summary; includes new unit/E2E coverage and test-fixture
    support for streaming usage data/snapshot scrubbing.
    > 
    > <sup>Written by [Cursor
    Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
    df1cdaacbe3e9f3fb47473a3e6965e302a75fe7a. This will update automatically
    on new commits. Configure
    [here](https://cursor.com/dashboard?tab=bugbot).</sup>
    <!-- /CURSOR_SUMMARY -->
    
    <!-- This is an auto-generated description by cubic. -->
    ---
    ## Summary by cubic
    Adds automatic context compaction for local-agent mode to summarize long
    conversations when token usage reaches 80% of the model’s context window
    or 180k tokens. Original messages are preserved and backed up, a
    structured summary is inserted, and a dyad-compaction indicator is
    shown.
    
    - **New Features**
    - New toggle in Settings > AI: enableContextCompaction (default on) with
    UI switch and searchable setting.
    - DB fields to track compaction and backups (chats: compacted_at,
    compaction_backup_path, pending_compaction; messages:
    is_compaction_summary).
    - Compaction handler backs up LLM-visible messages to
    .dyad/chats/<chatId>/compaction-*.md, generates structured summaries
    with a system prompt, inserts a summary message, and emits
    chat:compaction:complete.
    - Local-agent flow: pending compaction runs at the start of the next
    turn; LLM history includes only post-compaction messages; streaming
    updates target the placeholder message by ID to avoid overwriting the
    summary.
    - Token threshold checks integrated into local_agent_handler (min(80% of
    context window, 180k)).
    
    <sup>Written for commit df1cdaacbe3e9f3fb47473a3e6965e302a75fe7a.
    Summary will update on new commits.</sup>
    
    <!-- End of auto-generated description by cubic. -->
    
    ---------
    Co-authored-by: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
    d857371a
名称
最后提交
最后更新
.claude 正在载入提交数据...
.cursor/rules 正在载入提交数据...
.devcontainer 正在载入提交数据...
.github 正在载入提交数据...
.husky 正在载入提交数据...
.storybook 正在载入提交数据...
assets 正在载入提交数据...
docs 正在载入提交数据...
drizzle 正在载入提交数据...
e2e-tests 正在载入提交数据...
makers 正在载入提交数据...
packages/@dyad-sh 正在载入提交数据...
scaffold 正在载入提交数据...
scripts 正在载入提交数据...
shared 正在载入提交数据...
src 正在载入提交数据...
testing 正在载入提交数据...
tools 正在载入提交数据...
worker 正在载入提交数据...
workers/tsc 正在载入提交数据...
.cursorignore 正在载入提交数据...
.env.example 正在载入提交数据...
.eslintrc.json 正在载入提交数据...
.gitattributes 正在载入提交数据...
.gitignore 正在载入提交数据...
.oxfmtrc.json 正在载入提交数据...
.oxlintrc.json 正在载入提交数据...
.prettierignore 正在载入提交数据...
.prettierrc 正在载入提交数据...
AGENTS.md 正在载入提交数据...
CLA.md 正在载入提交数据...
CLAUDE.md 正在载入提交数据...
CONTRIBUTING.md 正在载入提交数据...
LICENSE 正在载入提交数据...
README.md 正在载入提交数据...
SECURITY.md 正在载入提交数据...
biome.json 正在载入提交数据...
components.json 正在载入提交数据...
drizzle.config.ts 正在载入提交数据...
forge.config.ts 正在载入提交数据...
forge.env.d.ts 正在载入提交数据...
index.html 正在载入提交数据...
lint-staged.config.js 正在载入提交数据...
merge.config.ts 正在载入提交数据...
package-lock.json 正在载入提交数据...
package.json 正在载入提交数据...
playwright.config.ts 正在载入提交数据...
tsconfig.app.json 正在载入提交数据...
tsconfig.json 正在载入提交数据...
tsconfig.node.json 正在载入提交数据...
vite.main.config.mts 正在载入提交数据...
vite.preload.config.mts 正在载入提交数据...
vite.renderer.config.mts 正在载入提交数据...
vite.worker.config.mts 正在载入提交数据...
vitest.config.ts 正在载入提交数据...
windowsSign.ts 正在载入提交数据...