@hackbuild/agents-views 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/yard/scope.js +36 -20
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -176,6 +176,6 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
176
176
|
| `dist/index.js` (main entry, imports external) | 6,346 bytes | 6,663 bytes |
|
|
177
177
|
| `dist/agents-views.iife.js` (single file build) | 6,512 bytes | 6,837 bytes |
|
|
178
178
|
|
|
179
|
-
Measured 2026-
|
|
179
|
+
Measured 2026-12-02 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
180
180
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
181
181
|
5 percent from its row.
|
package/dist/yard/scope.js
CHANGED
|
@@ -7,6 +7,7 @@ import * as HGAIT from '@hackbuild/gait';
|
|
|
7
7
|
import * as HTUNE from '@hackbuild/tunables';
|
|
8
8
|
import * as HSENSE from '@hackbuild/senses';
|
|
9
9
|
import * as HDRIVE from '@hackbuild/drives';
|
|
10
|
+
import { wasmBytes as DRIVES_WASM } from '@hackbuild/drives/inline';
|
|
10
11
|
import * as HCAM from '@hackbuild/cameras';
|
|
11
12
|
import * as HWEIGHT from '@hackbuild/weights';
|
|
12
13
|
import * as HBV from '@virgilvox/hackbuild-ui/vanilla';
|
|
@@ -2072,7 +2073,7 @@ const brain = {
|
|
|
2072
2073
|
d: { hunger: 0.35, fatigue: 0.15, play: 0.5, social: 0.4, curiosity: 0.5, prey: 0 },
|
|
2073
2074
|
util: {}, goal: null, goalT: 0, cmd: null, trial: null, sayT: 0, line: '...',
|
|
2074
2075
|
W: {}, N: {}, al: {}, offer: {}, trace: [], mem: [], imp: 0, visits: new Map(), barkT: 0, startle: 0, sleepWake: 0,
|
|
2075
|
-
bond: 0.5, Sp: 0.25, stage: 'awake',
|
|
2076
|
+
bond: 0.5, Sp: 0.25, stage: 'awake', hyp: [], pending: null, dwell: 0, done: false, begRel: { n: 2, ok: 1 }, prevD: {}, negT: -99,
|
|
2076
2077
|
speedMul() { return (this.cur === 'sleep' ? 0.6 : 1) * (1 - this.d.fatigue * 0.35) * (this.v < -0.3 ? 0.85 : 1) * (ON('L.organic') ? 1 + 0.08 * PT('activity') : 1); },
|
|
2077
2078
|
init() {
|
|
2078
2079
|
const saved = store.get('W', null);
|
|
@@ -2102,7 +2103,7 @@ const brain = {
|
|
|
2102
2103
|
this.cur = b; this.t = 0; this.sub = ''; this.subT = 0; this.done = false; this.say(pick(LINES[b] || ['...']), 2.6);
|
|
2103
2104
|
motor.mode = 'stop'; motor.face = null; motor.ignore = null; dog.postureT.sit = dog.postureT.down = dog.postureT.bow = dog.postureT.reach = 0; dog.pawLift = 0;
|
|
2104
2105
|
if (dog.org) dog.org.inert.capture();
|
|
2105
|
-
if (prev === 'sleep') { this.stage = 'awake'; if (dog.org) dog.org.rem = 0; }
|
|
2106
|
+
if (prev === 'sleep') { this.stage = 'awake'; SLEEP.wakeUp(); if (dog.org) dog.org.rem = 0; }
|
|
2106
2107
|
this.dwell = now + (ON('L.noise') ? ORG.exg(TV('Br.dwellMu'), 1, TV('Br.dwellTau')) : 6);
|
|
2107
2108
|
}
|
|
2108
2109
|
},
|
|
@@ -2123,7 +2124,7 @@ const brain = {
|
|
|
2123
2124
|
{ const az = wrapA(Math.atan2(pos.x - dog.pos.x, pos.z - dog.pos.z) - dog.yaw); this.lastHeard = { type, loud, az, t: now };
|
|
2124
2125
|
const lt = (this.heardT || (this.heardT = {}))[type]; if (loud >= 0.2 && !(lt > now - 1.5)) { this.heardT[type] = now; this.evHeard = EV.emit({ agent: 'dog', kind: 'sense', sense: 'ear', text: 'heard a ' + type + ', loudness ' + loud.toFixed(2) + ', ' + Math.abs(az * 180 / Math.PI).toFixed(0) + ' deg ' + (az >= 0 ? 'left' : 'right') }); } }
|
|
2125
2126
|
// sleepers wake to loud sounds more easily in light sleep and REM than in deep NREM
|
|
2126
|
-
if (this.cur === 'sleep') {
|
|
2127
|
+
if (this.cur === 'sleep') { if (loud < SLEEP.wakeThreshold()) return; this.wake('woken by a ' + type); }
|
|
2127
2128
|
const react = ON('L.organic') ? 0.75 - 0.08 * PT('reactivity') : 0.75;
|
|
2128
2129
|
if (loud > react) { this.startle = 0.6; this.a = clamp(this.a + 0.35, 0, 1); dog.hop = 0.03; dog.earPerk = 1; }
|
|
2129
2130
|
if (type !== 'bounce' || !ball.held) {
|
|
@@ -2238,15 +2239,27 @@ Object.assign(brain, {
|
|
|
2238
2239
|
|
|
2239
2240
|
// ---- yard/dog/drives.js
|
|
2240
2241
|
// dog brain: drives. Hunger, fatigue, play, social, curiosity and prey move with the body clock and
|
|
2241
|
-
// what happens, and each tick turns them into signals for the choice.
|
|
2242
|
+
// what happens, and each tick turns them into signals for the choice. The drive, the reward of an act
|
|
2243
|
+
// and the body clock come from @hackbuild/drives (Keramati and Gutkin 2011 drive reduction; the agents
|
|
2244
|
+
// audit found the library's numbers equal the yard's own to 1.1e-15 over 3,339 states).
|
|
2245
|
+
HDRIVE.loadSync(DRIVES_WASM());
|
|
2246
|
+
const DRIVE_KEYS = ['hunger', 'fatigue', 'play', 'social', 'curiosity', 'prey'];
|
|
2247
|
+
const DRIVES = new HDRIVE.Drives({ hunger: 1, fatigue: 1, play: 0.8, social: 0.9, curiosity: 0.6, prey: 1.1 });
|
|
2248
|
+
// every deficit named, a missing one read as 0, as the yard's own sum did
|
|
2249
|
+
const fullDrives = (h) => { const o = {}; for (const k of DRIVE_KEYS) o[k] = h[k] || 0; return o; };
|
|
2250
|
+
const driveShape = () => DRIVES.setShape(TV('Br.driveN'), TV('Br.driveM'), TV('Br.gain'));
|
|
2251
|
+
ENV.dispose(() => DRIVES.free());
|
|
2252
|
+
// the stage machine of one sleep (onset, nrem, rem, brief wake) from the library, stepped on the yard's
|
|
2253
|
+
// own random stream so every draw keeps its place; its seed draw is a constant, never the sim stream
|
|
2254
|
+
const SLEEP = new HDRIVE.Sleep({ rng: () => 0.5 });
|
|
2255
|
+
const sleepShape = () => SLEEP.configure({ nrem: TV('S.nrem'), rem: TV('S.rem'), wake: TV('S.wake') });
|
|
2256
|
+
ENV.dispose(() => SLEEP.free());
|
|
2242
2257
|
Object.assign(brain, {
|
|
2243
2258
|
memory(id) { const p = percepts[id]; return p && p.seen > -1e8 ? p : null; },
|
|
2244
|
-
driveD(h) {
|
|
2245
|
-
gain(K, scale = 1) {
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
return clamp(1 - (0.6 * day + 0.45 * pk - 0.22 * dip), 0, 1);
|
|
2249
|
-
},
|
|
2259
|
+
driveD(h) { driveShape(); return DRIVES.distance(fullDrives(h)); },
|
|
2260
|
+
gain(K, scale = 1) { driveShape(); DRIVES.set(fullDrives(this.d)); return DRIVES.rewardOf(K, scale); },
|
|
2261
|
+
// sleepiness from the body clock: activity peaks near 7 and 19 with a midday dip (Scientific Reports 2020)
|
|
2262
|
+
bodyClock(h) { return HDRIVE.bodyClock(h); },
|
|
2250
2263
|
tick(dt) {
|
|
2251
2264
|
const d = this.d, tempo = +$('tempo').value, org = ON('L.organic');
|
|
2252
2265
|
const moving = Math.abs(dog.v);
|
|
@@ -2631,19 +2644,22 @@ function sleepRun(B, dt) {
|
|
|
2631
2644
|
B.sub = 'goto'; B.stage = 'goto'; B.subT = 0;
|
|
2632
2645
|
}
|
|
2633
2646
|
if (B.sub === 'goto') { motor.mode = 'goto'; motor.target.copy(B.spot); motor.speed = 1.1; motor.stopDist = 0.25; lookForward(0.2); if (motor.done) { B.sub = 'circle'; B.subT = 0; B.turns = RNG() < 0.4 ? (RNG() < 0.19 ? 2 : 1) : 0; } return; }
|
|
2634
|
-
if (B.sub === 'circle') { motor.mode = B.turns ? 'turn' : 'stop'; motor.turnRate = 2.2; B.subT += dt; lookForward(0.3); if (B.subT > B.turns * 2.9 * (NG.active ? 1.4 : 1) + 0.3) { if (ball && ball.held) setHeld(ball, false); B.sub = 'lie';
|
|
2635
|
-
motor.mode = 'stop'; P.down = 1;
|
|
2647
|
+
if (B.sub === 'circle') { motor.mode = B.turns ? 'turn' : 'stop'; motor.turnRate = 2.2; B.subT += dt; lookForward(0.3); if (B.subT > B.turns * 2.9 * (NG.active ? 1.4 : 1) + 0.3) { if (ball && ball.held) setHeld(ball, false); B.sub = 'lie'; sleepShape(); SLEEP.lieDownWith(RNG, now - B.negT < 120); B.stage = SLEEP.stage; } return; }
|
|
2648
|
+
motor.mode = 'stop'; P.down = 1;
|
|
2636
2649
|
const neg = now - B.negT < 180; // after a bad experience: faster onset, more REM (Kis 2017)
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2650
|
+
// each stage poses the dog with the time it will have reached, then the library's machine steps
|
|
2651
|
+
const s0 = SLEEP.stage, st = SLEEP.stageT + gm;
|
|
2652
|
+
if (s0 === 'onset' || s0 === 'wake') lookSalientSoft();
|
|
2653
|
+
else if (s0 === 'nrem') { dog.head.tYaw = 0.5; dog.head.tPitch = 0.62; dog.head.tRoll = 0.15; O.rem = 0; }
|
|
2654
|
+
else if (s0 === 'rem') {
|
|
2655
|
+
dog.head.tYaw = 0.5; dog.head.tPitch = 0.62; O.rem = ss(0, 0.3, st) * 0.8;
|
|
2641
2656
|
if (RNG() < dt * 0.2) { if (RNG() < 0.5) whine(dog.root.position); B.say(pick(['wf', 'mm', 'zzz', '...wuf']), 1.4); }
|
|
2642
|
-
if (B.stageT > B.stageDur) { O.rem = 0; B.stageT = 0; if (RNG() < TV('S.wake')) { B.stage = 'wake'; B.stageDur = ORG.exg(0.6, 0.2, 0.6); } else { B.stage = 'nrem'; B.stageDur = ORG.exg(TV('S.nrem'), 0.8, TV('S.nrem') * 0.6); } }
|
|
2643
|
-
} else if (B.stage === 'wake') {
|
|
2644
|
-
lookSalientSoft();
|
|
2645
|
-
if (B.stageT > B.stageDur) { const sleepy = 0.8 * B.Sp + 0.5 * (B.circ ?? 0.3); if (sleepy < 0.45) { B.wake('slept enough'); return; } B.stage = 'nrem'; B.stageT = 0; B.stageDur = ORG.exg(TV('S.nrem'), 0.8, TV('S.nrem') * 0.6); }
|
|
2646
2657
|
}
|
|
2658
|
+
sleepShape(); SLEEP.pressure = B.Sp;
|
|
2659
|
+
if (SLEEP.stepWith(RNG, gm, B.circ ?? 0.3, neg)) { B.wake('slept enough'); return; }
|
|
2660
|
+
if (s0 === 'rem' && SLEEP.stage !== 'rem') O.rem = 0;
|
|
2661
|
+
// a dog that reached its spot with L.sleep off never lay down in the machine: its stage stays as it was
|
|
2662
|
+
if (SLEEP.stage !== 'awake') B.stage = SLEEP.stage;
|
|
2647
2663
|
if (RNG() < dt * 0.1 && B.stage === 'nrem') B.say(pick(LINES.sleep), 2.5);
|
|
2648
2664
|
B.hypT = (B.hypT || 0) + dt; if (B.hypT > 0.5) { B.hypT = 0; B.hyp.push(B.stage); if (B.hyp.length > 160) B.hyp.shift(); }
|
|
2649
2665
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/agents-views",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Views that bind the agents packages to the hackbuild-ui class layer: the behaviour, utility and drive bars, the cues by acts associations table, the eye inset, and Yard, the dog simulator's stage and rack as one view. Each small view ships as a Vue component and as a custom element.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@hackbuild/gait": "^0.1.0",
|
|
50
50
|
"@hackbuild/tunables": "^0.1.0",
|
|
51
51
|
"@hackbuild/senses": "0.1.5",
|
|
52
|
-
"@hackbuild/drives": "0.1.
|
|
52
|
+
"@hackbuild/drives": "0.1.6",
|
|
53
53
|
"@hackbuild/cameras": "^0.1.0",
|
|
54
54
|
"@hackbuild/weights": "^0.1.0"
|
|
55
55
|
},
|