peerband 0.1.5 → 0.2.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/herdr/control.mjs CHANGED
@@ -13,7 +13,8 @@ const matches = (a, b) => typeof a === "string" && timingSafeEqual(
13
13
  createHash("sha256").update(b).digest(),
14
14
  );
15
15
 
16
- export async function connectControl({ timeout = 3000, initialCommand } = {}) {
16
+ // Generous: on a loaded Windows machine the helper can take seconds to answer even a local pipe.
17
+ export async function connectControl({ timeout = 10_000, initialCommand } = {}) {
17
18
  const record = JSON.parse(await readFile(recordPath, "utf8"));
18
19
  const socket = createConnection(channel);
19
20
  await new Promise((resolve, reject) => {
@@ -16,15 +16,33 @@ const pluginRoot = resolve(dirname(script), "..");
16
16
  const connectorEntry = process.env.PEERBAND_CONNECTOR_ENTRY || join(pluginRoot, "dist", "peerband.mjs");
17
17
  const paneStatePath = relayStatePath(config);
18
18
 
19
+ // Starting Node can take several seconds on a loaded machine (5-8 s has been seen on Windows), so waits are
20
+ // deadlines measured in time, not a fixed number of quick retries.
21
+ const CONTROL_TIMEOUT_MS = 10_000;
22
+ const HELPER_START_MS = 30_000;
23
+ // A helper started for the Relay pane stops if no pane attaches within this time.
24
+ const AWAIT_UI_MS = 60_000;
25
+
26
+ async function waitForHelper() {
27
+ const deadline = Date.now() + HELPER_START_MS;
28
+ for (;;) {
29
+ try { return await request("status"); }
30
+ catch (error) {
31
+ if (Date.now() >= deadline) throw error;
32
+ await new Promise((resolve) => setTimeout(resolve, 200));
33
+ }
34
+ }
35
+ }
36
+
19
37
  async function request(command) {
20
- const socket = await connectControl({ initialCommand: command, timeout: 3000 });
38
+ const socket = await connectControl({ initialCommand: command, timeout: CONTROL_TIMEOUT_MS });
21
39
  return new Promise((resolve, reject) => {
22
40
  let text = "";
23
41
  let settled = false;
24
42
  const timer = setTimeout(() => {
25
43
  socket.destroy();
26
44
  finish(new Error("Helper control timeout"));
27
- }, 3000);
45
+ }, CONTROL_TIMEOUT_MS);
28
46
  const finish = (error, value) => {
29
47
  if (settled) return;
30
48
  settled = true;
@@ -154,10 +172,16 @@ async function supervise() {
154
172
  function forwardNote(input, reply) {
155
173
  const text = input.text;
156
174
  const paneId = input.paneId;
175
+ const channel = input.channel;
157
176
  if (typeof text !== "string" || text.length > 4096 || (paneId !== undefined && (typeof paneId !== "string" || paneId.length > 128))) {
158
177
  reply({ error: "invalid", message: "The note must be text of at most 1024 characters." }, true);
159
178
  return;
160
179
  }
180
+ // The connector validates the name; this only bounds what is forwarded.
181
+ if (channel !== undefined && (typeof channel !== "string" || channel.length > 64)) {
182
+ reply({ error: "invalid", message: "Invalid channel name." }, true);
183
+ return;
184
+ }
161
185
  const current = child;
162
186
  if (!current || stopping || finalStop || !current.connected) {
163
187
  reply({ error: "not-running", message: "The relay is turned off." }, true);
@@ -170,7 +194,7 @@ async function supervise() {
170
194
  }, 5000);
171
195
  timer.unref();
172
196
  pendingNotes.set(id, { reply, timer });
173
- current.send({ type: "peerband:notify", id, text, ...(paneId ? { paneId } : {}) }, (error) => {
197
+ current.send({ type: "peerband:notify", id, text, ...(paneId ? { paneId } : {}), ...(channel ? { channel } : {}) }, (error) => {
174
198
  if (!error || !pendingNotes.delete(id)) return;
175
199
  clearTimeout(timer);
176
200
  reply({ error: "not-running", message: "The connector is not reachable." }, true);
@@ -183,7 +207,7 @@ async function supervise() {
183
207
  clearTimeout(pending.timer);
184
208
  const text = (value, max) => (typeof value === "string" ? value.slice(0, max) : undefined);
185
209
  pending.reply(message.ok === true
186
- ? { ok: true, sent: message.sent === true, agentId: text(message.agentId, 256) ?? null, ...(text(message.eventId, 64) ? { eventId: text(message.eventId, 64) } : {}) }
210
+ ? { ok: true, sent: message.sent === true, agentId: text(message.agentId, 256) ?? null, ...(text(message.eventId, 64) ? { eventId: text(message.eventId, 64) } : {}), ...(text(message.channel, 64) ? { channel: text(message.channel, 64) } : {}) }
187
211
  : { error: text(message.code, 64) ?? "error", message: text(message.message, 512) ?? "The note could not be sent.", ...(text(message.nextStep, 512) ? { nextStep: text(message.nextStep, 512) } : {}) }, true);
188
212
  }
189
213
  const failNotes = () => {
@@ -274,7 +298,7 @@ async function supervise() {
274
298
  });
275
299
  if (process.argv[3] !== "--await-ui") startChild();
276
300
  else if (!owner) {
277
- const idleTimer = setTimeout(() => { if (!owner) stopSupervisor(); }, 15_000);
301
+ const idleTimer = setTimeout(() => { if (!owner) stopSupervisor(); }, AWAIT_UI_MS);
278
302
  idleTimer.unref();
279
303
  }
280
304
  }
@@ -361,11 +385,8 @@ async function main() {
361
385
  cwd: config, detached: true, stdio: "ignore", windowsHide: true, shell: false,
362
386
  });
363
387
  supervisor.unref();
364
- for (let attempt = 0; attempt < 30; attempt++) {
365
- try { console.log(JSON.stringify(await request("status"))); return; }
366
- catch { await new Promise((resolve) => setTimeout(resolve, 100)); }
367
- }
368
- throw new Error("The PeerBand helper did not start. Run `peerband status`, then `peerband login` if you are not logged in.");
388
+ try { console.log(JSON.stringify(await waitForHelper())); return; }
389
+ catch { throw new Error("The PeerBand helper did not start. Run `peerband status`, then `peerband login` if you are not logged in."); }
369
390
  }
370
391
  if (command === "start" || command === "enable") {
371
392
  await assertConnectorEntry();
@@ -379,17 +400,14 @@ async function main() {
379
400
  shell: false,
380
401
  });
381
402
  supervisor.unref();
382
- for (let attempt = 0; attempt < 30; attempt++) {
383
- try {
384
- console.log(JSON.stringify(await request("status")));
385
- return;
386
- } catch {
387
- await new Promise((resolve) => setTimeout(resolve, 100));
388
- }
403
+ try {
404
+ console.log(JSON.stringify(await waitForHelper()));
405
+ return;
406
+ } catch {
407
+ throw new Error(
408
+ "The PeerBand helper did not start. Run `peerband status`, then `peerband login` if you are not logged in.",
409
+ );
389
410
  }
390
- throw new Error(
391
- "The PeerBand helper did not start. Run `peerband status`, then `peerband login` if you are not logged in.",
392
- );
393
411
  }
394
412
  if (command === "status" || command === "stop" || command === "disable") {
395
413
  try {
package/herdr/pane.mjs CHANGED
@@ -50,14 +50,25 @@ function draw() {
50
50
  stdout.write("\x1b[2J\x1b[H" + renderPane({ snapshot, identity, email, messages, error: errorText, columns: stdout.columns, rows: stdout.rows }));
51
51
  }
52
52
  async function runLifecycle(command) {
53
- const { stdout: result } = await exec(process.execPath, [lifecycle, command], { timeout: 5000, windowsHide: true, maxBuffer: 65_536 });
53
+ // start-ui starts Node twice (lifecycle, then the helper); on a loaded machine that alone can take 10+ seconds.
54
+ const { stdout: result } = await exec(process.execPath, [lifecycle, command], { timeout: 45_000, windowsHide: true, maxBuffer: 65_536 });
54
55
  return JSON.parse(result.trim());
55
56
  }
56
57
  const controlAlive = () => Boolean(control && !control.destroyed);
58
+ // Renaming the tab runs the herdr CLI (several processes). Do it when the On/Off state changes, not on every refresh.
59
+ let tabState;
60
+ function syncTab(enabled) {
61
+ if (tabState === enabled) return;
62
+ tabState = enabled;
63
+ // Retry on the next refresh when the rename did not happen (it returns false without running herdr when this pane
64
+ // is not the recorded Relay tab).
65
+ const retry = () => { if (tabState === enabled) tabState = undefined; };
66
+ void syncRelayTab(enabled).then((renamed) => { if (!renamed) retry(); }, retry);
67
+ }
57
68
  function showUnavailable(message = UNAVAILABLE) {
58
69
  snapshot = { state: "stopping", connectionState: "helper-unavailable", activity: snapshot?.activity ?? [] };
59
70
  errorText = message;
60
- void syncRelayTab(false).catch(() => {});
71
+ syncTab(false);
61
72
  }
62
73
  async function refresh() {
63
74
  if (closing || pending || refreshInFlight) return;
@@ -66,7 +77,7 @@ async function refresh() {
66
77
  const generation = refreshGeneration;
67
78
  try {
68
79
  const next = await sendUi("ui-status");
69
- if (generation === refreshGeneration) { snapshot = next; if (!busyError) errorText = ""; void syncRelayTab(next.state === "running").catch(() => {}); }
80
+ if (generation === refreshGeneration) { snapshot = next; if (!busyError) errorText = ""; syncTab(next.state === "running"); }
70
81
  } catch {
71
82
  if (generation !== refreshGeneration) return;
72
83
  showUnavailable();
@@ -83,14 +94,16 @@ async function toggle() {
83
94
  draw();
84
95
  try {
85
96
  if (!controlAlive()) {
86
- // No helper: Space starts one, like opening the tab does.
97
+ // No helper: Space starts one, like opening the tab does. That can take a while on a busy machine.
98
+ errorText = "Starting the PeerBand relay…";
99
+ draw();
87
100
  await attach({ start: true });
88
101
  return;
89
102
  }
90
103
  const next = await sendUi(snapshot?.state === "running" ? "ui-disable" : "ui-enable");
91
104
  if (next.error === "busy") throw new Error("The relay is still stopping. Try On again in a moment.");
92
105
  snapshot = next;
93
- void syncRelayTab(next.state === "running").catch(() => {});
106
+ syncTab(next.state === "running");
94
107
  } catch (error) {
95
108
  errorText = error.message || "Could not change the connection. Check enrollment and the helper owner.";
96
109
  busyError = error.message === "The relay is still stopping. Try On again in a moment.";
@@ -184,7 +197,7 @@ async function attach({ start }) {
184
197
  ownsUi = true;
185
198
  snapshot = start ? await sendUi("ui-enable") : attached;
186
199
  errorText = "";
187
- void syncRelayTab(snapshot.state === "running").catch(() => {});
200
+ syncTab(snapshot.state === "running");
188
201
  draw();
189
202
  if (!timer) {
190
203
  timer = setInterval(refresh, 1000);
@@ -219,6 +232,8 @@ if (!stdinIsInteractive()) {
219
232
  console.log(renderPane({ snapshot, identity, email, messages, error: "Interactive terminal controls are required in this pane." }));
220
233
  } else {
221
234
  try {
235
+ errorText = "Starting the PeerBand relay…";
236
+ draw();
222
237
  await attach({ start: true });
223
238
  await refresh();
224
239
  } catch (error) {
@@ -236,7 +251,7 @@ function sendUi(command) {
236
251
  return new Promise((resolve, reject) => {
237
252
  if (!control || control.destroyed) { reject(new Error("Relay owner channel is closed")); return; }
238
253
  const request = { resolve, reject, timer: undefined };
239
- request.timer = setTimeout(() => failControl(new Error("Relay owner request timed out")), 3000);
254
+ request.timer = setTimeout(() => failControl(new Error("Relay owner request timed out")), 10_000);
240
255
  replies.push(request);
241
256
  control.write(JSON.stringify({ command }) + "\n");
242
257
  });
package/herdr-plugin.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  id = "peerband"
2
2
  name = "PeerBand"
3
- version = "0.1.5"
3
+ version = "0.2.0"
4
4
  min_herdr_version = "0.9.3"
5
5
  description = "Reach your Herdr agents from any MCP client through your PeerBand account"
6
6
  platforms = ["linux", "macos", "windows"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peerband",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "PeerBand CLI and Herdr plugin: reach your local coding agents from any MCP client through your PeerBand account",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,7 +29,7 @@ The grant flow (`enrollment-redeem.schema.json`) remains available for headless
29
29
  6. Agent events: the client sends `x-peerband-features: events` on the upgrade and then pushes `event` frames (`eventId`, `name`, `timestamp`, `data`) without being asked:
30
30
  - `agent.status_changed` `{agentId, status, previousStatus, label, workspace, revision}` when an agent's status changes (at most one per agent per 250 ms, latest wins, with an overall rate cap);
31
31
  - `agents.changed` `{}` when agents appear, exit or change occupant, and once after every (re)connect, so consumers re-list;
32
- - `agent.notified` `{agentId, text, audience: "owner"}` for a note sent with `peerband notify` (1 to 1024 characters, sanitized and redacted like agent output).
32
+ - `agent.notified` `{agentId, text, audience: "owner", channel?}` for a note sent with `peerband notify` (1 to 1024 characters, sanitized and redacted like agent output). `channel` is set by `peerband notify --channel NAME`: the name (`^[a-z0-9][a-z0-9-]{0,31}$`) of one of the owner's webhook endpoints. The note is still published on the machine's event stream (so it shows in the dashboard); only webhook delivery changes: that one endpoint receives it instead of every endpoint that takes notes. The CLI checks the channel with `GET /api/installation/channels` (installation credential; returns `{channels: [{name, format, state, events}]}`, never URLs or secrets) before sending.
33
33
  Events are metadata only and never carry terminal output. They are sent only while the socket is open; nothing is queued while disconnected.
34
34
 
35
35
  The client only reports metadata (tool, target id, outcome, latency) to its local activity log; message bodies and agent output are never logged.
@@ -54,13 +54,14 @@
54
54
  },
55
55
  "agentNotified": {
56
56
  "title": "data of agent.notified",
57
- "description": "A note sent with `peerband notify` from inside an agent's pane. `agentId` is that agent, or null when it could not be identified. The text is stripped of control characters and passed through the client's secret redaction. It is meant for the machine owner only (`audience`).",
57
+ "description": "A note sent with `peerband notify` from inside an agent's pane. `agentId` is that agent, or null when it could not be identified. The text is stripped of control characters and passed through the client's secret redaction. It is meant for the machine owner only (`audience`), optionally addressed to one of their channels (`channel`).",
58
58
  "type": "object",
59
59
  "required": ["agentId", "text", "audience"],
60
60
  "properties": {
61
61
  "agentId": { "type": ["string", "null"], "minLength": 1, "maxLength": 256 },
62
62
  "text": { "type": "string", "minLength": 1, "maxLength": 1024 },
63
- "audience": { "const": "owner" }
63
+ "audience": { "const": "owner" },
64
+ "channel": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{0,31}$", "description": "Optional (`peerband notify --channel`): the name of one of the owner's webhook endpoints. The note always appears on the machine's event stream (and so in the dashboard). Of the owner's webhook endpoints, only the named one receives it when `channel` is present; when absent, every endpoint that takes notes does. Servers that do not know the field may ignore it." }
64
65
  },
65
66
  "additionalProperties": false
66
67
  },
@@ -41,7 +41,7 @@ If your user (the owner, at the keyboard or in an owner-labelled relay message)
41
41
 
42
42
  To update later: `peerband update` (updates the CLI from npm, then the Herdr plugin, and restarts the relay; `--check` only reports). If `peerband status` says the plugin version does not match the CLI, run `peerband update`.
43
43
 
44
- Other commands: `peerband login` (log in again), `peerband relay` (open the Relay tab), `peerband skill` (install or update this skill for local agents), `peerband status` (login, relay, plugin health, installation ID), `peerband connect` (run the connector in the foreground; `--read-only` blocks messages), `peerband update` (update the CLI and the plugin), `peerband herdr install` (install or repair the plugin), `peerband share` (invite another PeerBand user to this machine; `share list`, `share revoke ID`), `peerband logout`.
44
+ Other commands: `peerband channels` (the channels `peerband notify --channel` can send to), `peerband login` (log in again), `peerband relay` (open the Relay tab), `peerband skill` (install or update this skill for local agents), `peerband status` (login, relay, plugin health, installation ID), `peerband connect` (run the connector in the foreground; `--read-only` blocks messages), `peerband update` (update the CLI and the plugin), `peerband herdr install` (install or repair the plugin), `peerband share` (invite another PeerBand user to this machine; `share list`, `share revoke ID`), `peerband logout`.
45
45
 
46
46
  ## MCP tools
47
47
 
@@ -92,3 +92,4 @@ peerband notify "Migration finished, 3 tests failing"
92
92
  - Never include secrets, credentials, tokens or personal data. Redaction is best effort, not a guarantee.
93
93
  - Notes go to the machine owner only, never to people the machine is shared with.
94
94
  - The note names your agent automatically (from the pane). It needs the relay to be running and connected; if the command fails ("No PeerBand relay is running", "not connected"), carry on and report the result in your normal output instead of retrying in a loop.
95
+ - **Channels.** The owner can set up channels (their webhooks, such as a Slack channel, each with a name). Every note shows in the owner's dashboard. Without `--channel` it also goes to every webhook that takes notes; that is the right default. With `--channel NAME` it goes to that one webhook instead of all of them. Use `peerband notify --channel NAME "<text>"` only when the owner asked for a specific channel, or a project's instructions name one. Run `peerband channels` to see the names and which are active. If the channel is unknown, inactive, or the server or relay does not support channels, the command fails and says why: don't guess other names; send the note without `--channel` or tell the user.