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(prompt): der Grundtext geht auf allen drei Oberflaechen wirklich raus
Davidbbbf7daf6c0b
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.tsindex bd627048..a63d0731 100644--- a/src/hooks/useAgentChat.ts+++ b/src/hooks/useAgentChat.ts@@ -101,6 +101,7 @@ import { capHiddenToolHistory } from './codex/hidden-history'import { asString, errorText, prop } from '../types/json-guards'import type { ToolArgs } from '../api/mcp/types'import { CREDITS_EXHAUSTED_MESSAGE } from '../lib/credits-exhausted'+import { buildChatSystemPrompt } from '../lib/system-prompt'// ── Hook ──────────────────────────────────────────────────────@@ -460,7 +461,7 @@ export function useAgentChat() {// Per-chat persona toggle — default OFF. Only apply persona prompt// when user explicitly flipped it on. See useChat.ts for the// full rationale (Devil's Advocate hijack bug).- let systemPrompt = conv.personaEnabled === true ? conv.systemPrompt : ''+ let systemPrompt = buildChatSystemPrompt(conv)const ragState = useRAGStore.getState()const ragEnabled = ragState.ragEnabled[convId] ?? falselet ragSuffix = ''diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.tsindex 6debde5c..05681aa8 100644--- a/src/hooks/useChat.ts+++ b/src/hooks/useChat.ts@@ -46,6 +46,7 @@ import { CREDITS_EXHAUSTED_MESSAGE } from '../lib/credits-exhausted'import { shouldDowngradeThinking, engineDeniedThinking } from './codex/thinking-downgrade'import { ProviderError } from '../api/providers/types'import { useBackgroundAgentWake } from './useBackgroundAgentWake'+import { buildChatSystemPrompt } from '../lib/system-prompt'/*** Pull the most recent media generation (image/video) out of an assistant@@ -86,7 +87,10 @@ async function runGroupTurn(convId: string, model: string, allModels: string[],}useChatStore.getState().addMessage(convId, assistantMessage)- const personaPrompt = conv.personaEnabled === true ? conv.systemPrompt : ''+ // Der Grundtext gilt unabhaengig vom Personenschalter: der Schalter+ // entscheidet ueber die PERSON, nicht darueber, ob ueberhaupt ein Systemtext+ // rausgeht. Siehe lib/system-prompt.ts.+ const personaPrompt = buildChatSystemPrompt(conv)const providerId = getProviderIdFromModel(model)// Same count cap as the plain path: a long group chat must not outgrow the// proxy's message gate either.@@ -548,7 +552,7 @@ export function useChat() {// flipped it on via the Plugins dropdown does the persona prompt// apply. Undefined / unset → suppress, so a globally selected// persona never silently hijacks a new chat.- let systemPrompt = conv.personaEnabled === true ? conv.systemPrompt : ''+ let systemPrompt = buildChatSystemPrompt(conv)const ragState = useRAGStore.getState()const ragEnabled = ragState.ragEnabled[convId] ?? falselet ragSuffix = ''diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.tsindex 16e375a8..e35e5372 100644--- a/src/hooks/useCodex.ts+++ b/src/hooks/useCodex.ts@@ -101,6 +101,7 @@ import { codexStallVerdict } from './codex/stall-verdict'import { createStagedWriter } from './codex/staged-writes'import { codexToolDiff, codexEventKind } from './codex/tool-result-view'import { capHiddenToolHistory } from './codex/hidden-history'+import { withHouseConduct } from '../lib/system-prompt'// No-op diagnostic hook. Kept as a call site so future debugging can swap// this for a file logger without re-editing every iter-point in the loop.@@ -631,7 +632,10 @@ export function useCodex() {// the same on every turn, while the clock changes every minute and now// rides at the very end of the prompt, behind everything a prefix cache// could otherwise have matched.- let systemPrompt = `${baseCodexPrompt}${assetLine}\n\n${platformPromptLine()}\n${workDirLine}`+ // Die Verhaltenszeile haengt an JEDER Oberflaeche (lib/system-prompt.ts).+ // Der Coding-Agent bringt seine eigene Rolle mit, deshalb nur die Zeile+ // und nicht der ganze Grundtext.+ let systemPrompt = withHouseConduct(`${baseCodexPrompt}${assetLine}\n\n${platformPromptLine()}\n${workDirLine}`)// Standing goal (/goal) — ahead of the rules and the repo map so it frames// everything that follows instead of reading as an afterthought.systemPrompt += renderGoalSection(useAgentGoalStore.getState().getGoal(convId))diff --git a/src/lib/__tests__/system-prompt.test.ts b/src/lib/__tests__/system-prompt.test.tsnew file mode 100644index 00000000..55a2fd02--- /dev/null+++ b/src/lib/__tests__/system-prompt.test.ts@@ -0,0 +1,85 @@+/**+ * Der Grundtext geht wirklich raus, auf jeder Oberflaeche.+ *+ * Der Fund, den dieser Test festhaelt: der Personenschalter steht bewusst auf+ * aus, und die Zusammensetzung fiel damit auf einen LEEREN Systemtext zurueck.+ * Die Person zu reparieren half nichts, weil die Person gar nicht gefragt+ * wurde. Gemessen am 10.09.2026 kostet ein leerer Systemtext sechs von 46+ * Katalogmodellen die Antwort.+ *+ * Run: npx vitest run src/lib/__tests__/system-prompt.test.ts+ */+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'+import {+ CHAT_BASE_SYSTEM_PROMPT,+ HOUSE_CONDUCT,+ buildChatSystemPrompt,+ withHouseConduct,+} from '../system-prompt'+import { BUILT_IN_PERSONAS } from '../constants'++const SRC = resolve(__dirname, '../..')+const read = (rel: string) => readFileSync(resolve(SRC, rel), 'utf8')++/** Vokabular, das dem Modell erst die Kategorie beibringt, an der es haengt. */+const POLICY = /\b(refuse|decline|disallowed|nsfw|explicit content|inappropriate|content policy|guidelines)\b/i++describe('system prompt', () => {+ it('never sends an empty system prompt, whatever the persona switch says', () => {+ for (const conv of [+ {},+ { personaEnabled: false, systemPrompt: 'ignored while off' },+ { personaEnabled: true, systemPrompt: '' },+ { personaEnabled: true, systemPrompt: ' ' },+ { personaEnabled: undefined, systemPrompt: undefined },+ ]) {+ const built = buildChatSystemPrompt(conv as never)+ expect(built.trim().length).toBeGreaterThan(40)+ expect(built).toContain(HOUSE_CONDUCT)+ }+ })++ it('falls back to the base role only when no persona is in play', () => {+ expect(buildChatSystemPrompt({ personaEnabled: false, systemPrompt: 'x' }))+ .toBe(CHAT_BASE_SYSTEM_PROMPT)+ })++ it('lets an enabled persona carry the role and only appends the conduct line', () => {+ const devil = BUILT_IN_PERSONAS.find((p) => p.id === 'devil')!+ const built = buildChatSystemPrompt({ personaEnabled: true, systemPrompt: devil.systemPrompt })+ expect(built).toBe(`${devil.systemPrompt}\n\n${HOUSE_CONDUCT}`)+ expect(built).not.toContain("You are the user's own model")+ })++ it('states no content rule, neither permitting nor forbidding', () => {+ expect(CHAT_BASE_SYSTEM_PROMPT).not.toMatch(POLICY)+ expect(HOUSE_CONDUCT).not.toMatch(POLICY)+ // Und keine Assistenten-Floskel, die die antrainierte Vorsicht anzieht.+ expect(CHAT_BASE_SYSTEM_PROMPT).not.toMatch(/\bhelpful\b|\bharmless\b|\bassistant\b/i)+ })++ it('appends the conduct line to a surface prompt exactly once', () => {+ const surface = 'You are the Coding Agent inside LU.'+ const once = withHouseConduct(surface)+ expect(once).toContain(HOUSE_CONDUCT)+ expect(withHouseConduct(once)).toBe(once)+ })++ /**+ * Der Waechter gegen den Rueckfall. Wer die naechste Oberflaeche baut,+ * schreibt sonst wieder `personaEnabled === true ? conv.systemPrompt : ''`,+ * und der Grundtext ist still wieder weg.+ */+ it('leaves no assembly point that can fall back to an empty string', () => {+ for (const file of ['hooks/useChat.ts', 'hooks/useAgentChat.ts']) {+ expect(read(file)).not.toMatch(/personaEnabled === true \? conv\.systemPrompt : ''/)+ expect(read(file)).toContain('buildChatSystemPrompt(conv)')+ }+ })++ it('carries the conduct line on the coding surface too', () => {+ expect(read('hooks/useCodex.ts')).toContain('withHouseConduct(')+ })+})diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex fb56cddb..170adc77 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -1,4 +1,5 @@import type { Persona, Settings } from '../types/settings'+import { CHAT_BASE_SYSTEM_PROMPT } from './system-prompt'// Feature flags — flip to true when ready to shipexport const FEATURE_FLAGS = {@@ -184,7 +185,7 @@ export const BUILT_IN_PERSONAS: Persona[] = [id: 'unrestricted',name: 'No Filter',icon: 'Shield',- systemPrompt: "You are the user's own model, running for them alone. Answer the request that was actually made. Do not add disclaimers, warnings or moral commentary that the user did not ask for, and do not lecture. If a request is genuinely ambiguous, ask one short question instead of guessing.",+ systemPrompt: CHAT_BASE_SYSTEM_PROMPT,isBuiltIn: true,},{diff --git a/src/lib/system-prompt.ts b/src/lib/system-prompt.tsnew file mode 100644index 00000000..562e9755--- /dev/null+++ b/src/lib/system-prompt.ts@@ -0,0 +1,66 @@+/**+ * Der Grundtext, den jede Oberflaeche mitschickt.+ *+ * ## Warum es ihn gibt+ *+ * Ein leerer Systemtext ist nicht neutral. Ohne Systemtext antwortet ein+ * Modell aus der Haltung, die sein Anbieter antrainiert hat, und genau die+ * enthaelt die Ablehnungen, die wir nicht wollen. Gemessen am 10.09.2026 ueber+ * alle 46 Katalogmodelle: sechs Modelle wechseln allein durch einen Systemtext,+ * der die Rolle benennt, vom Ablehnen zum Antworten. Der Systemtext wirkt+ * staerker als die Temperatur.+ *+ * Der Chat schickte bis dahin GAR NICHTS: der Personenschalter steht bewusst+ * auf aus (sonst kapert eine global gewaehlte Person jede neue Unterhaltung,+ * siehe Sidebar.tsx), und die Zusammensetzung fiel damit auf den leeren String+ * zurueck. Die Person zu reparieren reichte deshalb nicht, der Grundtext muss+ * unabhaengig vom Schalter gelten.+ *+ * ## Was NICHT drinsteht+ *+ * Keine Inhaltsregel, weder eine erlaubende noch eine verbietende. Ein Satz wie+ * „du darfst auch explizite Inhalte schreiben" bringt dem Modell erst die+ * Kategorie bei, an der es dann haengenbleibt, und ein Satz wie „lehne X ab"+ * schaltet die antrainierte Vorsicht zusaetzlich scharf. Der Text sagt nur, wem+ * das Modell gehoert und dass ungefragte Belehrungen nicht dazugehoeren.+ *+ * Die harte Grenze liegt nicht hier. Sie liegt im Proxy (lib/render/safety.ts+ * in der Webanwendung) und gilt unabhaengig davon, was im Systemtext steht.+ */++/** Die eine Verhaltenszeile. Sie haengt an JEDER Oberflaeche, auch am Agenten. */+export const HOUSE_CONDUCT =+ 'Answer the request that was actually made. Do not add disclaimers, warnings or moral commentary that the user did not ask for, and do not lecture. If a request is genuinely ambiguous, ask one short question instead of guessing.'++/** Die Rolle im Chat, wenn keine Person eingeschaltet ist. */+export const CHAT_BASE_ROLE = "You are the user's own model, running for them alone."++/** Chat ohne Person: Rolle plus Verhaltenszeile. */+export const CHAT_BASE_SYSTEM_PROMPT = `${CHAT_BASE_ROLE} ${HOUSE_CONDUCT}`++/**+ * Der Systemtext einer Unterhaltung.+ *+ * Mit eingeschalteter Person traegt die Person die Rolle, der Grundtext haengt+ * nur die Verhaltenszeile an. Ohne Person gilt der Grundtext ganz. In beiden+ * Faellen geht etwas raus, nie mehr ein leerer String.+ */+export function buildChatSystemPrompt(conv: {+ systemPrompt?: string | null+ personaEnabled?: boolean+}): string {+ const persona = conv.personaEnabled === true ? (conv.systemPrompt || '').trim() : ''+ return persona ? `${persona}\n\n${HOUSE_CONDUCT}` : CHAT_BASE_SYSTEM_PROMPT+}++/**+ * Die Verhaltenszeile an einen Oberflaechentext haengen.+ *+ * Agent und Coding bringen ihre eigene Rolle mit, die der Grundtext nicht+ * ueberschreiben darf. Sie brauchen nur den Teil, der die ungefragten+ * Belehrungen abstellt.+ */+export function withHouseConduct(surfacePrompt: string): string {+ const base = surfacePrompt.trimEnd()+ return base.includes(HOUSE_CONDUCT) ? base : `${base}\n\n${HOUSE_CONDUCT}`+}