Merge pull request #1 from AlexKucera/coderabbit_fixes
Enhances plugin architecture and fixes issues
This commit was merged in pull request #1.
This commit is contained in:
8 files changed
+69
-52
No files matched your search
@@ -108,7 +108,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [1.0.2] - 2025-01-21
|
## [1.0.2] - 2025-09-21
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
- Fix innerHTML usage in settings to prevent XSS vulnerabilities
|
- Fix innerHTML usage in settings to prevent XSS vulnerabilities
|
||||||
|
|||||||
@@ -48,15 +48,20 @@ Manual testing requires copying build artifacts (`main.js`, `manifest.json`, `st
|
|||||||
- **Production**: Minified output without sourcemaps
|
- **Production**: Minified output without sourcemaps
|
||||||
|
|
||||||
### Plugin Structure
|
### Plugin Structure
|
||||||
The plugin follows Obsidian's standard plugin architecture:
|
The plugin follows a modular architecture extending Obsidian's standard plugin system:
|
||||||
- **Main Plugin Class**: `MyPlugin` extends `Plugin` from obsidian API
|
- **Main Plugin Class**: `FreewritingCleanupPlugin` extends `Plugin` from obsidian API
|
||||||
|
- **Service Layer**: `CleanupService` handles AI API interactions
|
||||||
|
- **Command Layer**: `CleanupCommand` implements text processing logic
|
||||||
- **Settings System**: Interface-based settings with persistence via `loadData()`/`saveData()`
|
- **Settings System**: Interface-based settings with persistence via `loadData()`/`saveData()`
|
||||||
- **Commands**: Registered via `addCommand()` with unique IDs
|
- **Type Definitions**: Centralized in `types.ts` for consistency
|
||||||
- **UI Components**: Modal and settings tab classes
|
- **Lifecycle Management**: Uses proper initialization and cleanup patterns
|
||||||
- **Lifecycle Management**: Uses `registerDomEvent()`, `registerInterval()` for cleanup
|
|
||||||
|
|
||||||
### Key Files
|
### Key Files
|
||||||
- `main.ts`: Plugin entry point containing all core functionality
|
- `main.ts`: Plugin entry point coordinating services and commands
|
||||||
|
- `types.ts`: TypeScript interfaces for settings, API responses, and plugin configuration
|
||||||
|
- `settings.ts`: Settings tab implementation and default configuration
|
||||||
|
- `services/cleanupService.ts`: AI service integration and API handling
|
||||||
|
- `commands/cleanupCommand.ts`: Command execution and text processing
|
||||||
- `manifest.json`: Plugin metadata (ID, version, compatibility)
|
- `manifest.json`: Plugin metadata (ID, version, compatibility)
|
||||||
- `package.json`: npm configuration with build scripts
|
- `package.json`: npm configuration with build scripts
|
||||||
- `esbuild.config.mjs`: Build configuration
|
- `esbuild.config.mjs`: Build configuration
|
||||||
@@ -66,33 +71,48 @@ The plugin follows Obsidian's standard plugin architecture:
|
|||||||
## Plugin Architecture Patterns
|
## Plugin Architecture Patterns
|
||||||
|
|
||||||
### Settings Management
|
### Settings Management
|
||||||
Settings are defined as TypeScript interfaces with default values and persisted automatically:
|
Settings use the `FreewritingCleanupSettings` interface with modular defaults:
|
||||||
```typescript
|
```typescript
|
||||||
interface MyPluginSettings {
|
interface FreewritingCleanupSettings {
|
||||||
mySetting: string;
|
apiKey: string;
|
||||||
|
model: AnthropicModel;
|
||||||
|
cleanupPrompt: string;
|
||||||
|
enableCommentary: boolean;
|
||||||
|
commentaryStyle: CommentaryStyle;
|
||||||
|
customCommentaryPrompt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_SETTINGS: MyPluginSettings = {
|
const DEFAULT_SETTINGS: FreewritingCleanupSettings = {
|
||||||
mySetting: 'default'
|
apiKey: '',
|
||||||
|
model: 'claude-3-5-haiku-latest',
|
||||||
|
cleanupPrompt: 'I did some free writing. Please correct my jumbled typo mess...',
|
||||||
|
enableCommentary: false,
|
||||||
|
commentaryStyle: 'constructive',
|
||||||
|
customCommentaryPrompt: 'Provide thoughtful feedback...'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Command Registration
|
### Command Registration
|
||||||
Commands should have stable IDs and descriptive names:
|
Commands use dedicated command classes with service injection:
|
||||||
- Use `addCommand()` for simple commands
|
- Main plugin registers commands via `addCommand()` with stable IDs
|
||||||
- Use `editorCallback` for editor-specific commands
|
- `CleanupCommand` class handles execution logic and editor interaction
|
||||||
- Use `checkCallback` for conditional commands
|
- Service dependencies injected during plugin initialization
|
||||||
|
|
||||||
|
### Service Architecture
|
||||||
|
- `CleanupService` manages Anthropic API integration and connection testing
|
||||||
|
- Service instances created during plugin load and updated when settings change
|
||||||
|
- Clean separation between API logic and UI components
|
||||||
|
|
||||||
### UI Components
|
### UI Components
|
||||||
- Modals extend `Modal` class with `onOpen()`/`onClose()` lifecycle
|
- `FreewritingCleanupSettingTab` extends `PluginSettingTab` with comprehensive configuration
|
||||||
- Settings tabs extend `PluginSettingTab` with `display()` method
|
- Custom confirmation modal for destructive operations
|
||||||
- Use Obsidian's `Setting` class for form controls
|
- Dynamic UI updates based on setting states (e.g., commentary options)
|
||||||
|
|
||||||
### Resource Cleanup
|
### Resource Cleanup
|
||||||
Critical for plugin stability:
|
Standard Obsidian plugin lifecycle with service coordination:
|
||||||
- Use `registerDomEvent()` for DOM listeners
|
- Services initialized in `onload()` with proper dependency injection
|
||||||
- Use `registerInterval()` for timers
|
- Settings persistence triggers service updates automatically
|
||||||
- Use `registerEvent()` for Obsidian app events
|
- Clean separation allows for easy testing and maintenance
|
||||||
|
|
||||||
## Release Process
|
## Release Process
|
||||||
1. Update `manifest.json` version (semantic versioning)
|
1. Update `manifest.json` version (semantic versioning)
|
||||||
@@ -102,7 +122,8 @@ Critical for plugin stability:
|
|||||||
5. Attach `manifest.json`, `main.js`, and `styles.css` as release assets
|
5. Attach `manifest.json`, `main.js`, and `styles.css` as release assets
|
||||||
|
|
||||||
## Development Notes
|
## Development Notes
|
||||||
- This is currently the default Obsidian sample plugin template
|
- Plugin uses modular architecture with separate services, commands, and settings
|
||||||
- All functionality is in `main.ts` - consider splitting into modules for real development
|
- Build process bundles all TypeScript modules into single `main.js` artifact
|
||||||
- Plugin demonstrates ribbon icons, status bar, commands, modals, and settings
|
- Service layer enables clean testing and API interaction separation
|
||||||
|
- Settings system provides comprehensive user configuration with dynamic UI updates
|
||||||
- Mobile compatibility controlled by `isDesktopOnly` flag in manifest
|
- Mobile compatibility controlled by `isDesktopOnly` flag in manifest
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# Freewriting Cleanup
|
# Freewriting Cleanup
|
||||||
|
|
||||||
[](https://github.com/AlexKucera/freewriting-cleanup/releases)
|
[](https://github.com/AlexKucera/freewriting-cleanup/releases)
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
[](https://github.com/AlexKucera/freewriting-cleanup/releases)
|
[](https://github.com/AlexKucera/freewriting-cleanup/releases)
|
||||||
[](https://coderabbit.ai/)
|
[](https://coderabbit.ai/)
|
||||||

|

|
||||||
|
|||||||
@@ -69,8 +69,8 @@ You MUST use exactly these markers. Do not deviate from this format.`;
|
|||||||
const request: AnthropicRequest = {
|
const request: AnthropicRequest = {
|
||||||
model,
|
model,
|
||||||
max_tokens: ANTHROPIC_LIMITS.DEFAULT_MAX_OUTPUT_TOKENS,
|
max_tokens: ANTHROPIC_LIMITS.DEFAULT_MAX_OUTPUT_TOKENS,
|
||||||
messages: [{ role: 'user', content: userMessage }],
|
messages: [{ role: 'user', content: [{ type: 'text', text: userMessage }] }],
|
||||||
system: systemPrompt
|
system: [{ type: 'text', text: systemPrompt }]
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await this.makeRequestWithRetry(request);
|
const response = await this.makeRequestWithRetry(request);
|
||||||
@@ -100,8 +100,8 @@ You MUST use exactly these markers. Do not deviate from this format.`;
|
|||||||
const testRequest: AnthropicRequest = {
|
const testRequest: AnthropicRequest = {
|
||||||
model,
|
model,
|
||||||
max_tokens: 50,
|
max_tokens: 50,
|
||||||
messages: [{ role: 'user', content: 'Hello! Please respond with just "Test successful."' }],
|
messages: [{ role: 'user', content: [{ type: 'text', text: 'Hello! Please respond with just "Test successful."' }] }],
|
||||||
system: 'You are a test assistant. Respond only with "Test successful." and nothing else.'
|
system: [{ type: 'text', text: 'You are a test assistant. Respond only with "Test successful." and nothing else.' }]
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ export class CleanupCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate text length before proceeding
|
// Validate text selection before proceeding
|
||||||
const limits = CleanupService.isWithinLimits(selectedText);
|
const validation = this.validateSelection(selectedText);
|
||||||
if (!limits.withinCharacterLimit) {
|
if (!validation.isValid) {
|
||||||
new Notice(`Selected text is too long (${limits.characterCount} characters). Maximum: 680,000 characters.`);
|
new Notice(validation.error || 'Invalid text selection');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,19 +87,6 @@ export class CleanupCommand {
|
|||||||
|
|
||||||
// MARK: - Helper Methods
|
// MARK: - Helper Methods
|
||||||
|
|
||||||
private getInsertionPosition(editor: Editor): { line: number; ch: number } {
|
|
||||||
const selection = editor.listSelections()[0];
|
|
||||||
if (selection) {
|
|
||||||
// Insert after the selection
|
|
||||||
return {
|
|
||||||
line: selection.head.line,
|
|
||||||
ch: editor.getLine(selection.head.line).length
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to current cursor position
|
|
||||||
return editor.getCursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
private formatSelectedTextInfo(text: string): string {
|
private formatSelectedTextInfo(text: string): string {
|
||||||
const characterCount = text.length;
|
const characterCount = text.length;
|
||||||
|
|||||||
+4
-1
@@ -254,7 +254,7 @@ class ConfirmModal {
|
|||||||
private title: string;
|
private title: string;
|
||||||
private message: string;
|
private message: string;
|
||||||
private callback: (result: boolean) => void;
|
private callback: (result: boolean) => void;
|
||||||
private modalEl: HTMLElement;
|
private modalEl: HTMLElement | null = null;
|
||||||
|
|
||||||
constructor(app: App, title: string, message: string, callback: (result: boolean) => void) {
|
constructor(app: App, title: string, message: string, callback: (result: boolean) => void) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
@@ -284,7 +284,9 @@ class ConfirmModal {
|
|||||||
const confirmButton = buttons.createEl('button', { text: 'Confirm', cls: 'mod-warning' });
|
const confirmButton = buttons.createEl('button', { text: 'Confirm', cls: 'mod-warning' });
|
||||||
confirmButton.onclick = () => this.close(true);
|
confirmButton.onclick = () => this.close(true);
|
||||||
|
|
||||||
|
if (this.modalEl) {
|
||||||
document.body.appendChild(this.modalEl);
|
document.body.appendChild(this.modalEl);
|
||||||
|
}
|
||||||
confirmButton.focus();
|
confirmButton.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,6 +294,7 @@ class ConfirmModal {
|
|||||||
if (this.modalEl && this.modalEl.parentNode) {
|
if (this.modalEl && this.modalEl.parentNode) {
|
||||||
this.modalEl.parentNode.removeChild(this.modalEl);
|
this.modalEl.parentNode.removeChild(this.modalEl);
|
||||||
}
|
}
|
||||||
|
this.modalEl = null;
|
||||||
this.callback(result);
|
this.callback(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,14 +12,20 @@ export interface FreewritingCleanupSettings {
|
|||||||
|
|
||||||
export interface AnthropicMessage {
|
export interface AnthropicMessage {
|
||||||
role: 'user' | 'assistant' | 'system';
|
role: 'user' | 'assistant' | 'system';
|
||||||
content: string;
|
content: Array<{
|
||||||
|
type: string;
|
||||||
|
text: string;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AnthropicRequest {
|
export interface AnthropicRequest {
|
||||||
model: string;
|
model: string;
|
||||||
max_tokens: number;
|
max_tokens: number;
|
||||||
messages: AnthropicMessage[];
|
messages: AnthropicMessage[];
|
||||||
system?: string;
|
system?: Array<{
|
||||||
|
type: string;
|
||||||
|
text: string;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AnthropicResponse {
|
export interface AnthropicResponse {
|
||||||
|
|||||||
Reference in new issue
Block a user