feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)
This commit is contained in:
parent
f49acf0105
commit
10af20a0ad
157 changed files with 29455 additions and 913 deletions
|
|
@ -153,18 +153,12 @@ export function isWordBoundaryKey(keyClass: KeyStrokeClass): boolean {
|
|||
/**
|
||||
* 단어 수.
|
||||
*
|
||||
* 공백 분리 토큰 중 문자/숫자/CJK 를 포함한 것만 센다.
|
||||
* (중국어처럼 공백이 없는 언어는 과소 집계된다 — 활동 통계 전용. 학습 필터는
|
||||
* text-segmentation.ts 의 countLexicalWords 로 센다)
|
||||
* 공백 분리 언어(한국어·라틴 문자 등)는 공백 분리 토큰 중 문자/숫자를 포함한 것만 세고,
|
||||
* 띄어쓰기 없이 쓰는 문자 체계(중국어·일본어·태국어 등)는 `countLexicalWords`(Intl.Segmenter
|
||||
* 또는 글자 수 어림)로 분할해 과소 집계를 방지한다.
|
||||
*/
|
||||
export function countWords(text: string): number {
|
||||
if (!text) return 0
|
||||
const tokens = text.split(/\s+/)
|
||||
let count = 0
|
||||
for (const token of tokens) {
|
||||
if (/[\p{L}\p{N}]/u.test(token)) count += 1
|
||||
}
|
||||
return count
|
||||
return countLexicalWords(text)
|
||||
}
|
||||
|
||||
/** 문장 수 — 종결 부호 + 개행 기준. */
|
||||
|
|
|
|||
|
|
@ -115,3 +115,101 @@ export function renderInstructionAsSingleMessage(
|
|||
const { system, user } = renderInstruction(prompt, vars)
|
||||
return system === undefined ? user : `${system}\n\n${user}`
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 다단계 명령 파이프라인 (Multi-Instruction Pipeline) SSOT
|
||||
// ============================================================
|
||||
|
||||
/**
|
||||
* 저장된 `activeInstructionId` 문자열(단일 ID 또는 콤마 구분 복수 ID)이나 배열에서
|
||||
* 선택 순서를 보존하고 중복·빈 값을 제거한 명령 ID 목록을 반환한다.
|
||||
*/
|
||||
export function parseActiveInstructionIds(raw: unknown): string[] {
|
||||
const parts: string[] =
|
||||
typeof raw === 'string'
|
||||
? raw.split(',')
|
||||
: Array.isArray(raw)
|
||||
? raw.filter((v): v is string => typeof v === 'string')
|
||||
: []
|
||||
const seen = new Set<string>()
|
||||
const result: string[] = []
|
||||
for (const part of parts) {
|
||||
const trimmed = part.trim()
|
||||
if (trimmed.length > 0 && !seen.has(trimmed)) {
|
||||
seen.add(trimmed)
|
||||
result.push(trimmed)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 순서가 있는 명령 ID 배열을 `AppConfig.activeInstructionId` 저장 형식(콤마 구분 문자열)으로 직렬화한다.
|
||||
*/
|
||||
export function serializeActiveInstructionIds(ids: readonly string[]): string {
|
||||
return parseActiveInstructionIds(ids).join(',')
|
||||
}
|
||||
|
||||
/**
|
||||
* 파이프라인에서 특정 명령 ID를 토글(없으면 맨 뒤에 추가, 있으면 제거)한 새 배열을 반환한다.
|
||||
*/
|
||||
export function toggleInstructionInPipeline(
|
||||
currentIds: readonly string[],
|
||||
targetId: string,
|
||||
): string[] {
|
||||
const normalized = parseActiveInstructionIds(currentIds)
|
||||
const trimmed = targetId.trim()
|
||||
if (!trimmed) return normalized
|
||||
const idx = normalized.indexOf(trimmed)
|
||||
if (idx >= 0) {
|
||||
return normalized.filter((id) => id !== trimmed)
|
||||
}
|
||||
return [...normalized, trimmed]
|
||||
}
|
||||
|
||||
/**
|
||||
* 파이프라인 안에서 특정 명령의 실행 순서를 위(`up`) 또는 아래(`down`)로 한 칸 이동한다.
|
||||
*/
|
||||
export function moveInstructionInPipeline(
|
||||
currentIds: readonly string[],
|
||||
targetId: string,
|
||||
direction: 'up' | 'down',
|
||||
): string[] {
|
||||
const next = parseActiveInstructionIds(currentIds)
|
||||
const idx = next.indexOf(targetId.trim())
|
||||
if (idx === -1) return next
|
||||
const swapIdx = direction === 'up' ? idx - 1 : idx + 1
|
||||
if (swapIdx < 0 || swapIdx >= next.length) return next
|
||||
const temp = next[idx]
|
||||
next[idx] = next[swapIdx]
|
||||
next[swapIdx] = temp
|
||||
return next
|
||||
}
|
||||
|
||||
/**
|
||||
* 복수 명령(1단계 → 2단계 → …)을 단일 LLM 호출로 빠르게 처리하기 위한 파이프라인 프롬프트를 합성한다.
|
||||
* - 0개면 빈 문자열, 1개면 해당 지시문 원문을 그대로 반환한다(하위 호환 100%).
|
||||
* - 2개 이상이면 단계별 순서와 충돌 해결 규칙(어투·형식·언어 등 최종 표현은 뒤쪽 단계가 우선)을 명시해 합성한다.
|
||||
*/
|
||||
export function composeInstructionPipelinePrompt(
|
||||
steps: ReadonlyArray<{ name: string; prompt: string }>,
|
||||
): string {
|
||||
if (steps.length === 0) return ''
|
||||
if (steps.length === 1) return steps[0].prompt
|
||||
|
||||
const normalizedSteps = steps.map((step, index) => {
|
||||
const cleanedPrompt = step.prompt
|
||||
.replaceAll(INSTRUCTION_TEXT_PLACEHOLDER, '입력된 텍스트')
|
||||
.replaceAll(INSTRUCTION_USER_PROMPT_PLACEHOLDER, '입력된 텍스트')
|
||||
.trim()
|
||||
return `[${index + 1}단계: ${step.name}]\n${cleanedPrompt}`
|
||||
})
|
||||
|
||||
return [
|
||||
'다음 파이프라인 단계들을 1단계부터 순서대로 모두 적용하여 입력된 텍스트를 처리하세요.',
|
||||
'앞 단계의 처리 결과를 바탕으로 다음 단계를 이어서 적용하되, 어투(존댓말/반말/격식체)·출력 형식·번역 언어 등 최종 표현 방식이 단계 간에 충돌할 경우 반드시 **뒤쪽(마지막) 단계**의 지시를 최종 기준으로 우선 적용하세요.',
|
||||
'각 단계의 중간 과정이나 단계 번호, 부연 설명은 절대 출력하지 말고 **최종 완료된 결과 텍스트만** 출력하세요.',
|
||||
'',
|
||||
...normalizedSteps,
|
||||
].join('\n\n')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -478,6 +478,8 @@ export interface AppConfig {
|
|||
*/
|
||||
conversationBackend: 'local' | 'realtime'
|
||||
defaultLLMAction: LLMActionSelection
|
||||
/** 번역 대상 언어 (예: 'English', 'Korean', 'Japanese'). 기본값 'English'. */
|
||||
targetLanguage: string
|
||||
/**
|
||||
* 전체 키바인딩. 액션 id → 바인딩 목록(다중 바인딩).
|
||||
* 구조·기본값·검증은 `packages/core/src/keybinding.ts` 가 정본이다.
|
||||
|
|
|
|||
|
|
@ -1726,7 +1726,7 @@ export function detectHangulTypedLatin(
|
|||
const [, korPrefix, jamoRest] = korPrefixAndJamoRest
|
||||
if (Array.from(korPrefix).every((ch) => isCommonHangulSyllable(ch))) {
|
||||
const restResolved =
|
||||
LOOSE_JAMO_TWO_LETTER_ENGLISH[jamoRest] ?? detectHangulTypedLatin(jamoRest, options)
|
||||
LOOSE_JAMO_TWO_LETTER_ENGLISH[jamoRest] ?? detectHangulTypedLatin(jamoRest, context, options)
|
||||
if (restResolved) {
|
||||
return `${korPrefix}${restResolved}`
|
||||
}
|
||||
|
|
@ -2286,7 +2286,12 @@ export function detectJamoNoise(prefix: string, options: { ignoredWords?: readon
|
|||
if (!COMPAT_JAMO.test(char)) return true
|
||||
const lone = !COMPAT_JAMO.test(chars[position - 1] ?? '') && !COMPAT_JAMO.test(chars[position + 1] ?? '')
|
||||
if (!lone) return true
|
||||
if (position === chars.length - 1 && EMOTIVE_JAMO.has(char)) return true
|
||||
if (
|
||||
position === chars.length - 1 &&
|
||||
(EMOTIVE_JAMO.has(char) || (token.end === prefix.length && /^[\u3131-\u314e]$/u.test(char)))
|
||||
) {
|
||||
return true
|
||||
}
|
||||
changed = true
|
||||
return false
|
||||
})
|
||||
|
|
@ -2305,6 +2310,16 @@ function isIntentionalJamoToken(word: string): boolean {
|
|||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 커서 끝에서 다음 한글 음절을 조합하기 위해 막 초성 자음 하나만 누른 중간 상태인가
|
||||
* (예: "안ㄴ", "안녕ㅎ", "한ㄱ", "오늘 ㄴ"). 이 상태는 오타가 아니라 정상적인 한글 타이핑 과정이다.
|
||||
*/
|
||||
function isComposingTrailingConsonantAtEnd(region: string, token: WordToken): boolean {
|
||||
if (token.end !== region.length) return false
|
||||
if (LOOSE_JAMO_TWO_LETTER_ENGLISH[token.text]) return false
|
||||
return /^[가-힣]*[\u3131-\u314e]$/u.test(token.text)
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델에 오타 검사를 맡길 만큼 수상한 구간인가 — 낱자가 섞인 한글/한영 오타 단어, 드문 음절, 미등록 소문자 영단어.
|
||||
*
|
||||
|
|
@ -2312,9 +2327,16 @@ function isIntentionalJamoToken(word: string): boolean {
|
|||
* 수상한 흔적이 있을 때만 즉시 묻는다.
|
||||
*/
|
||||
export function hasSuspiciousTypo(region: string): boolean {
|
||||
if (detectJamoNoise(region).length > 0) return true
|
||||
if (
|
||||
detectJamoNoise(region).some(
|
||||
(c) => c.to !== '' || /[ \t]$/u.test(c.from) || c.end < region.length
|
||||
)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return tokenizeWords(region).some((token) => {
|
||||
const word = token.text
|
||||
if (isComposingTrailingConsonantAtEnd(region, token)) return false
|
||||
if (/[ㄱ-ㆎ]/u.test(word) && !isIntentionalJamoToken(word)) return true
|
||||
if (Array.from(word).some((char) => HANGUL_SYLLABLE.test(char) && !isCommonHangulSyllable(char))) {
|
||||
return true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue