@bom0792/herdgate 0.9.16 → 0.9.18
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/app-mod/herdgate/main.js +22 -2
- package/bin/herdgate.mjs +18 -6
- package/package.json +1 -1
- package/plugin/server/index.mjs +16 -4
package/app-mod/herdgate/main.js
CHANGED
|
@@ -72,7 +72,7 @@ async function readJson(path) {
|
|
|
72
72
|
export default class Herdgate extends View {
|
|
73
73
|
init(_props, cx) {
|
|
74
74
|
this.h = cx.focus_handle();
|
|
75
|
-
this.settings = { cloud: "", root: "", name: "", accountToken: "" };
|
|
75
|
+
this.settings = { cloud: "", root: "", name: "", accountToken: "", allowAct: false };
|
|
76
76
|
this.paired = false;
|
|
77
77
|
this.cloud = "";
|
|
78
78
|
this.publisher = { pid: null, running: false };
|
|
@@ -109,7 +109,7 @@ export default class Herdgate extends View {
|
|
|
109
109
|
|
|
110
110
|
async load() {
|
|
111
111
|
const s = await readJson(SETTINGS);
|
|
112
|
-
if (s) this.settings = { cloud: s.cloud ?? "", root: s.root ?? "", name: s.name ?? "", accountToken: s.accountToken ?? "" };
|
|
112
|
+
if (s) this.settings = { cloud: s.cloud ?? "", root: s.root ?? "", name: s.name ?? "", accountToken: s.accountToken ?? "", allowAct: s.allowAct === true };
|
|
113
113
|
await this.refresh();
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -140,6 +140,21 @@ export default class Herdgate extends View {
|
|
|
140
140
|
cx?.notify?.();
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/** Flip the owner's switch for `act` (control) devices — the only way a paired
|
|
144
|
+
* device gets more than read. Takes effect on the next pair; the publisher
|
|
145
|
+
* re-reads settings on each request. */
|
|
146
|
+
async toggleAct(cx) {
|
|
147
|
+
const cur = await readJson(SETTINGS);
|
|
148
|
+
const s = { cloud: "", root: "", name: "", accountToken: "", ...(cur ?? {}), ...this.settings };
|
|
149
|
+
s.allowAct = s.allowAct !== true;
|
|
150
|
+
await sh('umask 077; printf "%s" "$2" > "$3"', [BASE, JSON.stringify(s, null, 2), SETTINGS]);
|
|
151
|
+
this.settings = s;
|
|
152
|
+
this.message = s.allowAct
|
|
153
|
+
? "act devices allowed — new pairs can control (existing devices keep their scope)"
|
|
154
|
+
: "act devices blocked — new pairs are read-only";
|
|
155
|
+
cx?.notify?.();
|
|
156
|
+
}
|
|
157
|
+
|
|
143
158
|
// ---- pairing: mint, show, poll, write the token --------------------------
|
|
144
159
|
|
|
145
160
|
pair(cx) {
|
|
@@ -507,6 +522,11 @@ export default class Herdgate extends View {
|
|
|
507
522
|
.child(field("hg-root", this.rootInput, "herdgate folder"))
|
|
508
523
|
.child(field("hg-name", this.nameInput, "this machine's name"))
|
|
509
524
|
.child(field("hg-token", this.tokenInput, "account token (owner) — used to approve other machines"))
|
|
525
|
+
.child(
|
|
526
|
+
h_flex().justify_between().items_center().gap(6).child(
|
|
527
|
+
div().text_size(10).text_color(t.dim).child("control (act) devices — let paired machines do more than read"),
|
|
528
|
+
).child(this.button(t, "hg-act", this.settings.allowAct ? "allowed" : "blocked", (c) => this.toggleAct(c))),
|
|
529
|
+
)
|
|
510
530
|
.child(
|
|
511
531
|
h_flex().justify_between().items_center().child(
|
|
512
532
|
div().text_size(9.5).text_color(t.dim).child("stored under the app's herdgate dir, mode 0600"),
|
package/bin/herdgate.mjs
CHANGED
|
@@ -154,27 +154,39 @@ function integrate(home) {
|
|
|
154
154
|
}
|
|
155
155
|
let src = readFileSync(tabs, "utf8");
|
|
156
156
|
const anchor = `.when(enabled.includes("changes"), el => el.child(panelButton("changes", "Changes", "mods/changes/changes.svg")))`;
|
|
157
|
-
|
|
157
|
+
// The exact line we insert — the idempotency marker. (An earlier build checked
|
|
158
|
+
// for a different .when(…) string and never matched, so every re-install added
|
|
159
|
+
// one more button — this marker is the inserted text itself.)
|
|
160
|
+
const inserted = `.child(panelButton("herdgate", "herdgate", "mods/herdgate/herdgate.svg"))`;
|
|
161
|
+
const marker = 'panelButton("herdgate"';
|
|
162
|
+
// Repair old duplicates first: drop every inserted line, re-add exactly one.
|
|
163
|
+
const dupes = src.split("\n").filter((l) => l.trim().startsWith(inserted)).length;
|
|
164
|
+
let dropped = false;
|
|
165
|
+
if (dupes > 1 || (dupes === 1 && src.includes(anchor))) {
|
|
166
|
+
if (dupes > 1) console.log(`herdgate: removing ${dupes - 1} duplicate button(s) from earlier installs`);
|
|
167
|
+
src = src.split("\n").filter((l) => !l.trim().startsWith(inserted)).join("\n");
|
|
168
|
+
dropped = true;
|
|
169
|
+
}
|
|
158
170
|
let changed = false;
|
|
159
|
-
if (src.includes(anchor) && !src.includes(
|
|
171
|
+
if (src.includes(anchor) && !src.includes(marker)) {
|
|
160
172
|
// Unconditional .child — no shared("workspace.panels") gate, no new imports:
|
|
161
173
|
// the button exists on every Herdr version (older apps may lack setShared).
|
|
162
|
-
src = src.replace(anchor, `${anchor}\n
|
|
174
|
+
src = src.replace(anchor, `${anchor}\n ${inserted}`);
|
|
163
175
|
src = src.replace(
|
|
164
176
|
`const enabled = shared("workspace.panels") ?? ["files", "changes"];`,
|
|
165
177
|
`const enabled = shared("workspace.panels") ?? ["files", "changes", "herdgate"];`,
|
|
166
178
|
);
|
|
167
179
|
changed = true;
|
|
168
|
-
} else if (!src.includes(
|
|
180
|
+
} else if (!src.includes(marker)) {
|
|
169
181
|
console.log("herdgate: tabs mod anchors not found (Herdr version drift?) — button not added, pane.split still works");
|
|
170
182
|
}
|
|
171
|
-
if (changed) writeFileSync(tabs, src);
|
|
183
|
+
if (dropped || changed) writeFileSync(tabs, src);
|
|
172
184
|
if (changed && !verifyTabs(home, live)) {
|
|
173
185
|
console.log("herdgate: the patched tabs clone does not load — retrying from a fresh copy");
|
|
174
186
|
cpSync(join(home, "mods", "tabs"), join(home, "mods", "tabs-herdgate"), { recursive: true });
|
|
175
187
|
const fresh = readFileSync(tabs, "utf8");
|
|
176
188
|
if (fresh.includes(anchor)) {
|
|
177
|
-
writeFileSync(tabs, fresh.replace(anchor, `${anchor}\n
|
|
189
|
+
writeFileSync(tabs, fresh.replace(anchor, `${anchor}\n ${inserted}`));
|
|
178
190
|
}
|
|
179
191
|
if (!verifyTabs(home, live)) {
|
|
180
192
|
console.log("herdgate: still no — restoring the shipped tabs mod untouched (button not added; pane.split still works)");
|
package/package.json
CHANGED
package/plugin/server/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
10
10
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
|
|
11
11
|
import { join, dirname } from "node:path";
|
|
12
|
-
import { hostname } from "node:os";
|
|
12
|
+
import { hostname, homedir } from "node:os";
|
|
13
13
|
import { dirs, readConfig, writeConfig, readState, writeState, herdrSnapshot, summarize } from "./common.mjs";
|
|
14
14
|
import { createSshBridge } from "./ssh.mjs";
|
|
15
15
|
import { HostChannel, b64d, b64e, fingerprint, generateKeyPair } from "./e2e.mjs";
|
|
@@ -17,6 +17,10 @@ import { HostChannel, b64d, b64e, fingerprint, generateKeyPair } from "./e2e.mjs
|
|
|
17
17
|
const D = dirs();
|
|
18
18
|
const NAME = process.env.HERDGATE_HOST_NAME || hostname();
|
|
19
19
|
const log = (line) => console.error(`herdgate: ${line}`);
|
|
20
|
+
/** The panel's settings file (app home herdgate dir) — the owner's switches live
|
|
21
|
+
* there. HERDGATE_SETTINGS lets tests point somewhere else. */
|
|
22
|
+
const SETTINGS =
|
|
23
|
+
process.env.HERDGATE_SETTINGS ?? join(homedir(), ".config", "herdr-app", "herdgate", "settings.json");
|
|
20
24
|
|
|
21
25
|
/** The publisher runs as a detached child of `serve`, recording its pid in state. */
|
|
22
26
|
const pidPath = D.stateDir ? join(D.stateDir, "publisher.pid") : "";
|
|
@@ -273,7 +277,10 @@ async function publisherLoop() {
|
|
|
273
277
|
wsRef = ws;
|
|
274
278
|
let helloed = false;
|
|
275
279
|
ws.onopen = () => {
|
|
276
|
-
|
|
280
|
+
// Advertise honestly: `act` only when the owner's switch allows it.
|
|
281
|
+
let allowAct = false;
|
|
282
|
+
try { allowAct = (JSON.parse(readFileSync(SETTINGS, "utf8")) ?? {}).allowAct === true; } catch { /* no settings yet */ }
|
|
283
|
+
ws.send(JSON.stringify({ v: 1, t: "hello", roomToken: token, info: { name: NAME, version: "0.1.0", capabilities: ["dev.herdgate.host", allowAct ? "act" : "read-only"] } }));
|
|
277
284
|
};
|
|
278
285
|
ws.onmessage = (ev) => {
|
|
279
286
|
void (async () => {
|
|
@@ -329,8 +336,13 @@ async function publisherLoop() {
|
|
|
329
336
|
return void replyTo({ op: "error", code: "read-only", message: `dev.herdgate.host has no op ${String(op)}` });
|
|
330
337
|
}
|
|
331
338
|
if (m.t === "pair.request") {
|
|
332
|
-
//
|
|
333
|
-
|
|
339
|
+
// `act` (control) is the owner's call, made ON THIS MACHINE: the settings'
|
|
340
|
+
// allowAct switch. Read fresh — the panel can flip it while we run.
|
|
341
|
+
let allow = false;
|
|
342
|
+
try { allow = (JSON.parse(readFileSync(SETTINGS, "utf8")) ?? {}).allowAct === true; } catch { /* not configured */ }
|
|
343
|
+
const ok = allow && m.scope === "act";
|
|
344
|
+
log(`pair request from ${m.device?.name ?? "?"} for ${m.scope}: ${ok ? "approved (allowAct)" : "denied"}`);
|
|
345
|
+
ws.send(JSON.stringify({ v: 1, t: "pair.response", requestId: m.requestId, ok }));
|
|
334
346
|
return;
|
|
335
347
|
}
|
|
336
348
|
if (m.t === "ping") ws.send(JSON.stringify({ v: 1, t: "pong", n: m.n ?? 0 }));
|