Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: single server definition of DEFAULT_NEGATIVE_PROMPT

icn53815be00a78e06b
diff --git a/client/src/lib/imageGenDefaults.js b/client/src/lib/imageGenDefaults.js
index 24a0846dbb..430c4b7d91 100644
--- a/client/src/lib/imageGenDefaults.js
+++ b/client/src/lib/imageGenDefaults.js
@@ -1,8 +1,9 @@
// Image-gen defaults shared between the full Image Gen form and quick-submit
// entry points (e.g. the Dashboard Quick Image widget).
//
-// The server mirrors DEFAULT_NEGATIVE_PROMPT in
-// `server/services/imageGen/index.js` and `server/services/imageGen/external.js`
-// — when changing this string, update both server copies too.
+// The server keeps its own copy in `server/services/imageGen/defaults.js`
+// (the client cannot import server modules). The two are pinned together by
+// `server/services/imageGen/defaults.parity.test.js` — change one, and the
+// test names the other until they match again.
export const DEFAULT_NEGATIVE_PROMPT = 'blurry, low quality, distorted, deformed, ugly, watermark, text, signature';
diff --git a/server/services/imageGen/defaults.js b/server/services/imageGen/defaults.js
new file mode 100644
index 0000000000..07e2a89b70
--- /dev/null
+++ b/server/services/imageGen/defaults.js
@@ -0,0 +1,12 @@
+/**
+ * Image Gen — shared default constants.
+ *
+ * Standalone for the same reason as modes.js: the dispatcher (`index.js`)
+ * and the provider modules (`external.js`, …) both import, so the base
+ * negative prompt is defined exactly once on the server. The client keeps
+ * its own mirror in `client/src/lib/imageGenDefaults.js` because it cannot
+ * import server modules; `defaults.parity.test.js` fails when the two
+ * drift apart.
+ */
+
+export const DEFAULT_NEGATIVE_PROMPT = 'blurry, low quality, distorted, deformed, ugly, watermark, text, signature';
diff --git a/server/services/imageGen/defaults.parity.test.js b/server/services/imageGen/defaults.parity.test.js
new file mode 100644
index 0000000000..22c7655866
--- /dev/null
+++ b/server/services/imageGen/defaults.parity.test.js
@@ -0,0 +1,33 @@
+import { describe, it, expect } from 'vitest';
+import { readFileSync, readdirSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+import { DEFAULT_NEGATIVE_PROMPT } from './defaults.js';
+
+const HERE = dirname(fileURLToPath(import.meta.url));
+const read = (p) => readFileSync(join(HERE, p), 'utf8');
+
+describe('imageGen defaults', () => {
+ it('matches the client mirror, which cannot import this module', () => {
+ // client/src/lib/imageGenDefaults.js hardcodes the same string for the
+ // Image Gen form and the Dashboard Quick Image widget. If it drifts,
+ // the user edits against one default while the server applies another —
+ // silently, which is why this is a test and not a comment.
+ const clientSrc = read('../../../client/src/lib/imageGenDefaults.js');
+ const match = clientSrc.match(/DEFAULT_NEGATIVE_PROMPT = '([^']+)'/);
+ expect(match, 'client mirror not found — did DEFAULT_NEGATIVE_PROMPT move?').toBeTruthy();
+ expect(match[1]).toBe(DEFAULT_NEGATIVE_PROMPT);
+ });
+
+ it('is the only server-side definition of the base negative prompt', () => {
+ // The dedupe this module exists for: discover the service's modules
+ // rather than listing them, so a fresh pasted-in copy cannot sneak back
+ // in next to a new provider.
+ const offenders = readdirSync(HERE)
+ .filter((f) => f.endsWith('.js') && !f.endsWith('.test.js') && f !== 'defaults.js')
+ .map((f) => [f, read(f)])
+ .filter(([, src]) => src.includes("'blurry, low quality"))
+ .map(([f]) => f);
+ expect(offenders, 'literal copies found outside defaults.js').toEqual([]);
+ });
+});
diff --git a/server/services/imageGen/external.js b/server/services/imageGen/external.js
index b1586410a7..51550013e7 100644
--- a/server/services/imageGen/external.js
+++ b/server/services/imageGen/external.js
@@ -15,8 +15,8 @@ import { fetchWithTimeout } from '../../lib/fetchWithTimeout.js';
import { autoCleanGeneratedImage } from '../../lib/imageClean.js';
import { imageGenEvents } from '../imageGenEvents.js';
import { IMAGE_GEN_MODE } from './modes.js';
+import { DEFAULT_NEGATIVE_PROMPT } from './defaults.js';
-const DEFAULT_NEGATIVE_PROMPT = 'blurry, low quality, distorted, deformed, ugly, watermark, text, signature';
const PROGRESS_POLL_INTERVAL = 500;
const IMAGE_PREVIEW_THROTTLE = 2000;
const MODEL_CACHE_TTL = 5 * 60 * 1000;
diff --git a/server/services/imageGen/index.js b/server/services/imageGen/index.js
index a718e41a29..ebbbc3091a 100644
--- a/server/services/imageGen/index.js
+++ b/server/services/imageGen/index.js
@@ -23,6 +23,7 @@ import * as agy from './agy.js';
import {
IMAGE_GEN_MODE, IMAGE_GEN_MODES, CLOUD_IMAGE_GEN_MODES, isEditCapableMode,
} from './modes.js';
+import { DEFAULT_NEGATIVE_PROMPT } from './defaults.js';
import { resolveCloudProviderConfig } from './cloudProviderConfig.js';
import { rejectDegenerateFrame } from './frameGuard.js';
import { PATHS } from '../../lib/fileUtils.js';
@@ -157,8 +158,6 @@ async function guardResolvedFrame(result) {
return result;
}
-const DEFAULT_NEGATIVE_PROMPT = 'blurry, low quality, distorted, deformed, ugly, watermark, text, signature';
-
// Build the default avatar prompt for the human-centered Character surface (#2677).
// The Character page portrays the real human user, so a blank identity must NOT
// fall back to the old generic D&D adventurer/warrior prompt: an empty name/class