Skip to content

Commit abe8a79

Browse files
authored
Privacy-First AI Tool Calling
Summary This release introduces AI tool calling with human-in-the-loop approval—a significant step forward for knowledge management workflows. Your AI can now search your vault, read files, and query the web, but only with explicit approval at every step. Key additions: - Vault Search: AI discovers relevant notes across filenames and content - File Read: AI requests access to specific files you select - Web Search: Brave Search integration (1,000 free queries/month) - Editable queries: Modify AI-generated search terms before execution - Three-layer approval: Approve execution → Review results → Select what to share Architecture Changes New service layer (~2,500 lines): - ToolService - Orchestrates tool execution and approval workflow - VaultSearchService - Full-text vault search via Obsidian API - WebSearchService - Brave Search/custom endpoint integration - ToolSupportDetector + WhitelistValidator - Model capability detection Major refactoring (~22,000 insertions, ~4,500 deletions): - Consolidated 6 AI services into unified AiProviderService with provider adapters - Replaced ServiceLocator with new ServiceContainer - Extracted command handlers from monolithic CommandRegistry - Added comprehensive utility modules for error handling, input validation, and message processing New UI components: - ToolApprovalModal - Shows tool name, parameters, editable queries - SearchResultsApprovalModal - Multi-select file filtering - WebSearchApprovalModal - Web result filtering with previews Privacy & Security - Opt-in only: All tools disabled by default - Local execution: Vault operations run entirely within Obsidian's API - Selective sharing: Choose exactly which results reach the AI - No telemetry: Zero external tracking Configuration Settings → ChatGPT MD → Tool Calling: - Enable/disable tool calling (default: off) - Brave Search API key (optional) - Custom search provider URL - Max web results (1-10) Model Support Tool calling requires model support. The plugin includes: - Whitelist of tested models (~150 models across OpenAI, Anthropic, OpenRouter, Gemini) - Visual indicator in model selector showing tool compatibility - Automatic filtering for unsupported models Breaking Changes None. Existing configurations work unchanged. Tools are disabled by default. Test Plan - Verify tool calling toggle enables/disables all tool features - Test vault search with various query types - Confirm file read approval shows correct file list - Test web search with and without API key configured - Verify query editing works for vault and web search - Test with multiple AI providers (OpenAI, Anthropic, Ollama, etc.) - Confirm model selector shows tool support indicators
2 parents 5a1532b + 9533224 commit abe8a79

File tree

108 files changed

+20899
-4954
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+20899
-4954
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ChatGPT MD Changelog
22

3-
## v3.0.0 (December 2025) - Privacy-First AI Tool Calling
3+
## v3.0.0 - Privacy-First AI Tool Calling
44

55
### 🎯 Major Features
66

@@ -22,6 +22,11 @@
2222
- Review and filter web results before sharing
2323
- Custom search provider support for self-hosted solutions
2424
- Optional full page content fetching
25+
- Tool only available to LLM when Brave Search API key is configured
26+
- **Editable Search Queries**: Users can now edit vault search and web search queries before tool execution
27+
- Textarea in tool approval modal for query modification
28+
- Real-time validation prevents empty queries
29+
- Supports multi-line queries and special characters
2530

2631
### 🔒 Privacy & Control
2732

CLAUDE.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,70 @@
11
# CLAUDE.md
22

3-
This file provides guidance to Claude Code when working with code in this repository.
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

55
## Project Overview
66

77
ChatGPT MD is an Obsidian plugin that integrates multiple AI providers (OpenAI, OpenRouter, Anthropic, Gemini, Ollama, LM Studio) into Obsidian for seamless chat interactions within markdown notes. Users can have AI conversations directly in their notes, with support for note linking, streaming responses, and per-note configuration via frontmatter.
88

9-
## v3.0.0 Release - Privacy-First AI Tool Calling
9+
## v3.0.0 - Privacy-First AI Tool Calling
1010

11-
**Latest Release**: v3.0.0 (December 2025)
11+
Major feature: **Privacy-first AI tool calling** with human-in-the-loop approval:
1212

13-
Major new feature: **Privacy-first AI tool calling** with human-in-the-loop approval:
1413
- **Vault Search**: AI can search your notes (you approve which files to share)
1514
- **File Reading**: AI can request access to specific files (you select which ones)
1615
- **Web Search**: AI can search the web via Brave Search API (1,000 free queries/month)
1716
- **Three-Layer Approval**: Approve execution → Review results → Select what to share
18-
- **All tools disabled by default** (opt-in feature only)
19-
20-
See [`planning/code-review/`](planning/code-review/) for comprehensive code review and implementation guidance.
17+
- **All tools disabled by default** (opt-in via Settings → ChatGPT MD → Tool Calling)
2118

2219
## Quick Reference
2320

2421
**Entry point**: `src/main.ts``main.js`
2522

26-
**Common commands**:
23+
**Commands**:
2724

2825
```bash
2926
npm run dev # Development with watch mode
3027
npm run build # Production build with TypeScript checks
3128
npm run lint # Check code quality
3229
npm run lint:fix # Auto-fix linting issues
30+
npm run analyze # Bundle size analysis
3331
```
3432

