A little robot for your website, with a brain of his own.
Box walks along the bottom of your page. He looks at your headings, reads along when someone selects text, waves when the cursor comes close, jumps when you click him, and nods off when your visitor goes quiet to read.
Nib is the brain that decides all that. It's a tiny neural network of 6,839 numbers, and it runs right in your visitor's browser. Nothing is downloaded at run time, and nothing is sent anywhere.
He comes in five bodies, all driven by the same brain:
Put these two lines just before </body>:
<script src="https://cdn.jsdelivr.net/gh/erdemozkan/boxnib@v0.1.1/dist/boxnib.min.js"
integrity="sha384-daVl2Ssb2hqKy1rzY9t5ZrNpynnGqH8l/RGMBbDbacyMSUM8EaXwsUZiQKzNgsze" crossorigin="anonymous"></script>
<script>BoxNib.start()</script>
That's it. Refresh the page and say hello.
The integrity hash makes the browser refuse the file if it ever changes, so pin it together with the version.
Rather host it yourself? Download dist/boxnib.min.js and point the src at your copy.
It's one file of 108 KB (55 KB gzipped) with the brain inside.
Pick a body and give him your site's colours:
BoxNib.start({
skin: 'pixel', // box, pixel, wire, doodle or puppet
ink: '#f1efe8', // outlines and text
paper: '#1d2027', // fills
accent: '#ffb02e' // eyes, lights, highlights
});
Teach him a few lines about your own content:
BoxNib.start({
lines: { greet: ['Welcome to the shop!', 'Hi! {name} here.'] },
about: [
['pricing', ['Free! Well, nearly.']],
[/bread|sourdough/i, ['I can almost smell it.']]
]
});
Keep him inside one part of the page, like a hero banner:
BoxNib.create({ container: '#hero', skin: 'wire' });
If your site has a strict Content-Security-Policy, skip the second script tag and set the options on the first one:
<script src="boxnib.min.js" data-boxnib data-skin="doodle" data-accent="#0e7a5a"></script>
He needs no 'unsafe-inline', no 'unsafe-eval' and no network access. His styles live in his own shadow
root, so your CSS can't break him and his can't leak onto your page.
| Option | What it does |
|---|---|
size: 80 |
Make him smaller or bigger (height in pixels) |
bottom: 60 |
Lift him above a cookie bar or bottom menu |
mind: 'nib' |
Use the brain without the memory (or 'random' for plain dice) |
memory: false |
Never remember anything about the visitor |
storage: false |
Never write anything to the visitor's device |
annotate: false |
Hide the name tags and the "what I'm thinking" labels |
zIndex: 50 |
Put him behind something (the default is 1000) |
There are plenty more, plus the full API, in docs/OPTIONS.md.
Nib is two tiny networks. The first takes 60 numbers describing the moment (where Box is, where the cursor is, what's on screen, what he did last) and picks a move: walk, look, talk, wave, jump, idle or doze. The second scores each thing on screen to decide what he looks at.
They were trained by watching a teacher. I wrote a page of plain rules for how a charming robot should behave, ran it on 40,000 made-up page situations, and had Nib learn to copy it. On situations it had never seen, Nib picks the same move as the teacher 92% of the time.
In the browser it runs on the graphics card with WebGPU when it can, and on the processor when it can't. Click the coloured mind tag above his head to see what he chose and how sure he was.
Nib HD gives Box a memory. Every moment becomes a pattern of 10,240 bits, and similar moments make similar patterns. When a visitor reacts well to something (comes closer, clicks him, clicks what he pointed at), he remembers. Next time a moment feels familiar, he leans towards what worked. He also notices what people click and select, and points out related things.
It's all stored in the visitor's own browser. They can wipe it any time: click the mind tag and press Forget me.
- No network requests, cookies or analytics. The brain ships inside the script.
- The memory stays in the visitor's localStorage, and never leaves it.
- Use
memory: falseorstorage: falseif you'd rather he remembered nothing. If your visitors are in the EU or UK, that's worth thinking about until they've agreed to non-essential storage.
Clone the repo, run python3 -m http.server, and open http://localhost:8000/examples/. You'll find:
- a plain page
- a styled dark page
- a robot in a box
- a strict-CSP page
- an ES module version
- the whole lineup
He's happy on phones too.
You don't have to. But if you'd like Box to behave differently, change the rules in training/train.py, then:
python3 training/train.py # about a minute; needs numpy
node build.mjs # rebuilds dist/
node training/check_parity.mjs # makes sure JavaScript and Python agree
You only need Node 22 or newer. There are no npm packages to install.
node build.mjs # builds dist/
node test/browser.mjs # opens every example in headless Chrome and checks for errors
MIT. Do what you like with him; just keep the licence with it.