Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci

on:
push:
branches: [main]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v4
with:
version: 12.4.2
- uses: actions/setup-node@v5
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm verify
- run: pnpm build
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: release

on:
workflow_dispatch:
inputs:
tag:
description: npm dist-tag (leave empty for latest)
required: false
default: ''

permissions:
contents: read

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v4
with:
version: 12.4.2
- uses: actions/setup-node@v5
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm release -- --yes ${TAG:+--tag "$TAG"}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
TAG: ${{ inputs.tag }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ coverage/
.DS_Store
.env
.env.*
npm_release.token
*.orig
*.rej
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v24.21.0
9 changes: 9 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"printWidth": 100,
"singleQuote": true,
"semi": true,
"trailingComma": "all",
"tabWidth": 2,
"ignorePatterns": ["dist", "coverage", "pnpm-lock.yaml", "packages/avatar/test/fixtures"]
}
3 changes: 3 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignorePatterns": ["dist", "coverage"]
}
29 changes: 29 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# AGENTS.md — BotPixel

Two packages: `packages/morph` (`@botharness/pixel-morph`, generic pixel morph) and `packages/avatar` (`@botharness/pixel-avatar`, the avatar generator and symbols). Both are pure TypeScript with no third-party runtime dependencies; `pixel-avatar` depends only on `pixel-morph` (for `PixelCell` and attribute escaping).

## Commands

```bash
pnpm install
pnpm verify # format:check, lint, typecheck, test
pnpm build
```

## Rules

- Output compatibility is the contract. `packages/avatar/test/fixtures/botharness-golden.json` holds hashes of BotHarness's output for every option, preset, seed, symbol and morph. Do not regenerate it to make a change pass; a visual change to existing options needs a new `rigVersion`/`assetVersion`.
- Keep `pixel-morph` free of avatar concepts.
- Tool-to-symbol mapping belongs to the host app, not to this repo.

## Release

```bash
bash scripts/npm-token.sh # store the npm publish token (gitignored, mode 600)
pnpm release # build + verify, then print what it would publish
pnpm release -- --yes # publish pixel-morph, then pixel-avatar
```

Same flow as BotUI: a granular npm token with _Read and write_ + _Bypass 2FA_, scoped to `@botharness` (a token limited to package names cannot create new packages). To reuse BotUI's saved token, point at it: `NPM_TOKEN_FILE=../BotUI/npm_release.token pnpm release -- --yes`.

In CI, the `release` workflow (manual, Actions → release → Run workflow) does the same with the `NPM_TOKEN` repo secret.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## 0.1.0

- `@botharness/pixel-morph`: pixel pairing, frames, SVG markup and a `requestAnimationFrame` player, extracted from BotHarness; grid size is now an option.
- `@botharness/pixel-avatar`: the 32×32 pixel avatar generator, recipes, presets, name seeding and 16 state symbols, extracted from BotHarness with identical output, including split bangs, side and back hair with bounded eye spacing, feature height and hair length.
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
<p align="center"><img src="assets/banner.png" alt="BotPixel: the wordmark ringed by a hundred generated pixel avatars" width="100%"></p>

# BotPixel

Pixel art that changes shape: a pixel morph engine and a pixel avatar kit for agent products.
Pixel art that changes shape. Two small, dependency-free packages from [BotHarness](https://github.com/BotHarness/BotHarness):

| Package | What it does |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`@botharness/pixel-morph`](packages/morph) | Morphs any set of pixels into any other: every pixel hops along a short arc to a partner and snaps to the grid. Works on plain `{ x, y, c }` cells, so it is not tied to avatars. |
| [`@botharness/pixel-avatar`](packages/avatar) | Seeded, editable 32×32 chibi pixel avatars, plus 16 state symbols (thinking, reading, editing, searching…) the avatar can morph into while an agent works. |

```bash
npm install @botharness/pixel-avatar
```

```ts
import {
faceCells,
pixelAvatarSvg,
pixelSymbolCells,
seededRecipe,
} from '@botharness/pixel-avatar';
import { morphPixels } from '@botharness/pixel-morph';

const recipe = seededRecipe('DeepSeekBot'); // same name, same face, everywhere
element.innerHTML = pixelAvatarSvg(recipe);

// while a tool runs, turn the face into its symbol and back
const layer = element.querySelector<SVGGElement>('[data-avatar-pixel-morph]')!;
await morphPixels(layer, faceCells(recipe), pixelSymbolCells('search', recipe.hairColor), 800)
.finished;
```

<p align="center"><img src="assets/morph-turn.gif" alt="An avatar morphing into thinking, read, edit, shell and search symbols and back" width="288"></p>

While an agent works, its avatar becomes the tool it is using, pixel by pixel, and turns back into a face when the turn ends. Several bots each follow their own tool:

<p align="center"><img src="assets/morph-crew.gif" alt="Six avatars morphing into different tool symbols out of step" width="100%"></p>

## How the morph works

1. **Pair.** Both pixel sets are sorted by angle around their own centroid, then matched by proportional index. Neighbours fly to neighbours, and the smaller set is reused, so pixels split or merge instead of popping.
2. **Fly.** Each pair eases (`easeInOutCubic`) from start to end, hopping by `sin(kπ)·arc`, starting in 4×4 clumps from the top rows down.
3. **Snap.** Every frame rounds to whole grid cells and switches colour halfway, so it stays pixel art the whole way.

The engine does not know what it is drawing. Here it morphs one generated face straight into the next:

<p align="center"><img src="assets/morph-faces.gif" alt="Generated faces morphing into one another" width="224"></p>

`planPixels` and `pixelFrame` are pure functions, so frames can be rendered offline (video, GIF, canvas) as well as with `morphPixels` in the browser.

