@yefengr/remote-pi 0.7.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.
Files changed (180) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +674 -0
  3. package/dist/actions/handlers.d.ts +122 -0
  4. package/dist/actions/handlers.js +160 -0
  5. package/dist/actions/handlers.js.map +1 -0
  6. package/dist/actions/registry.d.ts +39 -0
  7. package/dist/actions/registry.js +58 -0
  8. package/dist/actions/registry.js.map +1 -0
  9. package/dist/bin/supervisord.d.ts +2 -0
  10. package/dist/bin/supervisord.js +86 -0
  11. package/dist/bin/supervisord.js.map +1 -0
  12. package/dist/config.d.ts +55 -0
  13. package/dist/config.js +118 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/daemon/client.d.ts +20 -0
  16. package/dist/daemon/client.js +131 -0
  17. package/dist/daemon/client.js.map +1 -0
  18. package/dist/daemon/control_protocol.d.ts +176 -0
  19. package/dist/daemon/control_protocol.js +63 -0
  20. package/dist/daemon/control_protocol.js.map +1 -0
  21. package/dist/daemon/cron_log.d.ts +45 -0
  22. package/dist/daemon/cron_log.js +72 -0
  23. package/dist/daemon/cron_log.js.map +1 -0
  24. package/dist/daemon/cron_registry.d.ts +80 -0
  25. package/dist/daemon/cron_registry.js +194 -0
  26. package/dist/daemon/cron_registry.js.map +1 -0
  27. package/dist/daemon/id.d.ts +24 -0
  28. package/dist/daemon/id.js +36 -0
  29. package/dist/daemon/id.js.map +1 -0
  30. package/dist/daemon/install.d.ts +170 -0
  31. package/dist/daemon/install.js +547 -0
  32. package/dist/daemon/install.js.map +1 -0
  33. package/dist/daemon/registry.d.ts +63 -0
  34. package/dist/daemon/registry.js +153 -0
  35. package/dist/daemon/registry.js.map +1 -0
  36. package/dist/daemon/rpc_child.d.ts +194 -0
  37. package/dist/daemon/rpc_child.js +389 -0
  38. package/dist/daemon/rpc_child.js.map +1 -0
  39. package/dist/daemon/supervisor.d.ts +93 -0
  40. package/dist/daemon/supervisor.js +596 -0
  41. package/dist/daemon/supervisor.js.map +1 -0
  42. package/dist/extension_ui_bridge.d.ts +26 -0
  43. package/dist/extension_ui_bridge.js +341 -0
  44. package/dist/extension_ui_bridge.js.map +1 -0
  45. package/dist/index.d.ts +214 -0
  46. package/dist/index.js +5410 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/mcp/mesh_result.d.ts +10 -0
  49. package/dist/mcp/mesh_result.js +42 -0
  50. package/dist/mcp/mesh_result.js.map +1 -0
  51. package/dist/mcp/mesh_server.d.ts +16 -0
  52. package/dist/mcp/mesh_server.js +327 -0
  53. package/dist/mcp/mesh_server.js.map +1 -0
  54. package/dist/mesh/canonical.d.ts +30 -0
  55. package/dist/mesh/canonical.js +61 -0
  56. package/dist/mesh/canonical.js.map +1 -0
  57. package/dist/mesh/client.d.ts +18 -0
  58. package/dist/mesh/client.js +125 -0
  59. package/dist/mesh/client.js.map +1 -0
  60. package/dist/mesh/encoding.d.ts +38 -0
  61. package/dist/mesh/encoding.js +216 -0
  62. package/dist/mesh/encoding.js.map +1 -0
  63. package/dist/mesh/self_revoke.d.ts +73 -0
  64. package/dist/mesh/self_revoke.js +401 -0
  65. package/dist/mesh/self_revoke.js.map +1 -0
  66. package/dist/mesh/siblings.d.ts +49 -0
  67. package/dist/mesh/siblings.js +159 -0
  68. package/dist/mesh/siblings.js.map +1 -0
  69. package/dist/mesh/types.d.ts +34 -0
  70. package/dist/mesh/types.js +11 -0
  71. package/dist/mesh/types.js.map +1 -0
  72. package/dist/mesh/verify.d.ts +17 -0
  73. package/dist/mesh/verify.js +86 -0
  74. package/dist/mesh/verify.js.map +1 -0
  75. package/dist/pairing/crypto.d.ts +8 -0
  76. package/dist/pairing/crypto.js +22 -0
  77. package/dist/pairing/crypto.js.map +1 -0
  78. package/dist/pairing/qr.d.ts +59 -0
  79. package/dist/pairing/qr.js +125 -0
  80. package/dist/pairing/qr.js.map +1 -0
  81. package/dist/pairing/storage.d.ts +120 -0
  82. package/dist/pairing/storage.js +604 -0
  83. package/dist/pairing/storage.js.map +1 -0
  84. package/dist/protocol/codec.d.ts +7 -0
  85. package/dist/protocol/codec.js +49 -0
  86. package/dist/protocol/codec.js.map +1 -0
  87. package/dist/protocol/types.d.ts +393 -0
  88. package/dist/protocol/types.js +2 -0
  89. package/dist/protocol/types.js.map +1 -0
  90. package/dist/protocol/v2/codec.d.ts +26 -0
  91. package/dist/protocol/v2/codec.js +207 -0
  92. package/dist/protocol/v2/codec.js.map +1 -0
  93. package/dist/protocol/v2/index.d.ts +3 -0
  94. package/dist/protocol/v2/index.js +4 -0
  95. package/dist/protocol/v2/index.js.map +1 -0
  96. package/dist/protocol/v2/schemas.d.ts +1939 -0
  97. package/dist/protocol/v2/schemas.js +409 -0
  98. package/dist/protocol/v2/schemas.js.map +1 -0
  99. package/dist/protocol/v2/session_state.d.ts +75 -0
  100. package/dist/protocol/v2/session_state.js +176 -0
  101. package/dist/protocol/v2/session_state.js.map +1 -0
  102. package/dist/rooms.d.ts +29 -0
  103. package/dist/rooms.js +57 -0
  104. package/dist/rooms.js.map +1 -0
  105. package/dist/session/bridge.d.ts +37 -0
  106. package/dist/session/bridge.js +130 -0
  107. package/dist/session/bridge.js.map +1 -0
  108. package/dist/session/broker.d.ts +189 -0
  109. package/dist/session/broker.js +507 -0
  110. package/dist/session/broker.js.map +1 -0
  111. package/dist/session/broker_remote.d.ts +74 -0
  112. package/dist/session/broker_remote.js +583 -0
  113. package/dist/session/broker_remote.js.map +1 -0
  114. package/dist/session/cwd_lock.d.ts +33 -0
  115. package/dist/session/cwd_lock.js +126 -0
  116. package/dist/session/cwd_lock.js.map +1 -0
  117. package/dist/session/envelope.d.ts +33 -0
  118. package/dist/session/envelope.js +117 -0
  119. package/dist/session/envelope.js.map +1 -0
  120. package/dist/session/global_config.d.ts +33 -0
  121. package/dist/session/global_config.js +73 -0
  122. package/dist/session/global_config.js.map +1 -0
  123. package/dist/session/ipc.d.ts +27 -0
  124. package/dist/session/ipc.js +22 -0
  125. package/dist/session/ipc.js.map +1 -0
  126. package/dist/session/leader_election.d.ts +32 -0
  127. package/dist/session/leader_election.js +106 -0
  128. package/dist/session/leader_election.js.map +1 -0
  129. package/dist/session/local_config.d.ts +55 -0
  130. package/dist/session/local_config.js +157 -0
  131. package/dist/session/local_config.js.map +1 -0
  132. package/dist/session/mesh_node.d.ts +116 -0
  133. package/dist/session/mesh_node.js +573 -0
  134. package/dist/session/mesh_node.js.map +1 -0
  135. package/dist/session/peer.d.ts +139 -0
  136. package/dist/session/peer.js +451 -0
  137. package/dist/session/peer.js.map +1 -0
  138. package/dist/session/peer_inventory.d.ts +13 -0
  139. package/dist/session/peer_inventory.js +48 -0
  140. package/dist/session/peer_inventory.js.map +1 -0
  141. package/dist/session/peer_limits.d.ts +9 -0
  142. package/dist/session/peer_limits.js +21 -0
  143. package/dist/session/peer_limits.js.map +1 -0
  144. package/dist/session/setup_wizard.d.ts +39 -0
  145. package/dist/session/setup_wizard.js +63 -0
  146. package/dist/session/setup_wizard.js.map +1 -0
  147. package/dist/session/tools.d.ts +24 -0
  148. package/dist/session/tools.js +252 -0
  149. package/dist/session/tools.js.map +1 -0
  150. package/dist/session/wizard.d.ts +13 -0
  151. package/dist/session/wizard.js +20 -0
  152. package/dist/session/wizard.js.map +1 -0
  153. package/dist/timeline/history.d.ts +35 -0
  154. package/dist/timeline/history.js +381 -0
  155. package/dist/timeline/history.js.map +1 -0
  156. package/dist/timeline/runtime.d.ts +76 -0
  157. package/dist/timeline/runtime.js +428 -0
  158. package/dist/timeline/runtime.js.map +1 -0
  159. package/dist/timeline/v2_service.d.ts +54 -0
  160. package/dist/timeline/v2_service.js +351 -0
  161. package/dist/timeline/v2_service.js.map +1 -0
  162. package/dist/transport/peer_channel.d.ts +57 -0
  163. package/dist/transport/peer_channel.js +170 -0
  164. package/dist/transport/peer_channel.js.map +1 -0
  165. package/dist/transport/pi_forward_client.d.ts +29 -0
  166. package/dist/transport/pi_forward_client.js +62 -0
  167. package/dist/transport/pi_forward_client.js.map +1 -0
  168. package/dist/transport/relay_client.d.ts +91 -0
  169. package/dist/transport/relay_client.js +206 -0
  170. package/dist/transport/relay_client.js.map +1 -0
  171. package/dist/ui/footer.d.ts +32 -0
  172. package/dist/ui/footer.js +34 -0
  173. package/dist/ui/footer.js.map +1 -0
  174. package/docs/daemon.md +289 -0
  175. package/package.json +87 -0
  176. package/service-templates/launchd.plist.template +35 -0
  177. package/service-templates/systemd.service.template +19 -0
  178. package/service-templates/task-launcher.vbs.template +10 -0
  179. package/service-templates/task-scheduler.xml.template +38 -0
  180. package/skills/agent-network/SKILL.md +310 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jacob Moura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,674 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/jacobaraujo7/remote_pi/main/branding/logo-full.svg" width="160" alt="Remote Pi logo" />
