uplink-cli 0.1.38 → 0.1.39

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.
Files changed (54) hide show
  1. package/AGENTS.md +161 -0
  2. package/LICENSE +21 -0
  3. package/README.md +46 -47
  4. package/cli/src/index.ts +5 -3
  5. package/cli/src/registrars/cloudflare.ts +148 -0
  6. package/cli/src/registrars/godaddy.ts +99 -0
  7. package/cli/src/registrars/hostinger.ts +106 -0
  8. package/cli/src/registrars/http.ts +18 -0
  9. package/cli/src/registrars/index.ts +30 -0
  10. package/cli/src/registrars/namecheap.ts +163 -0
  11. package/cli/src/registrars/secret.ts +66 -0
  12. package/cli/src/registrars/store.ts +55 -0
  13. package/cli/src/registrars/types.ts +40 -0
  14. package/cli/src/subcommands/admin.ts +17 -30
  15. package/cli/src/subcommands/db.ts +63 -57
  16. package/cli/src/subcommands/dev.ts +23 -25
  17. package/cli/src/subcommands/domains.ts +268 -0
  18. package/cli/src/subcommands/host-domains.ts +148 -0
  19. package/cli/src/subcommands/host.ts +3 -0
  20. package/cli/src/subcommands/menu/colors.ts +1 -1
  21. package/cli/src/subcommands/menu/effects/tunnel-clients.ts +87 -14
  22. package/cli/src/subcommands/menu/inline-tree-select.ts +6 -5
  23. package/cli/src/subcommands/menu/io.ts +27 -5
  24. package/cli/src/subcommands/menu/menus/domains.ts +199 -0
  25. package/cli/src/subcommands/menu/menus/hosting.ts +14 -46
  26. package/cli/src/subcommands/menu/menus/index.ts +1 -0
  27. package/cli/src/subcommands/menu/menus/tunnels.ts +25 -67
  28. package/cli/src/subcommands/menu/render.ts +2 -2
  29. package/cli/src/subcommands/menu/tests.ts +1 -1
  30. package/cli/src/subcommands/menu/tunnels.ts +10 -99
  31. package/cli/src/subcommands/menu/types.ts +8 -0
  32. package/cli/src/subcommands/menu.ts +32 -524
  33. package/cli/src/subcommands/system.ts +58 -36
  34. package/cli/src/subcommands/tunnel.ts +124 -33
  35. package/cli/src/templates/index.ts +3 -3
  36. package/cli/src/tui/App.tsx +197 -0
  37. package/cli/src/tui/AppInspector.tsx +114 -0
  38. package/cli/src/tui/HomeStatus.tsx +59 -0
  39. package/cli/src/tui/brand.tsx +20 -0
  40. package/cli/src/tui/format.ts +22 -0
  41. package/cli/src/tui/index.mts +6 -0
  42. package/cli/src/tui/liveTree.ts +40 -0
  43. package/cli/src/tui/package.json +3 -0
  44. package/cli/src/tui/runMenu.tsx +57 -0
  45. package/cli/src/tui/session.mts +382 -0
  46. package/cli/src/tui/snapshot.ts +146 -0
  47. package/cli/src/utils/launchDomainking.ts +64 -0
  48. package/docs/AGENTS.md +113 -147
  49. package/docs/MENU_STRUCTURE.md +56 -288
  50. package/docs/README.md +6 -6
  51. package/package.json +18 -35
  52. package/scripts/tunnel/client-improved.js +127 -38
  53. package/scripts/tunnel/client.js +118 -0
  54. package/assets/cli-screenshot.png +0 -0
@@ -1,6 +1,11 @@
1
1
  import { Command } from "commander";
2
2
  import { apiRequest } from "../http";
3
3
  import { handleError, printJson } from "../utils/machine";
4
+ import {
5
+ findTunnelClients,
6
+ killTunnelClient,
7
+ startTunnelClient,
8
+ } from "./menu/effects/tunnel-clients";
4
9
 
