peerband 0.1.0 → 0.1.2
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/README.md +35 -23
- package/SECURITY.md +3 -2
- package/dist/peerband.mjs +367 -163
- package/herdr/lifecycle.mjs +1 -1
- package/herdr/pane-ui.mjs +17 -6
- package/herdr/pane.mjs +10 -6
- package/herdr/paths.mjs +3 -1
- package/herdr-plugin.toml +1 -1
- package/install/install.ps1 +3 -9
- package/install/install.sh +6 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ MCP client --> PeerBand relay <== outbound WebSocket == peerband connector --> H
|
|
|
7
7
|
(Claude, ...) (peerband.com) (on your machine) (your agents)
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
Your MCP client can list agents, read their status and bounded recent output, and (
|
|
10
|
+
Your MCP client can list agents, read their status and bounded recent output, and send them a message (sending needs your approval of the `agents:message` permission when you connect the client, and a machine can opt out; see [Security model](#security-model)). This project is unofficial and is not affiliated with Herdr or Amazon.
|
|
11
11
|
|
|
12
12
|
## Requirements
|
|
13
13
|
|
|
@@ -17,6 +17,18 @@ Your MCP client can list agents, read their status and bounded recent output, an
|
|
|
17
17
|
|
|
18
18
|
## Install
|
|
19
19
|
|
|
20
|
+
Recommended (Node.js 22.13+, Herdr 0.9.3+):
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install -g peerband && peerband login
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`peerband login` opens your browser so you can approve this machine, then checks for Herdr and offers to add the PeerBand plugin to it (`Add the PeerBand plugin to Herdr now? [Y/n]`). After that, `peerband relay` opens the PeerBand Relay tab. If Herdr is not installed yet, login tells you how to finish later (install Herdr from https://herdr.dev, then `peerband herdr install` and `peerband relay`). Use `peerband login --herdr-plugin install` to add the plugin without being asked, or `--herdr-plugin skip` to leave Herdr alone.
|
|
27
|
+
|
|
28
|
+
### One-step install script (alternative)
|
|
29
|
+
|
|
30
|
+
The script checks Node, runs `npm install -g peerband`, then runs `peerband login --herdr-plugin install`.
|
|
31
|
+
|
|
20
32
|
macOS and Linux:
|
|
21
33
|
|
|
22
34
|
```sh
|
|
@@ -29,25 +41,15 @@ Windows PowerShell:
|
|
|
29
41
|
irm https://peerband.com/install.ps1 | iex
|
|
30
42
|
```
|
|
31
43
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
npm install -g peerband
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
The installers check Node, install the CLI, run `peerband login` (which opens your browser), and set up the Herdr plugin when Herdr is present.
|
|
39
|
-
|
|
40
|
-
Headless machine or CI with no browser? Pass a one-time grant from the PeerBand dashboard instead: `curl -fsSL https://peerband.com/install.sh | sh -s -- --grant GRANT --name "my-server"`, or on Windows `$env:PEERBAND_GRANT = 'GRANT'; irm https://peerband.com/install.ps1 | iex`.
|
|
44
|
+
### Headless machines and CI
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
No browser available? Pass a one-time grant from the PeerBand dashboard instead: `peerband login --grant GRANT` (or set `PEERBAND_GRANT`). With the scripts: `curl -fsSL https://peerband.com/install.sh | sh -s -- --grant GRANT --name "my-server"`, or on Windows `$env:PEERBAND_GRANT = 'GRANT'; irm https://peerband.com/install.ps1 | iex`.
|
|
43
47
|
|
|
44
48
|
## Quickstart
|
|
45
49
|
|
|
46
|
-
1.
|
|
47
|
-
2. `peerband
|
|
48
|
-
3. `peerband
|
|
49
|
-
4. `peerband relay` to open the PeerBand Relay tab, then press Space to connect.
|
|
50
|
-
5. Add the MCP server URL that `peerband relay` and `peerband status` print (`https://mcp.peerband.com/mcp`) to your MCP client: a custom connector in ChatGPT or Claude, or `claude mcp add --transport http peerband https://mcp.peerband.com/mcp` in Claude Code. Sign in and approve access when the client asks.
|
|
50
|
+
1. `npm install -g peerband && peerband login`. Confirm the code shown in your terminal when your browser opens, and answer Y to adding the Herdr plugin.
|
|
51
|
+
2. `peerband relay` to open the PeerBand Relay tab, then press Space to connect. (If you skipped the plugin: `peerband herdr install` first.)
|
|
52
|
+
3. Add the MCP server URL that `peerband relay` and `peerband status` print (`https://mcp.peerband.com/mcp`) to your MCP client: a custom connector in ChatGPT or Claude, or `claude mcp add --transport http peerband https://mcp.peerband.com/mcp` in Claude Code. Sign in and approve access when the client asks.
|
|
51
53
|
|
|
52
54
|
## Logging in
|
|
53
55
|
|
|
@@ -72,7 +74,7 @@ Opened your browser.
|
|
|
72
74
|
|
|
73
75
|
## The Relay tab
|
|
74
76
|
|
|
75
|
-
The plugin adds a persistent tab titled `PeerBand Relay [On]` or `[Off]` that shows your account, connection state and a metadata-only activity log.
|
|
77
|
+
The plugin adds a persistent tab titled `PeerBand Relay [On]` or `[Off]` that shows your machine, account (when the server returned an email), whether messages are allowed, the connection state and a metadata-only activity log.
|
|
76
78
|
|
|
77
79
|
- **Space** or **Enter** (or a click on the control box) toggles the connection.
|
|
78
80
|
- **Q**, **Esc** or **Ctrl+C** asks to close the tab; press it again to confirm. Closing it disconnects the relay.
|
|
@@ -82,11 +84,11 @@ The plugin adds a persistent tab titled `PeerBand Relay [On]` or `[Off]` that sh
|
|
|
82
84
|
|
|
83
85
|
| Command | What it does |
|
|
84
86
|
| --- | --- |
|
|
85
|
-
| `peerband login` | Sign in through your browser. Flags: `--no-browser`, `--name NAME`, `--server URL`; headless/CI: `--grant GRANT` |
|
|
87
|
+
| `peerband login` | Sign in through your browser, then offer to add the Herdr plugin. Flags: `--no-browser`, `--name NAME`, `--server URL`, `--herdr-plugin ask\|install\|skip`; headless/CI: `--grant GRANT` |
|
|
86
88
|
| `peerband logout` | Stop a running relay and delete the local credential. Does not revoke it on the server |
|
|
87
|
-
| `peerband status` | Show login, relay and Herdr state. `--json` for machine-readable output |
|
|
88
|
-
| `peerband connect` | Run the connector in the foreground. Flags: `--runtime herdr\|mock`, `--
|
|
89
|
-
| `peerband relay` | Open or focus the Relay tab in Herdr |
|
|
89
|
+
| `peerband status` | Show login, relay, messaging and Herdr state, including whether the Herdr plugin is the right one. `--json` for machine-readable output |
|
|
90
|
+
| `peerband connect` | Run the connector in the foreground. Flags: `--runtime herdr\|mock`, `--read-only`, `--config PATH`, `--server URL` (`--enable-writes` is still accepted but redundant) |
|
|
91
|
+
| `peerband relay` | Open or focus the Relay tab in Herdr. If the plugin is missing the wrong version, a local checkout, or points at another config directory, it offers to repair it first |
|
|
90
92
|
| `peerband herdr install` | Install (or update) the Herdr plugin |
|
|
91
93
|
| `peerband herdr uninstall` | Stop the relay, remove the plugin and its `settings.json` |
|
|
92
94
|
| `peerband --version`, `help [command]` | Version and help |
|
|
@@ -117,13 +119,23 @@ Optional `connector.json`:
|
|
|
117
119
|
}
|
|
118
120
|
```
|
|
119
121
|
|
|
120
|
-
All fields are optional. `allowedAgents` and `allowedWorkspaces` restrict what MCP clients can see; `stateDirectory` moves the receipt store (default `state/` in the config home). The `herdr` block is only needed when Herdr is not on `PATH` or you target a specific session.
|
|
122
|
+
All fields are optional. `enableWrites` defaults to `true`; set it to `false` to make this machine read-only (the same as `peerband connect --read-only`; it also applies to the Relay tab). `allowedAgents` and `allowedWorkspaces` restrict what MCP clients can see; `stateDirectory` moves the receipt store (default `state/` in the config home). The `herdr` block is only needed when Herdr is not on `PATH` or you target a specific session.
|
|
123
|
+
|
|
124
|
+
## Agent skill
|
|
125
|
+
|
|
126
|
+
Give your coding agents (Claude Code, Codex, Cursor, ...) a skill that explains the PeerBand MCP tools and how to use them safely:
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
npx skills add kshvidler/peerband-cli
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
It installs `skills/peerband/SKILL.md` from this repository with the [`skills`](https://github.com/vercel-labs/skills) tool. `peerband login` and `peerband relay` print this command after a successful setup. The skill is not part of the npm package.
|
|
121
133
|
|
|
122
134
|
## Security model
|
|
123
135
|
|
|
124
136
|
- **Outbound only.** The connector dials the relay over a WebSocket; it opens no listening port.
|
|
125
137
|
- **Credential on disk** is stored in `credentials.json`, readable only by your user (mode 0600 inside a 0700 directory).
|
|
126
|
-
- **
|
|
138
|
+
- **Messaging is on by default, gated by consent.** An MCP client can call `send_agent_message` only if you approved the `agents:message` scope when you connected it (reading needs only the read scope). Each send needs an idempotency key. A machine can opt out entirely with `peerband connect --read-only` or `"enableWrites": false` in `connector.json`; `peerband status` and the Relay tab show which mode it is in.
|
|
127
139
|
- **Metadata-only activity.** The Relay tab and receipts record what happened (tool, target, outcome), not prompts or output.
|
|
128
140
|
- **Logout does not revoke.** `peerband logout` only deletes the local file. To revoke a machine, remove it in the PeerBand dashboard.
|
|
129
141
|
|
package/SECURITY.md
CHANGED
|
@@ -12,7 +12,7 @@ This repository is the PeerBand client: the `peerband` CLI, the connector that d
|
|
|
12
12
|
|
|
13
13
|
- credential storage and handling (`credentials.json`, enrollment grants)
|
|
14
14
|
- the outbound relay connection and request handling
|
|
15
|
-
- the
|
|
15
|
+
- the write path (`send_agent_message`) and its authorization checks
|
|
16
16
|
- the installers (`install/install.sh`, `install/install.ps1`)
|
|
17
17
|
- the Herdr plugin launcher and process ownership
|
|
18
18
|
|
|
@@ -20,7 +20,8 @@ This repository is the PeerBand client: the `peerband` CLI, the connector that d
|
|
|
20
20
|
|
|
21
21
|
- The connector only makes outbound connections. It never listens for inbound ones.
|
|
22
22
|
- The credential file is created user-only (mode 0600 in a 0700 directory).
|
|
23
|
-
-
|
|
23
|
+
- Sending messages to agents (`send_agent_message`) is allowed by default, but a request is only honoured if the MCP client holds the `agents:message` OAuth scope that the user approved at consent. Machines can opt out with `peerband connect --read-only` or `"enableWrites": false` in `connector.json`; the connector then rejects every send. `peerband status` and the Relay tab show which mode applies.
|
|
24
|
+
- `peerband relay` and `peerband status` check that the installed Herdr plugin is the release matching the CLI and uses the same config directory, and offer a repair when it does not.
|
|
24
25
|
- The activity log is metadata only; prompts and agent output are not persisted.
|
|
25
26
|
- `peerband logout` deletes the local credential but does not revoke it. Revoke machines from your PeerBand dashboard.
|
|
26
27
|
|
package/dist/peerband.mjs
CHANGED
|
@@ -6873,7 +6873,7 @@ var require_compile = __commonJS({
|
|
|
6873
6873
|
const schOrFunc = root.refs[ref];
|
|
6874
6874
|
if (schOrFunc)
|
|
6875
6875
|
return schOrFunc;
|
|
6876
|
-
let _sch =
|
|
6876
|
+
let _sch = resolve5.call(this, root, ref);
|
|
6877
6877
|
if (_sch === void 0) {
|
|
6878
6878
|
const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
|
|
6879
6879
|
const { schemaId } = this.opts;
|
|
@@ -6900,7 +6900,7 @@ var require_compile = __commonJS({
|
|
|
6900
6900
|
function sameSchemaEnv(s1, s2) {
|
|
6901
6901
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
6902
6902
|
}
|
|
6903
|
-
function
|
|
6903
|
+
function resolve5(root, ref) {
|
|
6904
6904
|
let sch;
|
|
6905
6905
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
6906
6906
|
ref = sch;
|
|
@@ -7730,7 +7730,7 @@ var require_fast_uri = __commonJS({
|
|
|
7730
7730
|
}
|
|
7731
7731
|
return uri;
|
|
7732
7732
|
}
|
|
7733
|
-
function
|
|
7733
|
+
function resolve5(baseURI, relativeURI, options) {
|
|
7734
7734
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
7735
7735
|
const {
|
|
7736
7736
|
parsed: baseParsed,
|
|
@@ -8099,7 +8099,7 @@ var require_fast_uri = __commonJS({
|
|
|
8099
8099
|
var fastUri = {
|
|
8100
8100
|
SCHEMES,
|
|
8101
8101
|
normalize,
|
|
8102
|
-
resolve:
|
|
8102
|
+
resolve: resolve5,
|
|
8103
8103
|
resolveComponent,
|
|
8104
8104
|
equal,
|
|
8105
8105
|
serialize,
|
|
@@ -11867,8 +11867,8 @@ var ConnectorCore = class {
|
|
|
11867
11867
|
async execute(tool, args, principal = DEFAULT_PRINCIPAL) {
|
|
11868
11868
|
if (this.closed) throw new ConnectError("connector_closed", "The connector is shutting down.", "Restart the connector to make further requests.");
|
|
11869
11869
|
let finishOperation;
|
|
11870
|
-
const operation = new Promise((
|
|
11871
|
-
finishOperation =
|
|
11870
|
+
const operation = new Promise((resolve5) => {
|
|
11871
|
+
finishOperation = resolve5;
|
|
11872
11872
|
});
|
|
11873
11873
|
this.activeOperations.add(operation);
|
|
11874
11874
|
try {
|
|
@@ -11975,7 +11975,7 @@ var ConnectorCore = class {
|
|
|
11975
11975
|
}
|
|
11976
11976
|
async sendMessage(args, principal) {
|
|
11977
11977
|
assertKeys(args, ["agentId", "message", "idempotencyKey"]);
|
|
11978
|
-
if (!this.writesEnabled) throw new ConnectError("write_disabled", "Message sending is disabled.", "
|
|
11978
|
+
if (!this.writesEnabled) throw new ConnectError("write_disabled", "Message sending is disabled.", 'This machine is read-only. To allow messages, remove --read-only or set "enableWrites": true in connector.json on that machine.');
|
|
11979
11979
|
this.requireScope(principal, "agents:message");
|
|
11980
11980
|
const key = args.idempotencyKey;
|
|
11981
11981
|
const message = args.message;
|
|
@@ -12033,8 +12033,8 @@ var ConnectorCore = class {
|
|
|
12033
12033
|
async withSubmissionLock(key, action) {
|
|
12034
12034
|
const previous = this.submissionLocks.get(key) ?? Promise.resolve();
|
|
12035
12035
|
let release;
|
|
12036
|
-
const current = new Promise((
|
|
12037
|
-
release =
|
|
12036
|
+
const current = new Promise((resolve5) => {
|
|
12037
|
+
release = resolve5;
|
|
12038
12038
|
});
|
|
12039
12039
|
this.submissionLocks.set(key, current);
|
|
12040
12040
|
await previous;
|
|
@@ -12465,7 +12465,7 @@ async function runRemoteClient(core, credentials, options = {}) {
|
|
|
12465
12465
|
});
|
|
12466
12466
|
const reportActivity = options.onActivity ?? (() => {
|
|
12467
12467
|
});
|
|
12468
|
-
const sleep = options.sleep ?? ((ms) => new Promise((
|
|
12468
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve5) => setTimeout(resolve5, ms)));
|
|
12469
12469
|
const serverUrl = socketUrl(credentials.serverUrl);
|
|
12470
12470
|
const heartbeatTimeoutMs = options.heartbeatTimeoutMs ?? 75e3;
|
|
12471
12471
|
let stopped = false;
|
|
@@ -12485,7 +12485,7 @@ async function runRemoteClient(core, credentials, options = {}) {
|
|
|
12485
12485
|
while (!stopped) {
|
|
12486
12486
|
try {
|
|
12487
12487
|
setConnectionState("connecting");
|
|
12488
|
-
await new Promise((
|
|
12488
|
+
await new Promise((resolve5, reject) => {
|
|
12489
12489
|
const socket = new wrapper_default(serverUrl, {
|
|
12490
12490
|
headers: { Authorization: `Bearer ${credentials.credential}` },
|
|
12491
12491
|
maxPayload: MAX_FRAME,
|
|
@@ -12671,7 +12671,7 @@ async function runRemoteClient(core, credentials, options = {}) {
|
|
|
12671
12671
|
code === 1008 || code === 4001 ? `remote authentication or policy rejected the connection (${code})` : `remote connection closed (${code})${reason.length ? `: ${reason.toString()}` : ""}`
|
|
12672
12672
|
);
|
|
12673
12673
|
if (current === socket) current = void 0;
|
|
12674
|
-
|
|
12674
|
+
resolve5();
|
|
12675
12675
|
});
|
|
12676
12676
|
});
|
|
12677
12677
|
} catch (error) {
|
|
@@ -12711,12 +12711,12 @@ var DeviceLoginError = class extends Error {
|
|
|
12711
12711
|
var REQUEST_TIMEOUT_MS2 = 15e3;
|
|
12712
12712
|
var MAX_BACKOFF_MS = 3e4;
|
|
12713
12713
|
var SLOW_DOWN_STEP_S = 5;
|
|
12714
|
-
var defaultSleep = (ms, signal) => new Promise((
|
|
12715
|
-
if (signal?.aborted) return
|
|
12714
|
+
var defaultSleep = (ms, signal) => new Promise((resolve5) => {
|
|
12715
|
+
if (signal?.aborted) return resolve5();
|
|
12716
12716
|
const done = () => {
|
|
12717
12717
|
clearTimeout(timer);
|
|
12718
12718
|
signal?.removeEventListener("abort", done);
|
|
12719
|
-
|
|
12719
|
+
resolve5();
|
|
12720
12720
|
};
|
|
12721
12721
|
const timer = setTimeout(done, ms);
|
|
12722
12722
|
signal?.addEventListener("abort", done, { once: true });
|
|
@@ -12953,17 +12953,17 @@ function herdrBinary(env, platform = process.platform) {
|
|
|
12953
12953
|
return env.HERDR_BIN_PATH || (platform === "win32" ? "herdr.exe" : "herdr");
|
|
12954
12954
|
}
|
|
12955
12955
|
function createHerdrRunner(env) {
|
|
12956
|
-
return (args, options) => new Promise((
|
|
12956
|
+
return (args, options) => new Promise((resolve5) => {
|
|
12957
12957
|
execFile(
|
|
12958
12958
|
herdrBinary(env),
|
|
12959
12959
|
args,
|
|
12960
12960
|
{ env, timeout: options?.timeoutMs ?? 6e4, windowsHide: true, maxBuffer: 4 * 1024 * 1024, shell: false },
|
|
12961
12961
|
(error, stdout, stderr) => {
|
|
12962
|
-
if (!error) return
|
|
12962
|
+
if (!error) return resolve5({ code: 0, stdout, stderr });
|
|
12963
12963
|
const failure = error;
|
|
12964
|
-
if (failure.code === "ENOENT") return
|
|
12964
|
+
if (failure.code === "ENOENT") return resolve5({ code: 127, stdout: "", stderr: failure.message, notFound: true });
|
|
12965
12965
|
const code = typeof failure.code === "number" ? failure.code : 1;
|
|
12966
|
-
|
|
12966
|
+
resolve5({ code, stdout: stdout ?? "", stderr: stderr || (failure.killed ? "timed out" : failure.message) });
|
|
12967
12967
|
}
|
|
12968
12968
|
);
|
|
12969
12969
|
});
|
|
@@ -12982,7 +12982,7 @@ function failureDetail(result) {
|
|
|
12982
12982
|
}
|
|
12983
12983
|
|
|
12984
12984
|
// src/cli/commands/connect.ts
|
|
12985
|
-
import { resolve } from "node:path";
|
|
12985
|
+
import { resolve as resolve2 } from "node:path";
|
|
12986
12986
|
|
|
12987
12987
|
// src/runtime-herdr/adapter.ts
|
|
12988
12988
|
import { createHash as createHash2, randomUUID as randomUUID3 } from "node:crypto";
|
|
@@ -13038,7 +13038,7 @@ var HerdrSocketClient = class {
|
|
|
13038
13038
|
this.inflight -= 1;
|
|
13039
13039
|
throw error;
|
|
13040
13040
|
}
|
|
13041
|
-
return new Promise((
|
|
13041
|
+
return new Promise((resolve5, reject) => {
|
|
13042
13042
|
const timer = setTimeout(() => {
|
|
13043
13043
|
this.pending.delete(id);
|
|
13044
13044
|
this.inflight -= 1;
|
|
@@ -13046,7 +13046,7 @@ var HerdrSocketClient = class {
|
|
|
13046
13046
|
reject(method === "agent.prompt" ? new ConnectError("delivery_unknown", "Herdr did not acknowledge the prompt before the request timed out.", "Check the agent status before deciding whether to send the prompt again.") : new ConnectError("timeout", `Herdr ${method} request timed out`, "Check that Herdr is responsive and retry the read."));
|
|
13047
13047
|
}, this.timeoutMs);
|
|
13048
13048
|
timer.unref?.();
|
|
13049
|
-
this.pending.set(id, { resolve:
|
|
13049
|
+
this.pending.set(id, { resolve: resolve5, reject, timer, method, socket });
|
|
13050
13050
|
socket.write(line, (error) => {
|
|
13051
13051
|
if (!error) return;
|
|
13052
13052
|
const pending = this.pending.get(id);
|
|
@@ -13062,13 +13062,13 @@ var HerdrSocketClient = class {
|
|
|
13062
13062
|
async close() {
|
|
13063
13063
|
this.closed = true;
|
|
13064
13064
|
this.failAll(this.unavailable("Herdr socket client closed"));
|
|
13065
|
-
await Promise.all([...this.sockets].map((socket) => new Promise((
|
|
13066
|
-
if (socket.destroyed)
|
|
13067
|
-
else socket.end(
|
|
13065
|
+
await Promise.all([...this.sockets].map((socket) => new Promise((resolve5) => {
|
|
13066
|
+
if (socket.destroyed) resolve5();
|
|
13067
|
+
else socket.end(resolve5);
|
|
13068
13068
|
})));
|
|
13069
13069
|
}
|
|
13070
13070
|
connect() {
|
|
13071
|
-
return new Promise((
|
|
13071
|
+
return new Promise((resolve5, reject) => {
|
|
13072
13072
|
const socket = createConnection(this.socketPath);
|
|
13073
13073
|
const onError = () => {
|
|
13074
13074
|
socket.destroy();
|
|
@@ -13089,7 +13089,7 @@ var HerdrSocketClient = class {
|
|
|
13089
13089
|
this.buffers.delete(socket);
|
|
13090
13090
|
this.failSocket(socket, this.unavailable("Herdr closed the socket before replying"));
|
|
13091
13091
|
});
|
|
13092
|
-
|
|
13092
|
+
resolve5(socket);
|
|
13093
13093
|
});
|
|
13094
13094
|
});
|
|
13095
13095
|
}
|
|
@@ -13521,6 +13521,7 @@ var Output = class {
|
|
|
13521
13521
|
var symbols = { ok: "\u2713", dot: "\u25CF", ring: "\u25CB", warn: "!", fail: "\u2717" };
|
|
13522
13522
|
|
|
13523
13523
|
// src/cli/commands/shared.ts
|
|
13524
|
+
import { resolve } from "node:path";
|
|
13524
13525
|
var credentialsFile = (ctx) => credentialsPath({ env: ctx.env });
|
|
13525
13526
|
async function requireCredentials(ctx) {
|
|
13526
13527
|
try {
|
|
@@ -13532,6 +13533,19 @@ async function requireCredentials(ctx) {
|
|
|
13532
13533
|
throw error;
|
|
13533
13534
|
}
|
|
13534
13535
|
}
|
|
13536
|
+
async function loadMachineConnectorConfig(ctx, explicitPath) {
|
|
13537
|
+
const explicit = explicitPath ?? ctx.env.PEERBAND_CONNECTOR_CONFIG;
|
|
13538
|
+
return explicit ? loadConnectorConfig(resolve(explicit)) : loadConnectorConfig(connectorConfigPath({ env: ctx.env }), { optional: true });
|
|
13539
|
+
}
|
|
13540
|
+
function writesEnabled(config, flags = {}) {
|
|
13541
|
+
if (flags.readOnly) return false;
|
|
13542
|
+
if (flags.enableWrites) return true;
|
|
13543
|
+
return config.enableWrites !== false;
|
|
13544
|
+
}
|
|
13545
|
+
var SKILL_COMMAND = "npx skills add kshvidler/peerband-cli";
|
|
13546
|
+
function printSkillTip(ctx) {
|
|
13547
|
+
ctx.out.print(ctx.out.stdout.dim(`Give your coding agents the PeerBand skill: ${SKILL_COMMAND}`));
|
|
13548
|
+
}
|
|
13535
13549
|
var describeMachine = (credentials) => credentials.machineName ?? credentials.installationId;
|
|
13536
13550
|
function printMcpHint(ctx, serverUrl) {
|
|
13537
13551
|
const s = ctx.out.stdout;
|
|
@@ -13583,18 +13597,19 @@ function activityLine(s, activity, at = /* @__PURE__ */ new Date()) {
|
|
|
13583
13597
|
var spec = {
|
|
13584
13598
|
name: "connect",
|
|
13585
13599
|
summary: "Run the connector in the foreground",
|
|
13586
|
-
usage: "peerband connect [--runtime herdr|mock] [--
|
|
13587
|
-
description:
|
|
13600
|
+
usage: "peerband connect [--runtime herdr|mock] [--read-only] [--config PATH] [--server URL]",
|
|
13601
|
+
description: 'Connects this machine to PeerBand and serves agent requests from your MCP clients until you press Ctrl+C. MCP clients may send messages to agents by default, but only after you approve the agents:message consent when you connect them; pass --read-only (or set "enableWrites": false in connector.json) to make this machine read-only. Activity lines show metadata only (tool, target, outcome, latency), never message or output content. Most people use `peerband relay` instead, which runs the connector inside Herdr.',
|
|
13588
13602
|
options: [
|
|
13589
13603
|
{ name: "runtime", type: "string", valueName: "herdr|mock", description: 'Agent runtime. Default: $PEERBAND_RUNTIME or herdr. "mock" serves fake agents for testing.' },
|
|
13590
|
-
{ name: "
|
|
13604
|
+
{ name: "read-only", type: "boolean", description: 'Do not allow MCP clients to send messages to agents on this machine (also: "enableWrites": false in connector.json).' },
|
|
13605
|
+
{ name: "enable-writes", type: "boolean", description: "Redundant: sending messages is allowed by default. Kept so old scripts keep working." },
|
|
13591
13606
|
{ name: "config", type: "string", valueName: "PATH", description: "Connector config file. Default: $PEERBAND_CONNECTOR_CONFIG or connector.json in the config directory (optional)." },
|
|
13592
13607
|
{ name: "server", type: "string", valueName: "URL", description: "Override the server stored at login." },
|
|
13593
13608
|
{ name: "managed", type: "boolean", hidden: true, description: "Internal: run under the Herdr plugin supervisor over IPC." }
|
|
13594
13609
|
],
|
|
13595
13610
|
examples: [
|
|
13596
|
-
["peerband connect", "Serve
|
|
13597
|
-
["peerband connect --
|
|
13611
|
+
["peerband connect", "Serve until Ctrl+C; messages to agents are allowed (with OAuth consent)"],
|
|
13612
|
+
["peerband connect --read-only", "Never let MCP clients send messages to agents from this machine"],
|
|
13598
13613
|
["peerband connect --runtime mock", "Try the connection with fake agents"]
|
|
13599
13614
|
],
|
|
13600
13615
|
async run(parsed, ctx) {
|
|
@@ -13602,6 +13617,7 @@ var spec = {
|
|
|
13602
13617
|
{
|
|
13603
13618
|
runtime: str(parsed, "runtime"),
|
|
13604
13619
|
enableWrites: flag(parsed, "enable-writes"),
|
|
13620
|
+
readOnly: flag(parsed, "read-only"),
|
|
13605
13621
|
config: str(parsed, "config"),
|
|
13606
13622
|
server: str(parsed, "server"),
|
|
13607
13623
|
managed: flag(parsed, "managed")
|
|
@@ -13618,9 +13634,9 @@ async function connect(options, ctx) {
|
|
|
13618
13634
|
if (runtime !== "herdr" && runtime !== "mock") throw new UsageError(`Unknown runtime "${runtime}".`, "Use --runtime herdr or --runtime mock.");
|
|
13619
13635
|
const credentials = await requireCredentials(ctx);
|
|
13620
13636
|
if (options.server) credentials.serverUrl = validateServerUrl(options.server);
|
|
13621
|
-
|
|
13622
|
-
const config =
|
|
13623
|
-
const enableWrites =
|
|
13637
|
+
if (options.readOnly && options.enableWrites) throw new UsageError("--read-only and --enable-writes contradict each other.", "Use --read-only to turn messaging off; messaging is on by default.");
|
|
13638
|
+
const config = await loadMachineConnectorConfig(ctx, options.config);
|
|
13639
|
+
const enableWrites = writesEnabled(config, { readOnly: options.readOnly, enableWrites: options.enableWrites });
|
|
13624
13640
|
const managed = Boolean(options.managed);
|
|
13625
13641
|
const s = ctx.out.stderr;
|
|
13626
13642
|
const machine = describeMachine(credentials);
|
|
@@ -13629,7 +13645,7 @@ async function connect(options, ctx) {
|
|
|
13629
13645
|
writesEnabled: enableWrites,
|
|
13630
13646
|
allowedAgents: config.allowedAgents,
|
|
13631
13647
|
allowedWorkspaces: config.allowedWorkspaces,
|
|
13632
|
-
receiptPath: config.stateDirectory ?
|
|
13648
|
+
receiptPath: config.stateDirectory ? resolve2(config.stateDirectory, "receipts.json") : receiptsPath({ env: ctx.env })
|
|
13633
13649
|
});
|
|
13634
13650
|
const abort = new AbortController();
|
|
13635
13651
|
let signalled;
|
|
@@ -13664,7 +13680,7 @@ async function connect(options, ctx) {
|
|
|
13664
13680
|
await core.initialize();
|
|
13665
13681
|
if (!managed) {
|
|
13666
13682
|
ctx.out.warn(
|
|
13667
|
-
`${s.bold("peerband")} ${s.dim(`${runtime} runtime, ${enableWrites ? "
|
|
13683
|
+
`${s.bold("peerband")} ${s.dim(`${runtime} runtime, ${enableWrites ? "messages allowed" : "read-only"}. Press Ctrl+C to stop.`)}`
|
|
13668
13684
|
);
|
|
13669
13685
|
}
|
|
13670
13686
|
await runRemoteClient(core, credentials, {
|
|
@@ -13710,7 +13726,7 @@ async function connect(options, ctx) {
|
|
|
13710
13726
|
// src/cli/commands/herdr.ts
|
|
13711
13727
|
import { mkdir as mkdir4, rm as rm3, writeFile as writeFile4 } from "node:fs/promises";
|
|
13712
13728
|
import { statSync } from "node:fs";
|
|
13713
|
-
import { join as
|
|
13729
|
+
import { join as join5, resolve as resolve4 } from "node:path";
|
|
13714
13730
|
|
|
13715
13731
|
// src/cli/control.ts
|
|
13716
13732
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
@@ -13725,7 +13741,7 @@ import { dirname as dirname3 } from "node:path";
|
|
|
13725
13741
|
// herdr/paths.mjs
|
|
13726
13742
|
import { createHash as createHash3 } from "node:crypto";
|
|
13727
13743
|
import { homedir as homedir3, tmpdir } from "node:os";
|
|
13728
|
-
import { join as join3, posix, win32 } from "node:path";
|
|
13744
|
+
import { join as join3, posix, resolve as resolve3, win32 } from "node:path";
|
|
13729
13745
|
function configHome2(env = process.env, platform = process.platform, home = homedir3()) {
|
|
13730
13746
|
if (env.PEERBAND_CONFIG_HOME) return env.PEERBAND_CONFIG_HOME;
|
|
13731
13747
|
if (platform === "win32") return join3(env.APPDATA || join3(home, "AppData", "Roaming"), "peerband");
|
|
@@ -13850,7 +13866,7 @@ async function withLaunchLock(statePath, action) {
|
|
|
13850
13866
|
}
|
|
13851
13867
|
if (stale) continue;
|
|
13852
13868
|
if (Date.now() >= deadline) throw new Error("Another PeerBand Relay tab launch is already in progress");
|
|
13853
|
-
await new Promise((
|
|
13869
|
+
await new Promise((resolve5) => setTimeout(resolve5, 100));
|
|
13854
13870
|
}
|
|
13855
13871
|
}
|
|
13856
13872
|
try {
|
|
@@ -14011,6 +14027,7 @@ function paneLabel(snapshot) {
|
|
|
14011
14027
|
|
|
14012
14028
|
// src/cli/herdr-js.ts
|
|
14013
14029
|
var openRelayTab2 = openRelayTab;
|
|
14030
|
+
var canonicalConfig2 = canonicalConfig;
|
|
14014
14031
|
var controlChannel2 = controlChannel;
|
|
14015
14032
|
var ownerRecordPath2 = ownerRecordPath;
|
|
14016
14033
|
var fallbackPaneSnapshot2 = fallbackPaneSnapshot;
|
|
@@ -14023,7 +14040,7 @@ async function requestControl(command, env, timeoutMs = 3e3) {
|
|
|
14023
14040
|
const record = JSON.parse(await readFile7(ownerRecordPath2(config), "utf8"));
|
|
14024
14041
|
if (typeof record.token !== "string") throw new Error("Invalid helper record");
|
|
14025
14042
|
const socket = createConnection2(controlChannel2(config));
|
|
14026
|
-
return new Promise((
|
|
14043
|
+
return new Promise((resolve5, reject) => {
|
|
14027
14044
|
let text2 = "";
|
|
14028
14045
|
let settled = false;
|
|
14029
14046
|
const finish = (error, value) => {
|
|
@@ -14032,7 +14049,7 @@ async function requestControl(command, env, timeoutMs = 3e3) {
|
|
|
14032
14049
|
clearTimeout(timer);
|
|
14033
14050
|
socket.destroy();
|
|
14034
14051
|
if (error) reject(error);
|
|
14035
|
-
else
|
|
14052
|
+
else resolve5(value ?? {});
|
|
14036
14053
|
};
|
|
14037
14054
|
const timer = setTimeout(() => finish(new Error("Helper control timeout")), timeoutMs);
|
|
14038
14055
|
socket.once("error", (error) => finish(error));
|
|
@@ -14074,117 +14091,89 @@ async function stopRelay(env) {
|
|
|
14074
14091
|
}
|
|
14075
14092
|
}
|
|
14076
14093
|
|
|
14077
|
-
// src/cli/commands/
|
|
14094
|
+
// src/cli/commands/herdr-check.ts
|
|
14095
|
+
import { readFile as readFile8, stat as stat3 } from "node:fs/promises";
|
|
14096
|
+
import { join as join4 } from "node:path";
|
|
14097
|
+
var PLUGIN_ID = "peerband";
|
|
14098
|
+
var REPAIR_COMMAND = "peerband herdr install";
|
|
14078
14099
|
async function pluginInstalled(ctx) {
|
|
14079
14100
|
const result = await ctx.runHerdr(["plugin", "list"], { timeoutMs: 1e4 });
|
|
14080
|
-
if (result.notFound) return { found: false, installed: false };
|
|
14081
|
-
if (result.code !== 0) return { found: true, installed: false, detail: failureDetail(result) };
|
|
14082
|
-
|
|
14101
|
+
if (result.notFound) return { found: false, installed: false, source: null };
|
|
14102
|
+
if (result.code !== 0) return { found: true, installed: false, source: null, detail: failureDetail(result) };
|
|
14103
|
+
const line = /^\s*-\s+peerband\s.*$/m.exec(result.stdout)?.[0];
|
|
14104
|
+
if (line === void 0) return { found: true, installed: false, source: null };
|
|
14105
|
+
const source = /\[([^\]]*)\]\s*$/.exec(line)?.[1]?.trim() || null;
|
|
14106
|
+
return { found: true, installed: true, source };
|
|
14083
14107
|
}
|
|
14084
14108
|
function herdrVersion(output) {
|
|
14085
14109
|
return /\d+\.\d+\.\d+(?:[-+.\w]*)?/.exec(output)?.[0] ?? null;
|
|
14086
14110
|
}
|
|
14087
|
-
function
|
|
14111
|
+
async function readSettings(ctx) {
|
|
14112
|
+
const dir = await ctx.runHerdr(["plugin", "config-dir", PLUGIN_ID], { timeoutMs: 1e4 });
|
|
14113
|
+
const configDir = dir.code === 0 ? dir.stdout.trim() : "";
|
|
14114
|
+
if (!configDir) return null;
|
|
14088
14115
|
try {
|
|
14089
|
-
|
|
14116
|
+
const value = JSON.parse(await readFile8(join4(configDir, "settings.json"), "utf8"));
|
|
14117
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
14090
14118
|
} catch {
|
|
14091
14119
|
return null;
|
|
14092
14120
|
}
|
|
14093
14121
|
}
|
|
14094
|
-
async function
|
|
14095
|
-
let credentials;
|
|
14122
|
+
async function isFile(path) {
|
|
14096
14123
|
try {
|
|
14097
|
-
|
|
14124
|
+
return (await stat3(path)).isFile();
|
|
14098
14125
|
} catch {
|
|
14099
|
-
|
|
14126
|
+
return false;
|
|
14100
14127
|
}
|
|
14101
|
-
const snapshot = await relaySnapshot(ctx.env);
|
|
14102
|
-
const version = await ctx.runHerdr(["--version"], { timeoutMs: 1e4 });
|
|
14103
|
-
const plugin = version.notFound ? { found: false, installed: false } : await pluginInstalled(ctx);
|
|
14104
|
-
const herdrFound = !version.notFound;
|
|
14105
|
-
return {
|
|
14106
|
-
version: ctx.version,
|
|
14107
|
-
node: process.versions.node,
|
|
14108
|
-
configHome: configHome({ env: ctx.env }),
|
|
14109
|
-
loggedIn: Boolean(credentials),
|
|
14110
|
-
machine: credentials?.machineName ?? null,
|
|
14111
|
-
email: credentials?.accountEmail ?? null,
|
|
14112
|
-
server: credentials?.serverUrl ?? null,
|
|
14113
|
-
mcpUrl: credentials ? safeMcpUrl(credentials.serverUrl, ctx.env) : null,
|
|
14114
|
-
installationId: credentials?.installationId ?? null,
|
|
14115
|
-
enrolledAt: credentials?.enrolledAt ?? null,
|
|
14116
|
-
relay: {
|
|
14117
|
-
running: snapshot?.source === "control" && snapshot.state === "running",
|
|
14118
|
-
connection: snapshot?.connectionState ?? null,
|
|
14119
|
-
source: snapshot?.source ?? "none"
|
|
14120
|
-
},
|
|
14121
|
-
herdr: {
|
|
14122
|
-
found: herdrFound,
|
|
14123
|
-
version: herdrFound && version.code === 0 ? herdrVersion(`${version.stdout} ${version.stderr}`) : null,
|
|
14124
|
-
pluginInstalled: herdrFound ? plugin.installed : null
|
|
14125
|
-
}
|
|
14126
|
-
};
|
|
14127
14128
|
}
|
|
14128
|
-
function
|
|
14129
|
-
|
|
14130
|
-
|
|
14131
|
-
if (state === "connected") return s.green(`${symbols.dot} ${label}`);
|
|
14132
|
-
if (state === "connecting" || state === "reconnecting") return s.yellow(`${symbols.dot} ${label}`);
|
|
14133
|
-
if (state === "disabled") return s.dim(`${symbols.ring} ${label}`);
|
|
14134
|
-
return s.red(`${symbols.dot} ${label}`);
|
|
14129
|
+
function sourceRef(source) {
|
|
14130
|
+
const at = source.lastIndexOf("@");
|
|
14131
|
+
return at > 0 ? source.slice(at + 1) || null : null;
|
|
14135
14132
|
}
|
|
14136
|
-
function
|
|
14137
|
-
const
|
|
14138
|
-
|
|
14139
|
-
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
|
|
14143
|
-
|
|
14144
|
-
|
|
14145
|
-
|
|
14146
|
-
|
|
14147
|
-
|
|
14148
|
-
|
|
14149
|
-
|
|
14150
|
-
|
|
14151
|
-
|
|
14152
|
-
|
|
14153
|
-
|
|
14154
|
-
|
|
14155
|
-
|
|
14156
|
-
if (
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
|
|
14161
|
-
}
|
|
14162
|
-
|
|
14163
|
-
|
|
14164
|
-
|
|
14165
|
-
|
|
14133
|
+
async function checkHerdrPlugin(ctx) {
|
|
14134
|
+
const version = await ctx.runHerdr(["--version"], { timeoutMs: 1e4 });
|
|
14135
|
+
if (version.notFound) return { found: false, herdrVersion: null, installed: false, source: null, problems: [] };
|
|
14136
|
+
const herdrV = version.code === 0 ? herdrVersion(`${version.stdout} ${version.stderr}`) : null;
|
|
14137
|
+
const listed = await pluginInstalled(ctx);
|
|
14138
|
+
if (listed.detail) return { found: true, herdrVersion: herdrV, installed: false, source: null, detail: listed.detail, problems: [] };
|
|
14139
|
+
if (!listed.installed) {
|
|
14140
|
+
return { found: true, herdrVersion: herdrV, installed: false, source: null, problems: [{ code: "not-installed", message: "The PeerBand plugin is not installed in Herdr." }] };
|
|
14141
|
+
}
|
|
14142
|
+
const problems = [];
|
|
14143
|
+
const source = listed.source;
|
|
14144
|
+
const override = Boolean(ctx.env.PEERBAND_HERDR_SOURCE);
|
|
14145
|
+
if (source?.startsWith("local:")) {
|
|
14146
|
+
if (!override) problems.push({ code: "local-source", message: `The plugin is linked to a local checkout (${source.slice("local:".length)}), not the v${ctx.version} release.` });
|
|
14147
|
+
} else if (source !== null && !override) {
|
|
14148
|
+
const expected = ctx.env.PEERBAND_HERDR_REF || `v${ctx.version}`;
|
|
14149
|
+
const ref = sourceRef(source);
|
|
14150
|
+
if (ref !== expected) {
|
|
14151
|
+
problems.push({ code: "version-mismatch", message: `The plugin is ${ref ? `at ${ref}` : "not pinned to a version"}, but this CLI is ${expected}.` });
|
|
14152
|
+
}
|
|
14153
|
+
} else if (source !== null && ctx.env.PEERBAND_HERDR_REF) {
|
|
14154
|
+
const ref = sourceRef(source);
|
|
14155
|
+
if (ref !== ctx.env.PEERBAND_HERDR_REF) problems.push({ code: "version-mismatch", message: `The plugin is at ${ref ?? "no ref"}, but PEERBAND_HERDR_REF is ${ctx.env.PEERBAND_HERDR_REF}.` });
|
|
14156
|
+
}
|
|
14157
|
+
const settings = await readSettings(ctx);
|
|
14158
|
+
const current = configHome({ env: ctx.env });
|
|
14159
|
+
const fallback = configHome({ env: { ...ctx.env, PEERBAND_CONFIG_HOME: void 0 } });
|
|
14160
|
+
const recorded = settings && typeof settings.configHome === "string" && settings.configHome ? settings.configHome : fallback;
|
|
14161
|
+
if (settings && canonicalConfig2(recorded) !== canonicalConfig2(current)) {
|
|
14162
|
+
const shown = typeof settings.configHome === "string" && settings.configHome ? settings.configHome : `${fallback} (default)`;
|
|
14163
|
+
problems.push({ code: "config-home", message: `The plugin uses the config directory ${shown}, but this CLI uses ${current}.` });
|
|
14164
|
+
}
|
|
14165
|
+
const nodePath = settings?.nodePath;
|
|
14166
|
+
if (typeof nodePath !== "string" || !nodePath) {
|
|
14167
|
+
problems.push({ code: "node-path", message: "The plugin settings do not record a Node.js path." });
|
|
14168
|
+
} else if (!await isFile(nodePath)) {
|
|
14169
|
+
problems.push({ code: "node-path", message: `The Node.js recorded in the plugin settings no longer exists (${nodePath}).` });
|
|
14170
|
+
}
|
|
14171
|
+
return { found: true, herdrVersion: herdrV, installed: true, source, problems };
|
|
14166
14172
|
}
|
|
14167
|
-
var spec2 = {
|
|
14168
|
-
name: "status",
|
|
14169
|
-
summary: "Show login, relay and Herdr status",
|
|
14170
|
-
usage: "peerband status [--json]",
|
|
14171
|
-
description: "Shows whether this machine is logged in, whether the PeerBand Relay is running and connected, and whether Herdr and the PeerBand plugin are installed. Exits with code 3 when not logged in.",
|
|
14172
|
-
options: [{ name: "json", type: "boolean", description: "Print a stable machine-readable JSON object instead of text." }],
|
|
14173
|
-
examples: [
|
|
14174
|
-
["peerband status", "Human-readable summary"],
|
|
14175
|
-
["peerband status --json", "For scripts; check .loggedIn and .relay.connection"]
|
|
14176
|
-
],
|
|
14177
|
-
async run(parsed, ctx) {
|
|
14178
|
-
const report = await buildStatus(ctx);
|
|
14179
|
-
if (flag(parsed, "json")) ctx.out.print(JSON.stringify(report, null, 2));
|
|
14180
|
-
else renderHuman(report, ctx);
|
|
14181
|
-
return report.loggedIn ? 0 : EXIT_NOT_LOGGED_IN;
|
|
14182
|
-
}
|
|
14183
|
-
};
|
|
14184
14173
|
|
|
14185
14174
|
// src/cli/commands/herdr.ts
|
|
14186
14175
|
var DEFAULT_SOURCE = "kshvidler/peerband-cli";
|
|
14187
|
-
var
|
|
14176
|
+
var PLUGIN_ID2 = "peerband";
|
|
14188
14177
|
function isDirectory(path) {
|
|
14189
14178
|
try {
|
|
14190
14179
|
return statSync(path).isDirectory();
|
|
@@ -14202,9 +14191,9 @@ function must(result, what, hint) {
|
|
|
14202
14191
|
return result;
|
|
14203
14192
|
}
|
|
14204
14193
|
async function removePlugin(ctx) {
|
|
14205
|
-
const uninstall = await herdr(ctx, ["plugin", "uninstall",
|
|
14194
|
+
const uninstall = await herdr(ctx, ["plugin", "uninstall", PLUGIN_ID2]);
|
|
14206
14195
|
if (uninstall.code === 0) return { removed: true, detail: "" };
|
|
14207
|
-
const unlink3 = await herdr(ctx, ["plugin", "unlink",
|
|
14196
|
+
const unlink3 = await herdr(ctx, ["plugin", "unlink", PLUGIN_ID2]);
|
|
14208
14197
|
if (unlink3.code === 0) return { removed: true, detail: "" };
|
|
14209
14198
|
return { removed: false, detail: failureDetail(uninstall) };
|
|
14210
14199
|
}
|
|
@@ -14238,11 +14227,11 @@ var installSpec = {
|
|
|
14238
14227
|
if (before.detail) throw new CliError(`Herdr could not list plugins: ${before.detail}`, "Check that your Herdr is 0.9.3 or newer (`herdr --version`).");
|
|
14239
14228
|
if (before.installed) {
|
|
14240
14229
|
const removed = await removePlugin(ctx);
|
|
14241
|
-
if (!removed.removed) throw new CliError(`Could not replace the existing PeerBand plugin: ${removed.detail}`, `Run \`herdr plugin uninstall ${
|
|
14230
|
+
if (!removed.removed) throw new CliError(`Could not replace the existing PeerBand plugin: ${removed.detail}`, `Run \`herdr plugin uninstall ${PLUGIN_ID2}\` yourself, then retry.`);
|
|
14242
14231
|
ctx.out.print(s.dim(`Replacing the existing PeerBand plugin.`));
|
|
14243
14232
|
}
|
|
14244
14233
|
if (local) {
|
|
14245
|
-
const dir =
|
|
14234
|
+
const dir = resolve4(source);
|
|
14246
14235
|
must(await herdr(ctx, ["plugin", "link", dir]), "herdr plugin link", "Check that the directory is a peerband-cli checkout containing herdr-plugin.toml.");
|
|
14247
14236
|
ctx.out.print(`${s.green(symbols.ok)} Linked the PeerBand plugin from ${dir}`);
|
|
14248
14237
|
} else {
|
|
@@ -14253,11 +14242,11 @@ var installSpec = {
|
|
|
14253
14242
|
);
|
|
14254
14243
|
ctx.out.print(`${s.green(symbols.ok)} Installed the PeerBand plugin (${source} @ ${ref})`);
|
|
14255
14244
|
}
|
|
14256
|
-
const dirResult = must(await herdr(ctx, ["plugin", "config-dir",
|
|
14245
|
+
const dirResult = must(await herdr(ctx, ["plugin", "config-dir", PLUGIN_ID2]), "herdr plugin config-dir", "The plugin may not have registered; run `herdr plugin list`.");
|
|
14257
14246
|
const configDir = dirResult.stdout.trim();
|
|
14258
14247
|
if (!configDir) throw new CliError("Herdr did not report a plugin config directory.", "Run `herdr plugin config-dir peerband` to investigate.");
|
|
14259
14248
|
await mkdir4(configDir, { recursive: true });
|
|
14260
|
-
await writeFile4(
|
|
14249
|
+
await writeFile4(join5(configDir, "settings.json"), `${JSON.stringify(pluginSettings(ctx.env), null, 2)}
|
|
14261
14250
|
`, { mode: 384 });
|
|
14262
14251
|
ctx.out.print(`${s.green(symbols.ok)} Saved plugin settings ${s.dim(`(node ${process.execPath})`)}`);
|
|
14263
14252
|
const after = await pluginInstalled(ctx);
|
|
@@ -14283,11 +14272,11 @@ var uninstallSpec = {
|
|
|
14283
14272
|
return 0;
|
|
14284
14273
|
}
|
|
14285
14274
|
if (await stopRelay(ctx.env)) ctx.out.print(`${s.green(symbols.ok)} Stopped the running PeerBand Relay.`);
|
|
14286
|
-
const dirResult = await herdr(ctx, ["plugin", "config-dir",
|
|
14275
|
+
const dirResult = await herdr(ctx, ["plugin", "config-dir", PLUGIN_ID2]);
|
|
14287
14276
|
const configDir = dirResult.code === 0 ? dirResult.stdout.trim() : "";
|
|
14288
14277
|
const removed = await removePlugin(ctx);
|
|
14289
14278
|
if (!removed.removed) throw new CliError(`Could not remove the PeerBand plugin: ${removed.detail}`, "Run `herdr plugin list` to see its state.");
|
|
14290
|
-
if (configDir) await rm3(
|
|
14279
|
+
if (configDir) await rm3(join5(configDir, "settings.json"), { force: true }).catch(() => void 0);
|
|
14291
14280
|
ctx.out.print(`${s.green(symbols.ok)} Removed the PeerBand plugin from Herdr.`);
|
|
14292
14281
|
return 0;
|
|
14293
14282
|
}
|
|
@@ -14324,20 +14313,123 @@ function openerCommand(platform, url) {
|
|
|
14324
14313
|
}
|
|
14325
14314
|
function openBrowser(url, platform = process.platform) {
|
|
14326
14315
|
const { command, args } = openerCommand(platform, url);
|
|
14327
|
-
return new Promise((
|
|
14316
|
+
return new Promise((resolve5) => {
|
|
14328
14317
|
try {
|
|
14329
14318
|
const child = spawn(command, args, { detached: true, stdio: "ignore", windowsHide: true, shell: false });
|
|
14330
|
-
child.once("error", () =>
|
|
14319
|
+
child.once("error", () => resolve5(false));
|
|
14331
14320
|
child.once("spawn", () => {
|
|
14332
14321
|
child.unref();
|
|
14333
|
-
|
|
14322
|
+
resolve5(true);
|
|
14334
14323
|
});
|
|
14335
14324
|
} catch {
|
|
14336
|
-
|
|
14325
|
+
resolve5(false);
|
|
14337
14326
|
}
|
|
14338
14327
|
});
|
|
14339
14328
|
}
|
|
14340
14329
|
|
|
14330
|
+
// src/cli/prompt.ts
|
|
14331
|
+
var PromptAborted = class extends Error {
|
|
14332
|
+
constructor() {
|
|
14333
|
+
super("Prompt cancelled.");
|
|
14334
|
+
this.name = "PromptAborted";
|
|
14335
|
+
}
|
|
14336
|
+
};
|
|
14337
|
+
function askYesNo(stdin, stderr, prompt, defaultYes = true) {
|
|
14338
|
+
return new Promise((resolve5, reject) => {
|
|
14339
|
+
let value = "";
|
|
14340
|
+
const cleanup = () => {
|
|
14341
|
+
stdin.off("data", onData);
|
|
14342
|
+
stdin.pause();
|
|
14343
|
+
};
|
|
14344
|
+
const onData = (chunk) => {
|
|
14345
|
+
const text2 = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
14346
|
+
if (text2.includes("") || text2.includes("")) {
|
|
14347
|
+
cleanup();
|
|
14348
|
+
return reject(new PromptAborted());
|
|
14349
|
+
}
|
|
14350
|
+
const end = text2.search(/[\r\n]/);
|
|
14351
|
+
value += end === -1 ? text2 : text2.slice(0, end);
|
|
14352
|
+
if (end === -1) return;
|
|
14353
|
+
cleanup();
|
|
14354
|
+
const answer = value.trim().toLowerCase();
|
|
14355
|
+
resolve5(answer === "" ? defaultYes : answer === "y" || answer === "yes");
|
|
14356
|
+
};
|
|
14357
|
+
stderr.write(prompt);
|
|
14358
|
+
stdin.resume();
|
|
14359
|
+
stdin.on("data", onData);
|
|
14360
|
+
});
|
|
14361
|
+
}
|
|
14362
|
+
|
|
14363
|
+
// src/cli/commands/herdr-setup.ts
|
|
14364
|
+
var HERDR_PLUGIN_MODES = ["ask", "install", "skip"];
|
|
14365
|
+
async function herdrSetup(ctx, mode) {
|
|
14366
|
+
const s = ctx.out.stdout;
|
|
14367
|
+
const manual = `${s.dim("Next:")} peerband herdr install ${s.dim("then")} peerband relay`;
|
|
14368
|
+
const state = await checkHerdrPlugin(ctx);
|
|
14369
|
+
if (!state.found) {
|
|
14370
|
+
ctx.out.print("");
|
|
14371
|
+
ctx.out.print(`${s.yellow(symbols.warn)} Herdr was not found. The PeerBand Relay tab needs Herdr 0.9.3 or newer.`);
|
|
14372
|
+
ctx.out.print(" 1. Install Herdr: https://herdr.dev");
|
|
14373
|
+
ctx.out.print(` 2. ${s.bold("peerband herdr install")} ${s.dim("then")} ${s.bold("peerband relay")}`);
|
|
14374
|
+
return;
|
|
14375
|
+
}
|
|
14376
|
+
if (state.installed && state.problems.length === 0) {
|
|
14377
|
+
ctx.out.print(`${s.dim("Next:")} peerband relay ${s.dim("(opens the PeerBand Relay tab in Herdr)")}`);
|
|
14378
|
+
return;
|
|
14379
|
+
}
|
|
14380
|
+
const repair = state.installed;
|
|
14381
|
+
if (repair) {
|
|
14382
|
+
ctx.out.print("");
|
|
14383
|
+
ctx.out.print(`${s.yellow(symbols.warn)} The PeerBand plugin in Herdr needs repair: ${state.problems[0].message}`);
|
|
14384
|
+
if (state.problems.length > 1) ctx.out.print(s.dim(` (${state.problems.length - 1} more problem${state.problems.length > 2 ? "s" : ""}; see \`peerband status\`)`));
|
|
14385
|
+
}
|
|
14386
|
+
let install = mode === "install";
|
|
14387
|
+
if (mode === "ask" && ctx.stdin.isTTY && ctx.stderr.isTTY) {
|
|
14388
|
+
try {
|
|
14389
|
+
install = await askYesNo(ctx.stdin, ctx.stderr, repair ? "Repair the PeerBand plugin now? [Y/n] " : "Add the PeerBand plugin to Herdr now? [Y/n] ");
|
|
14390
|
+
} catch (error) {
|
|
14391
|
+
if (!(error instanceof PromptAborted)) throw error;
|
|
14392
|
+
ctx.out.print(manual);
|
|
14393
|
+
return;
|
|
14394
|
+
}
|
|
14395
|
+
if (!install) {
|
|
14396
|
+
ctx.out.print(s.dim(`Skipped. ${repair ? "Repair" : "Add"} it later with \`${REPAIR_COMMAND}\`, then open the relay with \`peerband relay\`.`));
|
|
14397
|
+
return;
|
|
14398
|
+
}
|
|
14399
|
+
}
|
|
14400
|
+
if (!install) {
|
|
14401
|
+
ctx.out.print(manual);
|
|
14402
|
+
return;
|
|
14403
|
+
}
|
|
14404
|
+
try {
|
|
14405
|
+
await installSpec.run({ values: {}, positionals: [] }, ctx);
|
|
14406
|
+
} catch (error) {
|
|
14407
|
+
const message = error.message;
|
|
14408
|
+
ctx.out.warn(`${s.yellow(symbols.warn)} Could not ${repair ? "repair" : "add"} the PeerBand plugin${repair ? "" : " to Herdr"}: ${message}`);
|
|
14409
|
+
if (error instanceof CliError && error.hint) ctx.out.warn(` ${error.hint}`);
|
|
14410
|
+
ctx.out.print(s.dim(`You are logged in. ${repair ? "Repair" : "Add"} the plugin later with \`peerband herdr install\`, then run \`peerband relay\`.`));
|
|
14411
|
+
}
|
|
14412
|
+
}
|
|
14413
|
+
async function ensureHerdrPlugin(ctx) {
|
|
14414
|
+
const check = await checkHerdrPlugin(ctx);
|
|
14415
|
+
if (!check.found || check.problems.length === 0) return;
|
|
14416
|
+
const s = ctx.out.stderr;
|
|
14417
|
+
const fix = "Run `peerband herdr install`, then `peerband relay`.";
|
|
14418
|
+
const reasons = check.problems.map((problem) => problem.message);
|
|
14419
|
+
if (!(ctx.stdin.isTTY && ctx.stderr.isTTY)) throw new CliError(`The PeerBand Herdr plugin needs repair. ${reasons.join(" ")}`, fix);
|
|
14420
|
+
ctx.out.warn(`${s.yellow(symbols.warn)} The PeerBand plugin in Herdr needs repair: ${reasons[0]}`);
|
|
14421
|
+
if (reasons.length > 1) ctx.out.warn(s.dim(` Also: ${reasons.slice(1).join(" ")}`));
|
|
14422
|
+
let repair;
|
|
14423
|
+
try {
|
|
14424
|
+
repair = await askYesNo(ctx.stdin, ctx.stderr, "Repair the PeerBand plugin now? [Y/n] ");
|
|
14425
|
+
} catch (error) {
|
|
14426
|
+
if (!(error instanceof PromptAborted)) throw error;
|
|
14427
|
+
repair = false;
|
|
14428
|
+
}
|
|
14429
|
+
if (!repair) throw new CliError(`The PeerBand Herdr plugin needs repair. ${reasons[0]}`, fix);
|
|
14430
|
+
await installSpec.run({ values: {}, positionals: [] }, ctx);
|
|
14431
|
+
}
|
|
14432
|
+
|
|
14341
14433
|
// src/cli/commands/login.ts
|
|
14342
14434
|
async function persist(ctx, redeemed) {
|
|
14343
14435
|
const credentials = { ...redeemed, enrolledAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -14453,25 +14545,30 @@ function mapFailure(error, serverUrl) {
|
|
|
14453
14545
|
return new CliError(error.message, "Run `peerband login` again, or use `peerband login --grant GRANT`.");
|
|
14454
14546
|
}
|
|
14455
14547
|
}
|
|
14456
|
-
var
|
|
14548
|
+
var spec2 = {
|
|
14457
14549
|
name: "login",
|
|
14458
14550
|
summary: "Connect this machine to your PeerBand account",
|
|
14459
|
-
usage: "peerband login [--name NAME] [--no-browser] [--server URL]\n peerband login --grant GRANT [--name NAME] [--server URL]",
|
|
14460
|
-
description: "Signs this machine in through your browser. login prints a link and a short code, opens the page (unless you are on SSH, a headless machine or pass --no-browser), and waits while you confirm the code in your PeerBand account. The credential is stored in your PeerBand config directory (readable only by you). Running login again replaces the existing enrollment.\n\nOn a headless machine or in CI, use a one-time grant instead: create it in the PeerBand dashboard and pass --grant GRANT (or set PEERBAND_GRANT).",
|
|
14551
|
+
usage: "peerband login [--name NAME] [--no-browser] [--server URL] [--herdr-plugin ask|install|skip]\n peerband login --grant GRANT [--name NAME] [--server URL]",
|
|
14552
|
+
description: "Signs this machine in through your browser. login prints a link and a short code, opens the page (unless you are on SSH, a headless machine or pass --no-browser), and waits while you confirm the code in your PeerBand account. The credential is stored in your PeerBand config directory (readable only by you). Running login again replaces the existing enrollment.\n\nOn a headless machine or in CI, use a one-time grant instead: create it in the PeerBand dashboard and pass --grant GRANT (or set PEERBAND_GRANT).\n\nWhen login succeeds it checks for Herdr. If the PeerBand plugin is missing, or installed but wrong (another version, a local checkout, a stale config directory), it offers to add or repair it (--herdr-plugin ask, the default; it only asks on a terminal), adds it without asking (install), or just prints the command (skip).",
|
|
14461
14553
|
options: [
|
|
14462
14554
|
{ name: "no-browser", type: "boolean", description: "Do not open a browser; print the link and code only (SSH, containers)." },
|
|
14463
14555
|
{ name: "name", type: "string", valueName: "NAME", description: "Name shown for this machine in the dashboard. Default: this computer's hostname." },
|
|
14464
14556
|
{ name: "server", type: "string", valueName: "URL", description: "PeerBand server. Default: $PEERBAND_SERVER or https://peerband.com." },
|
|
14465
|
-
{ name: "grant", type: "string", valueName: "GRANT", description: "Headless/CI: enroll with a dashboard grant instead of the browser. Default: $PEERBAND_GRANT." }
|
|
14557
|
+
{ name: "grant", type: "string", valueName: "GRANT", description: "Headless/CI: enroll with a dashboard grant instead of the browser. Default: $PEERBAND_GRANT." },
|
|
14558
|
+
{ name: "herdr-plugin", type: "string", valueName: "ask|install|skip", description: "After login, add the PeerBand plugin to Herdr: ask (default; prompts on a terminal), install, or skip." }
|
|
14466
14559
|
],
|
|
14467
14560
|
examples: [
|
|
14468
14561
|
["peerband login", "Open your browser, confirm the code, done"],
|
|
14562
|
+
["peerband login --herdr-plugin install", "Also add the PeerBand plugin to Herdr without asking (used by the install scripts)"],
|
|
14469
14563
|
["peerband login --no-browser", "Print the link and code; open the link on any other device"],
|
|
14470
14564
|
["PEERBAND_GRANT=... peerband login --name work-laptop", "Headless/CI with a dashboard grant; keeps it out of the process list"],
|
|
14471
14565
|
["peerband login --server http://localhost:8000", "Against a local development server"]
|
|
14472
14566
|
],
|
|
14473
14567
|
notes: ["The code you confirm in the browser must match the one shown here. The secret device code and any grant are never printed or stored. Plain HTTP is only accepted for localhost."],
|
|
14474
14568
|
async run(parsed, ctx) {
|
|
14569
|
+
const rawMode = str(parsed, "herdr-plugin")?.trim().toLowerCase() ?? "ask";
|
|
14570
|
+
if (!HERDR_PLUGIN_MODES.includes(rawMode)) throw new UsageError(`Invalid --herdr-plugin value "${rawMode}".`, "Use --herdr-plugin ask, install or skip.");
|
|
14571
|
+
const herdrMode = rawMode;
|
|
14475
14572
|
const serverUrl = resolveServerUrl(str(parsed, "server"), ctx.env);
|
|
14476
14573
|
const name = str(parsed, "name")?.trim() || hostname();
|
|
14477
14574
|
const grant = (str(parsed, "grant") ?? ctx.env.PEERBAND_GRANT)?.trim();
|
|
@@ -14483,13 +14580,15 @@ var spec3 = {
|
|
|
14483
14580
|
if (previous) ctx.out.print(s.dim(`Replaced the previous login (${previous.machineName ?? previous.installationId} on ${previous.serverUrl}).`));
|
|
14484
14581
|
const who = credentials.accountEmail ? ` (${credentials.accountEmail})` : "";
|
|
14485
14582
|
ctx.out.print(`${s.green(symbols.ok)} Logged in as ${s.bold(credentials.machineName ?? name)}${who}`);
|
|
14486
|
-
|
|
14583
|
+
await herdrSetup(ctx, herdrMode);
|
|
14584
|
+
ctx.out.print("");
|
|
14585
|
+
printSkillTip(ctx);
|
|
14487
14586
|
return 0;
|
|
14488
14587
|
}
|
|
14489
14588
|
};
|
|
14490
14589
|
|
|
14491
14590
|
// src/cli/commands/logout.ts
|
|
14492
|
-
var
|
|
14591
|
+
var spec3 = {
|
|
14493
14592
|
name: "logout",
|
|
14494
14593
|
summary: "Forget this machine's PeerBand credential",
|
|
14495
14594
|
usage: "peerband logout",
|
|
@@ -14514,15 +14613,16 @@ var spec4 = {
|
|
|
14514
14613
|
};
|
|
14515
14614
|
|
|
14516
14615
|
// src/cli/commands/relay.ts
|
|
14517
|
-
var
|
|
14616
|
+
var spec4 = {
|
|
14518
14617
|
name: "relay",
|
|
14519
14618
|
summary: "Open or focus the PeerBand Relay tab in Herdr",
|
|
14520
14619
|
usage: "peerband relay",
|
|
14521
|
-
description: "Opens the PeerBand Relay in a persistent Herdr tab, or focuses it if it is already open. The tab shows your account, connection state and metadata-only activity; closing it disconnects. Requires Herdr and the PeerBand plugin (`peerband herdr install`).",
|
|
14620
|
+
description: "Opens the PeerBand Relay in a persistent Herdr tab, or focuses it if it is already open. The tab shows your account, connection state and metadata-only activity; closing it disconnects. Requires Herdr and the PeerBand plugin (`peerband herdr install`). If the plugin is wrong (another version, a local checkout, or a stale config directory), relay offers to repair it first.",
|
|
14522
14621
|
options: [],
|
|
14523
14622
|
examples: [["peerband relay", "Open the relay tab"]],
|
|
14524
14623
|
async run(_parsed, ctx) {
|
|
14525
14624
|
const credentials = await requireCredentials(ctx);
|
|
14625
|
+
await ensureHerdrPlugin(ctx);
|
|
14526
14626
|
try {
|
|
14527
14627
|
await (ctx.openRelayTab ?? openRelayTab2)();
|
|
14528
14628
|
} catch (error) {
|
|
@@ -14536,12 +14636,124 @@ var spec5 = {
|
|
|
14536
14636
|
const s = ctx.out.stdout;
|
|
14537
14637
|
ctx.out.print(`${s.green(symbols.ok)} PeerBand Relay is open in Herdr.`);
|
|
14538
14638
|
printMcpHint(ctx, credentials.serverUrl);
|
|
14639
|
+
printSkillTip(ctx);
|
|
14539
14640
|
return 0;
|
|
14540
14641
|
}
|
|
14541
14642
|
};
|
|
14542
14643
|
|
|
14644
|
+
// src/cli/commands/status.ts
|
|
14645
|
+
function safeMcpUrl(serverUrl, env) {
|
|
14646
|
+
try {
|
|
14647
|
+
return mcpUrlFor(serverUrl, env);
|
|
14648
|
+
} catch {
|
|
14649
|
+
return null;
|
|
14650
|
+
}
|
|
14651
|
+
}
|
|
14652
|
+
async function buildStatus(ctx) {
|
|
14653
|
+
let credentials;
|
|
14654
|
+
try {
|
|
14655
|
+
credentials = await loadCredentials(credentialsFile(ctx));
|
|
14656
|
+
} catch {
|
|
14657
|
+
credentials = void 0;
|
|
14658
|
+
}
|
|
14659
|
+
const snapshot = await relaySnapshot(ctx.env);
|
|
14660
|
+
const plugin = await checkHerdrPlugin(ctx);
|
|
14661
|
+
const messages = await loadMachineConnectorConfig(ctx).then(
|
|
14662
|
+
(config) => writesEnabled(config) ? "allowed" : "read-only",
|
|
14663
|
+
() => null
|
|
14664
|
+
);
|
|
14665
|
+
return {
|
|
14666
|
+
version: ctx.version,
|
|
14667
|
+
node: process.versions.node,
|
|
14668
|
+
configHome: configHome({ env: ctx.env }),
|
|
14669
|
+
loggedIn: Boolean(credentials),
|
|
14670
|
+
machine: credentials?.machineName ?? null,
|
|
14671
|
+
email: credentials?.accountEmail ?? null,
|
|
14672
|
+
server: credentials?.serverUrl ?? null,
|
|
14673
|
+
mcpUrl: credentials ? safeMcpUrl(credentials.serverUrl, ctx.env) : null,
|
|
14674
|
+
installationId: credentials?.installationId ?? null,
|
|
14675
|
+
enrolledAt: credentials?.enrolledAt ?? null,
|
|
14676
|
+
relay: {
|
|
14677
|
+
running: snapshot?.source === "control" && snapshot.state === "running",
|
|
14678
|
+
connection: snapshot?.connectionState ?? null,
|
|
14679
|
+
source: snapshot?.source ?? "none"
|
|
14680
|
+
},
|
|
14681
|
+
messages,
|
|
14682
|
+
herdr: {
|
|
14683
|
+
found: plugin.found,
|
|
14684
|
+
version: plugin.herdrVersion,
|
|
14685
|
+
pluginInstalled: plugin.found ? plugin.installed : null,
|
|
14686
|
+
pluginSource: plugin.source,
|
|
14687
|
+
pluginProblems: plugin.problems
|
|
14688
|
+
}
|
|
14689
|
+
};
|
|
14690
|
+
}
|
|
14691
|
+
function colorConnection(s, state) {
|
|
14692
|
+
if (!state) return s.dim("not running");
|
|
14693
|
+
const label = paneLabel2({ state: "running", connectionState: state, activity: [] });
|
|
14694
|
+
if (state === "connected") return s.green(`${symbols.dot} ${label}`);
|
|
14695
|
+
if (state === "connecting" || state === "reconnecting") return s.yellow(`${symbols.dot} ${label}`);
|
|
14696
|
+
if (state === "disabled") return s.dim(`${symbols.ring} ${label}`);
|
|
14697
|
+
return s.red(`${symbols.dot} ${label}`);
|
|
14698
|
+
}
|
|
14699
|
+
function renderHuman(report, ctx) {
|
|
14700
|
+
const s = ctx.out.stdout;
|
|
14701
|
+
const rows = [];
|
|
14702
|
+
rows.push([
|
|
14703
|
+
"Account",
|
|
14704
|
+
report.loggedIn ? `${s.green(symbols.ok)} logged in${report.email ? ` as ${report.email}` : ""}` : `${s.red(symbols.fail)} not logged in ${s.dim("(run `peerband login`)")}`
|
|
14705
|
+
]);
|
|
14706
|
+
if (report.loggedIn) {
|
|
14707
|
+
rows.push(["Machine", report.machine ?? s.dim("(unnamed)")]);
|
|
14708
|
+
rows.push(["Server", report.server ?? ""]);
|
|
14709
|
+
if (report.mcpUrl) rows.push(["MCP server", report.mcpUrl]);
|
|
14710
|
+
rows.push(["Installation", report.installationId ?? ""]);
|
|
14711
|
+
if (report.enrolledAt) rows.push(["Enrolled", report.enrolledAt]);
|
|
14712
|
+
}
|
|
14713
|
+
const relayLine = report.relay.running ? colorConnection(s, report.relay.connection) : report.relay.source === "file" && report.relay.connection && report.relay.connection !== "helper-unavailable" ? `${colorConnection(s, report.relay.connection)} ${s.dim("(last known; relay not running)")}` : s.dim(`${symbols.ring} not running ${s.dim("(open it with `peerband relay`)")}`);
|
|
14714
|
+
rows.push(["Relay", relayLine]);
|
|
14715
|
+
if (report.messages) {
|
|
14716
|
+
rows.push([
|
|
14717
|
+
"Messages",
|
|
14718
|
+
report.messages === "allowed" ? `allowed ${s.dim('(needs the agents:message consent; turn off with --read-only or "enableWrites": false in connector.json)')}` : "read-only"
|
|
14719
|
+
]);
|
|
14720
|
+
}
|
|
14721
|
+
rows.push([
|
|
14722
|
+
"Herdr",
|
|
14723
|
+
!report.herdr.found ? `${s.yellow(symbols.warn)} not found ${s.dim("(set HERDR_BIN_PATH or add herdr to PATH)")}` : `${report.herdr.version ?? "unknown version"}`
|
|
14724
|
+
]);
|
|
14725
|
+
if (report.herdr.found) {
|
|
14726
|
+
const first = report.herdr.pluginProblems[0];
|
|
14727
|
+
rows.push([
|
|
14728
|
+
"Plugin",
|
|
14729
|
+
!report.herdr.pluginInstalled ? `${s.yellow(symbols.warn)} not installed ${s.dim(`(run \`${REPAIR_COMMAND}\`)`)}` : first ? `${s.yellow(symbols.warn)} ${first.message} ${s.dim(`(run \`${REPAIR_COMMAND}\`)`)}` : `${s.green(symbols.ok)} ${report.herdr.pluginSource ?? "installed"}`
|
|
14730
|
+
]);
|
|
14731
|
+
}
|
|
14732
|
+
rows.push(["peerband", `${report.version} ${s.dim(`(node ${report.node})`)}`]);
|
|
14733
|
+
rows.push(["Config", s.dim(report.configHome)]);
|
|
14734
|
+
const width = Math.max(...rows.map(([key]) => key.length));
|
|
14735
|
+
for (const [key, value] of rows) ctx.out.print(`${s.bold(key.padEnd(width))} ${value}`);
|
|
14736
|
+
}
|
|
14737
|
+
var spec5 = {
|
|
14738
|
+
name: "status",
|
|
14739
|
+
summary: "Show login, relay and Herdr status",
|
|
14740
|
+
usage: "peerband status [--json]",
|
|
14741
|
+
description: "Shows whether this machine is logged in, whether the PeerBand Relay is running and connected, and whether Herdr and the PeerBand plugin are installed. Exits with code 3 when not logged in.",
|
|
14742
|
+
options: [{ name: "json", type: "boolean", description: "Print a stable machine-readable JSON object instead of text." }],
|
|
14743
|
+
examples: [
|
|
14744
|
+
["peerband status", "Human-readable summary"],
|
|
14745
|
+
["peerband status --json", "For scripts; check .loggedIn and .relay.connection"]
|
|
14746
|
+
],
|
|
14747
|
+
async run(parsed, ctx) {
|
|
14748
|
+
const report = await buildStatus(ctx);
|
|
14749
|
+
if (flag(parsed, "json")) ctx.out.print(JSON.stringify(report, null, 2));
|
|
14750
|
+
else renderHuman(report, ctx);
|
|
14751
|
+
return report.loggedIn ? 0 : EXIT_NOT_LOGGED_IN;
|
|
14752
|
+
}
|
|
14753
|
+
};
|
|
14754
|
+
|
|
14543
14755
|
// src/cli/registry.ts
|
|
14544
|
-
var commands = [
|
|
14756
|
+
var commands = [spec2, spec3, spec5, spec4, spec];
|
|
14545
14757
|
var herdrCommands = [installSpec, uninstallSpec];
|
|
14546
14758
|
function lookup(words) {
|
|
14547
14759
|
const [first, second] = words;
|
|
@@ -14630,16 +14842,8 @@ function herdrGroupHelp(s) {
|
|
|
14630
14842
|
`;
|
|
14631
14843
|
}
|
|
14632
14844
|
|
|
14633
|
-
// src/cli/prompt.ts
|
|
14634
|
-
var PromptAborted = class extends Error {
|
|
14635
|
-
constructor() {
|
|
14636
|
-
super("Prompt cancelled.");
|
|
14637
|
-
this.name = "PromptAborted";
|
|
14638
|
-
}
|
|
14639
|
-
};
|
|
14640
|
-
|
|
14641
14845
|
// src/cli/cli.ts
|
|
14642
|
-
var VERSION = true ? "0.1.
|
|
14846
|
+
var VERSION = true ? "0.1.2" : "0.0.0-dev";
|
|
14643
14847
|
function createContext(overrides = {}) {
|
|
14644
14848
|
const env = overrides.env ?? process.env;
|
|
14645
14849
|
const stdout = overrides.stdout ?? process.stdout;
|
package/herdr/lifecycle.mjs
CHANGED
|
@@ -66,7 +66,7 @@ let paneStateWrites = Promise.resolve();
|
|
|
66
66
|
|
|
67
67
|
async function supervise() {
|
|
68
68
|
const token = randomBytes(32).toString("hex");
|
|
69
|
-
//
|
|
69
|
+
// Messaging is on by default; "enableWrites": false in connector.json (read by the connector itself) turns it off.
|
|
70
70
|
const childArgs = [connectorEntry, "connect", "--managed"];
|
|
71
71
|
if (process.env.PEERBAND_RUNTIME === "mock")
|
|
72
72
|
childArgs.push("--runtime", "mock");
|
package/herdr/pane-ui.mjs
CHANGED
|
@@ -8,7 +8,17 @@ const timeLabel = (value) => {
|
|
|
8
8
|
};
|
|
9
9
|
const safeText = (value, maximum = 160) => String(value ?? "").replace(/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1b\\)?)/g, "").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, maximum);
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// "Messages" is the connector's write state: allowed by default, read-only when connector.json says "enableWrites": false.
|
|
12
|
+
export const messagesLine = (messages) => messages === "read-only"
|
|
13
|
+
? "Messages read-only"
|
|
14
|
+
: messages === "allowed"
|
|
15
|
+
? 'Messages allowed (turn off: "enableWrites": false in connector.json)'
|
|
16
|
+
: "";
|
|
17
|
+
|
|
18
|
+
// 1-based screen rows of the on/off box; the Account row is only shown when the server returned an email.
|
|
19
|
+
export const controlBoxRows = (email) => (email ? [7, 9] : [6, 8]);
|
|
20
|
+
|
|
21
|
+
export function renderPane({ snapshot, identity, email, messages, error, columns = Infinity, rows: height = Infinity }) {
|
|
12
22
|
const label = paneLabel(snapshot);
|
|
13
23
|
const enabled = snapshot?.state === "running";
|
|
14
24
|
const width = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : Infinity;
|
|
@@ -17,10 +27,11 @@ export function renderPane({ snapshot, identity, email, error, columns = Infinit
|
|
|
17
27
|
if (heightLimit < 13) {
|
|
18
28
|
const compactRows = [
|
|
19
29
|
`RELAY ${enabled ? "ON" : "OFF"} · ${safeText(label, 20)}`,
|
|
20
|
-
`Account ${safeText(email || "Unavailable")}`,
|
|
30
|
+
email ? `Account ${safeText(email)}` : `Machine ${safeText(identity || "Unavailable")}`,
|
|
21
31
|
"Space / Enter toggle",
|
|
22
32
|
"q / Esc close relay",
|
|
23
33
|
"Close disconnects; reopen: peerband relay",
|
|
34
|
+
...(messages ? [`Messages ${messages === "read-only" ? "read-only" : "allowed"}`] : []),
|
|
24
35
|
];
|
|
25
36
|
return compactRows.slice(0, heightLimit).map(clipLine).join("\n");
|
|
26
37
|
}
|
|
@@ -31,7 +42,7 @@ export function renderPane({ snapshot, identity, email, error, columns = Infinit
|
|
|
31
42
|
"PeerBand · Herdr control",
|
|
32
43
|
"─".repeat(Number.isFinite(width) ? Math.max(0, Math.min(40, width)) : 40),
|
|
33
44
|
`Machine ${safeText(identity || "Unavailable")}`,
|
|
34
|
-
`Account ${safeText(email
|
|
45
|
+
...(email ? [`Account ${safeText(email)}`] : []),
|
|
35
46
|
"",
|
|
36
47
|
`┌${"─".repeat(innerWidth)}┐`,
|
|
37
48
|
boxLine(` RELAY ${enabled ? "● ON " : "○ OFF"} ${safeText(label, 20)}`),
|
|
@@ -39,7 +50,7 @@ export function renderPane({ snapshot, identity, email, error, columns = Infinit
|
|
|
39
50
|
? ` [Space/Enter] ${enabled ? "Off" : "On"}`
|
|
40
51
|
: ` [Space / Enter] ${enabled ? "Turn off" : "Turn on"}`),
|
|
41
52
|
`└${"─".repeat(innerWidth)}┘`,
|
|
42
|
-
|
|
53
|
+
safeText(messagesLine(messages)),
|
|
43
54
|
"Recent activity · metadata only",
|
|
44
55
|
];
|
|
45
56
|
const activities = (snapshot?.activity ?? []).slice(-8).reverse().map((item) =>
|
|
@@ -60,7 +71,7 @@ export function renderPane({ snapshot, identity, email, error, columns = Infinit
|
|
|
60
71
|
return body.map(clipLine).join("\n");
|
|
61
72
|
}
|
|
62
73
|
|
|
63
|
-
export function startPaneInput({ onToggle, onClose, input = stdin, output = stdout }) {
|
|
74
|
+
export function startPaneInput({ onToggle, onClose, input = stdin, output = stdout, boxRows = [7, 9] }) {
|
|
64
75
|
if (!input.isTTY || !input.setRawMode) return () => {};
|
|
65
76
|
const wasRaw = input.isRaw;
|
|
66
77
|
const mouseEnabled = !Number.isFinite(output.rows) || output.rows >= 13;
|
|
@@ -79,7 +90,7 @@ export function startPaneInput({ onToggle, onClose, input = stdin, output = stdo
|
|
|
79
90
|
const row = Number(match?.[2]);
|
|
80
91
|
const boxWidth = Number.isFinite(output.columns) ? Math.max(1, Math.min(42, Math.floor(output.columns))) : 42;
|
|
81
92
|
const hasControlBox = !Number.isFinite(output.rows) || output.rows >= 13;
|
|
82
|
-
if (mouseEnabled && hasControlBox && match && row >=
|
|
93
|
+
if (mouseEnabled && hasControlBox && match && row >= boxRows[0] && row <= boxRows[1] && column >= 1 && column <= boxWidth) onToggle();
|
|
83
94
|
if (mouseBuffer.includes("M")) mouseBuffer = "";
|
|
84
95
|
};
|
|
85
96
|
input.on("keypress", keypress);
|
package/herdr/pane.mjs
CHANGED
|
@@ -4,10 +4,10 @@ import { readFile } from "node:fs/promises";
|
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { stdout } from "node:process";
|
|
7
|
-
import { renderPane, startPaneInput } from "./pane-ui.mjs";
|
|
7
|
+
import { renderPane, startPaneInput, controlBoxRows } from "./pane-ui.mjs";
|
|
8
8
|
import { connectControl } from "./control.mjs";
|
|
9
9
|
import { syncRelayTab, closeRelayTab } from "./relay-tab.mjs";
|
|
10
|
-
import { credentialsPath } from "./paths.mjs";
|
|
10
|
+
import { credentialsPath, connectorConfigPath } from "./paths.mjs";
|
|
11
11
|
|
|
12
12
|
const exec = promisify(execFile);
|
|
13
13
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
@@ -18,7 +18,11 @@ const identity = typeof credentials.machineName === "string" && credentials.mach
|
|
|
18
18
|
: typeof credentials.installationId === "string" && credentials.installationId
|
|
19
19
|
? `Installation ${credentials.installationId}`
|
|
20
20
|
: "Not logged in (run `peerband login`)";
|
|
21
|
-
|
|
21
|
+
// No email (the server did not return one) is not an error: the Account row is simply not shown.
|
|
22
|
+
const email = typeof credentials.accountEmail === "string" && credentials.accountEmail ? credentials.accountEmail : "";
|
|
23
|
+
// Messages to agents are allowed unless connector.json says "enableWrites": false (same rule as `peerband connect`).
|
|
24
|
+
const connectorConfig = await readFile(connectorConfigPath(), "utf8").then(JSON.parse).catch(() => ({}));
|
|
25
|
+
const messages = connectorConfig && connectorConfig.enableWrites === false ? "read-only" : "allowed";
|
|
22
26
|
|
|
23
27
|
let closing = false;
|
|
24
28
|
let pending = false;
|
|
@@ -37,7 +41,7 @@ let controlClosed;
|
|
|
37
41
|
const closed = new Promise((resolve) => { controlClosed = resolve; });
|
|
38
42
|
function draw() {
|
|
39
43
|
if (closing || !stdout.isTTY) return;
|
|
40
|
-
stdout.write("\x1b[2J\x1b[H" + renderPane({ snapshot, identity, email, error: errorText, columns: stdout.columns, rows: stdout.rows }));
|
|
44
|
+
stdout.write("\x1b[2J\x1b[H" + renderPane({ snapshot, identity, email, messages, error: errorText, columns: stdout.columns, rows: stdout.rows }));
|
|
41
45
|
}
|
|
42
46
|
async function runLifecycle(command) {
|
|
43
47
|
const { stdout: result } = await exec(process.execPath, [lifecycle, command], { timeout: 5000, windowsHide: true, maxBuffer: 65_536 });
|
|
@@ -103,7 +107,7 @@ async function close() {
|
|
|
103
107
|
}
|
|
104
108
|
const onInputEnd = () => { void close(); };
|
|
105
109
|
const onSignal = () => { void close(); };
|
|
106
|
-
const stopInput = startPaneInput({ onToggle: toggle, onClose: () => {
|
|
110
|
+
const stopInput = startPaneInput({ boxRows: controlBoxRows(email), onToggle: toggle, onClose: () => {
|
|
107
111
|
if (closeArmed) { void close(); return; }
|
|
108
112
|
closeArmed = true;
|
|
109
113
|
errorText = "Closing disconnects the relay. Press q again to close; reopen with `peerband relay`.";
|
|
@@ -117,7 +121,7 @@ if (stdinIsInteractive()) {
|
|
|
117
121
|
process.once("SIGHUP", onSignal);
|
|
118
122
|
}
|
|
119
123
|
if (!stdinIsInteractive()) {
|
|
120
|
-
console.log(renderPane({ snapshot, identity, email, error: "Interactive terminal controls are required in this pane." }));
|
|
124
|
+
console.log(renderPane({ snapshot, identity, email, messages, error: "Interactive terminal controls are required in this pane." }));
|
|
121
125
|
} else {
|
|
122
126
|
try {
|
|
123
127
|
try { control = await connectControl(); }
|
package/herdr/paths.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Plain-JS twin of configHome() in src/core/config.ts. Keep the semantics identical.
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { homedir, tmpdir } from "node:os";
|
|
4
|
-
import { join, posix, win32 } from "node:path";
|
|
4
|
+
import { join, posix, resolve, win32 } from "node:path";
|
|
5
5
|
|
|
6
6
|
export function configHome(env = process.env, platform = process.platform, home = homedir()) {
|
|
7
7
|
if (env.PEERBAND_CONFIG_HOME) return env.PEERBAND_CONFIG_HOME;
|
|
@@ -9,6 +9,8 @@ export function configHome(env = process.env, platform = process.platform, home
|
|
|
9
9
|
return join(env.XDG_CONFIG_HOME || join(home, ".config"), "peerband");
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// PEERBAND_CONNECTOR_CONFIG overrides the default file, as in `peerband connect`.
|
|
13
|
+
export const connectorConfigPath = (config = configHome(), env = process.env) => env.PEERBAND_CONNECTOR_CONFIG ? resolve(env.PEERBAND_CONNECTOR_CONFIG) : join(config, "connector.json");
|
|
12
14
|
export const credentialsPath = (config = configHome()) => join(config, "credentials.json");
|
|
13
15
|
export const lockPath = (config = configHome()) => join(config, "relay-helper.lock");
|
|
14
16
|
export const ownerRecordPath = (config = configHome()) => join(lockPath(config), "owner.json");
|
package/herdr-plugin.toml
CHANGED
package/install/install.ps1
CHANGED
|
@@ -90,7 +90,7 @@ if (-not $pbOnPath) {
|
|
|
90
90
|
Say ' ok peerband installed' Green
|
|
91
91
|
|
|
92
92
|
Say '==> Logging in' Cyan
|
|
93
|
-
$loginArgs = @('login')
|
|
93
|
+
$loginArgs = @('login', '--herdr-plugin', 'install')
|
|
94
94
|
if ($pbName) { $loginArgs += @('--name', $pbName) }
|
|
95
95
|
try {
|
|
96
96
|
if ($pbGrant) { $env:PEERBAND_GRANT = $pbGrant }
|
|
@@ -102,20 +102,14 @@ try {
|
|
|
102
102
|
}
|
|
103
103
|
if ($loginCode -ne 0) { Fail "peerband login failed. Run 'peerband login' again, or on a headless machine use 'peerband login --grant GRANT' with a grant from your PeerBand dashboard." }
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
# `peerband login --herdr-plugin install` has already added the plugin to Herdr when Herdr is present.
|
|
106
106
|
$pbHasHerdr = [bool](Get-Command herdr -ErrorAction SilentlyContinue)
|
|
107
|
-
if ($pbHasHerdr) {
|
|
108
|
-
& $pbExe herdr install
|
|
109
|
-
if ($LASTEXITCODE -ne 0) { Fail 'peerband herdr install failed. Fix the error above and run it again.' }
|
|
110
|
-
} else {
|
|
111
|
-
Say ' !! Herdr was not found. PeerBand reaches the agents you run in Herdr.' Yellow
|
|
112
|
-
}
|
|
113
107
|
|
|
114
108
|
Say ''
|
|
115
109
|
if ($pbHasHerdr) {
|
|
116
110
|
Say 'PeerBand is ready. Next:' Green
|
|
117
111
|
Say ' peerband relay open the PeerBand Relay tab in Herdr'
|
|
118
|
-
Say ' peerband status check your connection'
|
|
112
|
+
Say ' peerband status check your connection (and the Herdr plugin)'
|
|
119
113
|
} else {
|
|
120
114
|
Say 'PeerBand is installed and logged in. Next:' Green
|
|
121
115
|
Say ' 1. Install Herdr 0.9.3 or newer: https://herdr.dev'
|
package/install/install.sh
CHANGED
|
@@ -79,14 +79,14 @@ ok "peerband installed"
|
|
|
79
79
|
step "Logging in"
|
|
80
80
|
if [ -n "$grant" ]; then
|
|
81
81
|
if [ -n "$name" ]; then
|
|
82
|
-
PEERBAND_GRANT=$grant "$pb" login --name "$name" || die "peerband login failed. Get a fresh grant from your PeerBand dashboard."
|
|
82
|
+
PEERBAND_GRANT=$grant "$pb" login --herdr-plugin install --name "$name" || die "peerband login failed. Get a fresh grant from your PeerBand dashboard."
|
|
83
83
|
else
|
|
84
|
-
PEERBAND_GRANT=$grant "$pb" login || die "peerband login failed. Get a fresh grant from your PeerBand dashboard."
|
|
84
|
+
PEERBAND_GRANT=$grant "$pb" login --herdr-plugin install || die "peerband login failed. Get a fresh grant from your PeerBand dashboard."
|
|
85
85
|
fi
|
|
86
86
|
else
|
|
87
87
|
# Browser sign-in. Under `curl | sh` stdin is the script itself; use the terminal instead.
|
|
88
|
-
set --
|
|
89
|
-
[ -z "$name" ] || set -- --name "$name"
|
|
88
|
+
set -- --herdr-plugin install
|
|
89
|
+
[ -z "$name" ] || set -- "$@" --name "$name"
|
|
90
90
|
if (exec </dev/tty) 2>/dev/null; then
|
|
91
91
|
"$pb" login "$@" </dev/tty
|
|
92
92
|
else
|
|
@@ -95,10 +95,9 @@ else
|
|
|
95
95
|
fi
|
|
96
96
|
grant=''
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
# `peerband login --herdr-plugin install` has already added the plugin to Herdr when Herdr is present.
|
|
99
99
|
if command -v herdr >/dev/null 2>&1; then
|
|
100
|
-
|
|
101
|
-
printf '\n%sPeerBand is ready.%s Next:\n peerband relay open the PeerBand Relay tab in Herdr\n peerband status check your connection\n' "$G" "$N"
|
|
100
|
+
printf '\n%sPeerBand is ready.%s Next:\n peerband relay open the PeerBand Relay tab in Herdr\n peerband status check your connection (and the Herdr plugin)\n' "$G" "$N"
|
|
102
101
|
else
|
|
103
102
|
warn "Herdr was not found. PeerBand reaches the agents you run in Herdr."
|
|
104
103
|
printf '\n%sPeerBand is installed and logged in.%s Next:\n 1. Install Herdr 0.9.3 or newer: https://herdr.dev\n 2. peerband herdr install then peerband relay\n peerband status check your connection\n' "$G" "$N"
|
package/package.json
CHANGED