feat(daemon)!: phone-first binding and a two-step pairing flow
Implements ADR 0001 (docs/adr/0001-phone-first-pairing.md): the console is
meant to be opened from a phone, so reachability stops being a mode and the
pairing link becomes the only access control that matters.
Binding / CORS
- `PI2_HOST` defaults to `0.0.0.0`; `PI2_ACCESS_MODE` (local|lan|tailscale) is
deleted, together with its parser, `AccessMode` type and LAN probe.
- `src/core/network.ts` is the single source of truth for reachable addresses:
kind classification, ordering (public → lan → other → tailscale → loopback,
physical NICs first, link-local skipped), bind-aware `networkBases()`,
`primaryBase()` and `localOrigins()`. Config, the pairing route, doctor and
the CLI all consume it, so the CORS allowlist always matches the pairing URL.
- `/api/v1/info` and `daemon.json` report `host` instead of `access`; doctor's
`access` check becomes `bind` (loopback ok, wildcard warns unless an `https:`
public URL is configured).
Pairing
- `POST /api/v1/pair` only mints, requires a token, and returns the code, the
chosen URL, the expiry, the nonce, the QR matrix and every usable base.
`base` may pin one of those bases; anything else is a 400.
- `POST /api/v1/pair/redeem` is the public half, rate limited per client
(5/min) and globally (50/h) → 429 `E_RATE_LIMITED` with `retry-after`.
- `GET /pair/:code` answers 302 to `/connect?code=…&auto=1`, so a scanned link
needs no JavaScript to reach the console.
- `src/core/qr.ts` (moved out of the CLI) is the one encoder: byte mode, EC
level M, versions 1–10, rows without a quiet zone, shared by the HTTP mint
response and the terminal renderer.
- `pi2 pairing` prints a human report plus a half-block terminal QR and keeps
`--base`; `--json` and `--public-url` are gone (the Neovim client calls the
HTTP mint directly).
Device scopes
- `Scope`, `SCOPES`, `DEFAULT_SCOPES`, `DeviceRecord.scopes` and the `scopes`
field in device/hello payloads are removed: nothing enforced them, and a
paired device now holds the same rights as the local browser. A permission
model, if wanted, gets its own ADR.
Breaking: `PI2_ACCESS_MODE`, `info.access`, `pi2 status --json`'s `access`,
`pi2 pairing --json`/`--public-url`, `POST /api/v1/pair {code}`, and the
`scopes` field. All in-repo callers and the e2e drivers are updated; the plugin
side (`:PiWebAccess`, `env.PI2_ACCESS_MODE`, text-format parsing) follows in
pi2.nvim.
Verification: root typecheck clean; 369/370 tests (the one failure is the
pre-existing supervisor timing flake, 24/24 in isolation ×3); `smoke.sh` green;
web suite 299/299; visual matrix 24/24.
This commit is contained in:
1 parent
3789394c85
commit
a57c874095
34 files changed
+2157
-488
No files matched your search
+2
-2
@@ -45,7 +45,7 @@ Options:
|
||||
Environment:
|
||||
PI2_PORT, PI2_HOST, PI2_STATIC_DIR, PI2_ORIGINS, PI2_RUNTIME_DIR,
|
||||
PI2_DATA_DIR, PI2_STATE_DIR, PI2_LOG_LEVEL, PI2_WORKSPACE_ROOTS,
|
||||
PI2_ACCESS_MODE (local|lan|tailscale), PI2_PUBLIC_URL
|
||||
PI2_PUBLIC_URL
|
||||
|
||||
Runtime files ($PI2_RUNTIME_DIR):
|
||||
d.sock plugin unix socket (nvim → daemon)
|
||||
@@ -181,7 +181,7 @@ export async function main(argv: readonly string[], ioOptions: RunDaemonOptions
|
||||
daemonId,
|
||||
startedAt: Date.now(),
|
||||
protocolVersion: PROTOCOL_VERSION,
|
||||
access: config.access,
|
||||
host: config.host,
|
||||
publicUrl: config.publicUrl,
|
||||
},
|
||||
});
|
||||
|
||||
+22
-26
@@ -11,7 +11,8 @@ import { homedir, platform as osPlatform } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { DEFAULT_PORT, loadConfig, type AccessMode } from "../config.js";
|
||||
import { DEFAULT_HOST, DEFAULT_PORT, describeHost, loadConfig } from "../config.js";
|
||||
import { isLoopbackHost } from "../core/network.js";
|
||||
import { daemonSocketPath, runtimeDir } from "../core/paths.js";
|
||||
import { PROTOCOL_VERSION } from "../protocol/types.js";
|
||||
import { formatTable } from "./util.js";
|
||||
@@ -43,8 +44,7 @@ export interface BinaryProbe {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface AccessModeContext {
|
||||
mode: AccessMode;
|
||||
export interface BindContext {
|
||||
host: string;
|
||||
port: number;
|
||||
publicUrl: string | null;
|
||||
@@ -62,7 +62,7 @@ export interface DoctorContext {
|
||||
socket: { path: string; exists: boolean };
|
||||
daemon: { reachable: boolean; port?: number; protocolVersion?: number; error?: string };
|
||||
port: { configured: number; bound: boolean };
|
||||
access: AccessModeContext;
|
||||
bind: BindContext;
|
||||
serviceManager: { name: "systemd" | "launchd"; available: boolean; detail?: string };
|
||||
linger: { checked: boolean; enabled?: boolean; detail?: string };
|
||||
webDist: { path: string; exists: boolean };
|
||||
@@ -217,27 +217,24 @@ export function checkPort(probe: DoctorContext["port"]): DoctorCheck {
|
||||
return { name: "port", status: "ok", detail: `${probe.configured} free` };
|
||||
}
|
||||
|
||||
function isLoopbackHost(host: string): boolean {
|
||||
return host === "127.0.0.1" || host === "::1" || host === "localhost";
|
||||
}
|
||||
|
||||
/**
|
||||
* `access`: local is fine; lan/tailscale warn because the daemon has no TLS of
|
||||
* its own, and fail when a non-loopback bind is exposed without a public URL.
|
||||
* `bind`: where the daemon listens. Loopback is private; anything else is
|
||||
* reachable from the LAN, which is the point of the console — so a non-loopback
|
||||
* bind only *warns*. Access is gated by pairing codes and per-device tokens,
|
||||
* and an `https:` public URL (e.g. behind `tailscale serve`) covers TLS.
|
||||
*/
|
||||
export function checkAccess(probe: AccessModeContext): DoctorCheck {
|
||||
if (probe.mode === "local") return { name: "access", status: "ok", detail: "local (loopback only)" };
|
||||
|
||||
const publicSuffix = probe.publicUrl === null ? "" : `, public ${probe.publicUrl}`;
|
||||
const detail = `${probe.mode} (bind ${probe.host}/${probe.port}${publicSuffix})`;
|
||||
if (probe.publicUrl === null && !isLoopbackHost(probe.host)) {
|
||||
return { name: "access", status: "fail", detail };
|
||||
export function checkBind(probe: BindContext): DoctorCheck {
|
||||
const suffix = probe.publicUrl === null ? "" : `, public ${probe.publicUrl}`;
|
||||
if (isLoopbackHost(probe.host)) {
|
||||
return { name: "bind", status: "ok", detail: `${probe.host}/${probe.port} (loopback only)${suffix}` };
|
||||
}
|
||||
const detail = `${describeHost(probe.host)}/${probe.port}${suffix}`;
|
||||
const tls = probe.publicUrl !== null && probe.publicUrl.startsWith("https:");
|
||||
if (tls) return { name: "bind", status: "ok", detail };
|
||||
return {
|
||||
name: "access",
|
||||
name: "bind",
|
||||
status: "warn",
|
||||
detail: tls ? detail : `${detail} — no TLS, prefer \`tailscale serve\``,
|
||||
detail: `${detail} — no TLS; pairing codes gate access, set PI2_HOST=127.0.0.1 to restrict`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -286,7 +283,7 @@ export function defaultProbes(ctx: DoctorContext): DoctorProbe[] {
|
||||
{ name: "socket", run: () => checkSocket(ctx.socket, ctx.daemon.reachable) },
|
||||
{ name: "daemon", run: () => checkDaemon(ctx.daemon) },
|
||||
{ name: "port", run: () => checkPort(ctx.port) },
|
||||
{ name: "access", run: () => checkAccess(ctx.access) },
|
||||
{ name: "bind", run: () => checkBind(ctx.bind) },
|
||||
{ name: "service-manager", run: () => checkServiceManager(ctx.serviceManager) },
|
||||
...(isLinux ? [{ name: "linger", run: () => checkLinger(ctx.linger) }] : []),
|
||||
{ name: "web-dist", run: () => checkWebDist(ctx.webDist) },
|
||||
@@ -370,15 +367,14 @@ function statOrUndefined(path: string): { exists: boolean; mode: number | undefi
|
||||
}
|
||||
}
|
||||
|
||||
/** Best-effort access context; an unparsable environment reports `local`. */
|
||||
function accessContext(env: NodeJS.ProcessEnv, port: number): AccessModeContext {
|
||||
/** Best-effort bind context; an unparsable environment reports the default bind. */
|
||||
function bindContext(env: NodeJS.ProcessEnv, port: number): BindContext {
|
||||
try {
|
||||
const config = loadConfig(env);
|
||||
return { mode: config.access, host: config.host, port, publicUrl: config.publicUrl };
|
||||
return { host: config.host, port, publicUrl: config.publicUrl };
|
||||
} catch {
|
||||
return {
|
||||
mode: "local",
|
||||
host: env.PI2_HOST?.trim() || "127.0.0.1",
|
||||
host: env.PI2_HOST?.trim() || DEFAULT_HOST,
|
||||
port,
|
||||
publicUrl: env.PI2_PUBLIC_URL?.trim().replace(/\/+$/, "") || null,
|
||||
};
|
||||
@@ -472,7 +468,7 @@ export async function collectContext(options: DoctorOptions = {}): Promise<Docto
|
||||
socket: { path: socketPath, exists: existsSync(socketPath) },
|
||||
daemon,
|
||||
port: { configured: daemon.port ?? configuredPort, bound: daemon.reachable },
|
||||
access: accessContext(env, daemon.port ?? configuredPort),
|
||||
bind: bindContext(env, daemon.port ?? configuredPort),
|
||||
serviceManager,
|
||||
linger,
|
||||
webDist: { path: env.PI2_STATIC_DIR?.trim() || defaultWebDist(), exists: existsSync(env.PI2_STATIC_DIR?.trim() || defaultWebDist()) },
|
||||
|
||||
+6
-11
@@ -6,11 +6,11 @@
|
||||
*
|
||||
* ```jsonc
|
||||
* {"pid":1234,"bootId":"…","port":7676,"daemonId":"d-…","startedAt":1733,"protocolVersion":1,
|
||||
* "access":"local","publicUrl":null}
|
||||
* "host":"0.0.0.0","publicUrl":null}
|
||||
* ```
|
||||
*
|
||||
* `access`/`publicUrl` are optional so readers built before the access modes
|
||||
* keep working.
|
||||
* `host`/`publicUrl` are optional so readers built before them keep working; a
|
||||
* legacy `access` field is simply ignored.
|
||||
*
|
||||
* The lock is created with `wx` (atomic: only one daemon wins) and is
|
||||
* considered **stale** when the pid is gone or the recorded boot id differs
|
||||
@@ -23,7 +23,6 @@ import { existsSync, readFileSync, renameSync, unlinkSync, writeFileSync } from
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { dirname, join } from "node:path";
|
||||
import { daemonLockPath, ensureDir, runtimeDir } from "../core/paths.js";
|
||||
import { ACCESS_MODES, type AccessMode } from "../config.js";
|
||||
|
||||
export const LOCK_FILE = "daemon.lock";
|
||||
export const DAEMON_JSON_FILE = "daemon.json";
|
||||
@@ -35,8 +34,8 @@ export interface DaemonLock {
|
||||
daemonId: string;
|
||||
startedAt: number;
|
||||
protocolVersion: number;
|
||||
/** Optional: written by daemons that know about access modes. */
|
||||
access?: AccessMode;
|
||||
/** Optional: the bind address the daemon actually used. */
|
||||
host?: string;
|
||||
/** Optional: external base URL (or explicit `null` when unset). */
|
||||
publicUrl?: string | null;
|
||||
}
|
||||
@@ -88,10 +87,6 @@ export function isPidAlive(pid: number): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function isAccessMode(value: unknown): value is AccessMode {
|
||||
return typeof value === "string" && (ACCESS_MODES as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
function isLock(value: unknown): value is DaemonLock {
|
||||
if (typeof value !== "object" || value === null) return false;
|
||||
const candidate = value as Partial<DaemonLock>;
|
||||
@@ -105,7 +100,7 @@ function isLock(value: unknown): value is DaemonLock {
|
||||
candidate.daemonId !== "" &&
|
||||
typeof candidate.startedAt === "number" &&
|
||||
typeof candidate.protocolVersion === "number" &&
|
||||
(candidate.access === undefined || isAccessMode(candidate.access)) &&
|
||||
(candidate.host === undefined || typeof candidate.host === "string") &&
|
||||
(candidate.publicUrl === undefined || candidate.publicUrl === null || typeof candidate.publicUrl === "string")
|
||||
);
|
||||
}
|
||||
|
||||
+136
-33
@@ -21,7 +21,6 @@ import { platform as osPlatform } from "node:os";
|
||||
import { runtimeDir } from "../core/paths.js";
|
||||
import type { InstanceResourcesSnapshot } from "../core/interfaces.js";
|
||||
import type { WorkspaceInfo } from "../protocol/types.js";
|
||||
import { PROTOCOL_VERSION } from "../protocol/types.js";
|
||||
import { main as runDaemonMain } from "./daemon.js";
|
||||
import { readDaemonJson, type DaemonLock } from "./lock.js";
|
||||
import { cliTokenPath, readCliToken } from "./token.js";
|
||||
@@ -54,15 +53,17 @@ Usage:
|
||||
pi2 status [--json] daemon info, instances, resources, health
|
||||
pi2 open [--print] [--no-browser] open the web console signed in (local only)
|
||||
pi2 doctor [--json] environment checks
|
||||
pi2 pairing [--public-url <url>] create a pairing code (URL + code + QR payload)
|
||||
pi2 pairing [--base <url>] create a pairing code (URL + code + QR)
|
||||
pi2 install-service [--dry-run|--write] systemd user unit / LaunchAgent
|
||||
pi2 uninstall-service [--dry-run|--write] remove the unit
|
||||
pi2 --version | --help
|
||||
|
||||
\`pi2 open\` flags: --print prints the URL only; --no-browser prints it instead
|
||||
of launching a browser (--print implies --no-browser).
|
||||
\`pi2 pairing\` flags: --public-url <url> rebuilds the URL on that public base
|
||||
(defaults to daemon.json's publicUrl, then PI2_PUBLIC_URL).
|
||||
\`pi2 pairing\` flags: --base <url> pins the link to one of the addresses the
|
||||
daemon advertises (it prints the alternatives; anything else is rejected).
|
||||
The link prefers a phone-reachable address: the public URL when one is
|
||||
configured, the primary LAN address, and loopback otherwise.
|
||||
|
||||
The daemon endpoint comes from $PI2_RUNTIME_DIR/daemon.json (port) and
|
||||
$PI2_RUNTIME_DIR/cli.token (local admin token). Start it with \`pi2 daemon\`.
|
||||
@@ -265,7 +266,7 @@ interface InfoBody {
|
||||
platform: string;
|
||||
capabilities: string[];
|
||||
limits: { maxBodyBytes: number; maxFrameBytes: number; maxConnections: number };
|
||||
access?: string;
|
||||
host?: string;
|
||||
publicUrl?: string | null;
|
||||
}
|
||||
|
||||
@@ -311,7 +312,7 @@ export async function runStatus(options: StatusOptions): Promise<number> {
|
||||
url: client.baseUrl,
|
||||
...info,
|
||||
// Older daemons may not report them; daemon.json does.
|
||||
access: info.access ?? client.daemon.access,
|
||||
host: info.host ?? client.daemon.host ?? null,
|
||||
publicUrl: info.publicUrl ?? client.daemon.publicUrl ?? null,
|
||||
},
|
||||
instances,
|
||||
@@ -365,45 +366,147 @@ export async function runStatus(options: StatusOptions): Promise<number> {
|
||||
export interface PairingOptions {
|
||||
client: DaemonClient;
|
||||
print?: (line: string) => void;
|
||||
/** Rebuild the printed/QR url on this public base (e.g. `https://host.ts.net`). */
|
||||
publicUrl?: string | null;
|
||||
/** `--base <url>`: pin the link to one of the addresses the daemon advertises. */
|
||||
base?: string | null;
|
||||
}
|
||||
|
||||
function withoutTrailingSlash(value: string): string {
|
||||
return value.trim().replace(/\/+$/, "");
|
||||
/** One address the daemon says it is reachable on (`bases[]` in the mint response). */
|
||||
export interface PairingBase {
|
||||
kind: string;
|
||||
name: string;
|
||||
address: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
/** `--public-url` → `daemon.json.publicUrl` → `PI2_PUBLIC_URL`, first non-empty wins. */
|
||||
export function resolvePublicUrl(client: DaemonClient, flag: string | undefined): string | null {
|
||||
for (const candidate of [flag, client.daemon.publicUrl, process.env.PI2_PUBLIC_URL]) {
|
||||
const value = candidate === undefined || candidate === null ? "" : withoutTrailingSlash(candidate);
|
||||
if (value !== "") return value;
|
||||
export interface PairingQr {
|
||||
version: number;
|
||||
ecc: string;
|
||||
mask: number;
|
||||
size: number;
|
||||
/** One string per module row, `1` = dark, without a quiet zone. */
|
||||
rows: string[];
|
||||
}
|
||||
|
||||
export interface PairingResult {
|
||||
code: string;
|
||||
url: string;
|
||||
expiresAt?: number;
|
||||
nonce?: string;
|
||||
qr?: PairingQr;
|
||||
bases: PairingBase[];
|
||||
}
|
||||
|
||||
/** Quiet zone around the terminal QR, in modules. */
|
||||
const QR_QUIET_ZONE = 2;
|
||||
|
||||
/**
|
||||
* Render a QR matrix for a terminal: one character per module, two module rows
|
||||
* per text row via half blocks. The caller owns the width budget; a version 3
|
||||
* symbol (29 modules) plus the quiet zone stays well inside 80 columns.
|
||||
*/
|
||||
export function renderTerminalQr(rows: readonly string[]): string[] {
|
||||
const size = rows[0]?.length ?? 0;
|
||||
if (size === 0) return [];
|
||||
const width = size + QR_QUIET_ZONE * 2;
|
||||
const blank = "0".repeat(width);
|
||||
const frame = Array.from({ length: QR_QUIET_ZONE }, () => blank);
|
||||
const padded = [
|
||||
...frame,
|
||||
...rows.map((row) => `${"0".repeat(QR_QUIET_ZONE)}${row}${"0".repeat(QR_QUIET_ZONE)}`),
|
||||
...frame,
|
||||
];
|
||||
|
||||
const lines: string[] = [];
|
||||
for (let index = 0; index < padded.length; index += 2) {
|
||||
const top = padded[index] ?? blank;
|
||||
const bottom = padded[index + 1] ?? blank;
|
||||
let line = "";
|
||||
for (let column = 0; column < width; column += 1) {
|
||||
const up = top[column] === "1";
|
||||
const down = bottom[column] === "1";
|
||||
line += up && down ? "█" : up ? "▀" : down ? "▄" : " ";
|
||||
}
|
||||
lines.push(line);
|
||||
}
|
||||
return null;
|
||||
return lines;
|
||||
}
|
||||
|
||||
function recordOf(value: unknown): Record<string, unknown> | undefined {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function pairingQrOf(raw: unknown): PairingQr | undefined {
|
||||
const record = recordOf(raw);
|
||||
if (!record || !Array.isArray(record.rows) || record.rows.length === 0) return undefined;
|
||||
const rows = record.rows.filter((row: unknown): row is string => typeof row === "string");
|
||||
if (rows.length === 0) return undefined;
|
||||
return {
|
||||
version: typeof record.version === "number" ? record.version : 0,
|
||||
ecc: typeof record.ecc === "string" ? record.ecc : "M",
|
||||
mask: typeof record.mask === "number" ? record.mask : 0,
|
||||
size: typeof record.size === "number" ? record.size : (rows[0]?.length ?? 0),
|
||||
rows,
|
||||
};
|
||||
}
|
||||
|
||||
function pairingBasesOf(raw: unknown): PairingBase[] {
|
||||
if (!Array.isArray(raw)) return [];
|
||||
return raw.flatMap((value) => {
|
||||
const record = recordOf(value);
|
||||
if (!record || typeof record.url !== "string") return [];
|
||||
return [
|
||||
{
|
||||
kind: typeof record.kind === "string" ? record.kind : "other",
|
||||
name: typeof record.name === "string" ? record.name : "",
|
||||
address: typeof record.address === "string" ? record.address : "",
|
||||
url: record.url,
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* `pi2 pairing` — mint a code and print a scannable link.
|
||||
*
|
||||
* The daemon owns the URL, the QR matrix and the list of usable bases (ADR
|
||||
* 0001); the CLI only renders them. `--base` narrows the choice, and the daemon
|
||||
* rejects anything it did not offer.
|
||||
*/
|
||||
export async function runPairing(options: PairingOptions): Promise<number> {
|
||||
const print = options.print ?? ((line: string) => process.stdout.write(`${line}\n`));
|
||||
const result = await options.client.post("/api/v1/pair", {});
|
||||
const code = typeof result.body.code === "string" ? result.body.code : undefined;
|
||||
if (code === undefined) throw new CliError("pairing failed: daemon returned no code");
|
||||
const expiresAt = typeof result.body.expiresAt === "number" ? result.body.expiresAt : undefined;
|
||||
const nonce = typeof result.body.nonce === "string" ? result.body.nonce : undefined;
|
||||
// Rebuild the URL from the *actual* base URL (or the public base when one is
|
||||
// known): the daemon's own `url` field is derived from the configured port,
|
||||
// which is stale after a retry or `--port 0`.
|
||||
const base = options.publicUrl === undefined || options.publicUrl === null || options.publicUrl.trim() === ""
|
||||
? options.client.baseUrl
|
||||
: withoutTrailingSlash(options.publicUrl);
|
||||
const url = `${base}/pair/${code}`;
|
||||
const payload = JSON.stringify({ v: PROTOCOL_VERSION, code, url, ...(expiresAt === undefined ? {} : { expiresAt }), ...(nonce === undefined ? {} : { nonce }) });
|
||||
const base = options.base?.trim() ?? "";
|
||||
const response = await options.client.post("/api/v1/pair", base === "" ? {} : { base });
|
||||
|
||||
const code = typeof response.body.code === "string" ? response.body.code : undefined;
|
||||
const url = typeof response.body.url === "string" ? response.body.url : undefined;
|
||||
if (code === undefined || url === undefined) throw new CliError("pairing failed: daemon returned no code");
|
||||
|
||||
const expiresAt = typeof response.body.expiresAt === "number" ? response.body.expiresAt : undefined;
|
||||
const qr = pairingQrOf(response.body.qr);
|
||||
const bases = pairingBasesOf(response.body.bases);
|
||||
|
||||
print(`url ${url}`);
|
||||
print(`code ${code}`);
|
||||
if (expiresAt !== undefined) {
|
||||
print(`expires ${new Date(expiresAt).toISOString()} (${Math.max(0, Math.round((expiresAt - Date.now()) / 1000))}s)`);
|
||||
const seconds = Math.max(0, Math.round((expiresAt - Date.now()) / 1000));
|
||||
print(`expires in ${seconds}s (${new Date(expiresAt).toISOString()})`);
|
||||
}
|
||||
if (qr === undefined) {
|
||||
print("");
|
||||
print("note the link is too long to encode as a QR code; open the url on the phone instead.");
|
||||
} else {
|
||||
print("");
|
||||
for (const line of renderTerminalQr(qr.rows)) print(line);
|
||||
}
|
||||
if (bases.length > 1) {
|
||||
print("");
|
||||
print("other addresses the phone could use (pi2 pairing --base <url>):");
|
||||
for (const candidate of bases) {
|
||||
print(` ${candidate.kind.padEnd(9)} ${candidate.name.padEnd(12)} ${candidate.url}`);
|
||||
}
|
||||
}
|
||||
print(`qr ${payload}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -633,7 +736,7 @@ export async function main(argv: readonly string[], options: Pi2Options = {}): P
|
||||
case "pairing":
|
||||
case "pair": {
|
||||
const parsed = parseArgs(rest, {
|
||||
values: ["--public-url"],
|
||||
values: ["--base"],
|
||||
booleans: ["--help"],
|
||||
aliases: { "-h": "--help" },
|
||||
});
|
||||
@@ -645,7 +748,7 @@ export async function main(argv: readonly string[], options: Pi2Options = {}): P
|
||||
return await runPairing({
|
||||
client,
|
||||
print: out,
|
||||
publicUrl: resolvePublicUrl(client, stringFlag(parsed.flags, "--public-url")),
|
||||
base: stringFlag(parsed.flags, "--base"),
|
||||
});
|
||||
}
|
||||
case "install-service":
|
||||
|
||||
@@ -93,7 +93,6 @@ export async function wireDaemon(options: WireOptions = {}): Promise<WiredDaemon
|
||||
const cliTokenPath = join(runtime, CLI_TOKEN_FILE);
|
||||
const auth = new AuthStore({
|
||||
path: config.deviceStorePath,
|
||||
baseUrl: `http://${config.host}:${config.port}`,
|
||||
localTokenPath: cliTokenPath,
|
||||
...(options.now === undefined ? {} : { now: options.now }),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user