@hackbuild/agents-views 0.2.5 → 0.2.7

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-11-26 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
179
+ Measured 2026-11-30 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.
@@ -1579,8 +1579,10 @@ function sense(t) {
1579
1579
  p.net = Math.max(0, p.net - 0.02);
1580
1580
  }
1581
1581
  for (const k in percepts) if (k.startsWith('treat') && !treats[+k.slice(5)]) delete percepts[k];
1582
- // a thing gone from the scene this frame (the human out the gate, a hidden squirrel) is no longer in view
1583
- for (const k in percepts) { const p = percepts[k]; if (p.frame !== t && p.vis) { p.vis = false; p.sal = 0; } }
1582
+ // the human out the gate is no longer in view. A hidden squirrel keeps its last sighting: the dog
1583
+ // watches where it went, and the scenario goldens were recorded on that (applying this to every
1584
+ // percept changed scent-trail, stroll-squirrel and both phone nudges, measured)
1585
+ { const p = percepts.you; if (p && p.frame !== t && p.vis) { p.vis = false; p.sal = 0; } }
1584
1586
  }
1585
1587
  // remembered position: errors grow with time but stay near the target (Fiset 2003)
1586
1588
  function memPos(p) { const age = Math.max(0, now - p.seen); return p.err ? p.pos.clone().addScaledVector(p.err, 0.25 * Math.sqrt(age / 60)) : p.pos.clone(); }
