summaryrefslogtreecommitdiffhomepage
path: root/.rules/changelog/2026-03/24/12.md
blob: 14e0070cea68fd45072b50fab9b7ff585640bf84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Changelog — 2026-03-24 #12

## Refactor: Deduplicate chat agent loop in ollama-client.ts

### Problem
The three chat functions (`sendChatMessage`, `sendChatMessageStreamingMobile`, `sendChatMessageStreamingDesktop`) duplicated the system prompt injection, tool-calling agent loop, tool execution, and approval handling logic. Any change (e.g., updating the system prompt) required editing all three in lockstep.

### Changes

- **`src/ollama-client.ts`**
  - Extracted `chatAgentLoop()` — a single shared function for system prompt injection, the iterative tool-calling loop, tool execution with approval, and message history management.
  - Introduced `ChatRequestStrategy` type — a callback that performs a single HTTP request and returns `{ content, toolCalls }`.
  - Extracted `TOOL_SYSTEM_PROMPT` constant — the system prompt now lives in one place.
  - `sendChatMessage` now creates an inline strategy using `requestUrl` (non-streaming) and delegates to `chatAgentLoop`.
  - `sendChatMessageStreaming` selects between `buildMobileStrategy` or `buildDesktopStreamingStrategy` based on platform, then delegates to `chatAgentLoop`.
  - `buildMobileStrategy` — extracted from the former `sendChatMessageStreamingMobile`.
  - `buildDesktopStreamingStrategy` — extracted from the former `sendChatMessageStreamingDesktop`.

- **`src/chat-view.ts`**
  - Updated `onApprovalRequest` callback to remove the empty streaming bubble before showing the approval prompt (from earlier fix).

### Also included (from prior uncommitted fix)
- System prompt updated to inform the model that some tools require user approval and to ask why if the user declines.
- Empty streaming bubble is removed before showing approval prompts (delete file, etc.).