@hansenexus/hud 0.8.0 → 0.9.0
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 +42 -0
- package/dist/index.js +4 -0
- package/dist/lanes-panel-Disg54DY.js +395 -0
- package/dist/next/config.cjs +2 -0
- package/dist/next/config.d.cts +1 -0
- package/dist/next/config.d.ts +1 -0
- package/dist/next/config.js +2 -0
- package/dist/plugins/lanes/server.d.ts +165 -0
- package/dist/plugins/lanes/server.js +845 -0
- package/dist/plugins/lanes.d.ts +22 -0
- package/dist/plugins/lanes.js +30 -0
- package/dist/types-BkrkOP3h.js +6 -0
- package/dist/types-Dazn3aWZ.d.ts +86 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -475,6 +475,48 @@ export const { GET, POST } = createHudHandler([agentDispatch({ providers }), scr
|
|
|
475
475
|
- Needs `capture.screenshot`: granted in development only. A dispatch waits up to 30 s for a
|
|
476
476
|
screenshot still rendering.
|
|
477
477
|
|
|
478
|
+
## Lanes plugin (lane previews and worker feedback)
|
|
479
|
+
|
|
480
|
+
`@hansenexus/hud/plugins/lanes` makes the HUD the preview and feedback channel for agent lanes
|
|
481
|
+
on one box (hud#101): open any lane's dev server from a phone, tell the lane's worker what to
|
|
482
|
+
change, and send it a screenshot of what you see.
|
|
483
|
+
|
|
484
|
+
```tsx
|
|
485
|
+
import { lanes } from "@hansenexus/hud/plugins/lanes";
|
|
486
|
+
defineHud({ app: "my-app", plugins: [lanes()] });
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
```ts
|
|
490
|
+
import { lanes } from "@hansenexus/hud/plugins/lanes/server";
|
|
491
|
+
hud({ plugins: [lanes()] }); // or createHudHandler([lanes()])
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
The Lanes panel lists every lane folder (`~/lanes/<repo>/<lane>`, and the Orca-era
|
|
495
|
+
`~/orca/workspaces`) with repo#issue, branch, the lane's worker from the session ledger, and the
|
|
496
|
+
dev servers listening in it (`lsof`; the agent CLIs' own sockets and the ephemeral port range are
|
|
497
|
+
skipped). Each server opens on the box's tailnet name (`tailscale status`, or `HUD_PREVIEW_HOST`),
|
|
498
|
+
so the link works from any device on the tailnet. A server bound to localhost only is marked so.
|
|
499
|
+
|
|
500
|
+
- **Start** runs the lane's `dev` script (`apps/<repo>` in a monorepo named after its app, else the
|
|
501
|
+
folder a root `dev` hands over to, else the root unless it is a `turbo` fan-out) on a port from
|
|
502
|
+
3100–3999 leased with `hn-lease port:<n>`, bound to the box's tailnet IPv4 only. The lease holder
|
|
503
|
+
is the dev server's own pid, so the lease ends with the server. Next gets `--hostname`, Vite
|
|
504
|
+
`--host --strictPort`; `HUD_PREVIEW_HOST` is set so `withHud` adds the tailnet name to Next's
|
|
505
|
+
`allowedDevOrigins`, and Vite's allowed hosts get it too. A lane without `node_modules` is
|
|
506
|
+
installed first. Logs go to `<tmpdir>/hud-lanes/<lane>.log`.
|
|
507
|
+
- **This lane** (the lane the page is served from) has a comment box and a Screenshot button.
|
|
508
|
+
A comment becomes a `hud-comment` event on the session ledger (`~/.claude/sessions/events.jsonl`,
|
|
509
|
+
`sid` = the lane's worker) and is typed into the lane's terminal through
|
|
510
|
+
`lane-runtime terminal send`, the path kommandant's session mirror types answers with.
|
|
511
|
+
- **Screenshot** renders the current URL headless at the viewer's width and height (the capture
|
|
512
|
+
plugin's route, with the viewer's cookies), saves the PNG under `<tmpdir>/hud-lanes/shots`, hands
|
|
513
|
+
its path to the worker the same way, and posts it to the lane's open PR: the PNG goes up as a
|
|
514
|
+
one-file commit on the `hud-shots` branch and the comment links it by commit.
|
|
515
|
+
- Everything reads and runs on the machine the dev server runs on: mount the server half only in
|
|
516
|
+
a dev server on the lanes' box. Writes are refused cross-site; the routes answer 404 outside
|
|
517
|
+
development like every HUD route. Pass `box` to replace the machine (the playground uses an
|
|
518
|
+
in-memory one) and `capture` for the screenshot's browser.
|
|
519
|
+
|
|
478
520
|
## Routes plugin and `hud sweep`
|
|
479
521
|
|
|
480
522
|
Every page of the app's `app/` tree, one click away, and a CI sweep over the same list.
|
package/dist/index.js
CHANGED
|
@@ -422,6 +422,9 @@ function snapEdge(x, y, viewport) {
|
|
|
422
422
|
//#region src/shell/panels/panel-frame.tsx
|
|
423
423
|
/** The narrowest a floating panel renders (`.panel { min-width }`). */
|
|
424
424
|
const MIN_WIDTH = 240;
|
|
425
|
+
const MIN_HEIGHT = 160;
|
|
426
|
+
/** Room left between a floating panel and the viewport's bottom edge. */
|
|
427
|
+
const EDGE_GAP = 12;
|
|
425
428
|
const PIN_GLYPH = {
|
|
426
429
|
left: "◧",
|
|
427
430
|
right: "◨",
|
|
@@ -483,6 +486,7 @@ function PanelFrame({ title, z, viewport, position, pinned, onFocus, onClose, on
|
|
|
483
486
|
} : {
|
|
484
487
|
left: pos.x,
|
|
485
488
|
top: pos.y,
|
|
489
|
+
maxHeight: Math.max(MIN_HEIGHT, viewport.h - pos.y - EDGE_GAP),
|
|
486
490
|
zIndex: z
|
|
487
491
|
};
|
|
488
492
|
return /* @__PURE__ */ jsxs("section", {
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { n as HudApiError } from "./plugins-CcW_K7c2.js";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/plugins/lanes/styles.ts
|
|
5
|
+
/** The Lanes panel's styles, rendered in a `<style>` inside the HUD's shadow root. */
|
|
6
|
+
const LANES_CSS = `
|
|
7
|
+
.lanes { display: grid; gap: 12px; }
|
|
8
|
+
.lanes-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
9
|
+
.lanes-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
10
|
+
.lanes-muted { color: var(--hud-fg-muted); }
|
|
11
|
+
.lanes-mono { font-family: var(--hud-mono); font-size: 11px; }
|
|
12
|
+
.lanes h3 { margin: 0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hud-fg-muted); }
|
|
13
|
+
.hud .lanes-btn {
|
|
14
|
+
padding: 4px 10px;
|
|
15
|
+
min-height: 28px;
|
|
16
|
+
border: 1px solid var(--hud-border);
|
|
17
|
+
border-radius: 6px;
|
|
18
|
+
background: var(--hud-bg-subtle);
|
|
19
|
+
text-decoration: none;
|
|
20
|
+
color: inherit;
|
|
21
|
+
display: inline-flex;
|
|
22
|
+
align-items: center;
|
|
23
|
+
gap: 4px;
|
|
24
|
+
}
|
|
25
|
+
.hud .lanes-btn[data-primary] { background: var(--hud-accent); color: var(--hud-accent-fg); border-color: transparent; }
|
|
26
|
+
.hud .lanes-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
27
|
+
.lanes-here {
|
|
28
|
+
display: grid;
|
|
29
|
+
gap: 8px;
|
|
30
|
+
padding: 8px;
|
|
31
|
+
border: 1px solid var(--hud-border);
|
|
32
|
+
border-radius: 8px;
|
|
33
|
+
background: var(--hud-bg-subtle);
|
|
34
|
+
}
|
|
35
|
+
.lanes textarea {
|
|
36
|
+
font: inherit;
|
|
37
|
+
color: inherit;
|
|
38
|
+
background: var(--hud-bg);
|
|
39
|
+
border: 1px solid var(--hud-border);
|
|
40
|
+
border-radius: 6px;
|
|
41
|
+
padding: 6px 8px;
|
|
42
|
+
min-height: 64px;
|
|
43
|
+
resize: vertical;
|
|
44
|
+
}
|
|
45
|
+
.lanes-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
|
|
46
|
+
.lanes-item {
|
|
47
|
+
display: grid;
|
|
48
|
+
gap: 4px;
|
|
49
|
+
padding: 6px 8px;
|
|
50
|
+
border: 1px solid var(--hud-border);
|
|
51
|
+
border-radius: 6px;
|
|
52
|
+
}
|
|
53
|
+
.lanes-item[data-current] { border-color: var(--hud-accent); }
|
|
54
|
+
.lanes-badge {
|
|
55
|
+
flex: none;
|
|
56
|
+
padding: 0 6px;
|
|
57
|
+
border-radius: 999px;
|
|
58
|
+
border: 1px solid currentColor;
|
|
59
|
+
font-size: 10px;
|
|
60
|
+
line-height: 16px;
|
|
61
|
+
color: var(--hud-fg-muted);
|
|
62
|
+
}
|
|
63
|
+
.lanes-badge[data-state="working"] { color: var(--hud-good); }
|
|
64
|
+
.lanes-badge[data-state="waiting-human"], .lanes-badge[data-state="blocked"] { color: var(--hud-warn); }
|
|
65
|
+
.lanes-result { display: grid; gap: 2px; margin: 0; }
|
|
66
|
+
.lanes-result[data-ok="false"] { color: var(--hud-poor); }
|
|
67
|
+
.lanes-result a { color: inherit; }
|
|
68
|
+
`;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/plugins/lanes/lanes-panel.tsx
|
|
71
|
+
/** How long Start keeps refreshing while the new server comes up. */
|
|
72
|
+
const START_WATCH_MS = 9e4;
|
|
73
|
+
function errorText(error) {
|
|
74
|
+
if (error instanceof HudApiError) {
|
|
75
|
+
const body = error.body;
|
|
76
|
+
return typeof body?.error === "string" ? body.error : `HTTP ${error.status}`;
|
|
77
|
+
}
|
|
78
|
+
return error instanceof Error ? error.message : String(error);
|
|
79
|
+
}
|
|
80
|
+
/** A preview link on the box's tailnet name; without one, on the host this page came from. */
|
|
81
|
+
function previewUrl(server, host, page = location) {
|
|
82
|
+
if (host) return server.url;
|
|
83
|
+
return `${page.protocol}//${page.hostname}:${server.port}/`;
|
|
84
|
+
}
|
|
85
|
+
function viewport() {
|
|
86
|
+
return {
|
|
87
|
+
width: Math.round(window.innerWidth),
|
|
88
|
+
height: Math.round(window.innerHeight)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function Result({ result }) {
|
|
92
|
+
if (!result.ok) {
|
|
93
|
+
const notes = "notes" in result ? result.notes : [];
|
|
94
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
95
|
+
className: "lanes-result",
|
|
96
|
+
"data-ok": "false",
|
|
97
|
+
role: "status",
|
|
98
|
+
children: [/* @__PURE__ */ jsxs("span", { children: ["Failed: ", result.error] }), notes.map((n) => /* @__PURE__ */ jsx("span", {
|
|
99
|
+
className: "lanes-muted",
|
|
100
|
+
children: n
|
|
101
|
+
}, n))]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
105
|
+
className: "lanes-result",
|
|
106
|
+
"data-ok": "true",
|
|
107
|
+
role: "status",
|
|
108
|
+
children: [
|
|
109
|
+
/* @__PURE__ */ jsxs("span", { children: [result.delivered ? "Typed into the worker's terminal" : "Recorded on the ledger for the worker", result.prComment && /* @__PURE__ */ jsxs(Fragment, { children: [" · ", /* @__PURE__ */ jsx("a", {
|
|
110
|
+
href: result.prComment,
|
|
111
|
+
target: "_blank",
|
|
112
|
+
rel: "noreferrer",
|
|
113
|
+
children: "PR comment"
|
|
114
|
+
})] })] }),
|
|
115
|
+
result.ref && /* @__PURE__ */ jsx("span", {
|
|
116
|
+
className: "lanes-muted lanes-mono",
|
|
117
|
+
children: result.ref
|
|
118
|
+
}),
|
|
119
|
+
result.notes.map((n) => /* @__PURE__ */ jsx("span", {
|
|
120
|
+
className: "lanes-muted",
|
|
121
|
+
children: n
|
|
122
|
+
}, n))
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/** The comment box and Screenshot button for the lane this page is served from. */
|
|
127
|
+
function ThisLane({ lane, ctx }) {
|
|
128
|
+
const [text, setText] = useState("");
|
|
129
|
+
const [busy, setBusy] = useState(null);
|
|
130
|
+
const [result, setResult] = useState(null);
|
|
131
|
+
const [width, setWidth] = useState(() => viewport().width);
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
const onResize = () => setWidth(viewport().width);
|
|
134
|
+
window.addEventListener("resize", onResize);
|
|
135
|
+
return () => window.removeEventListener("resize", onResize);
|
|
136
|
+
}, []);
|
|
137
|
+
async function send(kind) {
|
|
138
|
+
setBusy(kind);
|
|
139
|
+
setResult(null);
|
|
140
|
+
try {
|
|
141
|
+
const body = kind === "comment" ? {
|
|
142
|
+
lane: lane.lane,
|
|
143
|
+
text,
|
|
144
|
+
url: location.href,
|
|
145
|
+
viewport: viewport()
|
|
146
|
+
} : {
|
|
147
|
+
lane: lane.lane,
|
|
148
|
+
url: location.href,
|
|
149
|
+
viewport: viewport(),
|
|
150
|
+
text
|
|
151
|
+
};
|
|
152
|
+
const res = await ctx.api(kind === "comment" ? "/comment" : "/screenshot", {
|
|
153
|
+
method: "POST",
|
|
154
|
+
headers: { "content-type": "application/json" },
|
|
155
|
+
body: JSON.stringify(body)
|
|
156
|
+
});
|
|
157
|
+
setResult(res);
|
|
158
|
+
if (res.ok) setText("");
|
|
159
|
+
} catch (error) {
|
|
160
|
+
const body = error instanceof HudApiError ? error.body : void 0;
|
|
161
|
+
setResult(body && Array.isArray(body.notes) ? {
|
|
162
|
+
ok: false,
|
|
163
|
+
delivered: false,
|
|
164
|
+
notes: body.notes,
|
|
165
|
+
error: errorText(error)
|
|
166
|
+
} : {
|
|
167
|
+
ok: false,
|
|
168
|
+
error: errorText(error)
|
|
169
|
+
});
|
|
170
|
+
} finally {
|
|
171
|
+
setBusy(null);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const worker = lane.worker;
|
|
175
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
176
|
+
className: "lanes-here",
|
|
177
|
+
"aria-label": "This lane",
|
|
178
|
+
children: [
|
|
179
|
+
/* @__PURE__ */ jsxs("div", {
|
|
180
|
+
className: "lanes-row",
|
|
181
|
+
children: [/* @__PURE__ */ jsxs("h3", {
|
|
182
|
+
className: "lanes-grow",
|
|
183
|
+
children: [
|
|
184
|
+
"This lane · ",
|
|
185
|
+
lane.repo,
|
|
186
|
+
lane.issue ? `#${lane.issue}` : ""
|
|
187
|
+
]
|
|
188
|
+
}), worker ? /* @__PURE__ */ jsxs("span", {
|
|
189
|
+
className: "lanes-badge",
|
|
190
|
+
"data-state": worker.state,
|
|
191
|
+
title: worker.sid,
|
|
192
|
+
children: ["worker ", worker.state]
|
|
193
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
194
|
+
className: "lanes-badge",
|
|
195
|
+
children: "no worker"
|
|
196
|
+
})]
|
|
197
|
+
}),
|
|
198
|
+
/* @__PURE__ */ jsx("textarea", {
|
|
199
|
+
"aria-label": "Comment for the worker",
|
|
200
|
+
placeholder: "What should change on this page?",
|
|
201
|
+
value: text,
|
|
202
|
+
onChange: (e) => setText(e.target.value)
|
|
203
|
+
}),
|
|
204
|
+
/* @__PURE__ */ jsxs("div", {
|
|
205
|
+
className: "lanes-row",
|
|
206
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
207
|
+
type: "button",
|
|
208
|
+
className: "lanes-btn",
|
|
209
|
+
"data-primary": "",
|
|
210
|
+
disabled: busy !== null || !text.trim(),
|
|
211
|
+
onClick: () => void send("comment"),
|
|
212
|
+
children: busy === "comment" ? "Sending…" : "Send to worker"
|
|
213
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
214
|
+
type: "button",
|
|
215
|
+
className: "lanes-btn",
|
|
216
|
+
disabled: busy !== null,
|
|
217
|
+
onClick: () => void send("screenshot"),
|
|
218
|
+
title: "Renders this page at your current width, posts it to the PR and hands it to the worker",
|
|
219
|
+
children: busy === "screenshot" ? "Capturing…" : `Screenshot · ${width}px`
|
|
220
|
+
})]
|
|
221
|
+
}),
|
|
222
|
+
result && /* @__PURE__ */ jsx(Result, { result })
|
|
223
|
+
]
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function LaneRow({ lane, host, starting, onStart }) {
|
|
227
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
228
|
+
className: "lanes-item",
|
|
229
|
+
"data-current": lane.current ? "" : void 0,
|
|
230
|
+
"data-lane": lane.lane,
|
|
231
|
+
children: [
|
|
232
|
+
/* @__PURE__ */ jsxs("div", {
|
|
233
|
+
className: "lanes-row",
|
|
234
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
235
|
+
className: "lanes-grow",
|
|
236
|
+
title: lane.lane,
|
|
237
|
+
children: [
|
|
238
|
+
/* @__PURE__ */ jsxs("strong", { children: [lane.repo, lane.issue ? `#${lane.issue}` : ""] }),
|
|
239
|
+
" ",
|
|
240
|
+
/* @__PURE__ */ jsx("span", {
|
|
241
|
+
className: "lanes-muted lanes-mono",
|
|
242
|
+
children: lane.lane
|
|
243
|
+
})
|
|
244
|
+
]
|
|
245
|
+
}), lane.worker && /* @__PURE__ */ jsx("span", {
|
|
246
|
+
className: "lanes-badge",
|
|
247
|
+
"data-state": lane.worker.state,
|
|
248
|
+
children: lane.worker.state
|
|
249
|
+
})]
|
|
250
|
+
}),
|
|
251
|
+
lane.branch && /* @__PURE__ */ jsx("span", {
|
|
252
|
+
className: "lanes-muted lanes-mono lanes-grow",
|
|
253
|
+
children: lane.branch
|
|
254
|
+
}),
|
|
255
|
+
/* @__PURE__ */ jsxs("div", {
|
|
256
|
+
className: "lanes-row",
|
|
257
|
+
children: [lane.servers.map((server) => server.loopback ? /* @__PURE__ */ jsxs("span", {
|
|
258
|
+
className: "lanes-muted lanes-mono",
|
|
259
|
+
title: "bound to localhost only",
|
|
260
|
+
children: [
|
|
261
|
+
":",
|
|
262
|
+
server.port,
|
|
263
|
+
" localhost only"
|
|
264
|
+
]
|
|
265
|
+
}, server.port) : /* @__PURE__ */ jsxs("a", {
|
|
266
|
+
className: "lanes-btn lanes-mono",
|
|
267
|
+
href: previewUrl(server, host),
|
|
268
|
+
target: "_blank",
|
|
269
|
+
rel: "noreferrer",
|
|
270
|
+
children: [
|
|
271
|
+
":",
|
|
272
|
+
server.port,
|
|
273
|
+
" Open ↗"
|
|
274
|
+
]
|
|
275
|
+
}, server.port)), lane.servers.length === 0 && (lane.startable ? /* @__PURE__ */ jsx("button", {
|
|
276
|
+
type: "button",
|
|
277
|
+
className: "lanes-btn",
|
|
278
|
+
disabled: starting !== void 0,
|
|
279
|
+
onClick: onStart,
|
|
280
|
+
children: starting ?? "Start"
|
|
281
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
282
|
+
className: "lanes-muted",
|
|
283
|
+
children: "no dev script"
|
|
284
|
+
}))]
|
|
285
|
+
})
|
|
286
|
+
]
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function LanesPanel({ ctx, intervalMs }) {
|
|
290
|
+
const [data, setData] = useState(null);
|
|
291
|
+
const [error, setError] = useState(null);
|
|
292
|
+
const [starting, setStarting] = useState({});
|
|
293
|
+
const [startError, setStartError] = useState(null);
|
|
294
|
+
const load = useCallback(async () => {
|
|
295
|
+
try {
|
|
296
|
+
setData(await ctx.api("/lanes"));
|
|
297
|
+
setError(null);
|
|
298
|
+
} catch (e) {
|
|
299
|
+
setError(errorText(e));
|
|
300
|
+
}
|
|
301
|
+
}, [ctx]);
|
|
302
|
+
useEffect(() => {
|
|
303
|
+
load();
|
|
304
|
+
const timer = setInterval(() => {
|
|
305
|
+
if (!document.hidden) load();
|
|
306
|
+
}, intervalMs);
|
|
307
|
+
return () => clearInterval(timer);
|
|
308
|
+
}, [load, intervalMs]);
|
|
309
|
+
const pending = Object.keys(starting).length > 0;
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
if (!pending) return;
|
|
312
|
+
const timer = setInterval(() => void load(), 3e3);
|
|
313
|
+
return () => clearInterval(timer);
|
|
314
|
+
}, [pending, load]);
|
|
315
|
+
useEffect(() => {
|
|
316
|
+
if (!data) return;
|
|
317
|
+
setStarting((s) => {
|
|
318
|
+
const left = Object.fromEntries(Object.entries(s).filter(([lane]) => !data.lanes.find((l) => l.lane === lane)?.servers.length));
|
|
319
|
+
return Object.keys(left).length === Object.keys(s).length ? s : left;
|
|
320
|
+
});
|
|
321
|
+
}, [data]);
|
|
322
|
+
async function start(lane) {
|
|
323
|
+
setStartError(null);
|
|
324
|
+
setStarting((s) => ({
|
|
325
|
+
...s,
|
|
326
|
+
[lane]: "Starting…"
|
|
327
|
+
}));
|
|
328
|
+
try {
|
|
329
|
+
const res = await ctx.api("/start", {
|
|
330
|
+
method: "POST",
|
|
331
|
+
headers: { "content-type": "application/json" },
|
|
332
|
+
body: JSON.stringify({ lane })
|
|
333
|
+
});
|
|
334
|
+
if (res.ok) {
|
|
335
|
+
setStarting((s) => ({
|
|
336
|
+
...s,
|
|
337
|
+
[lane]: `Starting on :${res.port}…`
|
|
338
|
+
}));
|
|
339
|
+
setTimeout(() => setStarting(({ [lane]: _gone, ...rest }) => rest), START_WATCH_MS);
|
|
340
|
+
}
|
|
341
|
+
} catch (e) {
|
|
342
|
+
setStartError(`${lane}: ${errorText(e)}`);
|
|
343
|
+
setStarting(({ [lane]: _gone, ...rest }) => rest);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const here = data?.lanes.find((l) => l.current);
|
|
347
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
348
|
+
className: "lanes",
|
|
349
|
+
children: [
|
|
350
|
+
/* @__PURE__ */ jsx("style", { children: LANES_CSS }),
|
|
351
|
+
here && /* @__PURE__ */ jsx(ThisLane, {
|
|
352
|
+
lane: here,
|
|
353
|
+
ctx
|
|
354
|
+
}),
|
|
355
|
+
/* @__PURE__ */ jsxs("div", {
|
|
356
|
+
className: "lanes-row",
|
|
357
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
358
|
+
className: "lanes-grow",
|
|
359
|
+
children: data ? `${data.lanes.length} lanes on ${data.host ?? "this box"}` : "Loading…"
|
|
360
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
361
|
+
type: "button",
|
|
362
|
+
className: "lanes-btn",
|
|
363
|
+
onClick: () => void load(),
|
|
364
|
+
children: "Refresh"
|
|
365
|
+
})]
|
|
366
|
+
}),
|
|
367
|
+
error && /* @__PURE__ */ jsxs("p", {
|
|
368
|
+
className: "empty",
|
|
369
|
+
children: ["Lanes unavailable: ", error]
|
|
370
|
+
}),
|
|
371
|
+
startError && /* @__PURE__ */ jsxs("p", {
|
|
372
|
+
className: "lanes-result",
|
|
373
|
+
"data-ok": "false",
|
|
374
|
+
role: "alert",
|
|
375
|
+
children: ["Start failed: ", startError]
|
|
376
|
+
}),
|
|
377
|
+
data && data.lanes.length === 0 && /* @__PURE__ */ jsx("p", {
|
|
378
|
+
className: "empty",
|
|
379
|
+
children: "No lanes on this box."
|
|
380
|
+
}),
|
|
381
|
+
data && data.lanes.length > 0 && /* @__PURE__ */ jsx("ul", {
|
|
382
|
+
className: "lanes-list",
|
|
383
|
+
"aria-label": "Lanes",
|
|
384
|
+
children: data.lanes.map((lane) => /* @__PURE__ */ jsx(LaneRow, {
|
|
385
|
+
lane,
|
|
386
|
+
host: data.host,
|
|
387
|
+
starting: starting[lane.lane],
|
|
388
|
+
onStart: () => void start(lane.lane)
|
|
389
|
+
}, lane.lane))
|
|
390
|
+
})
|
|
391
|
+
]
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
//#endregion
|
|
395
|
+
export { LanesPanel, LanesPanel as default, previewUrl };
|
package/dist/next/config.cjs
CHANGED
|
@@ -164,12 +164,14 @@ function withHud(config, options = {}) {
|
|
|
164
164
|
const webpack = base.webpack;
|
|
165
165
|
const pinned = {};
|
|
166
166
|
for (const key of HUD_PUBLIC_ENV) pinned[key] = process.env[key] ?? "";
|
|
167
|
+
const preview = process.env.HUD_PREVIEW_HOST;
|
|
167
168
|
return {
|
|
168
169
|
...base,
|
|
169
170
|
env: {
|
|
170
171
|
...pinned,
|
|
171
172
|
...base.env
|
|
172
173
|
},
|
|
174
|
+
...preview ? { allowedDevOrigins: [.../* @__PURE__ */ new Set([...base.allowedDevOrigins ?? [], preview])] } : {},
|
|
173
175
|
turbopack: {
|
|
174
176
|
...base.turbopack,
|
|
175
177
|
resolveAlias: {
|
package/dist/next/config.d.cts
CHANGED
package/dist/next/config.d.ts
CHANGED
package/dist/next/config.js
CHANGED
|
@@ -51,12 +51,14 @@ function withHud(config, options = {}) {
|
|
|
51
51
|
const webpack = base.webpack;
|
|
52
52
|
const pinned = {};
|
|
53
53
|
for (const key of HUD_PUBLIC_ENV) pinned[key] = process.env[key] ?? "";
|
|
54
|
+
const preview = process.env.HUD_PREVIEW_HOST;
|
|
54
55
|
return {
|
|
55
56
|
...base,
|
|
56
57
|
env: {
|
|
57
58
|
...pinned,
|
|
58
59
|
...base.env
|
|
59
60
|
},
|
|
61
|
+
...preview ? { allowedDevOrigins: [.../* @__PURE__ */ new Set([...base.allowedDevOrigins ?? [], preview])] } : {},
|
|
60
62
|
turbopack: {
|
|
61
63
|
...base.turbopack,
|
|
62
64
|
resolveAlias: {
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ScreenshotServerOptions } from "../capture/server.js";
|
|
2
|
+
import { a as LaneServer, c as ShotBody, i as LaneInfo, l as StartResponse, n as Delivery, o as LaneWorker, s as LanesResponse, t as CommentBody } from "../../types-Dazn3aWZ.js";
|
|
3
|
+
//#region src/plugins/lanes/box.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The box side of the `lanes` plugin: which lanes exist, which dev servers
|
|
6
|
+
* listen in them, who works in them, and how a comment or screenshot reaches
|
|
7
|
+
* that worker. `nodeBox()` is the real one; the playground and tests pass
|
|
8
|
+
* their own.
|
|
9
|
+
*/
|
|
10
|
+
interface LaneBox {
|
|
11
|
+
/** The box's tailnet name (MagicDNS), or null when unknown. */
|
|
12
|
+
host(): Promise<string | null>;
|
|
13
|
+
lanes(): Promise<LaneInfo[]>;
|
|
14
|
+
start(lane: string): Promise<StartResponse>;
|
|
15
|
+
/** Record a message for the lane's worker on the ledger and type it into its terminal. */
|
|
16
|
+
message(lane: string, message: LaneMessage): Promise<Delivery>;
|
|
17
|
+
/** Save a screenshot, hand it to the worker and post it to the lane's PR. */
|
|
18
|
+
shot(lane: string, png: Uint8Array, message: LaneMessage): Promise<Delivery>;
|
|
19
|
+
}
|
|
20
|
+
interface LaneMessage {
|
|
21
|
+
text: string;
|
|
22
|
+
url?: string;
|
|
23
|
+
viewport?: {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface ExecResult {
|
|
29
|
+
code: number;
|
|
30
|
+
stdout: string;
|
|
31
|
+
stderr: string;
|
|
32
|
+
}
|
|
33
|
+
/** Runs one command, argv only, never a shell; never throws (a missing binary is code 127). */
|
|
34
|
+
type Exec = (command: string, args: string[], options?: {
|
|
35
|
+
cwd?: string;
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
}) => Promise<ExecResult>;
|
|
38
|
+
interface LaunchOrder {
|
|
39
|
+
cwd: string;
|
|
40
|
+
port: number;
|
|
41
|
+
lane: string;
|
|
42
|
+
theme: string;
|
|
43
|
+
log: string;
|
|
44
|
+
command: string[];
|
|
45
|
+
env: Record<string, string>;
|
|
46
|
+
}
|
|
47
|
+
/** `leased`: the server is starting; `held`: the port's lease belongs to someone else. */
|
|
48
|
+
type LaunchResult = {
|
|
49
|
+
status: "leased";
|
|
50
|
+
} | {
|
|
51
|
+
status: "held";
|
|
52
|
+
} | {
|
|
53
|
+
status: "failed";
|
|
54
|
+
error: string;
|
|
55
|
+
};
|
|
56
|
+
interface NodeBoxOptions {
|
|
57
|
+
/** Lane roots, each `<root>/<repo>/<lane>`. Default `~/lanes` and the Orca-era `~/orca/workspaces`. */
|
|
58
|
+
roots?: string[];
|
|
59
|
+
/** The box's tailnet name. Default `HUD_PREVIEW_HOST`, else `tailscale status --json`. */
|
|
60
|
+
host?: string;
|
|
61
|
+
/** Address a started dev server binds to. Default the box's tailnet IPv4 (`tailscale ip -4`). */
|
|
62
|
+
bindAddress?: string;
|
|
63
|
+
/** Ports Start leases from. Default 3100–3999. */
|
|
64
|
+
ports?: [number, number];
|
|
65
|
+
/** The session ledger. Default `~/.claude/sessions`. */
|
|
66
|
+
sessionsDir?: string;
|
|
67
|
+
/** Where screenshots and start logs go. Default `<tmpdir>/hud-lanes`. */
|
|
68
|
+
stateDir?: string;
|
|
69
|
+
/** Branch that holds screenshots linked from PR comments. Default `hud-shots`. */
|
|
70
|
+
shotsBranch?: string;
|
|
71
|
+
/** This dev server's directory, to mark its own lane. Default `process.cwd()`. */
|
|
72
|
+
cwd?: string;
|
|
73
|
+
/** Home directory. Default `os.homedir()`. */
|
|
74
|
+
home?: string;
|
|
75
|
+
/** Test seams. */
|
|
76
|
+
exec?: Exec;
|
|
77
|
+
launch?: (order: LaunchOrder) => Promise<LaunchResult>;
|
|
78
|
+
now?: () => Date;
|
|
79
|
+
}
|
|
80
|
+
interface Pkg {
|
|
81
|
+
scripts?: Record<string, unknown>;
|
|
82
|
+
dependencies?: Record<string, string>;
|
|
83
|
+
devDependencies?: Record<string, string>;
|
|
84
|
+
}
|
|
85
|
+
/** `hud-issue-101-slug` → `{ repo: "hud", issue: 101 }`; a name off the pattern keeps its folder's repo. */
|
|
86
|
+
export declare function parseLaneName(name: string): {
|
|
87
|
+
repo?: string;
|
|
88
|
+
issue?: number;
|
|
89
|
+
};
|
|
90
|
+
interface Listener {
|
|
91
|
+
pid: number;
|
|
92
|
+
port: number;
|
|
93
|
+
loopback: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* `lsof -nP -iTCP -sTCP:LISTEN -Fpcn` → one entry per pid and port. Ports
|
|
97
|
+
* below 1024 or in the ephemeral range, and agent CLI processes, are dropped.
|
|
98
|
+
*/
|
|
99
|
+
export declare function parseListeners(out: string): Listener[];
|
|
100
|
+
/** `lsof -a -d cwd -p <pids> -Fpn` → pid → working directory. */
|
|
101
|
+
export declare function parseCwds(out: string): Map<number, string>;
|
|
102
|
+
interface LedgerRecord {
|
|
103
|
+
sid?: unknown;
|
|
104
|
+
lane?: unknown;
|
|
105
|
+
state?: unknown;
|
|
106
|
+
last_seen?: unknown;
|
|
107
|
+
theme?: unknown;
|
|
108
|
+
}
|
|
109
|
+
/** The newest open ledger record working in `lane`. */
|
|
110
|
+
export declare function pickWorker(records: LedgerRecord[], lane: string): {
|
|
111
|
+
sid: string;
|
|
112
|
+
state: string;
|
|
113
|
+
theme?: string;
|
|
114
|
+
} | undefined;
|
|
115
|
+
/** The first terminal handle anywhere in `lane-runtime terminal list`'s JSON (as kommandant's session-mirror reads it). */
|
|
116
|
+
export declare function firstHandle(value: unknown): string | undefined;
|
|
117
|
+
/** Arguments that put a dev script on `port` and `address`, by framework. */
|
|
118
|
+
export declare function devArgs(target: {
|
|
119
|
+
dev: string;
|
|
120
|
+
pkg: Pkg;
|
|
121
|
+
}, port: number, address: string): string[];
|
|
122
|
+
/** `bun run --cwd playground dev`, `cd web && vite`: the folder a root `dev` hands over to. */
|
|
123
|
+
export declare function delegatedDir(dev: string): string | undefined;
|
|
124
|
+
/** `bun run dev`, `pnpm run dev` or `npm run dev --`, by lockfile. */
|
|
125
|
+
export declare function runDev(files: Set<string>, extra: string[]): string[];
|
|
126
|
+
/** What the worker reads in its terminal. One line: a terminal send submits on newline. */
|
|
127
|
+
export declare function messageLine(kind: "comment" | "screenshot", m: LaneMessage, file?: string): string;
|
|
128
|
+
/** The real box: lsof, git, the session ledger, `hn-lease`, `lane-runtime` and `gh`. */
|
|
129
|
+
export declare function nodeBox(options?: NodeBoxOptions): LaneBox;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/plugins/lanes/server.d.ts
|
|
132
|
+
export interface LanesServerOptions {
|
|
133
|
+
/** Where lanes, workers and delivery come from. Default `nodeBox()`, this machine. */
|
|
134
|
+
box?: LaneBox;
|
|
135
|
+
/** Options for the headless render behind the Screenshot button (the `capture` plugin's). */
|
|
136
|
+
capture?: ScreenshotServerOptions;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Server half of `lanes`: `GET /lanes` lists the box's lanes with their dev
|
|
140
|
+
* servers and workers, `POST /start` starts a lane's dev script on a leased
|
|
141
|
+
* port, `POST /comment` hands the worker a message over the ledger, and
|
|
142
|
+
* `POST /screenshot` renders the page at the viewer's width, posts it to the
|
|
143
|
+
* lane's PR and hands it to the worker. Everything is this machine's: mount it
|
|
144
|
+
* only on a dev server that runs on the box the lanes live on.
|
|
145
|
+
*/
|
|
146
|
+
export declare function lanes({ box, capture }?: LanesServerOptions): {
|
|
147
|
+
readonly id: "lanes";
|
|
148
|
+
readonly capability: "lanes.preview";
|
|
149
|
+
readonly routes: {
|
|
150
|
+
readonly "/lanes": {
|
|
151
|
+
GET: () => Promise<Response>;
|
|
152
|
+
};
|
|
153
|
+
readonly "/start": {
|
|
154
|
+
readonly POST: (request: Request) => Promise<Response>;
|
|
155
|
+
};
|
|
156
|
+
readonly "/comment": {
|
|
157
|
+
readonly POST: (request: Request) => Promise<Response>;
|
|
158
|
+
};
|
|
159
|
+
readonly "/screenshot": {
|
|
160
|
+
readonly POST: (request: Request) => Promise<Response>;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
//#endregion
|
|
165
|
+
export type { CommentBody, Delivery, Exec, ExecResult, LaneBox, LaneInfo, LaneMessage, LaneServer, LaneWorker, LanesResponse, LaunchOrder, LaunchResult, NodeBoxOptions, ShotBody, StartResponse };
|