@bom0792/herdgate 0.9.6 → 0.9.8
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/herdgate.svg +6 -0
- package/app-mod/herdgate/main.js +10 -1
- package/bin/herdgate.mjs +68 -0
- package/package.json +1 -1
- package/src/web/app.js +28 -1
- package/src/web/herdgate-host.zip +0 -0
- package/src/web/index.html +6 -0
- package/src/web/sw.js +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
2
|
+
<!-- a gate: two posts, a beam, and the dot that passes through -->
|
|
3
|
+
<path d="M2.5 13.5V5.5L8 2.5l5.5 3v8"/>
|
|
4
|
+
<path d="M6 13.5v-4h4v4"/>
|
|
5
|
+
<circle cx="8" cy="7.5" r="0.9" fill="currentColor" stroke="none"/>
|
|
6
|
+
</svg>
|
package/app-mod/herdgate/main.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { View, div } from "gpui-kit";
|
|
22
22
|
import { v_flex, h_flex, InputState, Input } from "gpui-base";
|
|
23
|
-
import { exec, appHome, readTextFile, notify, theme, props } from "herdr";
|
|
23
|
+
import { exec, appHome, readTextFile, notify, theme, props, shared, setShared } from "herdr";
|
|
24
24
|
|
|
25
25
|
const BASE = `${appHome()}/herdgate`;
|
|
26
26
|
const SETTINGS = `${BASE}/settings.json`;
|
|
@@ -71,6 +71,15 @@ async function readJson(path) {
|
|
|
71
71
|
export default class Herdgate extends View {
|
|
72
72
|
init(_props, cx) {
|
|
73
73
|
this.h = cx.focus_handle();
|
|
74
|
+
// The shipped tabs mod renders its panel buttons from shared("workspace.panels")
|
|
75
|
+
// (the welcome may have fixed it to ["files","changes"] — the layout clone's new
|
|
76
|
+
// default never applies then). Self-heal: join the list once, keeping whatever
|
|
77
|
+
// the person chose.
|
|
78
|
+
{
|
|
79
|
+
const panels = shared("workspace.panels");
|
|
80
|
+
const list = Array.isArray(panels) ? panels : ["files", "changes"];
|
|
81
|
+
if (!list.includes("herdgate")) setShared("workspace.panels", [...list, "herdgate"]);
|
|
82
|
+
}
|
|
74
83
|
this.settings = { cloud: "", root: "", name: "" };
|
|
75
84
|
this.paired = false;
|
|
76
85
|
this.cloud = "";
|
package/bin/herdgate.mjs
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { cpSync, mkdirSync, writeFileSync, existsSync, readFileSync } from "node:fs";
|
|
9
9
|
import { join, dirname } from "node:path";
|
|
10
10
|
import { homedir, hostname } from "node:os";
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
11
12
|
import { fileURLToPath } from "node:url";
|
|
12
13
|
|
|
13
14
|
const HERE = dirname(fileURLToPath(import.meta.url)); // <pkg>/bin
|
|
@@ -20,6 +21,7 @@ const help = `herdgate — every machine, one herd
|
|
|
20
21
|
--cloud your gate, e.g. https://gate.phuongnb.io.vn (required)
|
|
21
22
|
--name how this machine shows up on the phone (default: hostname)
|
|
22
23
|
--app-home herdr-app home (default: the platform's usual one)
|
|
24
|
+
--no-integrate skip the tab-bar panel integration (pane.split still works)
|
|
23
25
|
|
|
24
26
|
Everything else lives in the app's herdgate panel: Pair, then Publish.`;
|
|
25
27
|
|
|
@@ -81,6 +83,72 @@ function setupHost() {
|
|
|
81
83
|
Next: open (or restart) herdr-app → herdgate panel → Pair, then approve the
|
|
82
84
|
code in the PWA (${cloud}) and click Publish. Requires node >= 22 on PATH
|
|
83
85
|
for the publisher (node -v).`);
|
|
86
|
+
if (!arg("no-integrate")) integrate(home);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ---- first-class panel: clone the main layout + tabs mod, add herdgate to both ----
|
|
90
|
+
//
|
|
91
|
+
// Shipped Herdr is read-only: the right-sidebar stack (panel-body) holds files and
|
|
92
|
+
// changes, and the tab-bar buttons for them are hardcoded in the shipped `tabs` mod.
|
|
93
|
+
// Herdr's own sanctioned escape hatch (see its AGENTS.md — and how the community
|
|
94
|
+
// gallery shares layouts) is cloning: `mod.clone` + `layout.clone` are yours and
|
|
95
|
+
// never overwritten. We clone `tabs` (one extra button) and `main` (herdgate joins
|
|
96
|
+
// panel-body), then switch to the clone. Everything is idempotent; if the anchors
|
|
97
|
+
// drift in a future Herdr, we warn and leave the app untouched — the panel still
|
|
98
|
+
// opens with `pane.split`.
|
|
99
|
+
function do_(args) {
|
|
100
|
+
const r = spawnSync("herdr-app", ["do", ...args], { encoding: "utf8" });
|
|
101
|
+
return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function integrate(home) {
|
|
105
|
+
const probe = spawnSync("herdr-app", ["status"], { encoding: "utf8" }); if (probe.status !== 0) {
|
|
106
|
+
console.log("herdgate: herdr-app not reachable — start the app, then re-run setup-host");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// 1. clone the tabs mod and add our button.
|
|
110
|
+
let tabs = join(home, "mods", "tabs-herdgate", "main.js");
|
|
111
|
+
if (!existsSync(tabs)) {
|
|
112
|
+
const c = do_(["mod.clone", JSON.stringify({ name: "tabs", as: "tabs-herdgate" })]);
|
|
113
|
+
if (!c.ok && !existsSync(tabs)) return console.log(`herdgate: could not clone tabs (${c.out.slice(0, 120)}) — panel stays reachable via pane.split`);
|
|
114
|
+
}
|
|
115
|
+
let src = readFileSync(tabs, "utf8");
|
|
116
|
+
const anchor = `.when(enabled.includes("changes"), el => el.child(panelButton("changes", "Changes", "mods/changes/changes.svg")))`;
|
|
117
|
+
const btn = `.when(enabled.includes("herdgate"), el => el.child(panelButton("herdgate", "herdgate", "mods/herdgate/herdgate.svg")))`;
|
|
118
|
+
if (src.includes(anchor) && !src.includes(btn)) {
|
|
119
|
+
src = src.replace(anchor, `${anchor}\n ${btn}`);
|
|
120
|
+
src = src.replace(`shared("workspace.panels") ?? ["files", "changes"]`, `shared("workspace.panels") ?? ["files", "changes", "herdgate"]`);
|
|
121
|
+
writeFileSync(tabs, src);
|
|
122
|
+
} else if (!src.includes(btn)) {
|
|
123
|
+
console.log("herdgate: tabs mod anchors not found (Herdr version drift?) — button not added, pane.split still works");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 2. clone the main layout, seat herdgate in panel-body, point the tab bar at the clone.
|
|
127
|
+
const layoutPath = join(home, "layouts", "herdgate-main.json");
|
|
128
|
+
if (!existsSync(layoutPath)) {
|
|
129
|
+
const c = do_(["layout.clone", JSON.stringify({ name: "main", as: "herdgate-main" })]);
|
|
130
|
+
if (!c.ok && !existsSync(layoutPath)) return console.log(`herdgate: could not clone layout (${c.out.slice(0, 120)})`);
|
|
131
|
+
}
|
|
132
|
+
const tree = JSON.parse(readFileSync(layoutPath, "utf8"));
|
|
133
|
+
const find = (n, id) => {
|
|
134
|
+
if (!n || typeof n !== "object") return null;
|
|
135
|
+
if (n.id === id) return n;
|
|
136
|
+
for (const c of n.children ?? []) { const hit = find(c, id); if (hit) return hit; }
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
const body = find(tree, "panel-body");
|
|
140
|
+
if (body) {
|
|
141
|
+
body.children ??= [];
|
|
142
|
+
if (!body.children.some((c) => c.id === "herdgate"))
|
|
143
|
+
body.children.push({ id: "herdgate", type: "block", content: { mod: "herdgate" } });
|
|
144
|
+
}
|
|
145
|
+
const tabsBlock = find(tree, "tabs");
|
|
146
|
+
if (tabsBlock?.content?.mod === "tabs") tabsBlock.content.mod = "tabs-herdgate";
|
|
147
|
+
const set = do_(["layout.set", JSON.stringify({ layout: tree })]);
|
|
148
|
+
if (!set.ok) return console.log(`herdgate: layout.set failed (${set.out.slice(0, 120)})`);
|
|
149
|
+
do_(["layout.switch", JSON.stringify({ name: "herdgate-main" })]);
|
|
150
|
+
console.log("herdgate: panel button added to the tab bar (layout herdgate-main) — press it any time;");
|
|
151
|
+
console.log(" the shipped layout `main` stays untouched (layout.switch main goes back).");
|
|
84
152
|
}
|
|
85
153
|
|
|
86
154
|
const cmd = process.argv[2];
|
package/package.json
CHANGED
package/src/web/app.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// - the token lives in localStorage on this device and is never sent anywhere but the
|
|
12
12
|
// cloud's own WS endpoint.
|
|
13
13
|
|
|
14
|
-
const BUILD = "v0.9.
|
|
14
|
+
const BUILD = "v0.9.8";
|
|
15
15
|
|
|
16
16
|
const $ = (id) => document.getElementById(id);
|
|
17
17
|
const TOKEN_KEY = "herdgate.token";
|
|
@@ -742,6 +742,33 @@ $("signin-form").addEventListener("submit", (event) => {
|
|
|
742
742
|
connect();
|
|
743
743
|
});
|
|
744
744
|
|
|
745
|
+
// Approve a new machine: the owner types the code its herdgate panel shows.
|
|
746
|
+
$("addmachine").addEventListener("submit", async (event) => {
|
|
747
|
+
event.preventDefault();
|
|
748
|
+
const code = $("addmachine-code").value.trim();
|
|
749
|
+
const noteEl = $("addmachine-note");
|
|
750
|
+
noteEl.hidden = false;
|
|
751
|
+
noteEl.className = "muted small";
|
|
752
|
+
noteEl.textContent = "approving…";
|
|
753
|
+
try {
|
|
754
|
+
const r = await fetch(`${cloudBase()}/v1/agent/approve`, {
|
|
755
|
+
method: "POST",
|
|
756
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${state.token}` },
|
|
757
|
+
body: JSON.stringify({ code }),
|
|
758
|
+
});
|
|
759
|
+
if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error ?? `HTTP ${r.status}`);
|
|
760
|
+
$("addmachine-code").value = "";
|
|
761
|
+
noteEl.textContent = "approved — the machine appears when its publisher connects";
|
|
762
|
+
// A fresh hello lists the new room (rooms come from hello).
|
|
763
|
+
state.closedByUs = true;
|
|
764
|
+
state.ws?.close();
|
|
765
|
+
connect();
|
|
766
|
+
} catch (e) {
|
|
767
|
+
noteEl.className = "error small";
|
|
768
|
+
noteEl.textContent = String(e.message ?? e);
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
|
|
745
772
|
$("menu").addEventListener("click", () => {
|
|
746
773
|
$("cloud").value = state.cloud;
|
|
747
774
|
$("settings").showModal();
|
|
Binary file
|
package/src/web/index.html
CHANGED
|
@@ -39,6 +39,12 @@
|
|
|
39
39
|
<p id="rooms-empty" class="muted" hidden>
|
|
40
40
|
No machine is paired yet. Pair one from Herdr — its plugin or app panel prints a code.
|
|
41
41
|
</p>
|
|
42
|
+
<form id="addmachine" autocomplete="off">
|
|
43
|
+
<label for="addmachine-code">Add a machine — enter the code its herdgate panel shows</label>
|
|
44
|
+
<input id="addmachine-code" type="text" inputmode="text" autocomplete="off" placeholder="pairing code" required />
|
|
45
|
+
<button type="submit">Approve</button>
|
|
46
|
+
</form>
|
|
47
|
+
<p id="addmachine-note" class="muted small" hidden></p>
|
|
42
48
|
<p id="build" class="muted small"></p>
|
|
43
49
|
</section>
|
|
44
50
|
|
package/src/web/sw.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Bump VERSION when a shell file changes; old caches are dropped on activate.
|
|
5
5
|
|
|
6
|
-
const VERSION = "herdgate-
|
|
6
|
+
const VERSION = "herdgate-v9";
|
|
7
7
|
const SHELL = ["/", "/app.css", "/e2e.js", "/app.js", "/app.webmanifest", "/icons/icon.svg"];
|
|
8
8
|
|
|
9
9
|
self.addEventListener("install", (event) => {
|