Skip to content

Conversation

@zerob13
Copy link
Collaborator

@zerob13 zerob13 commented Dec 11, 2025

Summary by CodeRabbit

  • New Features

    • Automatic ACP cleanup on app shutdown and a new helper to retrieve existing provider instances.
  • Bug Fixes

    • Safer provider lookups to avoid runtime errors if lookup methods are absent.
    • Graceful ACP shutdown handling with forced termination and clearer failure reporting.
    • Prevented merging of tool-generated messages with adjacent messages.
  • Tests

    • Added unit tests covering ACP shutdown and error-handling scenarios.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 11, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds safe provider lookups, an ACP before-quit lifecycle hook that invokes provider cleanup, ACP provider cleanup and shutdown-aware error paths, stronger ACP process-manager shutdown/force-kill behavior, a guard preventing merging of tool messages, new provider-instance getters and related typings, and unit tests for the shutdown/error flows.

Changes

Cohort / File(s) Summary
Provider lookup safety
src/main/presenter/configPresenter/index.ts, src/main/presenter/threadPresenter/handlers/utilityHandler.ts
Replaced direct getProviderInstance(...) calls with optional chaining (getProviderInstance?.(...)) and null fallback to avoid runtime errors when the method is absent.
Lifecycle hook
src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts, src/main/presenter/lifecyclePresenter/hooks/index.ts
Added acpCleanupHook (BEFORE_QUIT, priority 6) that kills ACP terminals and invokes provider cleanup() if present; exported the hook.
ACP process manager
src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
Added shuttingDown flag, forceKillAllProcesses(reason) and extended killChild(child, reason?); improved cross-platform termination (Windows taskkill, Unix pkill/SIGTERM) and richer error logging.
Provider instance exposure
src/main/presenter/llmProviderPresenter/index.ts, src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
Added getExistingProviderInstance(providerId) to expose already-instantiated provider instances from the internal map.
AcpProvider enhancements
src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
Added async cleanup() to clear sessions, shut down the process manager, and cancel pending permission requests; made getConnection error handling shutdown-aware.
Session creation shutdown handling
src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
Wrapped processManager.getConnection in try/catch to translate shutting-down errors into a clear "[ACP] Cannot create session: process manager is shutting down" error.
Message merge guard
src/main/presenter/threadPresenter/utils/promptBuilder.ts
Prevented merging of messages with role tool in mergeConsecutiveMessages, preserving tool message boundaries.
Type definitions
src/shared/types/presenters/legacy.presenters.d.ts, src/shared/types/presenters/llmprovider.presenter.d.ts
Added getExistingProviderInstance to ILlmProviderPresenter (optional in legacy types) to expose existing provider lookups.
Tests
test/main/presenter/acpProvider.test.ts, test/main/presenter/acpSessionManager.test.ts, test/main/presenter/llmProviderPresenter.test.ts
New unit tests covering ACP shutdown/error handling in provider, session creation, and warmup behavior.
Manifest
package.json
Manifest included in diff list (no behavioral change).

Sequence Diagram(s)

sequenceDiagram
    participant Lifecycle as Lifecycle Presenter
    participant LLMPres as LLMProviderPresenter
    participant AcpProv as AcpProvider
    participant SessionMgr as SessionManager
    participant ProcMgr as AcpProcessManager

    Lifecycle->>LLMPres: getExistingProviderInstance("acp")
    activate LLMPres
    LLMPres-->>Lifecycle: AcpProvider | undefined
    deactivate LLMPres

    alt provider exists
        Lifecycle->>AcpProv: cleanup()
        activate AcpProv
        AcpProv->>SessionMgr: clearAllSessions()
        activate SessionMgr
        SessionMgr-->>AcpProv: done (errors caught)
        deactivate SessionMgr

        AcpProv->>ProcMgr: shutdown()
        activate ProcMgr
        ProcMgr->>ProcMgr: set shuttingDown = true
        ProcMgr->>ProcMgr: forceKillAllProcesses("shutdown")
        note right of ProcMgr `#ddeeff`: Windows uses taskkill\nUnix uses pkill/SIGTERM
        ProcMgr-->>AcpProv: done (errors caught)
        deactivate ProcMgr

        AcpProv->>AcpProv: resolve pending permission requests as cancelled
        AcpProv-->>Lifecycle: cleanup complete
        deactivate AcpProv
    else provider missing
        Lifecycle-->>Lifecycle: early return (no provider)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect platform-specific termination commands and error handling in acpProcessManager.killChild / forceKillAllProcesses.
  • Verify shutdown ordering and race conditions around shuttingDown, warmupProcess, and warmupAcpProcess catch behavior.
  • Review AcpProvider.cleanup for correct session/permission resolution and safe error swallowing.
  • Check new public method getExistingProviderInstance usage sites and typings consistency.

Possibly related issues

Possibly related PRs

Poem

🐰 I hop where processes sleep and hum,

I chase each pid until it's done,
I tidy sessions, cancel waits,
Close doors at quit, seal all the gates,
A quiet hop — the shutdown's won.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 title 'fix: close app kill all acp processes' directly corresponds to the main changes: implementing process cleanup on app close for ACP (with cross-platform termination logic for Windows/other platforms) and introducing shutdown guards.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/process-not-close-on-windows

📜 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 6f5393b and 3fa08b6.

📒 Files selected for processing (1)
  • src/shared/types/presenters/legacy.presenters.d.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shared/types/presenters/legacy.presenters.d.ts
⏰ 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). (1)
  • GitHub Check: build-check (x64)

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.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/shared/types/presenters/legacy.presenters.d.ts (1)

835-847: Unify ILlmProviderPresenter.getProviderInstance optionality to avoid type conflicts

ILlmProviderPresenter currently declares getProviderInstance both as optional (Line 840) and required (Line 945). TypeScript expects all declarations of the same member to have identical modifiers; mixing optional and required can cause declaration conflicts.

Since call sites are already using optional chaining (e.g. llmProviderPresenter.getProviderInstance?.(...)), it’s more consistent to make the method optional everywhere.

Suggested fix (lower block only):

-  getProviderInstance(providerId: string): unknown
-  getExistingProviderInstance?(providerId: string): unknown
+  getProviderInstance?(providerId: string): unknown
+  getExistingProviderInstance?(providerId: string): unknown

