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

Vary CoS Muse avatar coding animation and render full color

Adam Eivy0d53d99599dd
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 211ef65a6b..f09abadb92 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -20,6 +20,8 @@
## Changed
+- **The Cyber Muse (3D) Chief-of-Staff avatar now works with real color and a livelier "coding" state.** The rigged robot renders in its own full textures and color instead of a dark holographic silhouette with the agent-state hue painted over it — the per-state color now lives in the surrounding halo, ground glow, sparkles, and accent light, so the model reads clearly while the scene still signals what the agent is doing. And while an agent is working, the avatar no longer loops a single punch clip: it cycles a varied montage (jab → run → jump → thumbs-up → walk → celebrate) so a busy Chief of Staff looks busy. The run/walk cycles play "in place" so the avatar can't stride out of frame, and a custom GLB missing the montage clips falls back to its single base loop exactly as before.
+
- [issue-2677] **Your Character page is now about you, not a generic adventurer.** The page centers on the human who owns the install — your name, your avatar, your age-based level, and the skills, goals, and metrics derived from how you actually use PortOS — with the old D&D combat mechanics moved out of the way. Damage, rest, dice rolls, manual XP, the JIRA/task XP sync, and the event log now live in a collapsed "RPG mechanics" section that's closed by default; nothing was removed, so those buttons and endpoints still work and existing character files keep their history. When you haven't set a birth date yet there's no age to turn into a level, so instead of a blank badge the page prompts you to "set your birth date" and links straight to the age editor where that field lives. Your name and title now read as human placeholders ("Your name", "Add a title") instead of the old generic "Adventurer" / "Developer": a fresh install starts blank so it prompts for your real name (an existing install keeps whatever name is on record — edit it inline to make it yours).
- [issue-2669] **MeatSpace health forms no longer double-toast on failure.** Saving a genome marker note, or adding/editing a custom drink or custom nicotine product, showed two stacked error toasts when the request failed — once from the API helper and once from the form's own catch. These five sites now suppress the helper toast so a single error is shown.
diff --git a/PLAN.md b/PLAN.md
index 78dbc21c20..de510c52dc 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -201,6 +201,10 @@ by `/do:replan --issues`:
- [ ] **Retire or wire up `StatCard`'s never-passed `activeLabel` prop, and de-dup the two hand-rolled Learning cards.** `activeLabel` (`client/src/components/cos/StatCard.jsx:1`) has **zero callers** across the client — no `activeLabel=` usage and no spread props into `<StatCard>`. It is *visually* rendered only by the default variant (:59-63); the `compact` (:4-22) and `mini` (:24-42) variants honor it only through the `ariaLabel` interpolation at :2 (consumed via `aria-label` at :8 / :28) — i.e. it reaches the accessible name but is never displayed. So it is not fully inert: deleting it changes the accname on two variants. Either delete the prop + its render branch + the `ariaLabel` clause together, or make compact/mini render it. Related: the two Learning cards (`client/src/pages/ChiefOfStaff.jsx` ~512-540 compact, ~836-862 ascii `mini`) are hand-rolled buttons rather than `StatCard`s precisely because StatCard supports neither `onClick` nor a status-driven border color nor a visible sub-label on the compact variant — and each duplicates the same `status === 'critical' ? … : 'warning' ? …` color ternary twice (once for the border, once for the icon). Wiring a visible sub-label slot through all variants plus `onClick`/border-tone props would let both collapse onto StatCard. Deferred from the mobile-overflow fix (which only restructured the compact card's value/label stacking): removing or re-speccing a prop on a shared component used by every CoS stat card is a distinct refactor deserving its own PR + tests, and the overflow fix must not ride on it.
+### Cyber Muse avatar follow-ups
+
+- [ ] **Unify `MUSE_STATE_ANIMATIONS` (single-clip base loops) and `MUSE_STATE_SEQUENCES` (montages) into one `state → ordered steps` map.** Today `client/src/components/cos/constants.js` keeps two parallel maps: a single base-clip per state (`MUSE_STATE_ANIMATIONS`, step shape `{clip,timeScale,once}`) and an optional montage (`MUSE_STATE_SEQUENCES`, step shape `{clip,timeScale,reps}`). `MuseCoSAvatar.jsx` then forks base-vs-sequence in the state effect (`resumeMotion`), the `finished` listener, and `sequenceSteps`/`baseClip` resolution. A single looping clip is just a length-1 montage, so the two could collapse to one map `state → [{ clip, timeScale, loop: 'infinite' | 'once' | {reps: N} }]`: single-clip states become length-1 lists (`loop:'infinite'`), `coding` is a longer list, and the "montage's fallback is the base clip" relationship becomes structural (filter steps to present clips; if only one survives, play it looping) instead of prose-enforced (the current comment in constants.js says "keep every entry mapped… also the graceful fallback"). This would delete `MUSE_STATE_SEQUENCES` as a separate concept and remove the base-vs-sequence forks in the driver. Deferred from the `/simplify` pass on the avatar montage PR: it's a redesign of a state machine that was already visually verified (montage cycling + speaking-gesture defer/restore + fallback), so it warrants its own PR + a re-verification pass rather than riding on the cleanup. Consumers to update: `MuseCoSAvatar.jsx`, `constants.test.js`, `data.reference/avatar/README.md` (only in-repo references).
+
### Creative Director agents should not push code (deferred — needs a distinct completion contract)
- [ ] **Suppress `/simplify` + `/do:push` + PR in CD agent completions WITHOUT breaking their API output contract.** CD plan/treatment/evaluation agents persist their real output via an HTTP call in the task BODY (e.g. `PATCH http://localhost:5555/api/creative-director/{id}/plan` — see the plan prompt), and use the `.agent-done` sentinel only as a *done-signal* (a short markdown summary that PortOS's 2s poll consumes to finalize the run). They run on `main` (`useWorktree:false`, `configCodingOnMain:true`) and make no repo changes, so the trailing `/simplify` → `/do:push` completion is both pointless and dangerous (a `/do:push` on main could commit stray working-tree files). The fix must remove `/simplify`+`/do:push`+PR from the CD completion while KEEPING (a) the sentinel done-signal handshake and (b) the task-body PATCH as the output channel. **Do NOT reuse `discardWorktree`** — codex review (2026-07-16) correctly flagged that it routes to `buildProgrammaticOutputCompletionSection`, whose wording ("your *only* output channel is the `.agent-done` sentinel; write your result there in the payload format from your instructions") directly contradicts the PATCH and could make the agent write the plan to the sentinel instead of PATCHing → plan never persists → project stalls/re-enqueues. `readOnly:true` is also wrong ("read data and report findings only" contradicts the PATCH, and the CLI read-only path emits no sentinel). The correct fix is a NEW completion contract (e.g. a `apiOutput`/`noRepoOutput` metadata flag) that emits: "This task persists its output via the API/tool calls described above and makes no repo changes — do NOT run `/simplify`, `/do:push`, `/do:pr`, `git commit/push`, or open a PR; when done write a short summary to the sentinel to signal completion." Thread the flag through the completion selection in `server/services/agentPromptBuilder.js` (lines ~1137-1160 light path + the full-context path ~790, and whichever of `buildTuiCompletionSection`/`buildCliCompletionSection` CD actually reaches — confirm via a regenerated CD prompt fixture) and add a test asserting the CD prompt contains the sentinel step but NO `/do:push`/`/do:pr`/`/simplify`. Deferred from this PR because it needs a carefully-designed prompt-contract change + fixture test, not a rushed flag reuse.
diff --git a/client/src/components/cos/MuseCoSAvatar.jsx b/client/src/components/cos/MuseCoSAvatar.jsx
index b50ae59d30..66f2743dc3 100644
--- a/client/src/components/cos/MuseCoSAvatar.jsx
+++ b/client/src/components/cos/MuseCoSAvatar.jsx
@@ -6,6 +6,8 @@ import { SkeletonUtils } from 'three-stdlib';
import {
AGENT_STATES,
MUSE_STATE_ANIMATIONS,
+ MUSE_STATE_SEQUENCES,
+ MUSE_IN_PLACE_SUFFIX,
MUSE_ANIMATION_FALLBACK,
MUSE_SPEAKING_GESTURE,
MUSE_ROOT_MOTION_CLIPS,
@@ -13,15 +15,18 @@ import {
import CoSAvatarOrbitControls from './CoSAvatarOrbitControls';
import CoSAvatarFrame from './CoSAvatarFrame';
import CoSBackgroundCamera from './CoSBackgroundCamera';
+import { withInPlaceClips, inPlaceClipName } from '../../utils/animationClips';
const MODEL_URL = '/api/avatar/model.glb';
const FADE = 0.35; // crossfade seconds between state loops
-// Loaded avatar wrapped in a holographic material treatment. When the GLB
-// ships animation clips (the bundled RobotExpressive default does), an
-// AnimationMixer drives the skeleton per CoS state and `speaking`; otherwise it
-// falls back to the fully-procedural rotation/glow so static GLBs still render.
-function GLBAvatar({ color, state, speaking }) {
+// Loaded avatar rendered with its own textures/materials. When the GLB ships
+// animation clips (the bundled RobotExpressive default does), an AnimationMixer
+// drives the skeleton per CoS state and `speaking`; otherwise it falls back to
+// the gentle procedural float so static GLBs still render. The per-state color
+// lives entirely in the surrounding lights/halo/glow/sparkles (see Scene) — the
+// model itself keeps its real colors rather than being tinted.
+function GLBAvatar({ state, speaking }) {
const gltf = useGLTF(MODEL_URL);
const ref = useRef();
@@ -30,44 +35,28 @@ function GLBAvatar({ color, state, speaking }) {
// leaves the mixer driving bones the rendered mesh no longer references, so
// nothing would move — the reason clips were previously ignored.
const scene = useMemo(() => SkeletonUtils.clone(gltf.scene), [gltf.scene]);
- const { actions, names, mixer } = useAnimations(gltf.animations, scene);
+ // Append the treadmill (in-place) variants of the root-motion clips so the
+ // coding montage can run/walk without drifting. Memoized on the source clips.
+ const animations = useMemo(
+ () => withInPlaceClips(gltf.animations, MUSE_ROOT_MOTION_CLIPS, MUSE_IN_PLACE_SUFFIX),
+ [gltf.animations]
+ );
+ const { actions, names, mixer } = useAnimations(animations, scene);
const hasClips = names.length > 0;
- // Materials to pulse each frame (collected once so we don't traverse the
- // whole scene graph on every frame).
- const matsRef = useRef([]);
-
- // Apply the holographic material + fit the model to the viewport ONCE per
- // scene. Keyed on [scene] only — NOT color — because the fit is an absolute
- // `setScalar`, so re-measuring the already-scaled scene on a color change
- // would reset it toward native size (the avatar would pop between two sizes
- // on every state transition) and re-allocating materials each time would
- // leak GPU resources. Replacing the material does NOT affect skinning — the
- // skeleton drives deformation regardless of the bound material, so clips
- // still animate the body. The per-state emissive hue is handled separately
- // below so this heavy pass runs just once.
+ // Fit the model to the viewport ONCE per scene (absolute `setScalar`, so it
+ // must not re-run on state changes or the avatar would pop between sizes).
+ // Keep the GLB's original materials so the model renders in full texture and
+ // color — we only flip a couple of per-mesh flags. Frustum culling is
+ // disabled because animated poses (arms out, jump, running) can exceed the
+ // bind-pose bounding box and would otherwise blink the avatar out mid-clip.
useEffect(() => {
- const mats = [];
scene.traverse((obj) => {
if (!obj.isMesh) return;
obj.castShadow = false;
obj.receiveShadow = false;
- // Animated poses (arms out, jump) can exceed the bind-pose bounding box;
- // disable frustum culling so the avatar never blinks out mid-clip.
obj.frustumCulled = false;
- const material = new THREE.MeshStandardMaterial({
- color: '#120820',
- emissiveIntensity: 0.55,
- metalness: 0.55,
- roughness: 0.35,
- transparent: true,
- opacity: 0.94,
- side: THREE.FrontSide,
- });
- obj.material = material;
- mats.push(material);
});
- matsRef.current = mats;
// Fit bounding box into a fixed height so different models render consistently.
const box = new THREE.Box3().setFromObject(scene);
@@ -81,25 +70,22 @@ function GLBAvatar({ color, state, speaking }) {
-center.y * scale + 0.05,
-center.z * scale
);
- return () => { for (const m of mats) m.dispose(); };
}, [scene]);
- // Recolor the emissive hue in place when the CoS state changes — mutate the
- // materials created above rather than re-allocating them (see the fit effect).
- useEffect(() => {
- for (const m of matsRef.current) m.emissive.set(color);
- }, [color]);
-
// --- Animation driving -------------------------------------------------
- // The base loop we should return to when idle (updated by the state effect),
- // plus a flag so a state change mid-gesture defers the crossfade to the
- // gesture's finish handler instead of fighting it.
+ // A state resolves to EITHER a single looping base clip (desiredBaseRef) or a
+ // montage that cycles clips (sequenceRef). `gestureActiveRef` defers and
+ // restores around the one-shot speaking gesture so a state change mid-gesture
+ // still lands on the latest state.
const activeRef = useRef(null); // currently-playing action
const desiredBaseRef = useRef(null); // { name, timeScale, once } to rest on
+ const sequenceRef = useRef(null); // { steps, index } | null when looping
const gestureActiveRef = useRef(false);
const speakingRef = useRef(false);
- // Crossfade the currently-active action to `clipName`.
+ // Crossfade the currently-active action to `clipName`. `once` → play a single
+ // LoopOnce and clamp; `reps` → a finite LoopRepeat that fires `finished` after
+ // N cycles (used to advance a montage); neither → an infinite base loop.
const fadeTo = useCallback((clipName, opts = {}) => {
const next = actions[clipName];
if (!next) return;
@@ -108,14 +94,43 @@ function GLBAvatar({ color, state, speaking }) {
next.enabled = true;
next.setEffectiveTimeScale(opts.timeScale ?? 1);
next.setEffectiveWeight(1);
- next.setLoop(opts.once ? THREE.LoopOnce : THREE.LoopRepeat, opts.once ? 1 : Infinity);
- next.clampWhenFinished = !!opts.once;
+ if (opts.once || opts.reps) {
+ // Finite: one shot (`once`) or N reps of a montage step. Clamp on the last
+ // frame so it holds its (near-neutral) end pose through the crossfade to
+ // the next action instead of snapping toward the bind pose.
+ next.setLoop(opts.once ? THREE.LoopOnce : THREE.LoopRepeat, opts.once ? 1 : opts.reps);
+ next.clampWhenFinished = true;
+ } else {
+ next.setLoop(THREE.LoopRepeat, Infinity);
+ next.clampWhenFinished = false;
+ }
next.fadeIn(dur).play();
const prev = activeRef.current;
if (prev && prev !== next) prev.fadeOut(dur);
activeRef.current = next;
}, [actions]);
+ // Play montage step `index` (wraps). `index` is always ≥ 0 at every call site
+ // (0, the current index, or current+1), so a plain modulo is enough. Steps
+ // were pre-filtered to present clips.
+ const playSequenceStep = useCallback((index, duration) => {
+ const seq = sequenceRef.current;
+ if (!seq || !seq.steps.length) return;
+ const i = index % seq.steps.length;
+ seq.index = i;
+ const step = seq.steps[i];
+ fadeTo(step.clip, { timeScale: step.timeScale, reps: step.reps ?? 1, duration });
+ }, [fadeTo]);
+
+ // Resume the current state's motion — the montage from `fromIndex`, or the
+ // single base loop. Both the state effect and the gesture-finish handler need
+ // this exact "sequence vs base loop" decision, so it lives in one place.
+ const resumeMotion = useCallback((fromIndex, duration) => {
+ if (sequenceRef.current) { playSequenceStep(fromIndex, duration); return; }
+ const rest = desiredBaseRef.current;
+ if (rest?.name) fadeTo(rest.name, { timeScale: rest.timeScale, once: rest.once, duration });
+ }, [fadeTo, playSequenceStep]);
+
// Resolve the base loop clip for the current state (guarded against a GLB
// that lacks the mapped clip).
const baseCfg = MUSE_STATE_ANIMATIONS[state] || {};
@@ -129,38 +144,62 @@ function GLBAvatar({ color, state, speaking }) {
return names.find((n) => !MUSE_ROOT_MOTION_CLIPS.includes(n)) || names[0];
}, [hasClips, names, baseCfg.clip]);
- // Play / crossfade the base state loop.
+ // Resolve the montage steps for the current state against the loaded clips.
+ // The step's clip is auto-routed to its in-place variant if it's a root-motion
+ // clip — so the sequence data names real GLB clips (`Running`) and the
+ // fixed-frame no-drift guarantee is enforced here, not by a naming convention.
+ // A state needs ≥2 resolvable steps to run as a montage; otherwise it falls
+ // back to its single base loop (so a GLB missing the sequence clips — or the
+ // in-place variant — still animates). Kept as a memo so the state effect's
+ // dependency is stable.
+ const sequenceSteps = useMemo(() => {
+ if (!hasClips) return null;
+ const def = MUSE_STATE_SEQUENCES[state];
+ if (!Array.isArray(def)) return null;
+ const steps = def
+ .map((s) => ({ ...s, clip: inPlaceClipName(s.clip, MUSE_ROOT_MOTION_CLIPS, MUSE_IN_PLACE_SUFFIX) }))
+ .filter((s) => names.includes(s.clip));
+ return steps.length >= 2 ? steps : null;
+ }, [hasClips, names, state]);
+
+ // Start / crossfade to the current state's motion (montage or base loop).
useEffect(() => {
if (!baseClip) return;
desiredBaseRef.current = { name: baseClip, timeScale: baseCfg.timeScale, once: baseCfg.once };
+ sequenceRef.current = sequenceSteps ? { steps: sequenceSteps, index: 0 } : null;
// Mid-gesture: don't crossfade now — the gesture's finish handler restores
- // to whatever desiredBaseRef points at, so the latest state still wins.
+ // to whatever the refs point at, so the latest state still wins.
if (gestureActiveRef.current) return;
- fadeTo(baseClip, { timeScale: baseCfg.timeScale, once: baseCfg.once });
- }, [fadeTo, baseClip, baseCfg.timeScale, baseCfg.once]);
-
- // Persistent listener: when the one-shot speaking gesture finishes, hand
- // control back to whatever base loop the current state wants (read live from
- // desiredBaseRef, so a state change mid-gesture still lands correctly). Kept
- // separate from the trigger effect below so that `speaking` flipping back to
- // false mid-gesture can't tear down the restore path — the gesture always
- // returns to a base loop instead of freezing on its end pose.
+ resumeMotion(0);
+ }, [resumeMotion, baseClip, baseCfg.timeScale, baseCfg.once, sequenceSteps]);
+
+ // Persistent `finished` listener with two jobs: (1) when the one-shot speaking
+ // gesture finishes, hand control back to the live base loop / montage (read
+ // from the refs so a state change mid-gesture still lands correctly); (2) when
+ // a finite montage step finishes, advance to the next step. Non-sequence base
+ // loops are infinite (never fire) and the clamped `sleeping` pose is ignored.
useEffect(() => {
if (!hasClips) return;
const gesture = actions[MUSE_SPEAKING_GESTURE];
const onFinished = (e) => {
- if (!gestureActiveRef.current) return;
- if (gesture && e.action !== gesture) return; // ignore base clips finishing
- gestureActiveRef.current = false;
- const rest = desiredBaseRef.current;
- if (rest?.name) fadeTo(rest.name, { timeScale: rest.timeScale, once: rest.once, duration: 0.25 });
+ if (gestureActiveRef.current) {
+ if (gesture && e.action !== gesture) return; // ignore body clips finishing
+ gestureActiveRef.current = false;
+ resumeMotion(sequenceRef.current?.index ?? 0, 0.25); // back to montage / base loop
+ return;
+ }
+ // Advance the montage when the active step completes its reps.
+ if (sequenceRef.current && e.action === activeRef.current) {
+ playSequenceStep(sequenceRef.current.index + 1);
+ }
};
mixer.addEventListener('finished', onFinished);
return () => mixer.removeEventListener('finished', onFinished);
- }, [fadeTo, hasClips, actions, mixer]);
+ }, [resumeMotion, playSequenceStep, hasClips, actions, mixer]);
// Speaking overlay: on the false→true edge, crossfade to the gesture once.
- // The persistent listener above returns to the base loop when it finishes.
+ // The persistent listener above returns to the base loop / montage when it
+ // finishes.
useEffect(() => {
if (!hasClips) return;
const was = speakingRef.current;
@@ -168,15 +207,17 @@ function GLBAvatar({ color, state, speaking }) {
if (!speaking || was) return; // only fire on the rising edge
const gesture = actions[MUSE_SPEAKING_GESTURE];
+ if (!gesture) return;
+ // Skip if a non-montage state is already resting on the gesture clip.
const base = desiredBaseRef.current;
- if (!gesture || (base && gesture === actions[base.name])) return;
+ if (!sequenceRef.current && base && gesture === actions[base.name]) return;
gestureActiveRef.current = true;
fadeTo(MUSE_SPEAKING_GESTURE, { once: true, duration: 0.2 });
}, [fadeTo, speaking, hasClips, actions]);
- // Subtle container sway + holographic emissive pulse. The clip drives the
- // body; this only adds the gentle float/glow that reads as "holographic".
+ // Subtle container float. The clip drives the body; this only adds the gentle
+ // sway/head-bob so the avatar never feels frozen between clip transitions.
useFrame(({ clock }) => {
const t = clock.getElapsedTime();
if (ref.current) {
@@ -190,16 +231,6 @@ function GLBAvatar({ color, state, speaking }) {
? Math.sin(t * 10) * 0.03
: Math.sin(t * 0.3) * 0.02;
}
-
- const intensity =
- state === 'sleeping' ? 0.2 :
- state === 'thinking' ? 0.6 + Math.sin(t * 3) * 0.3 :
- state === 'coding' ? 0.75 + Math.sin(t * 8) * 0.3 :
- state === 'investigating' ? 0.7 + Math.sin(t * 5) * 0.25 :
- state === 'ideating' ? 0.8 + Math.sin(t * 4) * 0.4 :
- 0.55;
- const mats = matsRef.current;
- for (let i = 0; i < mats.length; i++) mats[i].emissiveIntensity = intensity;
});
return (
@@ -257,11 +288,16 @@ function Scene({ state, speaking, background }) {
<>
<CoSBackgroundCamera enabled={background} z={3.3} />
- <ambientLight intensity={0.25} />
- <pointLight position={[2, 3, 4]} intensity={0.6} color={color} />
- <pointLight position={[-2, 1, 3]} intensity={0.3} color="#f472b6" />
+ {/* Neutral, even lighting so the model renders in its own full texture
+ and color. The per-state hue lives in the accent point light + halo /
+ ground glow / sparkles below rather than being painted onto the model. */}
+ <ambientLight intensity={0.7} />
+ <hemisphereLight intensity={0.55} color="#ffffff" groundColor="#3a3a52" />
+ <directionalLight position={[3, 5, 4]} intensity={1.1} />
+ <pointLight position={[2, 3, 4]} intensity={0.45} color={color} />
+ <pointLight position={[-2, 1, 3]} intensity={0.25} color="#f472b6" />
<Halo color={color} state={state} />
- <GLBAvatar color={color} state={state} speaking={speaking} />
+ <GLBAvatar state={state} speaking={speaking} />
<StateEffects color={color} state={state} />
<GroundGlow color={color} />
diff --git a/client/src/components/cos/constants.js b/client/src/components/cos/constants.js
index 0cb1a080cf..1682b6e544 100644
--- a/client/src/components/cos/constants.js
+++ b/client/src/components/cos/constants.js
@@ -86,6 +86,11 @@ export const AGENT_STATES = {
// coding = jabbing away at the work (Punch); investigating = slow side-to-side
// scan (No); reviewing = approving nod (Yes); planning = confident "locked in"
// thumbs-up (ThumbsUp); ideating = creative celebration (Dance).
+//
+// This map is the single-clip base loop for each state — also the graceful
+// fallback for any state that ALSO has a MUSE_STATE_SEQUENCES entry (below) but
+// whose GLB is missing the sequence clips. Keep every entry mapped to an
+// in-place clip; the constants test asserts none is a MUSE_ROOT_MOTION_CLIPS.
export const MUSE_STATE_ANIMATIONS = {
sleeping: { clip: 'Sitting', timeScale: 0.8, once: true },
thinking: { clip: 'Idle', timeScale: 0.85 },
@@ -96,18 +101,50 @@ export const MUSE_STATE_ANIMATIONS = {
ideating: { clip: 'Dance', timeScale: 1.0 },
};
+// Naming suffix for the neutralized "run/walk in place" clip variants that
+// MuseCoSAvatar synthesizes at load time (see `withInPlaceClips` in
+// client/src/utils/animationClips.js). This is an INTERNAL implementation
+// detail — sequences below reference real GLB clip names (`Running`) and the
+// avatar auto-routes any root-motion clip to its stripped variant. Exported
+// only so the avatar and the clip util agree on the suffix.
+export const MUSE_IN_PLACE_SUFFIX = ' (in place)';
+
+// Multi-clip montages: a state can cycle through an ordered list of clips
+// instead of looping one. Each step plays for `reps` repetitions (finite
+// LoopRepeat), then the AnimationMixer's `finished` event advances to the next
+// step, wrapping around — so `coding` reads as an energetic, varied work
+// montage (jab, sprint, leap, approve, stride, celebrate) rather than a single
+// clip on infinite repeat. Steps name real GLB clips; root-motion clips
+// (`Running`/`Walking`) are automatically routed to their neutralized in-place
+// variant by the avatar, so they can't drift the fixed frame. Steps are
+// resolved against the loaded GLB at runtime; unresolvable clips are dropped,
+// and a state whose GLB yields fewer than 2 resolvable steps falls back to its
+// MUSE_STATE_ANIMATIONS base loop.
+export const MUSE_STATE_SEQUENCES = {
+ coding: [
+ { clip: 'Punch', timeScale: 1.2, reps: 2 },
+ { clip: 'Running', timeScale: 1.1, reps: 4 },
+ { clip: 'Jump', timeScale: 1.0, reps: 1 },
+ { clip: 'ThumbsUp', timeScale: 0.95, reps: 1 },
+ { clip: 'Walking', timeScale: 1.2, reps: 4 },
+ { clip: 'Dance', timeScale: 1.0, reps: 1 },
+ ],
+};
+
// Clip used when a mapped state clip is absent from the loaded GLB.
export const MUSE_ANIMATION_FALLBACK = 'Idle';
// One-shot gesture played on the rising edge of `speaking`, then the avatar
-// returns to its base state loop.
+// returns to its base state loop (or resumes its montage).
export const MUSE_SPEAKING_GESTURE = 'Wave';
// RobotExpressive clips that carry root translation (they walk the model
// forward). Never used as a base loop for the fixed-frame avatar — the state
// map above avoids them, the constants test asserts it, and MuseCoSAvatar's
// "GLB has clips but none are mapped" fallback skips them so a custom GLB
-// whose first clip happens to be a walk cycle can't drift out of view.
+// whose first clip happens to be a walk cycle can't drift out of view. When a
+// montage step names one of these, the avatar auto-routes it to its neutralized
+// in-place variant (root-translation stripped) so it no longer drifts.
export const MUSE_ROOT_MOTION_CLIPS = ['Walking', 'Running', 'WalkJump'];
// Default messages shown when no specific event message is available
diff --git a/client/src/components/cos/constants.test.js b/client/src/components/cos/constants.test.js
index f9d723d629..acfa50a716 100644
--- a/client/src/components/cos/constants.test.js
+++ b/client/src/components/cos/constants.test.js
@@ -7,6 +7,7 @@ import {
DEFAULT_DOMAIN_MODE,
AGENT_STATES,
MUSE_STATE_ANIMATIONS,
+ MUSE_STATE_SEQUENCES,
MUSE_ANIMATION_FALLBACK,
MUSE_SPEAKING_GESTURE,
MUSE_ROOT_MOTION_CLIPS
@@ -70,6 +71,33 @@ describe('muse avatar animation triggers', () => {
});
});
+// The `coding` montage cycles several clips so the working avatar reads as
+// varied/dynamic (jab, sprint, leap, approve, stride, celebrate). Steps name
+// real GLB clips; root-motion clips are auto-routed to their neutralized
+// in-place variant by the avatar (see animationClips.test.js for that routing),
+// so the data can freely name a walk/run cycle without risking drift. These
+// invariants just keep the montage steps well-formed.
+
+describe('muse avatar state sequences (montages)', () => {
+ it('gives the coding state a montage of at least 2 steps', () => {
+ expect(Array.isArray(MUSE_STATE_SEQUENCES.coding)).toBe(true);
+ expect(MUSE_STATE_SEQUENCES.coding.length).toBeGreaterThanOrEqual(2);
+ });
+
+ it('has well-formed steps (string clip + positive integer reps when present)', () => {
+ for (const [state, steps] of Object.entries(MUSE_STATE_SEQUENCES)) {
+ expect(Array.isArray(steps), `sequence "${state}" must be an array`).toBe(true);
+ for (const step of steps) {
+ expect(typeof step.clip, `sequence "${state}" step needs a clip name`).toBe('string');
+ expect(step.clip.length).toBeGreaterThan(0);
+ if (step.reps !== undefined) {
+ expect(Number.isInteger(step.reps) && step.reps > 0, `sequence "${state}" reps must be a positive integer`).toBe(true);
+ }
+ }
+ }
+ });
+});
+
describe('getDomainMode (existing helper, sanity)', () => {
it('defaults to execute for absent/invalid config', () => {
expect(getDomainMode(undefined, 'cos')).toBe(DEFAULT_DOMAIN_MODE);
diff --git a/client/src/utils/README.md b/client/src/utils/README.md
index 83cc621750..3212a41864 100644
--- a/client/src/utils/README.md
+++ b/client/src/utils/README.md
@@ -31,6 +31,7 @@ grep -i "what you want to do" client/src/utils/README.md
| Module | Purpose |
|---|---|
+| `animationClips` | Treadmill helpers for rigged GLB clips: `withInPlaceClips` synthesizes root-translation-stripped ("in place") variants of root-motion walk/run clips so a fixed-frame avatar can't drift; `inPlaceClipName` routes a clip name to its variant. Framework-agnostic (caller passes the root-motion names + suffix). |
| `coalesce` | Trailing-edge coalescer: wraps a function so rapid calls collapse into one deferred invocation. |
| `easing` | `smoothstep` interpolation easing curve. |
| `hashString` | Deterministic string → 32-bit hash (stable colors, keys, seeds). |
diff --git a/client/src/utils/animationClips.js b/client/src/utils/animationClips.js
new file mode 100644
index 0000000000..c8cd4d3e99
--- /dev/null
+++ b/client/src/utils/animationClips.js
@@ -0,0 +1,37 @@
+// Treadmill helpers for rigged GLB animation clips.
+//
+// A "root-motion" clip (a walk/run cycle that translates the model forward)
+// drifts a fixed-frame avatar out of view. These helpers synthesize an
+// "in place" variant — the same clip with its root-translation (`.position`)
+// tracks stripped — so the gait still animates via the joint-rotation tracks
+// without translating: the classic treadmill technique.
+//
+// Pure and framework-agnostic: they operate on any AnimationClip-shaped object
+// ({ name, tracks, clone() }), so the caller supplies the set of root-motion
+// clip names and the naming suffix rather than this module importing them.
+// Consumed by the CoS Muse avatar (client/src/components/cos/MuseCoSAvatar.jsx).
+
+// Route a clip name to its in-place variant: root-motion clips become
+// `${name}${suffix}`, everything else is returned unchanged. Used both to name
+// the synthesized variant and to look it up when resolving a montage step, so
+// callers never hand-decorate clip names.
+export function inPlaceClipName(name, rootMotionNames, suffix) {
+ return rootMotionNames.includes(name) ? `${name}${suffix}` : name;
+}
+
+// Return `clips` plus an in-place variant of each root-motion clip. Originals
+// are left untouched (they are typically shared from a loader cache); each
+// variant is a clone renamed via `inPlaceClipName` with its `.position` tracks
+// removed. A non-array input yields `[]`.
+export function withInPlaceClips(clips, rootMotionNames, suffix) {
+ if (!Array.isArray(clips)) return [];
+ const out = clips.slice();
+ for (const clip of clips) {
+ if (!rootMotionNames.includes(clip.name)) continue;
+ const inPlace = clip.clone();
+ inPlace.name = inPlaceClipName(clip.name, rootMotionNames, suffix);
+ inPlace.tracks = inPlace.tracks.filter((t) => !t.name.endsWith('.position'));
+ out.push(inPlace);
+ }
+ return out;
+}
diff --git a/client/src/utils/animationClips.test.js b/client/src/utils/animationClips.test.js
new file mode 100644
index 0000000000..37c3355b99
--- /dev/null
+++ b/client/src/utils/animationClips.test.js
@@ -0,0 +1,55 @@
+import { describe, it, expect } from 'vitest';
+import * as THREE from 'three';
+import { inPlaceClipName, withInPlaceClips } from './animationClips.js';
+
+const ROOT = ['Walking', 'Running', 'WalkJump'];
+const SUFFIX = ' (in place)';
+
+// Build a minimal AnimationClip with a root-translation position track plus a
+// joint-rotation (quaternion) track, so we can assert only the position track
+// is stripped from the in-place variant.
+function makeClip(name) {
+ const posTrack = new THREE.VectorKeyframeTrack('Body.position', [0, 1], [0, 0, 0, 0, 0, 2]);
+ const quatTrack = new THREE.QuaternionKeyframeTrack('Leg.quaternion', [0, 1], [0, 0, 0, 1, 0, 1, 0, 0]);
+ return new THREE.AnimationClip(name, 1, [posTrack, quatTrack]);
+}
+
+describe('inPlaceClipName', () => {
+ it('routes root-motion clips to the suffixed variant, leaves others unchanged', () => {
+ expect(inPlaceClipName('Running', ROOT, SUFFIX)).toBe('Running (in place)');
+ expect(inPlaceClipName('Punch', ROOT, SUFFIX)).toBe('Punch');
+ });
+});
+
+describe('withInPlaceClips', () => {
+ it('returns [] for a non-array input', () => {
+ expect(withInPlaceClips(undefined, ROOT, SUFFIX)).toEqual([]);
+ });
+
+ it('appends an in-place variant per root-motion clip, keeps originals', () => {
+ const clips = [makeClip('Running'), makeClip('Punch')];
+ const out = withInPlaceClips(clips, ROOT, SUFFIX);
+ const names = out.map((c) => c.name);
+ // Both originals survive, plus one variant for the root-motion clip only.
+ expect(names).toContain('Running');
+ expect(names).toContain('Punch');
+ expect(names).toContain('Running (in place)');
+ expect(names).not.toContain('Punch (in place)');
+ expect(out.length).toBe(3);
+ });
+
+ it('strips only the .position tracks from the variant (treadmill), leaving joint tracks', () => {
+ const [variant] = withInPlaceClips([makeClip('Running')], ROOT, SUFFIX).filter((c) => c.name.endsWith(SUFFIX));
+ const trackNames = variant.tracks.map((t) => t.name);
+ expect(trackNames).toContain('Leg.quaternion');
+ expect(trackNames).not.toContain('Body.position');
+ });
+
+ it('does not mutate the original clip', () => {
+ const original = makeClip('Running');
+ const before = original.tracks.length;
+ withInPlaceClips([original], ROOT, SUFFIX);
+ expect(original.name).toBe('Running');
+ expect(original.tracks.length).toBe(before);
+ });
+});
diff --git a/client/src/utils/index.js b/client/src/utils/index.js
index 74dcb5b3ae..ae3c2ccf2d 100644
--- a/client/src/utils/index.js
+++ b/client/src/utils/index.js
@@ -16,6 +16,7 @@ export * from './timeWindow.js';
export * from './timezone.js';
// === General pure helpers ===
+export * from './animationClips.js';
export * from './coalesce.js';
export * from './easing.js';
export * from './hashString.js';
diff --git a/data.reference/avatar/README.md b/data.reference/avatar/README.md
index ec3af938e8..92fd37e358 100644
--- a/data.reference/avatar/README.md
+++ b/data.reference/avatar/README.md
@@ -19,23 +19,42 @@ It ships 14 animation clips — `Idle`, `Walking`, `Running`, `Dance`, `Death`,
MuseCoSAvatar drives these clips from the CoS runtime via an `AnimationMixer`,
mapping each agent state to an **in-place** clip (see `MUSE_STATE_ANIMATIONS` in
`client/src/components/cos/constants.js`). `Walking` / `Running` / `WalkJump`
-carry root translation and are intentionally left unmapped so the fixed-frame
+carry root translation and are never used as a base loop so the fixed-frame
avatar can't drift out of view. The `speaking` flag fires a one-shot `Wave`
-overlay that returns to the base state loop.
+overlay that returns to the base loop (or resumes the montage).
+
+The model is rendered with its **own textures and full color** — the per-state
+hue lives in the surrounding lights, halo, ground glow, and sparkles, not as a
+tint painted onto the mesh.
| CoS state | Clip | Read |
|-----------|------|------|
| sleeping | `Sitting` | seated rest (clamped on final frame) |
| thinking | `Idle` | calm contemplation |
-| coding | `Punch` | jabbing away at the work |
+| coding | _montage_ | varied working sequence (see below) |
| investigating | `No` | slow side-to-side scan |
| reviewing | `Yes` | approving nod |
| planning | `ThumbsUp` | confident "locked in" |
| ideating | `Dance` | creative celebration |
| _speaking_ | `Wave` | one-shot gesture, then back to base loop |
+### `coding` montage
+
+Rather than looping a single clip, the `coding` state cycles an ordered montage
+(`MUSE_STATE_SEQUENCES.coding`) so a working agent reads as dynamic and varied:
+**Punch → Running → Jump → ThumbsUp → Walking → Dance**, then repeats. Each step
+plays for a set number of repetitions before the mixer's `finished` event
+advances to the next.
+
+The montage names real GLB clips. `Running` / `Walking` carry root translation,
+so the avatar auto-routes them to synthesized **"in place"** variants — cloned
+clips with their root-translation (`.position`) tracks stripped (the treadmill
+technique, in `client/src/utils/animationClips.js`) — so the gait animates
+without drifting the fixed frame. A GLB missing the montage clips falls back to
+the single-clip base loop (`MUSE_STATE_ANIMATIONS.coding` = `Punch`).
+
A GLB with none of these clips (or no clips at all) falls back to the
-procedural rotation/glow treatment, so static models still render.
+procedural float treatment, so static models still render.
## Selectable variants