Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
be001e1
feat(buddy): thread storage for saved chats
codemug Nov 21, 2026
573e778
feat(buddy): search over tools and skills (MiniSearch 7.2.0)
codemug Nov 21, 2026
d4ce9ba
feat(buddy): skills.md parser, checker and capped renderer
codemug Nov 21, 2026
de0c3b9
feat(buddy): flat tool arguments with teaching errors
codemug Nov 21, 2026
1e76e8b
feat(buddy): tool catalog with signatures and describe text
codemug Nov 21, 2026
0f6e7a2
feat(buddy): repair the call_tool mistakes small models make
codemug Nov 21, 2026
2d89a67
feat(buddy): desktop pack and the agent build step
codemug Nov 21, 2026
bcaaf7f
feat(buddy): Files pack
codemug Nov 21, 2026
e4f5764
feat(desktop): window.pcHost, a promise API for Buddy's desktop tools
codemug Nov 21, 2026
9d44ab3
feat(buddy): the six meta tools
codemug Nov 21, 2026
4c1e78a
feat(buddy): repair tool names that add or drop an _app suffix
codemug Nov 21, 2026
07121c0
feat(buddy): agent mode, Buddy runs WebPC through six meta tools
codemug Nov 21, 2026
47b406e
feat(buddy): safety policy for agent actions
codemug Nov 21, 2026
56017f9
feat(buddy): round-robin scheduler for background chats
codemug Nov 21, 2026
fd283e0
feat(buddy): Buddy uses the safety policy for the live backend
codemug Nov 21, 2026
9c6087d
feat(buddy): ArtCraft adapter and the GridCraft pack
codemug Nov 21, 2026
d1f1533
feat(buddy): per-call effects and ctx.craft; Buddy edits a real GridC…
codemug Nov 21, 2026
c576625
feat(buddy): one shared model behind every chat thread
codemug Nov 21, 2026
5e06192
feat(buddy): Excalidraw pack and the inner-frame app helper
codemug Nov 21, 2026
0cc73f4
feat(buddy): ArtCraft packs for eight more apps
codemug Nov 21, 2026
0fe2d5d
feat(buddy): CyberChef pack
codemug Nov 21, 2026
eccd129
feat(buddy): Docs pack
codemug Nov 21, 2026
16e3dca
feat(buddy): ctx.files reads and writes binary files
codemug Nov 21, 2026
0c8a40f
fix(buddy): serve every module Buddy's page imports
codemug Nov 21, 2026
2bd0da0
feat(desktop): the Buddy button shows chats running in the background
codemug Nov 21, 2026
aecbcbf
feat(buddy): saved chats that keep running in the background
codemug Nov 21, 2026
ce9bfb8
feat(buddy): Media Player and Terminal packs
codemug Nov 21, 2026
6435dd9
feat(buddy): Packet Viewer pack
codemug Nov 21, 2026
2075b7f
fix(buddy): Docs can type into a fresh document
codemug Nov 21, 2026
ca7c6eb
feat(buddy): BeepBox pack
codemug Nov 21, 2026
606ac86
fix(nettools): show DNS records, and add the Network Tools pack
codemug Nov 21, 2026
b752ef4
feat(buddy): open and save files in every ArtCraft app
codemug Nov 22, 2026
51ee410
feat(buddy): SQLiteViz pack
codemug Nov 22, 2026
333a5f9
fix(buddy): send "open the app" requests to desktop.open_app
codemug Nov 22, 2026
e2bc4f1
feat(buddy): measured defaults for small models, and the eval harness
codemug Nov 22, 2026
1523077
fix(buddy): pack fixes from the eval traces
codemug Nov 22, 2026
b3f873b
fix(buddy): an unexpected tool field names the fields the tool takes
codemug Nov 22, 2026
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ public/pc/vendor/

# Generated from catalog.yaml (npm run catalog)
src/scripts/pc/registry.generated.json
src/apps/ai-agent/generated/

# Upgrader output
upgrade-plan.json
upgrade-report.md

# Upstream app icons placed by scripts/catalog/icons.mjs (pinned in catalog.yaml)
public/pc/icons/

# Buddy eval run results (scripts/agent/eval.mjs)
tests/agent-eval/results/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
| **Developer** | Terminal (Alpine Linux) · Packet Viewer (Wireshark dissectors) · VS Code (opens vscode.dev) |
| **Utilities** | Files · Media Player · SQLiteViz · CyberChef · Network Tools (DNS, RDAP, global ping, subnets, password strength, age encryption) · VERT (opens vert.sh) |

## Buddy

Buddy is the assistant behind the taskbar's Buddy button: a panel over the right third of the desktop, not a window. It runs a local model by default (Qwen3.5 0.8B or 2B, or LFM3 1.7B, the default; the weights download once after you load the model and are cached in this browser) and can use an optional cloud model with your own key, opt-in per session and never persisted.

Buddy acts through a tool catalog of 257 tools in 25 packs, built by `npm run catalog` from the source packs in `agent/`: the desktop and its windows, the Files area, and every enabled app. It finds what to do with six meta tools:

- `lookup_skill_index`: search the skill wiki for how to do a task.
- `read_skill`: read one skill by path, or one of its sections.
- `find_in_skill`: find matching lines inside one skill.
- `find_tool`: search the tool catalog for what a tool does.
- `describe_tool`: show a tool's full parameter list, effect and call template.
- `call_tool`: call a catalog tool with its own parameters.

The action policy allows reads and asks before destructive or external actions, and asks before a change in a turn that took in untrusted content, such as a file read whose name was not in the user's message; an approval already given this turn for the same call is not asked again (`src/apps/ai-agent/runtime/policy.mjs`). `scripts/agent/eval.mjs` runs 60 tasks from `tests/agent-eval/tasks.yaml` against a running preview; the contributor guide for the packs is [agent/README.md](agent/README.md).

## How it ships

```mermaid
Expand Down
155 changes: 155 additions & 0 deletions agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Buddy app packs

How Buddy's tools and skills are built, and how to add a pack for an app.
Every pack is plain ES modules that run in the browser and in Node, so the
unit tests need no browser. The build reads the packs; nothing here is a page.

## Layout

- `agent/system/`, `agent/desktop/`, `agent/files/`: the core packs, always on.
The desktop pack drives `window.pcHost` (the desktop installed by
`src/scripts/pc/desktop.js`), the files pack the Files store.
- `agent/apps/<id>/tools.js`: the pack for one catalog app, included only when
the app has `enabled: true` in `catalog.yaml`.
- `agent/apps/<id>/skills.md`: the skills the wiki serves for that app.
- `agent/shared/`: helpers the packs share, such as `craft.js` (the Craft page
protocol), `inner-app.js` (digging into an app's iframe) and `craft-files.js`
(the Files open path).

The build is `npm run catalog`, which runs `scripts/catalog/catalog.mjs` (validates
`catalog.yaml` and writes the desktop registry) and then `scripts/agent/build.mjs`
(validates the packs and writes `src/apps/ai-agent/generated/`). For each pack it
checks that `tools.js` exports `pack = { id }` matching its directory, that every
tool has a `run` function and a non-empty `purpose` and `when`, that the param
specs are flat and well-formed, that every `examples` entry passes arg checking,
and that every `call_tool` line in a skill's Steps passes `checkArgs` against the
tool's real params. It writes `catalog.json` (the tool catalog), `skills.json`,
`search-tools.json` and `search-skills.json` (the search indexes), `packs.mjs`
(lazy imports of each pack) and `INDEX.md`. The generated directory is gitignored;
commit nothing from it. Run the build after changing a pack.

## The tool spec (tools.js)

```js
{
name: 'desktop.open_app',
purpose: 'Start an app on the desktop.',
when: 'Use when the user says start, launch or open, naming an app such as Files or GridCraft.',
params: { app: APP },
effect: 'change',
needs: ['host'],
examples: [{ args: { app: 'gridcraft' }, says: 'Launch GridCraft' }],
run: async (args, ctx) => call(ctx, host => host.open(args.app)),
},
```

- `name`: `<pack>.<verb_noun>`, unique across all packs.
- `purpose`: one line, what the tool does.
- `when`: starts with "Use when", at most 120 characters: the user phrasings that
should reach this tool.
- `params`: a flat object of param specs. Each has a `type` (one of the types in
`src/apps/ai-agent/runtime/args.mjs` TYPES: `string`, `text`, `integer`,
`number`, `boolean`, `enum`, `list`, `table`, `path`), a `description`, and
optionally `required`, `values` (for `enum`, or the live `apps` list),
`default`, `min`, `max`. In the excerpt, `APP` is the pack's shared
`{ type: 'enum', values: 'apps', ... }` spec for an app id.
- `effect`: `read`, `change`, `destructive` or `external`. The policy allows
reads and asks before destructive or external calls.
- `effectFor` (optional): a function of the args that returns the effective
effect, for a tool whose danger depends on an argument. The GridCraft pack
marks `file.new` and `sheet.delete` destructive this way.
- `needs` (optional): the capabilities the runtime must provide (`host`,
`files`, `app:<id>`), so the tool is a clean not_available error outside WebPC.
- `examples`: args a user utterance would produce, with the utterance in `says`.
The build validates them against the params.
- `run(args, ctx)`: the body. `ctx.host` is `window.pcHost`, `ctx.files` is the
Files store behind the access policy, and `ctx.craft(id)` is the app's page
API, opened if needed.

## Teaching errors

Wrap every failure the model can fix in a ToolError:
`new ToolError(type, message, fix)`, where `fix` is one call line the model can
copy (the signature is in `src/apps/ai-agent/runtime/args.mjs`). Small models
copy call lines. A generic error makes them guess and loop. The open_file
not_found teaching error in `agent/shared/craft-files.js`:

```js
throw new ToolError('not_found',
`${path} is not in Files. To open ${title} itself, use desktop.open_app; to open a file, find it first with files.find.`,
`call_tool tool=desktop.open_app app=${id}`);
```

The message says both ways out; the fix line points the model at the tool that
opens the app itself.

## skills.md

One `## ` block per skill. Before the first section come four metadata lines
(all required, and the slug must be unique, lowercase words with hyphens):

```md
## Open a file from Files
slug: open-a-file-from-files
summary: Open audio, MIDI or a session that is stored in Files in SoundCraft.
keywords: open, load, from files, audio, midi, session, scraftz, import
tools: desktop.open_app, soundcraft.open_file

When: the user wants to open audio, MIDI or a SoundCraft session that is stored in Files.
Steps:
1. call_tool tool=desktop.open_app app=soundcraft
2. call_tool tool=soundcraft.open_file path=/SoundCraft/session.scraftz
Check: soundcraft.status shows the wrapper opened the file; the session or audio appears in the editor.
Gotchas: change path= to the Files path of an audio, MIDI or .scraftz session file; SoundCraft stays silent until the wrapper's Enable audio button is clicked.
```

Then the sections: `When:` one line, the user intent. `Steps:` numbered
`call_tool` lines, the exact calls in order. The build checks every line against
the real tool, so a renamed param breaks the build. `Check:` how to verify the
end state. `Gotchas:` what the model gets wrong and how to stay out of it.
`parseSkills` and `checkSkills` in `src/apps/ai-agent/runtime/skills.mjs` are
the parsers and validators.

## Rules learned live

- Never put a realistic example value in a param description: `describe_tool` shows descriptions verbatim and the model copies them into its calls. Examples and skill steps reach the model as templates (`key=<key>`), but teaching-error fix lines are built from the first example's values, so keep those neutral too.
- Read the live app state, not a cached view.
- Most apps run in an inner iframe of their wrapper page: use the dig-in and poll from `agent/shared/inner-app.js`.
- Messages from another frame arrive in that frame's realm, so do not use `instanceof ArrayBuffer` on them.
- Wait for the app to finish (open, debounce) before you read.

## Testing

One test file per pack: `tests/agent-pack-<id>.test.mjs`, run with
`node --test tests/agent-pack-<id>.test.mjs`. The test builds a fake window
(the wrapper window, the `#editor` frame, the app's page API) and drives the
real `tools.js` against it, and it runs the real build validators
(`specErrors`, `checkArgs`, `parseSkills`, `checkSkills`) over the pack's spec
and skills. List every API name the fake assumes in a comment at the bottom of the
test, and check each tool on the real page before merging: a fake that mirrors
your own assumptions proves only the code path.

## The eval

`scripts/agent/eval.mjs` runs the task suite in `tests/agent-eval/tasks.yaml`
(60 tasks: A desktop and files, B ArtCraft, C other apps, D cross-app) against a
running preview. It starts no server: a preview must already be serving the
desktop at `--base` (default `http://127.0.0.1:4333`), and the prepared
`app.js` must carry the `?eval=1` trace hook (run the build, then restart the
preview). Usage:

```
node scripts/agent/eval.mjs --model lfm3-1.7b --set A [--limit N] [--prefetch on|off] [--base URL]
```

`--model` is the key from `src/apps/ai-agent/models.js` (default `lfm3-1.7b`);
`--set` runs one set and `--task <id>` one task; `--limit` caps the count;
`--prefetch on` loads the Buddy document with `?prefetch=1`, the eval-only
switch that puts the best skill's steps in the turn (Buddy's default is off).
Chrome runs headless with WebGPU and a persistent profile
(`/tmp/webpc-eval-profile`), so model downloads are cached across runs.
Results go to `tests/agent-eval/results/<model>-<set>-<timestamp>.json`:
per-task the tools seen, the end-state check, seconds and rounds, plus a
summary with the success rate, the tool accuracy and the median seconds.
A task passes when its end-state check holds and every expected tool was seen,
in order (a subsequence match, so extra calls in between do not fail it).
78 changes: 78 additions & 0 deletions agent/apps/beepbox/skills.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Get the song link
slug: get-the-song-link
summary: Get the current BeepBox song hash (its share URL) and tempo.
keywords: song link, share, hash, copy, tempo, bpm, song data
tools: desktop.open_app, beepbox.get_song

When: the user asks for the song link, or before loading a different song.
Steps:
1. call_tool tool=desktop.open_app app=beepbox
2. call_tool tool=beepbox.get_song
Check: the result has the hash (the part after # in a share URL) and the tempo in BPM.
Gotchas: the hash is the live song, so it is fresh after any edit; give the hash to the user as the part after # in a BeepBox URL.

## Load a song from a link
slug: load-a-song-from-a-link
summary: Open a BeepBox song from a share URL or a bare hash.
keywords: load, open, import, paste link, song url, share url, song
tools: desktop.open_app, beepbox.load_song

When: the user has a BeepBox song link or hash and wants it opened.
Steps:
1. call_tool tool=desktop.open_app app=beepbox
2. call_tool tool=beepbox.load_song hash=sJ3mR8k2q
Check: beepbox.get_song returns the same hash.
Gotchas: change hash=; a full URL is fine, the part after # is what matters; loading replaces the current song in the editor.

## Start a new song
slug: start-a-new-song
summary: Clear the editor to a blank song; the current song is lost unless its hash was saved.
keywords: new song, blank, fresh, start over, clear, reset
tools: desktop.open_app, beepbox.new_song

When: the user wants a fresh BeepBox song and agreed to lose the current one.
Steps:
1. call_tool tool=desktop.open_app app=beepbox
2. call_tool tool=beepbox.get_song
3. call_tool tool=beepbox.new_song
Check: beepbox.get_song returns a different hash (the blank song).
Gotchas: call get_song first and keep the old hash in the reply so the user can get the previous song back; this tool cannot undo.

## Change the tempo
slug: change-the-tempo
summary: Set the song tempo in beats per minute.
keywords: tempo, bpm, speed up, slow down, faster, slower, beats per minute
tools: desktop.open_app, beepbox.set_tempo

When: the user wants the song played faster or slower.
Steps:
1. call_tool tool=desktop.open_app app=beepbox
2. call_tool tool=beepbox.set_tempo bpm=180
Check: the result reports the new tempo and beepbox.get_song agrees.
Gotchas: change bpm=; the app allows 30 to 300 BPM; tempo affects playback speed, not the notes.

## Play the song
slug: play-the-song
summary: Play the current song from the start position.
keywords: play, listen, hear, start playback, audition, sound
tools: desktop.open_app, beepbox.play

When: the user wants to hear the song.
Steps:
1. call_tool tool=desktop.open_app app=beepbox
2. call_tool tool=beepbox.play
Check: the result says playing is true.
Gotchas: if the app muted the audio (the WebPC audio guard), tell the user to check the speaker in the BeepBox window; playing can be stopped with beepbox.stop.

## Stop the song
slug: stop-the-song
summary: Stop the song that is playing.
keywords: stop, pause, halt, quiet, silence, end playback
tools: desktop.open_app, beepbox.stop

When: the user wants playback to stop.
Steps:
1. call_tool tool=desktop.open_app app=beepbox
2. call_tool tool=beepbox.stop
Check: the result says playing is false.
Gotchas: stopping is a no-op with a clear result when nothing is playing; the song position is kept for the next play.
Loading
Loading