@hackbuild/agents-views 0.2.5 → 0.2.6

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.
@@ -2035,7 +2035,8 @@ $('bMic').addEventListener('click', () => {
2035
2035
 
2036
2036
 
2037
2037
  // ---- yard/dog/brain.js
2038
- // ---------- brain ----------
2038
+ // ---------- brain: its state, memory, hearing and the calls that set what it does. learning.js,
2039
+ // drives.js, choice.js and behave.js add their methods to it in that order.
2039
2040
  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
2041
  const LINES = {
2041
2042
  idle: ['...', 'hm.', 'what was that', 'nice out', 'ears on'], explore: ['what is over there', 'patrol', 'new smells', 'checking the perimeter'],
@@ -2134,6 +2135,12 @@ const brain = {
2134
2135
  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
2136
  },
2136
2137
  release() { if (this.cmd) this.cmd = null; this.v = clamp(this.v + 0.15, -1, 1); this.say('free.', 1.5); },
2138
+ };
2139
+
2140
+ // ---- yard/dog/learning.js
2141
+ // dog brain: cues and tricks. A cue starts a trial, an offered trick waits for a reward, and the
2142
+ // reward updates the cue to action values through an eligibility trace.
2143
+ Object.assign(brain, {
2137
2144
  cue(word) {
2138
2145
  if (!word) return;
2139
2146
  word = word.toLowerCase().slice(0, 18);
@@ -2214,6 +2221,12 @@ const brain = {
2214
2221
  if (txt) $('heard').textContent = txt;
2215
2222
  if (any) this.persist();
2216
2223
  },
2224
+ });
2225
+
2226
+ // ---- yard/dog/drives.js
2227
+ // dog brain: drives. Hunger, fatigue, play, social, curiosity and prey move with the body clock and
2228
+ // what happens, and each tick turns them into signals for the choice.
2229
+ Object.assign(brain, {
2217
2230
  memory(id) { const p = percepts[id]; return p && p.seen > -1e8 ? p : null; },
2218
2231
  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
2232
  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 +2304,12 @@ const brain = {
2291
2304
  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
2305
  if (this.reunionI) this.reunionI = Math.max(0, this.reunionI - dt * 0.02);
2293
2306
  },
2307
+ });
2308
+
2309
+ // ---- yard/dog/choice.js
2310
+ // dog brain: choice. Each behaviour gets a utility from drives, percepts and learning; the choice keeps
2311
+ // one long enough to finish, and records why.
2312
+ Object.assign(brain, {
2294
2313
  utilities() {
2295
2314
  const U = this.util, d = this.d, org = ON('L.organic');
2296
2315
  const ballP = this.memory('ball'), treatK = Object.keys(percepts).find(k => k.startsWith('treat') && percepts[k].conf > 0.3);
@@ -2398,6 +2417,11 @@ const brain = {
2398
2417
  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
2418
  else { this.pointT = now; this.say(pick(['?', 'your hand?', 'what']), 1.6); }
2400
2419
  },
2420
+ });
2421
+
2422
+ // ---- yard/dog/behave.js
2423
+ // dog brain: running the chosen behaviour each frame, obeying a cue, and the fetch.
2424
+ Object.assign(brain, {
2401
2425
  run(dt) {
2402
2426
  const b = this.cur, d = this.d;
2403
2427
  motor.ignore = null;
@@ -2560,7 +2584,7 @@ const brain = {
2560
2584
  const hd = Math.hypot(mouth.x - bp.x, mouth.z - bp.z);
2561
2585
  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
2586
  }
2563
- };
2587
+ });
2564
2588
  // 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
2589
  function playbowRun(B, dt, youP, youHead) {
2566
2590
  const P = dog.postureT;
@@ -2848,7 +2872,7 @@ const H_LINES = {
2848
2872
  missed: 'Come on buddy'
2849
2873
  };
2850
2874
 
2851
- // ---- yard/human/human.js
2875
+ // ---- yard/human/rig.js
2852
2876
  // ---------- the human: Moheeb (rig core from the owner's earlier voice app, biped gait with leg IK, task planner, optional VLM mind) ----------
2853
2877
  // Body animation: Quaternius Universal Animation Library (CC0) clips, retargeted offline onto his rig by world space deltas from a shared T-pose
2854
2878
  const RIG = (() => {
@@ -2883,6 +2907,10 @@ function classifyBone(raw) {
2883
2907
 
2884
2908
  return { classifyBone };
2885
2909
  })();
2910
+
2911
+ // ---- yard/human/anim.js
2912
+ // the human: his clip player. Clips load per bone role, sample by time, mix by weight; one shot acts
2913
+ // and holds layer over the locomotion cycle, and the seated cycle runs enter, idle or talk, then exit.
2886
2914
  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
2915
  function haLoad(pack) {
2888
2916
  HA.roles = pack.roles; HA.fps = pack.fps;
@@ -2964,6 +2992,9 @@ function haTick(dt, speed, speaking, turn = 0) {
2964
2992
  HA.roles.forEach((r, i) => { const b = HA.bones[r]; if (b) b.quaternion.copy(P.q[i]); });
2965
2993
  return P.p;
2966
2994
  }
2995
+
2996
+ // ---- yard/human/body.js
2997
+ // the human: his state, his eye camera, the rig setup, and the two bone IK and aim helpers of his body.
2967
2998
  const hq = [new THREE.Quaternion(), new THREE.Quaternion(), new THREE.Quaternion()], hv = [V3(), V3(), V3(), V3(), V3(), V3(), V3(), V3()];
2968
2999
  // his model calls go through @hackbuild/drives InferenceScheduler, at least 25 s apart, one at a time
2969
3000
  const humMindSched = new HDRIVE.InferenceScheduler({ minInterval: 25 });
@@ -3041,6 +3072,7 @@ function aimBone(bone, child, target, k) {
3041
3072
  }
3042
3073
  function swingBone(bone, axisW, ang) { if (!bone || !ang) return; rotateBoneWorld(bone, hq[2].setFromAxisAngle(axisW, ang)); }
3043
3074
 
3075
+ // ---- yard/human/voice.js
3044
3076
  // voice and words
3045
3077
  // the fixed lines he says live in human/lines.js (H_LINES)
3046
3078
  const NEW_WORDS = [['boop', 'paw'], ['twirl', 'spin'], ['chill', 'down'], ['woof', 'speak'], ['park it', 'sit']];
@@ -3068,6 +3100,9 @@ function humanHold(on) {
3068
3100
  ball.rb.setBodyType(on ? RAPIER.RigidBodyType.KinematicPositionBased : RAPIER.RigidBodyType.Dynamic, true);
3069
3101
  }
3070
3102
  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); }
3103
+
3104
+ // ---- yard/human/act.js
3105
+ // the human: starting a task, the layers a task may keep, and coming back from an errand early.
3071
3106
  // 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
3107
  // released explicitly: a held kneel skips the rest of its hold and plays the stand up (1.3 s), where
3073
3108
  // before it played on through the hold window and froze the feet up to 3.9 s
@@ -3097,6 +3132,8 @@ function startTask(name, args = {}, why = '') {
3097
3132
  if (HA.sit && HA.sit.ph !== 'exit') { if (name === 'sit') { HUM.task.s = 'down'; HUM.task.k = 0; } else haSit(false); }
3098
3133
  }
3099
3134
 
3135
+ // ---- yard/human/steer.js
3136
+ // the human: steering and gait, then where his eyes and head go.
3100
3137
  // steering and gait
3101
3138
  function humSteer(dt) {
3102
3139
  const m = HUM.motor; let vC = 0, wC = 0;
@@ -3192,6 +3229,9 @@ function humGaze(dt) {
3192
3229
  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
3230
  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
3231
  }
3232
+
3233
+ // ---- yard/human/pose.js
3234
+ // the human: the throw plan and his body pose each frame, from gait, acts, IK and gaze.
3195
3235
  // throw: a proximal to distal chain with phase shares from Owens 2024 (stride 37, cocking 14, acceleration 3, deceleration 20, follow 26 percent),
3196
3236
  // segment timing and order jittered per throw since real throwers rarely follow the textbook order (Frontiers 2021)
3197
3237
  function throwPlan() {
@@ -3318,6 +3358,7 @@ function humPose(dt, t) {
3318
3358
  const yo = OBST.find(o => o.kind === 'you'); if (yo) { yo.x = HUM.pos.x; yo.z = HUM.pos.z; }
3319
3359
  }
3320
3360
 
3361
+ // ---- yard/human/tasks.js
3321
3362
  // tasks
3322
3363
  const pct2 = v => Math.round(v * 100) + '%';
3323
3364
  function pickThrowTarget() {
@@ -3449,6 +3490,8 @@ function humTask(dt) {
3449
3490
  default: end();
3450
3491
  }
3451
3492
  }
3493
+
3494
+ // ---- yard/human/mind.js
3452
3495
  // ---------- the owner as an agent: needs with a daily routine, sampled among the top few options (The Sims), repetition penalty, human latencies ----------
3453
3496
  // Measured anchors: one ~30 min walk a day (Westgarth 2019), phone pickups about every 12.6 min awake (dscout, compressed here),
3454
3497
  // 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 +3624,9 @@ DO: one of ${HUM_DO.join(', ')}`;
3581
3624
  HUM.thinking = false; return started;
3582
3625
  } 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
3626
  }
3627
+
3628
+ // ---- yard/human/human.js
3629
+ // the human: one tick of his body, needs, plan, tasks, gaze and pose, in that order.
3584
3630
  function humTick(dt, t) {
3585
3631
  if (!HUM.ready) return;
3586
3632
  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.6",
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
  },