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([issue-708]): single-source trait-delta bounds + add mirror parity test

[._.]/ Adam Eivya99cf66cf841
diff --git a/client/src/components/digital-twin/tabs/PersonasTab.jsx b/client/src/components/digital-twin/tabs/PersonasTab.jsx
index baf717888b..cb833299a1 100644
--- a/client/src/components/digital-twin/tabs/PersonasTab.jsx
+++ b/client/src/components/digital-twin/tabs/PersonasTab.jsx
@@ -3,7 +3,14 @@ import { Drama, Plus, Pencil, Trash2, Check, X, CheckCircle2, SlidersHorizontal
import BrailleSpinner from '../../BrailleSpinner';
import * as api from '../../../services/api';
import toast from '../../ui/Toast';
-import { describeTraitAdjustments, BIG_FIVE_LEAN } from '../../../lib/personaTraitBlend.js';
+import {
+ describeTraitAdjustments,
+ BIG_FIVE_LEAN,
+ COMM_DELTA_MIN,
+ COMM_DELTA_MAX,
+ BIG_FIVE_DELTA_MIN,
+ BIG_FIVE_DELTA_MAX
+} from '../../../lib/personaTraitBlend.js';
const EMOJI_OPTIONS = ['never', 'rare', 'occasional', 'frequent'];
const BIG_FIVE_KEYS = ['O', 'C', 'E', 'A', 'N'];
@@ -507,8 +514,8 @@ function SliderRow({ id, label, hint, value, onChange }) {
<input
id={id}
type="range"
- min={-9}
- max={9}
+ min={COMM_DELTA_MIN}
+ max={COMM_DELTA_MAX}
step={1}
value={value}
onChange={(e) => onChange(Number(e.target.value))}
@@ -535,8 +542,8 @@ function BigFiveRow({ id, label, more, less, value, onChange }) {
<input
id={id}
type="range"
- min={-1}
- max={1}
+ min={BIG_FIVE_DELTA_MIN}
+ max={BIG_FIVE_DELTA_MAX}
step={0.1}
value={value}
onChange={(e) => onChange(roundTenth(Number(e.target.value)))}
diff --git a/server/lib/digitalTwinValidation.js b/server/lib/digitalTwinValidation.js
index 07d51f122a..69621b28f1 100644
--- a/server/lib/digitalTwinValidation.js
+++ b/server/lib/digitalTwinValidation.js
@@ -1,4 +1,14 @@
import { z } from 'zod';
+import {
+ COMM_DELTA_MIN,
+ COMM_DELTA_MAX,
+ BIG_FIVE_DELTA_MIN,
+ BIG_FIVE_DELTA_MAX
+} from './personaTraitBlend.js';
+
+// Emoji-usage vocabulary, shared by the base twin's communication profile and a
+// persona's trait-adjustment override so the two enums can't drift apart.
+export const EMOJI_USAGE_VALUES = ['never', 'rare', 'occasional', 'frequent'];
// Document category enum
export const documentCategoryEnum = z.enum([
@@ -156,12 +166,13 @@ export const soulSettingsSchema = digitalTwinSettingsSchema; // Alias for backwa
// ±9 delta can reach either end), absolute overrides for emoji usage and tone,
// and directional Big-Five leans (0..1 scale → ±1 delta). All fields optional;
// an instructions-only persona omits the whole object. The blend + directive
-// rendering live in `server/lib/personaTraitBlend.js`.
-const bigFiveDelta = z.number().min(-1).max(1);
+// rendering live in `server/lib/personaTraitBlend.js`, which is the single
+// source for the delta bounds the schema and UI sliders both enforce.
+const bigFiveDelta = z.number().min(BIG_FIVE_DELTA_MIN).max(BIG_FIVE_DELTA_MAX);
export const personaTraitAdjustmentsSchema = z.object({
- formality: z.number().int().min(-9).max(9).optional(),
- verbosity: z.number().int().min(-9).max(9).optional(),
- emojiUsage: z.enum(['never', 'rare', 'occasional', 'frequent']).optional(),
+ formality: z.number().int().min(COMM_DELTA_MIN).max(COMM_DELTA_MAX).optional(),
+ verbosity: z.number().int().min(COMM_DELTA_MIN).max(COMM_DELTA_MAX).optional(),
+ emojiUsage: z.enum(EMOJI_USAGE_VALUES).optional(),
tone: z.string().max(100).optional(),
bigFive: z.object({
O: bigFiveDelta.optional(),
@@ -220,7 +231,7 @@ export const communicationProfileSchema = z.object({
formality: z.number().int().min(1).max(10).describe('1=very casual, 10=very formal'),
verbosity: z.number().int().min(1).max(10).describe('1=terse, 10=elaborate'),
avgSentenceLength: z.number().min(5).max(50).optional(),
- emojiUsage: z.enum(['never', 'rare', 'occasional', 'frequent']).default('rare'),
+ emojiUsage: z.enum(EMOJI_USAGE_VALUES).default('rare'),
preferredTone: z.string().max(100).optional(),
distinctiveMarkers: z.array(z.string().max(200)).max(10).optional()
});
diff --git a/server/lib/personaTraitBlend.parity.test.js b/server/lib/personaTraitBlend.parity.test.js
new file mode 100644
index 0000000000..972831d43d
--- /dev/null
+++ b/server/lib/personaTraitBlend.parity.test.js
@@ -0,0 +1,30 @@
+/**
+ * Byte-for-byte parity for the persona trait-blend helper.
+ *
+ * `server/lib/personaTraitBlend.js` is the source of truth; `client/src/lib/
+ * personaTraitBlend.js` is a mirror the Personas UI imports for its live voice
+ * preview. The module's docstring promises the two stay byte-identical (so the
+ * preview wording matches the directive the embodied twin actually sees) — this
+ * suite enforces that promise: an edit to one copy that isn't mirrored fails CI
+ * here instead of letting the UI silently diverge from the server directive.
+ *
+ * It lives server-side because the parity check only needs filesystem reads,
+ * which the server (node) runner has.
+ */
+
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'fs';
+import { fileURLToPath } from 'url';
+import { dirname, join } from 'path';
+
+const here = dirname(fileURLToPath(import.meta.url));
+const SERVER_COPY = join(here, 'personaTraitBlend.js');
+const CLIENT_COPY = join(here, '../../client/src/lib/personaTraitBlend.js');
+
+describe('personaTraitBlend — server↔client byte parity', () => {
+ it('keeps the client mirror byte-for-byte identical to the server source', () => {
+ const server = readFileSync(SERVER_COPY, 'utf-8');
+ const client = readFileSync(CLIENT_COPY, 'utf-8');
+ expect(client).toBe(server);
+ });
+});