@hackbuild/agents-views 0.2.11 → 0.2.13

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 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-12-02 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
179
+ Measured 2026-12-03 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.
@@ -2073,7 +2073,7 @@ const brain = {
2073
2073
  d: { hunger: 0.35, fatigue: 0.15, play: 0.5, social: 0.4, curiosity: 0.5, prey: 0 },
2074
2074
  util: {}, goal: null, goalT: 0, cmd: null, trial: null, sayT: 0, line: '...',
2075
2075
  W: {}, N: {}, al: {}, offer: {}, trace: [], mem: [], imp: 0, visits: new Map(), barkT: 0, startle: 0, sleepWake: 0,
2076
- bond: 0.5, Sp: 0.25, stage: 'awake', stageT: 0, stageDur: 0, hyp: [], pending: null, dwell: 0, done: false, begRel: { n: 2, ok: 1 }, prevD: {}, negT: -99,
2076
+ bond: 0.5, Sp: 0.25, stage: 'awake', hyp: [], pending: null, dwell: 0, done: false, begRel: { n: 2, ok: 1 }, prevD: {}, negT: -99,
2077
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); },
2078
2078
  init() {
2079
2079
  const saved = store.get('W', null);
@@ -2103,8 +2103,8 @@ const brain = {
2103
2103
  this.cur = b; this.t = 0; this.sub = ''; this.subT = 0; this.done = false; this.say(pick(LINES[b] || ['...']), 2.6);
2104
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;
2105
2105
  if (dog.org) dog.org.inert.capture();
2106
- if (prev === 'sleep') { this.stage = 'awake'; if (dog.org) dog.org.rem = 0; }
2107
- this.dwell = now + (ON('L.noise') ? ORG.exg(TV('Br.dwellMu'), 1, TV('Br.dwellTau')) : 6);
2106
+ if (prev === 'sleep') { this.stage = 'awake'; SLEEP.wakeUp(); if (dog.org) dog.org.rem = 0; }
2107
+ chooseShape(); CHOOSE.setWith(RNG, b, now); this.dwell = CHOOSE.dwellUntil;
2108
2108
  }
2109
2109
  },