33+
**No test suite**: This project does not currently have automated tests.
34+
3535
## Architecture Overview
3636

37-
The plugin uses **Service Locator pattern** for dependency injection:
37+
The plugin uses **constructor injection** via `ServiceContainer`:
3838

39-
- `src/core/ServiceLocator.ts` - Central DI container
40-
- `src/core/CommandRegistry.ts` - Manages all Obsidian commands
41-
- AI services implement `IAiApiService` interface
39+
- `src/core/ServiceContainer.ts` - DI container with readonly service instances
40+
- `src/Commands/` - Command handlers (extracted from old CommandRegistry)
41+
- `src/Services/AiProviderService.ts` - Unified AI service with adapter pattern
4242

43-
**Message flow**: User command → EditorService extracts messages → MessageService parses → AI service calls API → Response streamed to editor
43+
**AI SDK**: Uses Vercel AI SDK (`ai` package) with provider-specific adapters (`@ai-sdk/openai`, `@ai-sdk/anthropic`, `@ai-sdk/google`, `@openrouter/ai-sdk-provider`).
44+
45+
**Message flow**: User command → EditorService extracts messages → MessageService parses → AiProviderService calls API → Response streamed to editor
4446

4547
## Code Organization
4648

47-
Each directory has its own CLAUDE.md with detailed context that auto-loads when you work in that area:
49+
Each directory has its own CLAUDE.md with detailed context:
4850

49-
- `src/core/` - Core infrastructure (ServiceLocator, CommandRegistry)
50-
- `src/Services/` - Service implementations
51-
- `src/Views/` - UI components
51+
- `src/core/` - ServiceContainer (DI)
52+
- `src/Commands/` - Obsidian command handlers
53+
- `src/Services/` - Service implementations + `Adapters/` subdirectory
54+
- `src/Views/` - UI components and modals
5255
- `src/Models/` - TypeScript interfaces
56+
- `src/Types/` - AI service type definitions
57+
- `src/Utilities/` - Pure helper functions
5358

5459
## Cross-cutting Documentation
5560

56-
For topics that span multiple areas:
57-
5861
- **[docs/development.md](docs/development.md)** - Build process, tooling, esbuild setup
5962
- **[docs/message-flow.md](docs/message-flow.md)** - Complete flow from user input to AI response
6063

6164
## Key Design Patterns
6265

63-
1. **Service Locator** - Centralized dependency injection
64-
2. **Strategy Pattern** - Different AI services, same interface
66+
1. **Constructor Injection** - Dependencies passed via ServiceContainer
67+
2. **Adapter Pattern** - Provider-specific adapters implement common interface
6568
3. **Frontmatter-driven config** - Per-note settings override globals
66-
4. **Streaming responses** - Real-time AI output with SSE
69+
4. **Streaming responses** - Real-time AI output via Vercel AI SDK
6770
5. **Link context injection** - Auto-include `[[Wiki Links]]` in prompts

README.md

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,15 @@
11
# ChatGPT MD
22

3-
🚀 A seamless integration of ChatGPT, OpenRouter.ai and local LLMs via Ollama into Obsidian.
3+
🚀 A seamless integration of ChatGPT, OpenRouter.ai and local LLMs via Ollama/LM Studio into Obsidian.
44

55
![Chatting with links about vacation plans](images/chat-with-link.gif)
66

7-
## 🚀 What's New in v3.0.0: Privacy-First AI Tool Calling
7+
## 🚀 What's New in v3.0.0: Privacy-First AI Tool Calling (off by default - Settings → ChatGPT MD → Tool Calling)
88

9-
**Your AI assistant can now search your vault, read files, and search the web—with explicit approval at every step.**
9+
**Your AI assistant can now actively search your vault, read files, and query the web—with a human-in-the-loop architecture that keeps you in control.**
1010

11-
### Key Features
11+
v3.0.0 introduces a **tool calling system** built on privacy-first principles. When your AI needs information, it requests permission to use tools—you approve execution, review results, and control exactly what gets shared back to the model. Nothing leaves your vault without explicit consent.
1212