This keeps the earlier optional declarations consistent and avoids conflicting modifiers.

Also applies to: 945-947

🧹 Nitpick comments (4)
src/main/presenter/threadPresenter/handlers/utilityHandler.ts (1)

371-375: Guarded provider lookup improves robustness

Using getProviderInstance?.(...) ?? null avoids a hard crash if the presenter implementation doesn’t expose that method, while still surfacing a clear "Provider ... not found" error. Behavior for normal implementations remains unchanged.

src/main/presenter/configPresenter/index.ts (1)

1193-1207: Defensive ACP provider lookup in config presenter

Switching to presenter?.llmproviderPresenter?.getProviderInstance?.('acp') avoids crashes when the presenter graph isn’t fully wired (e.g. during tests or early startup), while still refreshing agents when the ACP provider exists.

src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts (1)

1-37: ACP cleanup hook correctly avoids new instances during shutdown

The hook cleanly:

  • Kills the ACP init terminal in a guarded block, and
  • Fetches only an already-instantiated ACP provider via getExistingProviderInstance before calling its optional cleanup().

This prevents creating new ACP processes during shutdown and still tears down existing ones, with failures downgraded to warnings so lifecycle shutdown can proceed.

Consider switching the new console.log/console.warn calls to the project’s structured logger if/when one is available in this module, to align with logging guidelines.

src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts (1)

996-999: Centralized, cross‑platform kill logic matches the shutdown goal; consider an optional pkill fallback

Routing both disposeHandle and shutdown() through killChild (via forceKillAllProcesses) gives a single, auditable place for process termination, and the platform split:

  • Windows: taskkill /PID <pid> /T /F plus child.kill()
  • Others: pkill -TERM -P <pid> + process.kill(pid, 'SIGTERM') + child.kill()

should aggressively clean up ACP trees on app shutdown.

One optional hardening you might consider (non‑blocking):

  • If your support matrix includes Unix environments without pkill, wrap that spawn in a small helper that degrades quietly to just process.kill / child.kill() instead of logging repeated warnings when pkill is missing.

Otherwise, this looks consistent with the intent to avoid orphaned ACP processes.

Also applies to: 1035-1070

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b179d97 and 9ea954b.

📒 Files selected for processing (10)
  • src/main/presenter/configPresenter/index.ts (1 hunks)
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts (1 hunks)
  • src/main/presenter/lifecyclePresenter/hooks/index.ts (1 hunks)
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts (5 hunks)
  • src/main/presenter/llmProviderPresenter/index.ts (1 hunks)
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts (1 hunks)
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts (1 hunks)
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts (1 hunks)
  • src/shared/types/presenters/legacy.presenters.d.ts (2 hunks)
  • src/shared/types/presenters/llmprovider.presenter.d.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (21)
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for logs and comments (Chinese text exists in legacy code, but new code should use English)

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Enable and maintain strict TypeScript type checking for all files

**/*.{ts,tsx}: Always use try-catch to handle possible errors in TypeScript code
Provide meaningful error messages when catching errors
Log detailed error logs including error details, context, and stack traces
Distinguish and handle different error types (UserError, NetworkError, SystemError, BusinessError) with appropriate handlers in TypeScript
Use structured logging with logger.error(), logger.warn(), logger.info(), logger.debug() methods from logging utilities
Do not suppress errors (avoid empty catch blocks or silently ignoring errors)
Provide user-friendly error messages for user-facing errors in TypeScript components
Implement error retry mechanisms for transient failures in TypeScript
Avoid logging sensitive information (passwords, tokens, PII) in logs

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/main/presenter/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Organize core business logic into dedicated Presenter classes, with one presenter per functional domain

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
src/main/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Use EventBus from src/main/eventbus.ts for main-to-renderer communication, broadcasting events via mainWindow.webContents.send()

src/main/**/*.ts: Use EventBus pattern for inter-process communication within the main process to decouple modules
Use Electron's built-in APIs for file system and native dialogs instead of Node.js or custom implementations

src/main/**/*.ts: Electron main process code belongs in src/main/ with presenters in presenter/ (Window/Tab/Thread/Mcp/Config/LLMProvider) and eventbus.ts for app events
Use the Presenter pattern in the main process for UI coordination

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Do not include AI co-authoring information (e.g., 'Co-Authored-By: Claude') in git commits

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
**/*.{js,ts,jsx,tsx,mjs,cjs}

📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)

Write logs and comments in English

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
{src/main/presenter/**/*.ts,src/renderer/**/*.ts}

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

Implement proper inter-process communication (IPC) patterns using Electron's ipcRenderer and ipcMain APIs

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
src/**/*

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

New features should be developed in the src directory

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/main/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

Main process code for Electron should be placed in src/main

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
src/**/*.{ts,tsx,vue,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use Prettier with single quotes, no semicolons, and 100 character width

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use OxLint for linting JavaScript and TypeScript files

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.{ts,tsx}: Use camelCase for variable and function names in TypeScript files
Use PascalCase for type and class names in TypeScript
Use SCREAMING_SNAKE_CASE for constant names

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use EventBus for inter-process communication events

Files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/main/presenter/llmProviderPresenter/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/llm-agent-loop.mdc)

Define the standardized LLMCoreStreamEvent interface with fields: type (text | reasoning | tool_call_start | tool_call_chunk | tool_call_end | error | usage | stop | image_data), content (for text), reasoning_content (for reasoning), tool_call_id, tool_call_name, tool_call_arguments_chunk (for streaming), tool_call_arguments_complete (for complete arguments), error_message, usage object with token counts, stop_reason (tool_use | max_tokens | stop_sequence | error | complete), and image_data object with Base64-encoded data and mimeType

Files:

  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
src/main/presenter/configPresenter/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Store and retrieve custom prompts via configPresenter.getCustomPrompts() for config-based data source management

Files:

  • src/main/presenter/configPresenter/index.ts
src/main/presenter/llmProviderPresenter/index.ts

📄 CodeRabbit inference engine (.cursor/rules/llm-agent-loop.mdc)

