The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(create): spell non-ASCII trigger words in ASCII so captions, LoRA file and shelf agree
purple5b274645da83
diff --git a/src/components/create/experimental/SpecialIntentControls.tsx b/src/components/create/experimental/SpecialIntentControls.tsxindex 21c81a69..04388a6f 100644--- a/src/components/create/experimental/SpecialIntentControls.tsx+++ b/src/components/create/experimental/SpecialIntentControls.tsx@@ -277,6 +277,7 @@ function CharacterPanel() {placeholder="Trigger word, e.g. davechar"className="t-control w-44 px-2.5 h-[var(--control-h-sm)] rounded-md bg-white/[0.03] border border-white/[0.06] text-gray-200 placeholder-gray-600 focus:outline-none focus:border-white/15"/>+ <TriggerWordNote /><span className="t-label text-gray-600">{trainImages.length}/{maxTrainImages(backend)} photos added{trainImages.length < MIN_TRAIN_IMAGES ? `, need at least ${MIN_TRAIN_IMAGES}` : ''}</span>@@ -681,6 +682,7 @@ function LocalTrainControls() {placeholder="Trigger word, e.g. davechar"className="t-control w-44 px-2.5 h-[var(--control-h-sm)] rounded-md bg-white/[0.03] border border-white/[0.06] text-gray-200 placeholder-gray-600 focus:outline-none focus:border-white/15"/>+ <TriggerWordNote /><Segmentedsize="sm"layoutId="train-steps"@@ -804,6 +806,7 @@ function MacTrainControls() {placeholder="Trigger word, e.g. davechar"className="t-control w-44 px-2.5 h-[var(--control-h-sm)] rounded-md bg-white/[0.03] border border-white/[0.06] text-gray-200 placeholder-gray-600 focus:outline-none focus:border-white/15"/>+ <TriggerWordNote /><Segmentedsize="sm"layoutId="train-steps"@@ -1661,3 +1664,11 @@ function MotionControls() {</div>)}++/** C7: says under the trigger field what it did to the typed word ("Jörg" is+ * trained as "Joerg"), so the word on screen is visibly the word learned. */+function TriggerWordNote() {+ const note = useCreateStore((s) => s.triggerWordNote)+ if (!note) return null+ return <p role="status" data-testid="trigger-word-note" className={`w-full text-center t-micro ${HINWEIS_TEXT.ruhig}`}>{note}</p>+}diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.tsindex 6165052f..03b5de5b 100644--- a/src/hooks/useCreate.ts+++ b/src/hooks/useCreate.ts@@ -95,6 +95,7 @@ import {} from '../api/trainer'import { getMacTrainStatus, macTrainMissing } from '../api/mlx-train'import { buildTrainCaption } from '../lib/train-captions'+import { trainTriggerWord } from '../lib/train-trigger'import { useCreateStore, EDIT_MAX_DENOISE, characterImageRun, deriveIntent, type CreateState } from '../stores/createStore'import { useWorkflowStore } from '../stores/workflowStore'import { useSettingsStore } from '../stores/settingsStore'@@ -554,7 +555,10 @@ export function useCreate() {// below go there by themselves (api/trainer.ts); what differs is how the// memory is handed over.const mac = isMlxImageHost()- const trigger = state.triggerWord.trim()+ // C7: the same word Rust names the LoRA file after, so captions, file+ // name and the Use shelf's prompt token are one word (lib/train-trigger.ts).+ // Also catches a persisted "Jörg" saved before the field cleaned it.+ const trigger = trainTriggerWord(state.triggerWord)if (!trigger) {setError('Pick a trigger word first, e.g. davechar. It becomes the token that summons your character.')returndiff --git a/src/lib/__tests__/train-trigger-matches-the-lora-file.test.ts b/src/lib/__tests__/train-trigger-matches-the-lora-file.test.tsnew file mode 100644index 00000000..cebc04c0--- /dev/null+++ b/src/lib/__tests__/train-trigger-matches-the-lora-file.test.ts@@ -0,0 +1,79 @@+/**+ * C7 (funde-C.md): a trigger word "Jörg" was learned from captions saying+ * "Jörg", but Rust named the LoRA after `sanitize_component("Jörg")`, so the+ * file was `char_J_rg_zimage.safetensors` and the Use shelf put "J_rg" into+ * the prompt. Now the field itself turns the word into the form Rust keeps+ * unchanged, visibly, and the training run uses that form.+ *+ * Run: npx vitest run src/lib/__tests__/train-trigger-matches-the-lora-file.test.ts+ */+import { describe, it, expect, beforeEach } from 'vitest'+import fs from 'node:fs'+import path from 'node:path'+import { useCreateStore } from '../../stores/createStore'+import { buildTrainCaption } from '../train-captions'+import { parseLocalCharacterLora } from '../../api/trainer'+import { trainTriggerWord } from '../train-trigger'++/** src-tauri/src/commands/trainer.rs `sanitize_component`, 1:1. */+const rustSanitize = (s: string) =>+ [...s].map((c) => (/^[A-Za-z0-9_-]$/.test(c) ? c : '_')).join('').replace(/^_+|_+$/g, '').slice(0, 48)++/** What runCharacterTraining hands on, end to end: field, caption, file, shelf. */+function roundTrip(typed: string) {+ useCreateStore.getState().setTriggerWord(typed)+ const field = useCreateStore.getState().triggerWord+ const trigger = trainTriggerWord(field)+ const caption = buildTrainCaption(trigger)+ const file = `char_${rustSanitize(trigger)}_zimage.safetensors`+ return { field, caption, shelf: parseLocalCharacterLora(file)?.trigger }+}++beforeEach(() => useCreateStore.setState({ triggerWord: '', triggerWordNote: null }))++describe('C7: captions, LoRA file and Use shelf name the same trigger word', () => {+ it.each([+ ['Jörg', 'Joerg'],+ ['Zoë', 'Zoe'],+ ['Søren', 'Soren'],+ ['Renée', 'Renee'],+ ['Straße', 'Strasse'],+ ])('%s is shown and trained as %s', (typed, expected) => {+ const { field, caption, shelf } = roundTrip(typed)+ expect(field).toBe(expected)+ expect(caption).toBe(`${expected}, a photo of ${expected}`)+ expect(shelf).toBe(expected)+ })++ it('the field says what it did, and the note stays after the next keystroke', () => {+ useCreateStore.getState().setTriggerWord('Jörg')+ expect(useCreateStore.getState().triggerWordNote).toContain('“Joerg”')+ useCreateStore.getState().setTriggerWord('Joergx')+ expect(useCreateStore.getState().triggerWordNote).toContain('Joerg')+ useCreateStore.getState().setTriggerWord('')+ expect(useCreateStore.getState().triggerWordNote).toBeNull()+ })++ it('a plain ASCII word is untouched and gets no note', () => {+ const { field, shelf } = roundTrip('davechar')+ expect(field).toBe('davechar')+ expect(shelf).toBe('davechar')+ expect(useCreateStore.getState().triggerWordNote).toBeNull()+ })++ it('letters without a Latin form are dropped, with the rule said', () => {+ useCreateStore.getState().setTriggerWord('Сергей')+ expect(useCreateStore.getState().triggerWord).toBe('')+ expect(useCreateStore.getState().triggerWordNote).toMatch(/A to Z/)+ })++ it('end underscores are trimmed for the run, as Rust trims them', () => {+ expect(trainTriggerWord('_mia_')).toBe('mia')+ expect(rustSanitize(trainTriggerWord('_mia_'))).toBe('mia')+ })++ it('the training run builds its captions from the cleaned trigger', () => {+ const src = fs.readFileSync(path.join(__dirname, '..', '..', 'hooks', 'useCreate.ts'), 'utf8')+ expect(src).toContain('const trigger = trainTriggerWord(state.triggerWord)')+ })+})diff --git a/src/lib/train-trigger.ts b/src/lib/train-trigger.tsnew file mode 100644index 00000000..9519a978--- /dev/null+++ b/src/lib/train-trigger.ts@@ -0,0 +1,63 @@+/**+ * C7 (funde-C.md): the trigger word of a local character, in the one form+ * the trainer, the LoRA file name and the Use shelf all agree on.+ *+ * The Rust side names the LoRA after the trigger run through+ * `sanitize_component` (src-tauri/src/commands/trainer.rs): every character+ * that is not an ASCII letter, digit, "-" or "_" becomes "_", then "_" is+ * trimmed off both ends. The Use shelf reads the trigger back from that file+ * name (api/trainer.ts parseLocalCharacterLora). A trigger "Jörg" was learned+ * from captions saying "Jörg", saved as `char_J_rg_zimage.safetensors`, and+ * the shelf then put "J_rg" into the prompt, a token the LoRA never saw.+ *+ * Chosen fix: transliterate in the field itself, as the person types. "Jörg"+ * turns into "Joerg" right there, so the word on screen is the word that is+ * trained, written into the captions, named in the file and put into the+ * prompt later. A refusal would make someone called Jörg guess a spelling; a+ * silent rewrite at send time would repeat the bug in a new shape. Letters+ * with no Latin form (Cyrillic, CJK) are dropped, and the note below says why.+ */++const SPELLED_OUT: Record<string, string> = {+ ä: 'ae', ö: 'oe', ü: 'ue', Ä: 'Ae', Ö: 'Oe', Ü: 'Ue', ß: 'ss', ẞ: 'SS',+ ø: 'o', Ø: 'O', æ: 'ae', Æ: 'Ae', œ: 'oe', Œ: 'Oe',+ ł: 'l', Ł: 'L', đ: 'd', Đ: 'D', ð: 'd', Ð: 'D', þ: 'th', Þ: 'Th', ı: 'i',+}++/** The longest trigger the field keeps (the Rust side allows 48). */+export const TRIGGER_WORD_MAX = 30++/**+ * What the field shows while the person types: no whitespace, common accented+ * letters spelled in ASCII (ö to oe, é to e, ø to o), anything else dropped.+ * Underscores at the ends stay so "my_" can still become "my_char".+ */+export function typedTriggerWord(raw: string): string {+ return raw+ .replace(/\s+/g, '')+ .replace(/[^\p{ASCII}]/gu, (c) => SPELLED_OUT[c] ?? c)+ .normalize('NFKD')+ .replace(/\p{M}/gu, '')+ .replace(/[^A-Za-z0-9_-]/g, '')+ .slice(0, TRIGGER_WORD_MAX)+}++/**+ * The trigger as it goes to the trainer and into every caption: the typed+ * form, with the end underscores Rust trims off anyway. Rust's+ * `sanitize_component` leaves this string unchanged, so the file name ends in+ * exactly this word and the shelf reads it back as is.+ */+export function trainTriggerWord(raw: string): string {+ return typedTriggerWord(raw).replace(/^_+|_+$/g, '')+}++/** The note under the field when the typed word was changed, or null. */+export function triggerWordNote(raw: string): string | null {+ const typed = raw.replace(/\s+/g, '')+ const kept = typedTriggerWord(raw)+ if (!typed || typed.slice(0, TRIGGER_WORD_MAX) === kept) return null+ return kept+ ? `Trained as “${kept}”: trigger words use the letters A to Z, digits, - and _.`+ : 'Trigger words use the letters A to Z, digits, - and _.'+}diff --git a/src/mobile/screens/create/NewCharacterPage.tsx b/src/mobile/screens/create/NewCharacterPage.tsxindex 403ae77c..d8490265 100644--- a/src/mobile/screens/create/NewCharacterPage.tsx+++ b/src/mobile/screens/create/NewCharacterPage.tsx@@ -66,6 +66,7 @@ export default function NewCharacterPage() {useCatalogVersion()const f = useCreateFacts()const name = useCreateStore((s) => s.triggerWord)+ const nameNote = useCreateStore((s) => s.triggerWordNote)const photos = useCreateStore((s) => s.trainImages)const running = useCreateStore((s) => s.isGenerating)const progress = useCreateStore((s) => s.progress)@@ -265,7 +266,7 @@ export default function NewCharacterPage() {value={name}onChange={(v) => useCreateStore.getState().setTriggerWord(v)}placeholder={T.newChar.namePlaceholder}- hint={T.newChar.nameHint}+ hint={nameNote ?? T.newChar.nameHint}error={asked && !name.trim() ? T.newChar.nameMissing : undefined}disabled={running}maxLength={30}diff --git a/src/stores/createStore.ts b/src/stores/createStore.tsindex 223fcc91..22275abb 100644--- a/src/stores/createStore.ts+++ b/src/stores/createStore.ts@@ -59,6 +59,7 @@ import { cloudModelsFor } from './cloudCatalogStore'import { createRunModel } from '../lib/render/create-studio'import { DEFAULT_UPSCALE_FACTOR, normalizeUpscaleFactor, type UpscaleFactor } from '../lib/local-upscale'import { characterLoraFile, isLocalCharacter, type CharacterRef } from '../lib/character-ref'+import { triggerWordNote, typedTriggerWord } from '../lib/train-trigger'// ModelType includes: flux, flux2, zimage, sdxl, sd15, wan, hunyuan, unknownexport type ProgressPhase = 'idle' | 'queued' | 'loading-model' | 'loading-clip' | 'loading-vae' | 'sampling' | 'decoding' | 'complete'@@ -393,6 +394,9 @@ export interface CreateState {trainImages: MediaRef[]/** Character-Studio trigger word — the token that summons the character. */triggerWord: string+ /** C7: what the field did to the last typed trigger word (ö to oe, a+ * dropped letter), shown under it. Null when nothing was changed. */+ triggerWordNote: string | null/** Local training length (musubi steps). Quality/time tradeoff, persisted. */trainSteps: number/** 3.0.8 D28: each staged photo's own description (clothes, hair, place),@@ -1041,6 +1045,7 @@ export const useCreateStore = create<CreateState>()(characterTab: 'train' as 'train' | 'use',trainImages: [] as MediaRef[],triggerWord: '',+ triggerWordNote: null,// Dieselbe Zahl, die der Trainer ohne Angabe nimmt// (`steps.unwrap_or(1200)`, trainer.rs), und die Stufe `Standard`.trainSteps: TRAIN_STEPS_DEFAULT,@@ -1362,7 +1367,15 @@ export const useCreateStore = create<CreateState>()(releaseDroppedMediaRefs(get().trainImages, [])set({ trainImages: [], trainCaptions: {} })},- setTriggerWord: (w) => set({ triggerWord: w.replace(/\s+/g, '').slice(0, 30) }),+ // C7: the field holds the word in the one form the trainer, the LoRA+ // file name and the Use shelf agree on (lib/train-trigger.ts). The note+ // stays until the field is emptied, so it is still there after the next+ // keystroke.+ setTriggerWord: (w) => set((s) => {+ const triggerWord = typedTriggerWord(w)+ const note = triggerWordNote(w)+ return { triggerWord, triggerWordNote: triggerWord || note ? note ?? s.triggerWordNote : null }+ }),// Same clamp as the Rust command so the UI can never book a rejected run.setTrainSteps: (n) => set({ trainSteps: Math.max(100, Math.min(4000, Math.floor(n))) }),setTrainCaption: (name, text) => set((s) => {