@clothespin/pi-pippi 0.0.0-stage → 0.1.0
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/CHANGELOG.md +13 -0
- package/README.md +415 -2
- package/approvals.ts +552 -0
- package/ble.ts +1062 -0
- package/bluez.ts +962 -0
- package/bridge.ts +1759 -0
- package/claims.ts +453 -0
- package/index.ts +827 -0
- package/package.json +53 -4
- package/protocol.ts +593 -0
- package/simulate.ts +249 -0
- package/state.ts +91 -0
- package/transport.ts +183 -0
- package/usage.ts +959 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 - 2026-12-02
|
|
4
|
+
|
|
5
|
+
First public release of the pi bridge for the pippi desk pet.
|
|
6
|
+
|
|
7
|
+
- `/pippi scan` / `/pippi connect` pair a pet over Bluetooth (Nordic UART).
|
|
8
|
+
- Session activity — idle, busy, attention, completed — streams to the device.
|
|
9
|
+
- Risky tool calls raise an approval on the pet; A answers yes, B no, and
|
|
10
|
+
the first answer across windows wins.
|
|
11
|
+
- `/pippi approvals off|dangerous|all`, `/pippi name`, `/pippi tag`,
|
|
12
|
+
`/pippi push` (character packs), `/pippi status`.
|
|
13
|
+
- Custom character packs flash over BLE or USB (`flash_character.py`).
|
package/README.md
CHANGED
|
@@ -1,3 +1,416 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi ↔ Pippi desk-pet bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [pi](https://github.com/earendil-works/pi) extension that streams a live pi
|
|
4
|
+
session to an M5Stack desk pet over Bluetooth Low Energy, and turns the
|
|
5
|
+
pet's **A** / **B** buttons into approve / deny for risky tool calls.
|
|
6
|
+
|
|
7
|
+
It speaks the agent-neutral protocol in
|
|
8
|
+
[REFERENCE.md](../../docs/REFERENCE.md), so the firmware needs no changes — this
|
|
9
|
+
is the "pi" row in [BRIDGES.md](../../BRIDGES.md).
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
pi session ──events──▶ bridge.ts ──NDJSON──▶ ble.ts ──BLE──▶ M5StickS3
|
|
13
|
+
▲ (in process) │
|
|
14
|
+
│ └──D-Bus──▶ BlueZ
|
|
15
|
+
{"cmd":"permission", …} ◀────────────────┘
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Why the radio speaks D-Bus
|
|
19
|
+
|
|
20
|
+
pi runs in Node, and Node has no maintained cross-platform BLE stack that
|
|
21
|
+
handles LE Secure Connections pairing + bonding. On Linux the answer is BlueZ,
|
|
22
|
+
which is a system service: every radio call is a D-Bus method call. So rather
|
|
23
|
+
than keep a second language alive for the length of one method call, `bluez.ts`
|
|
24
|
+
marshals the D-Bus wire format itself — no native modules, no venv, nothing to
|
|
25
|
+
install — and `ble.ts` turns that into a link. If the bus misbehaves the bridge
|
|
26
|
+
degrades to "disconnected"; it never takes a pi session down with it.
|
|
27
|
+
|
|
28
|
+
`transport.ts` is the seam. `simulate.ts` is a pippi made of TypeScript that
|
|
29
|
+
answers the same calls, which is what `--simulate` and the offline tests run
|
|
30
|
+
against.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
Requirements: Node 20+ (pi itself) and, for a real pippi on Linux, BlueZ with
|
|
35
|
+
D-Bus access. Nothing has to be installed for the radio — the desktop session is
|
|
36
|
+
already talking to BlueZ.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Register the extension (writes to ~/.pi/agent/settings.json)
|
|
40
|
+
pi install npm:@clothespin/pi-pippi
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then `/reload` inside pi (or start a new session) and run `/pippi on`. Check what
|
|
44
|
+
pi has registered with `pi list`, and undo with
|
|
45
|
+
`pi remove npm:@clothespin/pi-pippi`. Working from a checkout instead of npm?
|
|
46
|
+
`pi install ./bridges/pi` loads it straight from the directory.
|
|
47
|
+
|
|
48
|
+
It loads in place rather than being copied, because `package.json` declares the
|
|
49
|
+
entry point under `pi.extensions` — so editing these files and running `/reload`
|
|
50
|
+
is the whole development loop. `PI_PIPPI_DISABLE=1` loads the extension but keeps
|
|
51
|
+
it off. For a single throwaway trial without touching settings, use `-e`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pi -e ./bridges/pi
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Use
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
/pippi scan find pippis (filters by NUS service UUID)
|
|
61
|
+
/pippi connect → pick one, or: /pippi connect AA:BB:CC:DD:EE:FF
|
|
62
|
+
/pippi status link, battery, encryption, tokens, last snapshot
|
|
63
|
+
/pippi approvals <policy> off | dangerous | all
|
|
64
|
+
/pippi tag [name] what this window is called on the pet
|
|
65
|
+
/pippi name <pet> rename the pet on the device
|
|
66
|
+
/pippi owner [name] whose desk this is (git user.name by default)
|
|
67
|
+
/pippi push <folder> stream a GIF character pack to the device
|
|
68
|
+
/pippi ping poll {"cmd":"status"} and print the reply
|
|
69
|
+
/pippi forget unpair and stop auto-connecting
|
|
70
|
+
/pippi on | off disable the bridge without unloading it
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Nothing is sent until this session attaches. A session does not attach by
|
|
74
|
+
starting — it attaches when you type in it (see
|
|
75
|
+
[Multiple pi sessions](#multiple-pi-sessions)), or on `/pippi connect` / `/pippi
|
|
76
|
+
on`. Once attached, the bridge pushes a snapshot on change, a keepalive every
|
|
77
|
+
10s, and polls `status` every 15s — the budgets `REFERENCE.md` asks for. The
|
|
78
|
+
footer shows `● Pi-A3F2 · 81% · busy` while linked, and
|
|
79
|
+
`○ pippi: standby (Enter to attach)` while it is waiting for you.
|
|
80
|
+
|
|
81
|
+
### Approvals
|
|
82
|
+
|
|
83
|
+
`approvals: dangerous` (the default) is a deny-list, not a sandbox — pi
|
|
84
|
+
still owns its own safety story. It gates `bash` calls matching a risky
|
|
85
|
+
pattern (recursive delete, `sudo`/`doas`/`pkexec`, `dd` to a raw device,
|
|
86
|
+
`mkfs`, shutdown/reboot, `curl … | sh`, `git push --force`,
|
|
87
|
+
`git reset --hard` / `clean -fd`, `chmod -R`/`777`, writes under `/etc` or
|
|
88
|
+
`/usr`, `DELETE TRUNCATE TABLE`, `kubectl`/`terraform`/`helm` apply-destroy,
|
|
89
|
+
`aws delete|terminate`, …) plus `write`/`edit`/`apply_patch` calls that touch
|
|
90
|
+
a sensitive file (`.env`, `.ssh`, `.aws`, `.gnupg`, `.npmrc`, `.netrc`,
|
|
91
|
+
`id_rsa`, `credentials`, shell rc files) or a path that resolves outside the
|
|
92
|
+
workspace. The lists live in `approvals.ts` and are meant to be edited.
|
|
93
|
+
`all` gates every tool call; `off` disables the gate but keeps the pet
|
|
94
|
+
animating.
|
|
95
|
+
|
|
96
|
+
**Paths are resolved, not string-compared.** `resolve(cwd, target)` plus a
|
|
97
|
+
structural containing check, so `../other-repo/x.ts` gates the same as
|
|
98
|
+
`/home/you/other-repo/x.ts`, and a sibling whose name merely starts with the
|
|
99
|
+
workspace's name is not mistaken for a descendant. `~` is never expanded. An
|
|
100
|
+
`apply_patch` body is read for its targets too — both dialects (`*** Update
|
|
101
|
+
File:`, and `--- a/`/`+++ b/`/`diff --git` headers) — under exactly the rules
|
|
102
|
+
`write` uses, so a patch cannot reach where `write` could not, and its device
|
|
103
|
+
prompt names the files instead of showing 80 bytes of body. A body we cannot
|
|
104
|
+
parse stays ungated, as it always did: this is a deny-list, and inventing a
|
|
105
|
+
target we cannot read is not how anybody learns to trust the prompt.
|
|
106
|
+
|
|
107
|
+
**Scratch space is not "outside".** `/tmp`, `/var/tmp` and `os.tmpdir()` are
|
|
108
|
+
throwaways; a write there never gates on location. Sensitive-file rules still
|
|
109
|
+
apply, because `/tmp/.env` is a secret file in a scratch directory. Recursive
|
|
110
|
+
deletes are exempt there too, but only when *every* operand of every `rm` in the
|
|
111
|
+
command is a child of a scratch directory — never the scratch root itself —
|
|
112
|
+
owned by the user running the bridge, and not a symlink pointing out of scratch.
|
|
113
|
+
The ownership half is load-bearing: `/tmp` is world-writable, so what lives
|
|
114
|
+
there is not necessarily yours. Glob and `$var` operands stay gated, because
|
|
115
|
+
resolving them means behaving like a shell, and so does `sudo rm -rf`, which is
|
|
116
|
+
no longer a plain `rm`. `rm -rf /tmp` always asks.
|
|
117
|
+
|
|
118
|
+
When a call is gated you get **both** prompts at once: pi's confirm dialog in
|
|
119
|
+
the terminal and `prompt:{id,tool,hint}` on the device. Whichever answers
|
|
120
|
+
first wins and the other is dismissed, so the device is usable as the only
|
|
121
|
+
interface (`/pippi` dialogs notwithstanding). No answer within 60s blocks the
|
|
122
|
+
tool call with an explanation; set `PI_PIPPI_APPROVAL_TIMEOUT=0` to wait
|
|
123
|
+
forever, or `PI_PIPPI_ON_TIMEOUT=allow` to fail open. The 60s is one number and
|
|
124
|
+
it bounds both surfaces: the pet's dialog is cleared by the host when it expires
|
|
125
|
+
(the device counts up and turns red at 10s, but nothing on it dismisses a
|
|
126
|
+
question), and the terminal dialog now closes on the same clock rather than
|
|
127
|
+
waiting out a human who has left the desk. An expired dialog is not a denial --
|
|
128
|
+
it is the absence of an answer, and the call stays blocked either way.
|
|
129
|
+
|
|
130
|
+
If this session cannot ask the human, the call is *not* silently allowed. A session that
|
|
131
|
+
does not hold the pippi falls back to pi's confirm dialog in that session's terminal, which
|
|
132
|
+
is still ours. Only when there is no terminal to ask in either (headless `pi -p`, no `--mode`
|
|
133
|
+
UI) does the call go through, with a warning, rather than deadlock pi.
|
|
134
|
+
|
|
135
|
+
A link that drops **mid**-approval does not fall back at all: the question stays open. The
|
|
136
|
+
panel keeps showing a dialog it was never told to clear -- the snapshot that would clear it
|
|
137
|
+
had nowhere to go -- so calling the question off the instant the radio wobbled meant the
|
|
138
|
+
human pressed **A**, watched the pet acknowledge it, and the answer arrived for a question
|
|
139
|
+
this session had stopped tracking. The tool call then waited in a terminal for a decision
|
|
140
|
+
they were sure they had already given, and the log line said nothing a human could act on. So
|
|
141
|
+
the prompt outlives the drop (`promptLinkGraceMs`, default 20s), keeps its id, and goes back
|
|
142
|
+
to the panel when the link does -- which is what makes the answer match. Two things still end
|
|
143
|
+
the wait: the grace, which reports `unavailable` (undeliverable, not unanswered) if the pippi
|
|
144
|
+
has not come back; and the approval timeout, which is the human's clock and keeps running
|
|
145
|
+
because a second of Bluetooth is not extra time to answer in. A question that was on the
|
|
146
|
+
panel for less than a second when the link went is treated as never drawn -- nobody could have
|
|
147
|
+
answered it yet, and that case must report immediately rather than after a grace nobody could
|
|
148
|
+
use. And when a decision does arrive for a question this session is not holding, it is logged
|
|
149
|
+
at error with the outcome that closed the last one, because that is the only sign there is
|
|
150
|
+
that a button was pressed and thrown away.
|
|
151
|
+
|
|
152
|
+
**One gated turn is one claim, and one failure is one message.** pi runs the tool
|
|
153
|
+
calls of an assistant turn concurrently, so five gated calls arrive at once and each
|
|
154
|
+
one wants the pippi; they now share a single claim. They used not to, and the result
|
|
155
|
+
was a wall of connect and disconnect lines in the terminal: five `Disconnect`s at a
|
|
156
|
+
device that was connected to nobody, five dials each torn down by the next, and a
|
|
157
|
+
failure logged for every teardown. Same on the radio side -- a claim checks whether
|
|
158
|
+
BlueZ thinks the device is connected before hanging anybody up, and a dial that fails
|
|
159
|
+
backs off (1s to 15s) instead of asking the adapter once a second forever, because a
|
|
160
|
+
pippi that is off will stay off through all of them.
|
|
161
|
+
|
|
162
|
+
### Multiple pi sessions
|
|
163
|
+
|
|
164
|
+
One pippi, many pi windows, no daemon and no lock file. **The pet belongs to
|
|
165
|
+
whichever session the human typed in last.** Pressing Enter in a window claims
|
|
166
|
+
it from whatever window had it; the previous session lets go and stops trying to
|
|
167
|
+
get it back until you type there.
|
|
168
|
+
|
|
169
|
+
That is the whole policy, and it holds up because there is one human: two claims
|
|
170
|
+
cannot be in flight at once, so there is nothing to arbitrate. Concretely:
|
|
171
|
+
|
|
172
|
+
* **Only typed input claims.** `pi.on("input")` with `source === "interactive"`.
|
|
173
|
+
Agent activity, tool events, timers, `pi -p`, and pi instances driven over RPC
|
|
174
|
+
or by other extensions never claim, so a busy background agent cannot win the
|
|
175
|
+
pet away from the window you are typing in — and a scripted pi cannot take it
|
|
176
|
+
at all.
|
|
177
|
+
* **A claim takes the link over, and the board -- not the radio -- decides who had
|
|
178
|
+
it.** A BlueZ connection belongs to the adapter, not the process, and a connected
|
|
179
|
+
peripheral stops advertising, so a pippi held by another window is not busy but
|
|
180
|
+
unreachable. `claim` asks BlueZ to drop the old link first (`ble.ts:releaseLink`).
|
|
181
|
+
What the adapter does *not* do is make that exclusive: with one window already
|
|
182
|
+
holding the pippi, a second one's `Connect` was answered with success on the same
|
|
183
|
+
ACL, the first window saw no drop at all, and both of their `status` requests were
|
|
184
|
+
served -- by two interleaved replies, which is what a `non-JSON from device` warning
|
|
185
|
+
is. Two sessions on one link is not a fight someone loses; it is a pippi whose
|
|
186
|
+
answers nobody can read. So nothing here is enforced by the radio: the board below is
|
|
187
|
+
the only arbiter, and a claim without checking it is a claim on your own session's
|
|
188
|
+
data.
|
|
189
|
+
* **A drop nobody asked for is chased back.** A reset, a flash, a battery swapped, a
|
|
190
|
+
walk out of range: the link dies and no human decided anything, so waiting for Enter
|
|
191
|
+
asks you to fix something you did not do. The bridge takes the pippi back by itself:
|
|
192
|
+
first try 2s after the drop, then doubling to a 20s cap, for 2 minutes
|
|
193
|
+
(`PI_PIPPI_RECLAIM`; `0` never chases), and the status line reads `reconnecting…`
|
|
194
|
+
while it runs. Measured on hardware: forced drop, link back in 6s, nobody touched
|
|
195
|
+
anything. A chase is not free, though -- it may only spend what the human last gave
|
|
196
|
+
it, which is the next bullet.
|
|
197
|
+
* **Who may claim the pippi is a directory, not a guess.** The board is
|
|
198
|
+
`$PI_PIPPI_CLAIM_DIR` (`/tmp/pi-pippi-claims` by default) holding one empty file per
|
|
199
|
+
session pid:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
touch $BOARD/$PPID # on human input, unconditionally
|
|
203
|
+
# before claiming: am I the newest stamp in there?
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
A session that was never typed into has no stamp, so it is last in line and cannot
|
|
207
|
+
take the pet off the window you are in -- opening a second pi costs nothing. Typing
|
|
208
|
+
in a window is the entire remedy for anything the board decides, in every window.
|
|
209
|
+
Stamps are the state, so nothing is handed back, no lease expires, and a crash needs
|
|
210
|
+
no cleanup: a dead process cannot touch its file again, and a stamp older than five
|
|
211
|
+
minutes stops counting even if its pid got recycled.
|
|
212
|
+
Being *derived from the directory* is what makes the claim agreeable: every session
|
|
213
|
+
reading it gets the same answer, so there is one claimant at a time without a
|
|
214
|
+
negotiation. That is worth stating as a rule, because it is easy to break from the
|
|
215
|
+
radio side -- **nothing that is not a human decision may move a stamp**, and no part
|
|
216
|
+
of `ble.ts` does. A reconnect that re-dated its own claim would find itself the
|
|
217
|
+
newest claimant every time it looked, in every window independently, which is the
|
|
218
|
+
livelock two bullets down.
|
|
219
|
+
* **Why a directory, when the radio is right there.** Because a scan answers "is
|
|
220
|
+
anyone holding this" and never "who did the human last ask for", and a chase driven
|
|
221
|
+
off the first question takes the pet off the window the human is in. Measured between
|
|
222
|
+
two windows on one machine before the board existed: nine hand-overs in 56s, held 3s,
|
|
223
|
+
stolen, repeat, both sides logging `pippi back after 11s` and neither able to see that
|
|
224
|
+
it is the one being stolen from. Not two windows disagreeing about a decision -- both
|
|
225
|
+
were obeying their own retry, and a retry that acts on the radio instead of on the
|
|
226
|
+
board re-awards the pippi to whoever is doing it. Asking the directory before every
|
|
227
|
+
attempt is what turns nine exchanges into one: the window the human left stands down,
|
|
228
|
+
logs which pid beat it, and stops.
|
|
229
|
+
* **A dial that never lands is stopped, and said once.** Between "the pippi is asleep"
|
|
230
|
+
and "the machine it lives on is powered off" the radio looks identical, and a retry
|
|
231
|
+
ladder cannot tell them apart -- so the ladder has a budget (90s). Spending it ends
|
|
232
|
+
the loop with one sentence, `pippi did not answer in Ns; press Enter here to try
|
|
233
|
+
again`, and leaves `not reachable` in the state for the status line. An unbounded
|
|
234
|
+
retry is not patience: it is a process quietly talking to a device no human is
|
|
235
|
+
waiting for, showing "connecting" forever when the true answer is "I can't reach it".
|
|
236
|
+
Enter restarts the budget from nothing, because the person pressing it has news the
|
|
237
|
+
loop does not.
|
|
238
|
+
* **A link we no longer own is let go, even when nothing dropped.** The keepalive is
|
|
239
|
+
the only moment a session looks at the world on a schedule, and this is the one thing
|
|
240
|
+
it cannot otherwise notice. A BlueZ connection belongs to the adapter, not to whoever
|
|
241
|
+
opened it -- measured, not theorized: with one window holding the link, a second
|
|
242
|
+
window's claim succeeded, the two sessions' replies arrived interleaved out of order,
|
|
243
|
+
and the first window never saw a disconnect. It kept reporting an attached pet,
|
|
244
|
+
writing snapshots to a device that had moved on, and queueing approval prompts that
|
|
245
|
+
would never be read on it. So each keepalive asks the board the same question a claim
|
|
246
|
+
would, and a newer stamp anywhere means this session closes the link it no longer owns
|
|
247
|
+
and says who has it. A *mask* is deliberately not a takeover: another window holding a
|
|
248
|
+
question is not holding the pet, and standing down for it would hand the pippi to
|
|
249
|
+
whoever asked first.
|
|
250
|
+
|
|
251
|
+
* **An approval outranks the board, and masks it.** A tool call blocked on an answer is
|
|
252
|
+
worth interrupting another window for, so it stamps the board and claims -- and then
|
|
253
|
+
writes `$BOARD/APPROVAL`, which is not a stamp. A stamp says who the human left last;
|
|
254
|
+
the mask says a question is on the screen, and while one is, claims stop everywhere:
|
|
255
|
+
other windows queue rather than seize the pet away from a dialog they cannot see. It
|
|
256
|
+
is written once and never refreshed, because its mtime is when the question started
|
|
257
|
+
and every party decides whether that question still exists by the same subtraction:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
[ $(($(date +%s) - $(stat -c %Y "$BOARD/APPROVAL"))) -gt $PI_PIPPI_APPROVAL_TIMEOUT ]
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
One constant, no negotiation, nothing to hand back: a session that died mid-question
|
|
264
|
+
stops being a question by arithmetic and the pippi comes back around by itself. The
|
|
265
|
+
terminal dialog this session falls back to is bounded by that same constant -- it used
|
|
266
|
+
to have no deadline at all, which is how an AFK human ended up with an approval
|
|
267
|
+
arriving an hour later on a tool call pi had long since given up on. If the claim
|
|
268
|
+
fails the failure cools off for 15s, because a background session working through a
|
|
269
|
+
list of gated commands would otherwise stall on every one and keep yanking the link.
|
|
270
|
+
* **A running session can go dark, on purpose.** Once you type elsewhere, the
|
|
271
|
+
other session's animations stop arriving; its tool calls still work, and so do
|
|
272
|
+
its approvals (they seize). "Latest activity wins" was the alternative, and it
|
|
273
|
+
flaps constantly.
|
|
274
|
+
|
|
275
|
+
Worth knowing: `/pippi scan` finds nothing while the pippi is attached, because a
|
|
276
|
+
connected peripheral stops advertising — that is Bluetooth, not a bug.
|
|
277
|
+
|
|
278
|
+
### Which window is asking
|
|
279
|
+
|
|
280
|
+
Because several windows can hold the pippi, an approval can arrive from a session
|
|
281
|
+
you are not looking at. Each one sends a short tag with its prompt and the pet
|
|
282
|
+
draws it beside the timer: `approve? 12s [m5sta]`. The default is the working
|
|
283
|
+
directory's name, so two windows in two projects tell themselves apart for free;
|
|
284
|
+
`/pippi tag <name>` renames this one, and `PI_PIPPI_TAG` does it from the shell for
|
|
285
|
+
people who script tmux layouts. `/pippi tag` with no argument reports the current
|
|
286
|
+
name, which is how you find out which window is `[m5sta]` without walking around
|
|
287
|
+
the desk.
|
|
288
|
+
|
|
289
|
+
Seven printable ASCII characters, because that is what fits beside a timer on a
|
|
290
|
+
240px panel and the device's field is `char[8]`. A name the font cannot draw is
|
|
291
|
+
refused with a message rather than silently dropped, and a tag is never persisted:
|
|
292
|
+
one that followed you into every window would read the same everywhere and tell
|
|
293
|
+
you nothing. Two windows open in the same project do show the same tag — the wire
|
|
294
|
+
has nothing better to say about them unless you name them.
|
|
295
|
+
|
|
296
|
+
## Configuration
|
|
297
|
+
|
|
298
|
+
Environment variables (all optional; every one is read at session start):
|
|
299
|
+
|
|
300
|
+
| Variable | Default | Meaning |
|
|
301
|
+
| --- | --- | --- |
|
|
302
|
+
| `PI_PIPPI_DISABLE` | — | `1` loads the extension but keeps it off |
|
|
303
|
+
| `PI_PIPPI_TRANSPORT` | `ble` | `ble` \| `simulate` \| `null` |
|
|
304
|
+
| `PI_PIPPI_DEVICE` | saved device | address to auto-connect |
|
|
305
|
+
| `PI_PIPPI_APPROVALS` | `dangerous` | `off` \| `dangerous` \| `all` |
|
|
306
|
+
| `PI_PIPPI_APPROVAL_TIMEOUT` | `60` | seconds; `0` waits forever |
|
|
307
|
+
| `PI_PIPPI_ON_TIMEOUT` | `block` | `block` \| `allow` |
|
|
308
|
+
| `PI_PIPPI_RECLAIM` | `120` | seconds to chase a pippi that dropped by itself; `0` never chases |
|
|
309
|
+
| `PI_PIPPI_CLAIM_DIR` | `/tmp/pi-pippi-claims` | the claim board: who may take the pippi, by whose keystroke, newest stamp wins. Two windows must share one directory, so relocate it together with `PI_PIPPI_STATE_DIR` if you relocate that |
|
|
310
|
+
| `PI_PIPPI_OWNER` | git user, else `$USER` | shown by the `owner` command |
|
|
311
|
+
| `PI_PIPPI_TAG` | working directory's name | shown beside an approval on the pet |
|
|
312
|
+
| `PI_PIPPI_PROVIDER` | the session's model provider | whose mark to wear beside the pet |
|
|
313
|
+
| `PI_PIPPI_TURN_EVENTS` | off | also send `{"evt":"turn"}` messages |
|
|
314
|
+
| `PI_PIPPI_WIRE_LOG` | — | append every tx/rx line to a file |
|
|
315
|
+
| `PI_PIPPI_STATE_DIR` | `$XDG_CACHE_HOME/pi-pippi` | where the device address, owner and daily token counter live |
|
|
316
|
+
| `PI_PIPPI_USAGE_INTERVAL` | `300` | seconds between usage queries; `0` leaves the usage rows off |
|
|
317
|
+
| `PI_PIPPI_USAGE_LOW` | `5` | percentage under which a usage bar blinks red |
|
|
318
|
+
| `PI_PIPPI_USAGE_SPEC` | — | draw these meters instead of asking a provider — see below |
|
|
319
|
+
|
|
320
|
+
`PI_PIPPI_USAGE_SPEC` exists because there are sessions whose usage cannot be
|
|
321
|
+
asked about and layouts that cannot be seen without it: a model served by a local
|
|
322
|
+
backend has no subscription and no balance to draw down, and the second quota
|
|
323
|
+
window of an account that has only used one takes a week of real use to produce. It
|
|
324
|
+
takes a report, not a conclusion — `5h=83,7d=21` are percentages left, `$balance=
|
|
325
|
+
12.50` is a wallet — and feeds it through the same normalisation and the same clamps
|
|
326
|
+
as a provider's own, so what it shows you is the real layout with invented numbers.
|
|
327
|
+
What it does not test is the query itself: the service on the event bus is bypassed
|
|
328
|
+
entirely, and the log says so once per distinct spec, because a bar that looks
|
|
329
|
+
ordinary and is not is the one failure mode this feature cannot afford.
|
|
330
|
+
|
|
331
|
+
The badge is the other thing the model is read for. `model_select` carries the
|
|
332
|
+
provider, and `ctx.model` is read at `session_start` because restoring a session does
|
|
333
|
+
not fire `model_select` — a resumed window would otherwise show no mark until you
|
|
334
|
+
cycled models. pi's name for a provider is not always the name of the company whose
|
|
335
|
+
account it is, so `openai-codex` is sent as `openai` and `Kimi For Coding` as
|
|
336
|
+
`moonshot`; a proxy pi knows nothing about — `llama-swap`, `my-box-lan` — goes
|
|
337
|
+
through as it came and the pet draws a square coloured from a hash of it with its
|
|
338
|
+
initial on top, which is the designed answer and not a missing logo. Set
|
|
339
|
+
`PI_PIPPI_PROVIDER=anthropic` when you know better than the endpoint: llama-swap
|
|
340
|
+
serving Claude should wear Claude's mark, and only you have configured the box.
|
|
341
|
+
|
|
342
|
+
Settings that persist across sessions (`state.ts`): the paired address, the
|
|
343
|
+
approvals policy, on/off, and the token counter — which resets at local
|
|
344
|
+
midnight so the pet's "tokens today" matches a day of work, not a week. An
|
|
345
|
+
explicit `PI_PIPPI_APPROVALS` / `PI_PIPPI_DEVICE` for one run wins over what
|
|
346
|
+
was saved. The session tag is the one setting that deliberately does not persist.
|
|
347
|
+
|
|
348
|
+
## Development
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
cd bridges/pi
|
|
352
|
+
node --test tests/ # 210 tests, no radio
|
|
353
|
+
node dev-run.mjs --smoke # end-to-end against the simulator
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
`tests/simulate.test.ts` drives the scripted pippi (`simulate.ts`: acks, scans,
|
|
357
|
+
connect failures, chunk accounting), and `tests/ble.test.ts` runs the real BlueZ
|
|
358
|
+
code path against a fake D-Bus — including the tree recorded from a live adapter
|
|
359
|
+
in `tests/fixtures/bluez_gatt_tree.json`, because a fake built from memory hides
|
|
360
|
+
exactly the hardware-only bug class. `dev-run.mjs` is the manual harness:
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
node dev-run.mjs # simulator: snapshots + a self-answered prompt
|
|
364
|
+
node dev-run.mjs --ble --scan # real radio: scan
|
|
365
|
+
node dev-run.mjs --ble --target AA:BB:CC:DD:EE:FF --keep
|
|
366
|
+
PI_PIPPI_WIRE_LOG=/tmp/wire.log node dev-run.mjs
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
To type-check against pi's real declarations:
|
|
370
|
+
|
|
371
|
+
```bash
|
|
372
|
+
npm install
|
|
373
|
+
npx tsc --noEmit --strict --target ES2022 --module nodenext \
|
|
374
|
+
--moduleResolution nodenext --allowImportingTsExtensions index.ts
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
The three `devDependencies` are build-time only: `pi-coding-agent` for the
|
|
378
|
+
extension API's types, `typescript` for the check above, `@types/node` for
|
|
379
|
+
`node --test`. Nothing here is imported at runtime -- pi provides the host
|
|
380
|
+
package, and the radio is BlueZ over D-Bus, which this directory speaks itself
|
|
381
|
+
(`bluez.ts`) -- so `npm install` is never needed to run the extension.
|
|
382
|
+
|
|
383
|
+
## Notes and known gaps
|
|
384
|
+
|
|
385
|
+
- **Protocol limits are enforced locally.** `REFERENCE.md` caps a device line
|
|
386
|
+
at 1024 bytes, so `protocol.ts` trims `msg`, drops oldest transcript
|
|
387
|
+
entries, and finally refuses to send rather than emit a line the firmware
|
|
388
|
+
would drop mid-parse. Folder pushes use 256-byte base64 chunks, matching
|
|
389
|
+
`src/xfer.h`.
|
|
390
|
+
- **Turn events are off by default.** Current firmware ignores
|
|
391
|
+
`{"evt":"turn"}`; the flag exists for a firmware that grows a use for it.
|
|
392
|
+
- **Discovery is by service UUID, not name.** The firmware advertises
|
|
393
|
+
`Pi-XXXX`, but the bridge never keys on that: it filters on the Nordic UART
|
|
394
|
+
UUID and offers `--name-prefix` if you want to narrow a noisy scan.
|
|
395
|
+
- **Pairing.** LE Secure Connections uses a passkey the device shows; type it
|
|
396
|
+
in the OS pairing prompt. Bonding is recommended — the pet re-pairs on
|
|
397
|
+
every boot otherwise. `/pippi forget` unpairs.
|
|
398
|
+
- **Daily token counter counts output tokens only**, since that is what pi
|
|
399
|
+
reports per assistant message.
|
|
400
|
+
- **A chase cannot repair a pairing.** It asks whether the pippi is free, not
|
|
401
|
+
whether it will accept the bond. If the two sides no longer share one — the
|
|
402
|
+
device's bonds were cleared, or `/pippi forget` ran on either side — every
|
|
403
|
+
attempt fails exactly the way it did before this existed, and the give-up line
|
|
404
|
+
points at Enter. Re-pair from the device's reset menu.
|
|
405
|
+
- **Throughput is timed by the bridge, not the provider.** The pet's
|
|
406
|
+
`prefill` and `decode` rows are token counts divided by the bridge's own
|
|
407
|
+
clock: prefill is every prompt token (cache reads included) over
|
|
408
|
+
time-to-first-token from `message_start`, decode is output tokens over the
|
|
409
|
+
streaming window. So prefill includes request setup and whatever the provider
|
|
410
|
+
queues before the first token — it is the wait you feel, not a tokenizer
|
|
411
|
+
benchmark. Rates are a mean of the last five responses, windows under 50ms
|
|
412
|
+
are refused as noise, and nothing is sent until one response has been timed
|
|
413
|
+
(the rows read `n/a` until then, never 0/s).
|
|
414
|
+
- **Headless pi** (`-p`, `--mode json`) still drives the pet, including
|
|
415
|
+
snapshots and `running`/`waiting` state, but there is no terminal dialog to
|
|
416
|
+
race, so gated calls wait for the device or the timeout.
|