Skip to content

feat(mpp-idea): implement Knowledge Agent functionality - #10

Merged
phodal merged 3 commits into
masterfrom
feat/mpp-idea-knowledge-agent
Nov 30, 2025
Merged

phodal merged 3 commits into
masterfrom
feat/mpp-idea-knowledge-agent

Conversation

@phodal

@phodal phodal commented Nov 30, 2025 •

Copy link
Copy Markdown
Member

Summary

Add Knowledge Agent feature to mpp-idea, aligned with mpp-ui's DocumentReaderViewModel and DocumentAgent.

Changes

New Files

mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/

  • IdeaKnowledgeModels.kt - State and data models for Knowledge Agent

    • IdeaKnowledgeState: Main state container
    • IdeaDocumentFile: Document file representation
    • IdeaDocumentMetadata: Document metadata
    • IndexingProgress / IndexingStatus: Indexing progress tracking
  • IdeaKnowledgeViewModel.kt - ViewModel with DocumentAgent integration

    • Initialize platform-specific parsers (Tika on JVM)
    • Load LLM configuration via shared ConfigManager
    • Create DocumentAgent for document queries
    • Scan project documents (supports md, pdf, docx, kt, java, py, etc.)
    • Load and parse document content
    • Send messages to DocumentAgent
    • Navigate to TOC items and specific line numbers
  • IdeaKnowledgeContent.kt - Three-panel Compose UI

    • Left: Document list with search functionality
    • Center: Document content viewer with TOC and line numbers
    • Right: AI Chat interface for document queries

Modified Files

  • IdeaAgentApp.kt: Integrate Knowledge tab with IdeaKnowledgeContent
  • IdeaComposeIcons.kt: Add Refresh, Description, Code, Delete icons

Code Reuse from mpp-ui/mpp-core

  • DocumentAgent (mpp-core) - Document query agent with DocQL support
  • DocumentRegistry and DocumentParserFactory (mpp-core) - Document parsing infrastructure
  • ConfigManager (mpp-ui) - LLM configuration management
  • JewelRenderer (mpp-idea) - Similar to mpp-ui's ComposeRenderer
  • AutoDevColors (mpp-ui) - Design system colors

Screenshots

The Knowledge tab now shows a three-panel layout:

  1. Document list with search
  2. Document content with line numbers and TOC navigation
  3. AI chat interface for document queries

Testing

Manual testing recommended:

  1. Open IntelliJ IDEA with the plugin
  2. Navigate to the Knowledge tab
  3. Browse and select documents
  4. Ask questions about document content

Pull Request opened by Augment Code with guidance from the PR author

Summary by CodeRabbit

  • New Features
    • Knowledge Agent: project document indexing, search, and full-text results with indexing progress indicators.
    • Three-pane interface: searchable/refreshable document list, content viewer with TOC and line highlighting/navigation, and AI chat panel with streaming responses.
    • Chat controls: send, stop generation, and clear history.
    • New UI icons for refresh, document, code, and delete actions.

✏️ Tip: You can customize this high-level summary in your review settings.

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
@coderabbitai

coderabbitai Bot commented Nov 30, 2025 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Adds 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

Cohort / File(s) Summary
Toolwindow Integration
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaAgentApp.kt
Added lazy knowledgeViewModel initialization, disposal when leaving KNOWLEDGE tab, and conditional rendering of IdeaKnowledgeContent with a loading guard.
Icon Library
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaComposeIcons.kt
Added four new ImageVector icons: Refresh, Description, Code, and Delete (24×24 dp, lazy-initialized).
Knowledge UI Component
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt
New public composable IdeaKnowledgeContent(...) implementing a three-pane UI (document list with search/refresh, content viewer with TOC/line highlighting, and AI chat panel with streaming messages).
Knowledge State & Models
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt
Added data models and enums: IdeaKnowledgeState, IdeaDocumentFile (with fromDocumentFile), IdeaDocumentMetadata, IndexingProgress, and IndexingStatus (plus placeholder index record).
Knowledge ViewModel
mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeViewModel.kt
New IdeaKnowledgeViewModel (implements Disposable) managing document scanning/loading, Koog/DocumentAgent setup, state flow, search/selection/navigation, chat messaging and streaming control, and lifecycle disposal.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

  • Focus review on:
    • IdeaKnowledgeViewModel.kt — coroutine usage, dispatchers, cancellation, resource disposal.
    • IdeaKnowledgeContent.kt — composable state handling, streaming UI, and event wiring.
    • IdeaKnowledgeModels.kt — correctness of model conversion (fromDocumentFile) and metadata fields.

Possibly related PRs

Poem

🐰
I nibble lines and hop through docs,
TOCs and highlights, little mental shocks.
I fetch, I chat, I refresh with glee,
Icons shine bright, knowledge for me —
A hopping helper, happy as can be 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and accurately summarizes the main change: implementing Knowledge Agent functionality, which aligns with all the new features added (models, view model, UI content, and integration).

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19bd676 and 1624e6b.

📒 Files selected for processing (1)
  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt (1 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Comment augment review to trigger a new review at any time.

if (projectPath.isEmpty()) {
updateState { it.copy(error = "No project path available") }
} else {
coroutineScope.launch {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👎

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 panelBackground color 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 unused IdeaDocumentIndexRecord.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c30107e and dde5b04.

📒 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/actual for 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.kt
  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt
  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeContent.kt
  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/IdeaComposeIcons.kt
  • mpp-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 knowledgeViewModel mirrors the existing codeReviewViewModel pattern, 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 DisposableEffect correctly disposes ViewModels when switching tabs. When currentAgentType changes, onDispose runs 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 IdeaKnowledgeContent when 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 IdeaKnowledgeContent composable properly structures the three-panel layout with document list, content viewer, and AI chat. State collection from the ViewModel is correctly implemented using collectAsState().


357-408: LGTM!

Content viewer with line numbers is well implemented. The remember(content) optimization for line splitting, auto-scroll via LaunchedEffect, and highlight logic for both target line and text matches are correctly handled. Based on learnings, the use of AutoDevColors.Yellow.c400 for 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!

ChatMessageItem comprehensively handles all TimelineItem variants with appropriate styling. The use of AutoDevColors for 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!

IdeaKnowledgeState is 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!

IdeaDocumentFile correctly wraps mpp-core's DocumentFile with a clean factory method. Storing formatType as 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 DocumentRegistry enables 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dde5b04 and 19bd676.

📒 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/actual for 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.kt
  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/toolwindow/knowledge/IdeaKnowledgeModels.kt
  • mpp-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 fromDocumentFile provides a clean conversion from the core DocumentFile type 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 AutoDevColors from cc.unitmesh.devins.ui.compose.theme throughout 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 the initJob is tracked and cancelled in dispose() (lines 396-397). This addresses the previous review comments about EDT violations and untracked coroutines.

The CancellationException handling 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.IO to 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)
  • CancellationException for 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant