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]): dedup magnitude ladder + form-shape factories

[._.]/ Adam Eivy5955065923d2
diff --git a/client/src/components/digital-twin/tabs/PersonasTab.jsx b/client/src/components/digital-twin/tabs/PersonasTab.jsx
index 889bebdcb0..baf717888b 100644
--- a/client/src/components/digital-twin/tabs/PersonasTab.jsx
+++ b/client/src/components/digital-twin/tabs/PersonasTab.jsx
@@ -11,8 +11,10 @@ const BIG_FIVE_LABELS = { O: 'Openness', C: 'Conscientiousness', E: 'Extraversio
// The editor's working shape. '' / 0 mean "no override" for that field; the
// payload builder strips them so an untouched editor sends no traitAdjustments.
-const EMPTY_ADJUSTMENTS = { formality: 0, verbosity: 0, emojiUsage: '', tone: '', bigFive: { O: 0, C: 0, E: 0, A: 0, N: 0 } };
-const EMPTY_FORM = { name: '', description: '', instructions: '', adjustments: EMPTY_ADJUSTMENTS };
+// Factories (not shared constants) so each form/reset gets its own nested
+// objects — a shared reference would let one form's edits leak into another.
+const makeEmptyAdjustments = () => ({ formality: 0, verbosity: 0, emojiUsage: '', tone: '', bigFive: { O: 0, C: 0, E: 0, A: 0, N: 0 } });
+const makeEmptyForm = () => ({ name: '', description: '', instructions: '', adjustments: makeEmptyAdjustments() });
// Hydrate the editor shape from a stored persona's traitAdjustments.
function adjustmentsToForm(traitAdjustments) {
@@ -54,10 +56,10 @@ export default function PersonasTab({ onRefresh }) {
const [busy, setBusy] = useState(false);
const [showCreate, setShowCreate] = useState(false);
- const [createForm, setCreateForm] = useState(EMPTY_FORM);
+ const [createForm, setCreateForm] = useState(makeEmptyForm());
const [editingId, setEditingId] = useState(null);
- const [editForm, setEditForm] = useState(EMPTY_FORM);
+ const [editForm, setEditForm] = useState(makeEmptyForm());
const [confirmDeleteId, setConfirmDeleteId] = useState(null);
@@ -92,7 +94,7 @@ export default function PersonasTab({ onRefresh }) {
setBusy(false);
if (!persona) return;
setPersonas(prev => [...prev, persona]);
- setCreateForm(EMPTY_FORM);
+ setCreateForm(makeEmptyForm());
setShowCreate(false);
toast.success('Persona created');
onRefresh?.();
@@ -176,7 +178,7 @@ export default function PersonasTab({ onRefresh }) {
</div>
{!showCreate && (
<button
- onClick={() => { setShowCreate(true); setCreateForm(EMPTY_FORM); }}
+ onClick={() => { setShowCreate(true); setCreateForm(makeEmptyForm()); }}
className="flex items-center justify-center gap-2 px-4 py-2.5 min-h-[44px] bg-port-accent text-white rounded-lg font-medium hover:bg-port-accent/80 shrink-0"
>
<Plus className="w-4 h-4" />
@@ -199,7 +201,7 @@ export default function PersonasTab({ onRefresh }) {
<Check className="w-4 h-4" /> Create
</button>
<button
- onClick={() => { setShowCreate(false); setCreateForm(EMPTY_FORM); }}
+ onClick={() => { setShowCreate(false); setCreateForm(makeEmptyForm()); }}
className="flex items-center gap-2 px-4 py-2 min-h-[40px] border border-port-border text-gray-400 rounded-lg hover:text-white"
>
<X className="w-4 h-4" /> Cancel
@@ -219,6 +221,7 @@ export default function PersonasTab({ onRefresh }) {
{personas.map(persona => {
const isActive = activeId === persona.id;
const isEditing = editingId === persona.id;
+ const voiceTags = describeTraitAdjustments(persona.traitAdjustments);
return (
<div
key={persona.id}
@@ -289,12 +292,12 @@ export default function PersonasTab({ onRefresh }) {
</div>
<p className="text-sm text-gray-300 mt-3 whitespace-pre-wrap bg-port-bg p-3 rounded">{persona.instructions}</p>
- {describeTraitAdjustments(persona.traitAdjustments).length > 0 && (
+ {voiceTags.length > 0 && (
<div className="mt-3 flex items-center gap-2 flex-wrap">
<span className="flex items-center gap-1 text-xs text-gray-500">
<SlidersHorizontal className="w-3.5 h-3.5" /> Voice:
</span>
- {describeTraitAdjustments(persona.traitAdjustments).map((d, i) => (
+ {voiceTags.map((d, i) => (
<span key={i} className="text-xs px-2 py-0.5 rounded bg-port-bg border border-port-border text-gray-300">{d}</span>
))}
</div>
@@ -393,7 +396,7 @@ function TraitAdjustmentsEditor({ idPrefix, adjustments, setAdjustments }) {
const setField = (key, value) => setAdjustments(a => ({ ...a, [key]: value }));
const setBigFive = (key, value) => setAdjustments(a => ({ ...a, bigFive: { ...a.bigFive, [key]: value } }));
- const reset = () => setAdjustments(() => ({ ...EMPTY_ADJUSTMENTS, bigFive: { ...EMPTY_ADJUSTMENTS.bigFive } }));
+ const reset = () => setAdjustments(makeEmptyAdjustments);
return (
<div className="border border-port-border rounded-lg">
diff --git a/client/src/lib/personaTraitBlend.js b/client/src/lib/personaTraitBlend.js
index a3e5d2d9a3..8918ecac90 100644
--- a/client/src/lib/personaTraitBlend.js
+++ b/client/src/lib/personaTraitBlend.js
@@ -38,15 +38,23 @@ export const BIG_FIVE_LEAN = {
const clamp = (n, lo, hi) => Math.max(lo, Math.min(hi, n));
-// Bare magnitude adverb for a 1..10-scale delta (slightly / notably / much) —
-// used where the paired verb already encodes direction (e.g. "more concise").
-function commAdverb(delta) {
+// Bin a delta's magnitude into slightly / notably / much against the [notably,
+// much] thresholds for its scale. One ladder, two scales (1..10 comm deltas use
+// [3, 5]; 0..1 Big-Five deltas use [0.2, 0.4]).
+function magnitudeAdverb(delta, notably, much) {
const mag = Math.abs(delta);
- if (mag >= 5) return 'much';
- if (mag >= 3) return 'notably';
+ if (mag >= much) return 'much';
+ if (mag >= notably) return 'notably';
return 'slightly';
}
+// Bare adverb for a 1..10-scale delta — used where the paired verb already
+// encodes direction (e.g. "more concise").
+const commAdverb = (delta) => magnitudeAdverb(delta, 3, 5);
+
+// Adverb for a 0..1-scale Big-Five delta.
+const bigFiveMagnitude = (delta) => magnitudeAdverb(delta, 0.2, 0.4);
+
// Signed wording for a fixed-quality 1..10 trait (e.g. formality): the quality
// word stays put and direction is "more"/"less" of it — "much more formal".
function commMagnitude(delta) {
@@ -59,14 +67,6 @@ function verbosityPhrase(delta) {
return `${commAdverb(delta)} more ${delta > 0 ? 'elaborate' : 'concise'}`;
}
-// Magnitude wording for a 0..1-scale Big-Five delta.
-function bigFiveMagnitude(delta) {
- const mag = Math.abs(delta);
- if (mag >= 0.4) return 'much';
- if (mag >= 0.2) return 'notably';
- return 'slightly';
-}
-
/**
* Does this persona carry any structured trait adjustment worth rendering?
* Empty objects / all-absent fields count as "none".
diff --git a/server/lib/personaTraitBlend.js b/server/lib/personaTraitBlend.js
index a3e5d2d9a3..8918ecac90 100644
--- a/server/lib/personaTraitBlend.js
+++ b/server/lib/personaTraitBlend.js
@@ -38,15 +38,23 @@ export const BIG_FIVE_LEAN = {
const clamp = (n, lo, hi) => Math.max(lo, Math.min(hi, n));
-// Bare magnitude adverb for a 1..10-scale delta (slightly / notably / much) —
-// used where the paired verb already encodes direction (e.g. "more concise").
-function commAdverb(delta) {
+// Bin a delta's magnitude into slightly / notably / much against the [notably,
+// much] thresholds for its scale. One ladder, two scales (1..10 comm deltas use
+// [3, 5]; 0..1 Big-Five deltas use [0.2, 0.4]).
+function magnitudeAdverb(delta, notably, much) {
const mag = Math.abs(delta);
- if (mag >= 5) return 'much';
- if (mag >= 3) return 'notably';
+ if (mag >= much) return 'much';
+ if (mag >= notably) return 'notably';
return 'slightly';
}
+// Bare adverb for a 1..10-scale delta — used where the paired verb already
+// encodes direction (e.g. "more concise").
+const commAdverb = (delta) => magnitudeAdverb(delta, 3, 5);
+
+// Adverb for a 0..1-scale Big-Five delta.
+const bigFiveMagnitude = (delta) => magnitudeAdverb(delta, 0.2, 0.4);
+
// Signed wording for a fixed-quality 1..10 trait (e.g. formality): the quality
// word stays put and direction is "more"/"less" of it — "much more formal".
function commMagnitude(delta) {
@@ -59,14 +67,6 @@ function verbosityPhrase(delta) {
return `${commAdverb(delta)} more ${delta > 0 ? 'elaborate' : 'concise'}`;
}
-// Magnitude wording for a 0..1-scale Big-Five delta.
-function bigFiveMagnitude(delta) {
- const mag = Math.abs(delta);
- if (mag >= 0.4) return 'much';
- if (mag >= 0.2) return 'notably';
- return 'slightly';
-}
-
/**
* Does this persona carry any structured trait adjustment worth rendering?
* Empty objects / all-absent fields count as "none".