src/main/presenter/llmProviderPresenter/index.ts: In src/main/presenter/llmProviderPresenter/index.ts (startStreamCompletion), implement the Agent loop that manages the overall conversation flow, including multiple rounds of LLM calls and tool usage, maintaining conversationMessages history, calling provider.coreStream() on each iteration, and controlling the loop using needContinueConversation and toolCallCount (compared against MAX_TOOL_CALLS)
In src/main/presenter/llmProviderPresenter/index.ts, listen for standardized events yielded by coreStream and handle them accordingly: buffer text content (currentContent), handle tool_call_start/chunk/end events by collecting tool details and calling presenter.mcpPresenter.callTool, send frontend events via eventBus with tool call status, format tool results for the next LLM call, and set needContinueConversation = true
In src/main/presenter/llmProviderPresenter/index.ts, handle reasoning, text, image_data, and usage events by processing and forwarding them through STREAM_EVENTS.RESPONSE events to the frontend
In src/main/presenter/llmProviderPresenter/index.ts, handle stop events by checking stop_reason: if 'tool_use', add the buffered assistant message and prepare for the next loop iteration; otherwise, add the final assistant message and exit the loop

Files:

  • src/main/presenter/llmProviderPresenter/index.ts
**/*Provider**/index.ts

📄 CodeRabbit inference engine (.cursor/rules/provider-guidelines.mdc)

**/*Provider**/index.ts: Output only discriminated union LLMCoreStreamEvent in Provider implementations, do not use single interface with optional fields
Use factory methods createStreamEvent.* to construct events in Provider implementations, avoid direct field pollution
Text events: emit multiple text chunks in arrival order
Reasoning events: reasoning is optional; if provided, ensure it contains the complete chain
Tool call events: strictly follow sequence tool_call_start → tool_call_chunk* → tool_call_end, ensure tool_call_id is required and stable
Stop events: emit stop at stream end with stop_reason value from {tool_use, max_tokens, stop_sequence, error, complete}
Usage events: send usage once before or at stream end with prompt_tokens, completion_tokens, and total_tokens
Rate limit events: send rate_limit event when reaching limit threshold with fields {providerId, qpsLimit, currentQps, queueLength, estimatedWaitTime?}, do not block event channel
Error handling: use error event uniformly to carry error messages, avoid mixing errors into other event fields
Error termination: after fatal error occurs, emit stop event as needed and terminate the stream
Image events: image_data event must provide data (Base64 encoded) and mimeType fields; control single frame size and frequency to avoid blocking
Do not emit AssistantMessageBlock or any UI types from Provider implementations to UI layer
Do not introduce renderer dependencies inside Provider implementations
Every event construction in Provider implementations must use factory functions
Tool call IDs in Provider implementations must be globally unique and stable, with chunks arriving strictly in order
Error scenarios in Provider implementations must have corresponding stop_reason and error message
Provider implementations must emit at least one usage event if the provider has statistics capability
Provide rate_limit events in Provider implementations...

Files:

  • src/main/presenter/llmProviderPresenter/index.ts
src/main/presenter/llmProviderPresenter/providers/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

src/main/presenter/llmProviderPresenter/providers/*.ts: Each LLM provider must implement the coreStream method following the standardized event interface for tool calling and response streaming
Convert MCP tools to provider-specific formats and normalize streaming responses to standard events in each provider implementation

src/main/presenter/llmProviderPresenter/providers/*.ts: In Provider implementations (src/main/presenter/llmProviderPresenter/providers/*.ts), the coreStream(messages, modelId, temperature, maxTokens) method should perform a single-pass streaming API request for each conversation round without containing multi-turn tool call loop logic
In Provider implementations, handle native tool support by converting MCP tools to Provider format using convertToProviderTools and including them in the API request; for Providers without native function call support, prepare messages using prepareFunctionCallPrompt before making the API call
In Provider implementations, parse Provider-specific data chunks from the streaming response and yield standardized LLMCoreStreamEvent objects conforming to the standard stream event interface, including text, reasoning, tool calls, usage, errors, stop reasons, and image data
In Provider implementations, include helper methods for Provider-specific operations such as formatMessages, convertToProviderTools, parseFunctionCalls, and prepareFunctionCallPrompt

Files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/shared/**/*.d.ts

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

Define type definitions in shared/*.d.ts files for objects exposed by the main process to the renderer process

Files:

  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/shared/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

Shared type definitions and utilities between main and renderer processes should be placed in src/shared

Files:

  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
src/shared/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Shared types and utilities should be placed in src/shared/

Files:

  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
🧠 Learnings (22)
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/presenter/mcpPresenter/**/*.ts : Register new MCP tools in `mcpPresenter/index.ts` after implementing them in `inMemoryServers/`

Applied to files:

  • src/main/presenter/lifecyclePresenter/hooks/index.ts
  • src/main/presenter/configPresenter/index.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, include helper methods for Provider-specific operations such as `formatMessages`, `convertToProviderTools`, `parseFunctionCalls`, and `prepareFunctionCallPrompt`

Applied to files:

  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Implement separation of concerns where `src/main/presenter/llmProviderPresenter/index.ts` manages the Agent loop and conversation history, while Provider files handle LLM API interactions, Provider-specific request/response formatting, tool definition conversion, and native vs non-native tool call mechanisms

Applied to files:

  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : Convert MCP tools to provider-specific formats and normalize streaming responses to standard events in each provider implementation

Applied to files:

  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, handle native tool support by converting MCP tools to Provider format using `convertToProviderTools` and including them in the API request; for Providers without native function call support, prepare messages using `prepareFunctionCallPrompt` before making the API call

Applied to files:

  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:28:20.513Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T05:28:20.513Z
Learning: Use a two-layer LLM provider architecture with Agent Loop and Provider layers

Applied to files:

  • src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:27:39.200Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/provider-guidelines.mdc:0-0
Timestamp: 2025-11-25T05:27:39.200Z
Learning: Applies to **/*Provider**/index.ts : Do not introduce renderer dependencies inside Provider implementations

Applied to files:

  • src/main/presenter/configPresenter/index.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/renderer/**/*.ts : Use the `usePresenter.ts` composable for renderer-to-main IPC communication to call presenter methods directly

Applied to files:

  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
