@hackbuild/agents-views 0.2.4 → 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 +1 -1
- package/dist/yard/scope.js +66 -4
- package/package.json +3 -3
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-
|
|
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.
|
package/dist/yard/scope.js
CHANGED
|
@@ -1567,6 +1567,7 @@ function sense(t) {
|
|
|
1567
1567
|
if (o.id === 'ball' && ball.held) vis = false;
|
|
1568
1568
|
if (brain.cur === 'sleep' && dog.posture.down > 0.7 && (!ON('L.sleep') || brain.stage === 'nrem' || brain.stage === 'rem')) vis = false;
|
|
1569
1569
|
const p = percepts[o.id] || (percepts[o.id] = { id: o.id, seen: -1e9, pos: V3(), vis: false, sal: 0, kind: o.kind || o.id, net: 0 });
|
|
1570
|
+
p.frame = t;
|
|
1570
1571
|
// read only tap: a sense event when something comes into view after 3 s out of it
|
|
1571
1572
|
if (vis && !p.vis && t - p.seen > 3) p.ev = EV.emit({ agent: 'dog', kind: 'sense', sense: 'eye', text: (p.seen > -1e8 ? 'saw ' : 'first saw ') + (o.id === 'you' ? 'moheeb' : o.id.replace(/\d+$/, '')) + ' at ' + dist.toFixed(1) + ' m' });
|
|
1572
1573
|
p.vis = vis; p.obj = o.obj; p.dist = dist; p.speed = speed;
|
|
@@ -1578,6 +1579,8 @@ function sense(t) {
|
|
|
1578
1579
|
p.net = Math.max(0, p.net - 0.02);
|
|
1579
1580
|
}
|
|
1580
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; } }
|
|
1581
1584
|
}
|
|
1582
1585
|
// remembered position: errors grow with time but stay near the target (Fiset 2003)
|
|
1583
1586
|
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(); }
|
|
@@ -2032,7 +2035,8 @@ $('bMic').addEventListener('click', () => {
|
|
|
2032
2035
|
|
|
2033
2036
|
|
|
2034
2037
|
// ---- yard/dog/brain.js
|
|
2035
|
-
// ---------- 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.
|
|
2036
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'];
|
|
2037
2041
|
const LINES = {
|
|
2038
2042
|
idle: ['...', 'hm.', 'what was that', 'nice out', 'ears on'], explore: ['what is over there', 'patrol', 'new smells', 'checking the perimeter'],
|
|
@@ -2131,6 +2135,12 @@ const brain = {
|
|
|
2131
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);
|
|
2132
2136
|
},
|
|
2133
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, {
|
|
2134
2144
|
cue(word) {
|
|
2135
2145
|
if (!word) return;
|
|
2136
2146
|
word = word.toLowerCase().slice(0, 18);
|
|
@@ -2211,6 +2221,12 @@ const brain = {
|
|
|
2211
2221
|
if (txt) $('heard').textContent = txt;
|
|
2212
2222
|
if (any) this.persist();
|
|
2213
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, {
|
|
2214
2230
|
memory(id) { const p = percepts[id]; return p && p.seen > -1e8 ? p : null; },
|
|
2215
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); },
|
|
2216
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)); },
|
|
@@ -2288,6 +2304,12 @@ const brain = {
|
|
|
2288
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;
|
|
2289
2305
|
if (this.reunionI) this.reunionI = Math.max(0, this.reunionI - dt * 0.02);
|
|
2290
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, {
|
|
2291
2313
|
utilities() {
|
|
2292
2314
|
const U = this.util, d = this.d, org = ON('L.organic');
|
|
2293
2315
|
const ballP = this.memory('ball'), treatK = Object.keys(percepts).find(k => k.startsWith('treat') && percepts[k].conf > 0.3);
|
|
@@ -2395,6 +2417,11 @@ const brain = {
|
|
|
2395
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); }
|
|
2396
2418
|
else { this.pointT = now; this.say(pick(['?', 'your hand?', 'what']), 1.6); }
|
|
2397
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, {
|
|
2398
2425
|
run(dt) {
|
|
2399
2426
|
const b = this.cur, d = this.d;
|
|
2400
2427
|
motor.ignore = null;
|
|
@@ -2557,7 +2584,7 @@ const brain = {
|
|
|
2557
2584
|
const hd = Math.hypot(mouth.x - bp.x, mouth.z - bp.z);
|
|
2558
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); }
|
|
2559
2586
|
}
|
|
2560
|
-
};
|
|
2587
|
+
});
|
|
2561
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)
|
|
2562
2589
|
function playbowRun(B, dt, youP, youHead) {
|
|
2563
2590
|
const P = dog.postureT;
|
|
@@ -2845,7 +2872,7 @@ const H_LINES = {
|
|
|
2845
2872
|
missed: 'Come on buddy'
|
|
2846
2873
|
};
|
|
2847
2874
|
|
|
2848
|
-
// ---- yard/human/
|
|
2875
|
+
// ---- yard/human/rig.js
|
|
2849
2876
|
// ---------- the human: Moheeb (rig core from the owner's earlier voice app, biped gait with leg IK, task planner, optional VLM mind) ----------
|
|
2850
2877
|
// Body animation: Quaternius Universal Animation Library (CC0) clips, retargeted offline onto his rig by world space deltas from a shared T-pose
|
|
2851
2878
|
const RIG = (() => {
|
|
@@ -2880,6 +2907,10 @@ function classifyBone(raw) {
|
|
|
2880
2907
|
|
|
2881
2908
|
return { classifyBone };
|
|
2882
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.
|
|
2883
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 };
|
|
2884
2915
|
function haLoad(pack) {
|
|
2885
2916
|
HA.roles = pack.roles; HA.fps = pack.fps;
|
|
@@ -2961,6 +2992,9 @@ function haTick(dt, speed, speaking, turn = 0) {
|
|
|
2961
2992
|
HA.roles.forEach((r, i) => { const b = HA.bones[r]; if (b) b.quaternion.copy(P.q[i]); });
|
|
2962
2993
|
return P.p;
|
|
2963
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.
|
|
2964
2998
|
const hq = [new THREE.Quaternion(), new THREE.Quaternion(), new THREE.Quaternion()], hv = [V3(), V3(), V3(), V3(), V3(), V3(), V3(), V3()];
|
|
2965
2999
|
// his model calls go through @hackbuild/drives InferenceScheduler, at least 25 s apart, one at a time
|
|
2966
3000
|
const humMindSched = new HDRIVE.InferenceScheduler({ minInterval: 25 });
|
|
@@ -3038,6 +3072,7 @@ function aimBone(bone, child, target, k) {
|
|
|
3038
3072
|
}
|
|
3039
3073
|
function swingBone(bone, axisW, ang) { if (!bone || !ang) return; rotateBoneWorld(bone, hq[2].setFromAxisAngle(axisW, ang)); }
|
|
3040
3074
|
|
|
3075
|
+
// ---- yard/human/voice.js
|
|
3041
3076
|
// voice and words
|
|
3042
3077
|
// the fixed lines he says live in human/lines.js (H_LINES)
|
|
3043
3078
|
const NEW_WORDS = [['boop', 'paw'], ['twirl', 'spin'], ['chill', 'down'], ['woof', 'speak'], ['park it', 'sit']];
|
|
@@ -3065,13 +3100,27 @@ function humanHold(on) {
|
|
|
3065
3100
|
ball.rb.setBodyType(on ? RAPIER.RigidBodyType.KinematicPositionBased : RAPIER.RigidBodyType.Dynamic, true);
|
|
3066
3101
|
}
|
|
3067
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.
|
|
3068
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
|
|
3069
3107
|
// released explicitly: a held kneel skips the rest of its hold and plays the stand up (1.3 s), where
|
|
3070
3108
|
// before it played on through the hold window and froze the feet up to 3.9 s
|
|
3071
3109
|
const TASK_LAYERS = { get_ball: ['kneel'], pet: ['kneel', 'crouch'], feed: ['kneel'] };
|
|
3072
3110
|
// read only tap: where the next task comes from (rule, routine, mind, you), set by the caller
|
|
3073
3111
|
let humSrcNext = null;
|
|
3112
|
+
// back through the gate early: a task or a treat while he is out ends the errand, so the dog's
|
|
3113
|
+
// senses and the minds panel see him again and the dog greets him for the time he was gone
|
|
3114
|
+
function humBack() {
|
|
3115
|
+
if (!HUM.away) return;
|
|
3116
|
+
const T = HUM.task, hours = T && T.name === 'errand' ? T.args.hours * Math.min(1, (now - HUM.awayT0) / Math.max(HUM.awayDur, 1e-3)) : 0.5;
|
|
3117
|
+
HUM.away = false; HUM.root.visible = true;
|
|
3118
|
+
brain.reunion(hours);
|
|
3119
|
+
// a treat leaves the errand running: it goes on from the walk back to his seat
|
|
3120
|
+
if (T && T.name === 'errand') T.s = 'back';
|
|
3121
|
+
}
|
|
3074
3122
|
function startTask(name, args = {}, why = '') {
|
|
3123
|
+
if (name !== 'errand') humBack();
|
|
3075
3124
|
const src = humSrcNext || (args.user ? 'you' : 'task'); humSrcNext = null;
|
|
3076
3125
|
if (src === 'rule') HUM.lastPlan = { at: now, rule: why, choice: name };
|
|
3077
3126
|
HUM.taskEv = EV.emit({ agent: 'human', kind: 'act', text: name.replace('_', ' ') + (why ? ', ' + why : ''), cause: src === 'rule' && /dog/.test(why) ? brain.evAct || null : src === 'mind' ? HUM.mindEv || null : null });
|
|
@@ -3083,6 +3132,8 @@ function startTask(name, args = {}, why = '') {
|
|
|
3083
3132
|
if (HA.sit && HA.sit.ph !== 'exit') { if (name === 'sit') { HUM.task.s = 'down'; HUM.task.k = 0; } else haSit(false); }
|
|
3084
3133
|
}
|
|
3085
3134
|
|
|
3135
|
+
// ---- yard/human/steer.js
|
|
3136
|
+
// the human: steering and gait, then where his eyes and head go.
|
|
3086
3137
|
// steering and gait
|
|
3087
3138
|
function humSteer(dt) {
|
|
3088
3139
|
const m = HUM.motor; let vC = 0, wC = 0;
|
|
@@ -3178,6 +3229,9 @@ function humGaze(dt) {
|
|
|
3178
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));
|
|
3179
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)); }
|
|
3180
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.
|
|
3181
3235
|
// throw: a proximal to distal chain with phase shares from Owens 2024 (stride 37, cocking 14, acceleration 3, deceleration 20, follow 26 percent),
|
|
3182
3236
|
// segment timing and order jittered per throw since real throwers rarely follow the textbook order (Frontiers 2021)
|
|
3183
3237
|
function throwPlan() {
|
|
@@ -3304,6 +3358,7 @@ function humPose(dt, t) {
|
|
|
3304
3358
|
const yo = OBST.find(o => o.kind === 'you'); if (yo) { yo.x = HUM.pos.x; yo.z = HUM.pos.z; }
|
|
3305
3359
|
}
|
|
3306
3360
|
|
|
3361
|
+
// ---- yard/human/tasks.js
|
|
3307
3362
|
// tasks
|
|
3308
3363
|
const pct2 = v => Math.round(v * 100) + '%';
|
|
3309
3364
|
function pickThrowTarget() {
|
|
@@ -3435,6 +3490,8 @@ function humTask(dt) {
|
|
|
3435
3490
|
default: end();
|
|
3436
3491
|
}
|
|
3437
3492
|
}
|
|
3493
|
+
|
|
3494
|
+
// ---- yard/human/mind.js
|
|
3438
3495
|
// ---------- the owner as an agent: needs with a daily routine, sampled among the top few options (The Sims), repetition penalty, human latencies ----------
|
|
3439
3496
|
// Measured anchors: one ~30 min walk a day (Westgarth 2019), phone pickups about every 12.6 min awake (dscout, compressed here),
|
|
3440
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).
|
|
@@ -3548,7 +3605,8 @@ DO: one of ${HUM_DO.join(', ')}`;
|
|
|
3548
3605
|
vlmLog({ t: callT, who: 'human', kind: 'think', prompt, text: txt, ms: r.ms, tokens: r.tokens, ok: true });
|
|
3549
3606
|
HUM.mindEv = EV.emit({ agent: 'human', kind: 'model', text: 'his mind replied in ' + (r.ms / 1000).toFixed(1) + ' s: ' + txt.replace(/\s+/g, ' ').slice(0, 90) });
|
|
3550
3607
|
humSrcNext = 'mind';
|
|
3551
|
-
|
|
3608
|
+
// only a SAY line is spoken: a small model that answers in the dog's SAW, THOUGHT or GOAL shape says nothing
|
|
3609
|
+
const say = ((txt.match(/^\s*SAY:\s*(.+)$/im) || [])[1] || '').replace(/^["']|["']$/g, '').replace(new RegExp('[' + String.fromCharCode(0x2013, 0x2014) + ']', 'g'), ',').trim();
|
|
3552
3610
|
const doL = ((txt.match(/DO:\s*(.+)/i) || [])[1] || '').toLowerCase();
|
|
3553
3611
|
if (vlm.last) vlm.last.plan = { say, do: doL };
|
|
3554
3612
|
$('humMind').textContent = 'say: ' + say + '\ndo: ' + (doL || '?') + ' (' + (r.ms / 1000).toFixed(1) + ' s)';
|
|
@@ -3566,6 +3624,9 @@ DO: one of ${HUM_DO.join(', ')}`;
|
|
|
3566
3624
|
HUM.thinking = false; return started;
|
|
3567
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; }
|
|
3568
3626
|
}
|
|
3627
|
+
|
|
3628
|
+
// ---- yard/human/human.js
|
|
3629
|
+
// the human: one tick of his body, needs, plan, tasks, gaze and pose, in that order.
|
|
3569
3630
|
function humTick(dt, t) {
|
|
3570
3631
|
if (!HUM.ready) return;
|
|
3571
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(); }
|
|
@@ -3612,6 +3673,7 @@ function throwBall(to) {
|
|
|
3612
3673
|
startTask('throw', { to, user: true }, 'you asked him to throw');
|
|
3613
3674
|
}
|
|
3614
3675
|
function tossTreat(noReward) {
|
|
3676
|
+
humBack();
|
|
3615
3677
|
if (!noReward) brain.reward(ON('L.learn') ? 0.5 : 1, 'treat');
|
|
3616
3678
|
const near = dist2(dog.pos, YOU) < 1.6;
|
|
3617
3679
|
if (near && !noReward) { brain.d.hunger = clamp(brain.d.hunger - 0.08, 0, 1); brain.say('crunch, thank you', 1.6); return; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/agents-views",
|
|
3
|
-
"version": "0.2.
|
|
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": "
|
|
52
|
-
"@hackbuild/drives": "
|
|
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
|
},
|