feat(agent): add manual compaction command#1619
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a DeepChat-only ChangesManual Compaction Command Feature
Sequence Diagram(s)sequenceDiagram
participant User as User/ChatPage
participant Client as SessionClient
participant IPC as IPC Bridge
participant Dispatcher as Dispatcher
participant Presenter as AgentSessionPresenter
participant Runtime as AgentRuntimePresenter
participant Service as CompactionService
participant DB as Session Storage
User->>Client: /compact command detected
Client->>IPC: invoke sessions.compact route
IPC->>Dispatcher: route to dispatchDeepchatRoute
Dispatcher->>Presenter: compactSession(sessionId)
Presenter->>Runtime: agent.compactSession(sessionId)
Runtime->>Service: prepareForManualCompaction()
Service->>DB: load context-history, sort by order
Service->>Service: prepareCompaction(protectedTurns:0, force:true)
Service-->>Runtime: CompactionIntent | null
alt Intent exists
Runtime->>DB: applyCompactionIntent()
Runtime-->>Presenter: { compacted: true, state }
else No intent
Runtime-->>Presenter: { compacted: false, state }
end
Presenter-->>Dispatcher: return result
Dispatcher-->>IPC: validated output
IPC-->>Client: { compacted, state }
Client->>User: refresh messages / show toast
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/presenter/agentRuntimePresenter/index.ts`:
- Around line 1629-1671: compactSession runs multiple awaits before calling
this.setSessionStatus(sessionId, 'generating'), allowing concurrent
sends/resumes to interleave; acquire the session-level "generating" lock or set
the generating status atomically before any awaited prep work (i.e. before
getEffectiveSessionGenerationSettings / resolveInterleavedReasoningConfig /
resolveDeepChatContextBudgetLength / capAgentRequestMaxTokens /
resolveActiveSkillNamesForToolProfile / resolveProjectDir /
loadToolDefinitionsForSession / buildSystemPromptWithSkills and the call to
compactionService.prepareForManualCompaction), and ensure you release or revert
that lock/status if prepareForManualCompaction returns no intent or on error so
you don't leave the session stuck (use the existing session lock API or move
this.setSessionStatus(sessionId, 'generating') up and add proper cleanup).
In `@src/renderer/src/components/chat/composables/useChatInputMentions.ts`:
- Around line 198-200: The hardcoded fallback string passed into
createManualCompactionSuggestion (options.compactCommandDescription?.value ??
'Compact conversation context') must be replaced with an i18n lookup; change the
fallback to use the component's i18n translator (e.g.,
useI18n().t('your.key.for.compactConversationContext')) so that when
options.compactCommandDescription is missing the user-facing text comes from the
i18n keys, not a raw English string; update the call site around
createManualCompactionSuggestion and ensure you import/use the same i18n
instance used elsewhere in this file.
In `@src/shared/types/presenters/agent-session.presenter.d.ts`:
- Line 104: Typo in the compactSession return type: change the misspelled
property name "compated" to "compacted" in the compactSession declaration so it
returns a Promise with a boolean "compacted" and the existing
SessionCompactionState; update the compactSession signature in
agent-session.presenter (and any related type/implementation that declare the
same shape) to use "compacted" to match consumers and implementations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f62c17ef-ee48-4a7f-8efe-00bb06d8b9ec
📒 Files selected for processing (38)
docs/features/manual-compaction-command/plan.mddocs/features/manual-compaction-command/spec.mddocs/features/manual-compaction-command/tasks.mdsrc/main/presenter/agentRuntimePresenter/compactionService.tssrc/main/presenter/agentRuntimePresenter/index.tssrc/main/presenter/agentSessionPresenter/index.tssrc/main/routes/index.tssrc/renderer/api/SessionClient.tssrc/renderer/src/components/chat/ChatInputBox.vuesrc/renderer/src/components/chat/composables/useChatInputMentions.tssrc/renderer/src/components/chat/mentions/utils.tssrc/renderer/src/i18n/da-DK/chat.jsonsrc/renderer/src/i18n/en-US/chat.jsonsrc/renderer/src/i18n/fa-IR/chat.jsonsrc/renderer/src/i18n/fr-FR/chat.jsonsrc/renderer/src/i18n/he-IL/chat.jsonsrc/renderer/src/i18n/ja-JP/chat.jsonsrc/renderer/src/i18n/ko-KR/chat.jsonsrc/renderer/src/i18n/pt-BR/chat.jsonsrc/renderer/src/i18n/ru-RU/chat.jsonsrc/renderer/src/i18n/zh-CN/chat.jsonsrc/renderer/src/i18n/zh-HK/chat.jsonsrc/renderer/src/i18n/zh-TW/chat.jsonsrc/renderer/src/pages/ChatPage.vuesrc/renderer/src/pages/NewThreadPage.vuesrc/shared/contracts/common.tssrc/shared/contracts/routes.tssrc/shared/contracts/routes/sessions.routes.tssrc/shared/types/agent-interface.d.tssrc/shared/types/presenters/agent-session.presenter.d.tstest/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.tstest/main/presenter/agentRuntimePresenter/compactionService.test.tstest/main/routes/contracts.test.tstest/main/routes/dispatcher.test.tstest/renderer/components/ChatPage.test.tstest/renderer/components/MessageList.test.tstest/renderer/components/NewThreadPage.test.tstest/renderer/composables/useChatInputMentions.test.ts
| createManualCompactionSuggestion( | ||
| options.compactCommandDescription?.value ?? 'Compact conversation context' | ||
| ) |
There was a problem hiding this comment.
Avoid hardcoded fallback for command description.
Line 199 falls back to a raw English string ('Compact conversation context'). This is user-facing and should come from i18n keys only.
Suggested fix
- createManualCompactionSuggestion(
- options.compactCommandDescription?.value ?? 'Compact conversation context'
- )
+ createManualCompactionSuggestion(options.compactCommandDescription?.value ?? '')As per coding guidelines, "All user-facing strings must use vue-i18n keys from src/renderer/src/i18n instead of hardcoded text".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/renderer/src/components/chat/composables/useChatInputMentions.ts` around
lines 198 - 200, The hardcoded fallback string passed into
createManualCompactionSuggestion (options.compactCommandDescription?.value ??
'Compact conversation context') must be replaced with an i18n lookup; change the
fallback to use the component's i18n translator (e.g.,
useI18n().t('your.key.for.compactConversationContext')) so that when
options.compactCommandDescription is missing the user-facing text comes from the
i18n keys, not a raw English string; update the call site around
createManualCompactionSuggestion and ensure you import/use the same i18n
instance used elsewhere in this file.
| ): Promise<ChatMessagePageResult> | ||
| searchHistory(query: string, options?: HistorySearchOptions): Promise<HistorySearchHit[]> | ||
| getSessionCompactionState(sessionId: string): Promise<SessionCompactionState> | ||
| compactSession(sessionId: string): Promise<{ compacted: boolean; state: SessionCompactionState }> |
There was a problem hiding this comment.
Fix typo in return type property name.
The return type contains a spelling error: compated should be compacted. This typo will cause type errors throughout the codebase where implementations and consumers use the correct spelling.
🐛 Proposed fix
- compactSession(sessionId: string): Promise<{ compated: boolean; state: SessionCompactionState }>
+ compactSession(sessionId: string): Promise<{ compacted: boolean; state: SessionCompactionState }>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| compactSession(sessionId: string): Promise<{ compacted: boolean; state: SessionCompactionState }> | |
| compactSession(sessionId: string): Promise<{ compacted: boolean; state: SessionCompactionState }> |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/shared/types/presenters/agent-session.presenter.d.ts` at line 104, Typo
in the compactSession return type: change the misspelled property name
"compated" to "compacted" in the compactSession declaration so it returns a
Promise with a boolean "compacted" and the existing SessionCompactionState;
update the compactSession signature in agent-session.presenter (and any related
type/implementation that declare the same shape) to use "compacted" to match
consumers and implementations.
Summary
/compactslash command and typedsessions.compactroute/compactduring generation without disabling other slash completions, and keep ACP/new-thread behavior unchangedCloses #1618
Tests
pnpm run formatpnpm run i18npnpm run lintpnpm run typecheckpnpm exec vitest run test/renderer/components/ChatPage.test.ts test/renderer/components/NewThreadPage.test.ts test/renderer/composables/useChatInputMentions.test.ts test/renderer/components/MessageList.test.ts test/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.ts test/main/presenter/agentRuntimePresenter/compactionService.test.ts test/main/routes/contracts.test.ts test/main/routes/dispatcher.test.tsSummary by CodeRabbit
New Features
/compactslash command to manually compress conversation context for idle sessions (runs without sending a user message).Improvements
Documentation
Tests