Repository navigation
feat(mpp-idea): implement Knowledge Agent functionality - #10
Conversation
Add Knowledge Agent feature to mpp-idea, aligned with mpp-ui's DocumentReaderViewModel. New files: - IdeaKnowledgeModels.kt: State and data models for Knowledge Agent - IdeaKnowledgeViewModel.kt: ViewModel with DocumentAgent integration - IdeaKnowledgeContent.kt: Three-panel UI (document list, viewer, AI chat) Features: - Project document scanning (md, pdf, docx, kt, java, py, etc.) - Document content viewing with line numbers and TOC navigation - AI-powered document querying via DocumentAgent - LLM configuration via shared ConfigManager Modified files: - IdeaAgentApp.kt: Integrate Knowledge tab with IdeaKnowledgeContent - IdeaComposeIcons.kt: Add Refresh, Description, Code, Delete icons Reuses mpp-core components: - DocumentAgent, DocumentRegistry, DocumentParserFactory - ConfigManager for LLM configuration - JewelRenderer for agent output rendering
|
Caution Review failedThe pull request is closed. WalkthroughAdds a Knowledge agent feature: a new composable UI, view model, domain models, and icons, integrated into the Idea toolwindow to load, search, navigate project documents and provide AI chat over document content. Changes
Sequence Diagram(s)sequenceDiagram
participant UI as IdeaKnowledgeContent (UI)
participant VM as IdeaKnowledgeViewModel (ViewModel)
participant Reg as DocumentRegistry (Storage)
participant Agent as DocumentAgent (LLM)
participant Rend as JewelRenderer (Renderer)
Note over VM: Initialization
VM->>Reg: scan & register project documents
Reg-->>VM: indexed documents
UI->>VM: selectDocument(doc)
VM->>Reg: load document content & TOC
Reg-->>VM: content, toc
VM-->>UI: update state (content, toc)
UI->>VM: sendMessage(text)
VM->>Agent: query with document context (streaming)
Agent->>Rend: render/format response chunks
Rend-->>VM: formatted chunks
VM-->>UI: stream chat messages
UI->>VM: navigateToLine(lineNo)
VM-->>UI: update highlight & scroll
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Comment |
| if (projectPath.isEmpty()) { | ||
| updateState { it.copy(error = "No project path available") } | ||
| } else { | ||
| coroutineScope.launch { |
There was a problem hiding this comment.
initializeLLMService() and loadDocuments() perform IO-heavy work; launching them on the UI/EDT coroutine scope can freeze the IDE — consider moving this initialization to a background task with proper progress indicator and IO dispatcher. (Guideline: edt_violations: edt_violations; background_task_handling: background_task_handling)
🤖 Was this useful? React with 👍 or 👎
| ) | ||
| ) | ||
|
|
||
| val (content, parsedDoc) = if (isBinary) { |
There was a problem hiding this comment.
File reads and document parsing happen in the same scope as UI (reading bytes/text and parsing); please ensure these run off the EDT to avoid UI stalls, especially for large files. This also applies to project scans and refresh flows. (Guideline: edt_violations: edt_violations; background_task_handling: background_task_handling)
🤖 Was this useful? React with 👍 or 👎
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt (1)
195-199: Consider improving selection visual distinction.The selected item uses the same
panelBackgroundcolor with only an alpha change (0.8f vs 1.0f), which may not provide sufficient visual distinction for selection state.val backgroundColor = if (isSelected) { - JewelTheme.globalColors.panelBackground.copy(alpha = 0.8f) + AutoDevColors.Blue.c400.copy(alpha = 0.15f) } else { JewelTheme.globalColors.panelBackground }mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt (1)
111-119: Consider removing unusedIdeaDocumentIndexRecord.This data class is defined but not used in the current implementation. If it's planned for future indexing features, consider adding a TODO comment; otherwise, it could be removed to reduce unused code.
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt (1)
276-308: Avoid rendering error message for intentional cancellation.When the user cancels generation, showing "Generation cancelled by user" as an error via
renderError()may be confusing since it's an intentional action, not an error condition.} catch (e: CancellationException) { renderer.forceStop() - renderer.renderError("Generation cancelled by user") + // Intentional cancellation - no error message needed } catch (e: Exception) { renderer.renderError("Error: ${e.message}") } finally {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaAgentApp.kt(5 hunks)mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaComposeIcons.kt(1 hunks)mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt(1 hunks)mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt(1 hunks)mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.kt
📄 CodeRabbit inference engine (AGENTS.md)
Use
expect/actualfor platform-specific code in KMP projects (e.g., file I/O on JVM/JS/Wasm)
Files:
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaAgentApp.ktmpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.ktmpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.ktmpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaComposeIcons.ktmpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt
🧠 Learnings (1)
📚 Learning: 2025-11-30T02:30:49.805Z
Learnt from: CR
Repo: phodal/auto-dev-sketch PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-30T02:30:49.805Z
Learning: Applies to **/src/{androidMain,desktopMain}/**/*.kt : For Compose (Desktop/Android), use `AutoDevColors` from `cc.unitmesh.devins.ui.compose.theme` or `MaterialTheme.colorScheme`
Applied to files:
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Build (223)
- GitHub Check: Build (241)
🔇 Additional comments (16)
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaAgentApp.kt (6)
27-28: LGTM!Imports for the new Knowledge Agent components are correctly added.
73-74: LGTM!Lazy initialization pattern for
knowledgeViewModelmirrors the existingcodeReviewViewModelpattern, maintaining consistency.
91-93: LGTM!ViewModel creation is correctly triggered when switching to the KNOWLEDGE tab, consistent with the CODE_REVIEW pattern.
96-108: Disposal logic works correctly but could be clearer.The
DisposableEffectcorrectly disposes ViewModels when switching tabs. WhencurrentAgentTypechanges,onDisposeruns with the new value, so the conditional checks correctly dispose the previous tab's ViewModel. This matches the existing CODE_REVIEW pattern and is functionally correct.
144-148: LGTM!Content switch correctly renders
IdeaKnowledgeContentwhen the Knowledge tab is active, with a loading fallback while the ViewModel initializes.
232-233: LGTM!Comment correctly documents that KnowledgeContent implementation moved to a separate file.
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaComposeIcons.kt (1)
184-331: LGTM!The four new icons (Refresh, Description, Code, Delete) follow the established pattern with lazy initialization, consistent 24dp sizing, and proper KDoc documentation. These icons correctly support the new Knowledge UI components.
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt (4)
31-81: LGTM!The main
IdeaKnowledgeContentcomposable properly structures the three-panel layout with document list, content viewer, and AI chat. State collection from the ViewModel is correctly implemented usingcollectAsState().
357-408: LGTM!Content viewer with line numbers is well implemented. The
remember(content)optimization for line splitting, auto-scroll viaLaunchedEffect, and highlight logic for both target line and text matches are correctly handled. Based on learnings, the use ofAutoDevColors.Yellow.c400for highlighting follows the design system conventions.
429-577: LGTM!The AI chat panel correctly implements message display, auto-scroll, input handling, and generation state management. The empty state with example prompts provides good UX guidance.
582-734: LGTM!
ChatMessageItemcomprehensively handles allTimelineItemvariants with appropriate styling. The use ofAutoDevColorsfor status indicators (Green, Red, Cyan, Neutral) aligns with the design system per learnings.mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt (2)
12-39: LGTM!
IdeaKnowledgeStateis well-structured with clear separation of document management, loading states, navigation, and error handling. The immutable data class design is appropriate for Compose state management.
45-71: LGTM!
IdeaDocumentFilecorrectly wraps mpp-core'sDocumentFilewith a clean factory method. StoringformatTypeas String (line 64) simplifies serialization for the plugin layer.mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt (3)
120-157: LGTM!Document scanning is well-implemented with appropriate file filtering (excluding
.git,node_modules,build,target) and a sensible 1000-file limit. The extension whitelist covers common document and code file types.
345-359: LGTM!TOC navigation correctly handles both line number-based navigation and fallback regex search for heading text when line numbers are unavailable. The regex pattern properly matches Markdown headings.
194-271: LGTM!Document content loading handles both binary and text formats appropriately, with proper error handling for missing files and unavailable parsers. The document registration with
DocumentRegistryenables DocQL queries.
Fixes based on review feedback: 1. EDT violations - Move IO-heavy operations to Dispatchers.IO: - initializeLLMService() and loadDocuments() in init block - selectDocument() file loading - File read/parse operations in loadDocumentContent() - refreshDocuments() document scanning 2. Init coroutine tracking - Store initJob for proper disposal: - Add initJob property to track init coroutine - Cancel initJob in dispose() - Handle CancellationException in init block 3. Cancellation handling - Remove error message for intentional cancellation: - Change renderError() to comment for CancellationException in sendMessage() 4. Selection visual distinction - Improve selected item highlighting: - Use AutoDevColors.Blue.c400.copy(alpha = 0.15f) for better visibility 5. Unused code - Comment out IdeaDocumentIndexRecord: - Add TODO comment for future indexing feature
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt(1 hunks)mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt(1 hunks)mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.kt
📄 CodeRabbit inference engine (AGENTS.md)
Use
expect/actualfor platform-specific code in KMP projects (e.g., file I/O on JVM/JS/Wasm)
Files:
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.ktmpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.ktmpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt
🧠 Learnings (1)
📚 Learning: 2025-11-30T02:30:49.805Z
Learnt from: CR
Repo: phodal/auto-dev-sketch PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-30T02:30:49.805Z
Learning: Applies to **/src/{androidMain,desktopMain}/**/*.kt : For Compose (Desktop/Android), use `AutoDevColors` from `cc.unitmesh.devins.ui.compose.theme` or `MaterialTheme.colorScheme`
Applied to files:
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt
🔇 Additional comments (5)
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt (1)
1-122: LGTM! Clean data model definitions.The state models, document representations, and indexing types are well-structured and appropriate for the Knowledge Agent feature. The factory method
fromDocumentFileprovides a clean conversion from the coreDocumentFiletype to the IDEA-specific representation.mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt (1)
17-17: Correct use of AutoDevColors for theming.The UI correctly uses
AutoDevColorsfromcc.unitmesh.devins.ui.compose.themethroughout for consistent theming, as per best practices for Compose Desktop components.Based on learnings, this aligns with the recommended theming approach.
Also applies to: 196-196, 387-387, 595-595
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt (3)
47-66: EDT violations properly addressed.The initialization now correctly runs on
Dispatchers.IO(line 55) and theinitJobis tracked and cancelled indispose()(lines 396-397). This addresses the previous review comments about EDT violations and untracked coroutines.The
CancellationExceptionhandling on lines 59-60 is also appropriate for intentional cancellations during disposal.
189-194: Proper IO dispatcher usage for file operations.Document selection (line 191) and refresh (line 386) correctly launch on
Dispatchers.IOto avoid blocking the UI thread during file system operations. This follows IntelliJ threading best practices.Also applies to: 384-389
281-316: Well-managed coroutine lifecycle.The message sending, generation control, and chat history management properly handle:
- Job cancellation and tracking (lines 287, 313, 322, 333)
CancellationExceptionfor intentional cancellations (lines 306-308)- State updates and renderer cleanup
The implementation correctly separates concerns between coroutine control and UI state updates.
Also applies to: 318-336
Use coerceAtLeast(1) to prevent IllegalArgumentException when tocItem.level is zero or negative in repeat() call.
Summary
Add Knowledge Agent feature to mpp-idea, aligned with mpp-ui's
DocumentReaderViewModelandDocumentAgent.Changes
New Files
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/
IdeaKnowledgeModels.kt- State and data models for Knowledge AgentIdeaKnowledgeState: Main state containerIdeaDocumentFile: Document file representationIdeaDocumentMetadata: Document metadataIndexingProgress/IndexingStatus: Indexing progress trackingIdeaKnowledgeViewModel.kt- ViewModel with DocumentAgent integrationConfigManagerDocumentAgentfor document queriesIdeaKnowledgeContent.kt- Three-panel Compose UIModified Files
IdeaAgentApp.kt: Integrate Knowledge tab withIdeaKnowledgeContentIdeaComposeIcons.kt: Add Refresh, Description, Code, Delete iconsCode Reuse from mpp-ui/mpp-core
DocumentAgent(mpp-core) - Document query agent with DocQL supportDocumentRegistryandDocumentParserFactory(mpp-core) - Document parsing infrastructureConfigManager(mpp-ui) - LLM configuration managementJewelRenderer(mpp-idea) - Similar to mpp-ui's ComposeRendererAutoDevColors(mpp-ui) - Design system colorsScreenshots
The Knowledge tab now shows a three-panel layout:
Testing
Manual testing recommended:
Pull Request opened by Augment Code with guidance from the PR author
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.