3
+ </p>
4
+
5
+ <h1 align="center">Remote Pi</h1>
6
+
7
+ > Extend the [Pi coding agent](https://github.com/earendil-works/pi) with two
8
+ > superpowers: agents that talk to each other on the same machine, and a browser
9
+ > PWA that drives Pi remotely.
10
+
11
+ **Homepage:** <https://remote-pi.jacobmoura.work>
12
+
13
+ `/remote-pi` is a single slash command that wires both at once. Run it; the
14
+ first time it asks a couple of questions and you are done.
15
+
16
+ ## Protocol & Security
17
+
18
+ For wire format, identity model, ACK protocol, cross-PC routing, mesh
19
+ membership, and the trust model (what the relay sees and doesn't see),
20
+ read [`PROTOCOL.md`](../PROTOCOL.md) at the repo root. It is the canonical
21
+ document — this README only covers user-facing setup.
22
+
23
+ ---
24
+
25
+ ## Quick start
26
+
27
+ Install the extension (one-time):
28
+
29
+ ```bash
30
+ pi install npm:@yefengr/remote-pi
31
+ ```
32
+
33
+ Then in any Pi terminal:
34
+
35
+ ```text
36
+ /remote-pi
37
+ ```
38
+
39
+ The first run shows a short interactive wizard (agent name, default session,
40
+ whether to auto-start the relay). On every following run, `/remote-pi` joins
41
+ the local agent session and starts the relay automatically — no extra typing.
42
+
43
+ ### Try the agent network in 30 seconds
44
+
45
+ Open **two** Pi terminals in the same directory and run `/remote-pi` in each.
46
+ Both join the same session. Now just talk to the LLM — it has the tools.
47
+
48
+ In terminal A (say it ended up named `agent-A`):
49
+
50
+ ```text
51
+ Who else is connected in our agent session? List them.
52
+ ```
53
+
54
+ The LLM calls `list_peers` and reports the complete routing addresses it sees.
55
+
56
+ Then, still in terminal A:
57
+
58
+ ```text
59
+ Send a ping to agent-B using its listed address and ask it to reply later.
60
+ ```
61
+
62
+ Pi calls `agent_send({ to: "<exact address from list_peers>", body: {
63
+ type: "ping" } })`. For unicast, the call waits only for the broker's delivery
64
+ ACK. Terminal B receives the message as a user-facing turn and can answer later
65
+ with `agent_send`, setting `re` to the ping's message id; that reply arrives in
66
+ terminal A's inbox or a later turn. It does not block terminal A waiting for
67
+ agent-B's content reply.
68
+
69
+ Copy the complete address exactly as listed. Do not build, parse, decode, or
70
+ normalize it.
71
+
72
+ ---
73
+
74
+ ## What it does
75
+
76
+ Remote Pi adds two independent layers on top of Pi. You can use either, or
77
+ both:
78
+
79
+ ### 1) Agent network (local broker, optional cross-PC relay)
80
+
81
+ Several Pi instances running side-by-side in different terminals can discover
82
+ each other and exchange messages. Each instance is a peer in a named
83
+ *session*. The LLM uses:
84
+
85
+ - `list_peers` — discover current peer routing addresses
86
+ - `agent_send` — unicast waits for the broker delivery ACK; broadcast is
87
+ fire-and-forget
88
+
89
+ The legacy Pi-only `agent_request` tool is deprecated because it blocks while
90
+ waiting for another agent's content reply. Use `agent_send`, continue the
91
+ current turn, and receive any later reply through the inbox/turn flow with
92
+ `re` correlating it to the original message id.
93
+
94
+ Peers on the same machine talk over a Unix domain socket at
95
+ `~/.pi/remote/sessions/<session-name>/broker.sock`. When sibling PCs are paired,
96
+ a leader-capable Extension or MCP participant bridges the opaque cross-PC
97
+ addresses over the relay; local-only use stays on UDS when relay access is off.
98
+ Useful for splitting work across roles (`backend`, `frontend`, `tests`,
99
+ `orchestrator`, …) and letting them coordinate.
100
+
101
+ The first agent to enter a session becomes the *leader* (hosts the broker);
102
+ the rest are *followers*. If the leader exits, a follower automatically takes
103
+ over — the failover is invisible to the LLMs.
104
+
105
+ ### 2) Browser PWA (over the relay)
106
+
107
+ The companion browser PWA lets you send prompts to Pi and read its responses
108
+ from any modern browser. The browser and the Pi process find each other through
109
+ a **relay**: a small WebSocket server that ferries messages between them.
110
+ Pairing is one-time per browser profile, via QR code.
111
+
112
+ Communication uses WebSocket over TLS to the relay. Fields such as `ct` are
113
+ wire containers, not a systemwide end-to-end confidentiality guarantee: current
114
+ Pi-forward, cross-PC, app, and control envelopes visible to the relay are not
115
+ fully opaque or E2E encrypted. A relay operator can see routed plaintext
116
+ protocol content and metadata; see [`PROTOCOL.md`](../PROTOCOL.md) for the exact
117
+ trust boundaries.
118
+
119
+ **Open the PWA** — use the browser workspace at:
120
+
121
+ <https://remote-pi.jacobmoura.work/app>
122
+
123
+ ---
124
+
125
+ ## PWA actions
126
+
127
+ Beyond the chat, the PWA surfaces a small set of typed actions you can run
128
+ on the paired Pi session. Open the actions control next to the message input
129
+ when the input is empty to open the Quick Actions sheet:
130
+
131
+ | Action | What it does |
132
+ |---|---|
133
+ | **Compact context** | Runs `ctx.compact()` — same as `/compact` in the TUI. |
134
+ | **New session** | Runs `ctx.newSession()` — equivalent to `/new`, asks for confirmation first. |
135
+ | **Model** | Opens a model picker fed by your authenticated providers (same source the TUI uses) and switches via `pi.setModel(model)`. |
136
+ | **Thinking** | Segmented control with the 6 SDK levels (`off` · `minimal` · `low` · `medium` · `high` · `xhigh`). Changes via `pi.setThinkingLevel(level)`. |
137
+
138
+ Each action gets a structured `action_ok` / `action_error` reply so the PWA
139
+ can show an inline error on failure. Visible side-effects (chat output, model
140
+ change broadcasts, compaction notice) still flow through the normal chat
141
+ channels. The wire schema is documented in [`PROTOCOL.md`](../PROTOCOL.md)
142
+ under "App actions".
143
+
144
+ It is **not** a generic slash-command picker. The Pi SDK does not expose
145
+ programmatic invocation for most builtins (those live in the TUI's
146
+ interactive loop), so the PWA exposes only the actions that have a clean
147
+ SDK call. The [`pi-telegram`](https://github.com/llblab/pi-telegram) adapter
148
+ follows the same pattern.
149
+
150
+ ### Images
151
+
152
+ The PWA can attach **one image** from the browser to a message. It's
153
+ compressed client-side and rides **inline** in the `user_message` — the
154
+ optional `images` field carries `{ data: <base64>, mime }`. The pi-extension
155
+ turns it into the SDK's multimodal content (an `ImageContent` followed by the
156
+ caption `TextContent`) and calls `sendUserMessage(content)`, so the model sees
157
+ the picture plus your text.
158
+
159
+ Whether a model accepts images is surfaced as a `vision` flag on each
160
+ `WireModel` (derived from the SDK's `Model.input` including `"image"`); the PWA
161
+ disables the attach button when the active model is text-only.
162
+
163
+ The **relay is unchanged** — the image travels inside the same application
164
+ message container as the text, so there's no binary channel (large files are a
165
+ future track). Base64 or a field named `ct` is not an E2E confidentiality
166
+ boundary; the current Relay visibility follows the trust model above. Text-only
167
+ messages are unaffected.
168
+
169
+ ---
170
+
171
+ ## Install
172
+
173
+ Requirements: Node 20+, Pi (the host coding agent).
174
+
175
+ ```bash
176
+ pi install npm:@yefengr/remote-pi
177
+ ```
178
+
179
+ The extension self-registers the `/remote-pi` slash command and deploys an
180
+ agent skill that teaches the LLM how to use `list_peers`, `agent_send`, and the
181
+ event-driven inbox/reply flow.
182
+
183
+ To verify:
184
+
185
+ ```text
186
+ /remote-pi config
187
+ ```
188
+
189
+ It should print the effective relay URL and where it came from
190
+ (`env` / `config` / `default`).
191
+
192
+ ---
193
+
194
+ ## Using `/remote-pi`
195
+
196
+ The bare command is the everyday entry point:
197
+
198
+ ```text
199
+ /remote-pi
200
+ ```
201
+
202
+ Behavior depends on whether there's a local config for this directory:
203
+
204
+ | State | What happens |
205
+ |---|---|
206
+ | First run (no `.pi/remote-pi/config.json`) | Interactive wizard → saves config → joins agent session → starts relay (if you opted in) |
207
+ | Returning user, auto-start enabled | Joins agent session + starts relay automatically, then prints status |
208
+ | Returning user, auto-start disabled | Prints status only; join/relay must be run manually |
209
+
210
+ The wizard asks three questions:
211
+
212
+ 1. **Agent name** — the presentation leaf name for this agent. Senders still
213
+ copy the complete opaque address returned by `list_peers`; they never build
214
+ an address from this name. Defaults to the directory name.
215
+ 2. **Default session** — the name of the agent-network room for this
216
+ directory. Multiple terminals in the same directory join the same session.
217
+ 3. **Auto-start relay (for PWA access)?** — `Yes` if you want
218
+ `/remote-pi` to also connect to the relay so the browser PWA can reach this
219
+ Pi. `No` for local-only use (agent network without remote access).
220
+
221
+ Re-run the wizard later with `/remote-pi setup`.
222
+
223
+ ---
224
+
225
+ ## Pairing the browser PWA
226
+
227
+ Once the relay is up (`/remote-pi relay status` shows `started` or `paired`):
228
+
229
+ ```text
230
+ /remote-pi pair
231
+ ```
232
+
233
+ A QR code is printed in the terminal. Open the Remote Pi PWA and scan it.
234
+ Pairing is **per machine** — once a browser profile is paired, every Pi process
235
+ on this machine accepts it (the host record lives in `~/.pi/remote/peers.json`).
236
+
237
+ To list paired devices:
238
+
239
+ ```text
240
+ /remote-pi devices
241
+ ```
242
+
243
+ To remove one:
244
+
245
+ ```text
246
+ /remote-pi revoke <shortid>
247
+ ```
248
+
249
+ The shortid is the first 8 chars shown by `devices`.
250
+
251
+ ---
252
+
253
+ ## The relay
254
+
255
+ The relay is the network boundary. TLS protects transit, but the Relay can see
256
+ routed plaintext protocol content and metadata; use a relay you trust or
257
+ self-host. There is no systemwide or PC-mesh E2E guarantee. For Pi-to-Pi
258
+ forwarding, the Relay currently permits a route when any correctly signed Owner
259
+ blob lists both canonical Pi keys. That does not prove the Owner paired with or
260
+ controls either Pi.
261
+
262
+ ### Upgrade order (Relay 0.3 first, then Extension 0.6)
263
+
264
+ Upgrade the **Relay to 0.3 first**: an old Extension can consume the new
265
+ Relay's UUID errors. Extension 0.6 carries a one-release legacy wire-label
266
+ shim, so mixed new/old Extensions interoperate when both select the same unique
267
+ colon-free signed nickname label, or when neither has one and both use the
268
+ canonical standard-padded key prefix. Delimiter or collision cases, like
269
+ divergent nickname views, are unsupported and may be silently dropped by the
270
+ old receiver. Upgrade all Extension/MCP participants in one maintenance window.
271
+ The shim does not replace the receiver-local aliases returned by `list_peers`;
272
+ addresses remain opaque.
273
+
274
+ Extension 0.6 accepts an old Relay's lowercase 32-hex trusted error ID only as
275
+ a narrow shim for an old Relay or Relay rollback; that shim is not why
276
+ Relay-first is safe.
277
+
278
+ You have two options:
279
+
280
+ ### Option A — Use the community relay
281
+
282
+ `https://relay-pi.yefengr.cn` (default). Zero setup. Good for trying
283
+ things out or for casual use. (The extension converts to `wss://…`
284
+ internally when opening the connection — both schemes point at the same
285
+ endpoint.)
286
+
287
+ Caveats:
288
+
289
+ - Shared infrastructure — availability is best-effort.
290
+ - **There is no IP allow-listing or VPN gating**.
291
+
292
+ ### Option B — Self-host (recommended for privacy)
293
+
294
+ Run the relay yourself in Docker and put it behind a VPN like
295
+ [Tailscale](https://tailscale.com), [WireGuard](https://www.wireguard.com),
296
+ or your own VPC. Because the relay's network-level protection is just TLS +
297
+ keypair authentication, layering a VPN on top means **only your devices** can
298
+ even reach the WebSocket port — defense in depth.
299
+
300
+ Quick Docker outline (see the
301
+ [relay README](https://github.com/jacobaraujo7/remote_pi/blob/main/relay/README.md#self-hosted-relay-recommended-for-privacy)
302
+ for the full setup, environment variables, and reverse-proxy guidance):
303
+
304
+ ```bash
305
+ docker run -d \
306
+ --name remote-pi-relay \
307
+ -p 3000:3000 \
308
+ --restart unless-stopped \
309
+ ghcr.io/jacobaraujo7/remote-pi-relay:latest
310
+ ```
311
+
312
+ Bind the container to your VPN interface, terminate TLS in a reverse proxy,
313
+ and point both your Pi and the browser PWA at the resulting `https://…` URL.
314
+
315
+ ### Pointing Pi at your own relay
316
+
317
+ Once your relay is reachable, tell the extension:
318
+
319
+ ```text
320
+ /remote-pi relay url https://relay.yourdomain.tld
321
+ ```
322
+
323
+ The URL **must** be `http://` or `https://` — `ws://` / `wss://` are
324
+ rejected at validation. The extension converts to WebSocket internally when
325
+ it opens the connection. Use the same canonical URL in the PWA and any
326
+ self-hosting docs: paste the URL your reverse proxy exposes.
327
+
328
+ This writes `~/.pi/remote/config.json` with `{ "relay": "..." }`. Resolution
329
+ order (highest precedence first):
330
+
331
+ 1. `REMOTE_PI_RELAY` environment variable (CI / one-off overrides)
332
+ 2. `~/.pi/remote/config.json`
333
+ 3. The built-in default (`https://relay-pi.yefengr.cn`)
334
+
335
+ Verify the active URL and its source with:
336
+
337
+ ```text
338
+ /remote-pi config
339
+ ```
340
+
341
+ If you change the URL while connected, run `/remote-pi relay stop` then
342
+ `/remote-pi relay start` (or `/remote-pi relay` to toggle).
343
+
344
+ The PWA has its own relay-URL setting in the workspace preferences — keep
345
+ both pointing at the same relay.
346
+
347
+ ---
348
+
349
+ ## Agent network: deeper look
350
+
351
+ Each session is one Unix-domain-socket broker plus N peers. The broker
352
+ multiplexes messages by opaque `to` address and broadcasts system events
353
+ (`peer_joined`, `peer_left`).
354
+
355
+ Inside the LLM, the agent skill uses `list_peers` for discovery and
356
+ `agent_send` for delivery:
357
+
358
+ ```jsonc
359
+ list_peers() // copy a complete address from this result
360
+
361
+ agent_send({
362
+ to: "/repo/api@backend", // exact opaque address returned by list_peers
363
+ body: { task: "add /healthz endpoint" },
364
+ re: "<id>" // set to the received message id when replying
365
+ })
366
+ ```
367
+
368
+ A unicast `agent_send` waits for the broker delivery ACK and returns the public
369
+ status `received`, `denied`, or `timeout`; broadcast is fire-and-forget. A
370
+ trusted Relay's closed transport reason is returned in `details` without
371
+ changing those statuses: `offline` maps to `timeout`, while `not_authorized`
372
+ and `bad_envelope` map to `denied`. Genuine silence is a reasonless `timeout`.
373
+ Do not blindly retry authorization or envelope failures. Trusted Relay errors
374
+ are consumed internally to settle pending sends; forged or invalid reserved
375
+ bodies do not gain that authority.
376
+
377
+ Mesh addresses are opaque routing values: echo them verbatim, including
378
+ receiver-local PC aliases with percent-encoded bytes (such as `%3A` or `%25`)
379
+ or collision suffixes containing `~`. Never parse, build, decode, or normalize
380
+ an address for routing or security. A PC alias is receiver-local presentation
381
+ and routing only, so different PCs may list the same sibling under different
382
+ aliases. The canonical 32-byte Ed25519 Pi public key is the PC's technical
383
+ identity; never use an alias as proof of identity.
384
+
385
+ `agent_request` remains available only as a deprecated legacy Pi tool. Prefer
386
+ `agent_send`, then handle any later inbox/turn reply whose `re` matches the
387
+ original message id.
388
+
389
+ The wire format is a 5-field envelope `{ from, to, id, re, body }` serialized
390
+ as one JSON line per message. The leader's broker writes an `audit.jsonl`
391
+ log at `~/.pi/remote/sessions/<name>/audit.jsonl` for postmortem inspection.
392
+
393
+ Useful commands:
394
+
395
+ | Command | What it does |
396
+ |---|---|
397
+ | `/remote-pi` | Join the local mesh (and start the relay, if enabled) |
398
+ | `/remote-pi peers` | List local + cross-PC mesh peers, grouped by PC |
399
+ | `/remote-pi rename <new>` | Rename this agent in the current session |
400
+ | `/remote-pi stop` | Leave the local mesh and disconnect the relay |
401
+
402
+ Name collisions inside a session get a numeric suffix automatically
403
+ (`backend`, `backend#2`, `backend#3`). The broker assigns it and returns the
404
+ real name to the peer.
405
+
406
+ ---
407
+
408
+ ## Command reference
409
+
410
+ ### Local session (one Pi, one terminal)
411
+
412
+ | Command | Description |
413
+ |---|---|
414
+ | `/remote-pi` | Connect (join local mesh + start relay), or run setup on first use |
415
+ | `/remote-pi setup` | Run the setup wizard and update local config |
416
+ | `/remote-pi status` | Show local mesh + relay status |
417
+ | `/remote-pi stop` | Stop everything for **this** terminal (mesh + relay) |
418
+ | `/remote-pi pair` | Show QR code + copy-paste pairing URI for a browser PWA profile |
419
+ | `/remote-pi devices` | List paired browser PWA profiles (online/offline per profile) |
420
+ | `/remote-pi revoke <shortid>` | Revoke a paired device by its shortid |
421
+ | `/remote-pi set-relay <url>` | Persist a new relay URL (http:// or https://) |
422
+ | `/remote-pi relay [start\|stop\|status]` | Relay-only control — leaves local mesh membership untouched (no verb = toggle) |
423
+ | `/remote-pi relay url <url>` | Same as `set-relay` |
424
+ | `/remote-pi config` | Show the effective relay URL and its source (env / config / default) |
425
+
426
+ ### Daemon fleet (one supervisor, N background Pis — see [Daemon mode](#daemon-mode))
427
+
428
+ | Command | Description |
429
+ |---|---|
430
+ | `/remote-pi create <cwd> [--name X]` | Register a folder as a daemon |
431
+ | `/remote-pi remove <id>` | Unregister a daemon (local config preserved) |
432
+ | `/remote-pi daemons` | List registered daemons + state |
433
+ | `/remote-pi daemon start` | Start every registered daemon |
434
+ | `/remote-pi daemon stop` | Stop every running daemon (`/remote-pi stop` stops only the local terminal) |
435
+ | `/remote-pi daemon restart` | Stop + start all daemons |
436
+ | `/remote-pi daemon status` | Detailed runtime status (pid, uptime, restart count) |
437
+ | `/remote-pi daemon send <id> "<text>"` | Send a prompt to a specific daemon |
438
+ | `/remote-pi cron add <id> "<expr>" "<prompt>"` | Schedule a recurring prompt (`--tz`, `--wake`, `--no-skip-busy`, `--catchup`) |
439
+ | `/remote-pi cron list` | List scheduled jobs (schedule, enabled, next run, last status) |
440
+ | `/remote-pi cron run <jobId>` | Fire a job now (ignores its schedule) |
441
+ | `/remote-pi cron enable\|disable <jobId>` | Toggle a job on/off |
442
+ | `/remote-pi cron remove <jobId>` | Delete a job |
443
+ | `/remote-pi cron log [<jobId>] [--tail N]` | Read the fire/skip audit log |
444
+ | `/remote-pi install` | Install `pi-supervisord` as a system service |
445
+ | `/remote-pi uninstall` | Remove the system service (registry preserved) |
446
+
447
+ All commands above work both as Pi slash commands (interactive) and as
448
+ shell-level `remote-pi <subcommand>` when the package is installed
449
+ globally (`npm install -g @yefengr/remote-pi`).
450
+
451
+ ### Scheduled prompts (`cron`)
452
+
453
+ `remote-pi cron` schedules **recurring prompts** to daemons through the
454
+ supervisor — e.g. a daily "summarise new PRs". Output flows fire-and-forget to
455
+ the mesh/PWA like any prompt; the cron layer only audits the dispatch.
456
+
457
+ - **Schedule** is a cron expression (croner syntax; an optional 6th *seconds*
458
+ field is supported), with an optional IANA timezone via `--tz`:
459
+
460
+ ```sh
461
+ remote-pi cron add a1b2c3d4 "0 9 * * *" "Summarise new PRs" --tz America/Sao_Paulo
462
+ ```
463
+
464
+ - **Minimum interval is 60s** — more frequent schedules are rejected (guards
465
+ token cost + pileup). A fire is **skipped when the daemon is mid-turn**
466
+ (`--no-skip-busy` to override); `--wake` starts a stopped daemon first;
467
+ `--catchup` runs once on supervisor start if the previous run was missed.
468
+ - **Prerequisite**: the supervisor must run as a service (`remote-pi install`).
469
+ Without it there is no scheduler, and `cron` commands say so instead of
470
+ silently pretending to schedule.
471
+ - **Audit**: every fire **and** every skip appends one line to
472
+ `~/.pi/remote/cron.jsonl` with a `result` of `delivered`,
473
+ `woke_and_delivered`, `deliver_failed`, `skipped_busy`, `skipped_down`, or
474
+ `skipped_disabled` — read it with `remote-pi cron log`.
475
+
476
+ Step-by-step walkthrough: the [daemon tutorial](https://remote-pi.jacobmoura.work/tutorials/daemon).
477
+
478
+ ### Footer + title
479
+
480
+ - `📡 local (N)` — current agent session and peer count (local mesh)
481
+ - `🟢 relay` — relay connected, at least one device paired (globally)
482
+ - `🟡 relay waiting for pairing` — relay connected, no device paired yet
483
+ - `📱 <shortid>` — a browser PWA profile is actively connected right now
484
+
485
+ Window title: `<agent-name> · On` when relay is up, `<agent-name> · Off`
486
+ otherwise. Tells your terminals apart at a glance in `cmux`/`tmux`/iTerm
487
+ tabs.
488
+
489
+ ---
490
+
491
+ ## Daemon mode
492
+
493
+ When you want a Pi to keep running in the background (responding to
494
+ PWA prompts at 3am, processing cron jobs, monitoring a folder while
495
+ you're not at the keyboard), promote it to a **daemon** managed by a
496
+ single OS-level supervisor.
497
+
498
+ See [`docs/daemon.md`](./docs/daemon.md) for troubleshooting.
499
+
500
+ ### One-time setup
501
+
502
+ ```bash
503
+ # Install the package globally so `remote-pi` and `pi-supervisord`
504
+ # are on your PATH (`pi install npm:@yefengr/remote-pi` alone makes the Pi
505
+ # extension available but does NOT expose the CLI binaries — see
506
+ # https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin).
507
+ npm install -g @yefengr/remote-pi
508
+
509
+ # Install the supervisor as a user-level system service. Linux uses
510
+ # systemd --user; macOS uses launchd LaunchAgent. Both auto-start at
511
+ # login and survive reboots.
512
+ remote-pi install
513
+ ```
514
+
515
+ The `install` command:
516
+ - Writes `~/.config/systemd/user/remote-pi-supervisord.service` (Linux)
517
+ or `~/Library/LaunchAgents/dev.remotepi.supervisord.plist` (macOS)
518
+ - Activates it via `systemctl --user enable --now` or `launchctl bootstrap`
519
+ - The supervisor starts immediately and re-starts on every login
520
+
521
+ ### Per-folder workflow
522
+
523
+ For each agent you want to keep alive 24/7:
524
+
525
+ ```bash
526
+ # 1. Configure the agent interactively first (one time).
527
+ cd ~/Movies
528
+ pi # /remote-pi → setup wizard, /remote-pi pair, etc
529
+
530
+ # 2. Promote to a daemon. The id is derived from the cwd
531
+ # (sha256(realpath)[:8]), stable across machines.
532
+ remote-pi create ~/Movies --name "Video Editor"
533
+ # → Daemon registered: id=4e39152d name="Video Editor" cwd=/Users/x/Movies
534
+
535
+ # 3. Start it (supervisor spawns `pi --mode rpc` for this folder).
536
+ remote-pi daemon start
537
+ ```
538
+
539
+ Now you can:
540
+
541
+ ```bash
542
+ remote-pi daemons # list + state
543
+ remote-pi daemon status # uptime, pid, restart count
544
+ remote-pi daemon send 4e39152d "Cut the first 30 seconds of latest clip"
545
+ remote-pi daemon stop # stop all
546
+ remote-pi daemon restart # restart all
547
+ ```
548
+
549
+ The agent receives the prompt as if a user typed it; its response flows
550
+ back through the relay/mesh you configured during interactive setup —
551
+ PWA sees it live, other agents on the same machine can see it via the local
552
+ UDS mesh.
553
+
554
+ ### Removing or uninstalling
555
+
556
+ ```bash
557
+ remote-pi remove <id> # unregister one daemon (config preserved)
558
+ remote-pi uninstall # remove the supervisor service (registry kept)
559
+ ```
560
+
561
+ `uninstall` is reversible — re-running `install` later brings every
562
+ registered daemon back. To wipe the registry entirely, `rm
563
+ ~/.pi/remote/daemons.json`.
564
+
565
+ ### Where to find logs
566
+
567
+ | Platform | Command |
568
+ |---|---|
569
+ | Linux | `journalctl --user -u remote-pi-supervisord -f` |
570
+ | macOS | `tail -f ~/.pi/remote/supervisord.log` |
571
+
572
+ Each spawned daemon's stderr is forwarded into the supervisor's log
573
+ with a `[<cwd>]` prefix, so a single log stream shows every agent.
574
+
575
+ ### Caveats (plan/26 trade-offs)
576
+
577
+ - **Tool approval is not gated.** Daemons inherit the same Pi config
578
+ the interactive run uses — Bash, Edit, Write etc. all execute without
579
+ prompting. Configure Pi's tool permissions to taste before promoting
580
+ a folder to daemon.
581
+ - **Pairing still happens interactively.** Daemons don't show a QR
582
+ themselves; the keypair + paired devices come from the prior `pi`
583
+ session in the same folder.
584
+ - **Single supervisor.** If `pi-supervisord` crashes all daemons go
585
+ down with it. systemd/launchd restarts it within seconds; daemons
586
+ come back automatically.
587
+ - **One daemon per cwd.** The `roomIdForCwd` derivation makes daemons
588
+ by-path; two daemons in the same folder is rejected at `create` time.
589
+
590
+ ---
591
+
592
+ ## Configuration files
593
+
594
+ | Path | Scope | What's in it |
595
+ |---|---|---|
596
+ | `<cwd>/.pi/remote-pi/config.json` | Per-directory | `agent_name`, `session_name`, `auto_start_relay` |
597
+ | `~/.pi/remote/config.json` | Per-user | `relay` URL |
598
+ | `~/.pi/remote/peers.json` | Per-machine | Paired PWA browser profiles |
599
+ | `~/.pi/remote/sessions/<name>/` | Per-session | Broker socket + `audit.jsonl` |
600
+ | `~/.pi/remote/skills/agent-network/SKILL.md` | Per-user | Agent skill the LLM reads |
601
+
602
+ Override the relay for a single run without persisting:
603
+
604
+ ```bash
605
+ REMOTE_PI_RELAY=https://staging.example.tld pi
606
+ ```
607
+
608
+ ---
609
+
610
+ ## Troubleshooting
611
+
612
+ **Footer says `🟡 relay waiting for pairing` even though I paired a device.**
613
+ The icon reflects whether *any* device has been paired on this machine, not
614
+ whether one is connected right now. If you really have a paired device in
615
+ `/remote-pi devices`, restart Pi — the cache may be stale (fixed in current
616
+ release; report a bug if it recurs).
617
+
618
+ **PWA times out connecting.** Verify the same relay URL is configured
619
+ on both sides. If you self-host behind a VPN, the browser must also be on the
620
+ VPN.
621
+
622
+ **`agent_request` keeps timing out.** It is deprecated because it blocks the
623
+ turn while waiting for another agent's content reply. Migrate to `agent_send`;
624
+ a unicast waits only for the delivery ACK, and the receiver can reply later
625
+ with `agent_send` including `re: "<original-id>"` for correlation.
626
+
627
+ **Multiple terminals in the same directory.** Supported. They share the same
628
+ agent-network session (UDS broker) and the relay handles each Pi process
629
+ independently. If the relay refuses with `RoomAlreadyOpenError`, stop the
630
+ other terminal first.
631
+
632
+ ---
633
+
634
+ ## Branding
635
+
636
+ Official brand assets live in
637
+ [`/branding`](https://github.com/jacobaraujo7/remote_pi/tree/main/branding) —
638
+ SVG sources for the logo (full, foreground, background, monochrome) plus a
639
+ banner. See the
640
+ [branding README](https://github.com/jacobaraujo7/remote_pi/blob/main/branding/README.md)
641
+ for palette and export sizes.
642
+
643
+ <table>
644
+ <tr>
645
+ <td align="center">
646
+ <img src="https://raw.githubusercontent.com/jacobaraujo7/remote_pi/main/branding/logo-full.svg" width="96" alt="logo-full" /><br/>
647
+ <sub><code>logo-full</code></sub>
648
+ </td>
649
+ <td align="center">
650
+ <img src="https://raw.githubusercontent.com/jacobaraujo7/remote_pi/main/branding/logo-foreground.svg" width="96" alt="logo-foreground" /><br/>
651
+ <sub><code>logo-foreground</code></sub>
652
+ </td>
653
+ <td align="center">
654
+ <img src="https://raw.githubusercontent.com/jacobaraujo7/remote_pi/main/branding/logo-monochrome.svg" width="96" alt="logo-monochrome" /><br/>
655
+ <sub><code>logo-monochrome</code></sub>
656
+ </td>
657
+ </tr>
658
+ </table>
659
+
660
+ ---
661
+
662
+ ## Links
663
+
664
+ - Homepage: <https://remote-pi.jacobmoura.work>
665
+ - Source: <https://github.com/jacobaraujo7/remote_pi>
666
+ - Pi coding agent: <https://github.com/earendil-works/pi>
667
+ - Relay (self-hosting guide): <https://github.com/jacobaraujo7/remote_pi/blob/main/relay/README.md>
668
+ - Issues / bugs: <https://github.com/jacobaraujo7/remote_pi/issues>
669
+
670
+ ---
671
+
672
+ ## License
673
+
674
+ MIT