@bom0792/herdgate 0.9.9 → 0.9.10
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/gpui-kit.d.ts +22762 -0
- package/app-mod/herdgate/jsconfig.json +32 -0
- package/app-mod/herdgate/main.js +165 -37
- package/package.json +1 -1
- package/src/web/herdgate-host.zip +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"// why": [
|
|
3
|
+
"Written once by gpui-shell, then yours: an existing jsconfig.json or",
|
|
4
|
+
"tsconfig.json is never replaced, and this file is not rewritten.",
|
|
5
|
+
"",
|
|
6
|
+
"`moduleResolution` is how a bare specifier is answered. Left to be",
|
|
7
|
+
"inferred it can still land on the resolution that never looks in",
|
|
8
|
+
"node_modules, and a Git dependency the runtime resolves fine is",
|
|
9
|
+
"underlined as a module the editor cannot find.",
|
|
10
|
+
"",
|
|
11
|
+
"`lib` decides which globals exist. The default hands a script the",
|
|
12
|
+
"browser's — a `console`, a `localStorage`, a `Window` this runtime does",
|
|
13
|
+
"not have — and their declarations collide with the ones gpui-kit.d.ts makes,",
|
|
14
|
+
"so the file describing the API is itself reported as the error.",
|
|
15
|
+
"",
|
|
16
|
+
"`strictNullChecks` is off, and this one is the runtime's shape rather than",
|
|
17
|
+
"a preference. A view assigns its state in `init`, which TypeScript cannot",
|
|
18
|
+
"see as definite assignment the way it sees a constructor, so every field",
|
|
19
|
+
"would read as possibly-undefined and every use would want a `?.` that",
|
|
20
|
+
"means nothing at run time. Turning it on would buy noise, not safety."
|
|
21
|
+
],
|
|
22
|
+
"compilerOptions": {
|
|
23
|
+
"target": "ES2022",
|
|
24
|
+
"module": "ES2022",
|
|
25
|
+
"moduleResolution": "bundler",
|
|
26
|
+
"lib": ["ES2022"],
|
|
27
|
+
"checkJs": true,
|
|
28
|
+
"strict": true,
|
|
29
|
+
"strictNullChecks": false,
|
|
30
|
+
"noEmit": true
|
|
31
|
+
}
|
|
32
|
+
}
|
package/app-mod/herdgate/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// herdgate for the Herdr app — a docked panel that pairs this machine to a herdgate
|
|
2
|
-
// cloud and
|
|
2
|
+
// cloud, publishes it, and (as the owner) approves other machines joining the herd.
|
|
3
3
|
//
|
|
4
4
|
// Official mod surface only (docs/mods.md, defaults/AGENTS.md "### UI" and
|
|
5
5
|
// "### The `herdr` module"):
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// - `herdr-app check <mod folder>` loads it once and reports errors.
|
|
12
12
|
//
|
|
13
13
|
// Division of labour: this panel owns the pairing conversation (mint a code with
|
|
14
|
-
// `fetch`, poll it, write the room token)
|
|
14
|
+
// `fetch`, poll it, write the room token), the owner conversation (approve another
|
|
15
|
+
// machine's code with the account token), and delegates long-lived publishing to the
|
|
15
16
|
// same publisher the TUI plugin ships (`<root>/plugin/server/index.mjs serve`).
|
|
16
17
|
// One implementation, two surfaces.
|
|
17
18
|
//
|
|
@@ -71,16 +72,7 @@ async function readJson(path) {
|
|
|
71
72
|
export default class Herdgate extends View {
|
|
72
73
|
init(_props, cx) {
|
|
73
74
|
this.h = cx.focus_handle();
|
|
74
|
-
|
|
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
|
-
}
|
|
83
|
-
this.settings = { cloud: "", root: "", name: "" };
|
|
75
|
+
this.settings = { cloud: "", root: "", name: "", accountToken: "" };
|
|
84
76
|
this.paired = false;
|
|
85
77
|
this.cloud = "";
|
|
86
78
|
this.publisher = { pid: null, running: false };
|
|
@@ -89,11 +81,24 @@ export default class Herdgate extends View {
|
|
|
89
81
|
this.pending = null; // { code, url, expiresAt } while a code is waiting
|
|
90
82
|
this.phase = "idle"; // idle | waiting | saving | error
|
|
91
83
|
this.message = "";
|
|
84
|
+
this.busy = { pair: false, publish: false, approve: false, save: false };
|
|
92
85
|
this.notified = false;
|
|
93
86
|
|
|
94
87
|
this.cloudInput = InputState.new({ placeholder: "https://herd.example.com" });
|
|
95
|
-
this.rootInput = InputState.new({ placeholder: "
|
|
88
|
+
this.rootInput = InputState.new({ placeholder: "set by `npx @bom0792/herdgate setup-host`" });
|
|
96
89
|
this.nameInput = InputState.new({ placeholder: "this-machine" });
|
|
90
|
+
this.tokenInput = InputState.new({ placeholder: "account token — only for approving other machines" });
|
|
91
|
+
this.codeInput = InputState.new({ placeholder: "the code its panel shows" });
|
|
92
|
+
|
|
93
|
+
// The shipped tabs mod renders its panel buttons from shared("workspace.panels")
|
|
94
|
+
// (the welcome may have fixed it to ["files","changes"] — the layout clone's new
|
|
95
|
+
// default never applies then). Self-heal: join the list once, keeping whatever
|
|
96
|
+
// the person chose.
|
|
97
|
+
{
|
|
98
|
+
const panels = shared("workspace.panels");
|
|
99
|
+
const list = Array.isArray(panels) ? panels : ["files", "changes"];
|
|
100
|
+
if (!list.includes("herdgate")) setShared("workspace.panels", [...list, "herdgate"]);
|
|
101
|
+
}
|
|
97
102
|
|
|
98
103
|
cx.spawn(async (cx) => {
|
|
99
104
|
await this.load();
|
|
@@ -111,7 +116,7 @@ export default class Herdgate extends View {
|
|
|
111
116
|
|
|
112
117
|
async load() {
|
|
113
118
|
const s = await readJson(SETTINGS);
|
|
114
|
-
if (s) this.settings = { cloud: s.cloud ?? "", root: s.root ?? "", name: s.name ?? "" };
|
|
119
|
+
if (s) this.settings = { cloud: s.cloud ?? "", root: s.root ?? "", name: s.name ?? "", accountToken: s.accountToken ?? "" };
|
|
115
120
|
await this.refresh();
|
|
116
121
|
}
|
|
117
122
|
|
|
@@ -131,25 +136,29 @@ export default class Herdgate extends View {
|
|
|
131
136
|
const cloud = (this.cloudInput.value() ?? "").trim().replace(/\/$/, "");
|
|
132
137
|
const root = (this.rootInput.value() ?? "").trim().replace(/\/$/, "");
|
|
133
138
|
const name = (this.nameInput.value() ?? "").trim();
|
|
134
|
-
|
|
139
|
+
const accountToken = (this.tokenInput.value() ?? "").trim() || this.settings.accountToken;
|
|
140
|
+
this.busy.save = true;
|
|
141
|
+
this.settings = { cloud, root, name, accountToken };
|
|
135
142
|
const body = JSON.stringify(this.settings, null, 2);
|
|
136
143
|
await sh('umask 077; mkdir -p "$1"; printf "%s" "$2" > "$3"', [BASE, body, SETTINGS]);
|
|
137
144
|
await this.refresh();
|
|
138
|
-
this.
|
|
145
|
+
this.busy.save = false;
|
|
146
|
+
this.message = cloud ? "settings saved" : "a cloud URL is required";
|
|
139
147
|
cx?.notify?.();
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
// ---- pairing: mint, show, poll, write the token --------------------------
|
|
143
151
|
|
|
144
152
|
pair(cx) {
|
|
145
|
-
if (this.
|
|
153
|
+
if (this.busy.pair) return;
|
|
146
154
|
const cloud = (this.settings.cloud || this.cloudInput.value() || "").replace(/\/$/, "");
|
|
147
155
|
if (!cloud) {
|
|
148
156
|
this.phase = "error";
|
|
149
|
-
this.message = "set the herdgate cloud URL first";
|
|
157
|
+
this.message = "set the herdgate cloud URL first (Settings below)";
|
|
150
158
|
cx?.notify?.();
|
|
151
159
|
return;
|
|
152
160
|
}
|
|
161
|
+
this.busy.pair = true;
|
|
153
162
|
this.phase = "waiting";
|
|
154
163
|
this.message = "asking the cloud for a code…";
|
|
155
164
|
cx?.notify?.();
|
|
@@ -163,12 +172,14 @@ export default class Herdgate extends View {
|
|
|
163
172
|
if (!res.ok) throw new Error(`the cloud answered HTTP ${res.status}`);
|
|
164
173
|
const minted = await res.json();
|
|
165
174
|
this.pending = { code: minted.code, url: minted.url, expiresAt: Date.now() + (minted.expiresIn ?? 600) * 1000 };
|
|
166
|
-
this.message = "approve
|
|
175
|
+
this.message = "waiting for approve — open the dashboard, or another herdgate panel";
|
|
167
176
|
this.notified = false;
|
|
177
|
+
this.busy.pair = false;
|
|
168
178
|
cx.notify();
|
|
169
179
|
this.poll(cx, cloud, minted.code);
|
|
170
180
|
} catch (e) {
|
|
171
181
|
this.phase = "error";
|
|
182
|
+
this.busy.pair = false;
|
|
172
183
|
this.message = e instanceof Error ? e.message : String(e);
|
|
173
184
|
cx.notify();
|
|
174
185
|
}
|
|
@@ -225,6 +236,43 @@ export default class Herdgate extends View {
|
|
|
225
236
|
cx.notify();
|
|
226
237
|
}
|
|
227
238
|
|
|
239
|
+
// ---- approving ANOTHER machine (owner action, no terminal needed) --------
|
|
240
|
+
|
|
241
|
+
approveOther(cx) {
|
|
242
|
+
if (this.busy.approve) return;
|
|
243
|
+
const cloud = (this.settings.cloud || this.cloudInput.value() || "").replace(/\/$/, "");
|
|
244
|
+
const token = (this.tokenInput.value() ?? "").trim() || this.settings.accountToken;
|
|
245
|
+
const code = (this.codeInput.value() ?? "").trim();
|
|
246
|
+
if (!cloud || !token || !code) {
|
|
247
|
+
this.phase = "error";
|
|
248
|
+
this.message = !cloud ? "set the cloud URL first" : !token ? "paste your account token (Settings)" : "enter the code the other machine shows";
|
|
249
|
+
cx?.notify?.();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
this.busy.approve = true;
|
|
253
|
+
this.message = "approving…";
|
|
254
|
+
cx?.notify?.();
|
|
255
|
+
cx.spawn(async (cx) => {
|
|
256
|
+
try {
|
|
257
|
+
const res = await fetch(`${cloud}/v1/agent/approve`, {
|
|
258
|
+
method: "POST",
|
|
259
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
|
|
260
|
+
body: JSON.stringify({ code }),
|
|
261
|
+
});
|
|
262
|
+
const body = await res.json().catch(() => ({}));
|
|
263
|
+
if (!res.ok) throw new Error(body.error ?? `the cloud answered HTTP ${res.status}`);
|
|
264
|
+
this.phase = "idle";
|
|
265
|
+
this.message = `approved “${body.name ?? code}” — it appears here once its publisher connects`;
|
|
266
|
+
notify({ title: "herdgate", body: `Machine “${body.name ?? code}” joined the herd.`, level: "success" });
|
|
267
|
+
} catch (e) {
|
|
268
|
+
this.phase = "error";
|
|
269
|
+
this.message = e instanceof Error ? e.message : String(e);
|
|
270
|
+
}
|
|
271
|
+
this.busy.approve = false;
|
|
272
|
+
cx.notify();
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
228
276
|
// ---- publishing: delegate to the shared herdgate publisher ---------------
|
|
229
277
|
|
|
230
278
|
publisherPath() {
|
|
@@ -245,13 +293,15 @@ export default class Herdgate extends View {
|
|
|
245
293
|
cx.notify();
|
|
246
294
|
return;
|
|
247
295
|
}
|
|
248
|
-
this.
|
|
296
|
+
this.busy.publish = true;
|
|
297
|
+
this.message = "starting publisher…";
|
|
249
298
|
cx.notify();
|
|
250
299
|
cx.spawn(async (cx) => {
|
|
251
300
|
const found = await sh('[ -f "$1" ] && command -v node >/dev/null && printf yes', [index]);
|
|
252
301
|
if (found?.stdout !== "yes") {
|
|
253
302
|
this.phase = "error";
|
|
254
|
-
this.
|
|
303
|
+
this.busy.publish = false;
|
|
304
|
+
this.message = `needs node on PATH and ${index}`;
|
|
255
305
|
cx.notify();
|
|
256
306
|
return;
|
|
257
307
|
}
|
|
@@ -264,7 +314,8 @@ export default class Herdgate extends View {
|
|
|
264
314
|
cx.timer.after(1_200, (cx) => {
|
|
265
315
|
cx.spawn(async (cx) => {
|
|
266
316
|
await this.refresh();
|
|
267
|
-
this.
|
|
317
|
+
this.busy.publish = false;
|
|
318
|
+
this.message = this.publisher.running ? "publisher started — this machine is live on the gate" : "the publisher did not start (see state/publisher.log)";
|
|
268
319
|
this.phase = this.publisher.running ? "idle" : "error";
|
|
269
320
|
cx.notify();
|
|
270
321
|
});
|
|
@@ -273,10 +324,12 @@ export default class Herdgate extends View {
|
|
|
273
324
|
}
|
|
274
325
|
|
|
275
326
|
stopPublisher(cx) {
|
|
327
|
+
this.busy.publish = true;
|
|
276
328
|
cx.spawn(async (cx) => {
|
|
277
329
|
if (this.publisher.pid) await sh('kill "$1" 2>/dev/null; true', [String(this.publisher.pid)]);
|
|
278
330
|
await sh('rm -f "$1"', [PID_FILE]);
|
|
279
331
|
await this.refresh();
|
|
332
|
+
this.busy.publish = false;
|
|
280
333
|
this.message = "publisher stopped";
|
|
281
334
|
cx.notify();
|
|
282
335
|
});
|
|
@@ -293,6 +346,8 @@ export default class Herdgate extends View {
|
|
|
293
346
|
.child(div().text_size(11.5).text_color(t.dim).child(label))
|
|
294
347
|
.child(div().flex_1().truncate().text_size(12).text_color(color ?? t.foreground).child(value));
|
|
295
348
|
|
|
349
|
+
const section = (label) => div().mt(2).text_size(9.5).font_semibold().text_color(t.dim).child(label);
|
|
350
|
+
|
|
296
351
|
return v_flex()
|
|
297
352
|
.id("herdgate-panel")
|
|
298
353
|
.track_focus(this.h)
|
|
@@ -314,8 +369,8 @@ export default class Herdgate extends View {
|
|
|
314
369
|
.rounded(5)
|
|
315
370
|
.text_size(10.5)
|
|
316
371
|
.bg(t.background)
|
|
317
|
-
.text_color(this.
|
|
318
|
-
.child(this.paired ? "paired" : "not paired"),
|
|
372
|
+
.text_color(this.publisher.running ? t.working : this.paired ? t.dim : t.muted)
|
|
373
|
+
.child(this.publisher.running ? "live" : this.paired ? "paired" : "not paired"),
|
|
319
374
|
),
|
|
320
375
|
)
|
|
321
376
|
.child(line("cloud", this.cloud || "—"))
|
|
@@ -328,9 +383,33 @@ export default class Herdgate extends View {
|
|
|
328
383
|
.child(`${this.lastPublish.summary.workspaces} spaces · ${this.lastPublish.summary.agents} agents · ${this.lastPublish.summary.herdr}`),
|
|
329
384
|
),
|
|
330
385
|
)
|
|
331
|
-
|
|
386
|
+
// The status banner: one place that always says what just happened or what is
|
|
387
|
+
// expected next. Colored by phase so "did my click do anything?" has an answer.
|
|
388
|
+
.child(
|
|
389
|
+
v_flex()
|
|
390
|
+
.id("hg-status")
|
|
391
|
+
.min_h(30)
|
|
392
|
+
.justify_center()
|
|
393
|
+
.px(8)
|
|
394
|
+
.py(4)
|
|
395
|
+
.rounded(6)
|
|
396
|
+
.bg(t.background)
|
|
397
|
+
.child(
|
|
398
|
+
div()
|
|
399
|
+
.text_size(11.5)
|
|
400
|
+
.text_color(this.phase === "error" ? t.accent : this.phase === "waiting" ? t.working : t.dim)
|
|
401
|
+
.child(
|
|
402
|
+
this.busy.pair || this.busy.publish || this.busy.approve || this.busy.save
|
|
403
|
+
? (this.message || "working…") + " ⏳"
|
|
404
|
+
: this.message || "ready — Pair this machine, or approve another one below",
|
|
405
|
+
),
|
|
406
|
+
),
|
|
407
|
+
)
|
|
408
|
+
.child(section("THIS MACHINE"))
|
|
332
409
|
.child(this.pairingBlock(t, cx))
|
|
333
|
-
.child(
|
|
410
|
+
.child(section("ADD ANOTHER MACHINE"))
|
|
411
|
+
.child(this.approveBlock(t, cx))
|
|
412
|
+
.child(section("SETTINGS"))
|
|
334
413
|
.child(this.settingsBlock(t, cx));
|
|
335
414
|
}
|
|
336
415
|
|
|
@@ -342,14 +421,58 @@ export default class Herdgate extends View {
|
|
|
342
421
|
.child(div().text_size(11.5).text_color(t.muted).child("approve in your dashboard"))
|
|
343
422
|
.child(div().text_size(22).font_semibold().text_color(t.accent).child(this.pending.code.replace(/^(.{4})/, "$1 ")))
|
|
344
423
|
.child(div().text_size(10.5).text_color(t.dim).truncate().child(this.pending.url ?? ""))
|
|
345
|
-
.child(
|
|
424
|
+
.child(
|
|
425
|
+
h_flex().gap(6).child(this.button(t, "hg-cancel", "Cancel", (cx2) => this.cancel(cx2), { enabled: !this.busy.pair })),
|
|
426
|
+
);
|
|
346
427
|
}
|
|
347
428
|
return h_flex()
|
|
348
429
|
.id("hg-actions")
|
|
349
430
|
.gap(6)
|
|
350
|
-
.child(
|
|
351
|
-
|
|
352
|
-
|
|
431
|
+
.child(
|
|
432
|
+
this.button(t, "hg-pair", this.busy.pair ? "pairing…" : this.paired ? "Pair again" : "Pair", (cx2) => this.pair(cx2), {
|
|
433
|
+
primary: true,
|
|
434
|
+
enabled: !this.busy.pair && !this.busy.save,
|
|
435
|
+
}),
|
|
436
|
+
)
|
|
437
|
+
.child(
|
|
438
|
+
this.button(t, "hg-publish", this.busy.publish ? "starting…" : "Publish", (cx2) => this.startPublisher(cx2), {
|
|
439
|
+
enabled: this.paired && !this.publisher.running && !this.busy.publish,
|
|
440
|
+
}),
|
|
441
|
+
)
|
|
442
|
+
.child(
|
|
443
|
+
this.button(t, "hg-stop", "Stop", (cx2) => this.stopPublisher(cx2), {
|
|
444
|
+
enabled: this.publisher.running && !this.busy.publish,
|
|
445
|
+
}),
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
approveBlock(t, cx) {
|
|
450
|
+
return v_flex()
|
|
451
|
+
.id("hg-approve")
|
|
452
|
+
.gap(5)
|
|
453
|
+
.child(div().text_size(10.5).text_color(t.dim).child("on the other machine's herdgate panel, press Pair and type its code here"))
|
|
454
|
+
.child(
|
|
455
|
+
h_flex()
|
|
456
|
+
.gap(6)
|
|
457
|
+
.child(
|
|
458
|
+
Input.new(this.codeInput)
|
|
459
|
+
.id("hg-code-input")
|
|
460
|
+
.flex_1()
|
|
461
|
+
.h(28)
|
|
462
|
+
.px(8)
|
|
463
|
+
.items_center()
|
|
464
|
+
.rounded(6)
|
|
465
|
+
.border(1)
|
|
466
|
+
.border_color(t.input)
|
|
467
|
+
.bg(t.background)
|
|
468
|
+
.text_size(11.5)
|
|
469
|
+
.text_color(t.foreground),
|
|
470
|
+
)
|
|
471
|
+
.child(this.button(t, "hg-approve", this.busy.approve ? "approving…" : "Approve", (cx2) => this.approveOther(cx2), {
|
|
472
|
+
primary: true,
|
|
473
|
+
enabled: !this.busy.approve,
|
|
474
|
+
})),
|
|
475
|
+
);
|
|
353
476
|
}
|
|
354
477
|
|
|
355
478
|
settingsBlock(t, cx) {
|
|
@@ -377,27 +500,32 @@ export default class Herdgate extends View {
|
|
|
377
500
|
.child(field("hg-cloud", this.cloudInput, "cloud URL"))
|
|
378
501
|
.child(field("hg-root", this.rootInput, "herdgate folder"))
|
|
379
502
|
.child(field("hg-name", this.nameInput, "this machine's name"))
|
|
503
|
+
.child(field("hg-token", this.tokenInput, "account token (owner) — used to approve other machines"))
|
|
380
504
|
.child(
|
|
381
505
|
h_flex().justify_between().items_center().child(
|
|
382
|
-
div().text_size(9.5).text_color(t.dim).child("
|
|
383
|
-
).child(this.button(t, "hg-save", "
|
|
506
|
+
div().text_size(9.5).text_color(t.dim).child("stored under the app's herdgate dir, mode 0600"),
|
|
507
|
+
).child(this.button(t, "hg-save", this.busy.save ? "saving…" : "Save", (c) => this.saveSettings(c), { enabled: !this.busy.save })),
|
|
384
508
|
);
|
|
385
509
|
}
|
|
386
510
|
|
|
387
|
-
button(t, id, label,
|
|
511
|
+
button(t, id, label, onClick, opts = {}) {
|
|
512
|
+
const { primary = false, enabled = true } = opts;
|
|
513
|
+
const bg = primary ? t.solid : t.input;
|
|
514
|
+
const fg = primary ? t.solid_foreground : t.foreground;
|
|
388
515
|
return h_flex()
|
|
389
516
|
.id(id)
|
|
390
|
-
.h(
|
|
391
|
-
.px(
|
|
517
|
+
.h(28)
|
|
518
|
+
.px(12)
|
|
392
519
|
.items_center()
|
|
393
520
|
.rounded(6)
|
|
394
521
|
.bg(bg)
|
|
395
522
|
.text_color(fg)
|
|
396
523
|
.text_size(11.5)
|
|
397
524
|
.when(!enabled, (el) => el.opacity(0.4))
|
|
525
|
+
.when(enabled, (el) => el.hover((s) => s.bg(primary ? bg : t.hover)))
|
|
398
526
|
.cursor_pointer()
|
|
399
|
-
.on_click((_e,
|
|
400
|
-
if (enabled) onClick(
|
|
527
|
+
.on_click((_e, c) => {
|
|
528
|
+
if (enabled) onClick(c);
|
|
401
529
|
})
|
|
402
530
|
.child(label);
|
|
403
531
|
}
|
package/package.json
CHANGED
|
Binary file
|