Skip to content

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.

fix(trainer): Installationspfad des Character-Trainers erreichbar machen

purplee26256682c3c
diff --git a/src/components/create/experimental/SpecialIntentControls.tsx b/src/components/create/experimental/SpecialIntentControls.tsx
index 07ff5f06..c078f5c9 100644
--- a/src/components/create/experimental/SpecialIntentControls.tsx
+++ b/src/components/create/experimental/SpecialIntentControls.tsx
@@ -21,6 +21,7 @@ import {
import { startModelDownload, getDownloadProgress } from '../../../api/discover'
import { useDownloadStore } from '../../../stores/downloadStore'
import { getLoraModels } from '../../../api/comfyui'
+import { isWindows } from '../../../api/backend'
import { musicTakesLyrics, musicHowtoLines } from '../../../lib/render/music-ui'
import { TRAIN_PRESETS, trainStepsNote } from '../../../lib/trainer-presets'
import { useCreateExp } from './CreateContext'
@@ -267,6 +268,17 @@ function LocalTrainControls() {
const [status, setStatus] = useState<TrainerStatus | null>(null)
const [busy, setBusy] = useState<'install' | 'bases' | null>(null)
const [note, setNote] = useState<string | null>(null)
+ // K5 (DIE-301-LISTE, Discord "Storage", x_guestieco_x): the trainer's
+ // venv, torch and its pip/HF/torch caches all follow `trainer_root`
+ // (see apply_trainer_cache_env in commands/trainer.rs), but nothing ever
+ // let a customer set `trainer_root` in the first place, so the redirect
+ // never fired for anyone. This is the smallest honest fix: the same
+ // "type a path, it becomes the install target" control Settings > ComfyUI
+ // already uses for install_comfyui, reused here for the one other local
+ // installer that downloads multiple GB. Left empty, install_character_trainer
+ // keeps its existing default (the app data folder), so this changes
+ // nothing for a customer who never touches it.
+ const [installPath, setInstallPath] = useState('')
const refresh = useCallback(() => {
characterTrainerStatus().then(setStatus).catch(() => setStatus(null))
@@ -324,7 +336,7 @@ function LocalTrainControls() {
const startInstall = async () => {
setBusy('install')
setNote('Setting up the trainer...')
- try { await installCharacterTrainer() } catch (e) {
+ try { await installCharacterTrainer(installPath.trim() || undefined) } catch (e) {
setNote(e instanceof Error ? e.message : 'Install could not start.')
setBusy(null)
}
@@ -357,12 +369,23 @@ function LocalTrainControls() {
if (!status.envReady || (busy === 'install' && status.install.status === 'installing')) {
return (
<div className="flex flex-col items-center gap-1.5">
- <div className="flex items-center gap-2">
+ <div className="flex items-center gap-2 flex-wrap justify-center">
<span className="t-label text-gray-500">Trains fully on your GPU. One time setup, about 3 GB.</span>
<Button size="sm" variant="secondary" icon={Download} loading={busy === 'install'} disabled={busy === 'install'} onClick={startInstall}>
{busy === 'install' ? 'Setting up…' : 'Set up trainer'}
</Button>
</div>
+ {busy !== 'install' && (
+ <div className="flex flex-col items-center gap-0.5">
+ <input
+ value={installPath}
+ onChange={(e) => setInstallPath(e.target.value)}
+ placeholder={isWindows() ? 'e.g. D:\\LU-Trainer' : 'e.g. ~/LU-Trainer'}
+ className="t-control w-64 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"
+ />
+ <span className="t-label text-gray-600">Installs to your app data folder by default. Set a path above to use another drive.</span>
+ </div>
+ )}
{note && <div role="status" tabIndex={0} className="text-xs leading-relaxed text-gray-600 max-w-[520px] max-h-40 overflow-y-auto select-text whitespace-pre-wrap text-center break-words">{note}</div>}
</div>
)
diff --git a/src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx b/src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx
new file mode 100644
index 00000000..432fd575
--- /dev/null
+++ b/src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx
@@ -0,0 +1,110 @@
+// @vitest-environment jsdom
+/**
+ * K5 (DIE-301-LISTE.md, Discord "Storage", x_guestieco_x, Rang B, 13.09.2026):
+ * "everytime I try to force the app to go to my E drive it always takes up
+ * space on my C drive". Opus Gesamtabnahme (review-gesamt.md, Abschnitt 7.3,
+ * Auflage 3) measured the actual gap: `trainer_root` already redirects
+ * pip/HF/torch caches once it is customized (`apply_trainer_cache_env` in
+ * commands/trainer.rs), and `install_character_trainer` already accepts an
+ * `installPath` argument that persists it, but the ONE production caller in
+ * SpecialIntentControls.tsx called `installCharacterTrainer()` with no
+ * argument. `trainer_root_is_customized()` could therefore never read true
+ * for a customer, and the redirect never fired for anyone.
+ *
+ * This file nails the missing half: a typed install path in the pre-install
+ * gate reaches `installCharacterTrainer`, and leaving it empty keeps the
+ * existing default (no override written) so nobody's working setup changes
+ * underneath them.
+ *
+ * Run: npx vitest run src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx
+ */
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+const backendCall = vi.fn(async () => ({ status: 'ok' }))
+vi.mock('../../../../api/backend', () => ({
+ isTauri: () => true,
+ isMacOS: () => false,
+ isWindows: () => true,
+ isLinux: () => false,
+ backendCall: (...a: unknown[]) => backendCall(...(a as [])),
+}))
+
+const installCharacterTrainer = vi.fn(async () => ({ status: 'installing' }))
+vi.mock('../../../../api/trainer', async () => {
+ const actual = await vi.importActual<typeof import('../../../../api/trainer')>('../../../../api/trainer')
+ return {
+ ...actual,
+ characterTrainerStatus: vi.fn(async () => ({
+ envReady: false,
+ basesReady: false,
+ dit: null,
+ textEncoder: null,
+ vae: null,
+ root: '',
+ install: { status: 'idle', logs: [] },
+ })),
+ installCharacterTrainer: (...a: unknown[]) => installCharacterTrainer(...(a as [])),
+ }
+})
+vi.mock('../../../../api/comfyui', () => ({ getLoraModels: vi.fn(async () => []) }))
+vi.mock('../../../../api/cloud/loras', () => ({ listLoras: vi.fn(async () => []), deleteLora: vi.fn() }))
+vi.mock('../../../../api/discover', async () => {
+ const actual = await vi.importActual<typeof import('../../../../api/discover')>('../../../../api/discover')
+ return {
+ ...actual,
+ startModelDownload: vi.fn(async () => {}),
+ getDownloadProgress: vi.fn(async () => ({})),
+ }
+})
+
+import { SpecialControls } from '../SpecialIntentControls'
+import { useCreateStore } from '../../../../stores/createStore'
+
+const quelle = readFileSync(resolve(__dirname, '..', 'SpecialIntentControls.tsx'), 'utf8')
+
+beforeEach(() => {
+ cleanup()
+ installCharacterTrainer.mockClear()
+ useCreateStore.setState({ backend: 'local', characterTab: 'train' })
+})
+
+describe('K5: der Installationspfad des Trainers erreicht den Aufruf', () => {
+ it('THE FIX: ein eingetragener Pfad wird an installCharacterTrainer uebergeben', async () => {
+ render(<SpecialControls intent="character" />)
+ const feld = await screen.findByPlaceholderText('e.g. D:\\LU-Trainer')
+ fireEvent.change(feld, { target: { value: ' D:\\LU-Trainer ' } })
+ fireEvent.click(screen.getByRole('button', { name: 'Set up trainer' }))
+ expect(installCharacterTrainer).toHaveBeenCalledWith('D:\\LU-Trainer')
+ })
+
+ it('GEGENPROBE: ein leeres Feld traegt keinen Pfad weiter, der Standard bleibt', async () => {
+ render(<SpecialControls intent="character" />)
+ await screen.findByPlaceholderText('e.g. D:\\LU-Trainer')
+ fireEvent.click(screen.getByRole('button', { name: 'Set up trainer' }))
+ expect(installCharacterTrainer).toHaveBeenCalledWith(undefined)
+ })
+
+ it('DIE ROTE ZAHL: ohne das Feld ruft die Oberflaeche installCharacterTrainer() ohne jedes Argument', () => {
+ // Genau das war der gemeldete Windows-Fall: der einzige Aufrufer liess
+ // installPath immer weg, trainer_root_is_customized() konnte nie wahr
+ // werden. Nagelt fest, dass der Aufruf jetzt IMMER ein (moeglicherweise
+ // leeres) Argument mitgibt, nicht die alte parameterlose Form.
+ expect(quelle).not.toContain('installCharacterTrainer()')
+ expect(quelle).toContain('installCharacterTrainer(installPath.trim() || undefined)')
+ })
+
+ it('das Feld ist die kleinste vorhandene Form: dieselbe Musterzeile wie der ComfyUI-Pfad', () => {
+ const settings = readFileSync(
+ resolve(__dirname, '../../../settings/SettingsPage.tsx'),
+ 'utf8',
+ )
+ // Keine neue Bedienidee: dasselbe "Pfad eintragen, er wird zum
+ // Installationsziel" wie Settings > ComfyUI, nicht ein zweites
+ // Bedienkonzept fuer denselben Zweck.
+ expect(settings).toContain("runInstall(customPath.trim() || status?.path || '')")
+ expect(quelle).toContain("installPath.trim() || undefined")
+ })
+})