page-harness 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -31
- package/README.zh-CN.md +36 -32
- package/dist/cli.js +145 -20
- package/dist/cli.js.map +1 -1
- package/dist/client/page/overlay.js +16 -16
- package/docs/dsh-preview-light.png +0 -0
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -2836,12 +2836,25 @@ var LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"])
|
|
|
2836
2836
|
function isLoopback(req) {
|
|
2837
2837
|
return LOOPBACK.has(req.socket.remoteAddress ?? "");
|
|
2838
2838
|
}
|
|
2839
|
+
function embedNext(raw) {
|
|
2840
|
+
if (!raw) return null;
|
|
2841
|
+
let u;
|
|
2842
|
+
try {
|
|
2843
|
+
u = new URL(raw, "http://localhost");
|
|
2844
|
+
} catch {
|
|
2845
|
+
return null;
|
|
2846
|
+
}
|
|
2847
|
+
if (u.origin !== "http://localhost") return null;
|
|
2848
|
+
if (!u.pathname.startsWith("/") || u.pathname.startsWith("//") || u.pathname.includes("\\")) return null;
|
|
2849
|
+
return u.pathname + u.search + u.hash;
|
|
2850
|
+
}
|
|
2839
2851
|
var Auth = class {
|
|
2840
2852
|
constructor(opts) {
|
|
2841
2853
|
this.opts = opts;
|
|
2842
2854
|
this.scheme = opts.publicScheme ?? "http";
|
|
2843
2855
|
this.cookieName = `__ph_${opts.controlPort}`;
|
|
2844
2856
|
this.appCookieName = `${this.cookieName}_app`;
|
|
2857
|
+
this.embedCookieName = `__ph_embed_${opts.controlPort}`;
|
|
2845
2858
|
const names = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
2846
2859
|
if (opts.host && opts.host !== "0.0.0.0" && opts.host !== "::") names.add(opts.host);
|
|
2847
2860
|
if (opts.host === "0.0.0.0" || opts.host === "::") {
|
|
@@ -2859,6 +2872,8 @@ var Auth = class {
|
|
|
2859
2872
|
cookieName;
|
|
2860
2873
|
/** Reviewer pass for the app port, so other machines only see the page through the invite. */
|
|
2861
2874
|
appCookieName;
|
|
2875
|
+
/** Proves a non-loopback browser exchanged the embed token. Scoped to the host, so both ports see it. */
|
|
2876
|
+
embedCookieName;
|
|
2862
2877
|
scheme;
|
|
2863
2878
|
hostnames;
|
|
2864
2879
|
/** Host header must name this machine and the port the request arrived on. */
|
|
@@ -2887,6 +2902,7 @@ var Auth = class {
|
|
|
2887
2902
|
* the owner session, and while sharing other machines get nothing (they need the invite link).
|
|
2888
2903
|
*/
|
|
2889
2904
|
issuePageSession(req, res) {
|
|
2905
|
+
if (!this.allowEmbed(req)) return null;
|
|
2890
2906
|
const who = this.identify(req);
|
|
2891
2907
|
if (who) return who;
|
|
2892
2908
|
if (this.sharing && !isLoopback(req)) return null;
|
|
@@ -2904,8 +2920,22 @@ var Auth = class {
|
|
|
2904
2920
|
res.appendHeader("Set-Cookie", `${this.appCookieName}=${team.sign(id)}; Path=/; HttpOnly; SameSite=Lax${this.secureAttr}; Max-Age=31536000`);
|
|
2905
2921
|
return { access: "reviewer", id };
|
|
2906
2922
|
}
|
|
2923
|
+
/** Non-loopback embed previews need the cookie from /__ph/embed. Loopback, including SSH forwards, stays open. */
|
|
2924
|
+
allowEmbed(req) {
|
|
2925
|
+
if (!this.opts.embedToken || isLoopback(req)) return true;
|
|
2926
|
+
const v = parseCookies(req.headers.cookie)[this.embedCookieName];
|
|
2927
|
+
return !!v && safeEqual(v, this.opts.embedToken);
|
|
2928
|
+
}
|
|
2929
|
+
acceptEmbedToken(token) {
|
|
2930
|
+
return !!this.opts.embedToken && safeEqual(token, this.opts.embedToken);
|
|
2931
|
+
}
|
|
2932
|
+
issueEmbedCookie(res) {
|
|
2933
|
+
if (!this.opts.embedToken) return;
|
|
2934
|
+
res.appendHeader("Set-Cookie", `${this.embedCookieName}=${this.opts.embedToken}; Path=/; HttpOnly; SameSite=Lax${this.secureAttr}`);
|
|
2935
|
+
}
|
|
2907
2936
|
/** App port: open locally; while sharing, other machines need the pass from the invite link. */
|
|
2908
2937
|
allowApp(req) {
|
|
2938
|
+
if (!this.allowEmbed(req)) return false;
|
|
2909
2939
|
if (!this.sharing || isLoopback(req)) return true;
|
|
2910
2940
|
const v = parseCookies(req.headers.cookie)[this.appCookieName];
|
|
2911
2941
|
return !!v && !!this.opts.team?.verify(v);
|
|
@@ -3511,7 +3541,26 @@ function addSource(values, source) {
|
|
|
3511
3541
|
if (!out.includes(source)) out.push(source);
|
|
3512
3542
|
return out;
|
|
3513
3543
|
}
|
|
3514
|
-
function
|
|
3544
|
+
function embedFrameAncestors(embedOrigins) {
|
|
3545
|
+
return `frame-ancestors 'self' ${embedOrigins.join(" ")}`;
|
|
3546
|
+
}
|
|
3547
|
+
function setFrameAncestors(dirs, embedOrigins) {
|
|
3548
|
+
const fa = dirs.find(([n]) => n === "frame-ancestors");
|
|
3549
|
+
if (embedOrigins.length) {
|
|
3550
|
+
const sources = ["'self'", ...embedOrigins];
|
|
3551
|
+
if (fa) fa[1] = sources;
|
|
3552
|
+
else dirs.push(["frame-ancestors", sources]);
|
|
3553
|
+
return;
|
|
3554
|
+
}
|
|
3555
|
+
if (fa) fa[1] = addSource(fa[1], "'self'");
|
|
3556
|
+
}
|
|
3557
|
+
function ensureEmbedFrameAncestors(csp, embedOrigins) {
|
|
3558
|
+
if (!embedOrigins.length) return csp;
|
|
3559
|
+
const dirs = parse(csp);
|
|
3560
|
+
setFrameAncestors(dirs, embedOrigins);
|
|
3561
|
+
return serialize(dirs);
|
|
3562
|
+
}
|
|
3563
|
+
function relaxCsp(csp, controlOrigin, embedOrigins = []) {
|
|
3515
3564
|
const dirs = parse(csp);
|
|
3516
3565
|
const get = (name) => dirs.find(([n]) => n === name);
|
|
3517
3566
|
const defaults = get("default-src")?.[1];
|
|
@@ -3542,8 +3591,7 @@ function relaxCsp(csp, controlOrigin) {
|
|
|
3542
3591
|
}
|
|
3543
3592
|
}
|
|
3544
3593
|
if (!framed && defaults) dirs.push(["frame-src", addSource([...defaults], controlOrigin)]);
|
|
3545
|
-
|
|
3546
|
-
if (fa) fa[1] = addSource(fa[1], "'self'");
|
|
3594
|
+
setFrameAncestors(dirs, embedOrigins);
|
|
3547
3595
|
return { csp: serialize(dirs), nonce, warning };
|
|
3548
3596
|
}
|
|
3549
3597
|
function escapeAttr(v) {
|
|
@@ -3554,12 +3602,12 @@ function scriptTag(nonce) {
|
|
|
3554
3602
|
return `<script src="${OVERLAY_PATH}" data-page-harness${n}></script>`;
|
|
3555
3603
|
}
|
|
3556
3604
|
var META_CSP = /<meta\b[^>]*http-equiv\s*=\s*["']?content-security-policy["']?[^>]*>/gi;
|
|
3557
|
-
function relaxMetaCsp(html, controlOrigin) {
|
|
3605
|
+
function relaxMetaCsp(html, controlOrigin, embedOrigins) {
|
|
3558
3606
|
let nonce;
|
|
3559
3607
|
const out = html.replace(META_CSP, (tag) => {
|
|
3560
3608
|
const m = /content\s*=\s*(["'])([\s\S]*?)\1/i.exec(tag);
|
|
3561
3609
|
if (!m) return tag;
|
|
3562
|
-
const r = relaxCsp(m[2].replace(/"/g, '"').replace(/'/g, "'"), controlOrigin);
|
|
3610
|
+
const r = relaxCsp(m[2].replace(/"/g, '"').replace(/'/g, "'"), controlOrigin, embedOrigins);
|
|
3563
3611
|
nonce = nonce ?? r.nonce;
|
|
3564
3612
|
return tag.replace(m[0], `content="${escapeAttr(r.csp)}"`);
|
|
3565
3613
|
});
|
|
@@ -3567,7 +3615,7 @@ function relaxMetaCsp(html, controlOrigin) {
|
|
|
3567
3615
|
}
|
|
3568
3616
|
function injectHtml(html, opts) {
|
|
3569
3617
|
if (html.includes("data-page-harness")) return html;
|
|
3570
|
-
const meta = relaxMetaCsp(html, opts.controlOrigin);
|
|
3618
|
+
const meta = relaxMetaCsp(html, opts.controlOrigin, opts.embedOrigins ?? []);
|
|
3571
3619
|
html = meta.html;
|
|
3572
3620
|
const tag = scriptTag(opts.nonce ?? meta.nonce);
|
|
3573
3621
|
const head = /<head\b[^>]*>/i.exec(html);
|
|
@@ -4558,6 +4606,7 @@ function decompress(body, encoding) {
|
|
|
4558
4606
|
function createProxy(opts) {
|
|
4559
4607
|
const { target } = opts;
|
|
4560
4608
|
const scheme = opts.scheme ?? "http";
|
|
4609
|
+
const embedOrigins = opts.embedOrigins ?? [];
|
|
4561
4610
|
const appOrigin = (req) => `${scheme}://${req.headers.host}`;
|
|
4562
4611
|
const secure = target.protocol === "https:";
|
|
4563
4612
|
const agent = secure ? new https.Agent({ keepAlive: true }) : new http.Agent({ keepAlive: true });
|
|
@@ -4604,8 +4653,14 @@ function createProxy(opts) {
|
|
|
4604
4653
|
if (k === "set-cookie") out[k] = v.map((c2) => rewriteSetCookie(c2, scheme === "http" && (secure || relay2?.protocol === "https:")));
|
|
4605
4654
|
else if (k === "location") out[k] = rewriteLocation(String(v), req, relay2);
|
|
4606
4655
|
else if (k === "strict-transport-security") continue;
|
|
4656
|
+
else if (k === "x-frame-options" && embedOrigins.length) continue;
|
|
4607
4657
|
else out[k] = v;
|
|
4608
4658
|
}
|
|
4659
|
+
if (embedOrigins.length) {
|
|
4660
|
+
const csp = out["content-security-policy"];
|
|
4661
|
+
if (typeof csp === "string") out["content-security-policy"] = ensureEmbedFrameAncestors(csp, embedOrigins);
|
|
4662
|
+
else if (csp === void 0) out["content-security-policy"] = embedFrameAncestors(embedOrigins);
|
|
4663
|
+
}
|
|
4609
4664
|
if (html) {
|
|
4610
4665
|
delete out["content-length"];
|
|
4611
4666
|
delete out["content-encoding"];
|
|
@@ -4616,7 +4671,7 @@ function createProxy(opts) {
|
|
|
4616
4671
|
function errorPage(res, req, err) {
|
|
4617
4672
|
const body = injectHtml(
|
|
4618
4673
|
`<!doctype html><html><head><meta charset="utf-8"><title>Page Harness</title></head><body style="font:14px system-ui;padding:48px;color:#444;background:#fafafa"><h2 style="margin:0 0 8px">Waiting for ${escapeHtml(target.origin)}</h2><p>The target is not reachable yet (${escapeHtml(err.message)}). This page retries automatically. You can still open the chat to ask the agent to start it.</p><script>setTimeout(function(){location.reload()},2500)</script></body></html>`,
|
|
4619
|
-
{ controlOrigin: opts.controlOrigin(req) }
|
|
4674
|
+
{ controlOrigin: opts.controlOrigin(req), embedOrigins }
|
|
4620
4675
|
);
|
|
4621
4676
|
if (!res.headersSent) res.writeHead(502, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
|
|
4622
4677
|
res.end(body);
|
|
@@ -4688,7 +4743,7 @@ function createProxy(opts) {
|
|
|
4688
4743
|
for (const h of ["content-security-policy", "content-security-policy-report-only"]) {
|
|
4689
4744
|
const v = headers[h];
|
|
4690
4745
|
if (typeof v !== "string") continue;
|
|
4691
|
-
const r = relaxCsp(v, controlOrigin);
|
|
4746
|
+
const r = relaxCsp(v, controlOrigin, embedOrigins);
|
|
4692
4747
|
headers[h] = r.csp;
|
|
4693
4748
|
nonce = nonce ?? r.nonce;
|
|
4694
4749
|
if (r.warning && !warned.has(r.warning)) {
|
|
@@ -4698,7 +4753,7 @@ function createProxy(opts) {
|
|
|
4698
4753
|
}
|
|
4699
4754
|
let html = body.toString("latin1");
|
|
4700
4755
|
html = html.split(target.origin).join(appOrigin(req));
|
|
4701
|
-
html = injectHtml(html, { nonce, controlOrigin });
|
|
4756
|
+
html = injectHtml(html, { nonce, controlOrigin, embedOrigins });
|
|
4702
4757
|
const out = Buffer.from(html, "latin1");
|
|
4703
4758
|
headers["content-length"] = String(out.length);
|
|
4704
4759
|
res.writeHead(up.statusCode ?? 200, up.statusMessage, headers);
|
|
@@ -4877,7 +4932,8 @@ async function startServers(o) {
|
|
|
4877
4932
|
const appDir = path13.join(dir, "app");
|
|
4878
4933
|
const controlOrigin = (req) => o.auth.origin(hostname(req), o.controlPort);
|
|
4879
4934
|
const appOrigin = (req) => o.auth.origin(hostname(req), o.appPort);
|
|
4880
|
-
const
|
|
4935
|
+
const embedOrigins = o.embedOrigins ?? [];
|
|
4936
|
+
const proxy = o.target ? createProxy({ target: o.target, cookieName: o.auth.cookieName, controlOrigin, keepHost: o.keepHost, scheme: o.auth.scheme, embedOrigins }) : null;
|
|
4881
4937
|
const pageScripts = {
|
|
4882
4938
|
[OVERLAY_PATH]: "overlay.js",
|
|
4883
4939
|
"/__ph/page-control.js": "page-control.js",
|
|
@@ -4895,8 +4951,15 @@ async function startServers(o) {
|
|
|
4895
4951
|
const serveApp = (req, res) => {
|
|
4896
4952
|
if (!proxy || !o.target) return send(res, 500, "page-harness: proxy is not running");
|
|
4897
4953
|
if (!o.auth.checkHost(req, o.appPort)) return send(res, 421, "page-harness: unexpected Host header");
|
|
4898
|
-
if (!o.auth.allowApp(req)) return noAccess(res, "Open this page with the invite link from the person running Page Harness.<br>\u8BF7\u4F7F\u7528 Page Harness \u53D1\u8D77\u4EBA\u5206\u4EAB\u7684\u9080\u8BF7\u94FE\u63A5\u6253\u5F00\u3002");
|
|
4899
4954
|
const url = new URL(req.url ?? "/", "http://x");
|
|
4955
|
+
if (url.pathname === "/__ph/embed" && req.method === "GET") {
|
|
4956
|
+
const next = embedNext(url.searchParams.get("next"));
|
|
4957
|
+
if (!o.auth.acceptEmbedToken(url.searchParams.get("t") ?? "") || !next) return noAccess(res, "This preview link is not valid.<br>\u9884\u89C8\u94FE\u63A5\u65E0\u6548\u3002");
|
|
4958
|
+
o.auth.issueEmbedCookie(res);
|
|
4959
|
+
res.writeHead(302, { Location: next, "Cache-Control": "no-store", "Referrer-Policy": "no-referrer" });
|
|
4960
|
+
return res.end();
|
|
4961
|
+
}
|
|
4962
|
+
if (!o.auth.allowApp(req)) return noAccess(res, "Open this page with the invite link from the person running Page Harness.<br>\u8BF7\u4F7F\u7528 Page Harness \u53D1\u8D77\u4EBA\u5206\u4EAB\u7684\u9080\u8BF7\u94FE\u63A5\u6253\u5F00\u3002");
|
|
4900
4963
|
if (url.pathname.startsWith("/__ph/")) {
|
|
4901
4964
|
if (url.pathname.startsWith(RELAY_PREFIX)) {
|
|
4902
4965
|
if (!proxy.relay(req, res)) send(res, 403, "page-harness: relay only reaches subdomains of the target site");
|
|
@@ -4908,7 +4971,7 @@ async function startServers(o) {
|
|
|
4908
4971
|
if (!existsSync9(p)) return send(res, 503, `/* page-harness: ${file} missing, run npm run build */`, "text/javascript");
|
|
4909
4972
|
let body = readFileSync9(p, "utf8");
|
|
4910
4973
|
if (file === "overlay.js") {
|
|
4911
|
-
body = `window.__PH_CONFIG=${JSON.stringify({ controlOrigin: controlOrigin(req), appPort: o.appPort, target: o.target.host, relay: proxy.site, ...o.noAgent ? { noAgent: true } : {}, ...o.lang ? { lang: o.lang } : {} })};
|
|
4974
|
+
body = `window.__PH_CONFIG=${JSON.stringify({ controlOrigin: controlOrigin(req), appPort: o.appPort, target: o.target.host, relay: proxy.site, ...o.noAgent ? { noAgent: true } : {}, ...o.lang ? { lang: o.lang } : {}, ...embedOrigins.length ? { embed: embedOrigins } : {} })};
|
|
4912
4975
|
` + body;
|
|
4913
4976
|
}
|
|
4914
4977
|
return send(res, 200, body, "text/javascript; charset=utf-8", { "Cross-Origin-Resource-Policy": "same-origin" });
|
|
@@ -4951,7 +5014,7 @@ async function startServers(o) {
|
|
|
4951
5014
|
if (!existsSync9(file)) return send(res, 503, "page-harness: client build missing, run npm run build");
|
|
4952
5015
|
const html = readFileSync9(file, "utf8").replace("<html", `<html data-app-origin="${appOrigin(req)}"`);
|
|
4953
5016
|
send(res, 200, html, "text/html; charset=utf-8", {
|
|
4954
|
-
"Content-Security-Policy": panelCsp(req, page === "panel" ? appOrigin(req) : "'none'"),
|
|
5017
|
+
"Content-Security-Policy": panelCsp(req, page === "panel" ? [appOrigin(req), ...embedOrigins].join(" ") : "'none'"),
|
|
4955
5018
|
"Referrer-Policy": "no-referrer",
|
|
4956
5019
|
"Cross-Origin-Opener-Policy": page === "history" ? "same-origin" : "unsafe-none"
|
|
4957
5020
|
});
|
|
@@ -4960,6 +5023,7 @@ async function startServers(o) {
|
|
|
4960
5023
|
const control = http2.createServer(async (req, res) => {
|
|
4961
5024
|
try {
|
|
4962
5025
|
if (!o.auth.checkHost(req, o.controlPort)) return send(res, 421, "page-harness: unexpected Host header");
|
|
5026
|
+
if (!o.auth.allowEmbed(req)) return noAccess(res, "Open this preview from the embedding page.<br>\u8BF7\u4ECE\u5D4C\u5165\u9884\u89C8\u7684\u9875\u9762\u6253\u5F00\u3002");
|
|
4963
5027
|
const url = new URL(req.url ?? "/", "http://x");
|
|
4964
5028
|
const p = url.pathname;
|
|
4965
5029
|
if (req.method === "OPTIONS" && (p === "/__ph/overlay.js" || p.startsWith("/__ph/api/review"))) {
|
|
@@ -5039,7 +5103,7 @@ async function startServers(o) {
|
|
|
5039
5103
|
};
|
|
5040
5104
|
try {
|
|
5041
5105
|
const url = new URL(req.url ?? "/", "http://x");
|
|
5042
|
-
if (!o.auth.checkHost(req, o.controlPort) || url.pathname !== "/__ph/ws" || o.auth.checkWs(req)) return deny();
|
|
5106
|
+
if (!o.auth.checkHost(req, o.controlPort) || !o.auth.allowEmbed(req) || url.pathname !== "/__ph/ws" || o.auth.checkWs(req)) return deny();
|
|
5043
5107
|
const who = o.auth.identify(req);
|
|
5044
5108
|
if (!who) return deny();
|
|
5045
5109
|
wss.handleUpgrade(req, socket, head, (ws) => attachClient(ws, who));
|
|
@@ -6580,7 +6644,10 @@ async function startHarness(o) {
|
|
|
6580
6644
|
}
|
|
6581
6645
|
}
|
|
6582
6646
|
const team = new Team(dataDir, !!o.share);
|
|
6583
|
-
const
|
|
6647
|
+
const wide = o.host === "0.0.0.0" || o.host === "::";
|
|
6648
|
+
const embedToken = o.embedOrigins?.length && !o.share && wide ? randomToken(18) : void 0;
|
|
6649
|
+
const extraHosts = [...o.allowHosts ?? [], ...o.publicHost ? [o.publicHost] : []];
|
|
6650
|
+
const auth = new Auth({ host: o.host, appPort: o.appPort ?? 0, controlPort: o.controlPort, extraHosts, team, publicScheme: o.publicScheme, embedToken });
|
|
6584
6651
|
const artifacts = new ArtifactStore(dataDir);
|
|
6585
6652
|
const uploads = new Uploads(dataDir);
|
|
6586
6653
|
const mode = noAgent ? "review" : o.mode ?? detectMode(o.target);
|
|
@@ -6590,8 +6657,9 @@ async function startHarness(o) {
|
|
|
6590
6657
|
const review = new ReviewStore(dataDir, o.target?.host ?? "");
|
|
6591
6658
|
const bookmarkletToken = randomToken(18);
|
|
6592
6659
|
const shownHost = o.host === "0.0.0.0" || o.host === "::" || o.host === "127.0.0.1" ? "localhost" : o.host;
|
|
6593
|
-
const
|
|
6594
|
-
const
|
|
6660
|
+
const reachHost = o.publicHost || shownHost;
|
|
6661
|
+
const appUrl = auth.origin(reachHost, o.appPort || o.controlPort);
|
|
6662
|
+
const shareHost = o.publicHost || (o.host === "0.0.0.0" || o.host === "::" ? lanAddress() ?? shownHost : shownHost);
|
|
6595
6663
|
const shareUrl = o.share ? `${auth.origin(shareHost, o.controlPort)}/__ph/join?t=${team.invite}` : void 0;
|
|
6596
6664
|
const gateway = new Gateway({
|
|
6597
6665
|
project: o.project,
|
|
@@ -6631,12 +6699,13 @@ async function startHarness(o) {
|
|
|
6631
6699
|
noAgent,
|
|
6632
6700
|
bookmarklet,
|
|
6633
6701
|
bookmarkletToken,
|
|
6634
|
-
lang: o.lang
|
|
6702
|
+
lang: o.lang,
|
|
6703
|
+
embedOrigins: o.embedOrigins
|
|
6635
6704
|
});
|
|
6636
6705
|
let closed = false;
|
|
6637
6706
|
return {
|
|
6638
6707
|
appUrl: bookmarklet ? auth.origin(shownHost, o.controlPort) : appUrl,
|
|
6639
|
-
controlUrl: auth.origin(shownHost, o.controlPort),
|
|
6708
|
+
controlUrl: auth.origin(bookmarklet ? shownHost : reachHost, o.controlPort),
|
|
6640
6709
|
agents,
|
|
6641
6710
|
defaultAgent,
|
|
6642
6711
|
mode,
|
|
@@ -6644,6 +6713,7 @@ async function startHarness(o) {
|
|
|
6644
6713
|
bookmarklet,
|
|
6645
6714
|
noAgent,
|
|
6646
6715
|
bookmarkletToken,
|
|
6716
|
+
embedToken,
|
|
6647
6717
|
gateway,
|
|
6648
6718
|
auth,
|
|
6649
6719
|
async close() {
|
|
@@ -6712,6 +6782,11 @@ Options
|
|
|
6712
6782
|
--lang <zh|en> Home page and dock language. Omit it and each browser keeps its own.
|
|
6713
6783
|
--share Listen on the network and print an invite link: teammates join as reviewers
|
|
6714
6784
|
(comment, reply, resolve, approve, edit text/style in review mode; never the agent)
|
|
6785
|
+
--public-host <name> Hostname or IP teammates use to reach this machine. Used in the invite link and
|
|
6786
|
+
accepted as a Host header (default: the first LAN address)
|
|
6787
|
+
--json Print one JSON line with the URLs to stdout once the servers are listening
|
|
6788
|
+
--embed-origin <url> Let this origin show the page in an iframe (repeatable), e.g. an IDE preview pane.
|
|
6789
|
+
Pick \u2192 Quote then posts the element to that window instead of the chat
|
|
6715
6790
|
--verbose / --quiet
|
|
6716
6791
|
-v, --version
|
|
6717
6792
|
-h, --help
|
|
@@ -6796,6 +6871,9 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
6796
6871
|
"no-agent": { type: "boolean" },
|
|
6797
6872
|
lang: { type: "string" },
|
|
6798
6873
|
share: { type: "boolean" },
|
|
6874
|
+
"public-host": { type: "string" },
|
|
6875
|
+
json: { type: "boolean" },
|
|
6876
|
+
"embed-origin": { type: "string", multiple: true },
|
|
6799
6877
|
verbose: { type: "boolean" },
|
|
6800
6878
|
quiet: { type: "boolean" },
|
|
6801
6879
|
version: { type: "boolean", short: "v" },
|
|
@@ -6813,6 +6891,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
6813
6891
|
if (values.verbose) log.setVerbose(true);
|
|
6814
6892
|
if (values.quiet) log.setQuiet(true);
|
|
6815
6893
|
const lang = parseLang(values.lang);
|
|
6894
|
+
const publicHost = publicHostOf(values["public-host"]);
|
|
6816
6895
|
const rawTarget = positionals[0];
|
|
6817
6896
|
if (!rawTarget) {
|
|
6818
6897
|
if (values.source) throw new Error("--source needs a frontend URL");
|
|
@@ -6829,9 +6908,11 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
6829
6908
|
controlPort: controlPort2,
|
|
6830
6909
|
allowHosts: values["allow-host"],
|
|
6831
6910
|
publicScheme: schemeOf(values["public-scheme"]),
|
|
6911
|
+
publicHost,
|
|
6832
6912
|
noAgent: true,
|
|
6833
6913
|
lang
|
|
6834
6914
|
});
|
|
6915
|
+
if (values.json) printReady(h2, project2);
|
|
6835
6916
|
log.info(`v${version()}`);
|
|
6836
6917
|
process.stderr.write(
|
|
6837
6918
|
[
|
|
@@ -6865,6 +6946,8 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
6865
6946
|
allowHosts: values["allow-host"],
|
|
6866
6947
|
keepHost: values["keep-host"],
|
|
6867
6948
|
publicScheme,
|
|
6949
|
+
publicHost,
|
|
6950
|
+
embedOrigins: embedOriginsOf(values["embed-origin"]),
|
|
6868
6951
|
agentPaths: {
|
|
6869
6952
|
claude: values["claude-path"],
|
|
6870
6953
|
codex: values["codex-path"],
|
|
@@ -6878,6 +6961,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
6878
6961
|
noAgent,
|
|
6879
6962
|
lang
|
|
6880
6963
|
});
|
|
6964
|
+
if (values.json) printReady(h, project, target);
|
|
6881
6965
|
const agentLine = h.agents.map((a) => a.available ? `${a.id === h.defaultAgent ? log.bold(a.id) : a.id}${a.version ? ` ${log.dim(a.version)}` : ""}` : log.dim(`${a.id} (not found)`)).join(" ");
|
|
6882
6966
|
log.info(`v${version()}`);
|
|
6883
6967
|
const modeLine = h.noAgent ? `review ${log.dim("(no agent: Pick and Notes only)")}` : h.mode === "review" ? `review ${log.dim("(no source: notes, page changes, Live candidates as page changes)")}` : "source";
|
|
@@ -6902,6 +6986,45 @@ function schemeOf(raw) {
|
|
|
6902
6986
|
if (s !== "http" && s !== "https") throw new Error("--public-scheme must be http or https");
|
|
6903
6987
|
return s;
|
|
6904
6988
|
}
|
|
6989
|
+
function publicHostOf(raw) {
|
|
6990
|
+
const s = raw?.trim();
|
|
6991
|
+
if (!s) return void 0;
|
|
6992
|
+
if (s.includes("://") || s.includes("/")) throw new Error("--public-host must be a hostname or IP address, without scheme or port");
|
|
6993
|
+
const bare = s.replace(/^\[|\]$/g, "");
|
|
6994
|
+
if (net.isIP(bare) === 6 && (s.startsWith("[") || bare.includes(":"))) return `[${bare.toLowerCase()}]`;
|
|
6995
|
+
if (net.isIP(s) === 4) return s;
|
|
6996
|
+
if (s.includes(":") || !/^[A-Za-z0-9.-]+$/.test(s)) throw new Error("--public-host must be a hostname or IP address, without scheme or port");
|
|
6997
|
+
return s.toLowerCase();
|
|
6998
|
+
}
|
|
6999
|
+
function embedOriginsOf(raw) {
|
|
7000
|
+
if (!raw?.length) return void 0;
|
|
7001
|
+
return raw.map((s) => {
|
|
7002
|
+
let u;
|
|
7003
|
+
try {
|
|
7004
|
+
u = new URL(s.trim());
|
|
7005
|
+
} catch {
|
|
7006
|
+
throw new Error(`--embed-origin must be an origin like http://localhost:3080, got "${s}"`);
|
|
7007
|
+
}
|
|
7008
|
+
if (u.protocol !== "http:" && u.protocol !== "https:" || u.origin !== s.trim().replace(/\/$/, "")) throw new Error(`--embed-origin must be an origin like http://localhost:3080, got "${s}"`);
|
|
7009
|
+
return u.origin;
|
|
7010
|
+
});
|
|
7011
|
+
}
|
|
7012
|
+
function printReady(h, project, target) {
|
|
7013
|
+
const ready = {
|
|
7014
|
+
event: "ready",
|
|
7015
|
+
version: version(),
|
|
7016
|
+
pid: process.pid,
|
|
7017
|
+
appUrl: h.appUrl,
|
|
7018
|
+
controlUrl: h.controlUrl,
|
|
7019
|
+
shareUrl: h.shareUrl ?? null,
|
|
7020
|
+
mode: h.mode,
|
|
7021
|
+
noAgent: h.noAgent,
|
|
7022
|
+
project,
|
|
7023
|
+
target: target?.href ?? null,
|
|
7024
|
+
...h.embedToken ? { embedToken: h.embedToken } : {}
|
|
7025
|
+
};
|
|
7026
|
+
process.stdout.write(JSON.stringify(ready) + "\n");
|
|
7027
|
+
}
|
|
6905
7028
|
function installShutdown(h) {
|
|
6906
7029
|
let closing = false;
|
|
6907
7030
|
const shutdown = async () => {
|
|
@@ -6934,7 +7057,9 @@ if (isEntry || process.env.PH_CLI === "1") {
|
|
|
6934
7057
|
});
|
|
6935
7058
|
}
|
|
6936
7059
|
export {
|
|
7060
|
+
embedOriginsOf,
|
|
6937
7061
|
main,
|
|
6938
|
-
normalizeTarget
|
|
7062
|
+
normalizeTarget,
|
|
7063
|
+
publicHostOf
|
|
6939
7064
|
};
|
|
6940
7065
|
//# sourceMappingURL=cli.js.map
|