@apps-in-toss/devtools 3.0.5 → 3.1.0-beta.1

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.
@@ -2,6 +2,71 @@ import { createRequire } from "node:module";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { resolve } from "node:path";
4
4
  import { createUnplugin } from "unplugin";
5
+ //#region src/shared/parent-watcher.ts
6
+ /**
7
+ * Shared parent-PID watcher — used by both the MCP debug daemon and the
8
+ * unplugin tunnel path to self-terminate when the parent process (e.g. Claude
9
+ * Code, vite) has died or been reparented without sending SIGTERM/SIGHUP.
10
+ *
11
+ * Intentionally react-free and Node-stdlib-only so this module is safe to
12
+ * import from the MCP daemon bundle (`dist/mcp/cli.js`) without violating the
13
+ * install-graph invariant.
14
+ */
15
+ /**
16
+ * Returns `true` when the given PID refers to a running process.
17
+ *
18
+ * Uses `process.kill(pid, 0)` — a no-op signal that succeeds when the process
19
+ * exists and we have permission to signal it; throws ESRCH when it doesn't exist.
20
+ */
21
+ function isPidAlive(pid) {
22
+ try {
23
+ process.kill(pid, 0);
24
+ return true;
25
+ } catch (err) {
26
+ if (err.code === "EPERM") return true;
27
+ return false;
28
+ }
29
+ }
30
+ /**
31
+ * Starts a periodic watcher that detects when the parent process (e.g. Claude
32
+ * Code) has died without sending SIGTERM/SIGHUP, and calls `onOrphaned` so the
33
+ * daemon can self-terminate rather than running as a zombie.
34
+ *
35
+ * Mirrors the `startAttachWatcher` pattern: `setInterval`-based, returns
36
+ * `{ stop(): void }`, injectable deps for testability.
37
+ *
38
+ * @param onOrphaned - Called once when the parent is gone.
39
+ * @param opts.intervalMs - Poll interval in milliseconds (default 5 000).
40
+ * @param opts.initialPpid - Parent PID to watch (default `process.ppid`).
41
+ * @param opts.isAlive - Predicate to test if a PID is running (default `isPidAlive`).
42
+ * @param opts.getPpid - Supplier of current ppid (default `() => process.ppid`).
43
+ * Detects ppid changes as well as death.
44
+ * @param opts.log - Logger (default `process.stderr.write`).
45
+ *
46
+ * @returns `stop` — call during shutdown to clear the interval.
47
+ */
48
+ function startParentWatcher(onOrphaned, opts) {
49
+ const { intervalMs = 5e3, initialPpid = process.ppid, isAlive = isPidAlive, getPpid = () => process.ppid, log = (msg) => process.stderr.write(msg) } = opts ?? {};
50
+ if (initialPpid <= 1) {
51
+ log("[ait-debug] parent-pid watcher: no parent to watch (ppid<=1), skipping\n");
52
+ return { stop() {} };
53
+ }
54
+ let fired = false;
55
+ const handle = setInterval(() => {
56
+ if (fired) return;
57
+ const currentPpid = getPpid();
58
+ if (currentPpid !== initialPpid || !isAlive(initialPpid)) {
59
+ fired = true;
60
+ clearInterval(handle);
61
+ log(`[ait-debug] parent-pid watcher: parent PID ${initialPpid} is gone (currentPpid=${currentPpid}) — shutting down\n`);
62
+ onOrphaned();
63
+ }
64
+ }, intervalMs);
65
+ return { stop() {
66
+ clearInterval(handle);
67
+ } };
68
+ }
69
+ //#endregion
5
70
  //#region src/unplugin/index.ts
6
71
  /**
7
72
  * @apps-in-toss/devtools unplugin
@@ -55,14 +120,6 @@ function detectInstalledSdkMajor(cwd = process.cwd()) {
55
120
  } catch {}
56
121
  return null;
57
122
  }
58
- /**
59
- * 패널 자동 주입 대상 진입점 파일명 기본 패턴. `entryPattern` 옵션 미지정 시
60
- * 사용된다. `id.test()`는 상태를 갖지 않아야 하므로(매 파일마다 호출) 이
61
- * 패턴과 사용자 지정 `entryPattern` 모두 `g`/`y` 플래그를 붙이지 않는다는
62
- * 전제다 — `RegExp.prototype.test`는 global/sticky 플래그가 있으면 호출마다
63
- * `lastIndex`가 전진해 다음 파일 매칭이 간헐적으로 실패한다.
64
- */
65
- const DEFAULT_ENTRY_PATTERN = /\/(main|index|entry|app)\.[tj]sx?$/i;
66
123
  const FRAMEWORK_ID = "@apps-in-toss/web-framework";
67
124
  const BRIDGE_ID = "@apps-in-toss/web-bridge";
68
125
  const ANALYTICS_ID = "@apps-in-toss/web-analytics";
