From 55dd3e51481292962df36d06eafefe2d62f8ddf4 Mon Sep 17 00:00:00 2001 From: gobeumsu Date: Sun, 28 Dec 2025 14:39:57 +0900 Subject: [PATCH] fix: extract magic number to named constant Replace hardcoded `0.2` with `COMMON_CONSTANTS.MIN_RELIABILITY_THRESHOLD` to improve code readability and maintainability. --- src/api/constants.ts | 1 + src/main.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/constants.ts b/src/api/constants.ts index 056b0ea..698c573 100644 --- a/src/api/constants.ts +++ b/src/api/constants.ts @@ -6,6 +6,7 @@ export const COMMON_CONSTANTS = { DEFAULT_RELIABILITY_MIN: 0, DEFAULT_RELIABILITY_MAX: 1, DEFAULT_TEMPERATURE: 0.7, + MIN_RELIABILITY_THRESHOLD: 0.2, VERIFY_CONNECTION_SYSTEM_PROMPT: 'You are a test system. You must respond with valid JSON.', VERIFY_CONNECTION_USER_PROMPT: 'Return a JSON object containing {"output": [], "reliability": 0}', }; diff --git a/src/main.ts b/src/main.ts index b621b25..3a3bd34 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import { processAPIRequest } from 'api'; import type { TFile } from 'obsidian'; import { Plugin } from 'obsidian'; import { CommonNotice } from 'ui/components/common/CommonNotice'; +import { COMMON_CONSTANTS } from './api/constants'; import { DEFAULT_SYSTEM_ROLE, getPromptTemplate } from './api/prompt'; import type { ProviderConfig } from './api/types'; import { getContentWithoutFrontmatter, getTags, insertToFrontMatter } from './frontmatter'; @@ -130,7 +131,7 @@ export default class AutoClassifierPlugin extends Plugin { ) ); - if (apiResponse && apiResponse.reliability > 0.2) { + if (apiResponse && apiResponse.reliability > COMMON_CONSTANTS.MIN_RELIABILITY_THRESHOLD) { const processFrontMatter = (file: TFile, fn: (frontmatter: any) => void) => this.app.fileManager.processFrontMatter(file, fn);