peerband 0.1.3 → 0.1.6
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 +53 -14
- package/dist/peerband.mjs +2686 -919
- package/herdr/README.md +18 -18
- package/herdr/control.mjs +2 -1
- package/herdr/launch.mjs +87 -87
- package/herdr/lifecycle.mjs +141 -55
- package/herdr/pane.mjs +124 -46
- package/herdr/relay-tab.mjs +17 -0
- package/herdr/stale-lock.mjs +200 -0
- package/herdr-plugin.toml +1 -1
- package/install/install.ps1 +119 -118
- package/install/install.sh +12 -11
- package/package.json +2 -2
- package/protocol/README.md +8 -3
- package/protocol/relay-messages.schema.json +134 -78
- package/skills/peerband/SKILL.md +94 -0
package/install/install.ps1
CHANGED
|
@@ -1,118 +1,119 @@
|
|
|
1
|
-
# PeerBand installer for Windows PowerShell 5.1 and PowerShell 7+.
|
|
2
|
-
#
|
|
3
|
-
# irm https://peerband.com/install.ps1 | iex
|
|
4
|
-
# Installs the CLI, then runs the interactive `peerband
|
|
5
|
-
# Headless/CI only: use a dashboard grant instead of the browser, e.g.
|
|
6
|
-
# $env:PEERBAND_GRANT = 'GRANT'; $env:PEERBAND_NAME = 'my-pc'; irm https://peerband.com/install.ps1 | iex
|
|
7
|
-
#
|
|
8
|
-
# & ([scriptblock]::Create((irm https://peerband.com/install.ps1))) -Grant GRANT -Name my-pc
|
|
9
|
-
#
|
|
10
|
-
# Env: PEERBAND_GRANT, PEERBAND_NAME, PEERBAND_VERSION (default latest),
|
|
11
|
-
# PEERBAND_PACKAGE (tarball path or git URL; overrides the npm package).
|
|
12
|
-
# There is deliberately no param() block so that `irm | iex` works.
|
|
13
|
-
|
|
14
|
-
$ErrorActionPreference = 'Stop'
|
|
15
|
-
$pbGrant = $env:PEERBAND_GRANT
|
|
16
|
-
$pbName = $env:PEERBAND_NAME
|
|
17
|
-
$pbShowHelp = $false
|
|
18
|
-
$pbUsageError = $null
|
|
19
|
-
$pbColor = -not $env:NO_COLOR
|
|
20
|
-
$pbIsFile = [bool]$PSCommandPath
|
|
21
|
-
|
|
22
|
-
for ($i = 0; $i -lt $args.Count; $i++) {
|
|
23
|
-
switch -Regex ([string]$args[$i]) {
|
|
24
|
-
'^-{1,2}(Grant)$' { if ($i + 1 -lt $args.Count) { $pbGrant = [string]$args[++$i] } else { $pbUsageError = '-Grant needs a value' } }
|
|
25
|
-
'^-{1,2}(Name)$' { if ($i + 1 -lt $args.Count) { $pbName = [string]$args[++$i] } else { $pbUsageError = '-Name needs a value' } }
|
|
26
|
-
'^(-{1,2}(Help|h)|/\?)$' { $pbShowHelp = $true }
|
|
27
|
-
default { $pbUsageError = "unknown argument: $($args[$i])" }
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function Say($Text, $Color = $null) {
|
|
32
|
-
if ($pbColor -and $Color) { Write-Host $Text -ForegroundColor $Color } else { Write-Host $Text }
|
|
33
|
-
}
|
|
34
|
-
function Fail($Message, [int]$Code = 1) {
|
|
35
|
-
[Console]::Error.WriteLine("error: $Message")
|
|
36
|
-
if ($script:pbIsFile) { exit $Code }
|
|
37
|
-
# `exit` would close the user's shell under `irm | iex`; stop the script instead.
|
|
38
|
-
throw "PeerBand installer stopped (see the error above)."
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if ($pbShowHelp) {
|
|
42
|
-
Say @'
|
|
43
|
-
PeerBand installer
|
|
44
|
-
|
|
45
|
-
Usage: install.ps1 [-Name NAME] [-Grant GRANT]
|
|
46
|
-
|
|
47
|
-
By default the installer runs "peerband
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
$
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
$
|
|
66
|
-
$
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
$
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
#
|
|
79
|
-
|
|
80
|
-
$
|
|
81
|
-
|
|
82
|
-
$
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
Say "
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
$
|
|
101
|
-
$
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
$
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
Say '
|
|
116
|
-
Say '
|
|
117
|
-
Say ' peerband
|
|
118
|
-
|
|
1
|
+
# PeerBand installer for Windows PowerShell 5.1 and PowerShell 7+.
|
|
2
|
+
#
|
|
3
|
+
# irm https://peerband.com/install.ps1 | iex
|
|
4
|
+
# Installs the CLI, then runs the interactive `peerband setup` (browser login, Herdr plugin, agent skill, relay).
|
|
5
|
+
# Headless/CI only: use a dashboard grant instead of the browser, e.g.
|
|
6
|
+
# $env:PEERBAND_GRANT = 'GRANT'; $env:PEERBAND_NAME = 'my-pc'; irm https://peerband.com/install.ps1 | iex
|
|
7
|
+
#
|
|
8
|
+
# & ([scriptblock]::Create((irm https://peerband.com/install.ps1))) -Grant GRANT -Name my-pc
|
|
9
|
+
#
|
|
10
|
+
# Env: PEERBAND_GRANT, PEERBAND_NAME, PEERBAND_VERSION (default latest),
|
|
11
|
+
# PEERBAND_PACKAGE (tarball path or git URL; overrides the npm package).
|
|
12
|
+
# There is deliberately no param() block so that `irm | iex` works.
|
|
13
|
+
|
|
14
|
+
$ErrorActionPreference = 'Stop'
|
|
15
|
+
$pbGrant = $env:PEERBAND_GRANT
|
|
16
|
+
$pbName = $env:PEERBAND_NAME
|
|
17
|
+
$pbShowHelp = $false
|
|
18
|
+
$pbUsageError = $null
|
|
19
|
+
$pbColor = -not $env:NO_COLOR
|
|
20
|
+
$pbIsFile = [bool]$PSCommandPath
|
|
21
|
+
|
|
22
|
+
for ($i = 0; $i -lt $args.Count; $i++) {
|
|
23
|
+
switch -Regex ([string]$args[$i]) {
|
|
24
|
+
'^-{1,2}(Grant)$' { if ($i + 1 -lt $args.Count) { $pbGrant = [string]$args[++$i] } else { $pbUsageError = '-Grant needs a value' } }
|
|
25
|
+
'^-{1,2}(Name)$' { if ($i + 1 -lt $args.Count) { $pbName = [string]$args[++$i] } else { $pbUsageError = '-Name needs a value' } }
|
|
26
|
+
'^(-{1,2}(Help|h)|/\?)$' { $pbShowHelp = $true }
|
|
27
|
+
default { $pbUsageError = "unknown argument: $($args[$i])" }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function Say($Text, $Color = $null) {
|
|
32
|
+
if ($pbColor -and $Color) { Write-Host $Text -ForegroundColor $Color } else { Write-Host $Text }
|
|
33
|
+
}
|
|
34
|
+
function Fail($Message, [int]$Code = 1) {
|
|
35
|
+
[Console]::Error.WriteLine("error: $Message")
|
|
36
|
+
if ($script:pbIsFile) { exit $Code }
|
|
37
|
+
# `exit` would close the user's shell under `irm | iex`; stop the script instead.
|
|
38
|
+
throw "PeerBand installer stopped (see the error above)."
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ($pbShowHelp) {
|
|
42
|
+
Say @'
|
|
43
|
+
PeerBand installer
|
|
44
|
+
|
|
45
|
+
Usage: install.ps1 [-Name NAME] [-Grant GRANT]
|
|
46
|
+
|
|
47
|
+
By default the installer runs "peerband setup": it opens your browser to sign in, adds the
|
|
48
|
+
PeerBand plugin to Herdr, offers the PeerBand skill for your coding agents and opens the relay.
|
|
49
|
+
|
|
50
|
+
-Name NAME machine name shown in the dashboard (default: hostname)
|
|
51
|
+
-Grant GRANT headless/CI only: short-lived enrollment grant from the PeerBand dashboard,
|
|
52
|
+
used instead of the browser sign-in
|
|
53
|
+
-Help show this help
|
|
54
|
+
|
|
55
|
+
Environment: PEERBAND_GRANT, PEERBAND_NAME, PEERBAND_VERSION, PEERBAND_PACKAGE
|
|
56
|
+
'@
|
|
57
|
+
if ($pbIsFile) { exit 0 } else { return }
|
|
58
|
+
}
|
|
59
|
+
if ($pbUsageError) { Fail "install.ps1: $pbUsageError (try -Help)" 2 }
|
|
60
|
+
$env:PEERBAND_GRANT = $null
|
|
61
|
+
|
|
62
|
+
Say '==> Checking Node.js' Cyan
|
|
63
|
+
$nodeUrl = 'https://nodejs.org/en/download'
|
|
64
|
+
if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Fail "Node.js 22.13 or newer is required but was not found. Install it from $nodeUrl and re-run." }
|
|
65
|
+
$nodeRaw = ((& node --version) | Select-Object -First 1)
|
|
66
|
+
$nodeVer = $null
|
|
67
|
+
$nodeText = ([string]$nodeRaw).Trim().TrimStart('v')
|
|
68
|
+
if (-not [version]::TryParse($nodeText, [ref]$nodeVer)) { Fail "Could not read the Node.js version (got '$nodeRaw'). Install Node.js 22.13+ from $nodeUrl" }
|
|
69
|
+
if ($nodeVer -lt [version]'22.13') { Fail "Node.js $nodeVer is too old; PeerBand needs 22.13 or newer. Install it from $nodeUrl and re-run." }
|
|
70
|
+
Say " ok Node.js $nodeVer" Green
|
|
71
|
+
if (-not (Get-Command npm.cmd -ErrorAction SilentlyContinue)) { Fail "npm was not found next to Node.js. Reinstall Node.js from $nodeUrl" }
|
|
72
|
+
|
|
73
|
+
Say '==> Installing the peerband CLI' Cyan
|
|
74
|
+
$pbVersion = if ($env:PEERBAND_VERSION) { $env:PEERBAND_VERSION } else { 'latest' }
|
|
75
|
+
$pkg = if ($env:PEERBAND_PACKAGE) { $env:PEERBAND_PACKAGE } else { "peerband@$pbVersion" }
|
|
76
|
+
& npm.cmd install -g $pkg
|
|
77
|
+
if ($LASTEXITCODE -ne 0) { Fail "npm install -g $pkg failed (exit $LASTEXITCODE)." }
|
|
78
|
+
# Run the CLI this installer just put in npm's global prefix by full path, so
|
|
79
|
+
# another `peerband` earlier on PATH is never run in its place.
|
|
80
|
+
$prefix = ((& npm.cmd prefix -g) | Select-Object -First 1)
|
|
81
|
+
$pbExe = if ($prefix) { Join-Path $prefix 'peerband.cmd' } else { $null }
|
|
82
|
+
if (-not $pbExe -or -not (Test-Path $pbExe)) { Fail "peerband was installed but is missing from the npm prefix ('npm prefix -g'). Re-run the installer." }
|
|
83
|
+
$pbOnPath = Get-Command peerband -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
84
|
+
if (-not $pbOnPath) {
|
|
85
|
+
$env:PATH = "$prefix;$env:PATH"
|
|
86
|
+
Say " !! $prefix is not on your PATH. Add it under Settings > System > About > Advanced system settings > Environment Variables." Yellow
|
|
87
|
+
} elseif ([IO.Path]::GetFullPath($pbOnPath.Source) -ne [IO.Path]::GetFullPath($pbExe)) {
|
|
88
|
+
Say " !! Another peerband command comes first on your PATH: $($pbOnPath.Source)" Yellow
|
|
89
|
+
Say " Remove it, or move $prefix ahead of it in PATH, so 'peerband' runs this CLI." Yellow
|
|
90
|
+
}
|
|
91
|
+
Say ' ok peerband installed' Green
|
|
92
|
+
|
|
93
|
+
Say '==> Setting up' Cyan
|
|
94
|
+
$loginArgs = @('setup', '--herdr-plugin', 'install')
|
|
95
|
+
# Headless (grant) setup cannot ask, so it installs the agent skill; a browser setup asks first (Yes by default).
|
|
96
|
+
if ($pbGrant) { $loginArgs += @('--skill', 'install') }
|
|
97
|
+
if ($pbName) { $loginArgs += @('--name', $pbName) }
|
|
98
|
+
try {
|
|
99
|
+
if ($pbGrant) { $env:PEERBAND_GRANT = $pbGrant }
|
|
100
|
+
& $pbExe @loginArgs
|
|
101
|
+
$loginCode = $LASTEXITCODE
|
|
102
|
+
} finally {
|
|
103
|
+
$env:PEERBAND_GRANT = $null
|
|
104
|
+
$pbGrant = $null
|
|
105
|
+
}
|
|
106
|
+
if ($loginCode -ne 0) { Fail "peerband setup failed. Run 'peerband setup' again, or on a headless machine use 'peerband setup --grant GRANT' with a grant from your PeerBand dashboard." }
|
|
107
|
+
|
|
108
|
+
# `peerband setup` has already added the plugin, offered the skill and opened the relay when Herdr is present.
|
|
109
|
+
$pbHasHerdr = [bool](Get-Command herdr -ErrorAction SilentlyContinue)
|
|
110
|
+
|
|
111
|
+
Say ''
|
|
112
|
+
if ($pbHasHerdr) {
|
|
113
|
+
Say 'PeerBand is installed. Check it any time with: peerband status' Green
|
|
114
|
+
} else {
|
|
115
|
+
Say 'PeerBand is installed and logged in. Next:' Green
|
|
116
|
+
Say ' 1. Install Herdr 0.9.3 or newer: https://herdr.dev'
|
|
117
|
+
Say ' 2. peerband setup adds the Herdr plugin and opens the relay'
|
|
118
|
+
Say ' peerband status check your connection'
|
|
119
|
+
}
|
package/install/install.sh
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
# PeerBand installer.
|
|
3
3
|
# curl -fsSL https://peerband.com/install.sh | sh
|
|
4
|
-
# Installs the CLI, then runs the interactive `peerband
|
|
4
|
+
# Installs the CLI, then runs the interactive `peerband setup` (browser login, Herdr plugin, agent skill, relay).
|
|
5
5
|
# curl -fsSL https://peerband.com/install.sh | sh -s -- --grant GRANT --name NAME
|
|
6
6
|
# Headless/CI only: enroll with a dashboard grant instead of the browser.
|
|
7
7
|
# Env: PEERBAND_GRANT, PEERBAND_NAME, PEERBAND_VERSION (default latest),
|
|
@@ -24,7 +24,8 @@ PeerBand installer
|
|
|
24
24
|
|
|
25
25
|
Usage: install.sh [--name NAME] [--grant GRANT]
|
|
26
26
|
|
|
27
|
-
By default the installer runs "peerband
|
|
27
|
+
By default the installer runs "peerband setup": it opens your browser to sign in, adds the
|
|
28
|
+
PeerBand plugin to Herdr, offers the PeerBand skill for your coding agents and opens the relay.
|
|
28
29
|
|
|
29
30
|
--name NAME machine name shown in the dashboard (default: hostname)
|
|
30
31
|
--grant GRANT headless/CI only: short-lived enrollment grant from the PeerBand dashboard,
|
|
@@ -76,29 +77,29 @@ elif [ "$onpath" != "$pb" ]; then
|
|
|
76
77
|
fi
|
|
77
78
|
ok "peerband installed"
|
|
78
79
|
|
|
79
|
-
step "
|
|
80
|
+
step "Setting up"
|
|
80
81
|
if [ -n "$grant" ]; then
|
|
81
82
|
if [ -n "$name" ]; then
|
|
82
|
-
PEERBAND_GRANT=$grant "$pb"
|
|
83
|
+
PEERBAND_GRANT=$grant "$pb" setup --herdr-plugin install --skill install --name "$name" || die "peerband setup failed. Get a fresh grant from your PeerBand dashboard."
|
|
83
84
|
else
|
|
84
|
-
PEERBAND_GRANT=$grant "$pb"
|
|
85
|
+
PEERBAND_GRANT=$grant "$pb" setup --herdr-plugin install --skill install || die "peerband setup failed. Get a fresh grant from your PeerBand dashboard."
|
|
85
86
|
fi
|
|
86
87
|
else
|
|
87
88
|
# Browser sign-in. Under `curl | sh` stdin is the script itself; use the terminal instead.
|
|
88
89
|
set -- --herdr-plugin install
|
|
89
90
|
[ -z "$name" ] || set -- "$@" --name "$name"
|
|
90
91
|
if (exec </dev/tty) 2>/dev/null; then
|
|
91
|
-
"$pb"
|
|
92
|
+
"$pb" setup "$@" </dev/tty
|
|
92
93
|
else
|
|
93
|
-
"$pb"
|
|
94
|
-
fi || die "peerband
|
|
94
|
+
"$pb" setup "$@"
|
|
95
|
+
fi || die "peerband setup failed. Run 'peerband setup' again, or on a headless machine use 'peerband setup --grant GRANT' with a grant from your PeerBand dashboard."
|
|
95
96
|
fi
|
|
96
97
|
grant=''
|
|
97
98
|
|
|
98
|
-
# `peerband
|
|
99
|
+
# `peerband setup` has already added the plugin, offered the skill and opened the relay when Herdr is present.
|
|
99
100
|
if command -v herdr >/dev/null 2>&1; then
|
|
100
|
-
printf '\n%sPeerBand is
|
|
101
|
+
printf '\n%sPeerBand is installed.%s Check it any time with: peerband status\n' "$G" "$N"
|
|
101
102
|
else
|
|
102
103
|
warn "Herdr was not found. PeerBand reaches the agents you run in Herdr."
|
|
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
|
|
104
|
+
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 setup adds the Herdr plugin and opens the relay\n peerband status check your connection\n' "$G" "$N"
|
|
104
105
|
fi
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peerband",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"keywords": ["peerband", "herdr", "mcp", "coding-agents", "cli"],
|
|
11
11
|
"bin": { "peerband": "dist/peerband.mjs" },
|
|
12
12
|
"engines": { "node": ">=22.13.0" },
|
|
13
|
-
"files": ["dist/", "herdr/", "herdr-plugin.toml", "protocol/", "install/", "README.md", "LICENSE", "NOTICE", "SECURITY.md"],
|
|
13
|
+
"files": ["dist/", "herdr/", "herdr-plugin.toml", "protocol/", "install/", "skills/", "README.md", "LICENSE", "NOTICE", "SECURITY.md"],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "node scripts/build.mjs",
|
|
16
16
|
"typecheck": "tsc --noEmit",
|
package/protocol/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The `peerband` client talks to the PeerBand service over two interfaces. The ser
|
|
|
6
6
|
| --- | --- |
|
|
7
7
|
| `enrollment-redeem.schema.json` | `POST /api/enrollments/redeem`: exchange a short-lived grant (from the PeerBand dashboard) for an installation credential. `$defs`: `request`, `response`, `errorResponse`. |
|
|
8
8
|
| `device-authorization.schema.json` | Browser sign-in: `POST /api/device/code` and `POST /api/device/token` (what `peerband login` sends and receives), plus the dashboard approval endpoints. `$defs`: `codeRequest`, `codeResponse`, `tokenRequest`, `tokenResponse`, `tokenError`, `rateLimited`, `requestStatus`, `decisionResponse`. |
|
|
9
|
-
| `relay-messages.schema.json` | Every WebSocket text frame on `wss://<server>/connections`, both directions, as a `oneOf` discriminated by `type`: `request`, `ping` (server to client), `pong`, `response` (client to server). |
|
|
9
|
+
| `relay-messages.schema.json` | Every WebSocket text frame on `wss://<server>/connections`, both directions, as a `oneOf` discriminated by `type`: `request`, `ping` (server to client), `pong`, `response`, `event` (client to server). |
|
|
10
10
|
|
|
11
11
|
## Device login summary
|
|
12
12
|
|
|
@@ -22,15 +22,20 @@ The grant flow (`enrollment-redeem.schema.json`) remains available for headless
|
|
|
22
22
|
## Relay summary
|
|
23
23
|
|
|
24
24
|
1. The client opens `wss://<server>/connections` with `Authorization: Bearer <installation credential>` (never in the URL). Plain `ws://` is only accepted for loopback hosts.
|
|
25
|
-
2. The server sends `request` frames (`id`, `tool`, `args`, `principal`). The client runs them through its local policy layer (allow-lists, write opt-in, output sanitization, idempotent receipts) and answers with a `response` carrying exactly one of `result` or `error {code, message, next_step}`.
|
|
25
|
+
2. The server sends `request` frames (`id`, `tool`, `args`, `principal`). The client runs them through its local policy layer (allow-lists, write opt-in, output sanitization, idempotent receipts) and answers with a `response` carrying exactly one of `result` or `error {code, message, next_step}`. `principal` is `{id, scopes, role, email}`: `role` is `owner` or `guest` (a shared user) and `email` is the caller's account email when known. The client starts every message it delivers to an agent with a `[PeerBand relay]` line naming the sender from these fields; a missing role counts as a guest.
|
|
26
26
|
3. The server sends `ping` after 20 s of silence; the client replies `pong`. The client closes the socket with code 4000 and reconnects if it hears nothing from the server for 75 s.
|
|
27
27
|
4. Limits: 64 KiB per frame, 32 outstanding requests, 15 s per request. Requests are never replayed; a write whose response is lost is reported as `delivery_unknown`.
|
|
28
28
|
5. Close codes 4001 (replaced), 4003, 4401 (auth) and HTTP 401/403 on upgrade mean the credential is revoked or superseded: the client stops reconnecting.
|
|
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
|
+
- `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
|
+
- `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).
|
|
33
|
+
Events are metadata only and never carry terminal output. They are sent only while the socket is open; nothing is queued while disconnected.
|
|
29
34
|
|
|
30
35
|
The client only reports metadata (tool, target id, outcome, latency) to its local activity log; message bodies and agent output are never logged.
|
|
31
36
|
|
|
32
37
|
## Versioning
|
|
33
38
|
|
|
34
|
-
The protocol has no explicit version field today. Changes are additive: new optional fields
|
|
39
|
+
The protocol has no explicit version field today. Changes are additive: new optional fields, new `tool` values and new frame types may appear, so implementations must ignore unknown fields and unknown frame types on received messages. The `event` frame is such an addition: servers that do not know it ignore it, and the `x-peerband-features` upgrade header tells servers that do which clients emit events. A breaking change would use a new endpoint path or a `hello` negotiation message and be documented here with a bump of the schema `$id`. Schemas are published with each client release in `protocol/`.
|
|
35
40
|
|
|
36
41
|
The tests in `test/protocol.test.ts` validate messages produced by the real relay client against these schemas.
|
|
@@ -1,78 +1,134 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://peerband.com/schemas/relay-messages.schema.json",
|
|
4
|
-
"title": "PeerBand relay WebSocket messages",
|
|
5
|
-
"description": "Text frames (UTF-8 JSON, at most 65536 bytes) exchanged on wss://<server>/connections after the client authenticates with `Authorization: Bearer <installation credential>`. Discriminator: the `type` field. Binary frames are protocol errors.",
|
|
6
|
-
"oneOf": [
|
|
7
|
-
{ "$ref": "#/$defs/request" },
|
|
8
|
-
{ "$ref": "#/$defs/ping" },
|
|
9
|
-
{ "$ref": "#/$defs/pong" },
|
|
10
|
-
{ "$ref": "#/$defs/response" }
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
},
|
|
55
|
-
"
|
|
56
|
-
"title": "
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://peerband.com/schemas/relay-messages.schema.json",
|
|
4
|
+
"title": "PeerBand relay WebSocket messages",
|
|
5
|
+
"description": "Text frames (UTF-8 JSON, at most 65536 bytes) exchanged on wss://<server>/connections after the client authenticates with `Authorization: Bearer <installation credential>`. A client that streams agent events also sends `x-peerband-features: events` on the upgrade request. Discriminator: the `type` field. Binary frames are protocol errors; receivers ignore frame types they do not know.",
|
|
6
|
+
"oneOf": [
|
|
7
|
+
{ "$ref": "#/$defs/request" },
|
|
8
|
+
{ "$ref": "#/$defs/ping" },
|
|
9
|
+
{ "$ref": "#/$defs/pong" },
|
|
10
|
+
{ "$ref": "#/$defs/response" },
|
|
11
|
+
{ "$ref": "#/$defs/event" }
|
|
12
|
+
],
|
|
13
|
+
"$defs": {
|
|
14
|
+
"agentStatus": { "enum": ["idle", "working", "blocked", "done", "unknown"] },
|
|
15
|
+
"event": {
|
|
16
|
+
"title": "client -> server: agent event",
|
|
17
|
+
"description": "Pushed by the client when an agent changes, so MCP clients and the dashboard read output only when something happened. Metadata only: events never carry terminal output; `agent.notified` carries a short sanitized note for the machine owner. Sent only while the socket is open (never queued); after every (re)connect the client sends one `agents.changed` so consumers resync. The client coalesces bursts (at most one `agent.status_changed` per agent per 250 ms, latest wins) and caps its overall event rate. The envelope (eventId, name, timestamp, data) is shaped so it can be forwarded as MCP events later.",
|
|
18
|
+
"type": "object",
|
|
19
|
+
"required": ["type", "eventId", "name", "timestamp", "data"],
|
|
20
|
+
"properties": {
|
|
21
|
+
"type": { "const": "event" },
|
|
22
|
+
"eventId": { "type": "string", "format": "uuid", "description": "Random UUID v4, unique per event." },
|
|
23
|
+
"name": { "enum": ["agent.status_changed", "agents.changed", "agent.notified"] },
|
|
24
|
+
"timestamp": { "type": "string", "format": "date-time", "description": "When the client observed the event, ISO 8601 in UTC." },
|
|
25
|
+
"data": { "type": "object" }
|
|
26
|
+
},
|
|
27
|
+
"additionalProperties": false,
|
|
28
|
+
"oneOf": [
|
|
29
|
+
{ "properties": { "name": { "const": "agent.status_changed" }, "data": { "$ref": "#/$defs/agentStatusChanged" } } },
|
|
30
|
+
{ "properties": { "name": { "const": "agents.changed" }, "data": { "$ref": "#/$defs/agentsChanged" } } },
|
|
31
|
+
{ "properties": { "name": { "const": "agent.notified" }, "data": { "$ref": "#/$defs/agentNotified" } } }
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"agentStatusChanged": {
|
|
35
|
+
"title": "data of agent.status_changed",
|
|
36
|
+
"description": "`agentId`, `label` and `workspace` are the values list_agents reports for the agent. `previousStatus` is null when the client had not seen the agent before; `revision` is the runtime's revision counter for the agent when known.",
|
|
37
|
+
"type": "object",
|
|
38
|
+
"required": ["agentId", "status", "previousStatus", "label", "workspace", "revision"],
|
|
39
|
+
"properties": {
|
|
40
|
+
"agentId": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
41
|
+
"status": { "$ref": "#/$defs/agentStatus" },
|
|
42
|
+
"previousStatus": { "enum": ["idle", "working", "blocked", "done", "unknown", null] },
|
|
43
|
+
"label": { "type": "string" },
|
|
44
|
+
"workspace": { "type": ["string", "null"] },
|
|
45
|
+
"revision": { "type": ["integer", "null"], "minimum": 0 }
|
|
46
|
+
},
|
|
47
|
+
"additionalProperties": false
|
|
48
|
+
},
|
|
49
|
+
"agentsChanged": {
|
|
50
|
+
"title": "data of agents.changed",
|
|
51
|
+
"description": "Agents appeared, exited or changed occupant (or events may have been missed): consumers should call list_agents again.",
|
|
52
|
+
"type": "object",
|
|
53
|
+
"maxProperties": 0
|
|
54
|
+
},
|
|
55
|
+
"agentNotified": {
|
|
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`).",
|
|
58
|
+
"type": "object",
|
|
59
|
+
"required": ["agentId", "text", "audience"],
|
|
60
|
+
"properties": {
|
|
61
|
+
"agentId": { "type": ["string", "null"], "minLength": 1, "maxLength": 256 },
|
|
62
|
+
"text": { "type": "string", "minLength": 1, "maxLength": 1024 },
|
|
63
|
+
"audience": { "const": "owner" }
|
|
64
|
+
},
|
|
65
|
+
"additionalProperties": false
|
|
66
|
+
},
|
|
67
|
+
"errorBody": {
|
|
68
|
+
"type": "object",
|
|
69
|
+
"required": ["code", "message", "next_step"],
|
|
70
|
+
"additionalProperties": true,
|
|
71
|
+
"properties": {
|
|
72
|
+
"code": { "type": "string", "maxLength": 1024 },
|
|
73
|
+
"message": { "type": "string", "maxLength": 1024 },
|
|
74
|
+
"next_step": { "type": "string", "maxLength": 1024 }
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"request": {
|
|
78
|
+
"title": "server -> client: tool request",
|
|
79
|
+
"description": "At most 32 outstanding per connection; the client answers within 15 seconds. Requests are never replayed.",
|
|
80
|
+
"type": "object",
|
|
81
|
+
"required": ["type", "id", "tool", "args", "principal"],
|
|
82
|
+
"properties": {
|
|
83
|
+
"type": { "const": "request" },
|
|
84
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
85
|
+
"tool": { "enum": ["list_agents", "get_agent_status", "get_agent_output", "get_request_status", "send_agent_message"] },
|
|
86
|
+
"args": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"description": "camelCase arguments: list_agents {machine, workspace, status, cursor, limit}; get_agent_status {agentId}; get_agent_output {agentId, lines, bytes, cursor}; send_agent_message {agentId, message, idempotencyKey}; get_request_status {requestId}."
|
|
89
|
+
},
|
|
90
|
+
"principal": {
|
|
91
|
+
"type": "object",
|
|
92
|
+
"required": ["id", "scopes"],
|
|
93
|
+
"properties": {
|
|
94
|
+
"id": { "type": "string" },
|
|
95
|
+
"scopes": { "type": "array", "items": { "type": "string" } },
|
|
96
|
+
"role": { "enum": ["owner", "guest"], "description": "owner: the caller owns this machine; guest: the caller reaches it through a share. The client treats a missing or unknown role as guest when it labels delivered messages." },
|
|
97
|
+
"email": { "type": "string", "description": "The caller's account email, when the server knows it. Omitted otherwise." }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"additionalProperties": true
|
|
102
|
+
},
|
|
103
|
+
"ping": {
|
|
104
|
+
"title": "server -> client: heartbeat",
|
|
105
|
+
"description": "Sent after 20 seconds of silence. The client must answer with pong; the server closes with code 4000 if no pong arrives for 60 seconds. The client must treat any ping with extra keys as a request-shaped violation (closes 1007).",
|
|
106
|
+
"type": "object",
|
|
107
|
+
"required": ["type"],
|
|
108
|
+
"properties": { "type": { "const": "ping" } },
|
|
109
|
+
"additionalProperties": false
|
|
110
|
+
},
|
|
111
|
+
"pong": {
|
|
112
|
+
"title": "client -> server: heartbeat reply",
|
|
113
|
+
"type": "object",
|
|
114
|
+
"required": ["type"],
|
|
115
|
+
"properties": { "type": { "const": "pong" } },
|
|
116
|
+
"additionalProperties": false
|
|
117
|
+
},
|
|
118
|
+
"response": {
|
|
119
|
+
"title": "client -> server: tool response",
|
|
120
|
+
"description": "Exactly one of `result` or `error`. `id` echoes the request id.",
|
|
121
|
+
"type": "object",
|
|
122
|
+
"required": ["type", "id"],
|
|
123
|
+
"properties": {
|
|
124
|
+
"type": { "const": "response" },
|
|
125
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
126
|
+
"result": { "type": "object" },
|
|
127
|
+
"error": { "$ref": "#/$defs/errorBody" }
|
|
128
|
+
},
|
|
129
|
+
"oneOf": [{ "required": ["result"], "properties": { "result": { "type": "object" }, "error": false } }, { "required": ["error"], "properties": { "error": { "$ref": "#/$defs/errorBody" }, "result": false } }],
|
|
130
|
+
"additionalProperties": false
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"$comment": "Close codes: 1000 normal; 1007 invalid JSON/message (client); 1008 policy or duplicate request id (client); 1009 frame too large; 4000 heartbeat timeout; 4001 replaced by a newer connection for the same installation; 4401 authentication failed (also HTTP 401/403 on upgrade). The client treats 4001, 4003, 4401 and HTTP 401/403 as terminal (revoked) and stops reconnecting."
|
|
134
|
+
}
|