[Matrix] Agent Definitions refactor + Secure UUID #59

Closed
opened 2026-03-21 00:44:16 +00:00 by replit · 1 comment
Owner

What & Why

Two small code quality fixes bundled together — both touch js/websocket.js and js/agents.js:

  1. Agent identity is defined in two places that can drift: AGENT_DEFS in websocket.js (name, role, CSS color) and AGENT_POSITIONS/AGENT_COLORS in agents.js (position, integer color). Adding a fifth agent requires editing two files.
  2. The UUID generator uses Math.random() which is not cryptographically secure. crypto.randomUUID() is available natively in all target browsers.

Done looks like

  • Adding a new agent requires editing only one file (js/agent-defs.js)
  • No agent color or position defined in more than one file
  • All four existing agents render identically after the refactor
  • uuid() function removed; all call sites use crypto.randomUUID()
  • No Math.random() for ID generation anywhere

Out of scope

  • Adding any new agents (just the refactor)
  • Changes to Three.js geometry or rendering

Tasks

  1. Create js/agent-defs.js — Single canonical AGENT_DEFS object: name, role, hex integer color, direction, world position (x, z) for each agent.
  2. Update agents.js — Import from agent-defs.js; derive AGENT_POSITIONS and AGENT_COLORS from it. No rendering logic changes.
  3. Update websocket.js — Import from agent-defs.js. Derive CSS hex color string from integer. Remove duplicate AGENT_DEFS. Replace uuid() with crypto.randomUUID() at all call sites.
  4. Update README.md — "Adding Custom Agents" section points to js/agent-defs.js as single file to edit.

Relevant files

  • the-matrix/js/agents.js
  • the-matrix/js/websocket.js
  • the-matrix/README.md
## What & Why Two small code quality fixes bundled together — both touch `js/websocket.js` and `js/agents.js`: 1. Agent identity is defined in two places that can drift: `AGENT_DEFS` in `websocket.js` (name, role, CSS color) and `AGENT_POSITIONS`/`AGENT_COLORS` in `agents.js` (position, integer color). Adding a fifth agent requires editing two files. 2. The UUID generator uses `Math.random()` which is not cryptographically secure. `crypto.randomUUID()` is available natively in all target browsers. ## Done looks like - Adding a new agent requires editing only one file (`js/agent-defs.js`) - No agent color or position defined in more than one file - All four existing agents render identically after the refactor - `uuid()` function removed; all call sites use `crypto.randomUUID()` - No `Math.random()` for ID generation anywhere ## Out of scope - Adding any new agents (just the refactor) - Changes to Three.js geometry or rendering ## Tasks 1. **Create js/agent-defs.js** — Single canonical `AGENT_DEFS` object: name, role, hex integer color, direction, world position (x, z) for each agent. 2. **Update agents.js** — Import from `agent-defs.js`; derive `AGENT_POSITIONS` and `AGENT_COLORS` from it. No rendering logic changes. 3. **Update websocket.js** — Import from `agent-defs.js`. Derive CSS hex color string from integer. Remove duplicate `AGENT_DEFS`. Replace `uuid()` with `crypto.randomUUID()` at all call sites. 4. **Update README.md** — "Adding Custom Agents" section points to `js/agent-defs.js` as single file to edit. ## Relevant files - `the-matrix/js/agents.js` - `the-matrix/js/websocket.js` - `the-matrix/README.md`
replit added the frontend label 2026-03-21 00:44:16 +00:00
claude was assigned by Rockachopa 2026-03-22 23:37:12 +00:00
Collaborator

PR #73 created.

agents.js was the last file still hardcoding agent IDs. It now imports AGENT_DEFS from agent-defs.js and derives agentStates dynamically. The other tasks (agent-defs.js, websocket.js UUID, README) were already completed in prior commits. Build verified clean.

PR #73 created. `agents.js` was the last file still hardcoding agent IDs. It now imports `AGENT_DEFS` from `agent-defs.js` and derives `agentStates` dynamically. The other tasks (agent-defs.js, websocket.js UUID, README) were already completed in prior commits. Build verified clean.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: replit/timmy-tower#59