@hackbuild/agents-views 0.1.0 → 0.1.2
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 +114 -75
- package/dist/agents-views.iife.js +205 -4
- package/dist/associations-table.d.ts +11 -1
- package/dist/associations-table.js +1 -0
- package/dist/drives-bars.d.ts +9 -1
- package/dist/drives-bars.js +1 -0
- package/dist/elements.d.ts +1 -0
- package/dist/elements.js +1 -0
- package/dist/eye-inset.d.ts +15 -1
- package/dist/eye-inset.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/map-inset.d.ts +34 -0
- package/dist/map-inset.js +60 -0
- package/dist/plan-log.d.ts +76 -0
- package/dist/plan-log.js +106 -0
- package/dist/vue.d.ts +74 -0
- package/dist/vue.js +58 -0
- package/llms.md +476 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,61 +1,79 @@
|
|
|
1
1
|
# @hackbuild/agents-views
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
when the keys change, so the bars move in place. `drivesBarsState(decision,
|
|
15
|
-
drives, { now, seconds })` builds the state from a `Chooser` decision and
|
|
16
|
-
a `Drives` object of `@hackbuild/drives`.
|
|
17
|
-
- `associationsTable(host, { onReset })`: cues by acts, each cell the net
|
|
18
|
-
strength (excitation minus inhibition) from 0 to 99 in pink, the attn
|
|
19
|
-
column (associability), the last rewarded cell marked aria-current, a line on the
|
|
20
|
-
last trial, the explanation and reset learning. `associationsState(learner)`
|
|
21
|
-
reads a `CueLearner`.
|
|
22
|
-
- `eyeInset(host, { who, draw })`: makes `host` the eye card, an inset
|
|
23
|
-
marked `data-ux="inset"`: a canvas, a who switch and a mode line. `frame()`
|
|
24
|
-
calls `draw` inside the who's `FirstPerson` eye of `@hackbuild/cameras`, so
|
|
25
|
-
its own head is hidden for that render; a returned string sets the mode
|
|
26
|
-
line. Pass `canvas` when a renderer owns one already.
|
|
27
|
-
- `defineViews()` registers `hb-drives-bars`, `hb-associations-table` and
|
|
28
|
-
`hb-eye-inset` (set `.state`, or `.options` and call `frame()`); the single
|
|
29
|
-
file build registers them when its script tag runs.
|
|
30
|
-
- `@hackbuild/agents-views/vue`: `DrivesBars`, `AssociationsTable` (emits
|
|
31
|
-
`reset`) and `EyeInset` (v-model:selected, an exposed `frame()`).
|
|
32
|
-
|
|
33
|
-
The views read the drives and cameras objects by their shape, so the package
|
|
34
|
-
has no runtime dependency; the tests bind them to the real packages.
|
|
3
|
+
The brain bars, the associations table and the eye card of a simulated animal, as views you mount on any page with the hackbuild-ui look.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@hackbuild/agents-views) [](../../LICENSE)  
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
- Draws what the animal is doing and why, what each act is worth now with the chosen one in pink, and how much it needs each thing.
|
|
10
|
+
- Draws what it has learned: cues by acts, each cell the net strength from 0 to 99, with how much it still pays attention to each cue.
|
|
11
|
+
- Makes an element the eye card: a canvas drawn from inside the animal's own eye, a switch for whose eyes, and a mode line.
|
|
12
|
+
- Ships each view three ways that draw the same markup: a plain function over a host element, a custom element and a Vue component.
|
|
13
|
+
- Reads @hackbuild/drives and @hackbuild/cameras objects by their shape, so it has no runtime dependency on either.
|
|
35
14
|
|
|
36
15
|
## Install
|
|
37
16
|
|
|
38
|
-
|
|
17
|
+
```sh
|
|
18
|
+
npm install @hackbuild/agents-views @hackbuild/drives @virgilvox/hackbuild-ui
|
|
19
|
+
```
|
|
39
20
|
|
|
40
|
-
`vue` is an optional peer, needed only for the
|
|
21
|
+
`@virgilvox/hackbuild-ui` (0.10 or 0.11) is a peer: the views write its classes and never style themselves, so load its `hackbuild.css` on the page. `vue` (3.5 or later) is an optional peer, needed only for the `@hackbuild/agents-views/vue` entry. @hackbuild/drives is what the quick start feeds the views; @hackbuild/cameras gives the eye card its `FirstPerson` eye. Neither is a dependency of this package.
|
|
41
22
|
|
|
42
|
-
##
|
|
23
|
+
## Quick start
|
|
43
24
|
|
|
44
25
|
```ts
|
|
45
|
-
import { drivesBars, drivesBarsState
|
|
26
|
+
import { associationsState, associationsTable, drivesBars, drivesBarsState } from "@hackbuild/agents-views";
|
|
27
|
+
import { Chooser, CueLearner, Drives, load, seededRng } from "@hackbuild/drives";
|
|
28
|
+
|
|
29
|
+
// the brain: two drives, three acts and a learner, all seeded
|
|
30
|
+
await load();
|
|
31
|
+
const rng = seededRng(7);
|
|
32
|
+
const drives = new Drives({ hunger: 1, play: 0.8 });
|
|
33
|
+
const chooser = new Chooser({ rng, options: ["idle", "eat", "fetch"] as const });
|
|
34
|
+
const learner = new CueLearner({ rng, actions: ["sit", "paw"] as const });
|
|
35
|
+
|
|
36
|
+
// the views: mount once, update each tick
|
|
37
|
+
const bars = drivesBars(document.body.appendChild(document.createElement("div")));
|
|
38
|
+
const table = associationsTable(document.body.appendChild(document.createElement("div")), { onReset: () => location.reload() });
|
|
39
|
+
let now = 0;
|
|
40
|
+
setInterval(() => {
|
|
41
|
+
now += 0.5;
|
|
42
|
+
drives.grow(0.5, { hunger: 0.02, play: 0.03 });
|
|
43
|
+
const d = chooser.update(now, { idle: 0.1, eat: drives.rewardOf({ hunger: -0.5 }), fetch: drives.rewardOf({ play: -0.4 }) });
|
|
44
|
+
bars.update(drivesBarsState(d, drives, { now }));
|
|
45
|
+
table.update(associationsState(learner));
|
|
46
|
+
}, 500);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Live example
|
|
50
|
+
|
|
51
|
+
Three demo pages run one yard built in code through a scripted day, so the views move with nobody at the keys: [drive bars](https://hackbuild.github.io/hackbuild-agents/drives-bars/), [associations table](https://hackbuild.github.io/hackbuild-agents/associations-table/) and [eye card](https://hackbuild.github.io/hackbuild-agents/eye-inset/). The suite's [creature with drives](https://hackbuild.github.io/hackbuild-suite/#/examples/think/drives) puts the bars beside a running animal.
|
|
52
|
+
|
|
53
|
+
## Concepts
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
const d = chooser.update(now, utilities);
|
|
49
|
-
bars.update(drivesBarsState(d, drives, { now, seconds: now - since }));
|
|
55
|
+
### a view is a function over a host
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
`drivesBars(host)`, `associationsTable(host, options)` and `eyeInset(host, options)` take an element you own, replace its children with the view and return a handle. Call `update(state)` each tick; `dispose()` empties the host. The drive and utility rows are rebuilt only when their keys change, so the bars move in place and a screen reader is not flooded.
|
|
58
|
+
|
|
59
|
+
### state is plain data
|
|
60
|
+
|
|
61
|
+
Each view draws a plain object you can build by hand: `DrivesBarsState` (behaviour, why, utilities, drives, an optional pending switch) and `AssociationsState` (actions, cue rows, the last rewarded cell, a line on the last trial). `drivesBarsState(decision, drives, { now, seconds })` builds the first from a `Chooser` decision and a `Drives` object; `associationsState(learner)` builds the second from a `CueLearner`, with net strength as excitation minus inhibition.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { drivesBars } from "@hackbuild/agents-views";
|
|
65
|
+
|
|
66
|
+
const bars = drivesBars(document.querySelector("#brain") as HTMLElement);
|
|
67
|
+
bars.update({ behavior: "fetch", why: "play is high", utilities: { idle: 0.1, fetch: 0.6 }, drives: { play: 0.8, hunger: 0.3 } });
|
|
56
68
|
```
|
|
57
69
|
|
|
58
|
-
|
|
70
|
+
### the eye card draws inside the eye
|
|
71
|
+
|
|
72
|
+
`eyeInset(host, { who, draw })` takes a list of who entries, each with an optional `eye`. `frame()` calls your `draw(canvas, who)` inside `who.eye.render`, so a `FirstPerson` from @hackbuild/cameras hides the animal's own head for that render only. A string returned from `draw` becomes the mode line, such as "dichromat". Pass `canvas` when a renderer owns one already. The card is a hackbuild-ui inset marked `data-ux="inset"`.
|
|
73
|
+
|
|
74
|
+
### custom elements and Vue
|
|
75
|
+
|
|
76
|
+
`defineViews()` registers `hb-drives-bars`, `hb-associations-table` (fires `reset`) and `hb-eye-inset` (set `.options`, call `frame()`, fires `who`); it is safe to call again. The single file build `dist/agents-views.iife.js` registers them when its script tag runs, so a page opened from file:// needs no bundler. `@hackbuild/agents-views/vue` has `DrivesBars`, `AssociationsTable` (emits `reset`) and `EyeInset` (v-model:selected and an exposed `frame()`).
|
|
59
77
|
|
|
60
78
|
```html
|
|
61
79
|
<script src="agents-views.iife.js"></script>
|
|
@@ -63,53 +81,74 @@ Plain HTML:
|
|
|
63
81
|
<script>document.getElementById("brain").state = { behavior: "idle", utilities: { idle: 0.1 }, drives: { hunger: 0.4 } };</script>
|
|
64
82
|
```
|
|
65
83
|
|
|
66
|
-
##
|
|
84
|
+
## API overview
|
|
85
|
+
|
|
86
|
+
| export | what it does |
|
|
87
|
+
|---|---|
|
|
88
|
+
| [`drivesBars`](../../docs/api/agents-views/index.md#drivesbars) | the behaviour, utility and drive panels in a host |
|
|
89
|
+
| [`drivesBarsState`](../../docs/api/agents-views/index.md#drivesbarsstate) | the bars' state from a `Chooser` decision and the drives |
|
|
90
|
+
| [`associationsTable`](../../docs/api/agents-views/index.md#associationstable) | the cues by acts table with attention and reset |
|
|
91
|
+
| [`associationsState`](../../docs/api/agents-views/index.md#associationsstate) | the table's state from a `CueLearner` |
|
|
92
|
+
| [`eyeInset`](../../docs/api/agents-views/index.md#eyeinset) | the eye card: canvas, who switch and mode line |
|
|
93
|
+
| [`defineViews`](../../docs/api/agents-views/index.md#defineviews) | registers the three custom elements |
|
|
94
|
+
| [`ELEMENT_NAMES`](../../docs/api/agents-views/index.md#element_names) | the tag names |
|
|
95
|
+
| [`DrivesBars`](../../docs/api/agents-views/vue.md#drivesbars) | the bars as a Vue component |
|
|
96
|
+
| [`AssociationsTable`](../../docs/api/agents-views/vue.md#associationstable) | the table as a Vue component |
|
|
97
|
+
| [`EyeInset`](../../docs/api/agents-views/vue.md#eyeinset) | the eye card as a Vue component |
|
|
98
|
+
|
|
99
|
+
The full reference is in [docs/api/agents-views](../../docs/api/agents-views/README.md).
|
|
100
|
+
|
|
101
|
+
## Browser support
|
|
67
102
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
103
|
+
| feature | needs | Chrome | Safari | Firefox | phone |
|
|
104
|
+
|---|---|---|---|---|---|
|
|
105
|
+
| the three views | DOM and CSS custom properties | yes | yes (inferred) | yes (inferred) | yes (inferred) |
|
|
106
|
+
| custom elements | `customElements` | yes | yes (inferred) | yes (inferred) | yes (inferred) |
|
|
107
|
+
| eye card canvas | whatever your `draw` uses: 2D canvas or WebGL | yes | as your renderer | as your renderer | as your renderer |
|
|
108
|
+
| single file build from file:// | a classic script | yes | yes (inferred) | yes (inferred) | unknown |
|
|
109
|
+
|
|
110
|
+
The views draw no frames of their own: they cost what `update` and your `draw` cost.
|
|
111
|
+
|
|
112
|
+
## Errors and troubleshooting
|
|
113
|
+
|
|
114
|
+
| message | cause | what to do |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `@hackbuild/agents-views: eyeInset needs at least one who` | `eyeInset` got an empty `who` list | pass at least one who entry |
|
|
71
117
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
118
|
+
A view with no hackbuild-ui stylesheet on the page draws unstyled bars: load `hackbuild.css` from @virgilvox/hackbuild-ui. A custom element whose `.state` is never set stays empty.
|
|
119
|
+
|
|
120
|
+
## Works with
|
|
121
|
+
|
|
122
|
+
- [@hackbuild/drives](../drives/README.md) gives the `Chooser`, `Drives` and `CueLearner` the bars and the table read.
|
|
123
|
+
- [@hackbuild/cameras](../cameras/README.md) gives the `FirstPerson` eye the card draws inside.
|
|
124
|
+
- [@hackbuild/scenario](../scenario/README.md) runs the scripted day of the demo pages.
|
|
125
|
+
|
|
126
|
+
## Changelog and licences
|
|
127
|
+
|
|
128
|
+
Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LICENSE](../../LICENSE)); this README is CC-BY-4.0 with its code samples also MIT.
|
|
77
129
|
|
|
78
130
|
## What is verified, and what is not
|
|
79
131
|
|
|
80
132
|
### Verified on this machine
|
|
81
133
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
restored after), the custom elements, and the Vue components following
|
|
88
|
-
their props.
|
|
89
|
-
- 2026-11-25: `node tools/smoke-views.mjs` passed its three smokes in
|
|
90
|
-
headless Chrome on the built pages (drive bars moved within 3 s, reset
|
|
91
|
-
left the three prior cues, the eye canvas brightness spread 212 of 255,
|
|
92
|
-
measured). The screen gate of the suite passed the three pages at 1440 by
|
|
93
|
-
900 and 390 by 844.
|
|
134
|
+
| date | check | result |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| 2026-11-25 | `npx vitest run packages/agents-views` in happy-dom: utility rows with one current row from a real `Chooser` decision, drive bars that move in place, the pending switch line, the table from a real `CueLearner` with the attn column and reset, the eye card drawing inside a real `FirstPerson` (head at 0.001 during the draw, restored after), the custom elements, the Vue components following their props | 8 of 8 tests pass (counted) |
|
|
137
|
+
| 2026-11-25 | `node tools/smoke-views.mjs` in headless Chrome on the built pages | drive bars moved within 3 s, reset left the three prior cues, eye canvas brightness spread 212 of 255 (measured) |
|
|
138
|
+
| 2026-11-25 | the suite's screen gate on the three pages | passed at 1440 by 900 and 390 by 844 |
|
|
94
139
|
|
|
95
140
|
### Not verified by anything
|
|
96
141
|
|
|
97
142
|
- Any view at real frame rate in a headful browser: nobody has looked.
|
|
98
|
-
- The dichromat matrix and the 1.2 px blur of the demo stand for dog
|
|
99
|
-
vision by eye only (inferred); the views draw whatever `draw` paints.
|
|
143
|
+
- The dichromat matrix and the 1.2 px blur of the demo stand for dog vision by eye only; the views draw whatever `draw` paints.
|
|
100
144
|
|
|
101
145
|
## Size budget
|
|
102
146
|
|
|
103
147
|
| file | gzip (measured) | ceiling |
|
|
104
148
|
|---|---|---|
|
|
105
|
-
| `dist/index.js` (main entry, imports external) | 4,
|
|
106
|
-
| `dist/agents-views.iife.js` (single file build) | 4,
|
|
149
|
+
| `dist/index.js` (main entry, imports external) | 4,420 bytes | 4,641 bytes |
|
|
150
|
+
| `dist/agents-views.iife.js` (single file build) | 4,553 bytes | 4,780 bytes |
|
|
107
151
|
|
|
108
152
|
Measured 2026-11-25 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
109
153
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
110
154
|
5 percent from its row.
|
|
111
|
-
|
|
112
|
-
## Licence
|
|
113
|
-
|
|
114
|
-
Code MIT (`LICENSE`, a copy of the repository root one). This README is CC-BY-4.0, its
|
|
115
|
-
code samples also MIT.
|
|
@@ -42,6 +42,7 @@ var HackbuildAgentsViews = (function(exports) {
|
|
|
42
42
|
if (o.trial) s.trial = o.trial;
|
|
43
43
|
return s;
|
|
44
44
|
}
|
|
45
|
+
/** The explanation under the table: how net strength, attention and delayed credit work. */
|
|
45
46
|
const ASSOCIATIONS_NOTE = "rows are cues, columns are acts. cells show net strength, excitation minus a separate inhibition that fades faster, so an extinguished cue partly comes back after a break. the attn column is each cue's associability: it rises after surprises and falls as the outcome becomes predictable. credit fades with delay, so a slow treat can reward whatever it is doing when it lands. if nothing is strong it offers tricks it was rewarded for before; teach a new word by praising whatever it does.";
|
|
46
47
|
/** hackle's cell: .hb-heat.is-pink fills by --v, the figure paper past 0.55. */
|
|
47
48
|
function paint(td, v) {
|
|
@@ -145,9 +146,10 @@ var HackbuildAgentsViews = (function(exports) {
|
|
|
145
146
|
if (o.pink) s.pink = o.pink;
|
|
146
147
|
return s;
|
|
147
148
|
}
|
|
149
|
+
/** The note under the utility rows while no switch is pending. */
|
|
148
150
|
const DRIVES_NOTE = "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
|
|
149
151
|
/** One gauge row per key, rebuilt only when the keys change. */
|
|
150
|
-
function rows(doc, r, label, items) {
|
|
152
|
+
function rows$1(doc, r, label, items) {
|
|
151
153
|
const keys = items.map((i) => i.k).join("\n");
|
|
152
154
|
if (keys !== r.keys) {
|
|
153
155
|
r.keys = keys;
|
|
@@ -219,14 +221,14 @@ var HackbuildAgentsViews = (function(exports) {
|
|
|
219
221
|
v: Number.isFinite(v) ? Math.max(0, v) : 0
|
|
220
222
|
}));
|
|
221
223
|
const max = Math.max(1, ...u.map((x) => x.v));
|
|
222
|
-
rows(doc, ur, "utility", u.map((x) => ({
|
|
224
|
+
rows$1(doc, ur, "utility", u.map((x) => ({
|
|
223
225
|
...x,
|
|
224
226
|
max,
|
|
225
227
|
cur: x.k === cur
|
|
226
228
|
})));
|
|
227
229
|
note.textContent = s.pending ? `next: ${s.pending.id} in ${Math.round(s.pending.inMs)} ms` : o.note ?? "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
|
|
228
230
|
const pink = new Set(s.pink ?? []);
|
|
229
|
-
rows(doc, dr, "drive", Object.entries(s.drives).map(([k, v]) => ({
|
|
231
|
+
rows$1(doc, dr, "drive", Object.entries(s.drives).map(([k, v]) => ({
|
|
230
232
|
k,
|
|
231
233
|
v: clamp01(v),
|
|
232
234
|
max: 1,
|
|
@@ -250,7 +252,7 @@ var HackbuildAgentsViews = (function(exports) {
|
|
|
250
252
|
const h = o.height ?? 160;
|
|
251
253
|
let sel = o.who.find((x) => x.id === o.selected) ?? o.who[0];
|
|
252
254
|
const hd = el(doc, "div", "hb-inset-hd");
|
|
253
|
-
const title = el(doc, "span", "hb-inset-title", "eye");
|
|
255
|
+
const title = el(doc, "span", "hb-inset-title", o.title ?? "eye");
|
|
254
256
|
const aux = el(doc, "span", "hb-hd-aux");
|
|
255
257
|
const whoGroup = el(doc, "span", "hb-inset-who");
|
|
256
258
|
whoGroup.setAttribute("role", "group");
|
|
@@ -310,6 +312,7 @@ var HackbuildAgentsViews = (function(exports) {
|
|
|
310
312
|
};
|
|
311
313
|
}
|
|
312
314
|
// src/elements.ts
|
|
315
|
+
/** The tag names `defineViews` registers. */
|
|
313
316
|
const ELEMENT_NAMES = {
|
|
314
317
|
drivesBars: "hb-drives-bars",
|
|
315
318
|
associationsTable: "hb-associations-table",
|
|
@@ -387,6 +390,199 @@ var HackbuildAgentsViews = (function(exports) {
|
|
|
387
390
|
}
|
|
388
391
|
});
|
|
389
392
|
}
|
|
393
|
+
// src/map-inset.ts
|
|
394
|
+
const token = (c, name, or) => {
|
|
395
|
+
return (typeof getComputedStyle === "function" ? getComputedStyle(c).getPropertyValue(name).trim() : "") || or;
|
|
396
|
+
};
|
|
397
|
+
/** Draws one frame of the map; returns the mode line, as "212 cells seen". */
|
|
398
|
+
function drawMap(canvas, m) {
|
|
399
|
+
const g = canvas.getContext("2d");
|
|
400
|
+
if (!g) return "";
|
|
401
|
+
const W = canvas.width;
|
|
402
|
+
const H = canvas.height;
|
|
403
|
+
const s = Math.min(W, H) / (m.half * 2);
|
|
404
|
+
const ox = (W - s * m.half * 2) / 2;
|
|
405
|
+
const oy = (H - s * m.half * 2) / 2;
|
|
406
|
+
const pink = token(canvas, "--hb-pink", "#fe0386");
|
|
407
|
+
g.fillStyle = token(canvas, "--hb-paper-sunk", "#efe9db");
|
|
408
|
+
g.fillRect(0, 0, W, H);
|
|
409
|
+
const cw = m.half * 2 * s / m.cols;
|
|
410
|
+
const ch = m.half * 2 * s / m.rows;
|
|
411
|
+
const free = token(canvas, "--hb-paper-raised", "#fffdf7");
|
|
412
|
+
const wall = token(canvas, "--hb-ink", "#1a1a1a");
|
|
413
|
+
let seen = 0;
|
|
414
|
+
for (let k = 0; k < m.cells.length; k++) {
|
|
415
|
+
const v = m.cells[k];
|
|
416
|
+
if (!v) continue;
|
|
417
|
+
seen++;
|
|
418
|
+
g.fillStyle = v === 2 ? wall : free;
|
|
419
|
+
g.fillRect(ox + k % m.cols * cw, oy + Math.floor(k / m.cols) * ch, Math.ceil(cw), Math.ceil(ch));
|
|
420
|
+
}
|
|
421
|
+
const px = (x) => ox + (x + m.half) * s;
|
|
422
|
+
const pz = (z) => oy + (z + m.half) * s;
|
|
423
|
+
g.strokeStyle = pink;
|
|
424
|
+
g.lineWidth = 1.5;
|
|
425
|
+
g.beginPath();
|
|
426
|
+
m.trail.forEach((p, i) => i ? g.lineTo(px(p.x), pz(p.z)) : g.moveTo(px(p.x), pz(p.z)));
|
|
427
|
+
g.stroke();
|
|
428
|
+
g.fillStyle = pink;
|
|
429
|
+
g.beginPath();
|
|
430
|
+
g.arc(px(m.at.x), pz(m.at.z), 4, 0, Math.PI * 2);
|
|
431
|
+
g.fill();
|
|
432
|
+
return `${seen} cells seen`;
|
|
433
|
+
}
|
|
434
|
+
/** Makes `host` the map card; call `frame()` to draw. */
|
|
435
|
+
function mapInset(host, o) {
|
|
436
|
+
const size = o.size ?? 160;
|
|
437
|
+
return eyeInset(host, {
|
|
438
|
+
who: [{
|
|
439
|
+
id: "map",
|
|
440
|
+
label: o.label ?? "map",
|
|
441
|
+
title: "the map he built"
|
|
442
|
+
}],
|
|
443
|
+
draw: (c) => drawMap(c, o.map()),
|
|
444
|
+
title: o.label ?? "map",
|
|
445
|
+
width: size,
|
|
446
|
+
height: size
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
// src/plan-log.ts
|
|
450
|
+
const VIA = {
|
|
451
|
+
reflex: "rules",
|
|
452
|
+
cache: "reused",
|
|
453
|
+
model: "model",
|
|
454
|
+
planner: "planner"
|
|
455
|
+
};
|
|
456
|
+
const call = (s) => `${s.tool}(${s.args.map(String).join(", ")})`;
|
|
457
|
+
/** A plan book keeping at most `max` steps and thoughts (default 200). */
|
|
458
|
+
function planBook(o = {}) {
|
|
459
|
+
const max = o.max ?? 200;
|
|
460
|
+
const now = o.now ?? (() => Date.now());
|
|
461
|
+
let s = {
|
|
462
|
+
plan: "",
|
|
463
|
+
via: "",
|
|
464
|
+
goals: [],
|
|
465
|
+
thoughts: [],
|
|
466
|
+
steps: []
|
|
467
|
+
};
|
|
468
|
+
return {
|
|
469
|
+
push(e) {
|
|
470
|
+
if (e.type === "plan" && "plan" in e) {
|
|
471
|
+
const p = e.plan;
|
|
472
|
+
s = {
|
|
473
|
+
...s,
|
|
474
|
+
via: VIA[e.via] ?? e.via,
|
|
475
|
+
plan: `${p.think ? `${p.think}. ` : ""}${p.do.map(call).join(", ") || "no steps"}`
|
|
476
|
+
};
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
if (e.type === "step" && "result" in e) {
|
|
480
|
+
const r = e.result;
|
|
481
|
+
s = {
|
|
482
|
+
...s,
|
|
483
|
+
steps: [...s.steps.slice(1 - max), {
|
|
484
|
+
t: now(),
|
|
485
|
+
line: `${call(r.step)}: ${r.text}`,
|
|
486
|
+
ok: r.ok
|
|
487
|
+
}]
|
|
488
|
+
};
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
return false;
|
|
492
|
+
},
|
|
493
|
+
think(kind, line) {
|
|
494
|
+
s = {
|
|
495
|
+
...s,
|
|
496
|
+
thoughts: [...s.thoughts.slice(1 - max), {
|
|
497
|
+
t: now(),
|
|
498
|
+
kind,
|
|
499
|
+
line
|
|
500
|
+
}]
|
|
501
|
+
};
|
|
502
|
+
},
|
|
503
|
+
setGoals(lines) {
|
|
504
|
+
s = {
|
|
505
|
+
...s,
|
|
506
|
+
goals: [...lines]
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
state: () => s,
|
|
510
|
+
clear() {
|
|
511
|
+
s = {
|
|
512
|
+
plan: "",
|
|
513
|
+
via: "",
|
|
514
|
+
goals: [],
|
|
515
|
+
thoughts: [],
|
|
516
|
+
steps: []
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
const clock = (t) => new Date(t).toTimeString().slice(0, 8);
|
|
522
|
+
/** Fills an `ol.hb-racklog` with step rows, newest at the foot. */
|
|
523
|
+
function rows(list, steps) {
|
|
524
|
+
const doc = list.ownerDocument;
|
|
525
|
+
const follow = list.scrollHeight - list.scrollTop - list.clientHeight < 8;
|
|
526
|
+
list.classList.toggle("is-empty", !steps.length);
|
|
527
|
+
list.replaceChildren(...steps.map((x) => {
|
|
528
|
+
const li = el(doc, "li", `hb-racklog-row is-${x.ok ? "ok" : "warn"}`);
|
|
529
|
+
li.append(el(doc, "time", "hb-racklog-t", clock(x.t)), el(doc, "span", "hb-racklog-line", x.line), el(doc, "span", "hb-racklog-level", x.ok ? "ok" : "warn"));
|
|
530
|
+
return li;
|
|
531
|
+
}));
|
|
532
|
+
if (follow) list.scrollTop = list.scrollHeight;
|
|
533
|
+
}
|
|
534
|
+
function logList(doc, label, empty) {
|
|
535
|
+
const list = el(doc, "ol", "hb-racklog is-empty");
|
|
536
|
+
list.setAttribute("role", "log");
|
|
537
|
+
list.setAttribute("aria-live", "polite");
|
|
538
|
+
list.setAttribute("aria-label", label);
|
|
539
|
+
list.dataset.empty = empty;
|
|
540
|
+
list.tabIndex = 0;
|
|
541
|
+
return list;
|
|
542
|
+
}
|
|
543
|
+
/** The step log: one rack log row per tool call. */
|
|
544
|
+
function stepLog(host, o = {}) {
|
|
545
|
+
const list = logList(host.ownerDocument, o.label ?? "steps", o.empty ?? "no steps yet.");
|
|
546
|
+
host.replaceChildren(list);
|
|
547
|
+
return {
|
|
548
|
+
update: (steps) => rows(list, steps),
|
|
549
|
+
dispose: () => host.replaceChildren()
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
/** The plan log: last plan with who made it, goals, thoughts, and the step log under them. */
|
|
553
|
+
function planLog(host, o = {}) {
|
|
554
|
+
const doc = host.ownerDocument;
|
|
555
|
+
const col = stack(host);
|
|
556
|
+
const plan = panel(doc, "last plan");
|
|
557
|
+
const planText = el(doc, "p", "hb-note", o.empty ?? "none yet. give an order.");
|
|
558
|
+
const goals = el(doc, "ul", "hb-list");
|
|
559
|
+
plan.root.append(planText, goals);
|
|
560
|
+
const thoughts = panel(doc, "thoughts");
|
|
561
|
+
const thoughtList = el(doc, "ul", "hb-list");
|
|
562
|
+
thoughts.root.append(thoughtList);
|
|
563
|
+
const steps = panel(doc, "steps");
|
|
564
|
+
const list = logList(doc, "steps", "no steps yet.");
|
|
565
|
+
steps.root.append(list);
|
|
566
|
+
col.append(plan.root, thoughts.root, ...o.steps === false ? [] : [steps.root]);
|
|
567
|
+
host.replaceChildren(col);
|
|
568
|
+
return {
|
|
569
|
+
update(s) {
|
|
570
|
+
plan.aux.textContent = s.via;
|
|
571
|
+
planText.textContent = s.plan || (o.empty ?? "none yet. give an order.");
|
|
572
|
+
goals.hidden = !s.goals.length;
|
|
573
|
+
goals.replaceChildren(...s.goals.map((g) => el(doc, "li", "", `goal ${g}`)));
|
|
574
|
+
thoughts.root.hidden = !s.thoughts.length;
|
|
575
|
+
thoughts.aux.textContent = s.thoughts.length ? String(s.thoughts.length) : "";
|
|
576
|
+
thoughtList.replaceChildren(...s.thoughts.slice(-8).reverse().map((x) => {
|
|
577
|
+
const li = el(doc, "li");
|
|
578
|
+
li.append(el(doc, "b", "", x.kind), doc.createTextNode(` ${x.line}`));
|
|
579
|
+
return li;
|
|
580
|
+
}));
|
|
581
|
+
rows(list, s.steps);
|
|
582
|
+
},
|
|
583
|
+
dispose: () => host.replaceChildren()
|
|
584
|
+
};
|
|
585
|
+
}
|
|
390
586
|
// src/single.ts
|
|
391
587
|
if (typeof customElements !== "undefined") defineViews();
|
|
392
588
|
exports.ASSOCIATIONS_NOTE = ASSOCIATIONS_NOTE;
|
|
@@ -395,8 +591,13 @@ var HackbuildAgentsViews = (function(exports) {
|
|
|
395
591
|
exports.associationsState = associationsState;
|
|
396
592
|
exports.associationsTable = associationsTable;
|
|
397
593
|
exports.defineViews = defineViews;
|
|
594
|
+
exports.drawMap = drawMap;
|
|
398
595
|
exports.drivesBars = drivesBars;
|
|
399
596
|
exports.drivesBarsState = drivesBarsState;
|
|
400
597
|
exports.eyeInset = eyeInset;
|
|
598
|
+
exports.mapInset = mapInset;
|
|
599
|
+
exports.planBook = planBook;
|
|
600
|
+
exports.planLog = planLog;
|
|
601
|
+
exports.stepLog = stepLog;
|
|
401
602
|
return exports;
|
|
402
603
|
})({});
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
/** One cue row of the table. */
|
|
1
2
|
export interface AssociationsRow {
|
|
3
|
+
/** the cue, as a word or `gesture:name` */
|
|
2
4
|
cue: string;
|
|
3
5
|
/** net strength per action, 0 to 1, in the order of `actions` */
|
|
4
6
|
values: number[];
|
|
5
7
|
/** how much it still pays attention to the cue, 0 to 1 */
|
|
6
8
|
attention: number;
|
|
7
9
|
}
|
|
10
|
+
/** What the table draws. Built from a CueLearner with `associationsState`, or by hand. */
|
|
8
11
|
export interface AssociationsState {
|
|
12
|
+
/** the act columns */
|
|
9
13
|
actions: string[];
|
|
10
14
|
/** newest last; the table shows the last 16 */
|
|
11
15
|
cues: AssociationsRow[];
|
|
@@ -38,19 +42,25 @@ export declare function associationsState(learner: LearnerLike, o?: {
|
|
|
38
42
|
} | null;
|
|
39
43
|
trial?: string;
|
|
40
44
|
}): AssociationsState;
|
|
45
|
+
/** Options of `associationsTable`. */
|
|
41
46
|
export interface AssociationsOptions {
|
|
42
47
|
/** reset learning was pressed */
|
|
43
48
|
onReset?: () => void;
|
|
44
|
-
/** the explanation under the table;
|
|
49
|
+
/** the explanation under the table; `ASSOCIATIONS_NOTE` by default */
|
|
45
50
|
note?: string;
|
|
46
51
|
/** rows shown, newest last (default 16) */
|
|
47
52
|
limit?: number;
|
|
48
53
|
}
|
|
54
|
+
/** What `associationsTable` returns: the host, an update and a dispose. */
|
|
49
55
|
export interface AssociationsHandle {
|
|
56
|
+
/** the host element */
|
|
50
57
|
readonly root: HTMLElement;
|
|
58
|
+
/** draws a new state */
|
|
51
59
|
update(state: AssociationsState): void;
|
|
60
|
+
/** empties the host */
|
|
52
61
|
dispose(): void;
|
|
53
62
|
}
|
|
63
|
+
/** The explanation under the table: how net strength, attention and delayed credit work. */
|
|
54
64
|
export declare const ASSOCIATIONS_NOTE = "rows are cues, columns are acts. cells show net strength, excitation minus a separate inhibition that fades faster, so an extinguished cue partly comes back after a break. the attn column is each cue's associability: it rises after surprises and falls as the outcome becomes predictable. credit fades with delay, so a slow treat can reward whatever it is doing when it lands. if nothing is strong it offers tricks it was rewarded for before; teach a new word by praising whatever it does.";
|
|
55
65
|
/** Renders the associations panel into `host`. */
|
|
56
66
|
export declare function associationsTable(host: HTMLElement, o?: AssociationsOptions): AssociationsHandle;
|
|
@@ -17,6 +17,7 @@ export function associationsState(learner, o = {}) {
|
|
|
17
17
|
s.trial = o.trial;
|
|
18
18
|
return s;
|
|
19
19
|
}
|
|
20
|
+
/** The explanation under the table: how net strength, attention and delayed credit work. */
|
|
20
21
|
export const ASSOCIATIONS_NOTE = "rows are cues, columns are acts. cells show net strength, excitation minus a separate inhibition that fades faster, so an extinguished cue partly comes back after a break. the attn column is each cue's associability: it rises after surprises and falls as the outcome becomes predictable. credit fades with delay, so a slow treat can reward whatever it is doing when it lands. if nothing is strong it offers tricks it was rewarded for before; teach a new word by praising whatever it does.";
|
|
21
22
|
/** hackle's cell: .hb-heat.is-pink fills by --v, the figure paper past 0.55. */
|
|
22
23
|
function paint(td, v) {
|
package/dist/drives-bars.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface DrivesBarsState {
|
|
|
14
14
|
current?: string;
|
|
15
15
|
/** need per drive, 0 to 1 */
|
|
16
16
|
drives: Record<string, number>;
|
|
17
|
-
/** drive rows drawn pink, as
|
|
17
|
+
/** drive rows drawn pink, such as prey and bond */
|
|
18
18
|
pink?: readonly string[];
|
|
19
19
|
/** a switch that is on its way */
|
|
20
20
|
pending?: {
|
|
@@ -38,6 +38,7 @@ export interface DecisionLike {
|
|
|
38
38
|
export type DrivesLike = Record<string, number> | {
|
|
39
39
|
readonly values: Record<string, number>;
|
|
40
40
|
};
|
|
41
|
+
/** Options of `drivesBarsState`: the clock, the seconds in the act and names of your own. */
|
|
41
42
|
export interface DrivesBarsFrom {
|
|
42
43
|
/** sim seconds now, for the pending switch */
|
|
43
44
|
now?: number;
|
|
@@ -49,19 +50,26 @@ export interface DrivesBarsFrom {
|
|
|
49
50
|
behavior?: string;
|
|
50
51
|
/** a why of your own in place of the decision's */
|
|
51
52
|
why?: string;
|
|
53
|
+
/** drive rows drawn pink */
|
|
52
54
|
pink?: readonly string[];
|
|
53
55
|
}
|
|
54
56
|
/** Builds the view state from a Chooser decision and the drives. */
|
|
55
57
|
export declare function drivesBarsState(d: DecisionLike, drives: DrivesLike, o?: DrivesBarsFrom): DrivesBarsState;
|
|
58
|
+
/** Options of `drivesBars`. */
|
|
56
59
|
export interface DrivesBarsOptions {
|
|
57
60
|
/** the note under the utility rows while no switch is pending */
|
|
58
61
|
note?: string;
|
|
59
62
|
}
|
|
63
|
+
/** What `drivesBars` returns: the host, an update and a dispose. */
|
|
60
64
|
export interface DrivesBarsHandle {
|
|
65
|
+
/** the host element */
|
|
61
66
|
readonly root: HTMLElement;
|
|
67
|
+
/** draws a new state; rows rebuild only when the keys change */
|
|
62
68
|
update(state: DrivesBarsState): void;
|
|
69
|
+
/** empties the host */
|
|
63
70
|
dispose(): void;
|
|
64
71
|
}
|
|
72
|
+
/** The note under the utility rows while no switch is pending. */
|
|
65
73
|
export declare const DRIVES_NOTE = "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
|
|
66
74
|
/** Renders the behavior, utility and drives panels into `host`. */
|
|
67
75
|
export declare function drivesBars(host: HTMLElement, o?: DrivesBarsOptions): DrivesBarsHandle;
|
package/dist/drives-bars.js
CHANGED
|
@@ -21,6 +21,7 @@ export function drivesBarsState(d, drives, o = {}) {
|
|
|
21
21
|
s.pink = o.pink;
|
|
22
22
|
return s;
|
|
23
23
|
}
|
|
24
|
+
/** The note under the utility rows while no switch is pending. */
|
|
24
25
|
export const DRIVES_NOTE = "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
|
|
25
26
|
/** One gauge row per key, rebuilt only when the keys change. */
|
|
26
27
|
function rows(doc, r, label, items) {
|
package/dist/elements.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type AssociationsState } from "./associations-table.js";
|
|
2
2
|
import { type DrivesBarsState } from "./drives-bars.js";
|
|
3
3
|
import { type EyeInsetHandle, type EyeInsetOptions } from "./eye-inset.js";
|
|
4
|
+
/** The tag names `defineViews` registers. */
|
|
4
5
|
export declare const ELEMENT_NAMES: {
|
|
5
6
|
readonly drivesBars: "hb-drives-bars";
|
|
6
7
|
readonly associationsTable: "hb-associations-table";
|
package/dist/elements.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { associationsTable } from "./associations-table.js";
|
|
4
4
|
import { drivesBars } from "./drives-bars.js";
|
|
5
5
|
import { eyeInset } from "./eye-inset.js";
|
|
6
|
+
/** The tag names `defineViews` registers. */
|
|
6
7
|
export const ELEMENT_NAMES = { drivesBars: "hb-drives-bars", associationsTable: "hb-associations-table", eyeInset: "hb-eye-inset" };
|
|
7
8
|
/** Defines the three elements once; safe to call again. */
|
|
8
9
|
export function defineViews(registry = customElements) {
|