summaryrefslogtreecommitdiffhomepage
path: root/.rules/changelog/2026-03/24/12.md
diff options
context:
space:
mode:
Diffstat (limited to '.rules/changelog/2026-03/24/12.md')
-rw-r--r--.rules/changelog/2026-03/24/12.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/.rules/changelog/2026-03/24/12.md b/.rules/changelog/2026-03/24/12.md
new file mode 100644
index 0000000..14e0070
--- /dev/null
+++ b/.rules/changelog/2026-03/24/12.md
@@ -0,0 +1,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.).