peerband 0.1.1 → 0.1.3
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 +18 -7
- package/SECURITY.md +3 -2
- package/dist/peerband.mjs +457 -204
- 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/package.json +1 -1
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/package.json
CHANGED