@vincentt-xr/cli 0.18.3 → 0.19.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/MIGRATION.md +16 -2
- package/dist/cli/index.js +11 -5
- package/dist/cli/usage-text.js +1 -1
- package/dist/lib/terminalText.d.ts +2 -0
- package/dist/lib/terminalText.js +7 -0
- package/dist/login/pkceLogin.d.ts +7 -1
- package/dist/login/pkceLogin.js +25 -4
- package/dist/preview/api.d.ts +15 -0
- package/dist/preview/api.js +27 -1
- package/dist/preview/command.d.ts +1 -1
- package/dist/preview/copy.d.ts +14 -1
- package/dist/preview/copy.js +37 -3
- package/dist/preview/devPort.d.ts +17 -0
- package/dist/preview/devPort.js +14 -0
- package/dist/preview/proxy.d.ts +16 -9
- package/dist/preview/proxy.js +102 -20
- package/dist/preview/runner.d.ts +10 -2
- package/dist/preview/runner.js +21 -6
- package/dist/preview/stream.d.ts +1 -1
- package/dist/preview/viewers.d.ts +1 -1
- package/dist/relay/server.js +1 -1
- package/dist/tunnel/cbor.d.ts +71 -0
- package/dist/tunnel/cbor.js +403 -0
- package/dist/tunnel/client.d.ts +225 -0
- package/dist/tunnel/client.js +764 -0
- package/dist/tunnel/forwardTarget.d.ts +69 -0
- package/dist/tunnel/forwardTarget.js +179 -0
- package/dist/tunnel/frame.d.ts +126 -0
- package/dist/tunnel/frame.js +244 -0
- package/dist/tunnel/index.d.ts +9 -0
- package/dist/tunnel/index.js +9 -0
- package/package.json +2 -2
package/MIGRATION.md
CHANGED
|
@@ -3,12 +3,26 @@
|
|
|
3
3
|
Per version, newest first. Read by the platform's own version surface and served to
|
|
4
4
|
creators' agents. Accurate or absent, never speculative (B-F5-2).
|
|
5
5
|
|
|
6
|
+
## 0.19.0
|
|
7
|
+
|
|
8
|
+
required: false
|
|
9
|
+
No action required for a project made from the Vincentt template. Behaviour that changed:
|
|
10
|
+
- The platform caps how many previews one person runs at once (5 by default, across every workspace; a preview that is still connecting counts, viewers never do). Re-running `vincentt preview` in a folder that already has a preview is never refused by the cap.
|
|
11
|
+
- `vincentt preview` past the preview cap exits 1, starts nothing and stops nothing, and says how many previews are running and how to stop one: Ctrl-C where it runs, `vincentt preview --stop` in its folder, or Stop on its project's Preview tab in the console.
|
|
12
|
+
- A preview refusal the CLI does not recognise prints the platform's own message instead of "A preview is already running for this folder."
|
|
13
|
+
- `vincentt preview` with no `vincentt.json`, `--port` or `--dev-command` starts the project's `dev` script on a free port, passed to it as `PORT`, instead of 5173, and never reuses a server it finds already listening. Two previews at once, or another server already on 5173, no longer share one app. The settings banner shows the chosen port. A port from `--port` or `vincentt.json` is kept, and a server already listening there is still reused.
|
|
14
|
+
- A preview answers 404 for any path segment shaped like a Windows short name (one to six characters, then `~` and a digit, such as `GIT~1` or `ENVLOC~1`), on every platform. On Windows these names open the dotted files the preview already hides. Bundler chunk names such as `vendors~main` are unaffected.
|
|
15
|
+
- The preview tunnel client is part of the CLI itself instead of being loaded from `@vincentt-xr/harness`. The preview behaves the same, and it works with any harness version a project has installed.
|
|
16
|
+
- A preview answers 404 for files and folders named like credentials, with no opt-out: `credentials.json`, `service-account*.json`, `*firebase-adminsdk*.json`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, `*.p8`, `*.ppk`, `id_rsa*`, `id_dsa*`, `id_ed25519*`, `id_ecdsa*`, `*.jks`, `*.keystore`, `*.env`, `*.tfstate`, `*.tfvars`, and their `~` or `.bak` backups, in any letter case. An app asset with one of these names (for example a `.key` file) needs a new name to load in a preview.
|
|
17
|
+
- A preview also refuses a Windows stream name, a name with trailing dots or spaces, and a query or fragment carrying a parent-folder step, a backslash or an encoded slash. The 404 advisory names the path decoded, without control or bidirectional-override characters, and now ends `A preview never serves hidden or credential files from your project.`
|
|
18
|
+
- `vincentt login` and the report consent prompt open a browser only for an `https:` address, or an `http:` address on `localhost`, `127.0.0.1` or `[::1]`; anything else is printed but not opened. On Windows the browser opens through `rundll32` instead of `cmd`.
|
|
19
|
+
|
|
6
20
|
## 0.18.3
|
|
7
21
|
|
|
8
22
|
required: false
|
|
9
23
|
No action required when the preview and the commands reading it (`logs`, `feedback`, `preview --stop`) come from the same CLI version. Behaviour that changed:
|
|
10
|
-
- The local preview relay refuses web pages other than the preview itself. It answers only requests whose Host is `127.0.0.1:<port>` or `localhost:<port>`, accepts the diagnostics socket and feedback posts only from the preview's own address (or from a client that sends no Origin), and refuses a POST
|
|
11
|
-
- The relay's diagnostics read and feedback long-poll now require a per-session token, which the preview writes to
|
|
24
|
+
- The local preview relay refuses web pages other than the preview itself. It answers only requests whose Host is `127.0.0.1:<port>` or `localhost:<port>`, accepts the diagnostics socket and feedback posts only from the preview's own address (or from a client that sends no Origin), and refuses a POST whose content type is not JSON with 415.
|
|
25
|
+
- The relay's diagnostics read and feedback long-poll now require a per-session token, which the preview writes to the project's relay record (now readable by the owner only). The CLI's own commands send it; a direct diagnostics or feedback request without the `x-vincentt-relay-token` header is refused with 401. A command from CLI 0.18.2 or older cannot read a preview started by this version, and the reverse still works.
|
|
12
26
|
- `vincentt relay` prints the token it requires and accepts `--origin <url>` for a page it should accept; without it, only pages served from localhost or 127.0.0.1 can connect.
|
|
13
27
|
|
|
14
28
|
## 0.18.2
|
package/dist/cli/index.js
CHANGED
|
@@ -37,13 +37,14 @@ import { USAGE_TEXT } from "./usage-text.js";
|
|
|
37
37
|
import { PreviewUi } from "../preview/command.js";
|
|
38
38
|
import { httpRelayClient } from "../lib/diagnostics.js";
|
|
39
39
|
import { readLivePreview, relayInfoDir } from "../lib/relayInfo.js";
|
|
40
|
-
import { attachedToRunning, mintRateLimited, noDiagnosticsStatic, notSignedIn, previewConflict, settingsBanner, startBlock, } from "../preview/copy.js";
|
|
40
|
+
import { attachedToRunning, mintRateLimited, noDiagnosticsStatic, notSignedIn, previewConflict, previewUserLimitRefused, settingsBanner, startBlock, } from "../preview/copy.js";
|
|
41
|
+
import { chooseDevPort } from "../preview/devPort.js";
|
|
41
42
|
import { isPortListening } from "../preview/net.js";
|
|
42
43
|
import { readSettings, resolveSettings, SettingsError, TEMPLATE_DEFAULTS, validateField, } from "../lib/settings.js";
|
|
43
44
|
import { settingsRefusal, sourceWords } from "../lib/settingsCopy.js";
|
|
44
45
|
import { listsHarness } from "../lib/template.js";
|
|
45
46
|
import { renderTerminalQr, shouldRenderQr } from "../preview/qr.js";
|
|
46
|
-
import { PreviewConflictError, PreviewLimitError, PreviewRateLimitedError, } from "../preview/api.js";
|
|
47
|
+
import { PreviewConflictError, PreviewLimitError, PreviewRateLimitedError, PreviewUserLimitError, } from "../preview/api.js";
|
|
47
48
|
import { previewLimitRefused, resolveCountLimit, } from "../shared/countLimit.js";
|
|
48
49
|
import { fetchNext, readCursor, writeCursor } from "../lib/feedback.js";
|
|
49
50
|
import * as feedbackCopy from "../lib/feedbackCopy.js";
|
|
@@ -531,14 +532,16 @@ async function preview() {
|
|
|
531
532
|
return;
|
|
532
533
|
}
|
|
533
534
|
const devCommand = settings.devCommand.value;
|
|
534
|
-
const devPort = settings
|
|
535
|
+
const { port: devPort, fresh: devPortFresh } = await chooseDevPort(settings);
|
|
536
|
+
// What the creator gets running the dev command by hand, without PORT.
|
|
537
|
+
const handRunUrl = `http://localhost:${settings.devPort.value}`;
|
|
535
538
|
const localUrl = `http://localhost:${devPort}`;
|
|
536
539
|
for (const l of settingsBanner({
|
|
537
540
|
devCommand,
|
|
538
541
|
devCommandSource: sourceWords(settings.devCommand),
|
|
539
542
|
devPort,
|
|
540
543
|
devPortSource: sourceWords(settings.devPort),
|
|
541
|
-
reused: await isPortListening(devPort),
|
|
544
|
+
reused: devPortFresh ? false : await isPortListening(devPort),
|
|
542
545
|
})) {
|
|
543
546
|
console.log(l);
|
|
544
547
|
}
|
|
@@ -549,7 +552,7 @@ async function preview() {
|
|
|
549
552
|
// The gate is LOCAL and NOTHING IS ATTEMPTED: no spinner, no partial mint, no
|
|
550
553
|
// session left in `pending`. The command stops before it touches the network.
|
|
551
554
|
if (!(await currentToken())) {
|
|
552
|
-
for (const l of notSignedIn(devCommand,
|
|
555
|
+
for (const l of notSignedIn(devCommand, handRunUrl))
|
|
553
556
|
console.log(l);
|
|
554
557
|
process.exitCode = EXIT.NOT_AUTHENTICATED;
|
|
555
558
|
return;
|
|
@@ -607,6 +610,7 @@ async function preview() {
|
|
|
607
610
|
try {
|
|
608
611
|
const started = await previewStart(cwd, (m) => console.error(`[preview] ${m}`), {
|
|
609
612
|
appPort: devPort,
|
|
613
|
+
appPortFresh: devPortFresh,
|
|
610
614
|
devCommand,
|
|
611
615
|
onHiddenPath: (p) => ui.hiddenPath(p),
|
|
612
616
|
appStdio: has("--verbose") ? "inherit" : "ignore",
|
|
@@ -842,6 +846,8 @@ function previewFailureLines(err, local) {
|
|
|
842
846
|
if (err instanceof PreviewLimitError) {
|
|
843
847
|
return previewLimitRefused(resolveCountLimit(err.detail, local));
|
|
844
848
|
}
|
|
849
|
+
if (err instanceof PreviewUserLimitError)
|
|
850
|
+
return previewUserLimitRefused(err.detail);
|
|
845
851
|
if (err instanceof PreviewConflictError)
|
|
846
852
|
return previewConflict();
|
|
847
853
|
if (err instanceof ProjectUnreachableError) {
|
package/dist/cli/usage-text.js
CHANGED
|
@@ -58,7 +58,7 @@ export const USAGE_TEXT = `Vincentt CLI: the local-first AR dev loop\n\n` +
|
|
|
58
58
|
` [--port <n>] [--dev-command <cmd>] [--tester <id>]\n` +
|
|
59
59
|
` [--no-qr] [--stop]\n` +
|
|
60
60
|
` Runs dev.command and forwards dev.port from vincentt.json,\n` +
|
|
61
|
-
` else npm run dev on
|
|
61
|
+
` else npm run dev on a free port (passed as PORT).\n` +
|
|
62
62
|
` Re-running prints the live link; --restart mints a new one.\n\n` +
|
|
63
63
|
// f16. HELP TEACHES THE CANONICAL VERBS ONLY: `add` and `remove` are accepted
|
|
64
64
|
// as silent aliases and are deliberately ABSENT here, because help, docs and
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const CONTROL_CHARS: RegExp;
|
|
2
2
|
/** Each C0/C1 control character as a visible `\uXXXX`, so nothing is hidden or redrawn. */
|
|
3
3
|
export declare function escapeControl(text: string): string;
|
|
4
|
+
/** Text with every C0/C1 control and bidi override or isolate removed. */
|
|
5
|
+
export declare function terminalSafe(text: string): string;
|
package/dist/lib/terminalText.js
CHANGED
|
@@ -8,3 +8,10 @@ const CONTROL_CHARS_G = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
|
8
8
|
export function escapeControl(text) {
|
|
9
9
|
return text.replace(CONTROL_CHARS_G, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
10
10
|
}
|
|
11
|
+
// U+202A..U+202E (embeddings, overrides) and U+2066..U+2069 (isolates) can
|
|
12
|
+
// reorder a terminal line, so a crafted name could disguise what it says.
|
|
13
|
+
const BIDI_CONTROLS_G = /[\u202a-\u202e\u2066-\u2069]/g;
|
|
14
|
+
/** Text with every C0/C1 control and bidi override or isolate removed. */
|
|
15
|
+
export function terminalSafe(text) {
|
|
16
|
+
return text.replace(CONTROL_CHARS_G, "").replace(BIDI_CONTROLS_G, "");
|
|
17
|
+
}
|
|
@@ -29,11 +29,17 @@ export declare class LoginTimeoutError extends Error {
|
|
|
29
29
|
export declare class LoginCallbackError extends Error {
|
|
30
30
|
constructor(message: string);
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* The platform command + args to open `url` in the default browser. On win32
|
|
34
|
+
* the URL goes to `rundll32` as one argument, so no command interpreter parses
|
|
35
|
+
* it and `&` cannot split the command.
|
|
36
|
+
*/
|
|
33
37
|
export declare function browserOpenCommand(url: string, platform?: string): {
|
|
34
38
|
cmd: string;
|
|
35
39
|
args: string[];
|
|
36
40
|
};
|
|
41
|
+
/** Only `https:`, or `http:` on a loopback host, is ever handed to the OS opener. */
|
|
42
|
+
export declare function isLaunchableUrl(url: string): boolean;
|
|
37
43
|
type SpawnLike = (cmd: string, args: string[], opts: {
|
|
38
44
|
stdio: "ignore";
|
|
39
45
|
detached: boolean;
|
package/dist/login/pkceLogin.js
CHANGED
|
@@ -30,14 +30,35 @@ export class LoginCallbackError extends Error {
|
|
|
30
30
|
this.name = "LoginCallbackError";
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The platform command + args to open `url` in the default browser. On win32
|
|
35
|
+
* the URL goes to `rundll32` as one argument, so no command interpreter parses
|
|
36
|
+
* it and `&` cannot split the command.
|
|
37
|
+
*/
|
|
34
38
|
export function browserOpenCommand(url, platform = process.platform) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
if (platform === "win32") {
|
|
40
|
+
return { cmd: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
|
|
41
|
+
}
|
|
42
|
+
return { cmd: platform === "darwin" ? "open" : "xdg-open", args: [url] };
|
|
43
|
+
}
|
|
44
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "[::1]", "localhost"]);
|
|
45
|
+
/** Only `https:`, or `http:` on a loopback host, is ever handed to the OS opener. */
|
|
46
|
+
export function isLaunchableUrl(url) {
|
|
47
|
+
let parsed;
|
|
48
|
+
try {
|
|
49
|
+
parsed = new URL(url);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (parsed.protocol === "https:")
|
|
55
|
+
return true;
|
|
56
|
+
return parsed.protocol === "http:" && LOOPBACK_HOSTS.has(parsed.hostname);
|
|
38
57
|
}
|
|
39
58
|
/** Launch the browser via an injected spawn; a throw is swallowed (fallback = the printed URL). */
|
|
40
59
|
export function launchBrowser(url, spawn, platform) {
|
|
60
|
+
if (!isLaunchableUrl(url))
|
|
61
|
+
return;
|
|
41
62
|
const { cmd, args } = browserOpenCommand(url, platform);
|
|
42
63
|
try {
|
|
43
64
|
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
package/dist/preview/api.d.ts
CHANGED
|
@@ -46,6 +46,21 @@ export declare class PreviewLimitError extends BackendError {
|
|
|
46
46
|
readonly detail: CountLimitDetail;
|
|
47
47
|
constructor(message: string, detail: CountLimitDetail);
|
|
48
48
|
}
|
|
49
|
+
/** The refusal body's detail on `preview_user_limit`. */
|
|
50
|
+
export interface PreviewUserLimitDetail {
|
|
51
|
+
limit?: string;
|
|
52
|
+
count?: number;
|
|
53
|
+
ceiling?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The caller already runs as many previews as one person may, across every
|
|
57
|
+
* workspace (`409 preview_user_limit`). A THIRD 409 on the mint route, told
|
|
58
|
+
* apart by its code. Nothing was ended; the remedy is stopping a preview.
|
|
59
|
+
*/
|
|
60
|
+
export declare class PreviewUserLimitError extends BackendError {
|
|
61
|
+
readonly detail: PreviewUserLimitDetail;
|
|
62
|
+
constructor(message: string, detail: PreviewUserLimitDetail);
|
|
63
|
+
}
|
|
49
64
|
/**
|
|
50
65
|
* The session is gone — `preview_session_ended`, the CLI's terminal branch.
|
|
51
66
|
*
|
package/dist/preview/api.js
CHANGED
|
@@ -47,6 +47,19 @@ export class PreviewLimitError extends BackendError {
|
|
|
47
47
|
this.name = "PreviewLimitError";
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* The caller already runs as many previews as one person may, across every
|
|
52
|
+
* workspace (`409 preview_user_limit`). A THIRD 409 on the mint route, told
|
|
53
|
+
* apart by its code. Nothing was ended; the remedy is stopping a preview.
|
|
54
|
+
*/
|
|
55
|
+
export class PreviewUserLimitError extends BackendError {
|
|
56
|
+
detail;
|
|
57
|
+
constructor(message, detail) {
|
|
58
|
+
super(message, 409);
|
|
59
|
+
this.detail = detail;
|
|
60
|
+
this.name = "PreviewUserLimitError";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
50
63
|
/**
|
|
51
64
|
* The session is gone — `preview_session_ended`, the CLI's terminal branch.
|
|
52
65
|
*
|
|
@@ -130,7 +143,20 @@ export async function mintPreviewSession(cfg, projectId, key, fetchImpl = apiFet
|
|
|
130
143
|
if (body.code === "preview_limit") {
|
|
131
144
|
throw new PreviewLimitError(body.message ?? "this organization is at its preview limit", body.detail ?? {});
|
|
132
145
|
}
|
|
133
|
-
|
|
146
|
+
if (body.code === "preview_user_limit") {
|
|
147
|
+
const d = body.detail ?? {};
|
|
148
|
+
throw new PreviewUserLimitError(body.message ?? "you already have the most previews one person can run at once", {
|
|
149
|
+
limit: typeof d.limit === "string" ? d.limit : undefined,
|
|
150
|
+
count: typeof d.count === "number" ? d.count : undefined,
|
|
151
|
+
ceiling: typeof d.ceiling === "number" ? d.ceiling : undefined,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (body.code === "preview_session_conflict" || body.code === undefined) {
|
|
155
|
+
throw new PreviewConflictError(body.message ?? "a preview is already running for this folder");
|
|
156
|
+
}
|
|
157
|
+
// An unrecognised refusal prints the server's own words rather than the
|
|
158
|
+
// folder-conflict screen, so a future 409 is never misread as a conflict.
|
|
159
|
+
throw new BackendError(body.message ?? `could not start a preview (409)`, 409);
|
|
134
160
|
}
|
|
135
161
|
throw new BackendError(body.message ?? `could not start a preview (${res.status})`, res.status);
|
|
136
162
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DiagEvent } from "@vincentt-xr/harness/events";
|
|
2
|
-
import type { TunnelState, UAClass } from "
|
|
2
|
+
import type { TunnelState, UAClass } from "../tunnel/index.js";
|
|
3
3
|
import type { EventTags } from "../relay/server.js";
|
|
4
4
|
import type { PreviewEndReason } from "./runner.js";
|
|
5
5
|
export interface PreviewUiDeps {
|
package/dist/preview/copy.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function deviceArrived(descriptor: string): string;
|
|
|
51
51
|
* The window's length is deliberately not printed.
|
|
52
52
|
*/
|
|
53
53
|
export declare function noDiagnosticsRuntime(descriptor: string): string[];
|
|
54
|
-
/** Flow P1 — the proxy refused a hidden path. Once per preview, naming the first. */
|
|
54
|
+
/** Flow P1 — the proxy refused a hidden or credential path. Once per preview, naming the first. */
|
|
55
55
|
export declare function hiddenPathRefused(requestPath: string): string;
|
|
56
56
|
/** Flow L16 — `--viewer`, a second terminal, not a second preview. */
|
|
57
57
|
export declare function followingBlock(label: string, descriptor: string): string[];
|
|
@@ -267,3 +267,16 @@ export declare function mintRateLimited(retryAfterSec: number): string[];
|
|
|
267
267
|
export declare function approxWait(seconds: number): string;
|
|
268
268
|
/** The conflict a supersede lost (409). Rare: the mint supersedes first. */
|
|
269
269
|
export declare function previewConflict(): string[];
|
|
270
|
+
/**
|
|
271
|
+
* The per-person preview cap, refused at mint (`409 preview_user_limit`, B-F3-9).
|
|
272
|
+
*
|
|
273
|
+
* The count and the cap come only from the refusal body, never from a number
|
|
274
|
+
* compiled in: the cap is an operator setting. It names no workspace, plan or
|
|
275
|
+
* price, because no plan raises it. "Still running" comes first among the facts
|
|
276
|
+
* for the same reason as the org-ceiling screen: the command that refused is the
|
|
277
|
+
* one that starts previews, so a creator assumes it took something down.
|
|
278
|
+
*/
|
|
279
|
+
export declare function previewUserLimitRefused(d: {
|
|
280
|
+
count?: number;
|
|
281
|
+
ceiling?: number;
|
|
282
|
+
}): string[];
|
package/dist/preview/copy.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// sharpest — it transits an agent's tool-output transcript by default in this
|
|
18
18
|
// product, so f1's "a token is never printed" extends to it verbatim.
|
|
19
19
|
/** Flow L13 — the start block. */
|
|
20
|
-
import { escapeControl } from "../lib/terminalText.js";
|
|
20
|
+
import { escapeControl, terminalSafe } from "../lib/terminalText.js";
|
|
21
21
|
export function startBlock(i) {
|
|
22
22
|
const out = [
|
|
23
23
|
"",
|
|
@@ -128,9 +128,9 @@ export function noDiagnosticsRuntime(descriptor) {
|
|
|
128
128
|
" stopped before that line ran.",
|
|
129
129
|
];
|
|
130
130
|
}
|
|
131
|
-
/** Flow P1 — the proxy refused a hidden path. Once per preview, naming the first. */
|
|
131
|
+
/** Flow P1 — the proxy refused a hidden or credential path. Once per preview, naming the first. */
|
|
132
132
|
export function hiddenPathRefused(requestPath) {
|
|
133
|
-
return `! Answered 404 for ${requestPath}. A preview never serves hidden files from your project.`;
|
|
133
|
+
return `! Answered 404 for ${terminalSafe(requestPath)}. A preview never serves hidden or credential files from your project.`;
|
|
134
134
|
}
|
|
135
135
|
/** Flow L16 — `--viewer`, a second terminal, not a second preview. */
|
|
136
136
|
export function followingBlock(label, descriptor) {
|
|
@@ -572,3 +572,37 @@ export function previewConflict() {
|
|
|
572
572
|
"",
|
|
573
573
|
];
|
|
574
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* The per-person preview cap, refused at mint (`409 preview_user_limit`, B-F3-9).
|
|
577
|
+
*
|
|
578
|
+
* The count and the cap come only from the refusal body, never from a number
|
|
579
|
+
* compiled in: the cap is an operator setting. It names no workspace, plan or
|
|
580
|
+
* price, because no plan raises it. "Still running" comes first among the facts
|
|
581
|
+
* for the same reason as the org-ceiling screen: the command that refused is the
|
|
582
|
+
* one that starts previews, so a creator assumes it took something down.
|
|
583
|
+
*/
|
|
584
|
+
export function previewUserLimitRefused(d) {
|
|
585
|
+
const { count, ceiling } = d;
|
|
586
|
+
const known = typeof count === "number" && typeof ceiling === "number" && ceiling > 0;
|
|
587
|
+
let first = "✗ You already have the most previews one person can run at once.";
|
|
588
|
+
if (known && count > ceiling) {
|
|
589
|
+
first = `✗ You already have ${count} previews running. One person can run ${ceiling} at once.`;
|
|
590
|
+
}
|
|
591
|
+
else if (known && count === ceiling) {
|
|
592
|
+
first = `✗ You already have ${count} previews running, the most one person can run at once.`;
|
|
593
|
+
}
|
|
594
|
+
return [
|
|
595
|
+
"",
|
|
596
|
+
first,
|
|
597
|
+
"",
|
|
598
|
+
" Every preview that was running is still running. This one did not start.",
|
|
599
|
+
" A preview that is still connecting counts too. Viewers never count.",
|
|
600
|
+
"",
|
|
601
|
+
" To start this one, stop a preview you no longer need:",
|
|
602
|
+
" press Ctrl-C where it runs, or run vincentt preview --stop in its folder,",
|
|
603
|
+
" or press Stop on its project's Preview tab in the console.",
|
|
604
|
+
"",
|
|
605
|
+
" Nothing was started.",
|
|
606
|
+
"",
|
|
607
|
+
];
|
|
608
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ResolvedSettings } from "../lib/settings.js";
|
|
2
|
+
export interface DevPortChoice {
|
|
3
|
+
port: number;
|
|
4
|
+
/**
|
|
5
|
+
* The port was picked for this preview. Nothing else may answer there, so a
|
|
6
|
+
* listener found on it is never reused as the app.
|
|
7
|
+
*/
|
|
8
|
+
fresh: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The port the preview's dev server runs on. Only the template default is
|
|
12
|
+
* replaced with a free port (passed to the dev command as PORT), so two
|
|
13
|
+
* previews never share one. A port from `--port` or `vincentt.json`, or any
|
|
14
|
+
* port paired with a custom dev command, is kept: many outside dev servers
|
|
15
|
+
* ignore PORT and listen where they were told.
|
|
16
|
+
*/
|
|
17
|
+
export declare function chooseDevPort(settings: Pick<ResolvedSettings, "devCommand" | "devPort">, pickPort?: () => Promise<number>): Promise<DevPortChoice>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getFreePort } from "./net.js";
|
|
2
|
+
/**
|
|
3
|
+
* The port the preview's dev server runs on. Only the template default is
|
|
4
|
+
* replaced with a free port (passed to the dev command as PORT), so two
|
|
5
|
+
* previews never share one. A port from `--port` or `vincentt.json`, or any
|
|
6
|
+
* port paired with a custom dev command, is kept: many outside dev servers
|
|
7
|
+
* ignore PORT and listen where they were told.
|
|
8
|
+
*/
|
|
9
|
+
export async function chooseDevPort(settings, pickPort = getFreePort) {
|
|
10
|
+
if (settings.devPort.source === "default" && settings.devCommand.source === "default") {
|
|
11
|
+
return { port: await pickPort(), fresh: true };
|
|
12
|
+
}
|
|
13
|
+
return { port: settings.devPort.value, fresh: false };
|
|
14
|
+
}
|
package/dist/preview/proxy.d.ts
CHANGED
|
@@ -36,17 +36,24 @@ export declare function proxyWs(req: IncomingMessage, socket: Duplex, head: Buff
|
|
|
36
36
|
export declare function relayRoute(url: string, harnessPath: string, kind: "http" | "upgrade"): "relay" | "refuse" | "app";
|
|
37
37
|
/**
|
|
38
38
|
* Whether the front proxy must answer 404 itself for this app-route URL, so a
|
|
39
|
-
* file-server dev tool serving the repo root cannot hand `/.env`, `/.git/config
|
|
40
|
-
*
|
|
39
|
+
* file-server dev tool serving the repo root cannot hand `/.env`, `/.git/config`,
|
|
40
|
+
* the binding or a credential file to any holder of a preview link.
|
|
41
41
|
*
|
|
42
42
|
* The path is decoded once, and an encoded `/` or `\` is refused outright (a
|
|
43
|
-
* separator the dev server would split on and this check would not).
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
43
|
+
* separator the dev server would split on and this check would not). The query
|
|
44
|
+
* and fragment may not carry a traversal or a separator either, because some
|
|
45
|
+
* dev servers resolve a file from a query parameter. A segment still carrying
|
|
46
|
+
* an encoded character after that one decode is judged as the dev server would
|
|
47
|
+
* read it after a second decode, so `%252eenv` cannot slip past; a second decode
|
|
48
|
+
* that throws is done leniently, never treated as "not hidden". `.` and `..`
|
|
49
|
+
* segments are always refused, which is what makes the `/@fs/` text containment
|
|
50
|
+
* below real containment.
|
|
48
51
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
52
|
+
* Three rules read the checked segments: the dot rule (raw name), and the
|
|
53
|
+
* short-name and credential-name rules (normalized name, see `normalizedName`).
|
|
54
|
+
*
|
|
55
|
+
* `projectRoot` is the realpath of the binding directory with forward slashes,
|
|
56
|
+
* taken once at preview start; inside-ness is a segment-aligned text prefix,
|
|
57
|
+
* with no disk call.
|
|
51
58
|
*/
|
|
52
59
|
export declare function isHiddenAppPath(url: string, projectRoot: string): boolean;
|
package/dist/preview/proxy.js
CHANGED
|
@@ -138,23 +138,34 @@ export function relayRoute(url, harnessPath, kind) {
|
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* Whether the front proxy must answer 404 itself for this app-route URL, so a
|
|
141
|
-
* file-server dev tool serving the repo root cannot hand `/.env`, `/.git/config
|
|
142
|
-
*
|
|
141
|
+
* file-server dev tool serving the repo root cannot hand `/.env`, `/.git/config`,
|
|
142
|
+
* the binding or a credential file to any holder of a preview link.
|
|
143
143
|
*
|
|
144
144
|
* The path is decoded once, and an encoded `/` or `\` is refused outright (a
|
|
145
|
-
* separator the dev server would split on and this check would not).
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
145
|
+
* separator the dev server would split on and this check would not). The query
|
|
146
|
+
* and fragment may not carry a traversal or a separator either, because some
|
|
147
|
+
* dev servers resolve a file from a query parameter. A segment still carrying
|
|
148
|
+
* an encoded character after that one decode is judged as the dev server would
|
|
149
|
+
* read it after a second decode, so `%252eenv` cannot slip past; a second decode
|
|
150
|
+
* that throws is done leniently, never treated as "not hidden". `.` and `..`
|
|
151
|
+
* segments are always refused, which is what makes the `/@fs/` text containment
|
|
152
|
+
* below real containment.
|
|
150
153
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
154
|
+
* Three rules read the checked segments: the dot rule (raw name), and the
|
|
155
|
+
* short-name and credential-name rules (normalized name, see `normalizedName`).
|
|
156
|
+
*
|
|
157
|
+
* `projectRoot` is the realpath of the binding directory with forward slashes,
|
|
158
|
+
* taken once at preview start; inside-ness is a segment-aligned text prefix,
|
|
159
|
+
* with no disk call.
|
|
153
160
|
*/
|
|
154
161
|
export function isHiddenAppPath(url, projectRoot) {
|
|
155
|
-
const
|
|
162
|
+
const [beforeHash = "", ...hash] = url.split("#");
|
|
163
|
+
const [raw = "", ...query] = beforeHash.split("?");
|
|
156
164
|
if (/%(2f|5c)/i.test(raw) || raw.includes("\\"))
|
|
157
165
|
return true;
|
|
166
|
+
const tail = [...query, ...hash].join("?");
|
|
167
|
+
if (/%(2f|5c)/i.test(tail) || tail.includes("\\") || tail.includes("/.."))
|
|
168
|
+
return true;
|
|
158
169
|
let decoded;
|
|
159
170
|
try {
|
|
160
171
|
decoded = decodeURIComponent(raw);
|
|
@@ -168,22 +179,93 @@ export function isHiddenAppPath(url, projectRoot) {
|
|
|
168
179
|
const checked = checkedSegmentIndexes(segments, projectRoot);
|
|
169
180
|
for (const i of checked) {
|
|
170
181
|
const seg = segments[i];
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
const spellings = [seg, secondDecode(seg)];
|
|
183
|
+
if (spellings.some((s) => s.startsWith(".")) && !isAllowedDotSegment(segments, i)) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
for (const s of spellings) {
|
|
187
|
+
const name = normalizedName(s);
|
|
188
|
+
if (name === REFUSE)
|
|
189
|
+
return true;
|
|
190
|
+
if (SHORT_NAME.test(name) || isCredentialName(name))
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
176
193
|
}
|
|
177
194
|
return false;
|
|
178
195
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
196
|
+
/** The segment as a second decode would read it; lenient when that decode throws. */
|
|
197
|
+
function secondDecode(segment) {
|
|
198
|
+
if (!/%[0-9a-f]{2}/i.test(segment))
|
|
199
|
+
return segment;
|
|
182
200
|
try {
|
|
183
|
-
return decodeURIComponent(segment)
|
|
201
|
+
return decodeURIComponent(segment);
|
|
184
202
|
}
|
|
185
203
|
catch {
|
|
186
|
-
return
|
|
204
|
+
return segment.replace(/(?:%[0-9a-f]{2})+/gi, (run) => {
|
|
205
|
+
try {
|
|
206
|
+
return decodeURIComponent(run);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return run.replace(/%([0-9a-f]{2})/gi, (_, h) => String.fromCharCode(parseInt(h, 16)));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const REFUSE = Symbol("refuse");
|
|
215
|
+
/**
|
|
216
|
+
* The name a Windows or case-insensitive file system would open for this
|
|
217
|
+
* segment: a stream suffix (`:$`) is refused outright, the rest is cut at the
|
|
218
|
+
* first colon (so `/@fs/C:/...` and `virtual:` modules still work), trailing
|
|
219
|
+
* dots and spaces are dropped (Windows resolves `server.pem. .` to `server.pem`),
|
|
220
|
+
* and compatibility and case forms are folded.
|
|
221
|
+
*/
|
|
222
|
+
function normalizedName(segment) {
|
|
223
|
+
if (segment.includes(":$"))
|
|
224
|
+
return REFUSE;
|
|
225
|
+
const beforeColon = segment.split(":")[0] ?? "";
|
|
226
|
+
return beforeColon.replace(/[. ]+$/, "").normalize("NFKC").toUpperCase().toLowerCase();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* A Windows 8.3 short name (`GIT~1`, `CREDEN~1.JSO`) opens the long-named file
|
|
230
|
+
* it stands for, and its short form carries no leading dot, so `/GIT~1/config`
|
|
231
|
+
* would read `.git/config` past the dot rule. Refused on every platform: the
|
|
232
|
+
* proxy can front a Windows file system from any client.
|
|
233
|
+
*/
|
|
234
|
+
const SHORT_NAME = /^[^~]{1,6}~[0-9]/;
|
|
235
|
+
/** D-Preview-hides-credential-files: hard-coded, no opt-out. `*` is any run of characters. */
|
|
236
|
+
const CREDENTIAL_NAMES = Object.freeze([
|
|
237
|
+
"credentials.json",
|
|
238
|
+
"service-account*.json",
|
|
239
|
+
"*firebase-adminsdk*.json",
|
|
240
|
+
"*.pem",
|
|
241
|
+
"*.key",
|
|
242
|
+
"*.p12",
|
|
243
|
+
"*.pfx",
|
|
244
|
+
"*.p8",
|
|
245
|
+
"*.ppk",
|
|
246
|
+
"id_rsa*",
|
|
247
|
+
"id_dsa*",
|
|
248
|
+
"id_ed25519*",
|
|
249
|
+
"id_ecdsa*",
|
|
250
|
+
"*.jks",
|
|
251
|
+
"*.keystore",
|
|
252
|
+
"*.env",
|
|
253
|
+
"*.tfstate",
|
|
254
|
+
"*.tfvars",
|
|
255
|
+
].map((glob) => new RegExp(`^${glob
|
|
256
|
+
.split("*")
|
|
257
|
+
.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
258
|
+
.join(".*")}$`, "s")));
|
|
259
|
+
/** A listed name, or one with backup endings (`~`, `.bak`) added, any number of times. */
|
|
260
|
+
function isCredentialName(name) {
|
|
261
|
+
let candidate = name;
|
|
262
|
+
for (;;) {
|
|
263
|
+
if (CREDENTIAL_NAMES.some((re) => re.test(candidate)))
|
|
264
|
+
return true;
|
|
265
|
+
const stripped = candidate.replace(/(?:~|\.bak)$/, "");
|
|
266
|
+
if (stripped === candidate)
|
|
267
|
+
return false;
|
|
268
|
+
candidate = stripped;
|
|
187
269
|
}
|
|
188
270
|
}
|
|
189
271
|
function checkedSegmentIndexes(segments, projectRoot) {
|
package/dist/preview/runner.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { type ControlKind, type TunnelState, type UAClass } from "
|
|
1
|
+
import { type ControlKind, type TunnelState, type UAClass } from "../tunnel/index.js";
|
|
2
2
|
import type { DiagEvent } from "@vincentt-xr/harness/events";
|
|
3
3
|
import { type EventTags } from "../relay/server.js";
|
|
4
4
|
import { type ResolvedConfig } from "../shared/config.js";
|
|
5
5
|
/** The path a 404 advisory names: the request's own path, without its query. */
|
|
6
6
|
export declare function requestPathOf(url: string | undefined): string;
|
|
7
|
+
/**
|
|
8
|
+
* The project root as the `/@fs/` check compares it: Vite writes `/@fs/C:/...`
|
|
9
|
+
* with forward slashes, so a Windows root holding backslashes would never match
|
|
10
|
+
* as inside, and a project under a dotted parent folder would get false 404s.
|
|
11
|
+
*/
|
|
12
|
+
export declare function hiddenPathRoot(realRoot: string): string;
|
|
7
13
|
/** Why a preview ended. Each maps to exactly one screen (Flow L20/L21). */
|
|
8
14
|
export type PreviewEndReason = "stopped"
|
|
9
15
|
/**
|
|
@@ -57,8 +63,10 @@ export interface StartPreviewOptions {
|
|
|
57
63
|
/** The API host + PAT. Resolved by the caller so the runner makes no policy. */
|
|
58
64
|
config: ResolvedConfig;
|
|
59
65
|
projectId: string;
|
|
60
|
-
/** App dev-serve port (default 5173). A server already here is REUSED
|
|
66
|
+
/** App dev-serve port (default 5173). A server already here is REUSED unless `appPortFresh`. */
|
|
61
67
|
appPort?: number;
|
|
68
|
+
/** appPort was picked for this preview, so the dev command always starts there. */
|
|
69
|
+
appPortFresh?: boolean;
|
|
62
70
|
relayPort?: number;
|
|
63
71
|
frontPort?: number;
|
|
64
72
|
/** Path routed to the relay instead of the app (default /__harness). */
|