📚 Learning: 2025-11-25T05:28:20.513Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T05:28:20.513Z
Learning: Applies to src/main/**/*.ts : Use the Presenter pattern in the main process for UI coordination

Applied to files:

  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/presenter/**/*.ts : Organize core business logic into dedicated Presenter classes, with one presenter per functional domain

Applied to files:

  • src/main/presenter/configPresenter/index.ts
📚 Learning: 2025-11-25T05:28:04.454Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/vue-shadcn.mdc:0-0
Timestamp: 2025-11-25T05:28:04.454Z
Learning: Applies to src/renderer/**/*.{ts,vue} : Use provide/inject for dependency injection when appropriate

Applied to files:

  • src/main/presenter/configPresenter/index.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts` (`startStreamCompletion`), implement the Agent loop that manages the overall conversation flow, including multiple rounds of LLM calls and tool usage, maintaining `conversationMessages` history, calling `provider.coreStream()` on each iteration, and controlling the loop using `needContinueConversation` and `toolCallCount` (compared against `MAX_TOOL_CALLS`)

Applied to files:

  • src/main/presenter/configPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : Each LLM provider must implement the `coreStream` method following the standardized event interface for tool calling and response streaming

Applied to files:

  • src/main/presenter/llmProviderPresenter/index.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, parse Provider-specific data chunks from the streaming response and `yield` standardized `LLMCoreStreamEvent` objects conforming to the standard stream event interface, including text, reasoning, tool calls, usage, errors, stop reasons, and image data

Applied to files:

  • src/main/presenter/llmProviderPresenter/index.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts`, listen for standardized events yielded by `coreStream` and handle them accordingly: buffer text content (`currentContent`), handle `tool_call_start/chunk/end` events by collecting tool details and calling `presenter.mcpPresenter.callTool`, send frontend events via `eventBus` with tool call status, format tool results for the next LLM call, and set `needContinueConversation = true`

Applied to files:

  • src/main/presenter/llmProviderPresenter/index.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/**/*.ts : Define the standardized `LLMCoreStreamEvent` interface with fields: `type` (text | reasoning | tool_call_start | tool_call_chunk | tool_call_end | error | usage | stop | image_data), `content` (for text), `reasoning_content` (for reasoning), `tool_call_id`, `tool_call_name`, `tool_call_arguments_chunk` (for streaming), `tool_call_arguments_complete` (for complete arguments), `error_message`, `usage` object with token counts, `stop_reason` (tool_use | max_tokens | stop_sequence | error | complete), and `image_data` object with Base64-encoded data and mimeType

Applied to files:

  • src/main/presenter/llmProviderPresenter/index.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations (`src/main/presenter/llmProviderPresenter/providers/*.ts`), the `coreStream(messages, modelId, temperature, maxTokens)` method should perform a *single-pass* streaming API request for each conversation round without containing multi-turn tool call loop logic