@@ -71,14 +128,40 @@ const WEBVIEW_BRIDGE_ID = "@apps-in-toss/webview-bridge";
71
128
  const MCP_STATE_PATH = "/api/ait-devtools/state";
72
129
  /** Browser runtime opt-in consumed by the panel's state-sync helper. */
73
130
  const MCP_ENABLE_SNIPPET = "globalThis.__AIT_DEVTOOLS_MCP_ENABLED__ = true;";
131
+ /**
132
+ * Resolves the effective tunnel option (#425).
133
+ *
134
+ * An explicit `tunnel` value (including `false`) always takes priority over
135
+ * env vars — the `??` operator means `undefined` (= omitted) falls through,
136
+ * but `false` / `true` / an object are preserved as-is (non-breaking).
137
+ *
138
+ * When the option is omitted:
139
+ * - `AIT_TUNNEL=1` enables the screen-preview tunnel.
140
+ * - Not set → `false` (disabled).
141
+ *
142
+ * Extracted as a pure function so it can be unit-tested without standing up
143
+ * a full Vite dev server.
144
+ *
145
+ * @param explicit - The `tunnel` option as passed by the consumer (or `undefined` when omitted).
146
+ * @param env - The process environment (injectable for testing).
147
+ */
148
+ function resolveTunnelOption(explicit, env) {
149
+ return explicit ?? !!env.AIT_TUNNEL;
150
+ }
74
151
  const aitDevtoolsPlugin = createUnplugin((options) => {
75
152
  const isDev = process.env.NODE_ENV !== "production";
76
- const shouldEnable = isDev || !!options?.forceEnable;
153
+ const shouldEnable = isDev;
77
154
  const shouldMock = shouldEnable && (options?.mock ?? isDev);
78
155
  const sdkMajor = options?.sdkVersion === "2" || options?.sdkVersion === "3" ? options.sdkVersion : detectInstalledSdkMajor() ?? "3";
79
156
  const shouldPanel = shouldEnable && (options?.panel ?? true);
80
157
  const shouldMcp = shouldEnable && (options?.mcp ?? false);
81
158
  let lastState = null;
159
+ const tunnelOpt = resolveTunnelOption(options?.tunnel, process.env);
160
+ const shouldTunnel = isDev && !!tunnelOpt;
161
+ const webViewType = options?.webViewType ?? "partner";
162
+ const navBarTransparent = options?.navBarTransparent;
163
+ const navBarTheme = options?.navBarTheme;
164
+ const tunnelConfig = typeof tunnelOpt === "object" ? tunnelOpt : {};
82
165
  return {
83
166
  name: "ait-co-devtools",
84
167
  enforce: "pre",
@@ -93,7 +176,7 @@ const aitDevtoolsPlugin = createUnplugin((options) => {
93
176
  },
94
177
  transformInclude(id) {
95
178
  if (!shouldPanel && !shouldMcp) return false;
96
- return /\.(tsx?|jsx?)$/.test(id) && (options?.entryPattern ?? DEFAULT_ENTRY_PATTERN).test(id) && !id.includes("node_modules");
179
+ return /\.(tsx?|jsx?)$/.test(id) && /\/(main|index|entry|app)\.[tj]sx?$/i.test(id) && !id.includes("node_modules");
97
180
  },
98
181
  transform(code) {
99
182
  let result = code;
@@ -110,8 +193,12 @@ const aitDevtoolsPlugin = createUnplugin((options) => {
110
193
  },
111
194
  vite: {
112
195
  config() {
113
- if (options?.initialState === void 0) return {};
114
- return { define: { __AIT_INITIAL_STATE__: JSON.stringify(options.initialState) } };
196
+ const define = { __WEB_VIEW_TYPE__: JSON.stringify(webViewType) };
197
+ if (!shouldTunnel) return { define };
198
+ return {
199
+ define,
200
+ server: { allowedHosts: [".trycloudflare.com"] }
201
+ };
115
202
  },
116
203
  configureServer(server) {
117
204
  if (shouldMcp) server.middlewares.use(MCP_STATE_PATH, (req, res) => {
@@ -153,6 +240,53 @@ const aitDevtoolsPlugin = createUnplugin((options) => {
153
240
  res.writeHead(405, { "Content-Type": "application/json" });
154
241
  res.end(JSON.stringify({ error: "Method not allowed" }));
155
242
  });
243
+ if (shouldTunnel) {
244
+ let tunnel = null;
245
+ let parentWatcher = null;
246
+ const httpServer = server.httpServer;
247
+ httpServer?.once("listening", () => {
248
+ const address = httpServer?.address();
249
+ const port = tunnelConfig.port ?? (address && typeof address === "object" ? address.port : void 0);
250
+ if (!port) {
251
+ console.warn("[@apps-in-toss/devtools] tunnel: could not determine the dev server port; skipping.");
252
+ return;
253
+ }
254
+ import("../tunnel-BvEf1qGV.js").then(async ({ startQuickTunnel, printTunnelBanner }) => {
255
+ const t = await startQuickTunnel(port);
256
+ tunnel = t;
257
+ let tunnelAppName;
258
+ try {
259
+ const { readFileSync } = await import("node:fs");
260
+ const pkgRaw = readFileSync(`${server.config.root}/package.json`, "utf8");
261
+ const pkg = JSON.parse(pkgRaw);
262
+ const rawName = typeof pkg.name === "string" ? pkg.name : "";
263
+ tunnelAppName = (rawName.includes("/") ? rawName.slice(rawName.indexOf("/") + 1) : rawName).trim() || void 0;
264
+ } catch {}
265
+ await printTunnelBanner(t.url, {
266
+ qr: tunnelConfig.qr,
267
+ name: tunnelAppName,
268
+ webViewType,
269
+ navBarTransparent,
270
+ navBarTheme
271
+ });
272
+ parentWatcher = startParentWatcher(() => {
273
+ cleanup();
274
+ process.exit(0);
275
+ });
276
+ }).catch((err) => {
277
+ console.warn(`[@apps-in-toss/devtools] tunnel failed to start: ${err instanceof Error ? err.message : String(err)}`);
278
+ });
279
+ });
280
+ const cleanup = () => {
281
+ parentWatcher?.stop();
282
+ tunnel?.stop();
283
+ };
284
+ httpServer?.once("close", cleanup);
285
+ process.once("SIGINT", cleanup);
286
+ process.once("SIGTERM", cleanup);
287
+ process.once("SIGHUP", cleanup);
288
+ process.once("exit", cleanup);
289
+ }
156
290
  }
157
291
  }
158
292
  };
@@ -164,4 +298,4 @@ const esbuild = aitDevtoolsPlugin.esbuild;
164
298
  const rspack = aitDevtoolsPlugin.rspack;
165
299
  const aitDevtools = aitDevtoolsPlugin;
166
300
  //#endregion
167
- export { aitDevtools as default, detectInstalledSdkMajor, esbuild, rollup, rspack, vite, webpack };
301
+ export { aitDevtools as default, detectInstalledSdkMajor, esbuild, resolveTunnelOption, rollup, rspack, vite, webpack };
@@ -0,0 +1,191 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let node_fs = require("node:fs");
3
+ let node_fs_promises = require("node:fs/promises");
4
+ let node_path = require("node:path");
5
+ //#region src/unplugin/tunnel.ts
6
+ /**
7
+ * Cloudflare quick-tunnel helper for the devtools unplugin.
8
+ *
9
+ * Loaded lazily (`await import('./tunnel.js')`) only when the `tunnel` option is
10
+ * on, so `cloudflared` / `qrcode-terminal` are never pulled in for the common
11
+ * case. This is the one place in `@apps-in-toss/devtools` that depends on Node-only
12
+ * APIs (`child_process` via the `cloudflared` wrapper) — keep it thin and out of
13
+ * jsdom unit tests; the spawn path is verified by hand / e2e (same spirit as the
14
+ * "web 모드는 e2e" rule in CLAUDE.md). The pure helpers below
15
+ * (`parseTrycloudflareUrl`, `printTunnelBanner`) are unit-tested.
16
+ */
17
+ /** Matches the public URL cloudflared prints for an unauthenticated quick tunnel. */
18
+ const TRYCLOUDFLARE_RE = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/i;
19
+ /**
20
+ * Extract the `https://<sub>.trycloudflare.com` URL from a line of cloudflared
21
+ * output, or `null` if the line doesn't contain one. Pulled out as a pure
22
+ * function so it can be unit-tested without spawning anything.
23
+ */
24
+ function parseTrycloudflareUrl(line) {
25
+ const m = line.match(TRYCLOUDFLARE_RE);
26
+ return m ? m[0] : null;
27
+ }
28
+ const LAUNCHER_URL = "https://devtools.aitc.dev/launcher/";
29
+ /**
30
+ * Build the deep-link URL that QR codes encode: when the launcher PWA is
31
+ * already on the phone's home screen, scanning this opens it directly into the
32
+ * live view for `tunnelUrl` (the launcher consumes `?url=` and clears it).
33
+ * Plain-text raw URL is no longer enough — the launcher gates its setup UI to
34
+ * the installed PWA, so a raw tunnel URL opened in a normal browser tab would
35
+ * land on a "please install" screen.
36
+ *
37
+ * When `opts.name` is given (non-blank), it is added as `&name=` so the launcher
38
+ * partner bar shows the app name instead of the generic default (#498).
39
+ *
40
+ * When `opts.webViewType` is `'game'`, `&navBarType=game` is appended so the
41
+ * launcher enters game nav chrome (floating capsule, no full bar) automatically
42
+ * on scan. `'partner'` is the launcher's implicit default and is not added to
43
+ * keep the URL clean (#584).
44
+ *
45
+ * When `opts.navBarTransparent` is `true`, `&navBarTransparent=1` is appended
46
+ * so the launcher partner bar renders with a transparent background (#587).
47
+ *
48
+ * When `opts.navBarTheme` is `'light'` or `'dark'`, `&navBarTheme=<v>` is
49
+ * appended so the launcher partner bar uses the matching foreground colour (#587).
50
+ */
51
+ function buildLauncherDeepLink(tunnelUrl, optsParam) {
52
+ const opts = optsParam ?? {};
53
+ let url = `${LAUNCHER_URL}?url=${encodeURIComponent(tunnelUrl)}`;
54
+ if (opts.name !== void 0 && opts.name.trim() !== "") url += `&name=${encodeURIComponent(opts.name.trim())}`;
55
+ if (opts.webViewType === "game") url += "&navBarType=game";
56
+ if (opts.navBarTransparent === true) url += "&navBarTransparent=1";
57
+ if (opts.navBarTheme === "light" || opts.navBarTheme === "dark") url += `&navBarTheme=${opts.navBarTheme}`;
58
+ return url;
59
+ }
60
+ /**
61
+ * Print the terminal banner announcing the live tunnel: the public URL, an ASCII
62
+ * QR encoding a launcher deep-link, and a one-line note that quick tunnels are
63
+ * ephemeral, unauthenticated and not for production. Pure w.r.t. side effects
64
+ * other than the injected `log` sink and `qrcode-terminal` — unit-tested.
65
+ */
66
+ async function printTunnelBanner(url, opts = {}) {
67
+ const log = opts.log ?? ((m) => console.log(m));
68
+ const deepLink = buildLauncherDeepLink(url, {
69
+ name: opts.name,
70
+ webViewType: opts.webViewType,
71
+ navBarTransparent: opts.navBarTransparent,
72
+ navBarTheme: opts.navBarTheme
73
+ });
74
+ log([
75
+ "",
76
+ " ┌─ @apps-in-toss/devtools · live tunnel ────────────────────────────",
77
+ ` │ ${url}`,
78
+ " │",
79
+ ` │ Install the launcher PWA once: ${LAUNCHER_URL}`,
80
+ " │ Then scan the QR below — it opens the launcher directly",
81
+ " │ into this tunnel URL (no manual paste needed).",
82
+ " │ Quick tunnels are unauthenticated, change every run, and are",
83
+ " │ not for production use.",
84
+ " └──────────────────────────────────────────────────────────────",
85
+ ""
86
+ ].join("\n"));
87
+ if (opts.qr !== false) {
88
+ const qrcode = (await import("qrcode-terminal")).default;
89
+ await new Promise((resolve) => {
90
+ qrcode.generate(deepLink, { small: true }, (out) => {
91
+ log(out);
92
+ resolve();
93
+ });
94
+ });
95
+ }
96
+ }
97
+ /**
98
+ * Sanitize cloudflared stderr output for error diagnostics (#421).
99
+ *
100
+ * Masks `*.trycloudflare.com` hostnames and full `https://` / `wss://` URLs
101
+ * that carry those hostnames so tunnel host values never appear in error
102
+ * messages. Diagnostic content (error codes, reasons, JSON blobs) is preserved.
103
+ *
104
+ * SECRET-HANDLING: tunnel host is SECRET-class per harness policy — only
105
+ * placeholder text is emitted.
106
+ */
107
+ function sanitizeCloudflaredOutput(line) {
108
+ let s = line.replace(/(?:https?|wss?):\/\/[a-z0-9-]+\.trycloudflare\.com(?:\/[^\s]*)*/gi, (m) => m.replace(/[a-z0-9-]+\.trycloudflare\.com/i, "<HOST>.trycloudflare.com"));
109
+ s = s.replace(/[a-z0-9-]+\.trycloudflare\.com/gi, "<HOST>.trycloudflare.com");
110
+ return s;
111
+ }
112
+ const URL_TIMEOUT_MS = 2e4;
113
+ /**
114
+ * Start an unauthenticated Cloudflare quick tunnel to `http://localhost:<port>`
115
+ * and resolve once the public URL is known. Downloads the `cloudflared` binary
116
+ * on first use if it is not already installed. Rejects with a friendly error if
117
+ * no URL appears within {@link URL_TIMEOUT_MS}.
118
+ */
119
+ async function startQuickTunnel(port) {
120
+ const { bin, install, Tunnel } = await import("cloudflared");
121
+ if (!(0, node_fs.existsSync)(bin)) {
122
+ await (0, node_fs_promises.mkdir)((0, node_path.dirname)(bin), { recursive: true });
123
+ await install(bin);
124
+ }
125
+ const tunnel = Tunnel.quick(`http://localhost:${port}`);
126
+ let stopped = false;
127
+ const stop = () => {
128
+ if (stopped) return;
129
+ stopped = true;
130
+ try {
131
+ tunnel.stop();
132
+ } catch {}
133
+ };
134
+ return new Promise((resolve, reject) => {
135
+ const stderrLines = [];
136
+ /**
137
+ * Format the last `n` sanitized stderr lines as a diagnostic appendix.
138
+ * Returns an empty string when no lines have been collected.
139
+ */
140
+ const stderrTail = (n = 15) => {
141
+ if (stderrLines.length === 0) return "";
142
+ const tail = stderrLines.slice(-n).map(sanitizeCloudflaredOutput).join("");
143
+ return `\ncloudflared 출력 (마지막 ${Math.min(n, stderrLines.length)}줄):\n${tail}`;
144
+ };
145
+ const timer = setTimeout(() => {
146
+ cleanup();
147
+ stop();
148
+ reject(/* @__PURE__ */ new Error(`[@apps-in-toss/devtools] cloudflared did not report a tunnel URL within ${URL_TIMEOUT_MS / 1e3}s. Check your network connection, or run \`cloudflared tunnel --url http://localhost:${port}\` manually.${stderrTail()}`));
149
+ }, URL_TIMEOUT_MS);
150
+ const onUrl = (line) => {
151
+ const found = parseTrycloudflareUrl(line);
152
+ if (!found) return;
153
+ clearTimeout(timer);
154
+ cleanup();
155
+ resolve({
156
+ url: found,
157
+ stop
158
+ });
159
+ };
160
+ const pushStderr = (line) => {
161
+ stderrLines.push(line);
162
+ };
163
+ const cleanup = () => {
164
+ tunnel.off("stdout", onUrl);
165
+ tunnel.off("stderr", onUrl);
166
+ tunnel.off("stderr", pushStderr);
167
+ };
168
+ tunnel.once("url", onUrl);
169
+ tunnel.on("stdout", onUrl);
170
+ tunnel.on("stderr", onUrl);
171
+ tunnel.on("stderr", pushStderr);
172
+ tunnel.once("error", (err) => {
173
+ clearTimeout(timer);
174
+ cleanup();
175
+ stop();
176
+ reject(err);
177
+ });
178
+ tunnel.once("exit", (code) => {
179
+ if (stopped) return;
180
+ clearTimeout(timer);
181
+ cleanup();
182
+ reject(/* @__PURE__ */ new Error(`[@apps-in-toss/devtools] cloudflared exited (code ${code ?? "null"}) before reporting a tunnel URL.${stderrTail()}`));
183
+ });
184
+ });
185
+ }
186
+ //#endregion
187
+ exports.buildLauncherDeepLink = buildLauncherDeepLink;
188
+ exports.parseTrycloudflareUrl = parseTrycloudflareUrl;
189
+ exports.printTunnelBanner = printTunnelBanner;
190
+ exports.sanitizeCloudflaredOutput = sanitizeCloudflaredOutput;
191
+ exports.startQuickTunnel = startQuickTunnel;
@@ -0,0 +1,140 @@
1
+ //#region src/unplugin/tunnel.d.ts
2
+ /**
3
+ * Cloudflare quick-tunnel helper for the devtools unplugin.
4
+ *
5
+ * Loaded lazily (`await import('./tunnel.js')`) only when the `tunnel` option is
6
+ * on, so `cloudflared` / `qrcode-terminal` are never pulled in for the common
7
+ * case. This is the one place in `@apps-in-toss/devtools` that depends on Node-only
8
+ * APIs (`child_process` via the `cloudflared` wrapper) — keep it thin and out of
9
+ * jsdom unit tests; the spawn path is verified by hand / e2e (same spirit as the
10
+ * "web 모드는 e2e" rule in CLAUDE.md). The pure helpers below
11
+ * (`parseTrycloudflareUrl`, `printTunnelBanner`) are unit-tested.
12
+ */
13
+ /**
14
+ * Extract the `https://<sub>.trycloudflare.com` URL from a line of cloudflared
15
+ * output, or `null` if the line doesn't contain one. Pulled out as a pure
16
+ * function so it can be unit-tested without spawning anything.
17
+ */
18
+ declare function parseTrycloudflareUrl(line: string): string | null;
19
+ interface PrintTunnelBannerOptions {
20
+ /** Print an ASCII QR encoding the tunnel URL (default: true). */
21
+ qr?: boolean;
22
+ /** Sink for the banner text (default: `console.log`). Injected for testing. */
23
+ log?: (msg: string) => void;
24
+ /**
25
+ * Human-readable app name to embed as `name=` in the launcher deep-link (#498).
26
+ * When provided (non-blank), the launcher partner bar shows this name instead of
27
+ * the generic default.
28
+ */
29
+ name?: string;
30
+ /**
31
+ * The miniapp's webViewType. When `'game'`, the deep-link carries `&navBarType=game`
32
+ * so the launcher enters game nav chrome automatically on scan (#584).
33
+ * `'partner'` (the default) is the launcher's implicit default — not added to
34
+ * keep the URL clean.
35
+ */
36
+ webViewType?: "partner" | "game";
37
+ /**
38
+ * Whether the miniapp's navigationBar has `transparentBackground: true`
39
+ * (granite.config `navigationBar.transparentBackground`, SDK 2.8.0, #587).
40
+ * When `true`, the deep-link carries `&navBarTransparent=1` so the launcher
41
+ * partner bar renders with a transparent background (content shows through).
42
+ * `false` / omitted → not added (URL clean, back-compat).
43
+ */
44
+ navBarTransparent?: boolean;
45
+ /**
46
+ * The miniapp's navigationBar theme (`granite.config `navigationBar.theme`,
47
+ * SDK 2.8.0, #587). When `'light'` or `'dark'`, the deep-link carries
48
+ * `&navBarTheme=<v>` so the launcher partner bar uses the matching foreground
49
+ * colour. Omitted / other values → not added (URL clean, back-compat).
50
+ */
51
+ navBarTheme?: "light" | "dark";
52
+ }
53
+ /**
54
+ * Options for {@link buildLauncherDeepLink}.
55
+ */
56
+ interface BuildLauncherDeepLinkOptions {
57
+ /**
58
+ * Human-readable app name shown in the partner nav bar (`name=` param, #498).
59
+ * Blank / whitespace-only values are not added.
60
+ */
61
+ name?: string;
62
+ /**
63
+ * The miniapp's webViewType. When `'game'`, adds `&navBarType=game` to the
64
+ * deep-link so the launcher enters game nav chrome automatically on scan (#584).
65
+ * `'partner'` (the launcher's implicit default) is not added to keep the URL
66
+ * clean.
67
+ */
68
+ webViewType?: "partner" | "game";
69
+ /**
70
+ * Whether the miniapp's navigationBar has `transparentBackground: true`
71
+ * (granite.config `navigationBar.transparentBackground`, SDK 2.8.0, #587).
72
+ * When `true`, adds `&navBarTransparent=1` to the deep-link so the launcher
73
+ * partner bar renders with a transparent background. Omitted when `false` /
74
+ * undefined to keep the URL clean (back-compat).
75
+ */
76
+ navBarTransparent?: boolean;
77
+ /**
78
+ * The miniapp's navigationBar theme (granite.config `navigationBar.theme`,
79
+ * SDK 2.8.0, #587). When `'light'` or `'dark'`, adds `&navBarTheme=<v>` to
80
+ * the deep-link so the launcher partner bar uses the matching foreground colour.
81
+ * Omitted when undefined / other values to keep the URL clean (back-compat).
82
+ */
83
+ navBarTheme?: "light" | "dark";
84
+ }
85
+ /**
86
+ * Build the deep-link URL that QR codes encode: when the launcher PWA is
87
+ * already on the phone's home screen, scanning this opens it directly into the
88
+ * live view for `tunnelUrl` (the launcher consumes `?url=` and clears it).
89
+ * Plain-text raw URL is no longer enough — the launcher gates its setup UI to
90
+ * the installed PWA, so a raw tunnel URL opened in a normal browser tab would
91
+ * land on a "please install" screen.
92
+ *
93
+ * When `opts.name` is given (non-blank), it is added as `&name=` so the launcher
94
+ * partner bar shows the app name instead of the generic default (#498).
95
+ *
96
+ * When `opts.webViewType` is `'game'`, `&navBarType=game` is appended so the
97
+ * launcher enters game nav chrome (floating capsule, no full bar) automatically
98
+ * on scan. `'partner'` is the launcher's implicit default and is not added to
99
+ * keep the URL clean (#584).
100
+ *
101
+ * When `opts.navBarTransparent` is `true`, `&navBarTransparent=1` is appended
102
+ * so the launcher partner bar renders with a transparent background (#587).
103
+ *
104
+ * When `opts.navBarTheme` is `'light'` or `'dark'`, `&navBarTheme=<v>` is
105
+ * appended so the launcher partner bar uses the matching foreground colour (#587).
106
+ */
107
+ declare function buildLauncherDeepLink(tunnelUrl: string, optsParam?: BuildLauncherDeepLinkOptions): string;
108
+ /**
109
+ * Print the terminal banner announcing the live tunnel: the public URL, an ASCII
110
+ * QR encoding a launcher deep-link, and a one-line note that quick tunnels are
111
+ * ephemeral, unauthenticated and not for production. Pure w.r.t. side effects
112
+ * other than the injected `log` sink and `qrcode-terminal` — unit-tested.
113
+ */
114
+ declare function printTunnelBanner(url: string, opts?: PrintTunnelBannerOptions): Promise<void>;
115
+ interface QuickTunnel {
116
+ /** The public `https://*.trycloudflare.com` URL. */
117
+ url: string;
118
+ /** Stop the underlying `cloudflared` process. Idempotent. */
119
+ stop: () => void;
120
+ }
121
+ /**
122
+ * Sanitize cloudflared stderr output for error diagnostics (#421).
123
+ *
124
+ * Masks `*.trycloudflare.com` hostnames and full `https://` / `wss://` URLs
125
+ * that carry those hostnames so tunnel host values never appear in error
126
+ * messages. Diagnostic content (error codes, reasons, JSON blobs) is preserved.
127
+ *
128
+ * SECRET-HANDLING: tunnel host is SECRET-class per harness policy — only
129
+ * placeholder text is emitted.
130
+ */
131
+ declare function sanitizeCloudflaredOutput(line: string): string;
132
+ /**
133
+ * Start an unauthenticated Cloudflare quick tunnel to `http://localhost:<port>`
134
+ * and resolve once the public URL is known. Downloads the `cloudflared` binary
135
+ * on first use if it is not already installed. Rejects with a friendly error if
136
+ * no URL appears within {@link URL_TIMEOUT_MS}.
137
+ */
138
+ declare function startQuickTunnel(port: number): Promise<QuickTunnel>;
139
+ //#endregion
140
+ export { BuildLauncherDeepLinkOptions, PrintTunnelBannerOptions, QuickTunnel, buildLauncherDeepLink, parseTrycloudflareUrl, printTunnelBanner, sanitizeCloudflaredOutput, startQuickTunnel };
@@ -0,0 +1,140 @@
1
+ //#region src/unplugin/tunnel.d.ts
2
+ /**
3
+ * Cloudflare quick-tunnel helper for the devtools unplugin.
4
+ *
5
+ * Loaded lazily (`await import('./tunnel.js')`) only when the `tunnel` option is
6
+ * on, so `cloudflared` / `qrcode-terminal` are never pulled in for the common
7
+ * case. This is the one place in `@apps-in-toss/devtools` that depends on Node-only
8
+ * APIs (`child_process` via the `cloudflared` wrapper) — keep it thin and out of
9
+ * jsdom unit tests; the spawn path is verified by hand / e2e (same spirit as the
10
+ * "web 모드는 e2e" rule in CLAUDE.md). The pure helpers below
11
+ * (`parseTrycloudflareUrl`, `printTunnelBanner`) are unit-tested.
12
+ */
13
+ /**
14
+ * Extract the `https://<sub>.trycloudflare.com` URL from a line of cloudflared
15
+ * output, or `null` if the line doesn't contain one. Pulled out as a pure
16
+ * function so it can be unit-tested without spawning anything.
17
+ */
18
+ declare function parseTrycloudflareUrl(line: string): string | null;
19
+ interface PrintTunnelBannerOptions {
20
+ /** Print an ASCII QR encoding the tunnel URL (default: true). */
21
+ qr?: boolean;
22
+ /** Sink for the banner text (default: `console.log`). Injected for testing. */
23
+ log?: (msg: string) => void;
24
+ /**
25
+ * Human-readable app name to embed as `name=` in the launcher deep-link (#498).
26
+ * When provided (non-blank), the launcher partner bar shows this name instead of
27
+ * the generic default.
28
+ */
29
+ name?: string;
30
+ /**
31
+ * The miniapp's webViewType. When `'game'`, the deep-link carries `&navBarType=game`
32
+ * so the launcher enters game nav chrome automatically on scan (#584).
33
+ * `'partner'` (the default) is the launcher's implicit default — not added to
34
+ * keep the URL clean.
35
+ */
36
+ webViewType?: "partner" | "game";
37
+ /**
38
+ * Whether the miniapp's navigationBar has `transparentBackground: true`
39
+ * (granite.config `navigationBar.transparentBackground`, SDK 2.8.0, #587).
40
+ * When `true`, the deep-link carries `&navBarTransparent=1` so the launcher
41
+ * partner bar renders with a transparent background (content shows through).
42
+ * `false` / omitted → not added (URL clean, back-compat).
43
+ */
44
+ navBarTransparent?: boolean;
45
+ /**
46
+ * The miniapp's navigationBar theme (`granite.config `navigationBar.theme`,
47
+ * SDK 2.8.0, #587). When `'light'` or `'dark'`, the deep-link carries
48
+ * `&navBarTheme=<v>` so the launcher partner bar uses the matching foreground
49
+ * colour. Omitted / other values → not added (URL clean, back-compat).
50
+ */
51
+ navBarTheme?: "light" | "dark";
52
+ }
53
+ /**
54
+ * Options for {@link buildLauncherDeepLink}.
55
+ */
56
+ interface BuildLauncherDeepLinkOptions {
57
+ /**
58
+ * Human-readable app name shown in the partner nav bar (`name=` param, #498).
59
+ * Blank / whitespace-only values are not added.
60
+ */
61
+ name?: string;
62
+ /**
63
+ * The miniapp's webViewType. When `'game'`, adds `&navBarType=game` to the
64
+ * deep-link so the launcher enters game nav chrome automatically on scan (#584).
65
+ * `'partner'` (the launcher's implicit default) is not added to keep the URL
66
+ * clean.
67
+ */
68
+ webViewType?: "partner" | "game";
69
+ /**
70
+ * Whether the miniapp's navigationBar has `transparentBackground: true`
71
+ * (granite.config `navigationBar.transparentBackground`, SDK 2.8.0, #587).
72
+ * When `true`, adds `&navBarTransparent=1` to the deep-link so the launcher
73
+ * partner bar renders with a transparent background. Omitted when `false` /
74
+ * undefined to keep the URL clean (back-compat).
75
+ */
76
+ navBarTransparent?: boolean;
77
+ /**
78
+ * The miniapp's navigationBar theme (granite.config `navigationBar.theme`,
79
+ * SDK 2.8.0, #587). When `'light'` or `'dark'`, adds `&navBarTheme=<v>` to
80
+ * the deep-link so the launcher partner bar uses the matching foreground colour.
81
+ * Omitted when undefined / other values to keep the URL clean (back-compat).
82
+ */
83
+ navBarTheme?: "light" | "dark";
84
+ }
85
+ /**
86
+ * Build the deep-link URL that QR codes encode: when the launcher PWA is
87
+ * already on the phone's home screen, scanning this opens it directly into the
88
+ * live view for `tunnelUrl` (the launcher consumes `?url=` and clears it).
89
+ * Plain-text raw URL is no longer enough — the launcher gates its setup UI to
90
+ * the installed PWA, so a raw tunnel URL opened in a normal browser tab would
91
+ * land on a "please install" screen.
92
+ *
93
+ * When `opts.name` is given (non-blank), it is added as `&name=` so the launcher
94
+ * partner bar shows the app name instead of the generic default (#498).
95
+ *
96
+ * When `opts.webViewType` is `'game'`, `&navBarType=game` is appended so the
97
+ * launcher enters game nav chrome (floating capsule, no full bar) automatically
98
+ * on scan. `'partner'` is the launcher's implicit default and is not added to
99
+ * keep the URL clean (#584).
100
+ *
101
+ * When `opts.navBarTransparent` is `true`, `&navBarTransparent=1` is appended
102
+ * so the launcher partner bar renders with a transparent background (#587).
103
+ *
104
+ * When `opts.navBarTheme` is `'light'` or `'dark'`, `&navBarTheme=<v>` is
105
+ * appended so the launcher partner bar uses the matching foreground colour (#587).
106
+ */
107
+ declare function buildLauncherDeepLink(tunnelUrl: string, optsParam?: BuildLauncherDeepLinkOptions): string;
108
+ /**
109
+ * Print the terminal banner announcing the live tunnel: the public URL, an ASCII
110
+ * QR encoding a launcher deep-link, and a one-line note that quick tunnels are
111
+ * ephemeral, unauthenticated and not for production. Pure w.r.t. side effects
112
+ * other than the injected `log` sink and `qrcode-terminal` — unit-tested.
113
+ */
114
+ declare function printTunnelBanner(url: string, opts?: PrintTunnelBannerOptions): Promise<void>;
115
+ interface QuickTunnel {
116
+ /** The public `https://*.trycloudflare.com` URL. */
117
+ url: string;
118
+ /** Stop the underlying `cloudflared` process. Idempotent. */
119
+ stop: () => void;
120
+ }
121
+ /**
122
+ * Sanitize cloudflared stderr output for error diagnostics (#421).
123
+ *
124
+ * Masks `*.trycloudflare.com` hostnames and full `https://` / `wss://` URLs
125
+ * that carry those hostnames so tunnel host values never appear in error
126
+ * messages. Diagnostic content (error codes, reasons, JSON blobs) is preserved.
127
+ *
128
+ * SECRET-HANDLING: tunnel host is SECRET-class per harness policy — only
129
+ * placeholder text is emitted.
130
+ */
131
+ declare function sanitizeCloudflaredOutput(line: string): string;
132
+ /**
133
+ * Start an unauthenticated Cloudflare quick tunnel to `http://localhost:<port>`
134
+ * and resolve once the public URL is known. Downloads the `cloudflared` binary
135
+ * on first use if it is not already installed. Rejects with a friendly error if
136
+ * no URL appears within {@link URL_TIMEOUT_MS}.
137
+ */
138
+ declare function startQuickTunnel(port: number): Promise<QuickTunnel>;
139
+ //#endregion
140
+ export { BuildLauncherDeepLinkOptions, PrintTunnelBannerOptions, QuickTunnel, buildLauncherDeepLink, parseTrycloudflareUrl, printTunnelBanner, sanitizeCloudflaredOutput, startQuickTunnel };