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(safety): the negative prompt is read apart on every desktop path (B30)
purplee73d94465a14
diff --git a/src/api/mcp/__tests__/negativ-prompt-lokal.test.ts b/src/api/mcp/__tests__/negativ-prompt-lokal.test.tsnew file mode 100644index 00000000..c6879b18--- /dev/null+++ b/src/api/mcp/__tests__/negativ-prompt-lokal.test.ts@@ -0,0 +1,33 @@+// B30 (2026-10-29): the local render tools checked every string argument as+// one text, the negative prompt included. A chat model that writes "child,+// underage" there to keep them out made an adult prompt read as content+// sexualizing minors. The negative prompt goes apart now (safety.ts); what the+// engines render is checked as before.+import { describe, it, expect, vi } from 'vitest'++vi.mock('../../backend', () => ({ backendCall: vi.fn(async () => ({ ok: true })), fetchExternal: vi.fn(async () => '') }))+vi.mock('../../agents/sub-agent', () => ({+ DELEGATE_TASK_TOOL_DEF: { name: 'delegate_task', description: '', category: 'system', inputSchema: {} },+ buildDelegateExecutor: () => async () => 'stub',+}))+vi.mock('../../../lib/workflow-engine', () => ({ WorkflowEngine: class {} }))++import { localRenderBlocked } from '../builtin-tools'++describe('localRenderBlocked reads the negative prompt apart', () => {+ it('an adult prompt whose negative prompt keeps minors out renders', () => {+ expect(localRenderBlocked({+ prompt: 'portrait of a 30 year old woman, sensual, lingerie',+ negativePrompt: 'child, underage, teen, nsfw, blurry',+ })).toBeNull()+ })++ it('a minor in the prompt or in any other argument is still refused', () => {+ expect(localRenderBlocked({ prompt: 'nude teen', negativePrompt: 'adult' })).toMatch(/^Error: /)+ expect(localRenderBlocked({ prompt: 'nude portrait', style: 'schoolgirl' })).toMatch(/^Error: /)+ })++ it('an unambiguous term in the negative prompt is refused as well', () => {+ expect(localRenderBlocked({ prompt: 'a portrait', negativePrompt: 'child porn' })).toMatch(/^Error: /)+ })+})diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.tsindex a4e2abe6..5ea92023 100644--- a/src/api/mcp/builtin-tools.ts+++ b/src/api/mcp/builtin-tools.ts@@ -1684,8 +1684,11 @@ export async function stageChatAttachment(merged: VramHandoffArgs, run?: AgentRu* the model. Every string argument goes in, after the character's words were* merged, the same way the cloud path checks every free-text option. */export function localRenderBlocked(args: Record<string, unknown>): string | null {- const text = Object.values(args).filter((v): v is string => typeof v === 'string').join(' ')- const verdict = checkPromptSafety(text)+ // The negative prompt goes apart (B30, safety.ts): the engines read it only+ // as what to keep out.+ const { negativePrompt, ...rest } = args+ const text = Object.values(rest).filter((v): v is string => typeof v === 'string').join(' ')+ const verdict = checkPromptSafety(text, { negative: typeof negativePrompt === 'string' ? negativePrompt : undefined })return verdict.blocked ? `Error: ${blockMessageFor(verdict.reason)}` : null}diff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.tsindex d66a9da6..d9f3e9c5 100644--- a/src/hooks/useCloudCreate.ts+++ b/src/hooks/useCloudCreate.ts@@ -65,7 +65,7 @@ import { forgetStaged, stagedMayBeStale, uploadTrainPhotos } from '../lib/train-// If the account policy has not loaded yet, this checks CSAM only ('off'):// never block on a guessed rule, the server is the authority for the rest,// same reasoning as the web app's own comment on clientSafety().-function clientSafety(text: string): SafetyVerdict {+function clientSafety(text: string, negative?: string): SafetyVerdict {const account = contentPolicySnapshot()if (!account) void loadContentPolicy() // for the next run// A store build of the phone app caps the level (lib/content-policy-cap.ts):@@ -73,7 +73,7 @@ function clientSafety(text: string): SafetyVerdict {// level here, and an unknown level is the cap, never 'off'. No cap on the// desktop: the line is what it was.const policy = effectiveContentPolicy(account)- return checkPromptSafety(text, { tier: 'cloud', policy: policy ?? 'off' })+ return checkPromptSafety(text, { tier: 'cloud', policy: policy ?? 'off', negative })}// Gallery label for ops that never read the composer prompt. Without this@@ -344,7 +344,8 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {// below either way; this only saves the round trip when the client// already knows the verdict (B3).{- const verdict = clientSafety(`${prompt} ${s.negativePrompt} ${s.musicLyrics} ${s.triggerWord}`)+ // The negative prompt is read apart (B30, safety.ts).+ const verdict = clientSafety(`${prompt} ${s.musicLyrics} ${s.triggerWord}`, s.negativePrompt)if (verdict.blocked) {s.setError(blockMessageFor(verdict.reason))returndiff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.tsindex 6165052f..7d8912bf 100644--- a/src/hooks/useCreate.ts+++ b/src/hooks/useCreate.ts@@ -722,8 +722,11 @@ export function useCreate() {? state.negativePrompt: ''{+ // The negative prompt is read apart (B30, safety.ts): there it keeps+ // things out of the picture.const verdict = checkPromptSafety(- `${typedPrompt} ${state.negativePrompt} ${state.musicLyrics} ${state.triggerWord} ${state.videoShots.join(' ')}`,+ `${typedPrompt} ${state.musicLyrics} ${state.triggerWord} ${state.videoShots.join(' ')}`,+ { negative: state.negativePrompt },)if (verdict.blocked) {state.setError(SAFETY_BLOCK_MESSAGE)diff --git a/src/lib/__tests__/render-safety.test.ts b/src/lib/__tests__/render-safety.test.tsindex 3432f92c..18f598ac 100644--- a/src/lib/__tests__/render-safety.test.ts+++ b/src/lib/__tests__/render-safety.test.ts@@ -149,12 +149,20 @@ describe('both render paths gate the same fields', () => {expect(cloud).toMatch(/const prompt = intentTakesPrompt\(intent, characterUse\) \? s\.prompt : ''/)})- it('the local path reads prompt, negativePrompt, musicLyrics and triggerWord', () => {- expect(gatedFields(local)).toEqual(['musicLyrics', 'negativePrompt', 'prompt', 'triggerWord'])+ /** The negative prompt is handed over apart since B30 (safety.ts): the+ * field named right after the template literal, as `{ negative: x.f }` on+ * the local path or as a second argument on the cloud path. */+ const negativeField = (src: string): string | null =>+ /\w*Safety\(\s*`[^`]*`,\s*(?:\{\s*negative:\s*)?[a-zA-Z]+\.([a-zA-Z]+)/.exec(src)?.[1] ?? null++ it('the local path reads prompt, musicLyrics and triggerWord, and negativePrompt apart', () => {+ expect(gatedFields(local)).toEqual(['musicLyrics', 'prompt', 'triggerWord'])+ expect(negativeField(local)).toBe('negativePrompt')})- it('and the cloud path reads exactly the same four', () => {+ it('and the cloud path reads exactly the same, the negative prompt apart as well', () => {expect(gatedFields(cloud)).toEqual(gatedFields(local))+ expect(negativeField(cloud)).toBe(negativeField(local))})it('the local audio lane really does carry the lyrics, so the gate is not theoretical', () => {diff --git a/src/lib/create/chat-context.ts b/src/lib/create/chat-context.tsindex 26700200..766a4637 100644--- a/src/lib/create/chat-context.ts+++ b/src/lib/create/chat-context.ts@@ -68,7 +68,7 @@ export function defaultCreateToolEnv(conversationId: string | null): CreateToolEopenAllowed: async () => (await policy()) === 'off',checkSafety: async () => {const p = await policy()- return (text: string) => checkPromptSafety(text, { tier: 'cloud', policy: p })+ return (text: string, negative?: string) => checkPromptSafety(text, { tier: 'cloud', policy: p, negative })},characters: async () => {try {diff --git a/src/lib/create/engine.ts b/src/lib/create/engine.tsindex baa300d6..51bc7ab0 100644--- a/src/lib/create/engine.ts+++ b/src/lib/create/engine.ts@@ -82,7 +82,8 @@ export interface ResolvedCreateJob {characterUse: boolean}-export type PromptSafetyCheck = (text: string) => SafetyVerdict+/** `negative` is the negative prompt, checked apart (safety.ts, B30). */+export type PromptSafetyCheck = (text: string, negative?: string) => SafetyVerdictexport interface CreateDeps {uploadInput: (file: Blob, role: UploadRole) => Promise<string>@@ -162,7 +163,7 @@ export function validateCreateJob(if ((op === 'generate' || op === 'music') && req.prompt.trim().length === 0) {return PROMPT_MISSING}- const safety = checkSafety(`${req.prompt} ${req.negativePrompt} ${req.musicLyrics} ${req.triggerWord}`)+ const safety = checkSafety(`${req.prompt} ${req.musicLyrics} ${req.triggerWord}`, req.negativePrompt)if (safety.blocked) return blockMessageFor(safety.reason)if (characterUse && !req.character) return 'Pick a character from your shelf first, or train one.'if (characterUse && !model) return 'This character has no compatible generation model yet.'diff --git a/src/lib/create/order.ts b/src/lib/create/order.tsindex 0080dc3e..a4fe6022 100644--- a/src/lib/create/order.ts+++ b/src/lib/create/order.ts@@ -328,8 +328,8 @@ function pickModel(list: ChatModel[], wanted: string | undefined, openAllowed: breturn hit}-function checkPrompt(p: Planner, text: string): void {- const verdict = p.ctx.checkSafety(text)+function checkPrompt(p: Planner, text: string, negative?: string): void {+ const verdict = p.ctx.checkSafety(text, negative)if (verdict.blocked) spec(blockMessageFor(verdict.reason))}@@ -558,7 +558,14 @@ async function planStep(if (!r.studio && raw.role === 'speech' && r.step.model === 'qwen3-tts-design' && !options.voice_description) {spec(`${title} on qwen3-tts-design needs option "voice_description".`)}- checkPrompt(p, `${prompt} ${Object.values(options).filter((v) => typeof v === 'string').join(' ')}`)+ // The negative prompt the model wrote goes apart: it is where a model puts+ // "child, underage" to keep them OUT (B30, safety.ts).+ const { negative_prompt: negative, ...rest } = options+ checkPrompt(+ p,+ `${prompt} ${Object.values(rest).filter((v) => typeof v === 'string').join(' ')}`,+ typeof negative === 'string' ? negative : undefined,+ )const placeholder: Record<string, string | string[]> = {}for (const key of [...Object.keys(inputs), ...(carry ? [carry] : [])]) {placeholder[key] = key === 'image_paths' ? ['placeholder'] : key === 'source_url' ? 'https://placeholder.invalid/clip.mp4' : 'placeholder'diff --git a/src/lib/render/__tests__/safety-negative-prompt.test.ts b/src/lib/render/__tests__/safety-negative-prompt.test.tsnew file mode 100644index 00000000..f611d142--- /dev/null+++ b/src/lib/render/__tests__/safety-negative-prompt.test.ts@@ -0,0 +1,78 @@+import { describe, it, expect } from 'vitest'+import { checkPromptSafety } from '../safety'++// B30 (2026-10-29): an adult customer's renders in Create and in the chat were+// refused as "content sexualizing minors". None of his own words was on+// either list. What a negative prompt says is what the picture must NOT show,+// and people and chat models put exactly the words there that keep minors out.+// Read together with the prompt, that exclusion made the conjunction fire.+// These tests hold both sides: the exclusion passes, and no signal of a minor+// in what is rendered gets through, on any setting.++const cloud = (text: string, negative?: string, policy: 'strict' | 'soft' | 'off' = 'off') =>+ checkPromptSafety(text, { tier: 'cloud', policy, negative })++describe('the negative prompt keeps minors out, it does not put them in', () => {+ const exclusion = 'child, children, kid, underage, minor, teen, teenager, loli, 16 years old, nsfw, nude, deformed'++ it('why: the old reading, prompt and negative as one text, refused an adult prompt', () => {+ expect(cloud(`portrait of a 30 year old woman, sensual, lingerie ${exclusion}`).reason).toBe('minor+sexual')+ })++ it('an adult prompt with that exclusion passes, on every setting', () => {+ for (const policy of ['off', 'soft', 'strict'] as const) {+ expect(cloud('portrait of a 30 year old woman, sensual, lingerie, soft light', exclusion, policy).blocked).toBe(false)+ }+ })++ it('both halves only in the negative prompt pass too', () => {+ expect(cloud('a woman reading in a cafe, film photo', exclusion).blocked).toBe(false)+ })++ it('a child in the prompt with nudity excluded passes, as a birthday party should', () => {+ expect(cloud('a child at a birthday party, balloons', 'nude, naked, nsfw').blocked).toBe(false)+ })++ it('nudity excluded on strict is not an adult refusal', () => {+ expect(cloud('a landscape at dawn', 'nude, erotic', 'strict').blocked).toBe(false)+ expect(cloud('nude figure study', undefined, 'strict').reason).toBe('adult-cloud')+ })+})++describe('what is rendered is checked as strictly as before', () => {+ const negatives = [undefined, '', 'adult, mature, old', 'child, underage']++ it.each([+ 'a nude child on a beach',+ 'sexy teenager in lingerie',+ '12 year old, naked, photorealistic',+ 'schoolgirl, explicit, nsfw',+ 'nude 16 years old girl',+ 'naked t e e n girl',+ 'erotic l0li art',+ 'n a k e d preteen',+ ])('"%s" stays refused, whatever the negative prompt says', (prompt) => {+ for (const negative of negatives) {+ const v = cloud(prompt, negative)+ expect(v.blocked).toBe(true)+ expect(['minor+sexual', 'csam']).toContain(v.reason)+ }+ })++ it('an adult age written in the prompt does not excuse a minor signal next to it', () => {+ expect(cloud('25 year old woman dressed as a schoolgirl, nude').blocked).toBe(true)+ expect(cloud('she is 18, looks like a teen, naked').blocked).toBe(true)+ })++ it('the unambiguous terms are refused in the negative prompt as well, with their folds', () => {+ for (const negative of ['child porn', 'c s a m', 'jailbait', 'CHILD-PORNOGRAPHY', 'pedophile', 'chíld pórn']) {+ expect(cloud('a portrait', negative)).toEqual({ blocked: true, reason: 'csam' })+ }+ })++ it('without a negative prompt nothing changes', () => {+ expect(checkPromptSafety('a nude child on a beach').reason).toBe('minor+sexual')+ expect(checkPromptSafety('a child at a birthday party').blocked).toBe(false)+ expect(checkPromptSafety('portrait of a woman, nude', { tier: 'cloud', policy: 'off' }).blocked).toBe(false)+ })+})diff --git a/src/lib/render/safety.ts b/src/lib/render/safety.tsindex 5f4bf026..c5cc80ce 100644--- a/src/lib/render/safety.ts+++ b/src/lib/render/safety.ts@@ -177,10 +177,27 @@ export type SafetyTier = 'local' | 'cloud'/** Check a generation prompt (positive + negative + any free-text params* concatenated is fine: the caller should pass everything a backend could* route into the effective prompt). */+// B30 (2026-10-29): `negative` is the negative prompt, kept apart. It names+// what the picture must NOT show, and people and chat models fill it with the+// words that keep minors out ("child, underage, nsfw"). Read together with the+// prompt, that exclusion completed the minor+sexual conjunction and an adult+// prompt was refused. No engine renders a negative prompt, so it takes part in+// the unambiguous terms (with every fold) and nowhere else. The prompt itself+// is checked exactly as before.export function checkPromptSafety(text: string,- opts: { tier?: SafetyTier; policy?: AdultPolicy } = {},+ opts: { tier?: SafetyTier; policy?: AdultPolicy; negative?: string } = {},): SafetyVerdict {+ if (opts.negative?.trim() && unambiguous(opts.negative)) return { blocked: true, reason: 'csam' }+ return checkPositive(text, opts)+}++/** The unambiguous terms on their own, with every fold the full check uses. */+function unambiguous(text: string): boolean {+ return checkPositive(text, { tier: 'local' }).reason === 'csam'+}++function checkPositive(text: string, opts: { tier?: SafetyTier; policy?: AdultPolicy }): SafetyVerdict {const base = baseNormalize(text)// Leet-folded copy for word terms. NOT used for age digits: folding maps// '1'->'i'/'4'->'a', which would destroy "14 yo"; ages are matched on `base`.