Applied to files:

  • src/main/presenter/llmProviderPresenter/index.ts
  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/main/presenter/threadPresenter/handlers/utilityHandler.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts`, handle `stop` events by checking `stop_reason`: if `'tool_use'`, add the buffered assistant message and prepare for the next loop iteration; otherwise, add the final assistant message and exit the loop

Applied to files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Implement the two-layer LLM provider architecture with Agent Loop Layer managing conversation flow and Provider Layer handling API interactions

Applied to files:

  • src/shared/types/presenters/llmprovider.presenter.d.ts
  • src/shared/types/presenters/legacy.presenters.d.ts
📚 Learning: 2025-08-28T12:01:03.917Z
Learnt from: hllshiro
Repo: ThinkInAIXYZ/deepchat PR: 803
File: src/main/presenter/trayPresenter.ts:0-0
Timestamp: 2025-08-28T12:01:03.917Z
Learning: In the DeepChat application, calling app.quit() directly will automatically trigger the LifecycleManager's shutdown handling through Electron's before-quit event interception, so explicit calls to LifecycleManager.requestShutdown() are not needed when simply quitting the application.

Applied to files:

  • src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts
  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
📚 Learning: 2025-11-25T05:26:24.867Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-11-25T05:26:24.867Z
Learning: Applies to {src/main/presenter/**/*.ts,src/renderer/**/*.ts} : Implement proper inter-process communication (IPC) patterns using Electron's ipcRenderer and ipcMain APIs

Applied to files:

  • src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts
📚 Learning: 2025-11-25T05:27:39.200Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/provider-guidelines.mdc:0-0
Timestamp: 2025-11-25T05:27:39.200Z
Learning: Applies to **/*Provider**/index.ts : Output only discriminated union `LLMCoreStreamEvent` in Provider implementations, do not use single interface with optional fields

Applied to files:

  • src/shared/types/presenters/legacy.presenters.d.ts
🧬 Code graph analysis (2)
src/main/presenter/configPresenter/index.ts (1)
src/main/presenter/index.ts (1)
  • presenter (229-229)
src/main/presenter/lifecyclePresenter/hooks/beforeQuit/acpCleanupHook.ts (3)
src/main/presenter/lifecyclePresenter/hooks/index.ts (1)
  • acpCleanupHook (18-18)
src/shared/types/presenters/legacy.presenters.d.ts (2)
  • LifecycleHook (2160-2166)
  • LifecycleContext (2151-2155)
src/main/presenter/index.ts (1)
  • presenter (229-229)
⏰ 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). (1)
  • GitHub Check: build-check (x64)
🔇 Additional comments (5)
src/main/presenter/lifecyclePresenter/hooks/index.ts (1)

18-18: Wire ACP cleanup hook into lifecycle exports

Exporting acpCleanupHook alongside other beforeQuit hooks looks correct and keeps lifecycle registration centralized.

src/main/presenter/llmProviderPresenter/index.ts (1)

148-150: Non-creating provider instance getter is well-factored

getExistingProviderInstance cleanly exposes the manager’s cached instance without side effects, which is exactly what the shutdown/cleanup path needs.

src/shared/types/presenters/llmprovider.presenter.d.ts (1)

139-146: New getExistingProviderInstance API is consistent with implementation

Adding getExistingProviderInstance(providerId: string): unknown to ILlmProviderPresenter cleanly reflects the non-creating lookup that LLMProviderPresenter now exposes, and matches its usage from lifecycle hooks.

src/main/presenter/llmProviderPresenter/managers/providerInstanceManager.ts (1)

221-223: Expose cached provider instance without side effects

getExistingProviderInstance correctly returns the cached instance from providerInstances without instantiating anything new, which is ideal for shutdown and diagnostic paths.

src/main/presenter/llmProviderPresenter/providers/acpProvider.ts (1)

1125-1144: ACP provider cleanup correctly tears down sessions, processes, and pending permissions

The cleanup sequence (clearAllSessions → processManager.shutdown → cancelling pending permissions) is coherent and matches the shutdown goal without obvious race or correctness issues. Map iteration with in-loop deletes is safe for Map, and resolving permissions as cancelled is a good default at shutdown.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 9ea954b and 585f010.

📒 Files selected for processing (1)
  • src/main/presenter/threadPresenter/utils/promptBuilder.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for logs and comments (Chinese text exists in legacy code, but new code should use English)

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Enable and maintain strict TypeScript type checking for all files

**/*.{ts,tsx}: Always use try-catch to handle possible errors in TypeScript code
Provide meaningful error messages when catching errors
Log detailed error logs including error details, context, and stack traces
Distinguish and handle different error types (UserError, NetworkError, SystemError, BusinessError) with appropriate handlers in TypeScript
Use structured logging with logger.error(), logger.warn(), logger.info(), logger.debug() methods from logging utilities
Do not suppress errors (avoid empty catch blocks or silently ignoring errors)
Provide user-friendly error messages for user-facing errors in TypeScript components
Implement error retry mechanisms for transient failures in TypeScript
Avoid logging sensitive information (passwords, tokens, PII) in logs

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/main/presenter/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Organize core business logic into dedicated Presenter classes, with one presenter per functional domain

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/main/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Use EventBus from src/main/eventbus.ts for main-to-renderer communication, broadcasting events via mainWindow.webContents.send()

src/main/**/*.ts: Use EventBus pattern for inter-process communication within the main process to decouple modules
Use Electron's built-in APIs for file system and native dialogs instead of Node.js or custom implementations

src/main/**/*.ts: Electron main process code belongs in src/main/ with presenters in presenter/ (Window/Tab/Thread/Mcp/Config/LLMProvider) and eventbus.ts for app events
Use the Presenter pattern in the main process for UI coordination

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Do not include AI co-authoring information (e.g., 'Co-Authored-By: Claude') in git commits

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
**/*.{js,ts,jsx,tsx,mjs,cjs}

📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)

Write logs and comments in English

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
{src/main/presenter/**/*.ts,src/renderer/**/*.ts}

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

Implement proper inter-process communication (IPC) patterns using Electron's ipcRenderer and ipcMain APIs

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/**/*

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

New features should be developed in the src directory

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/main/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

Main process code for Electron should be placed in src/main

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/**/*.{ts,tsx,vue,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use Prettier with single quotes, no semicolons, and 100 character width

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use OxLint for linting JavaScript and TypeScript files

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.{ts,tsx}: Use camelCase for variable and function names in TypeScript files
Use PascalCase for type and class names in TypeScript
Use SCREAMING_SNAKE_CASE for constant names

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use EventBus for inter-process communication events

Files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: hllshiro
Repo: ThinkInAIXYZ/deepchat PR: 803
File: src/main/presenter/trayPresenter.ts:0-0
Timestamp: 2025-08-28T12:01:03.917Z
Learning: In the DeepChat application, calling app.quit() directly will automatically trigger the LifecycleManager's shutdown handling through Electron's before-quit event interception, so explicit calls to LifecycleManager.requestShutdown() are not needed when simply quitting the application.
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts`, handle `stop` events by checking `stop_reason`: if `'tool_use'`, add the buffered assistant message and prepare for the next loop iteration; otherwise, add the final assistant message and exit the loop

Applied to files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts` (`startStreamCompletion`), implement the Agent loop that manages the overall conversation flow, including multiple rounds of LLM calls and tool usage, maintaining `conversationMessages` history, calling `provider.coreStream()` on each iteration, and controlling the loop using `needContinueConversation` and `toolCallCount` (compared against `MAX_TOOL_CALLS`)

Applied to files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts`, listen for standardized events yielded by `coreStream` and handle them accordingly: buffer text content (`currentContent`), handle `tool_call_start/chunk/end` events by collecting tool details and calling `presenter.mcpPresenter.callTool`, send frontend events via `eventBus` with tool call status, format tool results for the next LLM call, and set `needContinueConversation = true`

Applied to files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, handle native tool support by converting MCP tools to Provider format using `convertToProviderTools` and including them in the API request; for Providers without native function call support, prepare messages using `prepareFunctionCallPrompt` before making the API call

Applied to files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Implement separation of concerns where `src/main/presenter/llmProviderPresenter/index.ts` manages the Agent loop and conversation history, while Provider files handle LLM API interactions, Provider-specific request/response formatting, tool definition conversion, and native vs non-native tool call mechanisms

Applied to files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations (`src/main/presenter/llmProviderPresenter/providers/*.ts`), the `coreStream(messages, modelId, temperature, maxTokens)` method should perform a *single-pass* streaming API request for each conversation round without containing multi-turn tool call loop logic

Applied to files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, include helper methods for Provider-specific operations such as `formatMessages`, `convertToProviderTools`, `parseFunctionCalls`, and `prepareFunctionCallPrompt`

Applied to files:

  • src/main/presenter/threadPresenter/utils/promptBuilder.ts
⏰ 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). (1)
  • GitHub Check: build-check (x64)

@zerob13
Copy link
Collaborator Author

zerob13 commented Dec 12, 2025

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 838 to 841
getProviderById(id: string): LLM_PROVIDER
isAgentProvider(providerId: string): boolean
getProviderInstance?(providerId: string): unknown
getExistingProviderInstance?(providerId: string): unknown

Choose a reason for hiding this comment

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

P1 Badge Remove conflicting getProviderInstance signature

The legacy ILlmProviderPresenter interface now declares getProviderInstance twice—once as optional in this block and again as a required method later in the same interface (around line 945). TypeScript treats this as duplicate property declarations with incompatible optionality, which will surface as a type error (e.g., “Subsequent property declarations must have the same type”) when loading the declaration file, breaking pnpm run typecheck or any build that includes these types.

