3 Commits
Author SHA1 Message Date
AlexKucera 38c977b9aa Removes redundant settings header
Simplifies the user interface by removing an unnecessary
settings header that is no longer needed for functionality
clarity or user guidance.
2025-11-09 22:13:02 +01:00
AlexKucera fa59c14cbd Improves error notices and settings descriptions
Refines user-facing text in error notices and settings to improve
clarity and user experience. Standardizes settings header creation,
updates placeholder text, and simplifies setting descriptions.
2025-11-09 17:29:05 +01:00
AlexKucera 1f69c568bb Refines settings UI and error handling
Simplifies commentary prompt assignments and streamlines
the Freewriting Cleanup Plugin command registration.

Improves consistency and readability in the settings interface
by standardizing heading and button labels. Removes redundant
model selection logging.

This enhances user experience by making the interface
more intuitive and declutters the codebase for easier maintenance.
2025-11-09 17:17:37 +01:00
5 changed files with 49 additions and 58 deletions

No files matched your search

+1 -1
View File
@@ -78,7 +78,7 @@ export class AnthropicClient {
} else if (commentaryStyle === 'custom') { } else if (commentaryStyle === 'custom') {
throw new ConfigurationError('Custom commentary style requires a custom prompt. Please provide customCommentaryPrompt.'); throw new ConfigurationError('Custom commentary style requires a custom prompt. Please provide customCommentaryPrompt.');
} else { } else {
commentaryPrompt = COMMENTARY_PRESETS[commentaryStyle as Exclude<CommentaryStyle, 'custom'>]; commentaryPrompt = COMMENTARY_PRESETS[commentaryStyle];
} }
} }
+1 -1
View File
@@ -92,7 +92,7 @@ export class CleanupCommand {
} else if (error instanceof ServiceUnavailableError) { } else if (error instanceof ServiceUnavailableError) {
new Notice(error.message); new Notice(error.message);
} else if (error instanceof InvalidResponseError) { } else if (error instanceof InvalidResponseError) {
new Notice('Received an unexpected response from Claude. Please try again.'); new Notice('Received an unexpected response from Claude. Please try again');
} else if (error instanceof NetworkError) { } else if (error instanceof NetworkError) {
new Notice('Network error. Check your connection and try again.'); new Notice('Network error. Check your connection and try again.');
} else if (error instanceof Error) { } else if (error instanceof Error) {
+2 -2
View File
@@ -72,7 +72,7 @@ export default class FreewritingCleanupPlugin extends Plugin {
*/ */
async loadSettings(): Promise<FreewritingCleanupData | null> { async loadSettings(): Promise<FreewritingCleanupData | null> {
const data = await this.loadData() as FreewritingCleanupData | null; const data = await this.loadData() as FreewritingCleanupData | null;
const { modelCache, ...persisted } = data ?? {}; const { ...persisted } = data ?? {};
this.settings = { this.settings = {
...DEFAULT_SETTINGS, ...DEFAULT_SETTINGS,
...(persisted as Partial<FreewritingCleanupSettings>) ...(persisted as Partial<FreewritingCleanupSettings>)
@@ -111,7 +111,7 @@ export default class FreewritingCleanupPlugin extends Plugin {
*/ */
private registerCommand() { private registerCommand() {
this.addCommand({ this.addCommand({
id: 'freewriting-cleanup-cleanup-text', id: 'cleanup-text',
name: 'Clean up text', name: 'Clean up text',
editorCallback: async (editor: Editor, view: MarkdownView) => { editorCallback: async (editor: Editor, view: MarkdownView) => {
await this.executeCleanupCommand(editor, view); await this.executeCleanupCommand(editor, view);
+22 -28
View File
@@ -1,7 +1,6 @@
// ABOUTME: Service class for orchestrating freewriting text cleanup operations // ABOUTME: Service class for orchestrating freewriting text cleanup operations
// ABOUTME: Handles validation, API coordination, and result formatting // ABOUTME: Handles validation, API coordination, and result formatting
import { Notice } from 'obsidian';
import { AnthropicClient } from '../api/anthropicClient'; import { AnthropicClient } from '../api/anthropicClient';
import { FreewritingCleanupSettings, CleanupResult, ANTHROPIC_LIMITS } from '../types'; import { FreewritingCleanupSettings, CleanupResult, ANTHROPIC_LIMITS } from '../types';
import { ApiKeyError, TextTooLongError } from '../errors'; import { ApiKeyError, TextTooLongError } from '../errors';
@@ -64,36 +63,31 @@ export class CleanupService {
const startTime = Date.now(); const startTime = Date.now();
try { const { cleanedText, commentary, usage } = await this.client.cleanupText(
const { cleanedText, commentary, usage } = await this.client.cleanupText( text,
text, settings.model,
settings.model, settings.cleanupPrompt,
settings.cleanupPrompt, settings.enableCommentary,
settings.enableCommentary, settings.commentaryStyle,
settings.commentaryStyle, settings.customCommentaryPrompt
settings.customCommentaryPrompt );
);
const duration = Date.now() - startTime; const duration = Date.now() - startTime;
const result: CleanupResult = { const result: CleanupResult = {
originalText: text, originalText: text,
cleanedText, cleanedText,
commentary, commentary,
timestamp: new Date(), timestamp: new Date(),
model: settings.model, model: settings.model,
tokensUsed: { tokensUsed: {
input: usage?.input_tokens ?? 0, input: usage?.input_tokens ?? 0,
output: usage?.output_tokens ?? 0 output: usage?.output_tokens ?? 0
}, },
duration duration
}; };
return result; return result;
} catch (error) {
// Let the command layer handle user feedback to avoid duplicate notices
throw error;
}
} }
/** /**
+23 -26
View File
@@ -54,7 +54,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
private scheduleSave(): void { private scheduleSave(): void {
if (this.saveDebounce !== null) window.clearTimeout(this.saveDebounce); if (this.saveDebounce !== null) window.clearTimeout(this.saveDebounce);
this.saveDebounce = window.setTimeout(() => { this.saveDebounce = window.setTimeout(() => {
this.plugin.saveSettings(); void this.plugin.saveSettings();
this.saveDebounce = null; this.saveDebounce = null;
}, 300); }, 300);
} }
@@ -70,8 +70,6 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
const { containerEl } = this; const { containerEl } = this;
containerEl.empty(); containerEl.empty();
containerEl.createEl('h2', { text: 'Freewriting Cleanup Settings' });
// Load models asynchronously in the background // Load models asynchronously in the background
this.loadModels() this.loadModels()
.then(() => { .then(() => {
@@ -86,13 +84,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - API Configuration // MARK: - API Configuration
containerEl.createEl('h3', { text: 'API Configuration' }); new Setting(containerEl).setName('API configuration').setHeading();
new Setting(containerEl) new Setting(containerEl)
.setName('Anthropic API Key') .setName('Anthropic API key')
.setDesc('Your Anthropic API key for Claude. Get one at https://console.anthropic.com/') .setDesc('Your Anthropic API key for Claude. Get one at https://console.anthropic.com/')
.addText(text => text .addText(text => text
.setPlaceholder('sk-ant-...') .setPlaceholder('Enter API key')
.setValue(this.plugin.settings.apiKey) .setValue(this.plugin.settings.apiKey)
.onChange(async (value) => { .onChange(async (value) => {
this.plugin.settings.apiKey = value; this.plugin.settings.apiKey = value;
@@ -115,17 +113,17 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
}); });
new Setting(containerEl) new Setting(containerEl)
.setName('Test API Key') .setName('Test API key')
.setDesc('Test your API key to verify it works correctly') .setDesc('Test your API key to verify it works correctly')
.addButton(button => button .addButton(button => button
.setButtonText('Test Connection') .setButtonText('Test connection')
.onClick(async () => { .onClick(async () => {
await this.testApiKey(button); await this.testApiKey(button);
})); }));
new Setting(containerEl) new Setting(containerEl)
.setName('Claude Model') .setName('Claude model')
.setDesc('Which Claude model to use for text cleanup') .setDesc('Claude model to use for text cleanup')
.addDropdown(dropdown => { .addDropdown(dropdown => {
this.modelDropdown = dropdown; this.modelDropdown = dropdown;
this.populateModelDropdown(dropdown); this.populateModelDropdown(dropdown);
@@ -139,16 +137,16 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Cleanup Configuration // MARK: - Cleanup Configuration
containerEl.createEl('h3', { text: 'Cleanup Configuration' }); new Setting(containerEl).setName('Cleanup configuration').setHeading();
new Setting(containerEl) new Setting(containerEl)
.setName('Cleanup Prompt') .setName('Cleanup prompt')
.setDesc('Instructions for how Claude should clean up your freewriting text') .setDesc('Instructions for how to clean up your freewriting text')
.addTextArea(textArea => { .addTextArea(textArea => {
textArea textArea
.setPlaceholder('Enter your cleanup instructions...') .setPlaceholder('Enter your cleanup instructions...')
.setValue(this.plugin.settings.cleanupPrompt) .setValue(this.plugin.settings.cleanupPrompt)
.onChange(async (value) => { .onChange((value) => {
this.plugin.settings.cleanupPrompt = value; this.plugin.settings.cleanupPrompt = value;
this.scheduleSave(); this.scheduleSave();
}); });
@@ -160,14 +158,14 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Commentary Configuration // MARK: - Commentary Configuration
containerEl.createEl('h3', { text: 'AI Commentary' }); new Setting(containerEl).setName('AI commentary').setHeading();
new Setting(containerEl) new Setting(containerEl)
.setName('AI should comment on text') .setName('AI should comment on text')
.setDesc('After cleaning up your text, AI will provide thoughtful commentary on your freewriting session') .setDesc('After cleaning up your text, AI will provide thoughtful commentary on your freewriting session')
.addToggle(toggle => toggle .addToggle(toggle => toggle
.setValue(this.plugin.settings.enableCommentary) .setValue(this.plugin.settings.enableCommentary)
.onChange(async (value) => { .onChange((value) => {
this.plugin.settings.enableCommentary = value; this.plugin.settings.enableCommentary = value;
this.scheduleSave(); this.scheduleSave();
this.display(); // Refresh to show/hide commentary options this.display(); // Refresh to show/hide commentary options
@@ -175,7 +173,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
if (this.plugin.settings.enableCommentary) { if (this.plugin.settings.enableCommentary) {
new Setting(containerEl) new Setting(containerEl)
.setName('Commentary Style') .setName('Commentary style')
.setDesc('Choose the type of feedback AI should provide') .setDesc('Choose the type of feedback AI should provide')
.addDropdown(dropdown => { .addDropdown(dropdown => {
COMMENTARY_STYLES.forEach(style => { COMMENTARY_STYLES.forEach(style => {
@@ -184,7 +182,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
}); });
dropdown dropdown
.setValue(this.plugin.settings.commentaryStyle) .setValue(this.plugin.settings.commentaryStyle)
.onChange(async (value) => { .onChange((value) => {
this.plugin.settings.commentaryStyle = value as CommentaryStyle; this.plugin.settings.commentaryStyle = value as CommentaryStyle;
this.scheduleSave(); this.scheduleSave();
this.display(); // Refresh to show/hide custom prompt this.display(); // Refresh to show/hide custom prompt
@@ -193,13 +191,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
if (this.plugin.settings.commentaryStyle === 'custom') { if (this.plugin.settings.commentaryStyle === 'custom') {
new Setting(containerEl) new Setting(containerEl)
.setName('Custom Commentary Prompt') .setName('Custom commentary prompt')
.setDesc('Instructions for how AI should comment on your freewriting') .setDesc('Instructions for how AI should comment on your freewriting')
.addTextArea(textArea => { .addTextArea(textArea => {
textArea textArea
.setPlaceholder('Enter your commentary instructions...') .setPlaceholder('Enter your commentary instructions...')
.setValue(this.plugin.settings.customCommentaryPrompt) .setValue(this.plugin.settings.customCommentaryPrompt)
.onChange(async (value) => { .onChange((value) => {
this.plugin.settings.customCommentaryPrompt = value; this.plugin.settings.customCommentaryPrompt = value;
this.scheduleSave(); this.scheduleSave();
}); });
@@ -210,7 +208,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
}); });
} else { } else {
// Show the current preset for reference // Show the current preset for reference
const presetText = COMMENTARY_PRESETS[this.plugin.settings.commentaryStyle as Exclude<CommentaryStyle, 'custom'>]; const presetText = COMMENTARY_PRESETS[this.plugin.settings.commentaryStyle];
const descDiv = containerEl.createDiv({ cls: 'setting-item-description freewriting-cleanup-description' }); const descDiv = containerEl.createDiv({ cls: 'setting-item-description freewriting-cleanup-description' });
descDiv.empty(); descDiv.empty();
descDiv.createEl('strong', { text: 'Selected style: ' }); descDiv.createEl('strong', { text: 'Selected style: ' });
@@ -220,7 +218,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Usage Information // MARK: - Usage Information
containerEl.createEl('h3', { text: 'Usage Information' }); new Setting(containerEl).setName('Usage information').setHeading();
const usageDiv = containerEl.createDiv(); const usageDiv = containerEl.createDiv();
usageDiv.empty(); usageDiv.empty();
@@ -243,13 +241,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Reset Settings // MARK: - Reset Settings
containerEl.createEl('h3', { text: 'Reset' }); new Setting(containerEl).setName('Reset').setHeading();
new Setting(containerEl) new Setting(containerEl)
.setName('Reset to Defaults') .setName('Reset to defaults')
.setDesc('Reset all settings to their default values') .setDesc('Reset all settings to their default values')
.addButton(button => button .addButton(button => button
.setButtonText('Reset Settings') .setButtonText('Reset settings')
.setWarning() .setWarning()
.onClick(async () => { .onClick(async () => {
await this.resetSettings(); await this.resetSettings();
@@ -334,7 +332,6 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
const newModel = this.availableModels[0].id; const newModel = this.availableModels[0].id;
this.plugin.settings.model = newModel; this.plugin.settings.model = newModel;
this.modelDropdown.setValue(newModel); this.modelDropdown.setValue(newModel);
console.log(`Model '${currentModel}' no longer available, switched to '${newModel}'`);
} }
} }