5
10
  type TunnelResponse = {
6
11
  id: string;
@@ -9,10 +14,13 @@ type TunnelResponse = {
9
14
  port?: number;
10
15
  token?: string;
11
16
  alias?: string | null;
17
+ aliasUrl?: string | null;
12
18
  status?: string;
19
+ connected?: boolean;
13
20
  createdAt?: string;
14
21
  updatedAt?: string;
15
22
  ingressHttpUrl?: string;
23
+ targetPort?: number;
16
24
  };
17
25
 
18
26
  type TunnelListResponse = {
@@ -22,16 +30,18 @@ type TunnelListResponse = {
22
30
 
23
31
  type TunnelStatsResponse = any;
24
32
 
25
- export const tunnelCommand = new Command("tunnel")
26
- .description("Manage tunnels non-interactively (agent-friendly)");
33
+ export const tunnelCommand = new Command("tunnel").description(
34
+ "Manage tunnels non-interactively (agent-friendly)"
35
+ );
27
36
 
28
- // Create tunnel
37
+ // Create tunnel + start local client (unless --no-client)
29
38
  tunnelCommand
30
39
  .command("create")
31
- .description("Create a tunnel")
40
+ .description("Create a tunnel and start the local client")
32
41
  .requiredOption("--port <port>", "Local port to expose")
33
42
  .option("--alias <alias>", "Optional permanent alias (if enabled on account)")
34
43
  .option("--project <project>", "Optional project id")
44
+ .option("--api-only", "Create API record only; do not start the local client", false)
35
45
  .option("--json", "Output JSON", false)
36
46
  .action(async (opts) => {
37
47
  const port = Number(opts.port);
@@ -41,42 +51,75 @@ tunnelCommand
41
51
  }
42
52
 
43
53
  try {
54
+ const existing = findTunnelClients().filter((c) => c.port === port);
55
+ if (existing.length > 0 && !opts.apiOnly) {
56
+ const err = `Tunnel client already running on port ${port} (pid ${existing[0].pid})`;
57
+ if (opts.json) {
58
+ printJson({ error: err, existing: existing[0] });
59
+ } else {
60
+ console.error(err);
61
+ }
62
+ process.exit(2);
63
+ }
64
+
44
65
  const body: Record<string, unknown> = { port };
45
66
  if (opts.project) body.project = opts.project;
46
67
 
47
- const tunnel = await apiRequest("POST", "/v1/tunnels", body) as TunnelResponse;
68
+ const tunnel = (await apiRequest("POST", "/v1/tunnels", body)) as TunnelResponse;
48
69
  let aliasResult: TunnelResponse | null = null;
49
70
  let aliasError: string | null = null;
50
71
 
51
72
  if (opts.alias) {
52
73
  try {
53
- aliasResult = await apiRequest("POST", `/v1/tunnels/${tunnel.id}/alias`, {
74
+ aliasResult = (await apiRequest("POST", `/v1/tunnels/${tunnel.id}/alias`, {
54
75
  alias: opts.alias,
55
- }) as TunnelResponse;
76
+ })) as TunnelResponse;
56
77
  } catch (err: any) {
57
78
  aliasError = err?.message || String(err);
58
79
  }
59
80
  }
60
81
 
82
+ let client: { pid: number; started: boolean } | null = null;
83
+ if (!opts.apiOnly) {
84
+ const token = tunnel.token;
85
+ if (!token) {
86
+ throw new Error("Tunnel created but API returned no token; cannot start client");
87
+ }
88
+ const started = startTunnelClient({ token, port });
89
+ // Brief wait so list/connected is more likely accurate for agents.
90
+ await new Promise((resolve) => setTimeout(resolve, 1500));
91
+ client = { pid: started.pid, started: true };
92
+ }
93
+
94
+ const url =
95
+ aliasResult?.aliasUrl ||
96
+ aliasResult?.url ||
97
+ tunnel.url ||
98
+ tunnel.ingressHttpUrl ||
99
+ null;
100
+ const alias = aliasResult?.alias ?? tunnel.alias ?? null;
101
+
61
102
  if (opts.json) {
62
103
  printJson({
63
- tunnel,
64
- alias: aliasResult?.alias ?? null,
104
+ tunnel: {
105
+ ...tunnel,
106
+ alias,
107
+ aliasUrl: aliasResult?.aliasUrl ?? tunnel.aliasUrl ?? null,
108
+ url: tunnel.url ?? tunnel.ingressHttpUrl,
109
+ },
110
+ alias,
65
111
  aliasError,
112
+ url,
113
+ client,
66
114
  });
67
115
  } else {
68
116
  console.log(`Created tunnel ${tunnel.id}`);
69
- console.log(` url: ${tunnel.url ?? tunnel.ingressHttpUrl ?? "-"}`);
70
- console.log(` token: ${tunnel.token ?? "-"}`);
71
- if (opts.alias) {
72
- if (aliasResult?.alias) {
73
- console.log(` alias: ${aliasResult.alias}`);
74
- } else if (aliasError) {
75
- console.log(` alias: failed - ${aliasError}`);
76
- }
77
- } else if (tunnel.alias) {
78
- console.log(` alias: ${tunnel.alias}`);
79
- }
117
+ console.log(` url: ${url ?? "-"}`);
118
+ console.log(` token: ${tunnel.token ?? "-"}`);
119
+ if (alias) console.log(` alias: ${alias}`);
120
+ else if (aliasError) console.log(` alias: failed - ${aliasError}`);
121
+ if (client) console.log(` client: started (pid ${client.pid})`);
122
+ else console.log(` client: not started (--api-only)`);
80
123
  }
81
124
  } catch (error) {
82
125
  handleError(error, { json: opts.json });
@@ -90,7 +133,7 @@ tunnelCommand
90
133
  .option("--json", "Output JSON", false)
91
134
  .action(async (opts) => {
92
135
  try {
93
- const result = await apiRequest("GET", "/v1/tunnels") as TunnelListResponse;
136
+ const result = (await apiRequest("GET", "/v1/tunnels")) as TunnelListResponse;
94
137
  if (opts.json) {
95
138
  printJson(result);
96
139
  } else {
@@ -100,8 +143,10 @@ tunnelCommand
100
143
  }
101
144
  console.log(`Tunnels (${result.count}):`);
102
145
  for (const t of result.tunnels) {
146
+ const connected = t.connected ? "connected" : "idle";
147
+ const token = t.token ? `${String(t.token).slice(0, 8)}…` : "-";
103
148
  console.log(
104
- `${t.id} ${t.url ?? t.ingressHttpUrl ?? "-"} token=${t.token ?? "-"} alias=${t.alias ?? "-"} status=${t.status ?? "-"}`
149
+ `${t.id} ${t.url ?? t.ingressHttpUrl ?? "-"} token=${token} alias=${t.alias ?? "-"} status=${t.status ?? "-"} ${connected}`
105
150
  );
106
151
  }
107
152
  }
@@ -119,9 +164,9 @@ tunnelCommand
119
164
  .option("--json", "Output JSON", false)
120
165
  .action(async (opts) => {
121
166
  try {
122
- const result = await apiRequest("POST", `/v1/tunnels/${opts.id}/alias`, {
167
+ const result = (await apiRequest("POST", `/v1/tunnels/${opts.id}/alias`, {
123
168
  alias: opts.alias,
124
- }) as TunnelResponse;
169
+ })) as TunnelResponse;
125
170
  if (opts.json) {
126
171
  printJson(result);
127
172
  } else {
@@ -140,7 +185,10 @@ tunnelCommand
140
185
  .option("--json", "Output JSON", false)
141
186
  .action(async (opts) => {
142
187
  try {
143
- const result = await apiRequest("DELETE", `/v1/tunnels/${opts.id}/alias`) as TunnelResponse;
188
+ const result = (await apiRequest(
189
+ "DELETE",
190
+ `/v1/tunnels/${opts.id}/alias`
191
+ )) as TunnelResponse;
144
192
  if (opts.json) {
145
193
  printJson(result);
146
194
  } else {
@@ -159,7 +207,10 @@ tunnelCommand
159
207
  .option("--json", "Output JSON", false)
160
208
  .action(async (opts) => {
161
209
  try {
162
- const result = await apiRequest("GET", `/v1/tunnels/${opts.id}/stats`) as TunnelStatsResponse;
210
+ const result = (await apiRequest(
211
+ "GET",
212
+ `/v1/tunnels/${opts.id}/stats`
213
+ )) as TunnelStatsResponse;
163
214
  if (opts.json) {
164
215
  printJson(result);
165
216
  } else {
@@ -171,22 +222,62 @@ tunnelCommand
171
222
  }
172
223
  });
173
224
 
174
- // Stop (delete) tunnel
225
+ // Stop (delete) tunnel and kill any matching local client
175
226
  tunnelCommand
176
227
  .command("stop")
177
- .description("Stop (delete) a tunnel")
178
- .requiredOption("--id <id>", "Tunnel id")
228
+ .description("Stop a tunnel: kill the local client and delete the record")
229
+ .option("--id <id>", "Tunnel id")
230
+ .option("--all", "Stop every tunnel for this account", false)
179
231
  .option("--json", "Output JSON", false)
180
232
  .action(async (opts) => {
233
+ if (!opts.all && !opts.id) {
234
+ console.error("Provide --id or --all");
235
+ process.exit(2);
236
+ }
237
+
181
238
  try {
182
- const result = await apiRequest("DELETE", `/v1/tunnels/${opts.id}`) as { id: string; status: string };
239
+ if (opts.all) {
240
+ const listed = (await apiRequest("GET", "/v1/tunnels")) as TunnelListResponse;
241
+ let killed = 0;
242
+ for (const client of findTunnelClients()) {
243
+ if (killTunnelClient(client.pid)) killed++;
244
+ }
245
+ let deleted = 0;
246
+ for (const t of listed.tunnels || []) {
247
+ if (!t.id) continue;
248
+ try {
249
+ await apiRequest("DELETE", `/v1/tunnels/${t.id}`);
250
+ deleted++;
251
+ } catch {
252
+ /* already gone */
253
+ }
254
+ }
255
+ if (opts.json) {
256
+ printJson({ ok: true, killed, deleted });
257
+ } else {
258
+ console.log(`Stopped ${killed} local client(s), removed ${deleted} tunnel record(s)`);
259
+ }
260
+ return;
261
+ }
262
+
263
+ const listed = (await apiRequest("GET", "/v1/tunnels")) as TunnelListResponse;
264
+ const target = (listed.tunnels || []).find((t) => t.id === opts.id);
265
+ if (target?.token) {
266
+ for (const client of findTunnelClients().filter((c) => c.token === target.token)) {
267
+ killTunnelClient(client.pid);
268
+ }
269
+ }
270
+
271
+ const result = (await apiRequest("DELETE", `/v1/tunnels/${opts.id}`)) as {
272
+ id: string;
273
+ status: string;
274
+ };
183
275
  if (opts.json) {
184
276
  printJson(result);
185
277
  } else {
186
278
  console.log(`Stopped tunnel ${result.id} (status=${result.status})`);
187
279
  }
188
- } catch (error: any) {
189
- console.error(error?.message || String(error));
190
- process.exit(30);
280
+ } catch (error) {
281
+ handleError(error, { json: opts.json });
191
282
  }
192
283
  });
@@ -154,7 +154,7 @@ RUN npm install -g serve
154
154
  COPY --from=builder /app/${distDir} ./public
155
155
 
156
156
  EXPOSE ${port}
157
- CMD ["sh", "-c", "serve -s public -l ${PORT}"]
157
+ CMD ["sh", "-c", "serve -s public -l \${PORT}"]
158
158
  `;
159
159
  }
160
160
 
@@ -184,7 +184,7 @@ RUN npm install -g serve
184
184
  COPY --from=builder /app/${distDir} ./public
185
185
 
186
186
  EXPOSE ${port}
187
- CMD ["sh", "-c", "serve -s public -l ${PORT}"]
187
+ CMD ["sh", "-c", "serve -s public -l \${PORT}"]
188
188
  `;
189
189
  }
190
190
 
@@ -215,7 +215,7 @@ RUN npm install -g serve
215
215
  COPY --from=builder /app/${distDir} ./public
216
216
 
217
217
  EXPOSE ${port}
218
- CMD ["sh", "-c", "serve -s public -l ${PORT}"]
218
+ CMD ["sh", "-c", "serve -s public -l \${PORT}"]
219
219
  `;
220
220
  }
221
221
 
@@ -0,0 +1,197 @@
1
+ import { Box, Text, useApp, useInput } from "ink";
2
+ import { useState } from "react";
3
+ import type { MenuChoice } from "../subcommands/menu/types";
4
+ import { HomeStatus } from "./HomeStatus";
5
+ import { AppInspector } from "./AppInspector";
6
+ import { cleanLabel } from "./format";
7
+
8
+ export type TunnelLine = { url: string; port: number };
9
+
10
+ export type MenuStatus = {
11
+ connected: boolean;
12
+ latencyMs: number | null;
13
+ tunnels: TunnelLine[];
14
+ apps: { name: string; id: string; url?: string; createdAt?: string }[];
15
+ providers: string[];
16
+ };
17
+
18
+ export type MenuOutcome =
19
+ | { kind: "quit" }
20
+ | {
21
+ kind: "action";
22
+ action: () => Promise<string>;
23
+ isExit: boolean;
24
+ stack: MenuChoice[][];
25
+ titles: string[];
26
+ selected: number;
27
+ };
28
+
29
+ function isDanger(label: string): boolean {
30
+ const lower = label.toLowerCase();
31
+ return lower.includes("stop all") || lower.includes("⚠") || lower.includes("delete");
32
+ }
33
+
34
+ function isExitLabel(label: string): boolean {
35
+ return label.toLowerCase() === "exit";
36
+ }
37
+
38
+ function noticeColor(line: string): string | undefined {
39
+ if (line.startsWith("Error:") || line.startsWith("✗")) return "red";
40
+ if (line.startsWith("✓")) return "green";
41
+ return undefined;
42
+ }
43
+
44
+ export function MenuApp({
45
+ tree,
46
+ status,
47
+ message,
48
+ initialStack,
49
+ initialTitles,
50
+ initialSelected,
51
+ onOutcome,
52
+ }: {
53
+ tree: MenuChoice[];
54
+ status: MenuStatus;
55
+ message: string;
56
+ initialStack: MenuChoice[][];
57
+ initialTitles: string[];
58
+ initialSelected: number;
59
+ onOutcome: (outcome: MenuOutcome) => void;
60
+ }) {
61
+ const { exit } = useApp();
62
+ const [stack, setStack] = useState<MenuChoice[][]>(initialStack);
63
+ const [titles, setTitles] = useState<string[]>(initialTitles);
64
+ const [selected, setSelected] = useState(initialSelected);
65
+ const [notice, setNotice] = useState(message);
66
+
67
+ const current = stack[stack.length - 1] ?? tree;
68
+ const atRoot = stack.length === 1;
69
+ const crumb = titles.slice(1).join(" › ");
70
+ const selectedChoice = current[selected];
71
+ const inspecting = Boolean(selectedChoice?.inspect);
72
+
73
+ const finish = (outcome: MenuOutcome) => {
74
+ onOutcome(outcome);
75
+ exit();
76
+ };
77
+
78
+ const goBack = () => {
79
+ if (notice) {
80
+ setNotice("");
81
+ return;
82
+ }
83
+ if (atRoot) {
84
+ finish({ kind: "quit" });
85
+ return;
86
+ }
87
+ setStack((prev) => prev.slice(0, -1));
88
+ setTitles((prev) => prev.slice(0, -1));
89
+ setSelected(0);
90
+ };
91
+
92
+ useInput((_input, key) => {
93
+ if (key.escape || key.leftArrow) {
94
+ goBack();
95
+ return;
96
+ }
97
+ if (_input === "q" && atRoot && !notice) {
98
+ finish({ kind: "quit" });
99
+ return;
100
+ }
101
+ if (key.upArrow) {
102
+ setSelected((i) => (i - 1 + current.length) % current.length);
103
+ return;
104
+ }
105
+ if (key.downArrow) {
106
+ setSelected((i) => (i + 1) % current.length);
107
+ return;
108
+ }
109
+ if (key.return) {
110
+ if (notice) {
111
+ setNotice("");
112
+ return;
113
+ }
114
+ const choice = current[selected];
115
+ if (!choice) return;
116
+ if (choice.subMenu && choice.subMenu.length > 0) {
117
+ setStack((prev) => [...prev, choice.subMenu!]);
118
+ setTitles((prev) => [...prev, cleanLabel(choice.label)]);
119
+ setSelected(0);
120
+ return;
121
+ }
122
+ if (choice.action) {
123
+ finish({
124
+ kind: "action",
125
+ action: choice.action,
126
+ isExit: isExitLabel(choice.label),
127
+ stack,
128
+ titles,
129
+ selected,
130
+ });
131
+ }
132
+ }
133
+ });
134
+
135
+ return (
136
+ <Box flexDirection="column" paddingX={1} paddingY={1}>
137
+ {atRoot ? (
138
+ <HomeStatus status={status} />
139
+ ) : (
140
+ <Box flexDirection="column">
141
+ <Text dimColor>UPLINK</Text>
142
+ {crumb ? (
143
+ <Box marginTop={1}>
144
+ <Text dimColor>{crumb}</Text>
145
+ </Box>
146
+ ) : null}
147
+ </Box>
148
+ )}
149
+
150
+ <Box flexDirection="column" marginTop={atRoot ? 1 : 1}>
151
+ {current.map((choice, i) => {
152
+ const active = i === selected;
153
+ const label = cleanLabel(choice.label);
154
+ const suffix = choice.subMenu ? " ›" : "";
155
+ const danger = isDanger(label);
156
+ const exitItem = isExitLabel(label);
157
+ return (
158
+ <Text
159
+ key={`${label}-${i}`}
160
+ bold={active && !exitItem}
161
+ color={active && danger ? "red" : undefined}
162
+ dimColor={!active || exitItem}
163
+ >
164
+ {active ? "› " : " "}
165
+ {label}
166
+ {suffix}
167
+ </Text>
168
+ );
169
+ })}
170
+ </Box>
171
+
172
+ {inspecting ? <AppInspector inspect={selectedChoice?.inspect} /> : null}
173
+
174
+ {notice ? (
175
+ <Box flexDirection="column" marginTop={1}>
176
+ {notice.split("\n").map((line, i) => (
177
+ <Text key={i} color={noticeColor(line)} dimColor={!noticeColor(line)}>
178
+ {line || " "}
179
+ </Text>
180
+ ))}
181
+ </Box>
182
+ ) : null}
183
+
184
+ <Box marginTop={1}>
185
+ <Text dimColor>
186
+ {notice
187
+ ? "enter/esc dismiss"
188
+ : inspecting
189
+ ? "↑↓ inspect · ↵ open · esc back"
190
+ : atRoot
191
+ ? "↑↓ enter · esc/q quit"
192
+ : "↑↓ enter · esc back"}
193
+ </Text>
194
+ </Box>
195
+ </Box>
196
+ );
197
+ }
@@ -0,0 +1,114 @@
1
+ import { Box, Text } from "ink";
2
+ import { useEffect, useState } from "react";
3
+ import type { MenuInspect } from "../subcommands/menu/types";
4
+ import { ARTIFACT_CAP_BYTES, fetchAppInspect, type AppInspect } from "./snapshot";
5
+ import { formatBytes, formatDate } from "./format";
6
+
7
+ const LABEL_WIDTH = 10;
8
+ const GAUGE_WIDTH = 16;
9
+
10
+ function Row({
11
+ label,
12
+ value,
13
+ color,
14
+ dim,
15
+ }: {
16
+ label: string;
17
+ value: string;
18
+ color?: "green" | "red";
19
+ dim?: boolean;
20
+ }) {
21
+ return (
22
+ <Box>
23
+ <Box width={LABEL_WIDTH}>
24
+ <Text dimColor>{label}</Text>
25
+ </Box>
26
+ <Text color={color} dimColor={dim}>
27
+ {value}
28
+ </Text>
29
+ </Box>
30
+ );
31
+ }
32
+
33
+ function SizeGauge({ bytes }: { bytes: number }) {
34
+ const ratio = Math.min(1, bytes / ARTIFACT_CAP_BYTES);
35
+ const filled = Math.round(ratio * GAUGE_WIDTH);
36
+ return (
37
+ <Box>
38
+ <Box width={LABEL_WIDTH}>
39
+ <Text dimColor>size</Text>
40
+ </Box>
41
+ <Text>
42
+ <Text color="green">{"█".repeat(filled)}</Text>
43
+ <Text dimColor>{"░".repeat(GAUGE_WIDTH - filled)}</Text>
44
+ <Text dimColor>
45
+ {" "}
46
+ {formatBytes(bytes)} / {formatBytes(ARTIFACT_CAP_BYTES)}
47
+ </Text>
48
+ </Text>
49
+ </Box>
50
+ );
51
+ }
52
+
53
+ function statusColor(value?: string): "green" | "red" | undefined {
54
+ if (!value) return undefined;
55
+ if (value === "running" || value === "ready") return "green";
56
+ if (value === "failed") return "red";
57
+ return undefined;
58
+ }
59
+
60
+ export function AppInspector({ inspect }: { inspect?: MenuInspect }) {
61
+ const [detail, setDetail] = useState<AppInspect | null>(null);
62
+ const [loading, setLoading] = useState(false);
63
+
64
+ useEffect(() => {
65
+ if (!inspect || inspect.kind !== "app") {
66
+ setDetail(null);
67
+ return;
68
+ }
69
+ let cancelled = false;
70
+ const timer = setTimeout(() => {
71
+ setLoading(true);
72
+ fetchAppInspect(inspect.id).then((next) => {
73
+ if (cancelled) return;
74
+ setDetail(next);
75
+ setLoading(false);
76
+ });
77
+ }, 120);
78
+ return () => {
79
+ cancelled = true;
80
+ clearTimeout(timer);
81
+ };
82
+ }, [inspect?.id, inspect?.kind]);
83
+
84
+ if (!inspect) return null;
85
+
86
+ const url = detail?.url || inspect.url || "—";
87
+ const deploy = detail?.deploy || (loading ? "…" : "—");
88
+ const build = detail?.build || (loading ? "…" : "—");
89
+ const domainText =
90
+ detail && detail.domains.length > 0
91
+ ? detail.domains
92
+ .slice(0, 2)
93
+ .map((domain) => `${domain.hostname}${domain.verified ? "" : " (pending)"}`)
94
+ .join(", ") + (detail.domains.length > 2 ? ` +${detail.domains.length - 2}` : "")
95
+ : loading && !detail
96
+ ? "…"
97
+ : "none";
98
+
99
+ return (
100
+ <Box flexDirection="column" marginTop={1}>
101
+ <Text dimColor>── inspect ──</Text>
102
+ <Row label="url" value={url} />
103
+ <Row label="status" value={deploy} color={statusColor(detail?.deploy)} dim={!detail?.deploy} />
104
+ <Row label="build" value={build} color={statusColor(detail?.build)} dim={!detail?.build} />
105
+ {detail?.sizeBytes != null ? (
106
+ <SizeGauge bytes={detail.sizeBytes} />
107
+ ) : (
108
+ <Row label="size" value={loading ? "…" : "none"} dim />
109
+ )}
110
+ <Row label="created" value={formatDate(detail?.createdAt || inspect.createdAt)} dim={!detail?.createdAt && !inspect.createdAt} />
111
+ <Row label="domains" value={domainText} dim={domainText === "none"} />
112
+ </Box>
113
+ );
114
+ }
@@ -0,0 +1,59 @@
1
+ import { Box, Text } from "ink";
2
+ import type { MenuStatus } from "./App";
3
+ import { Wordmark } from "./brand";
4
+
5
+ const LABEL_WIDTH = 12;
6
+ const BAR_CAP = 24;
7
+
8
+ function CountBar({ count }: { count: number }) {
9
+ if (count <= 0) return null;
10
+ const filled = Math.min(count, BAR_CAP);
11
+ return (
12
+ <Text>
13
+ <Text color="green">{"█".repeat(filled)}</Text>
14
+ {count > BAR_CAP ? <Text dimColor> +{count - BAR_CAP}</Text> : null}
15
+ </Text>
16
+ );
17
+ }
18
+
19
+ function Metric({ label, count }: { label: string; count: number }) {
20
+ return (
21
+ <Box>
22
+ <Box width={LABEL_WIDTH}>
23
+ <Text dimColor>{label}</Text>
24
+ </Box>
25
+ <Box width={4}>
26
+ {count > 0 ? <Text>{count}</Text> : <Text dimColor>—</Text>}
27
+ </Box>
28
+ <CountBar count={count} />
29
+ </Box>
30
+ );
31
+ }
32
+
33
+ export function HomeStatus({ status }: { status: MenuStatus }) {
34
+ const latency =
35
+ status.connected && status.latencyMs != null ? `${status.latencyMs}ms` : "—";
36
+
37
+ return (
38
+ <Box flexDirection="column">
39
+ <Wordmark />
40
+ <Box marginTop={1}>
41
+ <Text color={status.connected ? "green" : "red"}>
42
+ {status.connected ? "connected" : "offline"}
43
+ </Text>
44
+ <Text dimColor> · {latency}</Text>
45
+ </Box>
46
+ <Box marginTop={1} marginBottom={1}>
47
+ <Text dimColor>{"─".repeat(36)}</Text>
48
+ </Box>
49
+ <Box flexDirection="column">
50
+ <Metric label="apps" count={status.apps.length} />
51
+ <Metric label="tunnels" count={status.tunnels.length} />
52
+ <Metric label="registrars" count={status.providers.length} />
53
+ </Box>
54
+ <Box marginTop={1}>
55
+ <Text dimColor>{"─".repeat(36)}</Text>
56
+ </Box>
57
+ </Box>
58
+ );
59
+ }
@@ -0,0 +1,20 @@
1
+ import { Box, Text } from "ink";
2
+
3
+ const WORDMARK = [
4
+ " _ _ ___ _ ___ _ _ _ __",
5
+ "| | | | _ \\ | |_ _| \\| | |/ /",
6
+ "| |_| | _/ |__ | || .` | ' < ",
7
+ " \\___/|_| |____|___|_|\\_|_|\\_\\",
8
+ ];
9
+
10
+ export function Wordmark() {
11
+ return (
12
+ <Box flexDirection="column">
13
+ {WORDMARK.map((line) => (
14
+ <Text key={line} bold>
15
+ {line}
16
+ </Text>
17
+ ))}
18
+ </Box>
19
+ );
20
+ }