2110
2110
  stimulus(kind, s = 1) {
@@ -2124,7 +2124,7 @@ const brain = {
2124
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 };
2125
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') }); } }
2126
2126
  // sleepers wake to loud sounds more easily in light sleep and REM than in deep NREM
2127
- if (this.cur === 'sleep') { const thr = this.stage === 'nrem' ? 0.75 : 0.45; if (loud < thr) return; this.wake('woken by a ' + type); }
2127
+ if (this.cur === 'sleep') { if (loud < SLEEP.wakeThreshold()) return; this.wake('woken by a ' + type); }
2128
2128
  const react = ON('L.organic') ? 0.75 - 0.08 * PT('reactivity') : 0.75;
2129
2129
  if (loud > react) { this.startle = 0.6; this.a = clamp(this.a + 0.35, 0, 1); dog.hop = 0.03; dog.earPerk = 1; }
2130
2130
  if (type !== 'bounce' || !ball.held) {
@@ -2249,6 +2249,11 @@ const DRIVES = new HDRIVE.Drives({ hunger: 1, fatigue: 1, play: 0.8, social: 0.9
2249
2249
  const fullDrives = (h) => { const o = {}; for (const k of DRIVE_KEYS) o[k] = h[k] || 0; return o; };
2250
2250
  const driveShape = () => DRIVES.setShape(TV('Br.driveN'), TV('Br.driveM'), TV('Br.gain'));
2251
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());
2252
2257
  Object.assign(brain, {
2253
2258
  memory(id) { const p = percepts[id]; return p && p.seen > -1e8 ? p : null; },
2254
2259
  driveD(h) { driveShape(); return DRIVES.distance(fullDrives(h)); },
@@ -2329,7 +2334,16 @@ Object.assign(brain, {
2329
2334
 
2330
2335
  // ---- yard/dog/choice.js
2331
2336
  // dog brain: choice. Each behaviour gets a utility from drives, percepts and learning; the choice keeps
2332
- // one long enough to finish, and records why.
2337
+ // one long enough to finish, and records why. The sampled choice, its dwell and its latencies are the
2338
+ // library's Chooser, stepped on the yard's stream (RNG) so the draw order stays; the yard keeps its
2339
+ // pending switch (it also carries the cue's go function and where the head looks) and the canned
2340
+ // argmax path, whose line is drawn before its dwell.
2341
+ const CHOOSE = new HDRIVE.Chooser({ rng: () => 0.5, options: BEH });
2342
+ ENV.dispose(() => CHOOSE.free());
2343
+ const chooseShape = () => CHOOSE.configure({
2344
+ temperature: TV('Br.temp'), commitment: TV('Br.commit') * (1 + 0.35 * PT('independence')), dwellMu: TV('Br.dwellMu'), dwellTau: TV('Br.dwellTau'),
2345
+ reactMu: TV('Br.reactMu'), reactTau: TV('Br.reactTau'), reactScale: 1 - 0.12 * PT('reactivity'), sample: ON('L.sample'), noise: ON('L.noise'),
2346
+ });
2333
2347
  Object.assign(brain, {
2334
2348
  utilities() {
2335
2349
  const U = this.util, d = this.d, org = ON('L.organic');
@@ -2391,25 +2405,18 @@ Object.assign(brain, {
2391
2405
  if (this.pending) { if (now >= this.pending.at) { const p = this.pending; this.pending = null; if (p.fn) p.fn(); else { this.kindNext = p.kind; this.causeNext = p.ev; this.set(p.b, p.why); } } return; }
2392
2406
  let best = 'idle', bv = -1; for (const b of BEH) if (U[b] > bv) { bv = U[b]; best = b; }
2393
2407
  if (!ON('L.sample')) { U[this.cur] += 0.12; if (U[this.cur] >= bv) best = this.cur; if (best !== this.cur) { this.lastChoice = { at: now, U: Object.assign({}, U), cur: this.cur, best, picked: best, path: 'argmax' }; this.kindNext = 'top'; this.causeNext = this.choiceEv(best, whyOf(best), 'top'); this.set(best, whyOf(best)); } return; }
2394
- const commit = TV('Br.commit') * (1 + 0.35 * PT('independence'));
2395
- const curU = U[this.cur] + (this.done ? -1 : commit);
2396
- const lat = mul => ON('L.noise') ? ORG.exg(TV('Br.reactMu') * mul * (1 - 0.12 * PT('reactivity')), 0.06, TV('Br.reactTau') * mul) : 0;
2397
- // react: something much better that cannot wait starts after a short heavy tailed latency, while the head already turns to it
2398
- if (best !== this.cur && bv > curU + 0.05 && (REACTIVE.has(best) || (this.forced && this.forced.b === best && this.forced.until > now))) {
2399
- this.pending = { b: best, why: whyOf(best), at: now + lat(1), look: this.causeOf(best) };
2400
- { const P = this.pending, kind = this.forced && this.forced.b === best && this.forced.until > now ? 'forced' : 'react'; P.kind = kind; this.lastChoice = { at: now, U: Object.assign({}, U), cur: this.cur, curU, commit, best, picked: best, path: 'react', lat: P.at - now }; P.ev = this.choiceEv(best, P.why, kind, P.at - now); }
2401
- return;
2402
- }
2403
- // otherwise choose only when the current act is done or its dwell ran out: sample, so the best option usually but not always wins
2404
- if (this.done || now > this.dwell) {
2405
- const T = TV('Br.temp'), ex = BEH.map(b => [b, Math.exp(((b === this.cur ? curU : U[b]) - bv) / T)]);
2406
- let tot = ex.reduce((s, x) => s + x[1], 0), r = RNG() * tot, pickB = best; for (const [b, w] of ex) if ((r -= w) <= 0) { pickB = b; break; }
2407
- this.dwell = now + ORG.exg(TV('Br.dwellMu'), 1, TV('Br.dwellTau'));
2408
- if (pickB !== this.cur) this.pending = { b: pickB, why: whyOf(pickB) + (pickB !== best ? ', took a lower scored option this time' : ''), at: now + lat(0.6), look: this.causeOf(pickB) };
2409
- else this.done = false;
2410
- this.lastChoice = { at: now, U: Object.assign({}, U), cur: this.cur, curU, commit, T, probs: Object.fromEntries(ex.map(([b, w]) => [b, w / tot])), best, picked: pickB, path: 'sample' };
2411
- if (pickB !== this.cur) { const P = this.pending; P.kind = pickB !== best ? 'sampled' : 'top'; this.lastChoice.lat = P.at - now; P.ev = this.choiceEv(pickB, P.why, P.kind, P.at - now); }
2412
- }
2408
+ chooseShape();
2409
+ CHOOSE.dwellUntil = this.dwell; if (this.done) CHOOSE.markDone();
2410
+ const d = CHOOSE.updateWith(RNG, now, U, REACTIVE, this.forced && this.forced.until > now ? this.forced.b : undefined);
2411
+ this.dwell = CHOOSE.dwellUntil; this.done = CHOOSE.done;
2412
+ // react: something much better that cannot wait starts after a short heavy tailed latency, while the head already turns to it.
2413
+ // otherwise it chose only because the act is done or its dwell ran out: a sample, so the best option usually but not always wins
2414
+ if (!d.pending) return;
2415
+ CHOOSE.cancel();
2416
+ const b = d.pending.id, kind = d.reason === 'reactive' ? 'react' : d.reason;
2417
+ const P = this.pending = { b, why: whyOf(b) + (kind === 'sampled' ? ', took a lower scored option this time' : ''), at: d.pending.at, look: this.causeOf(b), kind };
2418
+ this.lastChoice = { at: now, U: Object.assign({}, U), cur: this.cur, best: d.best, picked: b, path: kind === 'react' || kind === 'forced' ? 'react' : 'sample', p: d.probability, lat: P.at - now };
2419
+ P.ev = this.choiceEv(b, P.why, kind, P.at - now);
2413
2420
  },
2414
2421
  // the sense event a choice answers: the newest sighting of the thing causeOf() turns the head to
2415
2422
  causeKey(b) { return ({ fetch: 'ball', chase: 'squirrel', greet: 'you', beg: 'you', playbow: 'you', obey: 'you', eat: 'bowl', treat: 'treat', sniff: 'scent', investigate: 'point' })[b] || null; },
@@ -2639,19 +2646,22 @@ function sleepRun(B, dt) {
2639
2646
  B.sub = 'goto'; B.stage = 'goto'; B.subT = 0;
2640
2647
  }
2641
2648
  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; }
2642
- 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'; B.stage = 'onset'; B.stageT = 0; B.stageDur = ORG.exg(1.5, 0.4, 1.5) * (now - B.negT < 120 ? 0.5 : 1); } return; }
2643
- motor.mode = 'stop'; P.down = 1; B.stageT += gm;
2649
+ 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; }
2650
+ motor.mode = 'stop'; P.down = 1;
2644
2651
  const neg = now - B.negT < 180; // after a bad experience: faster onset, more REM (Kis 2017)
2645
- if (B.stage === 'onset') { lookSalientSoft(); if (B.stageT > B.stageDur) { B.stage = 'nrem'; B.stageT = 0; B.stageDur = ORG.exg(TV('S.nrem'), 0.8, TV('S.nrem') * 0.6) * (neg ? 0.7 : 1); } }
2646
- else if (B.stage === 'nrem') { dog.head.tYaw = 0.5; dog.head.tPitch = 0.62; dog.head.tRoll = 0.15; O.rem = 0; if (B.stageT > B.stageDur) { B.stage = 'rem'; B.stageT = 0; B.stageDur = ORG.exg(TV('S.rem') * 0.7, 0.3, TV('S.rem') * 0.4) * (neg ? 1.6 : 1); } }
2647
- else if (B.stage === 'rem') {
2648
- dog.head.tYaw = 0.5; dog.head.tPitch = 0.62; O.rem = ss(0, 0.3, B.stageT) * 0.8;
2652
+ // each stage poses the dog with the time it will have reached, then the library's machine steps
2653
+ const s0 = SLEEP.stage, st = SLEEP.stageT + gm;
2654
+ if (s0 === 'onset' || s0 === 'wake') lookSalientSoft();
2655
+ else if (s0 === 'nrem') { dog.head.tYaw = 0.5; dog.head.tPitch = 0.62; dog.head.tRoll = 0.15; O.rem = 0; }
2656
+ else if (s0 === 'rem') {
2657
+ dog.head.tYaw = 0.5; dog.head.tPitch = 0.62; O.rem = ss(0, 0.3, st) * 0.8;
2649
2658
  if (RNG() < dt * 0.2) { if (RNG() < 0.5) whine(dog.root.position); B.say(pick(['wf', 'mm', 'zzz', '...wuf']), 1.4); }
2650
- 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); } }
2651
- } else if (B.stage === 'wake') {
2652
- lookSalientSoft();
2653
- 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); }
2654
2659
  }
2660
+ sleepShape(); SLEEP.pressure = B.Sp;
2661
+ if (SLEEP.stepWith(RNG, gm, B.circ ?? 0.3, neg)) { B.wake('slept enough'); return; }
2662
+ if (s0 === 'rem' && SLEEP.stage !== 'rem') O.rem = 0;
2663
+ // a dog that reached its spot with L.sleep off never lay down in the machine: its stage stays as it was
2664
+ if (SLEEP.stage !== 'awake') B.stage = SLEEP.stage;
2655
2665
  if (RNG() < dt * 0.1 && B.stage === 'nrem') B.say(pick(LINES.sleep), 2.5);
2656
2666
  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(); }
2657
2667
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackbuild/agents-views",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
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.5",
52
+ "@hackbuild/drives": "0.1.7",
53
53
  "@hackbuild/cameras": "^0.1.0",
54
54
  "@hackbuild/weights": "^0.1.0"
55
55
  },