Skip to content

Commit 9533224

Browse files
committed
updates CLAUDE.md files
1 parent 481ff55 commit 9533224

File tree

9 files changed

+666
-468
lines changed

9 files changed

+666
-468
lines changed

CLAUDE.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +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)
12-
13-
Major new feature: **Privacy-first AI tool calling** with human-in-the-loop approval:
11+
Major feature: **Privacy-first AI tool calling** with human-in-the-loop approval:
1412

1513
- **Vault Search**: AI can search your notes (you approve which files to share)
1614
- **File Reading**: AI can request access to specific files (you select which ones)
1715
- **Web Search**: AI can search the web via Brave Search API (1,000 free queries/month)
1816
- **Three-Layer Approval**: Approve execution → Review results → Select what to share
19-
- **All tools disabled by default** (opt-in feature only)
20-
21-
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)
2218

2319
## Quick Reference
2420

2521
**Entry point**: `src/main.ts``main.js`
2622

27-
**Common commands**:
23+
**Commands**:
2824

2925
```bash
3026
npm run dev # Development with watch mode
3127
npm run build # Production build with TypeScript checks
3228
npm run lint # Check code quality
3329
npm run lint:fix # Auto-fix linting issues
30+
npm run analyze # Bundle size analysis
3431
```
3532

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

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

40-
- `src/core/ServiceLocator.ts` - Central DI container
41-
- `src/core/CommandRegistry.ts` - Manages all Obsidian commands
42-
- 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
4342

44-
**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
4546

4647
## Code Organization
4748

48-
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:
4950

50-
- `src/core/` - Core infrastructure (ServiceLocator, CommandRegistry)
51-
- `src/Services/` - Service implementations
52-
- `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
5355
- `src/Models/` - TypeScript interfaces
56+
- `src/Types/` - AI service type definitions
57+
- `src/Utilities/` - Pure helper functions
5458

5559
## Cross-cutting Documentation
5660

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

6264
## Key Design Patterns
6365

64-
1. **Service Locator** - Centralized dependency injection
65-
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
6668
3. **Frontmatter-driven config** - Per-note settings override globals
67-
4. **Streaming responses** - Real-time AI output with SSE
69+
4. **Streaming responses** - Real-time AI output via Vercel AI SDK
6870
5. **Link context injection** - Auto-include `[[Wiki Links]]` in prompts

src/Commands/CLAUDE.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Commands
2+
3+
Obsidian command handlers extracted from the old `CommandRegistry.ts`.
4+
5+
## Architecture
6+
7+
Commands follow a handler pattern with interfaces defined in `CommandHandler.ts`:
8+
9+
```typescript
10+
interface CommandHandler {
11+
getCommand(): CommandMetadata; // { id, name, icon }
12+
}
13+
14+
interface EditorCommandHandler extends CommandHandler {
15+
execute(editor: Editor): void | Promise<void>;
16+
}
17+
18+
interface EditorViewCommandHandler extends CommandHandler {
19+
execute(editor: Editor, view: MarkdownView): void | Promise<void>;
20+
}
21+
22+
interface CallbackCommandHandler extends CommandHandler {
23+
execute(): void | Promise<void>;
24+
}
25+
```
26+
27+
## CommandRegistrar.ts
28+
29+
**Utility for simplifying command registration**
30+
31+
Reduces boilerplate in `main.ts`:
32+
33+
```typescript
34+
const registrar = new CommandRegistrar(plugin);
35+
registrar.registerEditorCommand(chatHandler);
36+
registrar.registerEditorViewCommand(inferTitleHandler);
37+
registrar.registerCallbackCommand(stopStreamingHandler);
38+
```
39+
40+
## Main Handlers
41+
42+
### ChatHandler.ts
43+
44+
**Main chat command** - The primary command users invoke.
45+
46+
Flow:
47+
48+
1. Get messages from editor via EditorService
49+
2. Parse frontmatter for model/settings
50+
3. Get appropriate AI service from AiProviderService
51+
4. Call AI API with messages + config
52+
5. Stream response to editor
53+
6. Optional auto title inference
54+
55+
Uses `ServiceContainer` for dependency injection.
56+
57+
### ModelSelectHandler.ts
58+
59+
**Model selection modal**
60+
61+
- Opens model selection modal
62+
- Fetches fresh models from all configured providers
63+
- Updates note frontmatter when selected
64+
65+
### InferTitleHandler.ts
66+
67+
**Generate title from conversation**
68+
69+
- Calls AI to suggest title based on messages
70+
- Renames note file with inferred title
71+
- Validates title (no special characters)
72+
73+
### StopStreamingHandler.ts
74+
75+
**Abort in-progress streaming**
76+
77+
- Calls `aiService.stopStreaming()`
78+
- Desktop only (uses abort controller)
79+
80+
## Utility Handlers
81+
82+
### SimpleHandlers.ts
83+
84+
Simple one-liner commands:
85+
86+
- **AddDividerHandler** - Inserts `<hr class="__chatgpt_plugin">`
87+
- **AddCommentBlockHandler** - Inserts comment block markers
88+
- **ClearChatHandler** - Removes messages, keeps frontmatter
89+
90+
### RemainingHandlers.ts
91+
92+
Additional commands:
93+
94+
- **NewChatWithHighlightedTextHandler** - Create chat from selection
95+
- **ChooseChatTemplateHandler** - Create chat from template
96+
97+
## CommandUtilities.ts
98+
99+
**Shared utilities for command handlers**
100+
101+
- `getAiApiUrls(frontmatter)` - Get service URLs from merged frontmatter
102+
- Status bar helpers
103+
104+
## StatusBarManager
105+
106+
Reusable status bar management:
107+
108+
```typescript
109+
class StatusBarManager {
110+
setText(text: string): void;
111+
clear(): void;
112+
}
113+
```

0 commit comments

Comments
 (0)