## Custom avatars

A recipe is plain JSON (`head`, `hair`, `eyes`, `outfit`, `accessory`, colours…). `AVATAR_PARTS`, `AVATAR_SWATCHES` and `AVATAR_PRESETS` list every option, so an app can build its own avatar editor on top; `isPixelAvatarRecipe` validates what users save.

Hosts add their own state symbols with `symbolArtCells(rows, color)`, which draws 24×24 character art (`A` body, `H` highlight) in the built-in style.

## Contributing

```bash
pnpm install
pnpm verify # format, lint, typecheck, test
pnpm build
pnpm assets # re-render the README banner and GIFs (needs ffmpeg)
```

- New eyes, brows, mouths and symbols are character art: add rows, and the diff shows the picture.
- `packages/avatar/test/fixtures/botharness-golden.json` locks the output of every existing option and seed. Saved avatars must not change, so a PR that breaks it needs a new recipe version, not a new fixture.

## License

MIT
15 changes: 15 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p align="center"><img src="assets/banner.png" alt="BotPixel" width="100%"></p>

# BotPixel

会变形的像素画。来自 [BotHarness](https://github.com/BotHarness/BotHarness) 的两个零依赖小包:

- **`@botharness/pixel-morph`**:任意一组像素变成另一组像素。每个像素按极角配对,沿小弧线跳到目标,并始终对齐网格。只认 `{ x, y, c }`,不限于头像。
- **`@botharness/pixel-avatar`**:按名字生成、可编辑的 32×32 Q 版像素头像,加上 16 个状态符号(思考、读文件、编辑、搜索……),Agent 工作时头像可以变形成这些符号。

<p align="center"><img src="assets/morph-turn.gif" alt="头像变形成各个工具的符号再变回来" width="288"></p>
<p align="center"><img src="assets/morph-crew.gif" alt="多个头像各自变形成不同工具的符号" width="100%"></p>

用法、原理和贡献方式见 [README.md](README.md)。

已保存的头像不能变:`packages/avatar/test/fixtures/botharness-golden.json` 锁住了每个选项和种子的输出。
Binary file added assets/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/morph-crew.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/morph-faces.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/morph-turn.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "botpixel",
"version": "0.0.0",
"private": true,
"description": "BotPixel — a pixel morph engine and a pixel avatar kit for agent products",
"type": "module",
"scripts": {
"build": "pnpm -r --filter \"./packages/*\" build",
"typecheck": "tsc --noEmit -p packages/morph && tsc --noEmit -p packages/avatar",
"lint": "oxlint",
"lint:fix": "oxlint --fix",
"format": "oxfmt --write .",
"format:check": "oxfmt --check .",
"test": "vitest run",
"test:watch": "vitest",
"assets": "pnpm build && node scripts/readme-assets.mjs",
"verify": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm test",
"release": "node scripts/release.mjs"
},
"devDependencies": {
"@types/node": "^22.20.2",
"oxfmt": "^0.68.0",
"oxlint": "^1.50.0",
"tsdown": "^0.20.0",
"typescript": "7.0.2",
"vitest": "^4.0.18"
},
"engines": {
"node": ">=22"
},
"packageManager": "pnpm@12.4.2"
}
21 changes: 21 additions & 0 deletions packages/avatar/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 BotHarness

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions packages/avatar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @botharness/pixel-avatar

Seeded, editable 32×32 chibi pixel avatars with state symbols they can morph into.

```ts
import {
pixelAvatarSvg,
seededRecipe,
faceCells,
pixelSymbolCells,
} from '@botharness/pixel-avatar';

const recipe = seededRecipe('DeepSeekBot');
const svg = pixelAvatarSvg(recipe); // 32×32 viewBox, crisp edges, no ids or scripts
```

- `seededRecipe(name)`: the same name always gives the same face. `createSeededRecipe(namespace)` makes a factory with its own set of faces.
- `AVATAR_PARTS`, `AVATAR_SWATCHES`, `AVATAR_PRESETS`, `DEFAULT_RECIPE`: everything an editor needs.
- `isPixelAvatarRecipe`, `canonicalRecipe`: validate and normalise saved recipes.
- `AVATAR_HAIR_PARTS`, `AVATAR_RANGES`, `detailedRecipe(recipe)`: optional finer controls. A recipe may carry `bangs`, `sideHair`, `backHair`, `spacing`, `height` and `hairLength`, all six or none; `detailedRecipe` derives them from the plain `hair` so an editor can start from what is on screen. Recipes without them render exactly as before.
- `faceCells`, `pixelSymbolCells`, `symbolArtCells`: pixels for [`@botharness/pixel-morph`](../morph).
- `pixelAvatarSvg(recipe, { turns, classPrefix })`: optional pre-rendered head turns, and rig layer classes (`<prefix>-body`, `-head`, `-face`, `-gaze`, `-blink`) for CSS animation.
49 changes: 49 additions & 0 deletions packages/avatar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@botharness/pixel-avatar",
"version": "0.1.0",
"description": "Seeded, editable 32×32 chibi pixel avatars with state symbols that morph in and out",
"keywords": [
"agent-ui",
"avatar",
"generator",
"identicon",
"pixel-art",
"svg"
],
"homepage": "https://github.com/BotHarness/BotPixel",
"bugs": {
"url": "https://github.com/BotHarness/BotPixel/issues"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/BotHarness/BotPixel.git",
"directory": "packages/avatar"
},
"files": [
"dist"
],
"type": "module",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "tsdown",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@botharness/pixel-morph": "workspace:^"
},
"devDependencies": {
"tsdown": "^0.20.0",
"typescript": "^5.9.3"
}
}
Loading
Loading