astralis-devtools 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -2,7 +2,43 @@
2
2
 
3
3
  All notable changes to `astralis-devtools`.
4
4
 
5
- ## 0.1.0 (2026-10-01)
5
+ ## 0.2.0 (2026-11-21)
6
+
7
+ Uses astralis-cli 0.6.0 and reads the prop descriptions astralis-ui 0.10.0 puts in its system spec.
8
+
9
+ ### Added
10
+
11
+ - **Every prop a component takes, on its page.** Under the props it was
12
+ given, the component's page now lists every prop the installed system spec
13
+ says it accepts: its own props first, then its style props by group (Box,
14
+ Placement, Text…). Each shows the values it takes (a long scale shows its
15
+ first few and opens to the rest), whether it is required, its description
16
+ and default where the spec has them, and the value this instance uses. A
17
+ search finds a prop by name, long spelling (`padding` finds `p`) or value.
18
+ Groups other than the first open when asked for. On a trigger wrapping a
19
+ Button, both can be listed.
20
+ - **Minimize.** The panel's header has a minimize button that folds it down
21
+ to the launcher, leaving the page free to click. The launcher's mark,
22
+ `Shift+Alt+A` or Escape from inside the panel do the same, and bringing it
23
+ back returns to the screen it was on. Whether it is open stays for the
24
+ browser tab's session, as before.
25
+
26
+ ### Changed
27
+
28
+ - `Shift+Alt+A` brings the panel back on the screen it was minimized on,
29
+ instead of on Home.
30
+ - After a report is sent, a confirmation shows **Open the issue on GitHub**
31
+ and says how to add a screenshot or a file there. No tab opens by itself.
32
+
33
+ ### Removed
34
+
35
+ - **The Report screen's screenshot.** Capturing the tab could include the
36
+ open panel itself, and GitHub's API cannot attach images anyway. Pictures
37
+ and files are added on GitHub, in the issue. The snapshot DevTools builds
38
+ no longer carries a `screenshot` field; the snapshot format still accepts
39
+ one, so snapshots filed before and `astralis report` are unchanged.
40
+
41
+ ## 0.1.0 (2026-11-19)
6
42
 
7
43
  The first release: a development overlay for Astralis UI. A launcher you can
8
44
  drag anywhere on the page opens a panel with five screens.
