pi-agent-swarm 0.0.0 β 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/LICENSE +21 -0
- package/README.md +227 -2
- package/dist/chunks/chunk-XD4GFZPB.ts +39 -0
- package/dist/chunks/chunk-XD4GFZPB.ts.map +7 -0
- package/dist/chunks/menu-MZS6N2VS.ts +348 -0
- package/dist/chunks/menu-MZS6N2VS.ts.map +7 -0
- package/dist/index.ts +4053 -0
- package/dist/index.ts.map +7 -0
- package/package.json +54 -2
- package/src/color.ts +79 -0
- package/src/external.ts +150 -0
- package/src/i3-workspace.ts +281 -0
- package/src/index.ts +1 -0
- package/src/launch-envelope.ts +124 -0
- package/src/launcher.ts +93 -0
- package/src/menu.ts +397 -0
- package/src/pi-agent-swarm.ts +194 -0
- package/src/pi-invocation.ts +144 -0
- package/src/protocol.ts +766 -0
- package/src/reload-handoff.ts +33 -0
- package/src/renderer.ts +30 -0
- package/src/runtime-directory.ts +249 -0
- package/src/settings.ts +358 -0
- package/src/swarm-controller.ts +1270 -0
- package/src/terminal.ts +54 -0
- package/src/text.ts +42 -0
- package/src/tools.ts +275 -0
- package/src/transport-io.ts +155 -0
- package/src/transport.ts +935 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 narumiruna
|
|
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
CHANGED
|
@@ -1,3 +1,228 @@
|
|
|
1
|
-
#
|
|
1
|
+
# π Pi Agent Swarm β Launch and Connect Local Pi Sessions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/pi-agent-swarm) [](https://pi.dev) [](./LICENSE)
|
|
4
|
+
|
|
5
|
+
Launch another Pi process in an external terminal window without replacing the current session.
|
|
6
|
+
You can also connect trusted local Pi sessions for bounded notifications and one-turn requests.
|
|
7
|
+
Every agent is a real terminal window tiled by your window manager β never a headless child process.
|
|
8
|
+
|
|
9
|
+
## β¨ Features
|
|
10
|
+
|
|
11
|
+
- Opens a distinct Pi process in an external terminal window while preserving the parent session.
|
|
12
|
+
- Pins each new window to the lead session's workspace instead of the focused one.
|
|
13
|
+
- Inherits the cwd, model, thinking level, and optional first task after launch review.
|
|
14
|
+
- Waits for the child to authenticate before reporting that the new session is ready.
|
|
15
|
+
- Connects explicitly joined same-user sessions through owner-only local sockets and ephemeral invites.
|
|
16
|
+
- Delivers notifications without a model turn and bounds each allowed request to one turn.
|
|
17
|
+
- Relays user input from a worker window into the leader's model context.
|
|
18
|
+
- Authenticates and bounds local protocol traffic, peers, retries, rates, deadlines, and diagnostics.
|
|
19
|
+
- Cleans all sockets, launchers, tasks, timers, and status on leave, reload, replacement, or shutdown.
|
|
20
|
+
|
|
21
|
+
## π¦ Install
|
|
22
|
+
|
|
23
|
+
Install persistently:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pi install npm:pi-agent-swarm
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Try the published package without a permanent install:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pi -e npm:pi-agent-swarm
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Build and load the extension from a local checkout:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm --workspace pi-agent-swarm run build
|
|
39
|
+
pi --no-extensions --no-skills --no-session -e ./packages/pi-agent-swarm
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The package declares `dist/index.ts`, so an unbuilt local checkout must run the build before Pi loads the package directory.
|
|
43
|
+
A child started in any terminal uses normal Pi extension discovery.
|
|
44
|
+
Install Pi Agent Swarm persistently to test spawn-and-auto-join because the child does not inherit the parent's temporary `-e` argument.
|
|
45
|
+
|
|
46
|
+
Pi extensions execute with your user permissions.
|
|
47
|
+
Review extension source before installing it.
|
|
48
|
+
|
|
49
|
+
## π Quick start
|
|
50
|
+
|
|
51
|
+
Run `/swarm`, choose **New Pi sessionβ¦**, select a window direction, and optionally enter a first task.
|
|
52
|
+
Before creating a window, Pi Agent Swarm asks for the configured launch confirmation.
|
|
53
|
+
|
|
54
|
+
## π§ Launch flow
|
|
55
|
+
|
|
56
|
+
Use **Settings** to change final launch confirmation or toggle lead-workspace pinning.
|
|
57
|
+
New windows are launched through the configured external terminal command.
|
|
58
|
+
|
|
59
|
+
After any configured launch confirmation, Pi Agent Swarm:
|
|
60
|
+
|
|
61
|
+
1. Creates or reuses an ephemeral local group.
|
|
62
|
+
2. Starts the external terminal command.
|
|
63
|
+
3. Starts a separate named Pi process in the selected cwd.
|
|
64
|
+
4. Waits for the child to authenticate and report readiness.
|
|
65
|
+
5. Sends the optional first task through a launch-specific one-time kickoff.
|
|
66
|
+
|
|
67
|
+
If the terminal creates a window but the child does not become ready, Pi Agent Swarm reports a partial launch.
|
|
68
|
+
It leaves the visible window open instead of closing a potentially useful process.
|
|
69
|
+
|
|
70
|
+
## π οΈ Tools
|
|
71
|
+
|
|
72
|
+
### `session_spawn`
|
|
73
|
+
|
|
74
|
+
Creates a separate Pi process in an external terminal window.
|
|
75
|
+
|
|
76
|
+
| Parameter | Required | Description |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `direction` | No | `right`, `down`, `left`, or `up`; defaults to `right`. |
|
|
79
|
+
| `task` | No | First task sent only after authenticated readiness. |
|
|
80
|
+
| `name` | No | Child session display name. |
|
|
81
|
+
| `color` | No | Child color: a palette name or a `#rrggbb` hex. |
|
|
82
|
+
| `model` | No | Child model as `provider/id`; defaults to inheriting the current session model. |
|
|
83
|
+
| `cwd` | No | Existing directory; defaults to the current cwd. |
|
|
84
|
+
|
|
85
|
+
The tool supports only TUI and RPC modes because launch may require confirmation.
|
|
86
|
+
In JSON and print modes, it fails before creating a group, launcher, or window.
|
|
87
|
+
Successful details include `terminalId` and `terminalVersion`.
|
|
88
|
+
|
|
89
|
+
### `session_bus`
|
|
90
|
+
|
|
91
|
+
Lists or messages sessions in the active Pi Agent Swarm group.
|
|
92
|
+
|
|
93
|
+
| Action | Fields | Behavior |
|
|
94
|
+
| --- | --- | --- |
|
|
95
|
+
| `list` | none | Lists authenticated live peers and request policy. |
|
|
96
|
+
| `send` | `targetSessionId`, `message`, optional `mode` | Sends `notify` by default or a permitted one-turn `request`. |
|
|
97
|
+
| `reply` | `targetSessionId`, `message`, `replyTo` | Correlates a reply without starting another automatic turn. |
|
|
98
|
+
| `shutdown` | `targetSessionId` | Asks a peer to shut down gracefully. |
|
|
99
|
+
|
|
100
|
+
An accepted acknowledgement means the recipient extension accepted or deduplicated the message, not that the remote agent completed the work.
|
|
101
|
+
Rejected and busy acknowledgements use stable codes such as `requests_disabled`, `rate_limited`, `target_busy`, `shutdown_unauthorized`, and `delivery_failed`.
|
|
102
|
+
Rate-limited responses may include a bounded retry delay.
|
|
103
|
+
Peer-list text and details share a 40 KiB UTF-8 result budget below Pi's tool-output limit.
|
|
104
|
+
|
|
105
|
+
## π¬ Commands
|
|
106
|
+
|
|
107
|
+
| Command | Purpose |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `/swarm` | Launch Pi sessions and manage group messaging, peers, invites, and request policy. |
|
|
110
|
+
| `/swarm <piagentswarm:v1:invite>` | Review the join confirmation and join one ephemeral local group. |
|
|
111
|
+
| `/lead` | Promote a session to leader or inspect the current leader. |
|
|
112
|
+
| `/color` | Set the current session's footer color. |
|
|
113
|
+
|
|
114
|
+
All routes support TUI and RPC, reject unknown or trailing arguments, and fail in print or JSON mode before opening sockets.
|
|
115
|
+
Review the [launch flow](#-launch-flow) and [Security and privacy](#-security-and-privacy): accepted peer requests can start paid model turns.
|
|
116
|
+
|
|
117
|
+
## π₯οΈ External terminal backend
|
|
118
|
+
|
|
119
|
+
Pi Agent Swarm launches each session as a plain terminal window through a configurable command (default `alacritty -e`).
|
|
120
|
+
The window manager β any tiling window manager β decides where the window appears.
|
|
121
|
+
|
|
122
|
+
When `pinToLeadWorkspace` is enabled, Pi Agent Swarm snapshots the window tree before creating the window, locates the lead session's workspace by walking the process tree to the terminal's `_NET_WM_PID`, and moves the new window onto that workspace as soon as it appears.
|
|
123
|
+
Placement is best-effort: if the window manager cannot move the window, it stays where it was placed.
|
|
124
|
+
|
|
125
|
+
## βοΈ Settings
|
|
126
|
+
|
|
127
|
+
Open `/swarm` and choose **Settings**.
|
|
128
|
+
Pi Agent Swarm stores user settings in `<getAgentDir()>/pi-agent-swarm.json`, normally `~/.pi/agent/pi-agent-swarm.json`:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"externalCommand": "alacritty -e",
|
|
133
|
+
"confirmSessionLaunch": true,
|
|
134
|
+
"pinToLeadWorkspace": false
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Setting | Values | Default | Behavior |
|
|
139
|
+
| --- | --- | --- | --- |
|
|
140
|
+
| `externalCommand` | any terminal command | `alacritty -e` | Command used to open each new window. |
|
|
141
|
+
| `confirmSessionLaunch` | `true`, `false` | `true` | Shows or skips the final launch preview for menu and tool launches. |
|
|
142
|
+
| `pinToLeadWorkspace` | `true`, `false` | `false` | Moves each new window onto the lead session's workspace instead of the focused one. |
|
|
143
|
+
|
|
144
|
+
Pi Agent Swarm does not read project settings or extension-specific environment-variable overrides.
|
|
145
|
+
A missing file uses the defaults without creating the file.
|
|
146
|
+
Each Settings change saves immediately.
|
|
147
|
+
Writes preserve unknown fields, run in order within one Pi process, and publish atomically through a private temporary file and rename.
|
|
148
|
+
The Settings screen reports malformed or invalid files and does not overwrite them.
|
|
149
|
+
Separate Pi processes do not share a settings lock, so do not edit this file concurrently from multiple sessions.
|
|
150
|
+
A Settings change applies immediately in the current process; other running Pi processes reload it on their next session start or `/reload`.
|
|
151
|
+
|
|
152
|
+
Group secrets, request permission, peers, readiness state, and deduplication state stay in memory.
|
|
153
|
+
The `piagentswarm:v1` prefix versions the bearer-invite encoding separately from the version-3 socket protocol.
|
|
154
|
+
Version-3 messages normally expire after two minutes and cannot declare a lifetime longer than five minutes.
|
|
155
|
+
Accepted message ids remain deduplicated for ten minutes, longer than their valid delivery window.
|
|
156
|
+
A copied invite is still a reusable bearer secret, so discard it or start a new group when you need to rotate access.
|
|
157
|
+
A short-lived in-process handoff preserves a group across `/reload` for the same `sessionManager` only.
|
|
158
|
+
Membership does not carry into `/new`, `/resume`, or another logical session without a new invite.
|
|
159
|
+
|
|
160
|
+
The terminal child receives an internal launch-only environment envelope containing a parent-only kickoff capability.
|
|
161
|
+
The child consumes and deletes those values during `session_start` before Pi tools can inherit them.
|
|
162
|
+
These values are not user settings or supported environment overrides.
|
|
163
|
+
|
|
164
|
+
Incoming agent requests are blocked by default.
|
|
165
|
+
Enabling them permits trusted invite holders to start paid model turns that may edit the same workspace concurrently.
|
|
166
|
+
|
|
167
|
+
## π Security and privacy
|
|
168
|
+
|
|
169
|
+
- Runtime directories are owned by the current user and restricted to `0700`, which is the portable filesystem access boundary.
|
|
170
|
+
- Endpoint manifests and Unix sockets are restricted to `0600` as additional platform-specific defense in depth.
|
|
171
|
+
- Discovery ignores symlinks, non-regular files, oversized manifests, wrong owners, malformed records, endpoint filename mismatches, and incompatible versions.
|
|
172
|
+
- Discovery scans at most 512 directory entries, accepts at most 64 valid manifests, probes at most 16 peers concurrently, and finishes under one overall deadline.
|
|
173
|
+
- Invalid manifests do not consume the valid-peer quota, and bounded non-secret diagnostics distinguish saturation, conflicts, protocol failures, deadlines, and unreachable peers.
|
|
174
|
+
- Every manifest, request, and response is authenticated for its group and endpoint instance.
|
|
175
|
+
Frames also bind the logical target, claimed sender, clock window, nonce, and request id.
|
|
176
|
+
- The shared group MAC proves possession of the bearer invite, not a separate cryptographic identity for each peer.
|
|
177
|
+
- A trusted invite holder can claim another session id, so session and endpoint labels are collaboration hints rather than a separate authorization boundary.
|
|
178
|
+
- Launch kickoffs also require a random capability shared only through the parent-to-child launch envelope.
|
|
179
|
+
It is not published through peer discovery or persisted with delivered messages.
|
|
180
|
+
- Two simultaneously live endpoints claiming one session id are omitted from discovery and rejected as an explicit identity conflict.
|
|
181
|
+
- Bearer invites are shown only on the explicit invite screen or direct join input.
|
|
182
|
+
- Pi Agent Swarm does not retain invites as durable settings or group state, but a recipient can copy and reuse one until every holder discards it or moves to a new group.
|
|
183
|
+
- Invites are not placed in tool output, status, notifications, custom renderers, or model context.
|
|
184
|
+
- Launch values briefly exist in a private `0700` launcher that unlinks itself before starting Pi, so terminal command metadata cannot retain them.
|
|
185
|
+
- Peer names, paths, messages, model ids, and errors are treated as untrusted terminal text and sanitized only at display boundaries.
|
|
186
|
+
- A same-user process or another privileged Pi extension is outside the security boundary and may inspect process arguments, private runtime files, memory, or environment.
|
|
187
|
+
- Pi Agent Swarm separates groups but does not sandbox them from the operating-system user.
|
|
188
|
+
|
|
189
|
+
## π§ Limitations
|
|
190
|
+
|
|
191
|
+
- Local same-user communication only.
|
|
192
|
+
- POSIX Unix-socket transport only.
|
|
193
|
+
- No LAN, internet, cross-user, remote-host, or public-room transport.
|
|
194
|
+
- No daemon, offline mailbox, separate Swarm history, delivery receipt, global ordering, or exactly-once guarantee.
|
|
195
|
+
- No automatic trust or discovery of every Pi process.
|
|
196
|
+
- No automatic close of a window after partial child startup.
|
|
197
|
+
- Protocol version 3 intentionally rejects version-1 and version-2 manifests and frames.
|
|
198
|
+
- One request uses one short-lived socket connection; there is no persistent multiplexed channel or delivery stream.
|
|
199
|
+
- Server connections use an absolute request deadline rather than an activity-reset timeout, and at most eight message deliveries run concurrently.
|
|
200
|
+
- Per-sender and endpoint-wide rate limits are fixed windows, so a busy response can require waiting before retrying.
|
|
201
|
+
- Old orphan temporary files, private launchers, and sockets are removed after a grace period.
|
|
202
|
+
Empty private group directories may remain to avoid cross-process startup races.
|
|
203
|
+
- No tab, window, resize, focus-navigation, or general layout manager.
|
|
204
|
+
- Multiple Pi sessions can still race while editing the same workspace.
|
|
205
|
+
|
|
206
|
+
## ποΈ Package layout
|
|
207
|
+
|
|
208
|
+
```text
|
|
209
|
+
packages/pi-agent-swarm/
|
|
210
|
+
βββ src/ # Authoritative implementation and helpers
|
|
211
|
+
β βββ index.ts # Thin Pi entrypoint
|
|
212
|
+
β βββ pi-agent-swarm.ts # Local session launch and messaging
|
|
213
|
+
β βββ i3-workspace.ts # Lead-workspace window pinning
|
|
214
|
+
βββ dist/ # Generated Jiti runtime
|
|
215
|
+
βββ scripts/build-runtime.mjs # Runtime builder
|
|
216
|
+
βββ test/ # Behavior and lifecycle coverage
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The generated runtime is built from `src/index.ts` and does not import back into `src`.
|
|
220
|
+
|
|
221
|
+
## π Keywords
|
|
222
|
+
|
|
223
|
+
Pi extension, Pi Agent Swarm, Pi sessions, external terminal, tiling window manager, local agents, agent communication, Unix socket, TypeScript.
|
|
224
|
+
|
|
225
|
+
## π License
|
|
226
|
+
|
|
227
|
+
MIT.
|
|
228
|
+
See [`LICENSE`](./LICENSE).
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
|
|
4
|
+
// src/text.ts
|
|
5
|
+
function safeTerminalText(value) {
|
|
6
|
+
let output = "";
|
|
7
|
+
for (const character of value) {
|
|
8
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
9
|
+
if (isTerminalControl(codePoint)) continue;
|
|
10
|
+
output += character === " " ? " " : character;
|
|
11
|
+
}
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
14
|
+
function safeTerminalLine(value) {
|
|
15
|
+
return safeTerminalText(value).replace(/[\r\n]+/gu, " ").trim();
|
|
16
|
+
}
|
|
17
|
+
function safeError(error) {
|
|
18
|
+
return safeTerminalLine(error instanceof Error ? error.message : String(error));
|
|
19
|
+
}
|
|
20
|
+
function normalizeOptionalText(value, label, maxBytes) {
|
|
21
|
+
if (value === void 0) return void 0;
|
|
22
|
+
const normalized = value.trim();
|
|
23
|
+
if (!normalized) return void 0;
|
|
24
|
+
if (normalized.includes("\0") || Buffer.byteLength(normalized) > maxBytes) {
|
|
25
|
+
throw new Error(`Pi Agent Swarm ${label} is invalid or too large`);
|
|
26
|
+
}
|
|
27
|
+
return normalized;
|
|
28
|
+
}
|
|
29
|
+
function isTerminalControl(codePoint) {
|
|
30
|
+
return codePoint >= 0 && codePoint <= 8 || codePoint === 11 || codePoint === 12 || codePoint === 13 || codePoint >= 14 && codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
safeTerminalText,
|
|
35
|
+
safeTerminalLine,
|
|
36
|
+
safeError,
|
|
37
|
+
normalizeOptionalText
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-XD4GFZPB.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/text.ts"],
|
|
4
|
+
"sourcesContent": ["export function safeTerminalText(value: string): string {\n let output = \"\";\n for (const character of value) {\n const codePoint = character.codePointAt(0) ?? 0;\n if (isTerminalControl(codePoint)) continue;\n output += character === \"\\t\" ? \" \" : character;\n }\n return output;\n}\n\nexport function safeTerminalLine(value: string): string {\n return safeTerminalText(value)\n .replace(/[\\r\\n]+/gu, \" \")\n .trim();\n}\n\nexport function safeError(error: unknown): string {\n return safeTerminalLine(error instanceof Error ? error.message : String(error));\n}\n\nexport function normalizeOptionalText(value: string | undefined, label: string, maxBytes: number): string | undefined {\n if (value === undefined) return undefined;\n const normalized = value.trim();\n if (!normalized) return undefined;\n if (normalized.includes(\"\\0\") || Buffer.byteLength(normalized) > maxBytes) {\n throw new Error(`Pi Agent Swarm ${label} is invalid or too large`);\n }\n return normalized;\n}\n\nfunction isTerminalControl(codePoint: number): boolean {\n return (\n (codePoint >= 0x00 && codePoint <= 0x08) ||\n codePoint === 0x0b ||\n codePoint === 0x0c ||\n codePoint === 0x0d ||\n (codePoint >= 0x0e && codePoint <= 0x1f) ||\n (codePoint >= 0x7f && codePoint <= 0x9f) ||\n (codePoint >= 0x202a && codePoint <= 0x202e) ||\n (codePoint >= 0x2066 && codePoint <= 0x2069)\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAAO,SAAS,iBAAiB,OAAuB;AACtD,MAAI,SAAS;AACb,aAAW,aAAa,OAAO;AAC7B,UAAM,YAAY,UAAU,YAAY,CAAC,KAAK;AAC9C,QAAI,kBAAkB,SAAS,EAAG;AAClC,cAAU,cAAc,MAAO,SAAS;AAAA,EAC1C;AACA,SAAO;AACT;AAEO,SAAS,iBAAiB,OAAuB;AACtD,SAAO,iBAAiB,KAAK,EAC1B,QAAQ,aAAa,GAAG,EACxB,KAAK;AACV;AAEO,SAAS,UAAU,OAAwB;AAChD,SAAO,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAChF;AAEO,SAAS,sBAAsB,OAA2B,OAAe,UAAsC;AACpH,MAAI,UAAU,OAAW,QAAO;AAChC,QAAM,aAAa,MAAM,KAAK;AAC9B,MAAI,CAAC,WAAY,QAAO;AACxB,MAAI,WAAW,SAAS,IAAI,KAAK,OAAO,WAAW,UAAU,IAAI,UAAU;AACzE,UAAM,IAAI,MAAM,kBAAkB,KAAK,0BAA0B;AAAA,EACnE;AACA,SAAO;AACT;AAEA,SAAS,kBAAkB,WAA4B;AACrD,SACG,aAAa,KAAQ,aAAa,KACnC,cAAc,MACd,cAAc,MACd,cAAc,MACb,aAAa,MAAQ,aAAa,MAClC,aAAa,OAAQ,aAAa,OAClC,aAAa,QAAU,aAAa,QACpC,aAAa,QAAU,aAAa;AAEzC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
safeError,
|
|
5
|
+
safeTerminalLine
|
|
6
|
+
} from "./chunk-XD4GFZPB.ts";
|
|
7
|
+
|
|
8
|
+
// src/menu.ts
|
|
9
|
+
var DIRECTION_OPTIONS = ["Right", "Down", "Left", "Up"];
|
|
10
|
+
function createSwarmMenu(source) {
|
|
11
|
+
const getState = ({ signal } = {}) => source.snapshot(signal);
|
|
12
|
+
const menu = {
|
|
13
|
+
start: "main",
|
|
14
|
+
screens: {
|
|
15
|
+
main: ({ state }) => mainScreen(state),
|
|
16
|
+
join: () => ({
|
|
17
|
+
kind: "input",
|
|
18
|
+
title: "Join Pi Agent Swarm",
|
|
19
|
+
lines: [
|
|
20
|
+
"Paste a local piagentswarm:v1 bearer invite.",
|
|
21
|
+
"Anyone holding it can message this Pi session while both processes are running."
|
|
22
|
+
],
|
|
23
|
+
placeholder: "piagentswarm:v1:\u2026",
|
|
24
|
+
action: "join",
|
|
25
|
+
hint: "back"
|
|
26
|
+
}),
|
|
27
|
+
sessions: ({ state }) => ({
|
|
28
|
+
kind: "browse",
|
|
29
|
+
title: "Pi Agent Swarm sessions",
|
|
30
|
+
lines: state.peers.length ? ["Authenticated live sessions in this ephemeral local group."] : ["No other live sessions are currently authenticated."],
|
|
31
|
+
items: state.peers.map((peer) => ({
|
|
32
|
+
id: peer.sessionId,
|
|
33
|
+
label: safeTerminalLine(peer.name ?? peer.sessionId),
|
|
34
|
+
statusText: peer.acceptsRequests ? "requests allowed" : "messages only",
|
|
35
|
+
description: safeTerminalLine(peer.cwd),
|
|
36
|
+
details: [
|
|
37
|
+
`Session: ${safeTerminalLine(peer.sessionId)}`,
|
|
38
|
+
`Process: ${peer.pid}`,
|
|
39
|
+
...peer.launchId ? [`Launch: ${safeTerminalLine(peer.launchId)}`] : []
|
|
40
|
+
]
|
|
41
|
+
})),
|
|
42
|
+
viewportSize: "adaptive",
|
|
43
|
+
hint: "back"
|
|
44
|
+
}),
|
|
45
|
+
invite: ({ state }) => ({
|
|
46
|
+
kind: "review",
|
|
47
|
+
title: "Pi Agent Swarm bearer invite",
|
|
48
|
+
lines: [
|
|
49
|
+
"Copy this only into another local Pi session you trust.",
|
|
50
|
+
"Pi Agent Swarm does not save the invite, but any copied bearer remains usable until its holder discards it."
|
|
51
|
+
],
|
|
52
|
+
content: state.invite ?? "Invite is unavailable.",
|
|
53
|
+
format: { kind: "text" },
|
|
54
|
+
viewportSize: "adaptive",
|
|
55
|
+
hint: "back"
|
|
56
|
+
}),
|
|
57
|
+
requestPolicy: ({ state }) => ({
|
|
58
|
+
kind: "choice",
|
|
59
|
+
title: "Incoming agent requests",
|
|
60
|
+
lines: [
|
|
61
|
+
"Messages always enter context without starting a turn.",
|
|
62
|
+
"Allowed requests may spend model tokens and edit this workspace concurrently."
|
|
63
|
+
],
|
|
64
|
+
items: [
|
|
65
|
+
{ id: "block", label: "Messages only", description: "Do not start remote-request turns" },
|
|
66
|
+
{ id: "allow", label: "Allow requests", description: "Permit one turn per request" }
|
|
67
|
+
],
|
|
68
|
+
action: "setPolicy",
|
|
69
|
+
currentItemId: state.acceptsRequests ? "allow" : "block",
|
|
70
|
+
initialItemId: state.acceptsRequests ? "allow" : "block",
|
|
71
|
+
viewportSize: 4,
|
|
72
|
+
hint: "back"
|
|
73
|
+
}),
|
|
74
|
+
settings: ({ state }) => ({
|
|
75
|
+
kind: "settings",
|
|
76
|
+
title: "Pi Agent Swarm Settings",
|
|
77
|
+
lines: [`User settings \xB7 ${safeTerminalLine(state.settingsPath)}`],
|
|
78
|
+
items: [
|
|
79
|
+
{
|
|
80
|
+
id: "confirmSessionLaunch",
|
|
81
|
+
label: "Confirm new sessions",
|
|
82
|
+
description: "Ask before a new Pi process may spend tokens or edit the workspace.",
|
|
83
|
+
currentValue: state.settings.confirmSessionLaunch ? "Ask" : "Skip",
|
|
84
|
+
values: ["Ask", "Skip"],
|
|
85
|
+
action: "setConfirmation"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "pinToLeadWorkspace",
|
|
89
|
+
label: "Pin new windows to lead workspace",
|
|
90
|
+
description: "On i3, place new external windows on the lead session's workspace instead of the focused one.",
|
|
91
|
+
currentValue: state.settings.pinToLeadWorkspace ? "On" : "Off",
|
|
92
|
+
values: ["On", "Off"],
|
|
93
|
+
action: "setPinToLeadWorkspace"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}),
|
|
97
|
+
settingsInvalid: ({ state }) => ({
|
|
98
|
+
kind: "detail",
|
|
99
|
+
title: "Pi Agent Swarm Settings \xB7 Read only",
|
|
100
|
+
lines: [
|
|
101
|
+
`Invalid settings file. Fix ${safeTerminalLine(state.settingsPath)} and run /reload. The file will not be overwritten.`,
|
|
102
|
+
...state.issue ? [`Issue: ${safeTerminalLine(state.issue.message)}`] : []
|
|
103
|
+
],
|
|
104
|
+
hint: "back"
|
|
105
|
+
}),
|
|
106
|
+
status: ({ state }) => ({
|
|
107
|
+
kind: "detail",
|
|
108
|
+
title: "Pi Agent Swarm status",
|
|
109
|
+
lines: state.connected ? [
|
|
110
|
+
"State: connected",
|
|
111
|
+
`Session: ${safeTerminalLine(state.self?.name ?? state.self?.sessionId ?? "unknown")}`,
|
|
112
|
+
`Cwd: ${safeTerminalLine(state.self?.cwd ?? "unknown")}`,
|
|
113
|
+
`Other live sessions: ${state.peers.length}`,
|
|
114
|
+
`Incoming requests: ${state.acceptsRequests ? "allowed" : "blocked"}`,
|
|
115
|
+
`Launch confirmation: ${state.settings.confirmSessionLaunch ? "Ask" : "Skip"}`,
|
|
116
|
+
`Pin new windows to lead workspace: ${state.settings.pinToLeadWorkspace ? "On" : "Off"}`,
|
|
117
|
+
"Delivery acknowledgement means extension acceptance, not remote task completion."
|
|
118
|
+
] : [
|
|
119
|
+
"State: disconnected",
|
|
120
|
+
"No socket, group secret, or background discovery is active.",
|
|
121
|
+
`Launch confirmation: ${state.settings.confirmSessionLaunch ? "Ask" : "Skip"}`,
|
|
122
|
+
`Pin new windows to lead workspace: ${state.settings.pinToLeadWorkspace ? "On" : "Off"}`
|
|
123
|
+
],
|
|
124
|
+
hint: "back"
|
|
125
|
+
}),
|
|
126
|
+
help: () => ({
|
|
127
|
+
kind: "detail",
|
|
128
|
+
title: "Pi Agent Swarm help",
|
|
129
|
+
lines: [
|
|
130
|
+
"Pi Agent Swarm connects explicit sessions owned by one OS user.",
|
|
131
|
+
"New Pi session creates a separate process in an external terminal window and preserves the parent.",
|
|
132
|
+
"Notify messages do not start turns, requests require recipient permission, and replies do not auto-trigger another turn.",
|
|
133
|
+
"Groups, invites, peer state, and message deduplication are ephemeral."
|
|
134
|
+
],
|
|
135
|
+
hint: "back"
|
|
136
|
+
}),
|
|
137
|
+
leave: ({ state }) => ({
|
|
138
|
+
kind: "review",
|
|
139
|
+
title: "Leave Pi Agent Swarm group?",
|
|
140
|
+
lines: [
|
|
141
|
+
`Other live sessions: ${state.peers.length}`,
|
|
142
|
+
"Leaving closes this session's socket and forgets its in-memory bearer invite."
|
|
143
|
+
],
|
|
144
|
+
content: "Already delivered peer messages remain in each Pi session transcript.",
|
|
145
|
+
format: { kind: "text" },
|
|
146
|
+
confirm: { id: "leave", label: "Leave group", action: "leave" },
|
|
147
|
+
hint: "back"
|
|
148
|
+
})
|
|
149
|
+
},
|
|
150
|
+
actions: {
|
|
151
|
+
spawn: async ({ ctx, signal }) => {
|
|
152
|
+
const directionChoice = await ctx.ui.select("Terminal window direction", [...DIRECTION_OPTIONS], {
|
|
153
|
+
signal
|
|
154
|
+
});
|
|
155
|
+
if (!directionChoice || signal.aborted) return { kind: "stay" };
|
|
156
|
+
const task = await ctx.ui.input("Optional first task", "Submit an empty value for an idle child session", {
|
|
157
|
+
signal
|
|
158
|
+
});
|
|
159
|
+
if (task === void 0 || signal.aborted) return { kind: "stay" };
|
|
160
|
+
await source.spawn(
|
|
161
|
+
ctx,
|
|
162
|
+
{
|
|
163
|
+
direction: directionChoice.toLowerCase(),
|
|
164
|
+
...task ? { task } : {}
|
|
165
|
+
},
|
|
166
|
+
signal
|
|
167
|
+
);
|
|
168
|
+
return { kind: "close" };
|
|
169
|
+
},
|
|
170
|
+
start: async ({ ctx, signal }) => {
|
|
171
|
+
const confirmed = await ctx.ui.confirm(
|
|
172
|
+
"Start local Pi Agent Swarm group?",
|
|
173
|
+
"This creates one owner-only Unix socket and an ephemeral bearer invite. Incoming requests start blocked.",
|
|
174
|
+
{ signal }
|
|
175
|
+
);
|
|
176
|
+
if (!confirmed || signal.aborted) return { kind: "stay" };
|
|
177
|
+
await source.start(ctx, signal);
|
|
178
|
+
return { kind: "stay" };
|
|
179
|
+
},
|
|
180
|
+
join: async ({ ctx, signal, value }) => {
|
|
181
|
+
if (!value) return { kind: "rejected", error: new Error("Pi Agent Swarm invite is required") };
|
|
182
|
+
const confirmed = await ctx.ui.confirm(
|
|
183
|
+
"Join local Pi Agent Swarm group?",
|
|
184
|
+
"The bearer invite permits local peer messages. Incoming agent requests start blocked.",
|
|
185
|
+
{ signal }
|
|
186
|
+
);
|
|
187
|
+
if (!confirmed || signal.aborted) return { kind: "stay" };
|
|
188
|
+
await source.join(ctx, value, signal);
|
|
189
|
+
return { kind: "to", screen: "main" };
|
|
190
|
+
},
|
|
191
|
+
send: async ({ ctx, signal, state }) => {
|
|
192
|
+
if (state.peers.length === 0) {
|
|
193
|
+
return { kind: "rejected", error: new Error("No other live Pi Agent Swarm sessions") };
|
|
194
|
+
}
|
|
195
|
+
const labels = state.peers.map(
|
|
196
|
+
(peer2) => `${safeTerminalLine(peer2.name ?? peer2.sessionId)} \xB7 ${safeTerminalLine(peer2.sessionId)}`
|
|
197
|
+
);
|
|
198
|
+
const selected = await ctx.ui.select("Send to Pi session", labels, { signal });
|
|
199
|
+
if (!selected || signal.aborted) return { kind: "stay" };
|
|
200
|
+
const peer = state.peers[labels.indexOf(selected)];
|
|
201
|
+
if (!peer) return { kind: "rejected", error: new Error("Selected peer is stale") };
|
|
202
|
+
const modeLabel = await ctx.ui.select(
|
|
203
|
+
"Delivery mode",
|
|
204
|
+
["Message only", "Agent request \u2014 may start a paid turn"],
|
|
205
|
+
{ signal }
|
|
206
|
+
);
|
|
207
|
+
if (!modeLabel || signal.aborted) return { kind: "stay" };
|
|
208
|
+
const text = await ctx.ui.input("Message", "Type a bounded message", { signal });
|
|
209
|
+
if (!text || signal.aborted) return { kind: "stay" };
|
|
210
|
+
await source.send(
|
|
211
|
+
ctx,
|
|
212
|
+
{
|
|
213
|
+
targetSessionId: peer.sessionId,
|
|
214
|
+
text,
|
|
215
|
+
mode: modeLabel.startsWith("Agent request") ? "request" : "notify"
|
|
216
|
+
},
|
|
217
|
+
signal
|
|
218
|
+
);
|
|
219
|
+
return { kind: "stay" };
|
|
220
|
+
},
|
|
221
|
+
setConfirmation: ({ ctx, signal, value }) => saveSettingsPatch(
|
|
222
|
+
source,
|
|
223
|
+
ctx,
|
|
224
|
+
signal,
|
|
225
|
+
{ confirmSessionLaunch: value !== "Skip" },
|
|
226
|
+
`Confirm new sessions: ${value}.`
|
|
227
|
+
),
|
|
228
|
+
setPinToLeadWorkspace: ({ ctx, signal, value }) => saveSettingsPatch(
|
|
229
|
+
source,
|
|
230
|
+
ctx,
|
|
231
|
+
signal,
|
|
232
|
+
{ pinToLeadWorkspace: value !== "Off" },
|
|
233
|
+
`Pin new windows to lead workspace: ${value}.`
|
|
234
|
+
),
|
|
235
|
+
setPolicy: async ({ ctx, signal, itemId }) => {
|
|
236
|
+
const allow = itemId === "allow";
|
|
237
|
+
if (itemId !== "allow" && itemId !== "block") {
|
|
238
|
+
return { kind: "rejected", error: new Error("Pi Agent Swarm request policy is invalid") };
|
|
239
|
+
}
|
|
240
|
+
if (allow) {
|
|
241
|
+
const confirmed = await ctx.ui.confirm(
|
|
242
|
+
"Allow incoming agent requests?",
|
|
243
|
+
"A trusted invite holder may start paid model turns that can edit the current workspace.",
|
|
244
|
+
{ signal }
|
|
245
|
+
);
|
|
246
|
+
if (!confirmed || signal.aborted) return { kind: "stay" };
|
|
247
|
+
}
|
|
248
|
+
source.setAcceptsRequests(allow);
|
|
249
|
+
return { kind: "to", screen: "requestPolicy" };
|
|
250
|
+
},
|
|
251
|
+
leave: async () => {
|
|
252
|
+
await source.leave();
|
|
253
|
+
return { kind: "to", screen: "main" };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
return { menu, getState };
|
|
258
|
+
}
|
|
259
|
+
async function showSwarmMenu(ctx, source, ownership) {
|
|
260
|
+
const { runMenu } = await import("@narumitw/pi-tui-kit");
|
|
261
|
+
if (ownership.signal.aborted || !ownership.isCurrent()) return;
|
|
262
|
+
const controller = createSwarmMenu(source);
|
|
263
|
+
await runMenu(ctx, controller.menu, {
|
|
264
|
+
getState: controller.getState,
|
|
265
|
+
signal: ownership.signal,
|
|
266
|
+
isCurrent: ownership.isCurrent,
|
|
267
|
+
onError: (_ctx, error) => {
|
|
268
|
+
if (ownership.isCurrent() && !ownership.signal.aborted) {
|
|
269
|
+
ctx.ui.notify(`Pi Agent Swarm failed: ${safeError(error)}`, "error");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async function saveSettingsPatch(source, ctx, signal, patch, successMessage) {
|
|
275
|
+
if (signal.aborted) return { kind: "rejected" };
|
|
276
|
+
try {
|
|
277
|
+
await source.updateSettings(patch, signal);
|
|
278
|
+
if (signal.aborted) return { kind: "rejected" };
|
|
279
|
+
ctx.ui.notify(successMessage, "info");
|
|
280
|
+
return { kind: "stay" };
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (!signal.aborted) {
|
|
283
|
+
ctx.ui.notify(`Could not save Pi Agent Swarm settings; the previous value remains: ${safeError(error)}`, "error");
|
|
284
|
+
}
|
|
285
|
+
return { kind: "rejected" };
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function settingsMenuItem(state) {
|
|
289
|
+
return state.issue ? {
|
|
290
|
+
id: "settings",
|
|
291
|
+
label: "Settings",
|
|
292
|
+
description: "Read-only until the invalid settings file is fixed.",
|
|
293
|
+
to: "settingsInvalid"
|
|
294
|
+
} : { id: "settings", label: "Settings", to: "settings" };
|
|
295
|
+
}
|
|
296
|
+
function mainScreen(state) {
|
|
297
|
+
if (!state.connected) {
|
|
298
|
+
return {
|
|
299
|
+
kind: "actions",
|
|
300
|
+
title: "Pi Agent Swarm \xB7 disconnected",
|
|
301
|
+
lines: ["Local Pi sessions with configured terminal launches and messaging."],
|
|
302
|
+
items: [
|
|
303
|
+
{
|
|
304
|
+
id: "spawn",
|
|
305
|
+
label: "New Pi session\u2026",
|
|
306
|
+
action: "spawn",
|
|
307
|
+
busyLabel: "Launching"
|
|
308
|
+
},
|
|
309
|
+
{ id: "join", label: "Join with invite", to: "join" },
|
|
310
|
+
{ id: "start", label: "Start local group", action: "start" },
|
|
311
|
+
settingsMenuItem(state),
|
|
312
|
+
{ id: "status", label: "Status", to: "status" },
|
|
313
|
+
{ id: "help", label: "Help", to: "help" }
|
|
314
|
+
],
|
|
315
|
+
hint: "close"
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
kind: "actions",
|
|
320
|
+
title: `Pi Agent Swarm \xB7 ${safeTerminalLine(state.self?.name ?? state.self?.sessionId ?? "connected")}`,
|
|
321
|
+
lines: [
|
|
322
|
+
`${state.peers.length} other live session${state.peers.length === 1 ? "" : "s"} \xB7 incoming requests ${state.acceptsRequests ? "allowed" : "blocked"}`,
|
|
323
|
+
"Delivery acknowledgement confirms extension acceptance only."
|
|
324
|
+
],
|
|
325
|
+
items: [
|
|
326
|
+
{
|
|
327
|
+
id: "spawn",
|
|
328
|
+
label: "New Pi session\u2026",
|
|
329
|
+
action: "spawn",
|
|
330
|
+
busyLabel: "Launching"
|
|
331
|
+
},
|
|
332
|
+
{ id: "send", label: "Send message", action: "send" },
|
|
333
|
+
{ id: "sessions", label: "Sessions", to: "sessions" },
|
|
334
|
+
{ id: "invite", label: "Invite another session", to: "invite" },
|
|
335
|
+
{ id: "policy", label: "Request policy", to: "requestPolicy" },
|
|
336
|
+
settingsMenuItem(state),
|
|
337
|
+
{ id: "status", label: "Status", to: "status" },
|
|
338
|
+
{ id: "help", label: "Help", to: "help" },
|
|
339
|
+
{ id: "leave", label: "Leave group\u2026", to: "leave" }
|
|
340
|
+
],
|
|
341
|
+
hint: "close"
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
export {
|
|
345
|
+
createSwarmMenu,
|
|
346
|
+
showSwarmMenu
|
|
347
|
+
};
|
|
348
|
+
//# sourceMappingURL=menu-MZS6N2VS.ts.map
|