@@ -2035,7 +2037,8 @@ $('bMic').addEventListener('click', () => {
2035
2037
 
2036
2038
 
2037
2039
  // ---- yard/dog/brain.js
2038
- // ---------- brain ----------
2040
+ // ---------- brain: its state, memory, hearing and the calls that set what it does. learning.js,
2041
+ // drives.js, choice.js and behave.js add their methods to it in that order.
2039
2042
  const BEH = ['idle', 'explore', 'sniff', 'eat', 'treat', 'fetch', 'chase', 'greet', 'beg', 'playbow', 'zoomies', 'rest', 'sleep', 'obey', 'confused', 'shake', 'appease', 'stretch', 'investigate', 'follow', 'waitdoor', 'nudge'];
2040
2043
  const LINES = {
2041
2044
  idle: ['...', 'hm.', 'what was that', 'nice out', 'ears on'], explore: ['what is over there', 'patrol', 'new smells', 'checking the perimeter'],
@@ -2134,6 +2137,12 @@ const brain = {
2134
2137
  if (this.cur === 'sleep') this.wake('he came home'); this.force('greet', 4 + 4 * I); this.remember('my human came home after ' + hours.toFixed(1) + ' hours', 6 * I);
2135
2138
  },
2136
2139
  release() { if (this.cmd) this.cmd = null; this.v = clamp(this.v + 0.15, -1, 1); this.say('free.', 1.5); },
2140
+ };
2141
+
2142
+ // ---- yard/dog/learning.js
2143
+ // dog brain: cues and tricks. A cue starts a trial, an offered trick waits for a reward, and the
2144
+ // reward updates the cue to action values through an eligibility trace.
2145
+ Object.assign(brain, {
2137
2146
  cue(word) {
2138
2147
  if (!word) return;
2139
2148
  word = word.toLowerCase().slice(0, 18);
@@ -2214,6 +2223,12 @@ const brain = {
2214
2223
  if (txt) $('heard').textContent = txt;
2215
2224
  if (any) this.persist();
2216
2225
  },
2226
+ });
2227
+
2228
+ // ---- yard/dog/drives.js
2229
+ // dog brain: drives. Hunger, fatigue, play, social, curiosity and prey move with the body clock and
2230
+ // what happens, and each tick turns them into signals for the choice.
2231
+ Object.assign(brain, {
2217
2232
  memory(id) { const p = percepts[id]; return p && p.seen > -1e8 ? p : null; },
2218
2233
  driveD(h) { const n = TV('Br.driveN'), m = TV('Br.driveM'), w = { hunger: 1, fatigue: 1, play: 0.8, social: 0.9, curiosity: 0.6, prey: 1.1 }; let s = 0; for (const k in w) s += w[k] * Math.pow(Math.max(h[k] || 0, 0), n); return Math.pow(s, 1 / m); },
2219
2234
  gain(K, scale = 1) { const h = Object.assign({}, this.d); for (const k in K) h[k] = clamp(h[k] + K[k] * (K[k] < 0 ? scale : 1), 0, 1); return TV('Br.gain') * (this.driveD(this.d) - this.driveD(h)); },
@@ -2291,6 +2306,12 @@ const brain = {
2291
2306
  if (this.cmd && this.cmd.action === 'stay' && !watching) { this.unw = (this.unw || 0) + dt; if (this.unw > 2 && RNG() < dt * 0.15 * (1 + 0.4 * PT('independence'))) { this.cmd = null; this.done = true; this.say('he is not looking...', 1.6); } } else this.unw = 0;
2292
2307
  if (this.reunionI) this.reunionI = Math.max(0, this.reunionI - dt * 0.02);
2293
2308
  },
2309
+ });
2310
+
2311
+ // ---- yard/dog/choice.js
2312
+ // dog brain: choice. Each behaviour gets a utility from drives, percepts and learning; the choice keeps
2313
+ // one long enough to finish, and records why.
2314
+ Object.assign(brain, {
2294
2315
  utilities() {
2295
2316
  const U = this.util, d = this.d, org = ON('L.organic');
2296
2317
  const ballP = this.memory('ball'), treatK = Object.keys(percepts).find(k => k.startsWith('treat') && percepts[k].conf > 0.3);
@@ -2398,6 +2419,11 @@ const brain = {
2398
2419
  if (follow) { this.inv = { p: target.clone(), until: now + 14, why: 'followed the point' }; this.force('investigate', 1.2); this.remember('the human pointed somewhere', 1.5); }
2399
2420
  else { this.pointT = now; this.say(pick(['?', 'your hand?', 'what']), 1.6); }
2400
2421
  },
2422
+ });
2423
+
2424
+ // ---- yard/dog/behave.js
2425
+ // dog brain: running the chosen behaviour each frame, obeying a cue, and the fetch.
2426
+ Object.assign(brain, {
2401
2427
  run(dt) {
2402
2428
  const b = this.cur, d = this.d;
2403
2429
  motor.ignore = null;
@@ -2560,7 +2586,7 @@ const brain = {
2560
2586
  const hd = Math.hypot(mouth.x - bp.x, mouth.z - bp.z);
2561
2587
  if ((hd < 0.3 || (NG.active && dd < 0.5)) && bp.y < mouth.y + 0.1 && bodyVel(ball).length() < 2.2) { setHeld(ball, true); this.grabT = now; this.v = clamp(this.v + 0.2, -1, 1); this.a = clamp(this.a + 0.1, 0, 1); }
2562
2588
  }
2563
- };
2589
+ });
2564
2590
  // play bow: about 2.25 s, given when the partner is looking, after a lull, then a run away invitation (Byosiere, Espinosa and Smuts 2016)
2565
2591
  function playbowRun(B, dt, youP, youHead) {
2566
2592
  const P = dog.postureT;
@@ -2848,7 +2874,7 @@ const H_LINES = {
2848
2874
  missed: 'Come on buddy'
2849
2875
  };
2850
2876
 
2851
- // ---- yard/human/human.js
2877
+ // ---- yard/human/rig.js
2852
2878
  // ---------- the human: Moheeb (rig core from the owner's earlier voice app, biped gait with leg IK, task planner, optional VLM mind) ----------
2853
2879
  // Body animation: Quaternius Universal Animation Library (CC0) clips, retargeted offline onto his rig by world space deltas from a shared T-pose
2854
2880
  const RIG = (() => {
@@ -2883,6 +2909,10 @@ function classifyBone(raw) {
2883
2909
 
2884
2910
  return { classifyBone };
2885
2911
  })();
2912
+
2913
+ // ---- yard/human/anim.js
2914
+ // the human: his clip player. Clips load per bone role, sample by time, mix by weight; one shot acts
2915
+ // and holds layer over the locomotion cycle, and the seated cycle runs enter, idle or talk, then exit.
2886
2916
  const HA = { roles: [], clips: {}, bones: {}, hipH: 0.96, lphase: 0, idleT: 0, talkT: 0, talkW: 0, act: null, actW: 0, loco: [1, 0, 0, 0], pose: null, tmpA: null, tmpB: null };
2887
2917
  function haLoad(pack) {
2888
2918
  HA.roles = pack.roles; HA.fps = pack.fps;
@@ -2964,6 +2994,9 @@ function haTick(dt, speed, speaking, turn = 0) {
2964
2994
  HA.roles.forEach((r, i) => { const b = HA.bones[r]; if (b) b.quaternion.copy(P.q[i]); });
2965
2995
  return P.p;
2966
2996
  }
2997
+
2998
+ // ---- yard/human/body.js
2999
+ // the human: his state, his eye camera, the rig setup, and the two bone IK and aim helpers of his body.
2967
3000
  const hq = [new THREE.Quaternion(), new THREE.Quaternion(), new THREE.Quaternion()], hv = [V3(), V3(), V3(), V3(), V3(), V3(), V3(), V3()];
2968
3001
  // his model calls go through @hackbuild/drives InferenceScheduler, at least 25 s apart, one at a time
2969
3002
  const humMindSched = new HDRIVE.InferenceScheduler({ minInterval: 25 });
@@ -3041,6 +3074,7 @@ function aimBone(bone, child, target, k) {
3041
3074
  }
3042
3075
  function swingBone(bone, axisW, ang) { if (!bone || !ang) return; rotateBoneWorld(bone, hq[2].setFromAxisAngle(axisW, ang)); }
3043
3076
 
3077
+ // ---- yard/human/voice.js
3044
3078
  // voice and words
3045
3079
  // the fixed lines he says live in human/lines.js (H_LINES)
3046
3080
  const NEW_WORDS = [['boop', 'paw'], ['twirl', 'spin'], ['chill', 'down'], ['woof', 'speak'], ['park it', 'sit']];
@@ -3068,6 +3102,9 @@ function humanHold(on) {
3068
3102
  ball.rb.setBodyType(on ? RAPIER.RigidBodyType.KinematicPositionBased : RAPIER.RigidBodyType.Dynamic, true);
3069
3103
  }
3070
3104
  function handPos(out = V3()) { return HUM.hand ? HUM.hand.getWorldPosition(out) : out.copy(HUM.pos).setY(H(HUM.pos.x, HUM.pos.z) + 1.0); }
3105
+
3106
+ // ---- yard/human/act.js
3107
+ // the human: starting a task, the layers a task may keep, and coming back from an errand early.
3071
3108
  // blocking layers each task may keep across a task change (learned in earlier builds: a held layer can outlive its task); any other held layer is
3072
3109
  // released explicitly: a held kneel skips the rest of its hold and plays the stand up (1.3 s), where
3073
3110
  // before it played on through the hold window and froze the feet up to 3.9 s
@@ -3097,6 +3134,8 @@ function startTask(name, args = {}, why = '') {
3097
3134
  if (HA.sit && HA.sit.ph !== 'exit') { if (name === 'sit') { HUM.task.s = 'down'; HUM.task.k = 0; } else haSit(false); }
3098
3135
  }
3099
3136
 
3137
+ // ---- yard/human/steer.js
3138
+ // the human: steering and gait, then where his eyes and head go.
3100
3139
  // steering and gait
3101
3140
  function humSteer(dt) {
3102
3141
  const m = HUM.motor; let vC = 0, wC = 0;
@@ -3192,6 +3231,9 @@ function humGaze(dt) {
3192
3231
  if (dog.ready) { const tdg = V3(dog.pos.x - HUM.pos.x, 0, dog.pos.z - HUM.pos.z), dd = tdg.length(), vd = V3(Math.sin(HUM.yaw), 0, Math.cos(HUM.yaw));
3193
3232
  HUM.threat = clamp((HUM.v - 0.5) / 1.2, 0, 1) * ss(0.85, 0.97, vd.dot(tdg.normalize())) * (HUM.lookingAtDog ? 1 : 0.4) * (1 - ss(2, 4, dd)); }
3194
3233
  }
3234
+
3235
+ // ---- yard/human/pose.js
3236
+ // the human: the throw plan and his body pose each frame, from gait, acts, IK and gaze.
3195
3237
  // throw: a proximal to distal chain with phase shares from Owens 2024 (stride 37, cocking 14, acceleration 3, deceleration 20, follow 26 percent),
3196
3238
  // segment timing and order jittered per throw since real throwers rarely follow the textbook order (Frontiers 2021)
3197
3239
  function throwPlan() {
@@ -3318,6 +3360,7 @@ function humPose(dt, t) {
3318
3360
  const yo = OBST.find(o => o.kind === 'you'); if (yo) { yo.x = HUM.pos.x; yo.z = HUM.pos.z; }
3319
3361
  }
3320
3362
 
3363
+ // ---- yard/human/tasks.js
3321
3364
  // tasks
3322
3365
  const pct2 = v => Math.round(v * 100) + '%';
3323
3366
  function pickThrowTarget() {
@@ -3449,6 +3492,8 @@ function humTask(dt) {
3449
3492
  default: end();
3450
3493
  }
3451
3494
  }
3495
+
3496
+ // ---- yard/human/mind.js
3452
3497
  // ---------- the owner as an agent: needs with a daily routine, sampled among the top few options (The Sims), repetition penalty, human latencies ----------
3453
3498
  // Measured anchors: one ~30 min walk a day (Westgarth 2019), phone pickups about every 12.6 min awake (dscout, compressed here),
3454
3499
  // praise about 0.62 s and food about 0.98 s after the dog responds (Browne), training spaced rather than massed (Meyer and Ladewig 2008, Demant 2011).
@@ -3581,6 +3626,9 @@ DO: one of ${HUM_DO.join(', ')}`;
3581
3626
  HUM.thinking = false; return started;
3582
3627
  } catch (e) { console.warn('human mind', e); vlmLog({ t: callT, who: 'human', kind: 'think', prompt: '', text: String(e.message || e), ms: 0, tokens: 0, ok: false }); $('humMind').textContent = 'error: ' + (e.message || e); HUM.thinking = false; return false; }
3583
3628
  }
3629
+
3630
+ // ---- yard/human/human.js
3631
+ // the human: one tick of his body, needs, plan, tasks, gaze and pose, in that order.
3584
3632
  function humTick(dt, t) {
3585
3633
  if (!HUM.ready) return;
3586
3634
  for (let i = HUM.later.length - 1; i >= 0; i--) if (now >= HUM.later[i].at) { const f = HUM.later[i].fn; HUM.later.splice(i, 1); f(); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackbuild/agents-views",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
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",
@@ -48,8 +48,8 @@
48
48
  "@hackbuild/motion-net": "^0.2.0",
49
49
  "@hackbuild/gait": "^0.1.0",
50
50
  "@hackbuild/tunables": "^0.1.0",
51
- "@hackbuild/senses": "^0.1.0",
52
- "@hackbuild/drives": "^0.1.0",
51
+ "@hackbuild/senses": "0.1.4",
52
+ "@hackbuild/drives": "0.1.4",
53
53
  "@hackbuild/cameras": "^0.1.0",
54
54
  "@hackbuild/weights": "^0.1.0"
55
55
  },