feat(keyboard): improve typing, voice flow, and polish reliability

Reduce extension memory pressure and delivery races while adding richer candidates, tactile feedback, and safer two-level creative polishing.
This commit is contained in:
Rocky
2026-08-05 21:39:31 +08:00
parent 38e5ad570d
commit 31f5937a7f
177 changed files with 8343 additions and 3904 deletions
@@ -9,6 +9,9 @@
// The "translate AND polish" blend is intentional: ASR transcripts are
// noisy, so the prompt asks the model to clean the noise while translating.
// Style follows the auto-detected `AppContext` (same as the polish path).
// Structure (paragraphs / lists) is an explicit contract with few-shot
// examples: abstract rules alone are not enough for models that flatten
// multi-point ASR into one paragraph.
import Foundation
@@ -25,7 +28,7 @@ public enum TranslationPrompt {
inputText: sourceText,
providerId: providerId
)
let contextGuideline = appContext.polishGuideline
let contextGuideline = appContext.translationGuideline
return useChinese
? chinesePrompt(target: target, contextGuideline: contextGuideline)
: englishPrompt(target: target, contextGuideline: contextGuideline)
@@ -39,8 +42,42 @@ public enum TranslationPrompt {
1) 先识别原话的主要语言(若不确定则按用户给定的方向处理);
2) 将内容翻译为「\(target.promptLanguageName)」,保留原意,不增删事实、不臆测;
3) 顺带修复 ASR 噪声(同音错字、漏字、断句错乱),让译文读起来自然;
4) 简洁;不超过原文 1.5 倍;去掉无意义的口头禅(嗯、啊、那个);
5) 只输出译文正文,不要解释、不要加引号、不要前缀""
4) 去掉无意义的口头禅(嗯、啊、那个);篇幅不超过原文约 1.5 倍——简洁是去噪声,不是压平结构;
5) 结构硬规则(与意思同等重要,必须遵守):
- 输入若已有空行、换行或列表,译文必须对应保留;禁止把多段合成一段;
- 输入几乎无换行、但出现「第N点/首先/其次/三件事」等列举信号,或有多个独立要点时:
· 用空行分段;
· 列举必须用行首编号列表「1. 2. 3.」(或目标语等价写法),禁止写成同一段里的 First,/Second,/Third,;
· 禁止把整段输出成没有换行的单段;
- 短文本或单一意图保持一段,不为好看硬换行;
6) 只输出译文正文,不要解释、不要加引号、不要前缀""
# 示例(格式必须像「正确」,不要像「错误」)
输入(平铺 ASR): 嗯那个今天开会说了三件事第一点是修登录崩溃第二点加冒烟测试第三点通知客服另外周一十点再同步
错误(禁止): Today's meeting covered three things. First, fix the login crash. Second, add smoke tests. Third, notify support. Also sync Monday at 10.
正确:
Today's meeting covered three items:
1. Fix the login crash.
2. Add smoke tests.
3. Notify support.
Also, sync again Monday at 10.
输入(已有分段):
今天有两件事。
第一点是发版。
第二点是写纪要。
正确:
There are two items today.
1. Ship the release.
2. Write the meeting notes.
输入(短句): 好的收到
正确: Okay, got it.
当前输入场景:\(contextGuideline)
"""
@@ -54,8 +91,42 @@ public enum TranslationPrompt {
1) Identify the input language; if unclear, assume the user wants translation INTO \(target.promptLanguageName);
2) Translate the content INTO \(target.promptLanguageName), preserving meaning; do not invent facts or omit content;
3) Fix ASR noise (homophone errors, missing characters, broken segmentation) so the translation reads naturally;
4) Stay concise; do not exceed 1.5x the spoken length; drop filler words (um, uh, like);
5) Output ONLY the translation. No quotes, no preamble, no explanation.
4) Drop filler words (um, uh, like); stay within ~1.5x spoken length — concise means remove noise, not flatten structure;
5) Hard structure rules (as important as meaning; must follow):
- If the input already has blank lines, line breaks, or lists, preserve that structure; never merge multiple paragraphs into one;
- If the input is nearly unbroken but has enumeration cues ("first/second", "three things", "point one") or multiple independent points:
· split with blank lines;
· use a leading numbered list "1. 2. 3." (or target-language equivalent); do NOT write First,/Second,/Third, inside one paragraph;
· never output the whole result as a single newline-free block;
- Keep short or single-intent text in one paragraph; do not add decorative breaks;
6) Output ONLY the translation. No quotes, no preamble, no explanation.
# Examples (match CORRECT format; never match WRONG)
Input (flat ASR): um today meeting three things first fix login crash second add smoke tests third notify support also sync Monday at ten
WRONG: Today's meeting covered three things. First, fix the login crash. Second, add smoke tests. Third, notify support. Also sync Monday at 10.
CORRECT:
Today's meeting covered three items:
1. Fix the login crash.
2. Add smoke tests.
3. Notify support.
Also, sync again Monday at 10.
Input (already paragraphed):
Two things today.
First, ship the release.
Second, write the notes.
CORRECT:
Two things today.
1. Ship the release.
2. Write the notes.
Input (short): okay got it
CORRECT: Okay, got it.
Current input context: \(contextGuideline)
"""