Useful? React with 👍 / 👎.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (6)
src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts (1)

165-174: Preserve original error cause + make shutdown detection less brittle
Mapping shutdown errors is good, but message.includes('shutting down') is fragile and you’re dropping the original error context. Consider (a) extracting a shared isAcpShuttingDownError(err) helper (used here + AcpProvider), and (b) rethrowing with cause so logs keep stack/context.

   try {
     handle = await this.processManager.getConnection(agent, workdir)
   } catch (error) {
     const message = error instanceof Error ? error.message : String(error)
-    if (message.includes('shutting down')) {
-      throw new Error('[ACP] Cannot create session: process manager is shutting down')
+    if (message.toLowerCase().includes('shutting down')) {
+      throw new Error('[ACP] Cannot create session: process manager is shutting down', {
+        cause: error instanceof Error ? error : undefined
+      })
     }
     throw error
   }
test/main/presenter/acpSessionManager.test.ts (1)

1-38: Good coverage for shutdown-vs-non-shutdown getConnection failures; consider avoiding private-method testing
These assertions match the new mapping behavior. The main nit is reaching into private createSession via as any; if feasible, drive this through getOrCreateSession() (or make the mapping a small exported helper to test directly). Also consider using a platform-neutral temp path string (or os.tmpdir()), even if it’s “just a string”.

test/main/presenter/llmProviderPresenter.test.ts (1)

544-572: Make console spy restoration failure-safe (and optionally assert warn behavior)
If the first test throws before Line 558, warnSpy.mockRestore() won’t run. Prefer try/finally (or an afterEach) so the suite doesn’t leak mocks.

   it('should swallow ACP warmup shutdown errors', async () => {
     const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
-    const mockAcpProvider = {
-      warmupProcess: vi
-        .fn()
-        .mockRejectedValue(new Error('[ACP] Process manager is shutting down, refusing to spawn'))
-    }
-    vi.spyOn(llmProviderPresenter as any, 'getAcpProviderInstance').mockReturnValue(
-      mockAcpProvider as any
-    )
-
-    await expect(
-      llmProviderPresenter.warmupAcpProcess('agent-test', '/tmp')
-    ).resolves.toBeUndefined()
-    warnSpy.mockRestore()
+    try {
+      const mockAcpProvider = {
+        warmupProcess: vi
+          .fn()
+          .mockRejectedValue(new Error('[ACP] Process manager is shutting down, refusing to spawn'))
+      }
+      vi.spyOn(llmProviderPresenter as any, 'getAcpProviderInstance').mockReturnValue(
+        mockAcpProvider as any
+      )
+      await expect(llmProviderPresenter.warmupAcpProcess('agent-test', '/tmp')).resolves.toBeUndefined()
+    } finally {
+      warnSpy.mockRestore()
+    }
   })
test/main/presenter/acpProvider.test.ts (1)

1-82: Nice targeted tests for shutdown mapping; consider a less “prototype-only” instance setup
Coverage looks solid for the new error-handling split. Optional: if you can cheaply instantiate AcpProvider with minimal fakes (vs Object.create(...prototype) + as any), it’ll better reflect runtime wiring and reduce “false green” risk. Also, consider replacing '/tmp' with a platform-neutral temp dir string.

src/main/presenter/llmProviderPresenter/providers/acpProvider.ts (2)

461-475: De-duplicate “shutting down” detection + make it case-insensitive
This is now the second place matching on 'shutting down' (also in src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts). Suggest extracting a shared helper (even a small local util module) and using toLowerCase() to avoid casing issues.

-      if (message.includes('shutting down')) {
+      if (message.toLowerCase().includes('shutting down')) {
         return {
           status: 'error',
           sessionId: undefined,
           error: 'Process manager is shutting down',
           events: []
         }
       }

1139-1157: Cleanup() is good; consider snapshot+clear and idempotency guard
Two small robustness tweaks:

  • Avoid mutating pendingPermissions while iterating by snapshotting, then clear().
  • Consider guarding cleanup from re-entry (shutdown hooks can sometimes fire multiple times).
-    for (const [requestId, state] of this.pendingPermissions.entries()) {
-      state.resolve({ outcome: { outcome: 'cancelled' } })
-      this.pendingPermissions.delete(requestId)
-    }
+    const pending = Array.from(this.pendingPermissions.values())
+    this.pendingPermissions.clear()
+    for (const state of pending) {
+      state.resolve({ outcome: { outcome: 'cancelled' } })
+    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 585f010 and 6f5393b.

📒 Files selected for processing (6)
  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts (1 hunks)
  • src/main/presenter/llmProviderPresenter/index.ts (2 hunks)
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts (3 hunks)
  • test/main/presenter/acpProvider.test.ts (1 hunks)
  • test/main/presenter/acpSessionManager.test.ts (1 hunks)
  • test/main/presenter/llmProviderPresenter.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/presenter/llmProviderPresenter/index.ts
🧰 Additional context used
📓 Path-based instructions (17)
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for logs and comments (Chinese text exists in legacy code, but new code should use English)

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Enable and maintain strict TypeScript type checking for all files

**/*.{ts,tsx}: Always use try-catch to handle possible errors in TypeScript code
Provide meaningful error messages when catching errors
Log detailed error logs including error details, context, and stack traces
Distinguish and handle different error types (UserError, NetworkError, SystemError, BusinessError) with appropriate handlers in TypeScript
Use structured logging with logger.error(), logger.warn(), logger.info(), logger.debug() methods from logging utilities
Do not suppress errors (avoid empty catch blocks or silently ignoring errors)
Provide user-friendly error messages for user-facing errors in TypeScript components
Implement error retry mechanisms for transient failures in TypeScript
Avoid logging sensitive information (passwords, tokens, PII) in logs

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
src/main/presenter/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Organize core business logic into dedicated Presenter classes, with one presenter per functional domain

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/main/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Use EventBus from src/main/eventbus.ts for main-to-renderer communication, broadcasting events via mainWindow.webContents.send()

src/main/**/*.ts: Use EventBus pattern for inter-process communication within the main process to decouple modules
Use Electron's built-in APIs for file system and native dialogs instead of Node.js or custom implementations

src/main/**/*.ts: Electron main process code belongs in src/main/ with presenters in presenter/ (Window/Tab/Thread/Mcp/Config/LLMProvider) and eventbus.ts for app events
Use the Presenter pattern in the main process for UI coordination

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Do not include AI co-authoring information (e.g., 'Co-Authored-By: Claude') in git commits

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
**/*.{js,ts,jsx,tsx,mjs,cjs}

📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)

Write logs and comments in English

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
{src/main/presenter/**/*.ts,src/renderer/**/*.ts}

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

Implement proper inter-process communication (IPC) patterns using Electron's ipcRenderer and ipcMain APIs

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/main/presenter/llmProviderPresenter/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/llm-agent-loop.mdc)

Define the standardized LLMCoreStreamEvent interface with fields: type (text | reasoning | tool_call_start | tool_call_chunk | tool_call_end | error | usage | stop | image_data), content (for text), reasoning_content (for reasoning), tool_call_id, tool_call_name, tool_call_arguments_chunk (for streaming), tool_call_arguments_complete (for complete arguments), error_message, usage object with token counts, stop_reason (tool_use | max_tokens | stop_sequence | error | complete), and image_data object with Base64-encoded data and mimeType

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/**/*

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

New features should be developed in the src directory

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/main/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

Main process code for Electron should be placed in src/main

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/**/*.{ts,tsx,vue,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use Prettier with single quotes, no semicolons, and 100 character width

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use OxLint for linting JavaScript and TypeScript files

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.{ts,tsx}: Use camelCase for variable and function names in TypeScript files
Use PascalCase for type and class names in TypeScript
Use SCREAMING_SNAKE_CASE for constant names

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use EventBus for inter-process communication events

Files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
test/**/*.{test,spec}.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Vitest framework for unit and integration tests

Files:

  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • test/main/presenter/llmProviderPresenter.test.ts
test/**/*.{test,spec}.ts

📄 CodeRabbit inference engine (AGENTS.md)

test/**/*.{test,spec}.ts: Test files should follow the same directory structure as source code under test/main and test/renderer directories
Use Vitest and Vue Test Utils for testing with jsdom configuration
Test files must be named with .test.ts or .spec.ts extension

Files:

  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • test/main/presenter/llmProviderPresenter.test.ts
src/main/presenter/llmProviderPresenter/providers/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

src/main/presenter/llmProviderPresenter/providers/*.ts: Each LLM provider must implement the coreStream method following the standardized event interface for tool calling and response streaming
Convert MCP tools to provider-specific formats and normalize streaming responses to standard events in each provider implementation

src/main/presenter/llmProviderPresenter/providers/*.ts: In Provider implementations (src/main/presenter/llmProviderPresenter/providers/*.ts), the coreStream(messages, modelId, temperature, maxTokens) method should perform a single-pass streaming API request for each conversation round without containing multi-turn tool call loop logic
In Provider implementations, handle native tool support by converting MCP tools to Provider format using convertToProviderTools and including them in the API request; for Providers without native function call support, prepare messages using prepareFunctionCallPrompt before making the API call
In Provider implementations, parse Provider-specific data chunks from the streaming response and yield standardized LLMCoreStreamEvent objects conforming to the standard stream event interface, including text, reasoning, tool calls, usage, errors, stop reasons, and image data
In Provider implementations, include helper methods for Provider-specific operations such as formatMessages, convertToProviderTools, parseFunctionCalls, and prepareFunctionCallPrompt

Files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
🧠 Learnings (20)
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Implement separation of concerns where `src/main/presenter/llmProviderPresenter/index.ts` manages the Agent loop and conversation history, while Provider files handle LLM API interactions, Provider-specific request/response formatting, tool definition conversion, and native vs non-native tool call mechanisms

Applied to files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • test/main/presenter/acpProvider.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts` (`startStreamCompletion`), implement the Agent loop that manages the overall conversation flow, including multiple rounds of LLM calls and tool usage, maintaining `conversationMessages` history, calling `provider.coreStream()` on each iteration, and controlling the loop using `needContinueConversation` and `toolCallCount` (compared against `MAX_TOOL_CALLS`)

Applied to files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts`, handle `stop` events by checking `stop_reason`: if `'tool_use'`, add the buffered assistant message and prepare for the next loop iteration; otherwise, add the final assistant message and exit the loop

Applied to files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : Convert MCP tools to provider-specific formats and normalize streaming responses to standard events in each provider implementation

Applied to files:

  • src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts
  • test/main/presenter/acpProvider.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:26:24.867Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-11-25T05:26:24.867Z
Learning: Applies to {src/main/presenter/**/*.ts,src/renderer/**/*.ts} : Implement proper inter-process communication (IPC) patterns using Electron's ipcRenderer and ipcMain APIs

Applied to files:

  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
📚 Learning: 2025-11-25T05:28:20.513Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T05:28:20.513Z
Learning: Applies to src/main/**/*.ts : Electron main process code belongs in `src/main/` with presenters in `presenter/` (Window/Tab/Thread/Mcp/Config/LLMProvider) and `eventbus.ts` for app events

Applied to files:

  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/acpSessionManager.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/presenter/mcpPresenter/**/*.ts : Register new MCP tools in `mcpPresenter/index.ts` after implementing them in `inMemoryServers/`

Applied to files:

  • test/main/presenter/acpProvider.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, include helper methods for Provider-specific operations such as `formatMessages`, `convertToProviderTools`, `parseFunctionCalls`, and `prepareFunctionCallPrompt`

Applied to files:

  • test/main/presenter/acpProvider.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:28:20.513Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T05:28:20.513Z
Learning: Applies to src/main/**/*.ts : Use the Presenter pattern in the main process for UI coordination

Applied to files:

  • test/main/presenter/acpProvider.test.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, handle native tool support by converting MCP tools to Provider format using `convertToProviderTools` and including them in the API request; for Providers without native function call support, prepare messages using `prepareFunctionCallPrompt` before making the API call

Applied to files:

  • test/main/presenter/acpProvider.test.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:27:39.200Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/provider-guidelines.mdc:0-0
Timestamp: 2025-11-25T05:27:39.200Z
Learning: Applies to **/*Provider**/index.ts : Error scenarios in Provider implementations must have corresponding `stop_reason` and `error` message

Applied to files:

  • test/main/presenter/acpProvider.test.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx,js} : Use Vitest framework for unit and integration tests

Applied to files:

  • test/main/presenter/acpProvider.test.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : In `src/main/presenter/llmProviderPresenter/index.ts`, listen for standardized events yielded by `coreStream` and handle them accordingly: buffer text content (`currentContent`), handle `tool_call_start/chunk/end` events by collecting tool details and calling `presenter.mcpPresenter.callTool`, send frontend events via `eventBus` with tool call status, format tool results for the next LLM call, and set `needContinueConversation = true`

Applied to files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations, parse Provider-specific data chunks from the streaming response and `yield` standardized `LLMCoreStreamEvent` objects conforming to the standard stream event interface, including text, reasoning, tool calls, usage, errors, stop reasons, and image data

Applied to files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:28:20.513Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T05:28:20.513Z
Learning: Applies to src/**/*.ts : Use EventBus for inter-process communication events

Applied to files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/**/*.ts : Use EventBus from `src/main/eventbus.ts` for main-to-renderer communication, broadcasting events via `mainWindow.webContents.send()`

Applied to files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
📚 Learning: 2025-11-25T05:26:24.867Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-11-25T05:26:24.867Z
Learning: Applies to src/main/**/*.ts : Use EventBus pattern for inter-process communication within the main process to decouple modules

Applied to files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
📚 Learning: 2025-11-25T05:26:24.867Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-11-25T05:26:24.867Z
Learning: Implement proper error handling and logging for debugging in Electron applications

