Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
feat(cli): add hidden local password setup
Codexf74ace8584d8
diff --git a/bin/mso b/bin/msoindex c08747ca..b997cc0f 100755--- a/bin/mso+++ b/bin/mso@@ -99,6 +99,7 @@# approve <id> [label] [--role ...] Approve a device id# revoke <id> Revoke one device# whoami This CLI's device id + session state+# passwd [status] Set/change local login password with hidden prompts; status is metadata only# login Force a fresh login# logout Drop the session (server-side + local jar)#@@ -169,27 +170,9 @@ while [ $# -gt 0 ]; doesacdone-# Help and local maintenance do not source credentials or create a cookie jar.-case "${1-}" in- help|-h|--help)- # shellcheck source=../scripts/cli/help.sh- source "$ROOT/scripts/cli/help.sh"; usage; exit 0 ;;- heartbeat)- [ -z "$BASE_OVERRIDE" ] || die "heartbeat is local-only; omit --base"- shift- MSO_GATEWAY_ROOT="$ROOT" MSO_GATEWAY_ENV="${ENV_OVERRIDE:-${MSO_ENV:-${OS_ENV:-$ROOT/.env.local}}}" exec "$ROOT/scripts/mso-heartbeat" "$@" ;;- reset|uninstall)- [ -z "$BASE_OVERRIDE$ENV_OVERRIDE${MSO_BASE:-}${OS_BASE:-}${MSO_ENV:-}${OS_ENV:-}" ] \- || die "maintenance is local-only; omit --base/--env and run over SSH on the intended host"- exec node "$ROOT/scripts/mso-maintenance.mjs" "$@" ;;- tenant)- [ -z "$BASE_OVERRIDE$ENV_OVERRIDE${MSO_BASE:-}${OS_BASE:-}${MSO_ENV:-}${OS_ENV:-}" ] \- || die "tenant enrollment is local-only; omit --base/--env and run over SSH on the intended host"- shift- set -a; . "$ROOT/.env.local" 2>/dev/null || true; set +a- export PATH="$HOME/.bun/bin:$PATH"- exec bun "$ROOT/scripts/mso-tenant.ts" "$@" ;;-esac+# Help and local maintenance run before credentials or HTTP session state.+# shellcheck source=../scripts/cli/local-maintenance.sh+source "$ROOT/scripts/cli/local-maintenance.sh"B="${BASE_OVERRIDE:-${MSO_BASE:-${OS_BASE:-http://127.0.0.1:4005}}}"ENVF="${ENV_OVERRIDE:-${MSO_ENV:-${OS_ENV:-$ROOT/.env.local}}}"diff --git a/bin/mso-update-offline.test.ts b/bin/mso-update-offline.test.tsindex b52cae47..14ce365f 100644--- a/bin/mso-update-offline.test.ts+++ b/bin/mso-update-offline.test.ts@@ -37,6 +37,7 @@ function fixture() {"scripts/cli/service.sh","scripts/cli/transport.sh","scripts/cli/onboarding.sh", "scripts/cli/onboarding-ai.sh",+ "scripts/cli/local-maintenance.sh","scripts/cli/commands.sh","scripts/cli/help.sh","scripts/cli/commands-host.sh",diff --git a/docs/CLI.md b/docs/CLI.mdindex 91e91087..b3a21a67 100644--- a/docs/CLI.md+++ b/docs/CLI.md@@ -139,6 +139,7 @@ Commands:approve <id> [label] [--role ...] Approve a device idrevoke <id> Revoke one devicewhoami This CLI's device id + session state+ passwd [status] Set/change local login password with hidden prompts; status is metadata onlylogin Force a fresh loginlogout Drop the session (server-side + local jar)diff --git a/docs/PROGRESS.md b/docs/PROGRESS.mdindex 36920532..d7071c5f 100644--- a/docs/PROGRESS.md+++ b/docs/PROGRESS.md@@ -204,6 +204,10 @@ The Security Core gate was failing deterministically at `bff30987` on the SemgreA ChatGPT connector therefore reconnects against the callback it already holds; no re-add is required.+## 2026-10-17: Local hidden-prompt login password setup++`mso passwd` creates or changes the local installation login password without an HTTP session, password arguments, env-file execution or cookie-jar creation. It reuses login password validation and rotation; fresh configuration is published without overwriting another writer, mode 0600, with a random session signing secret and MCP disabled. Existing signing secrets and other configuration remain unchanged. Changing an existing password requires its current value. `mso passwd status` exposes configuration metadata only; no password read/delete operation is provided. The user must start/restart MSO explicitly to apply local file changes; existing sessions are not revoked. Tests use temporary installation fixtures, including a real PTY to verify hidden input and cancellation. No live installation credentials are created by development or tests.+## 2026-10-14: Fix the provider picker and make `mso models add` scriptable`mso models add` with no argument died with `mso picker: EAGAIN: resource temporarily unavailable, read`. The native arrow picker read its candidate rows with `fs.readFileSync(0)`, and Node throws instead of retrying when it is handed a non-blocking pipe that has not been written yet — exactly the state the manager's subshell pipeline produces. The picker now drains fd 0 through `fs.readSync` in a loop, sleeping on `Atomics.wait` and retrying `EAGAIN` until the producer closes the pipe, so the same selector works for both a pipeline and a redirected file. This restores the live provider list (Nvidia, OpenCode, OpenRouter, ZenMux and the rest) that the broken read had been hiding behind the static fallback.diff --git a/lib/auth/local-password.ts b/lib/auth/local-password.tsnew file mode 100644index 00000000..716635f3--- /dev/null+++ b/lib/auth/local-password.ts@@ -0,0 +1,53 @@+import { constants, promises as fs } from "node:fs";+import { randomBytes } from "node:crypto";+import path from "node:path";+import { constantTimeEq } from "./session";+import { extractLoginPassword, LoginPasswordError, passwordPolicyError, readLoginPasswordEnvironment, rotateLoginPassword } from "./login-password";++async function safeParent(file: string): Promise<void> {+ const parent = path.dirname(file);+ const stat = await fs.lstat(parent);+ if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 0o022)) {+ throw new LoginPasswordError("password_file_unsafe");+ }+}++export async function localPasswordStatus(file: string) {+ await safeParent(file);+ try { await fs.lstat(file); }+ catch (error) {+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return { configured: false, sessionConfigured: false };+ throw new LoginPasswordError("password_file_unsafe");+ }+ const text = await readLoginPasswordEnvironment(file);+ extractLoginPassword(text);+ return { configured: true, sessionConfigured: /^OS_SESSION_SECRET=.+$/m.test(text) };+}++export async function setLocalPassword(file: string, input: { current: string; next: string; confirm: string }) {+ const status = await localPasswordStatus(file);+ if (passwordPolicyError(input.next)) throw new LoginPasswordError("weak_password");+ if (!constantTimeEq(input.next, input.confirm)) throw new LoginPasswordError("mismatch");+ if (status.configured) {+ const text = await readLoginPasswordEnvironment(file);+ process.env.OS_LOGIN_PASSWORD = extractLoginPassword(text);+ await rotateLoginPassword({ ...input, actor: "local-cli", file });+ return;+ }+ if (input.current) throw new LoginPasswordError("password_source_mismatch");+ const tmp = path.join(path.dirname(file), `.mso-password-${randomBytes(16).toString("hex")}.tmp`);+ let created = false;+ try {+ const handle = await fs.open(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);+ created = true;+ try {+ await handle.writeFile(`OS_LOGIN_PASSWORD=${input.next}\nOS_SESSION_SECRET=${randomBytes(32).toString("hex")}\nOS_MCP_ENABLED=0\nOS_MCP_MAX_SCOPE=read\n`);+ await handle.sync();+ } finally { await handle.close(); }+ await fs.link(tmp, file);+ } catch {+ throw new LoginPasswordError("password_file_unsafe");+ } finally {+ if (created) await fs.unlink(tmp).catch(() => undefined);+ }+}diff --git a/lib/auth/login-password.ts b/lib/auth/login-password.tsindex c8f60621..051bd023 100644--- a/lib/auth/login-password.ts+++ b/lib/auth/login-password.ts@@ -82,7 +82,7 @@ export function replaceLoginPassword(text: string, next: string): string {return lines.join("\n");}-async function readEnvFile(file: string): Promise<string> {+export async function readLoginPasswordEnvironment(file: string): Promise<string> {let handle: Awaited<ReturnType<typeof fs.open>> | null = null;try {handle = await fs.open(file, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);@@ -138,7 +138,7 @@ export async function rotateLoginPassword(input: {}if (constantTimeEq(configured, input.next)) throw new LoginPasswordError("unchanged");const file = input.file ?? loginPasswordPath();- const text = await readEnvFile(file);+ const text = await readLoginPasswordEnvironment(file);const stored = extractLoginPassword(text);if (!constantTimeEq(stored, configured)) throw new LoginPasswordError("password_source_mismatch");await writeEnvFile(file, replaceLoginPassword(text, input.next));diff --git a/scripts/cli/local-maintenance.sh b/scripts/cli/local-maintenance.shnew file mode 100644index 00000000..b6b4dc4c--- /dev/null+++ b/scripts/cli/local-maintenance.sh@@ -0,0 +1,30 @@+#!/usr/bin/env bash+# Dispatch local maintenance before sourcing credentials or creating a cookie jar.+case "${1-}" in+ help|-h|--help)+ # shellcheck source=help.sh+ source "$ROOT/scripts/cli/help.sh"; usage; exit 0 ;;+ passwd)+ [ -z "$BASE_OVERRIDE$ENV_OVERRIDE${MSO_BASE:-}${OS_BASE:-}${MSO_ENV:-}${OS_ENV:-}" ] \+ || die "passwd edits this local installation; omit --base/--env and their environment overrides"+ shift+ source "$ROOT/scripts/cli/passwd.sh"+ mso_passwd "$ROOT" "$@"+ exit $? ;;+ heartbeat)+ [ -z "$BASE_OVERRIDE" ] || die "heartbeat is local-only; omit --base"+ shift+ MSO_GATEWAY_ROOT="$ROOT" MSO_GATEWAY_ENV="${ENV_OVERRIDE:-${MSO_ENV:-${OS_ENV:-$ROOT/.env.local}}}" exec "$ROOT/scripts/mso-heartbeat" "$@" ;;+ reset|uninstall)+ [ -z "$BASE_OVERRIDE$ENV_OVERRIDE${MSO_BASE:-}${OS_BASE:-}${MSO_ENV:-}${OS_ENV:-}" ] \+ || die "maintenance is local-only; omit --base/--env and run over SSH on the intended host"+ exec node "$ROOT/scripts/mso-maintenance.mjs" "$@" ;;+ tenant)+ [ -z "$BASE_OVERRIDE$ENV_OVERRIDE${MSO_BASE:-}${OS_BASE:-}${MSO_ENV:-}${OS_ENV:-}" ] \+ || die "tenant enrollment is local-only; omit --base/--env and run over SSH on the intended host"+ shift+ set -a; . "$ROOT/.env.local" 2>/dev/null || true; set +a+ export PATH="$HOME/.bun/bin:$PATH"+ exec bun "$ROOT/scripts/mso-tenant.ts" "$@" ;;+esac+diff --git a/scripts/cli/passwd-pty-test.py b/scripts/cli/passwd-pty-test.pynew file mode 100755index 00000000..526a368c--- /dev/null+++ b/scripts/cli/passwd-pty-test.py@@ -0,0 +1,93 @@+"""PTY regression fixtures only; never targets an installed MSO environment."""+import errno+import os+import pty+import select+import signal+import sys+import termios+import time+++def start(root):+ pid, fd = pty.fork()+ if pid == 0:+ os.execv('/bin/bash', ['bash', root + '/bin/mso', 'passwd'])+ return pid, fd+++def until(fd, marker):+ output = b''+ deadline = time.monotonic() + 8+ while marker not in output:+ if time.monotonic() > deadline:+ raise AssertionError('prompt timeout')+ if select.select([fd], [], [], 0.1)[0]:+ try:+ data = os.read(fd, 4096)+ except OSError as error:+ if error.errno == errno.EIO:+ break+ raise+ if not data:+ break+ output += data+ assert marker in output, 'expected prompt not reached'+ assert not termios.tcgetattr(fd)[3] & termios.ECHO, 'password echo enabled'+ return output+++def finish(pid, fd):+ output = b''+ deadline = time.monotonic() + 8+ status = None+ while time.monotonic() < deadline:+ if select.select([fd], [], [], 0.05)[0]:+ try:+ data = os.read(fd, 4096)+ except OSError as error:+ if error.errno == errno.EIO:+ break+ raise+ if not data:+ break+ output += data+ else:+ os.kill(pid, signal.SIGKILL)+ raise AssertionError('child timeout')+ _, status = os.waitpid(pid, 0)+ os.close(fd)+ return os.waitstatus_to_exitcode(status), output+++root, cancelled = sys.argv[1:]+pid, fd = start(root)+output = until(fd, b'New password: ')+assert not os.path.exists(root + '/.env.local'), 'credentials created before input'+os.write(fd, b'fixture-hidden-123\n')+output += until(fd, b'Confirm password: ')+assert not os.path.exists(root + '/.env.local'), 'credentials created before confirmation'+os.write(fd, b'fixture-hidden-123\n')+code, tail = finish(pid, fd)+assert code == 0, 'fresh setup failed'+assert b'fixture-hidden-123' not in output + tail, 'password was echoed'++pid, fd = start(root)+output = until(fd, b'Current password: ')+os.write(fd, b'fixture-hidden-123\n')+output += until(fd, b'New password: ')+os.write(fd, b'fixture-replaced-456\n')+output += until(fd, b'Confirm password: ')+os.write(fd, b'fixture-replaced-456\n')+code, tail = finish(pid, fd)+assert code == 0, 'rotation failed'+assert b'fixture-hidden-123' not in output + tail, 'current password echoed'+assert b'fixture-replaced-456' not in output + tail, 'new password echoed'++pid, fd = start(cancelled)+until(fd, b'New password: ')+os.write(fd, b'\x03')+code, _ = finish(pid, fd)+assert code != 0, 'cancel returned success'+assert not os.path.exists(cancelled + '/.env.local'), 'cancel wrote credentials'+print('PTY hidden input, confirmation and cancellation passed')diff --git a/scripts/cli/passwd.sh b/scripts/cli/passwd.shnew file mode 100644index 00000000..7902015e--- /dev/null+++ b/scripts/cli/passwd.sh@@ -0,0 +1,36 @@+#!/usr/bin/env bash+# Local password setup runs before env sourcing, HTTP auth or cookie-jar creation.+set +x+mso_passwd() {+ local root="$1"; shift+ case "${1-}" in+ -h|--help|help)+ [ "$#" -eq 1 ] || die "usage: mso passwd [status]"+ printf '%s\n' 'usage: mso passwd [status]' \+ 'Set/change the local login password with hidden prompts (6-128 supported characters).' \+ 'An existing password is required to change it. status shows metadata only.' \+ 'Fresh setup creates the session secret with MCP disabled; no device is approved.' \+ 'No server is started/restarted. Existing sessions remain valid.'+ return ;;+ status) [ "$#" -eq 1 ] || die "usage: mso passwd [status]" ;;+ '') [ "$#" -eq 0 ] || die "password arguments are forbidden; run mso passwd" ;;+ *) die "password arguments are forbidden; run mso passwd" ;;+ esac+ local runner+ runner=$(command -v bun) || die "bun is required for mso passwd"+ if [ "${1-}" = status ]; then "$runner" "$root/scripts/mso-passwd.ts" "$root" status; return; fi+ [ -t 0 ] || die "a terminal is required; password input cannot be piped"+ local state current='' next confirm+ state=$("$runner" "$root/scripts/mso-passwd.ts" "$root" status) || return+ exec 3<>/dev/tty || { die "a terminal is required; password input cannot be piped"; }+ if [[ "$state" == '{"configured":true,'* ]]; then+ read -r -s -p 'Current password: ' -u 3 current || { exec 3>&-; return 1; }+ printf '\n' >&3+ fi+ read -r -s -p 'New password: ' -u 3 next || { exec 3>&-; return 1; }+ printf '\n' >&3+ read -r -s -p 'Confirm password: ' -u 3 confirm || { exec 3>&-; return 1; }+ printf '\n' >&3+ exec 3>&-+ printf '%s\0' "$current" "$next" "$confirm" | "$runner" "$root/scripts/mso-passwd.ts" "$root" set+}diff --git a/scripts/mso-passwd.node.mjs b/scripts/mso-passwd.node.mjsnew file mode 100755index 00000000..872f4e45--- /dev/null+++ b/scripts/mso-passwd.node.mjs@@ -0,0 +1,116 @@+import { test, after } from "node:test";+import assert from "node:assert/strict";+import { mkdtempSync, mkdirSync, copyFileSync, readFileSync, writeFileSync, chmodSync, lstatSync, existsSync, symlinkSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import path from "node:path";+import { fileURLToPath } from "node:url";+import { spawnSync, spawn } from "node:child_process";++const repo = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");+const tmp = mkdtempSync(path.join(tmpdir(), "mso-passwd-test-"));+chmodSync(tmp, 0o700);+after(() => rmSync(tmp, { recursive: true, force: true }));+let number = 0;+function fixture() {+ const root = path.join(tmp, String(number++));+ mkdirSync(root, { mode: 0o700 });+ for (const name of ["bin/mso", "scripts/cli/passwd.sh", "scripts/cli/local-maintenance.sh", "scripts/cli/help.sh", "scripts/mso-passwd.ts", "lib/auth/local-password.ts", "lib/auth/login-password.ts", "lib/auth/session.ts"]) {+ mkdirSync(path.dirname(path.join(root, name)), { recursive: true, mode: 0o700 });+ copyFileSync(path.join(repo, name), path.join(root, name));+ }+ return root;+}+const env = { ...process.env, MSO_ENV: "", OS_ENV: "", MSO_BASE: "", OS_BASE: "" };+const run = (root, action, values = []) => spawnSync("bun", [path.join(root, "scripts/mso-passwd.ts"), root, action], {+ env, encoding: "utf8", input: values.length ? values.join("\0") + "\0" : "",+});+const set = (root, current = "", next = "fixture-next-123", confirm = next) => run(root, "set", [current, next, confirm]);+const seed = (root, text = "OS_LOGIN_PASSWORD=fixture-current\nOS_SESSION_SECRET=fixture-session-key-never-used-live\nOS_MCP_ENABLED=0\nOTHER=keep\n") => {+ writeFileSync(path.join(root, ".env.local"), text, { mode: 0o600 });+};++test("fresh setup uses the existing env source, private permissions and disabled MCP", () => {+ const root = fixture();+ assert.equal(run(root, "status").stdout.trim(), '{"configured":false,"sessionConfigured":false}');+ const out = set(root);+ assert.equal(out.status, 0, out.stderr);+ const file = path.join(root, ".env.local"), text = readFileSync(file, "utf8");+ assert.match(text, /^OS_LOGIN_PASSWORD=fixture-next-123$/m);+ assert.match(text, /^OS_SESSION_SECRET=[a-f0-9]{64}$/m);+ assert.match(text, /^OS_MCP_ENABLED=0$/m);+ assert.equal(lstatSync(file).mode & 0o777, 0o600);+ assert.ok(!out.stdout.includes("fixture-next-123"));+ assert.ok(!existsSync(path.join(root, ".mso")));+});++test("rotation verifies the current password and preserves session secret/config", () => {+ const root = fixture(); seed(root);+ const out = set(root, "fixture-current");+ assert.equal(out.status, 0, out.stderr);+ const text = readFileSync(path.join(root, ".env.local"), "utf8");+ assert.match(text, /OS_SESSION_SECRET=fixture-session-key-never-used-live/);+ assert.match(text, /OTHER=keep/);+ assert.match(text, /OS_LOGIN_PASSWORD=fixture-next-123/);+ assert.ok(!out.stdout.includes("fixture-current"));+ const status = run(root, "status");+ assert.deepEqual(JSON.parse(status.stdout), { configured: true, sessionConfigured: true });+ assert.ok(!status.stdout.includes("fixture-"));+});++test("wrong current, mismatch, weak input and unsafe files never mutate the file", () => {+ const root = fixture(); seed(root);+ const file = path.join(root, ".env.local"), before = readFileSync(file, "utf8");+ for (const values of [["wrong-current", "fixture-next-123", "fixture-next-123"], ["fixture-current", "fixture-next-123", "different"], ["fixture-current", "bad pass", "bad pass"]]) {+ assert.notEqual(run(root, "set", values).status, 0);+ assert.equal(readFileSync(file, "utf8"), before);+ }+ chmodSync(file, 0o640);+ assert.notEqual(set(root, "fixture-current").status, 0);+ assert.equal(readFileSync(file, "utf8"), before);+ const other = fixture();+ symlinkSync(file, path.join(other, ".env.local"));+ assert.notEqual(set(other).status, 0);+});++test("rejects ambiguous env, unsafe parent and secret arguments without echoing", () => {+ const root = fixture(); seed(root, "OS_LOGIN_PASSWORD=first-one\nOS_LOGIN_PASSWORD=second-one\n");+ assert.notEqual(set(root).status, 0);+ const other = fixture(); chmodSync(other, 0o777);+ assert.notEqual(set(other).status, 0);+ const clean = fixture();+ const out = spawnSync("bash", [path.join(clean, "bin/mso"), "passwd", "fixture-argument"], { env, encoding: "utf8" });+ assert.notEqual(out.status, 0);+ assert.ok(!(out.stdout + out.stderr).includes("fixture-argument"));+ assert.ok(!existsSync(path.join(clean, ".env.local")));+});++test("concurrent fresh setup publishes one complete configuration", async () => {+ const root = fixture();+ const launch = () => new Promise(resolve => {+ const child = spawn("bun", [path.join(root, "scripts/mso-passwd.ts"), root, "set"], { env, stdio: ["pipe", "ignore", "ignore"] });+ child.stdin.on("error", () => {});+ child.stdin.end("\0fixture-next-123\0fixture-next-123\0");+ child.on("close", resolve);+ });+ const results = await Promise.all([launch(), launch()]);+ assert.equal(results.filter(code => code === 0).length, 1);+ assert.match(readFileSync(path.join(root, ".env.local"), "utf8"), /^OS_SESSION_SECRET=[a-f0-9]{64}$/m);+});++test("help/status do not create session state, remote targets and non-TTY input fail closed", () => {+ const root = fixture(), home = path.join(root, "home"); mkdirSync(home);+ const invoke = args => spawnSync("bash", [path.join(root, "bin/mso"), ...args], { env: { ...env, HOME: home }, encoding: "utf8", input: "fixture-next-123\n" });+ assert.equal(invoke(["-h"]).status, 0);+ assert.match(invoke(["-h"]).stdout, /passwd \[status\]/);+ assert.equal(invoke(["passwd", "--help"]).status, 0);+ assert.equal(invoke(["passwd", "status"]).status, 0);+ assert.notEqual(invoke(["--base", "https://example.invalid", "passwd"]).status, 0);+ assert.notEqual(invoke(["passwd"]).status, 0);+ assert.ok(!existsSync(path.join(home, ".mso")));+ assert.ok(!existsSync(path.join(root, ".env.local")));+});++test("real PTY hides passwords, requires confirmation, and cancels without credentials", () => {+ const out = spawnSync("python3", [path.join(repo, "scripts/cli/passwd-pty-test.py"), fixture(), fixture()], { env, encoding: "utf8", timeout: 20000 });+ assert.equal(out.status, 0, out.stderr || out.stdout);+});diff --git a/scripts/mso-passwd.test.ts b/scripts/mso-passwd.test.tsnew file mode 100755index 00000000..80cf397a--- /dev/null+++ b/scripts/mso-passwd.test.ts@@ -0,0 +1,11 @@+import { execFileSync } from "node:child_process";+import path from "node:path";+import { expect, it } from "vitest";++it("checks local password storage and real hidden terminal prompts in isolated fixtures", () => {+ const output = execFileSync(process.execPath, ["--test", path.join(process.cwd(), "scripts/mso-passwd.node.mjs")], {+ encoding: "utf8",+ timeout: 30_000,+ });+ expect(output).toMatch(/(?:pass 7|tests 7)/);+}, 35_000);diff --git a/scripts/mso-passwd.ts b/scripts/mso-passwd.tsnew file mode 100644index 00000000..bcb9a7fc--- /dev/null+++ b/scripts/mso-passwd.ts@@ -0,0 +1,29 @@+import path from "node:path";+import { LoginPasswordError } from "../lib/auth/login-password";+import { localPasswordStatus, setLocalPassword } from "../lib/auth/local-password";++const [root, action, ...extra] = process.argv.slice(2);+try {+ if (!root || !path.isAbsolute(root) || extra.length || !["status", "set"].includes(action)) throw new Error("usage");+ const file = path.join(root, ".env.local");+ if (action === "status") {+ console.log(JSON.stringify(await localPasswordStatus(file)));+ } else {+ const chunks: Buffer[] = [];+ let length = 0;+ for await (const chunk of process.stdin) {+ length += chunk.length;+ if (length > 4096) throw new Error("input");+ chunks.push(Buffer.from(chunk));+ }+ const values = Buffer.concat(chunks).toString("utf8").split("\0");+ if (values.length !== 4 || values.pop() !== "") throw new Error("input");+ const [current, next, confirm] = values;+ await setLocalPassword(file, { current, next, confirm });+ console.log("Password saved locally. Start/restart MSO manually to apply; existing sessions are unchanged.");+ }+} catch (error) {+ const code = error instanceof LoginPasswordError ? error.code : "password_command_failed";+ console.error(`mso passwd: ${code}`);+ process.exitCode = 1;+}