@bom0792/herdgate 0.9.5 → 0.9.7

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.
@@ -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/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
 
@@ -32,9 +34,8 @@ function appHome() {
32
34
  const forced = arg("app-home");
33
35
  if (forced) return forced;
34
36
  if (process.env.HERDR_APP_HOME) return process.env.HERDR_APP_HOME;
35
- const plat = process.platform;
36
- if (plat === "win32") return join(process.env.APPDATA ?? join(homedir(), "AppData", "Roaming"), "herdr-app");
37
- if (plat === "darwin") return join(homedir(), "Library", "Application Support", "herdr-app");
37
+ // herdr-app keeps the same home everywhere: ~/.config/herdr-app ("Home:" line in
38
+ // `herdr-app --help`) — Windows included.
38
39
  return join(homedir(), ".config", "herdr-app");
39
40
  }
40
41
 
@@ -82,6 +83,72 @@ function setupHost() {
82
83
  Next: open (or restart) herdr-app → herdgate panel → Pair, then approve the
83
84
  code in the PWA (${cloud}) and click Publish. Requires node >= 22 on PATH
84
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).");
85
152
  }
86
153
 
87
154
  const cmd = process.argv[2];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bom0792/herdgate",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "Cloud relay hub for herdr-core: every machine dials out, phones and browsers follow (PWA + SSH leg, E2E payloads).",
5
5
  "type": "module",
6
6
  "engines": {
Binary file