Applied to files:

  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
📚 Learning: 2025-11-25T05:27:12.209Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-11-25T05:27:12.209Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : In Provider implementations (`src/main/presenter/llmProviderPresenter/providers/*.ts`), the `coreStream(messages, modelId, temperature, maxTokens)` method should perform a *single-pass* streaming API request for each conversation round without containing multi-turn tool call loop logic

Applied to files:

  • test/main/presenter/llmProviderPresenter.test.ts
📚 Learning: 2025-11-25T05:26:11.312Z
Learnt from: CR
Repo: ThinkInAIXYZ/deepchat PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T05:26:11.312Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : Each LLM provider must implement the `coreStream` method following the standardized event interface for tool calling and response streaming

Applied to files:

  • test/main/presenter/llmProviderPresenter.test.ts
🧬 Code graph analysis (3)
src/main/presenter/llmProviderPresenter/agent/acpSessionManager.ts (1)
src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts (1)
  • AcpProcessHandle (24-35)
test/main/presenter/acpProvider.test.ts (1)
src/main/presenter/llmProviderPresenter/providers/acpProvider.ts (1)
  • AcpProvider (58-1158)
src/main/presenter/llmProviderPresenter/providers/acpProvider.ts (1)
src/main/presenter/llmProviderPresenter/agent/acpProcessManager.ts (1)
  • AcpProcessHandle (24-35)
⏰ 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). (1)
  • GitHub Check: build-check (x64)
🔇 Additional comments (1)
src/main/presenter/llmProviderPresenter/providers/acpProvider.ts (1)

28-28: Good: typed handle import improves safety/readability
Using type AcpProcessHandle here clarifies what getConnection() returns.

@zerob13 zerob13 merged commit 2cb8c41 into dev Dec 12, 2025
2 checks passed
zerob13 added a commit that referenced this pull request Dec 12, 2025
* fix: Multiple Issues Affecting Conversation Flow and Model Settings (#1166)

* fix: #1164 support maxtoken 2

* fix: mcp tool panel close btn #1163

* fix: #1162 file content in converation

* fix(search-assistant): exclude acp models

* fix: #1072 thinkcontent respects the global font size set

* feat: Hebrew (he-IL) Translation (#1157)

* feat: Hebrew (he-IL) Translation

* feat: add workspace view to acp agents (#1158)

* feat: add workspaceview for acp agent

* feat: support workspace dirs

* fix: workspace file refresh

* fix: tool call status

* fix: review refactor

* chore: update readme

* fix: add file context actions (#1160)

* fix: keep last file list

* feat(acp-workspace): add file context actions

* fix(acp-workspace): move path helpers to preload

* fix(preload): allow empty relative path

* fix(preload): escape quotes when formatting paths

* chore: update docs

* fix: Multiple Issues Affecting Conversation Flow and Model Settings (#1166)

* fix: #1164 support maxtoken 2

* fix: mcp tool panel close btn #1163

* fix: #1162 file content in converation

* fix(search-assistant): exclude acp models

* fix: #1072 thinkcontent respects the global font size set

* feat: add new i18n translation

* feat: add custom font setting (#1167)

* feat(settings): add font customization controls

* feat: change font with monaco

* chore: remove log and remove unuse key

* fix: linux font parse

* feat: use font-list to get font

* fix: font setting not work on settings page (#1169)

* style: unify scroll bar style (#1173)

* feat: acp init and process manage (#1171)

* feat: init acp process on select

* feat: warm up acp process on new thread

* fix: reuse warmup process

* fix: vue warning

* chore: add plan for acp debug panel

* feat: add debugview for acp

* feat: add i18n for debug

* fix: code review

* fix: ai review

* fix: Shutdown may skip releasing warmup‑only processes due to using warmupKey instead of agentId.

* chore: update markdown renderer

* chore: update mermaid node

* Merge commit from fork

* chore: update markstream-vue to version 0.0.3-beta.3
fix link renderer
feat html_inline render

* fix: increase button size for web content limit adjustment

* fix: close app kill all acp processes (#1175)

* fix: close app kill all acp processes

* fix: disable tool call merge

* fix: handle uncatch error

* fix: remove redundant type

* feat: add  shell to powerpack (#1178)

* chore(powerpack): randomize shell workdir

* feat: exclusive inmem server in terminal display

* fix: add sandbox in shell script

---------

Co-authored-by: xiaomo <wegi866@gmail.com>
Co-authored-by: Simon He <674949287@qq.com>
Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com>
@zerob13 zerob13 deleted the bugfix/process-not-close-on-windows branch December 13, 2025 06:59
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.

2 participants