Skip to content

Commit b43614c

Browse files
committed
Fix snippet expansion: strip ASR punctuation and reorder pipeline
Two issues prevented snippet triggers from matching: 1. Voxtral adds trailing punctuation (e.g., "Snippet email signature.") which made the trigger comparison fail. Now strip punctuation from both the lowered command and the extracted trigger before matching. 2. Replacements ran before snippet resolution, so a replacement could corrupt a command prefix or trigger word. Now snippets are checked first on the raw text. If a snippet matches, skip replacements on the expanded content. Made-with: Cursor
1 parent 2b7fc3c commit b43614c

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

voxtral_realtime/macos/VoxtralRealtime/Services/TextPipeline.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ final class TextPipeline {
5757
baseText = trimmed
5858
}
5959

60-
let replacementsApplied = applyReplacements(to: baseText)
61-
let snippetResolution = resolveSnippet(in: replacementsApplied, allowExpansion: context == .dictation && !literalCommand)
62-
let styleApplied = applyStyle(to: snippetResolution.text)
60+
let snippetResolution = resolveSnippet(in: baseText, allowExpansion: context == .dictation && !literalCommand)
61+
let afterSnippets = snippetResolution.text
62+
let replacementsApplied = snippetResolution.usedSnippetIDs.isEmpty
63+
? applyReplacements(to: afterSnippets)
64+
: afterSnippets
65+
let styleApplied = applyStyle(to: replacementsApplied)
6366

6467
var tags: [String] = []
65-
if replacementsApplied != baseText {
68+
if replacementsApplied != afterSnippets {
6669
tags.append("replacement")
6770
}
6871
if !snippetResolution.usedSnippetIDs.isEmpty {
@@ -145,10 +148,13 @@ final class TextPipeline {
145148

146149
let normalized = text.trimmingCharacters(in: .whitespacesAndNewlines)
147150
let lowered = normalized.lowercased()
151+
.trimmingCharacters(in: .punctuationCharacters)
148152
let commandPrefixes = ["insert snippet ", "snippet ", "template "]
149153

150154
for prefix in commandPrefixes where lowered.hasPrefix(prefix) {
151-
let requestedTrigger = String(normalized.dropFirst(prefix.count)).trimmingCharacters(in: .whitespacesAndNewlines)
155+
let requestedTrigger = String(lowered.dropFirst(prefix.count))
156+
.trimmingCharacters(in: .whitespacesAndNewlines)
157+
.trimmingCharacters(in: .punctuationCharacters)
152158
if let snippet = snippetStore.snippets.first(where: {
153159
$0.isEnabled && $0.trigger.compare(requestedTrigger, options: .caseInsensitive) == .orderedSame
154160
}) {

0 commit comments

Comments
 (0)