feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)

This commit is contained in:
Yun Chan 2026-10-31 02:54:54 +09:00
parent f49acf0105
commit 10af20a0ad
157 changed files with 29455 additions and 913 deletions

View file

@ -230,17 +230,103 @@ class DictionaryService {
/**
* 사전 단어 목록을 STT initialPrompt 형태로 반환한다.
* 발음(pronunciation)이 등록된 항목은 인식 힌트로 함께 포함한다.
*/
getPromptHints(limit = 50): string {
const db = getDatabase()
const words = db
.select({ word: dictionary.word })
.select({ word: dictionary.word, pronunciation: dictionary.pronunciation })
.from(dictionary)
.orderBy(desc(dictionary.usageCount))
.limit(limit)
.all()
return words.map((w) => w.word).join(', ')
return words
.map((w) => {
const pron = typeof w.pronunciation === 'string' ? w.pronunciation.trim() : ''
return pron ? `${w.word} (${pron})` : w.word
})
.join(', ')
}
getPromptHint(limit = 50): string {
return this.getPromptHints(limit)
}
/**
* 전사 텍스트에서 사전 단어 또는 발음(pronunciation) 변형을 찾아 표준 단어로 치환하고
* 매칭된 사전 항목의 사용 횟수(usageCount)를 증가시킨다.
*/
applyDictionaryCorrections(text: string): { text: string; matchedIds: string[] } {
if (!text || text.trim().length === 0) {
return { text, matchedIds: [] }
}
const db = getDatabase()
const entries = db
.select({
id: dictionary.id,
word: dictionary.word,
pronunciation: dictionary.pronunciation
})
.from(dictionary)
.orderBy(desc(dictionary.usageCount))
.all()
if (!entries || entries.length === 0) {
return { text, matchedIds: [] }
}
let currentText = text
const matchedIds: string[] = []
const escapeRegExp = (str: string): string => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const isAsciiWordChar = (ch: string | undefined): boolean => Boolean(ch && /[A-Za-z0-9]/.test(ch))
const buildTokenRegex = (token: string): RegExp => {
const escaped = escapeRegExp(token)
const prefix = isAsciiWordChar(token[0]) ? '(?<![A-Za-z0-9])' : ''
const suffix = isAsciiWordChar(token[token.length - 1]) ? '(?![A-Za-z0-9])' : ''
return new RegExp(`${prefix}${escaped}${suffix}`, 'gi')
}
for (const entry of entries) {
const canonicalWord = entry.word?.trim()
if (!canonicalWord) continue
let matched = false
const rawPron = typeof entry.pronunciation === 'string' ? entry.pronunciation.trim() : ''
if (rawPron.length > 0) {
const variants = Array.from(
new Set(
[rawPron, ...rawPron.split(/[,/;]+/)]
.map((v) => v.trim())
.filter((v) => v.length > 0 && v.toLowerCase() !== canonicalWord.toLowerCase())
)
).sort((a, b) => b.length - a.length)
for (const variant of variants) {
const regex = buildTokenRegex(variant)
if (regex.test(currentText)) {
matched = true
currentText = currentText.replace(buildTokenRegex(variant), canonicalWord)
}
}
}
const wordRegex = buildTokenRegex(canonicalWord)
if (wordRegex.test(currentText)) {
matched = true
currentText = currentText.replace(buildTokenRegex(canonicalWord), canonicalWord)
}
if (matched) {
matchedIds.push(entry.id)
this.incrementUsage(entry.id)
}
}
return { text: currentText, matchedIds }
}
async exportDictionary(params: DictionaryExportParams): Promise<string> {