refactor: Restructure file search settings

This commit restructures the file search settings. The previously individual settings for file search method, regex search backend, match search backend, and ripgrep path have been grouped into a new filesSearchSettings object.
This commit is contained in:
travertexg 2025-06-10 06:54:25 +00:00
parent a00b640dad
commit f0be561cfc
10 changed files with 63 additions and 28 deletions

View File

@ -611,7 +611,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
}
}
} else if (toolArgs.type === 'match_search_files') {
const searchBackend = settings.matchSearchBackend
const searchBackend = settings.filesSearchSettings.matchBackend
let results: string;
if (searchBackend === 'omnisearch') {
results = await matchSearchUsingOmnisearch(toolArgs.query, app)
@ -633,7 +633,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
}
}
} else if (toolArgs.type === 'regex_search_files') {
const searchBackend = settings.regexSearchBackend
const searchBackend = settings.filesSearchSettings.regexBackend
let results: string;
if (searchBackend === 'coreplugin') {
results = await regexSearchUsingCorePlugin(toolArgs.regex, app)
@ -641,7 +641,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
// @ts-expect-error Obsidian API type mismatch
const baseVaultPath = String(app.vault.adapter.getBasePath())
const absolutePath = path.join(baseVaultPath, toolArgs.filepath)
const ripgrepPath = settings.ripgrepPath
const ripgrepPath = settings.filesSearchSettings.ripgrepPath
results = await regexSearchUsingRipgrep(absolutePath, toolArgs.regex, ripgrepPath)
}
const formattedContent = `[regex_search_files for '${toolArgs.filepath}'] Result:\n${results}\n`;

View File

@ -367,7 +367,7 @@ const CustomModeView = () => {
{t('prompt.overrideWarning')} <button
className="infio-preview-btn"
onClick={async () => {
let filesSearchMethod = settings.filesSearchMethod
let filesSearchMethod = settings.filesSearchSettings.method
if (filesSearchMethod === 'auto' && settings.embeddingModelId && settings.embeddingModelId !== '') {
filesSearchMethod = 'semantic'
}

View File

@ -3,6 +3,7 @@ import * as path from 'path'
import { App, normalizePath } from 'obsidian'
import { FilesSearchSettings } from "../../types/settings"
import {
CustomModePrompts,
Mode,
@ -68,6 +69,7 @@ export class SystemPrompt {
cwd: string,
supportsComputerUse: boolean,
mode: Mode,
searchSettings: FilesSearchSettings,
filesSearchMethod: string,
mcpHub?: McpHub,
diffStrategy?: DiffStrategy,
@ -105,6 +107,7 @@ ${getSharedToolUseSection()}
${getToolDescriptionsForMode(
mode,
cwd,
searchSettings,
filesSearchMethod,
supportsComputerUse,
diffStrategy,
@ -148,6 +151,7 @@ ${await addCustomInstructions(this.app, promptComponent?.customInstructions || m
cwd: string,
supportsComputerUse: boolean,
mode: Mode = defaultModeSlug,
searchSettings: FilesSearchSettings,
filesSearchMethod: string = 'regex',
preferredLanguage?: string,
diffStrategy?: DiffStrategy,
@ -203,6 +207,7 @@ ${customInstructions}`
cwd,
supportsComputerUse,
currentMode.slug,
searchSettings,
filesSearchMethod,
mcpHub,
diffStrategy,

View File

@ -1,6 +1,7 @@
import { Mode, ModeConfig, getGroupName, getModeConfig, isToolAllowedForMode } from "../../../utils/modes"
import { DiffStrategy } from "../../diff/DiffStrategy"
import { McpHub } from "../../mcp/McpHub"
import { FilesSearchSettings } from "../../../types/settings"
import { getAccessMcpResourceDescription } from "./access-mcp-resource"
import { getAskFollowupQuestionDescription } from "./ask-followup-question"
@ -40,6 +41,7 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
export function getToolDescriptionsForMode(
mode: Mode,
cwd: string,
searchSettings: FilesSearchSettings,
searchTool: string,
supportsComputerUse: boolean,
diffStrategy?: DiffStrategy,
@ -51,6 +53,7 @@ export function getToolDescriptionsForMode(
const config = getModeConfig(mode, customModes)
const args: ToolArgs = {
cwd,
searchSettings,
searchTool,
supportsComputerUse,
diffStrategy,

View File

@ -1,5 +1,4 @@
import { ToolArgs } from "./types"
import { useSettings } from '../../../contexts/SettingsContext'
export function getSearchFilesDescription(args: ToolArgs): string {
if (args.searchTool === 'match') {
@ -34,9 +33,8 @@ Example: Requesting to search for all Markdown files containing 'test' in the cu
}
export function getRegexSearchFilesDescription(args: ToolArgs): string {
const { settings } = useSettings()
let regex_syntax: string;
switch (settings.regexSearchBackend) {
switch (args.searchSettings.regexBackend) {
case 'coreplugin':
regex_syntax = "ECMAScript (JavaScript)";
break;

View File

@ -1,8 +1,10 @@
import { FilesSearchSettings } from "../../../types/settings"
import { DiffStrategy } from "../../diff/DiffStrategy"
import { McpHub } from "../../mcp/McpHub"
export type ToolArgs = {
cwd: string
searchSettings: FilesSearchSettings,
searchTool?: string,
supportsComputerUse: boolean
diffStrategy?: DiffStrategy

View File

@ -156,11 +156,14 @@ export class InfioSettingTab extends PluginSettingTab {
.addOption('semantic', t('settings.FilesSearch.semantic'))
.addOption('regex', t('settings.FilesSearch.regex'))
.addOption('match', t('settings.FilesSearch.match'))
.setValue(this.plugin.settings.filesSearchMethod)
.setValue(this.plugin.settings.filesSearchSettings.method)
.onChange(async (value) => {
await this.plugin.setSettings({
...this.plugin.settings,
filesSearchMethod: value as 'match' | 'regex' | 'semantic' | 'auto',
filesSearchSettings: {
...this.plugin.settings.filesSearchSettings,
method: value as 'match' | 'regex' | 'semantic' | 'auto',
}
})
}),
)
@ -171,11 +174,14 @@ export class InfioSettingTab extends PluginSettingTab {
dropdown
.addOption('ripgrep', t('settings.FilesSearch.ripgrep'))
.addOption('coreplugin', t('settings.FilesSearch.coreplugin'))
.setValue(this.plugin.settings.regexSearchBackend)
.setValue(this.plugin.settings.filesSearchSettings.regexBackend)
.onChange(async (value) => {
await this.plugin.setSettings({
...this.plugin.settings,
regexSearchBackend: value as 'ripgrep' | 'coreplugin',
filesSearchSettings: {
...this.plugin.settings.filesSearchSettings,
regexBackend: value as 'ripgrep' | 'coreplugin',
}
})
}),
)
@ -186,11 +192,14 @@ export class InfioSettingTab extends PluginSettingTab {
dropdown
.addOption('coreplugin', t('settings.FilesSearch.coreplugin'))
.addOption('omnisearch', t('settings.FilesSearch.omnisearch'))
.setValue(this.plugin.settings.matchSearchBackend)
.setValue(this.plugin.settings.filesSearchSettings.matchBackend)
.onChange(async (value) => {
await this.plugin.setSettings({
...this.plugin.settings,
matchSearchBackend: value as 'coreplugin' | 'omnisearch',
filesSearchSettings: {
...this.plugin.settings.filesSearchSettings,
matchBackend: value as 'coreplugin' | 'omnisearch',
}
})
}),
)
@ -200,11 +209,14 @@ export class InfioSettingTab extends PluginSettingTab {
.addText((text) =>
text
.setPlaceholder('/opt/homebrew/bin/')
.setValue(this.plugin.settings.ripgrepPath)
.setValue(this.plugin.settings.filesSearchSettings.ripgrepPath)
.onChange(async (value) => {
await this.plugin.setSettings({
...this.plugin.settings,
ripgrepPath: value,
filesSearchSettings: {
...this.plugin.settings.filesSearchSettings,
ripgrepPath: value,
}
})
}),
)

View File

@ -12,9 +12,12 @@ describe('parseSmartCopilotSettings', () => {
infioApiKey: '',
openAIApiKey: '',
anthropicApiKey: '',
filesSearchMethod: 'auto',
regexSearchBackend: 'ripgrep',
matchSearchBackend: 'coreplugin',
filesSearchSettings: {
method: 'auto',
regexBackend: 'ripgrep',
matchBackend: 'coreplugin',
ripgrepPath: '',
},
fuzzyMatchThreshold: 0.85,
geminiApiKey: '',
groqApiKey: '',
@ -100,7 +103,6 @@ describe('parseSmartCopilotSettings', () => {
defaultMention: 'none',
removeDuplicateMathBlockIndicator: true,
removeDuplicateCodeBlockIndicator: true,
ripgrepPath: '',
serperApiKey: '',
serperSearchEngine: 'google',
ignoredFilePatterns: '**/secret/**\n',
@ -197,9 +199,12 @@ describe('settings migration', () => {
infioApiKey: '',
openAIApiKey: '',
anthropicApiKey: '',
filesSearchMethod: 'auto',
regexSearchBackend: 'ripgrep',
matchSearchBackend: 'coreplugin',
filesSearchSettings: {
method: 'auto',
regexBackend: 'ripgrep',
matchBackend: 'coreplugin',
ripgrepPath: '',
},
fuzzyMatchThreshold: 0.85,
geminiApiKey: '',
groqApiKey: '',
@ -285,7 +290,6 @@ describe('settings migration', () => {
defaultMention: 'none',
removeDuplicateMathBlockIndicator: true,
removeDuplicateCodeBlockIndicator: true,
ripgrepPath: '',
serperApiKey: '',
serperSearchEngine: 'google',
ignoredFilePatterns: '**/secret/**\n',

View File

@ -201,6 +201,18 @@ export const triggerSchema = z.object({
}
});
const FilesSearchSettingsSchema = z.object({
method: z.enum(['match', 'regex', 'semantic', 'auto']).catch('auto'),
regexBackend: z.enum(['coreplugin', 'ripgrep']).catch('ripgrep'),
matchBackend: z.enum(['omnisearch', 'coreplugin']).catch('coreplugin'),
ripgrepPath: z.string().catch(''),
}).catch({
method: 'auto',
regexBackend: 'ripgrep',
matchBackend: 'coreplugin',
ripgrepPath: '',
});
export const InfioSettingsSchema = z.object({
// Version
version: z.literal(SETTINGS_SCHEMA_VERSION).catch(SETTINGS_SCHEMA_VERSION),
@ -260,10 +272,7 @@ export const InfioSettingsSchema = z.object({
jinaApiKey: z.string().catch(''),
// Files Search
filesSearchMethod: z.enum(['match', 'regex', 'semantic', 'auto']).catch('auto'),
regexSearchBackend: z.enum(['coreplugin', 'ripgrep']).catch('ripgrep'),
matchSearchBackend: z.enum(['omnisearch', 'coreplugin']).catch('coreplugin'),
ripgrepPath: z.string().catch(''),
filesSearchSettings: FilesSearchSettingsSchema,
/// [compatible]
// activeModels [compatible]
@ -365,6 +374,7 @@ export const InfioSettingsSchema = z.object({
})
export type InfioSettings = z.infer<typeof InfioSettingsSchema>
export type FilesSearchSettings = z.infer<typeof FilesSearchSettingsSchema>
type Migration = {
fromVersion: number

View File

@ -182,7 +182,7 @@ export class PromptGenerator {
},
]
let filesSearchMethod = this.settings.filesSearchMethod
let filesSearchMethod = this.settings.filesSearchSettings.method
if (filesSearchMethod === 'auto' && this.settings.embeddingModelId && this.settings.embeddingModelId !== '') {
filesSearchMethod = 'semantic'
}
@ -520,6 +520,7 @@ export class PromptGenerator {
this.app.vault.getRoot().path,
false,
mode,
this.settings.filesSearchSettings,
filesSearchMethod,
preferredLanguage,
this.diffStrategy,