package/README.md CHANGED
@@ -1,82 +1,86 @@
1
- # astralis-devtools
2
-
3
- A development overlay for [Astralis UI](https://astralis-ui.com). A small
4
- launcher, which you can drag anywhere on the page, opens a panel with five
5
- screens:
6
-
7
- - **Home.** What is on the page at a glance.
8
- - **Components.** Every Astralis component on the page, grouped by kind. Each
9
- opens a page of its own: its name, the props it was given, how it reaches
10
- the browser (Server Component, client island or Client Component), where it
11
- sits, a link to its documentation, and the findings about it. This includes
12
- Server Components, which React DevTools cannot see because they never
13
- hydrate.
14
- - **Findings.** What `astralis validate` says is broken in your project, kept
15
- current as you save. On Next.js, the files that render the current page are
16
- listed first.
17
- - **Recommendations.** The validator's warnings: what works but could be
18
- better.
19
- - **Report.** Open a problem as a GitHub issue on the Astralis repository,
20
- from your own account, with an issue snapshot: the components under the one
21
- you picked with their props, the versions in use, the validator's findings
22
- and a small reproduction. You see the exact JSON first, page text is
23
- replaced by placeholders unless you include it, and nothing is sent until
24
- you press Send. **Your issues** lists the issues you have opened and where
25
- each stands.
26
-
27
- `Shift+Alt+A` opens and closes it. `Shift+Alt+C` picks a component on the page
28
- and opens its page.
29
-
30
- It runs in development only. Production builds contain none of it, and the
31
- library's production HTML carries no DevTools attributes.
32
-
33
- ## Set up
34
-
35
- ```bash
36
- npx astralis-cli init --devtools
37
- ```
38
-
39
- New projects made with `npm create astralis` have it already. To wire it by hand:
40
-
41
- **Next.js.** Add the component to the root layout:
42
-
43
- ```tsx
44
- import { AstralisDevTools } from "astralis-devtools/next";
45
-
46
- <body>
47
- {children}
48
- <AstralisDevTools />
49
- </body>
50
- ```
51
-
52
- Then add the bridge's route at `app/api/astralis-devtools/[...path]/route.ts`:
53
-
54
- ```ts
55
- export { GET, POST } from "astralis-devtools/next/route";
56
- ```
57
-
58
- **Vite.** Add the plugin:
59
-
60
- ```ts
61
- import { astralisDevtools } from "astralis-devtools/vite";
62
-
63
- export default defineConfig({ plugins: [react(), astralisDevtools()] });
64
- ```
65
-
66
- ## How it works
67
-
68
- In development, every astralis-ui component names itself on the element it
69
- renders (`data-astralis="Card.Body"`), together with the props it was
70
- configured with. The overlay reads those attributes.
71
-
72
- A small bridge runs inside your dev server. It validates your `.tsx` and
73
- `.jsx` files against the installed astralis-ui's `system-spec.json` and
74
- re-validates each file when you save it. It answers requests from your own
75
- machine only. On Next.js it is the route above, and it returns 404 in
76
- production. On Vite it is dev-server middleware that `vite build` never loads.
77
-
78
- The overlay talks only to your own dev server. The bridge talks to GitHub only for you: to sign you in with a code (through the Astralis DevTools GitHub App, which can only read and write issues on the Astralis repository), to open a report you have read and sent, and, while you are signed in, to list your issues. The token is kept in a file in your user config directory that only you can read, never in the page, and `astralis report` shares it.
79
-
80
- ## License
81
-
82
- MIT
1
+ # astralis-devtools
2
+
3
+ A development overlay for [Astralis UI](https://astralis-ui.com). A small
4
+ launcher, which you can drag anywhere on the page, opens a panel with five
5
+ screens:
6
+
7
+ - **Home.** What is on the page at a glance.
8
+ - **Components.** Every Astralis component on the page, grouped by kind. Each
9
+ opens a page of its own: its name, the props it was given, every prop it
10
+ takes with the values each accepts (searchable by name or value), how it
11
+ reaches the browser (Server Component, client island or Client Component), where it
12
+ sits, a link to its documentation, and the findings about it. This includes
13
+ Server Components, which React DevTools cannot see because they never
14
+ hydrate.
15
+ - **Findings.** What `astralis validate` says is broken in your project, kept
16
+ current as you save. On Next.js, the files that render the current page are
17
+ listed first.
18
+ - **Recommendations.** The validator's warnings: what works but could be
19
+ better.
20
+ - **Report.** Open a problem as a GitHub issue on the Astralis repository,
21
+ from your own account, with an issue snapshot: the components under the one
22
+ you picked with their props, the versions in use, the validator's findings
23
+ and a small reproduction. You see the exact JSON first, page text is
24
+ replaced by placeholders unless you include it, and nothing is sent until
25
+ you press Send. To add a screenshot or a file, open the issue on GitHub
26
+ once it is created and drop it in there. **Your issues** lists the issues
27
+ you have opened and where each stands.
28
+
29
+ The minimize button in the panel's header, `Shift+Alt+A`, or Escape from
30
+ inside the panel fold it down to the launcher, so the page is free to use; the
31
+ launcher or `Shift+Alt+A` brings it back where it was. `Shift+Alt+C` picks a
32
+ component on the page and opens its page.
33
+
34
+ It runs in development only. Production builds contain none of it, and the
35
+ library's production HTML carries no DevTools attributes.
36
+
37
+ ## Set up
38
+
39
+ ```bash
40
+ npx astralis-cli init --devtools
41
+ ```
42
+
43
+ New projects made with `npm create astralis` have it already. To wire it by hand:
44
+
45
+ **Next.js.** Add the component to the root layout:
46
+
47
+ ```tsx
48
+ import { AstralisDevTools } from "astralis-devtools/next";
49
+
50
+ <body>
51
+ {children}
52
+ <AstralisDevTools />
53
+ </body>
54
+ ```
55
+
56
+ Then add the bridge's route at `app/api/astralis-devtools/[...path]/route.ts`:
57
+
58
+ ```ts
59
+ export { GET, POST } from "astralis-devtools/next/route";
60
+ ```
61
+
62
+ **Vite.** Add the plugin:
63
+
64
+ ```ts
65
+ import { astralisDevtools } from "astralis-devtools/vite";
66
+
67
+ export default defineConfig({ plugins: [react(), astralisDevtools()] });
68
+ ```
69
+
70
+ ## How it works
71
+
72
+ In development, every astralis-ui component names itself on the element it
73
+ renders (`data-astralis="Card.Body"`), together with the props it was
74
+ configured with. The overlay reads those attributes.
75
+
76
+ A small bridge runs inside your dev server. It validates your `.tsx` and
77
+ `.jsx` files against the installed astralis-ui's `system-spec.json` and
78
+ re-validates each file when you save it. It answers requests from your own
79
+ machine only. On Next.js it is the route above, and it returns 404 in
80
+ production. On Vite it is dev-server middleware that `vite build` never loads.
81
+
82
+ The overlay talks only to your own dev server. The bridge talks to GitHub only for you: to sign you in with a code (through the Astralis DevTools GitHub App, which can only read and write issues on the Astralis repository), to open a report you have read and sent, and, while you are signed in, to list your issues. The token is kept in a file in your user config directory that only you can read, never in the page, and `astralis report` shares it.
83
+
84
+ ## License
85
+
86
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astralis-devtools",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Development overlay for Astralis UI: inspect any component on the page (Server Components included) and see the validator's findings live as you edit. Next.js and Vite.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  "node": "^22.18.0 || >=24.11.0"
49
49
  },
50
50
  "dependencies": {
51
- "astralis-cli": "^0.5.0"
51
+ "astralis-cli": "^0.6.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "react": "^19.1.1"
@@ -1,194 +1,194 @@
1
- import { bridgeFor } from "./bridge.mjs";
2
- import { githubSession } from "./github.mjs";
3
- import { assembleSnapshot } from "./snapshot.mjs";
4
-
5
- /* The bridge over HTTP, in web-standard Request/Response so the Next.js
6
- route handler and the Vite middleware share it. Mounted at BASE_PATH:
7
-
8
- GET info versions of astralis-ui (with the spec's SHA-256), the framework and React
9
- GET spec the installed system spec, for the component pages
10
- GET findings the validator's findings for the project
11
- GET events the same findings as a server-sent event stream, re-sent on every change
12
- GET route-files ?path=/about: the files that render that page (Next.js)
13
- POST snapshot the page's part of an issue snapshot in; the complete snapshot out
14
- POST submit a snapshot the reporter confirmed, opened as a GitHub issue;
15
- ?addTo=12 adds it to that existing issue instead
16
- GET github the GitHub sign-in: set up or not, who, and a code to enter
17
- POST github/sign-in start signing in with a code (the bridge polls GitHub)
18
- POST github/sign-out forget the saved sign-in
19
- GET github/issues the issues the signed-in user opened on the Astralis repository
20
- POST github/similar a snapshot in; the issues that may already report it out
21
- POST github/link a snapshot in; GitHub's own new-issue form, filled in, out
22
-
23
- It answers the local machine only, and nothing at all in production. The
24
- POST routes take JSON only: a page on another site cannot send that type
25
- without a preflight the bridge never grants. The GitHub token never leaves
26
- the bridge: the page sees the login, never the token. */
27
-
28
- export const BASE_PATH = "/api/astralis-devtools";
29
-
30
- const KEEPALIVE_MS = 15_000;
31
- /** A snapshot is at most 256 kB; the page's part, with a screenshot, stays well under this. */
32
- const MAX_BODY_BYTES = 1024 * 1024;
33
- const LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
34
-
35
- const json = (body, status = 200) =>
36
- new Response(JSON.stringify(body), {
37
- status,
38
- headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
39
- });
40
-
41
- /**
42
- * A request from this machine: addressed to a loopback host and, when a page
43
- * sent it, from a loopback page. A dev server opened to the network
44
- * (`next dev -H 0.0.0.0`) still refuses the bridge to other machines, and a
45
- * page on another site cannot read it by pointing a DNS name at 127.0.0.1.
46
- */
47
- export function isLocal(request) {
48
- const hostname = (value) => {
49
- try {
50
- return new URL(value).hostname;
51
- } catch {
52
- return null;
53
- }
54
- };
55
- const host = request.headers.get("host");
56
- if (!host || !LOOPBACK.has(hostname(`http://${host}`))) return false;
57
- const origin = request.headers.get("origin");
58
- return origin === null || LOOPBACK.has(hostname(origin));
59
- }
60
-
61
- /** The path after BASE_PATH, e.g. "findings". */
62
- function route(url) {
63
- const at = url.pathname.indexOf(BASE_PATH);
64
- const rest = at === -1 ? url.pathname : url.pathname.slice(at + BASE_PATH.length);
65
- return rest.replace(/^\/+|\/+$/g, "");
66
- }
67
-
68
- function eventStream(bridge, signal) {
69
- const encoder = new TextEncoder();
70
- let stop = () => {};
71
- const stream = new ReadableStream({
72
- start(controller) {
73
- const send = (text) => {
74
- try {
75
- controller.enqueue(encoder.encode(text));
76
- } catch {
77
- stop();
78
- }
79
- };
80
- const publish = (findings) => send(`event: findings\ndata: ${JSON.stringify(findings)}\n\n`);
81
- const unlisten = bridge.listen(publish);
82
- const keepalive = setInterval(() => send(": keepalive\n\n"), KEEPALIVE_MS);
83
- stop = () => {
84
- unlisten();
85
- clearInterval(keepalive);
86
- try {
87
- controller.close();
88
- } catch {
89
- // already closed by the client
90
- }
91
- };
92
- signal?.addEventListener("abort", stop, { once: true });
93
- publish(bridge.findings());
94
- },
95
- cancel() {
96
- stop();
97
- },
98
- });
99
- return new Response(stream, {
100
- headers: {
101
- "content-type": "text/event-stream; charset=utf-8",
102
- "cache-control": "no-store, no-transform",
103
- connection: "keep-alive",
104
- "x-accel-buffering": "no",
105
- },
106
- });
107
- }
108
-
109
- /**
110
- * Answer one request. `root` is the project directory, `framework` "next" or
111
- * "vite"; `watch` optionally replaces fs.watch (Vite passes its own watcher).
112
- */
113
- /** The JSON body of a POST, or a Response explaining why it cannot be read. */
114
- async function readJson(request) {
115
- if (!/^application\/json\b/i.test(request.headers.get("content-type") ?? "")) {
116
- return json({ error: "Send JSON (content-type: application/json)." }, 415);
117
- }
118
- const declared = Number(request.headers.get("content-length") ?? 0);
119
- if (declared > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
120
- const text = await request.text();
121
- if (text.length > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
122
- try {
123
- return { body: JSON.parse(text) };
124
- } catch {
125
- return json({ error: "The request is not valid JSON." }, 400);
126
- }
127
- }
128
-
129
- /** A GitHub failure as a response: 401 when the reporter has to sign in (again). */
130
- const githubFailure = (error) =>
131
- json({ error: error.message, code: error.code ?? "github" }, error.code === "signed-out" ? 401 : error.code === "invalid" ? 400 : 502);
132
-
133
- const POSTS = new Set(["snapshot", "submit", "github/sign-in", "github/sign-out", "github/similar", "github/link"]);
134
-
135
- async function handlePost(bridge, path, request, github, url) {
136
- if (!POSTS.has(path)) return json({ error: "Not found." }, 404);
137
- const read = await readJson(request);
138
- if (read instanceof Response) return read;
139
- try {
140
- if (path === "github/sign-in") return json(await github.signIn());
141
- if (path === "github/sign-out") return json(github.signOut());
142
- if (path === "github/similar") return json(await github.similar(read.body));
143
- if (path === "github/link") return json(github.link(read.body));
144
- } catch (error) {
145
- return githubFailure(error);
146
- }
147
- if (bridge.problem) return json({ error: bridge.problem }, 409);
148
- if (path === "snapshot") return json(assembleSnapshot(bridge, read.body));
149
- const addTo = url.searchParams.has("addTo") ? Number(url.searchParams.get("addTo")) : null;
150
- if (addTo !== null && !(Number.isInteger(addTo) && addTo > 0)) return json({ error: "addTo takes an issue number." }, 400);
151
- try {
152
- return json(await github.submit(read.body, { addTo }));
153
- } catch (error) {
154
- return githubFailure(error);
155
- }
156
- }
157
-
158
- export async function handle(request, { root = process.cwd(), framework, watch, github = githubSession() } = {}) {
159
- if (process.env.NODE_ENV === "production") return new Response(null, { status: 404 });
160
- if (!isLocal(request)) return json({ error: "The Astralis DevTools bridge answers this machine only." }, 403);
161
- if (request.method !== "GET" && request.method !== "POST") return json({ error: "Method not allowed." }, 405);
162
-
163
- const bridge = bridgeFor(root, framework, { watch });
164
- await bridge.start();
165
- const url = new URL(request.url);
166
- if (request.method === "POST") return handlePost(bridge, route(url), request, github, url);
167
-
168
- switch (route(url)) {
169
- case "info":
170
- return bridge.problem ? json({ problem: bridge.problem }) : json(bridge.info);
171
- case "spec":
172
- return bridge.problem
173
- ? json({ problem: bridge.problem }, 404)
174
- : new Response(bridge.specText, {
175
- headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
176
- });
177
- case "findings":
178
- return json(bridge.findings());
179
- case "events":
180
- return eventStream(bridge, request.signal);
181
- case "github":
182
- return json(github.status());
183
- case "github/issues":
184
- try {
185
- return json({ issues: await github.issues() });
186
- } catch (error) {
187
- return githubFailure(error);
188
- }
189
- case "route-files":
190
- return json({ path: url.searchParams.get("path") ?? "/", files: bridge.routeFiles(url.searchParams.get("path") ?? "/") });
191
- default:
192
- return json({ error: "Not found." }, 404);
193
- }
194
- }
1
+ import { bridgeFor } from "./bridge.mjs";
2
+ import { githubSession } from "./github.mjs";
3
+ import { assembleSnapshot } from "./snapshot.mjs";
4
+
5
+ /* The bridge over HTTP, in web-standard Request/Response so the Next.js
6
+ route handler and the Vite middleware share it. Mounted at BASE_PATH:
7
+
8
+ GET info versions of astralis-ui (with the spec's SHA-256), the framework and React
9
+ GET spec the installed system spec, for the component pages
10
+ GET findings the validator's findings for the project
11
+ GET events the same findings as a server-sent event stream, re-sent on every change
12
+ GET route-files ?path=/about: the files that render that page (Next.js)
13
+ POST snapshot the page's part of an issue snapshot in; the complete snapshot out
14
+ POST submit a snapshot the reporter confirmed, opened as a GitHub issue;
15
+ ?addTo=12 adds it to that existing issue instead
16
+ GET github the GitHub sign-in: set up or not, who, and a code to enter
17
+ POST github/sign-in start signing in with a code (the bridge polls GitHub)
18
+ POST github/sign-out forget the saved sign-in
19
+ GET github/issues the issues the signed-in user opened on the Astralis repository
20
+ POST github/similar a snapshot in; the issues that may already report it out
21
+ POST github/link a snapshot in; GitHub's own new-issue form, filled in, out
22
+
23
+ It answers the local machine only, and nothing at all in production. The
24
+ POST routes take JSON only: a page on another site cannot send that type
25
+ without a preflight the bridge never grants. The GitHub token never leaves
26
+ the bridge: the page sees the login, never the token. */
27
+
28
+ export const BASE_PATH = "/api/astralis-devtools";
29
+
30
+ const KEEPALIVE_MS = 15_000;
31
+ /** A snapshot is at most 256 kB; the page's part stays well under this. */
32
+ const MAX_BODY_BYTES = 1024 * 1024;
33
+ const LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
34
+
35
+ const json = (body, status = 200) =>
36
+ new Response(JSON.stringify(body), {
37
+ status,
38
+ headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
39
+ });
40
+
41
+ /**
42
+ * A request from this machine: addressed to a loopback host and, when a page
43
+ * sent it, from a loopback page. A dev server opened to the network
44
+ * (`next dev -H 0.0.0.0`) still refuses the bridge to other machines, and a
45
+ * page on another site cannot read it by pointing a DNS name at 127.0.0.1.
46
+ */
47
+ export function isLocal(request) {
48
+ const hostname = (value) => {
49
+ try {
50
+ return new URL(value).hostname;
51
+ } catch {
52
+ return null;
53
+ }
54
+ };
55
+ const host = request.headers.get("host");
56
+ if (!host || !LOOPBACK.has(hostname(`http://${host}`))) return false;
57
+ const origin = request.headers.get("origin");
58
+ return origin === null || LOOPBACK.has(hostname(origin));
59
+ }
60
+
61
+ /** The path after BASE_PATH, e.g. "findings". */
62
+ function route(url) {
63
+ const at = url.pathname.indexOf(BASE_PATH);
64
+ const rest = at === -1 ? url.pathname : url.pathname.slice(at + BASE_PATH.length);
65
+ return rest.replace(/^\/+|\/+$/g, "");
66
+ }
67
+
68
+ function eventStream(bridge, signal) {
69
+ const encoder = new TextEncoder();
70
+ let stop = () => {};
71
+ const stream = new ReadableStream({
72
+ start(controller) {
73
+ const send = (text) => {
74
+ try {
75
+ controller.enqueue(encoder.encode(text));
76
+ } catch {
77
+ stop();
78
+ }
79
+ };
80
+ const publish = (findings) => send(`event: findings\ndata: ${JSON.stringify(findings)}\n\n`);
81
+ const unlisten = bridge.listen(publish);
82
+ const keepalive = setInterval(() => send(": keepalive\n\n"), KEEPALIVE_MS);
83
+ stop = () => {
84
+ unlisten();
85
+ clearInterval(keepalive);
86
+ try {
87
+ controller.close();
88
+ } catch {
89
+ // already closed by the client
90
+ }
91
+ };
92
+ signal?.addEventListener("abort", stop, { once: true });
93
+ publish(bridge.findings());
94
+ },
95
+ cancel() {
96
+ stop();
97
+ },
98
+ });
99
+ return new Response(stream, {
100
+ headers: {
101
+ "content-type": "text/event-stream; charset=utf-8",
102
+ "cache-control": "no-store, no-transform",
103
+ connection: "keep-alive",
104
+ "x-accel-buffering": "no",
105
+ },
106
+ });
107
+ }
108
+
109
+ /**
110
+ * Answer one request. `root` is the project directory, `framework` "next" or
111
+ * "vite"; `watch` optionally replaces fs.watch (Vite passes its own watcher).
112
+ */
113
+ /** The JSON body of a POST, or a Response explaining why it cannot be read. */
114
+ async function readJson(request) {
115
+ if (!/^application\/json\b/i.test(request.headers.get("content-type") ?? "")) {
116
+ return json({ error: "Send JSON (content-type: application/json)." }, 415);
117
+ }
118
+ const declared = Number(request.headers.get("content-length") ?? 0);
119
+ if (declared > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
120
+ const text = await request.text();
121
+ if (text.length > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
122
+ try {
123
+ return { body: JSON.parse(text) };
124
+ } catch {
125
+ return json({ error: "The request is not valid JSON." }, 400);
126
+ }
127
+ }
128
+
129
+ /** A GitHub failure as a response: 401 when the reporter has to sign in (again). */
130
+ const githubFailure = (error) =>
131
+ json({ error: error.message, code: error.code ?? "github" }, error.code === "signed-out" ? 401 : error.code === "invalid" ? 400 : 502);
132
+
133
+ const POSTS = new Set(["snapshot", "submit", "github/sign-in", "github/sign-out", "github/similar", "github/link"]);
134
+
135
+ async function handlePost(bridge, path, request, github, url) {
136
+ if (!POSTS.has(path)) return json({ error: "Not found." }, 404);
137
+ const read = await readJson(request);
138
+ if (read instanceof Response) return read;
139
+ try {
140
+ if (path === "github/sign-in") return json(await github.signIn());
141
+ if (path === "github/sign-out") return json(github.signOut());
142
+ if (path === "github/similar") return json(await github.similar(read.body));
143
+ if (path === "github/link") return json(github.link(read.body));
144
+ } catch (error) {
145
+ return githubFailure(error);
146
+ }
147
+ if (bridge.problem) return json({ error: bridge.problem }, 409);
148
+ if (path === "snapshot") return json(assembleSnapshot(bridge, read.body));
149
+ const addTo = url.searchParams.has("addTo") ? Number(url.searchParams.get("addTo")) : null;
150
+ if (addTo !== null && !(Number.isInteger(addTo) && addTo > 0)) return json({ error: "addTo takes an issue number." }, 400);
151
+ try {
152
+ return json(await github.submit(read.body, { addTo }));
153
+ } catch (error) {
154
+ return githubFailure(error);
155
+ }
156
+ }
157
+
158
+ export async function handle(request, { root = process.cwd(), framework, watch, github = githubSession() } = {}) {
159
+ if (process.env.NODE_ENV === "production") return new Response(null, { status: 404 });
160
+ if (!isLocal(request)) return json({ error: "The Astralis DevTools bridge answers this machine only." }, 403);
161
+ if (request.method !== "GET" && request.method !== "POST") return json({ error: "Method not allowed." }, 405);
162
+
163
+ const bridge = bridgeFor(root, framework, { watch });
164
+ await bridge.start();
165
+ const url = new URL(request.url);
166
+ if (request.method === "POST") return handlePost(bridge, route(url), request, github, url);
167
+
168
+ switch (route(url)) {
169
+ case "info":
170
+ return bridge.problem ? json({ problem: bridge.problem }) : json(bridge.info);
171
+ case "spec":
172
+ return bridge.problem
173
+ ? json({ problem: bridge.problem }, 404)
174
+ : new Response(bridge.specText, {
175
+ headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
176
+ });
177
+ case "findings":
178
+ return json(bridge.findings());
179
+ case "events":
180
+ return eventStream(bridge, request.signal);
181
+ case "github":
182
+ return json(github.status());
183
+ case "github/issues":
184
+ try {
185
+ return json({ issues: await github.issues() });
186
+ } catch (error) {
187
+ return githubFailure(error);
188
+ }
189
+ case "route-files":
190
+ return json({ path: url.searchParams.get("path") ?? "/", files: bridge.routeFiles(url.searchParams.get("path") ?? "/") });
191
+ default:
192
+ return json({ error: "Not found." }, 404);
193
+ }
194
+ }