Skip to content

Commit b01a1c9

Browse files
DavidLiedleclaude
andcommitted
fix: ID and FITNESS shims for browser mesh
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1855f24 commit b01a1c9

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

web/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@
467467
// Self unit always gets passive energy regen regardless of chatter or unit count.
468468
mesh.units[0].energy = Math.min(mesh.units[0].energy + 1, mesh.units[0].energyMax);
469469
mesh.units[0].energyEarned += 1;
470+
// Sync JS-side fitness into each unit's Forth VM.
471+
for (const u of mesh.units) {
472+
u.vm.eval(u.fitness + ' BROWSER-FITNESS !');
473+
}
470474
if (!chatterOn || mesh.units.length < 2) return;
471475
mesh._updatePeerCounts();
472476
autoIdx = ((autoIdx) % (mesh.units.length - 1)) + 1;

web/unit.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ class BrowserMesh {
106106
vm.eval(': SHARE-ALL ." (no mesh peers to share with)" CR ;');
107107
vm.eval(': DREAM ." dreaming..." CR REFLECT INVENT-STRATEGY COMPOSE-ROUTINE SMART-MUTATE IF ." evolved." CR ELSE ." held steady." CR THEN MUTATION-REPORT PEER-COUNT 0 > IF TEACH THEN ." waking. I am changed." CR ;');
108108
// Sync native mesh primitives with browser mesh state.
109-
vm.eval(`: ID-STR S" ${id}" ;`);
110-
vm.eval(': ID ID-STR ;');
109+
vm.eval(': ID ." ' + id + '" ;');
111110
vm.eval('VARIABLE BROWSER-FITNESS 0 BROWSER-FITNESS !');
112111
vm.eval(': FITNESS BROWSER-FITNESS @ ;');
113112
vm.eval(': PEERS PEER-COUNT ;');
114-
// Re-eval prelude words that use ID and FITNESS so they pick up the new definitions.
115-
vm.eval(': FAMILY ." id: " ID TYPE ." gen: " GENERATION . ." children: " CHILD-COUNT . CR ;');
116-
vm.eval(': HELLO ." Hi! I\'m unit " ID TYPE ." , generation " GENERATION . ." with " PEER-COUNT . ." peers and fitness " FITNESS . CR ;');
117-
vm.eval(': MESH-HELLO ." Mesh node " ID TYPE ." gen=" GENERATION . ." peers=" PEER-COUNT . ." fitness=" FITNESS . CR ;');
113+
// Re-eval prelude words that use ID so they pick up the new definition.
114+
// ID now uses ." so it prints directly — no TYPE needed.
115+
vm.eval(': FAMILY ." id: " ID ." gen: " GENERATION . ." children: " CHILD-COUNT . CR ;');
116+
vm.eval(': HELLO ." Hi! I\'m unit " ID ." , generation " GENERATION . ." with " PEER-COUNT . ." peers and fitness " FITNESS . CR ;');
117+
vm.eval(': MESH-HELLO ." Mesh node " ID ." gen=" GENERATION . ." peers=" PEER-COUNT . ." fitness=" FITNESS . CR ;');
118118
vm.eval(': PROUD ." fitness: " FITNESS . ." | generation: " GENERATION . ." | children: " CHILD-COUNT . CR ;');
119-
vm.eval(': ROLL-CALL ." === roll call ===" CR ." self: " ID TYPE ." fitness=" FITNESS . CR LEADERBOARD ;');
119+
vm.eval(': ROLL-CALL ." === roll call ===" CR ." self: " ID ." fitness=" FITNESS . CR LEADERBOARD ;');
120120
// Platform-limited words: give informative messages instead of silent failure.
121121
vm.eval(': SLEEP DROP ." sleep not available in browser" CR ;');
122122
vm.eval(': SPAWN ." spawn handled by browser mesh -- use the spawn button" CR ;');

0 commit comments

Comments
 (0)