13-
- **🔍 Vault Search**: AI discovers relevant notes in your vault (you approve which files to share)
14-
- **📄 File Reading**: AI can request access to specific files (you select which ones)
15-
- **🌐 Web Search**: AI searches the web via Brave Search API (1,000 free queries/month)
16-
- **✅ Three-Layer Approval System**:
17-
1. Approve what the AI wants to do
18-
2. Review what it found
19-
3. Select exactly which results to share
20-
- **🔒 Privacy-First Design**: No data reaches the AI without your explicit consent
21-
- **🎯 All Providers Supported**: OpenAI, Anthropic, Gemini, OpenRouter, Ollama, LM Studio
22-
- **⚙️ Disabled by Default**: Opt-in feature only—enable in Settings → Tool Calling
23-
24-
### Why This Matters
25-
26-
For privacy-conscious note-takers, this is a game-changer. You get the power of AI with full control over your data. Your vault stays yours.
27-
28-
### Getting Started with Tool Calling
29-
30-
1. **Install the beta**: Use [BRAT plugin](https://github.com/TfTHacker/obsidian42-brat) and select version **2.12.0-beta**
31-
2. **Enable in settings**: Go to Settings → ChatGPT MD → Tool Calling
32-
3. **Optional**: Add Brave Search API key for web search (1,000 free queries/month)
33-
4. **Start chatting**: Your AI will ask for approval when it wants to use tools
34-
35-
⚠️ **Beta Warning**: Test on a backup/test vault first. This is a beta release with active development.
36-
37-
### Use Cases
38-
39-
- **Research Assistant**: "Search my vault for notes about quantum computing and find recent papers"
40-
- **Knowledge Synthesis**: "Find all my Q3 meeting notes and summarize key decisions"
41-
- **Web-Enhanced Writing**: "Search the web for latest statistics and incorporate them"
42-
- **Note Discovery**: "Find connections between notes I might have missed"
4313

4414
## A simple and quick Start 🏁
4515
Get started in just a few simple steps:
@@ -160,6 +130,77 @@ openaiUrl: https://api.openai.com
160130
💡 Pro tip: Increasing `max_tokens` to a higher value e.g. `4096` for more complex tasks like reasoning, coding or text creation.
161131
The default model `gpt-5-mini` is optimized for speed and efficiency. Upgrade to `gpt-5` for enhanced reasoning capabilities or use `gpt-5-nano` for ultra-lightweight responses.
162132

133+
### Tools
134+
135+
1. **Install**: Update or install v3.0.0+ from Obsidian
136+
2. **Configure**: Settings → ChatGPT MD → Tool Calling → Enable,
137+
3. **Optional**: Add [Brave Search API key](https://brave.com/search/api/) (free tier: 1,000 queries/month)
138+
4. **Chat**: Use the `ChatGPT MD: Chat` command. AI will request tool use when needed.
139+
140+
The implementation follows a three-layer approval pattern:
141+
142+
1. **Execution Layer**: AI requests tool use with parameters
143+
2. **Processing Layer**: Tool executes locally in your vault using Obsidian's API (full-text search across filenames and content)
144+
3. **Approval Layer**: Interactive modals let you filter results before they're returned to the AI
145+
146+
### Available Tools
147+
148+
**Vault Search** (`vault_search`)
149+
- Multi-word OR search: matches ANY query term across your vault
150+
- Searches both filenames and file content simultaneously
151+
- Excludes current file to prevent recursion
152+
- Configurable result limits (default: 5 files)
153+
- Query editing: refine search terms before execution
154+
155+
**File Read** (`file_read`)
156+
- Direct file access when AI knows specific file paths
157+
- Batch reading support for multiple files
158+
- Full content extraction with your approval
159+
- Useful for targeted lookups once files are discovered
160+
161+
**Web Search** (`web_search`)
162+
- Powered by Brave Search API (privacy-focused, 1,000 free queries/month)
163+
- Custom search provider support for self-hosted endpoints
164+
- Optional full-page content fetching
165+
- Automatic API key validation—tool only appears when configured
166+
- Query editing: modify web search queries before execution
167+
168+
### Privacy & Security
169+
170+
- **Local-First Execution**: All vault operations run entirely within Obsidian's API
171+
- **Selective Sharing**: Multi-select modals let you choose exactly which results to share
172+
- **No Telemetry**: Zero tracking or analytics—tool usage stays private
173+
174+
### Configuration
175+
176+
Enable tool calling in **Settings → ChatGPT MD → Tool Calling**:
177+
178+
- **Enable Tool Calling**: Master switch (default: disabled)
179+
- **Brave Search API Key**: Your Brave Search API key
180+
- **Custom Provider URL**: Self-hosted search endpoint
181+
- **Max Web Results**: Number of web results to return (1-10)
182+
183+
### Use Cases
184+
185+
**Research Assistant**: "Search my vault for notes about quantum computing algorithms and recent papers on the topic"
186+
187+
→ AI discovers relevant notes → You approve which files to share → AI synthesizes information with proper attribution
188+
189+
**Knowledge Synthesis**: "Find all my Q3 meeting notes and summarize key decisions about product roadmap"
190+
191+
→ Vault search returns meeting files → You select the relevant ones → AI extracts and summarizes decisions
192+
193+
**Web-Enhanced Writing**: "Search the web for latest climate change statistics and incorporate them into my article"
194+
195+
→ Web search fetches current data → You filter reliable sources → AI integrates citations into your draft
196+
197+
**Cross-Reference Discovery**: "Find notes that mention both machine learning and productivity techniques"
198+
199+
→ Multi-word OR search finds intersections → You approve interesting connections → AI highlights patterns you might have missed
200+
201+
⚠️ **Note**: Tool support depends on model capabilities. Older models may not support function calling. You can check tool capabilities in the tool selection list after enabling tool support in the settings.
202+
203+
163204
### Multi Model Chats
164205
You can set and change the model for each request in your note.
165206
Specify the `model` property via frontmatter:

0 commit comments

Comments
 (0)