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
fix(cli): repair provider picker and make models add scriptable
Abdurrahman Fakhrulbff3098781a4
diff --git a/bin/mso-update-offline.test.ts b/bin/mso-update-offline.test.tsindex 41c2fb3d..f530c22f 100644--- a/bin/mso-update-offline.test.ts+++ b/bin/mso-update-offline.test.ts@@ -32,6 +32,7 @@ function fixture() {"scripts/mso-update","scripts/mso-cli-agent.sh","scripts/cli/ai-provider-catalog.sh",+ "scripts/cli/ai-provider-auth.sh","scripts/cli/runtime.sh","scripts/cli/service.sh","scripts/cli/transport.sh",diff --git a/bin/mso.test.ts b/bin/mso.test.tsindex e94c5475..a3944400 100644--- a/bin/mso.test.ts+++ b/bin/mso.test.ts@@ -108,6 +108,7 @@ describe("bin/mso", () => {fs.readFileSync(path.join(repo, "scripts/cli/commands.sh"), "utf8"),...commandOwnerFiles.map((rel) => fs.readFileSync(path.join(repo, rel), "utf8")),fs.readFileSync(path.join(repo, "scripts/mso-cli-agent.sh"), "utf8"),+ fs.readFileSync(path.join(repo, "scripts/cli/ai-provider-auth.sh"), "utf8"),fs.readFileSync(path.join(repo, "scripts/mso-cli-integrations.sh"), "utf8"),].join("\n");diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 4591c242..c56b852b 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -12,6 +12,7 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh**Fixed**+- `cli` repair provider picker and make models add scriptable- `config` keep tenant config path traceable by Turbopack## 2026-10-13diff --git a/docs/PROGRESS.md b/docs/PROGRESS.mdindex d17d5bc4..59ca4800 100644--- a/docs/PROGRESS.md+++ b/docs/PROGRESS.md@@ -1,3 +1,13 @@+## 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.++Provider auth now matches the shape operators already use elsewhere: `mso models add <provider> [--api-key <key>] [--type api-key|oauth] [--name <name>] [--base-url <url>] [--protocol openai|anthropic] [--models <ids>]`, with `mso models add --help`, a single-provider probe (`mso models status <provider>`), and the existing `list`/`rm`/`catalog`/`test` verbs unchanged. `--api-key` skips the hidden prompt so the credential can be supplied from a script or CI runner; the key still reaches the server through the stdin-bodied `secret_post` path and never appears in process argv. `openai-codex` and `--type oauth` remain device-flow sign-ins and reject a pasted key. Any unknown id carrying `--base-url` is treated as a custom OpenAI/Anthropic-compatible endpoint, and the `custom` subcommand keeps its interactive prompts.++The non-interactive path also exposed a latent terminal bug: `tty_ok` only tested `[ -r/-w /dev/tty ]`, which stays true for a char device that exists while its open fails with `ENXIO` under a process with no controlling terminal. A prompt issued in that state wrote to `/dev/tty`, the redirect failed, and `set -e` killed the whole script mid-run. `tty_ok` now performs the real open, so piped invocations correctly fall through to the non-interactive defaults instead of aborting. Contract tests assert the new flags, the picker's stream read, and that `readFileSync(0` never returns.++The provider-auth functions moved to `scripts/cli/ai-provider-auth.sh`, sourced by `scripts/mso-cli-agent.sh`: the added flag parsing pushed that slice past the 500-line architecture ratchet, and the boundary policy forbids raising the limit, so the auth responsibility now shares the `ai-provider-catalog.sh` pattern instead.+## 2026-10-10: Keep the raw-stream fixture fully visible to security scanningSemgrep's pinned parser rejected the inline import type inside the mock loader's generic call. The fixture now applies the same module type to the awaited import result. All thirteen real-file stream tests and strict scanner coverage remain required; no rule or file is excluded.diff --git a/lib/onboard-contract.test.ts b/lib/onboard-contract.test.tsindex e0759d02..a392c8e3 100644--- a/lib/onboard-contract.test.ts+++ b/lib/onboard-contract.test.ts@@ -12,6 +12,7 @@ const cli = [fs.readFileSync(path.join(__dirname, "../scripts/cli/onboarding-ai.sh"), "utf8"),fs.readFileSync(path.join(__dirname, "../scripts/mso-cli-agent.sh"), "utf8"),fs.readFileSync(path.join(__dirname, "../scripts/cli/ai-provider-catalog.sh"), "utf8"),+ fs.readFileSync(path.join(__dirname, "../scripts/cli/ai-provider-auth.sh"), "utf8"),fs.readFileSync(path.join(__dirname, "../scripts/cli/transport.sh"), "utf8"),].join("\n");diff --git a/scripts/cli/ai-provider-auth.sh b/scripts/cli/ai-provider-auth.shnew file mode 100644index 00000000..d741ddd2--- /dev/null+++ b/scripts/cli/ai-provider-auth.sh@@ -0,0 +1,109 @@+#!/usr/bin/env bash+# AI provider authentication: connect OAuth (device flow), paste/flag an API key,+# or declare a custom OpenAI/Anthropic-compatible endpoint. Sourced by+# scripts/mso-cli-agent.sh after HTTP/TTY transport and the provider catalog exist.+# Split out of mso-cli-agent.sh to keep that slice under the architecture line budget.++configure_oauth_provider() {+ local provider="$1" response code url interval poll+ [ "$provider" = "openai-codex" ] || die "OAuth provider not supported yet: $provider"+ response=$(jpost "/api/oauth/openai" '{"action":"start","select":false}')+ code=$(jq -r '.userCode // empty' <<<"$response"); url=$(jq -r '.verificationUrl // empty' <<<"$response"); interval=$(jq -r '.intervalMs // 5000' <<<"$response")+ [ -n "$code" ] && [ -n "$url" ] || die "OpenAI OAuth did not return a device code"+ echo "Open this URL in any browser: $url"+ echo "Enter code: $code"+ echo "Waiting for authorization (active model will NOT change)..."+ while true; do+ poll_seconds=$((interval / 1000))+ [ "$poll_seconds" -gt 2 ] || poll_seconds=3+ sleep "$poll_seconds"+ poll=$(jpost "/api/oauth/openai" '{"action":"poll","select":false}')+ if [ "$(jq -r '.ok // false' <<<"$poll")" = true ]; then+ echo " ✓ connected $(jq -r '.slug' <<<"$poll"); model selection unchanged"+ return+ fi+ [ "$(jq -r '.pending // false' <<<"$poll")" = true ] || die "OpenAI OAuth failed: $poll"+ tty_print "."+ done+}++usage_models_add() {+ cat <<'TXT'+usage: mso models add <provider> [options]+ mso models add <name> --base-url <url> --api-key <key> # custom endpoint++Options:+ --api-key <key> Credential value (skips the hidden prompt; use in scripts/CI)+ --type api-key|oauth Credential type (default: api-key; oauth only: openai-codex)+ --name <name> Display name for a custom endpoint (defaults to the provider arg)+ --base-url <url> Custom OpenAI/Anthropic-compatible base URL+ --protocol <p> Custom endpoint protocol: openai (default) | anthropic+ --models <ids> Custom endpoint model ids, comma/newline separated+TXT+}++configure_ai_provider() {+ local provider="${1:?provider required}"; shift || true+ local body name base="" protocol="" models="" api_key="" cred_type="" opt_name=""+ while [ $# -gt 0 ]; do+ case "$1" in+ --api-key|--key) api_key="${2:?--api-key needs a value}"; shift 2 ;;+ --type) cred_type="${2:?--type needs api-key or oauth}"; shift 2 ;;+ --name) opt_name="${2:?--name needs a value}"; shift 2 ;;+ --base-url|--base) base="${2:?--base-url needs a value}"; shift 2 ;;+ --protocol) protocol="${2:?--protocol needs openai or anthropic}"; shift 2 ;;+ --models) models="${2:?--models needs a value}"; shift 2 ;;+ *) die "unknown provider option: $1 (see: mso models add --help)" ;;+ esac+ done+ case "$cred_type" in+ ""|api-key|api_key|key|oauth) ;;+ *) die "--type must be api-key or oauth" ;;+ esac+ case "$provider" in chatgpt|codex) provider=openai-codex ;; esac++ # OAuth (device flow) is a sign-in, never a pasted key.+ if [ "$cred_type" = oauth ] || [ "$provider" = openai-codex ]; then+ [ -z "$api_key" ] || die "--api-key cannot be combined with the OAuth provider $provider"+ configure_oauth_provider "$provider"; return+ fi++ # Custom / self-hosted endpoint: explicit `custom`, or any id with a --base-url.+ if [ "$provider" = custom ] || { [ -n "$base" ] && ! ai_provider_supported "$provider"; }; then+ name="$opt_name"; [ "$provider" = custom ] || [ -n "$name" ] || name="$provider"+ if ! tty_ok; then+ { [ -n "$name" ] && [ -n "$base" ] && [ -n "$api_key" ]; } \+ || die "custom provider in non-interactive mode needs --base-url and --api-key (and --name when the id is 'custom')"+ fi+ if [ -z "$name" ]; then tty_line "Provider name: " ""; name="$REPLY"; fi+ [ -n "$name" ] || die "provider name required"+ if [ -z "$base" ]; then tty_line "Base URL (https://.../v1): " ""; base="$REPLY"; fi+ [ -n "$base" ] || die "base URL required"+ if [ -z "$protocol" ]; then+ if tty_ok; then tty_line "Protocol [openai|anthropic] [openai]: " "openai"; protocol="$REPLY"; else protocol=openai; fi+ fi+ case "$protocol" in+ openai|anthropic) ;;+ *) die "protocol must be openai or anthropic" ;;+ esac+ if [ -z "$models" ] && tty_ok; then tty_line "Models (comma/newline IDs; optional): " ""; models="$REPLY"; fi+ if [ -z "$api_key" ]; then tty_secret "API key: "; api_key="$REPLY"; fi+ [ -n "$api_key" ] || die "empty API key"+ body=$(printf '%s\0%s\0%s\0%s\0%s' "$name" "$base" "$protocol" "$api_key" "$models" | custom_provider_body_unselected)+ secret_post "/api/config" "$body" >/dev/null+ unset api_key body REPLY+ echo " ✓ custom provider configured; active model unchanged"+ return+ fi++ ai_provider_supported "$provider" || die "unknown/unsupported AI provider '$provider'; run: mso models free or mso models add"+ if [ -z "$api_key" ]; then+ tty_ok || die "provider setup needs a credential; pass --api-key <key> or run interactively"+ tty_secret "Paste $provider API key: "; api_key="$REPLY"+ fi+ [ -n "$api_key" ] || die "empty API key"+ body=$(printf '%s\0%s' "$provider" "$api_key" | provider_key_body_unselected)+ secret_post "/api/config" "$body" >/dev/null+ unset api_key body REPLY+ echo " ✓ $provider configured; active model unchanged"+}diff --git a/scripts/cli/commands.sh b/scripts/cli/commands.shindex c6d6c1f3..91054dce 100755--- a/scripts/cli/commands.sh+++ b/scripts/cli/commands.sh@@ -52,7 +52,7 @@ U_agent_vault="agent-vault show|sync [project]|read <project> <note-path>"U_config="config show|set <json>|key <provider>|style <off|caveman|ponytail>|rm <provider>"U_prefs="prefs show|set <json>"U_federation="federation status"-U_models="models [status|list|add|auth <provider>|rm <provider>|catalog [provider]|test]"+U_models="models [status|list [provider]|add <provider> [--api-key <key>] [--type api-key|oauth]|auth <provider>|rm <provider>|catalog [provider]|test]"U_jev="jev status|decide <model.route|failure.triage|recipe.promote> [JSON|@file]|request <JSON|@file>"U_skills="skills list|read <id>|search <query…>|available|info <id>|install <id…> [-y] [--force]|remove <id…> [-y]|store list|store install|remove <id> <revision>"U_mcp="mcp project <JSON>|list|pat <label> [read|write|exec] [ttlDays]|activity [n]|service-token --label <label> --client-id <id> --scope <read|write|exec> --tools <name,name> [--constraints-json <json>]|revoke <id>|revoke all"diff --git a/scripts/cli/onboarding.sh b/scripts/cli/onboarding.shindex d887df86..23b94323 100755--- a/scripts/cli/onboarding.sh+++ b/scripts/cli/onboarding.sh@@ -2,7 +2,10 @@# TTY and guided onboarding helpers. Sourced by scripts/cli/runtime.sh.# shellcheck source=onboarding-ai.shsource "$ROOT/scripts/cli/onboarding-ai.sh"-tty_ok() { [ -r /dev/tty ] && [ -w /dev/tty ]; }+# `[ -r/-w /dev/tty ]` is not enough: the char device can exist while opening it+# fails with ENXIO when the process has no controlling terminal, which made+# non-interactive (piped) runs die inside tty_print's redirect. Test the real open.+tty_ok() { { : </dev/tty; } 2>/dev/null && { : >/dev/tty; } 2>/dev/null; }tty_print() { if tty_ok; then printf '%s' "$*" > /dev/tty; else printf '%s' "$*"; fi; }tty_line() {local prompt="$1" default="${2-}" value=""diff --git a/scripts/mso-cli-agent.sh b/scripts/mso-cli-agent.shindex 8f93a211..779f90de 100755--- a/scripts/mso-cli-agent.sh+++ b/scripts/mso-cli-agent.sh@@ -141,61 +141,10 @@ print_model_catalog() {}-configure_oauth_provider() {- local provider="$1" response code url interval poll- [ "$provider" = "openai-codex" ] || die "OAuth provider not supported yet: $provider"- response=$(jpost "/api/oauth/openai" '{"action":"start","select":false}')- code=$(jq -r '.userCode // empty' <<<"$response"); url=$(jq -r '.verificationUrl // empty' <<<"$response"); interval=$(jq -r '.intervalMs // 5000' <<<"$response")- [ -n "$code" ] && [ -n "$url" ] || die "OpenAI OAuth did not return a device code"- echo "Open this URL in any browser: $url"- echo "Enter code: $code"- echo "Waiting for authorization (active model will NOT change)..."- while true; do- poll_seconds=$((interval / 1000))- [ "$poll_seconds" -gt 2 ] || poll_seconds=3- sleep "$poll_seconds"- poll=$(jpost "/api/oauth/openai" '{"action":"poll","select":false}')- if [ "$(jq -r '.ok // false' <<<"$poll")" = true ]; then- echo " ✓ connected $(jq -r '.slug' <<<"$poll"); model selection unchanged"- return- fi- [ "$(jq -r '.pending // false' <<<"$poll")" = true ] || die "OpenAI OAuth failed: $poll"- tty_print "."- done-}--configure_ai_provider() {- local provider="$1" key body name base protocol models- case "$provider" in- chatgpt|codex) provider=openai-codex ;;- esac- case "$provider" in- openai-codex) configure_oauth_provider "$provider"; return ;;- custom)- tty_ok || die "custom provider setup needs an interactive terminal"- tty_line "Provider name: " ""; name="$REPLY"; [ -n "$name" ] || die "provider name required"- tty_line "Base URL (https://.../v1): " ""; base="$REPLY"; [ -n "$base" ] || die "base URL required"- tty_line "Protocol [openai|anthropic] [openai]: " "openai"; protocol="$REPLY"- case "$protocol" in- openai|anthropic) ;;- *) die "protocol must be openai or anthropic" ;;- esac- tty_line "Models (comma/newline IDs; optional): " ""; models="$REPLY"- tty_secret "API key: "; key="$REPLY"; [ -n "$key" ] || die "empty API key"- body=$(printf '%s\0%s\0%s\0%s\0%s' "$name" "$base" "$protocol" "$key" "$models" | custom_provider_body_unselected)- secret_post "/api/config" "$body" >/dev/null- unset key body REPLY- echo " ✓ custom provider configured; active model unchanged"- return ;;- *) ai_provider_supported "$provider" || die "unknown/unsupported AI provider '$provider'; run: mso models free or mso models add" ;;- esac- tty_ok || die "provider setup needs an interactive terminal"- tty_secret "Paste $provider API key: "; key="$REPLY"; [ -n "$key" ] || die "empty API key"- body=$(printf '%s\0%s' "$provider" "$key" | provider_key_body_unselected)- secret_post "/api/config" "$body" >/dev/null- unset key body REPLY- echo " ✓ $provider configured; active model unchanged"-}+# AI provider auth (OAuth device flow, key/custom endpoint): kept in its own slice+# so this file stays under the architecture line budget.+# shellcheck source=cli/ai-provider-auth.sh+source "$ROOT/scripts/cli/ai-provider-auth.sh"select_model_ref() {local requested="$1" cfg provider model candidate data@@ -263,20 +212,28 @@ run_model_setup() {run_models() {local sub="${1:-}" cfg provider action rc+ case "$sub" in+ -h|--help|help) usage_models_add; return 0 ;;+ esacensure_local_cli_device; ensure_onboard_runtime; jget "/api/auth/me" >/dev/nullcfg=$(ai_model_config)case "$sub" in- status|list) print_ai_providers "$cfg" ;;+ status|list)+ if [ -n "${2-}" ]; then+ ai_provider_connected "$2" "$cfg" && echo "$2 connected" || { echo "$2 not connected"; return 1; }+ else print_ai_providers "$cfg"; fi ;;free) print_free_ai_options "${2:-}" ;;add|auth)provider="${2-}"+ if [ "$provider" = "-h" ] || [ "$provider" = "--help" ]; then usage_models_add; return 0; fiif [ -z "$provider" ] && tty_ok; thenprovider=$(dynamic_ai_provider_picker_rows "" "" | tui_select "Connect AI platform" "") || {rc=$?; [ "$rc" -eq 130 ] && { picker_cancelled; return 0; }; return "$rc";}fi- [ -n "$provider" ] || die "usage: mso models $sub <provider>"- configure_ai_provider "$provider" ;;+ [ -n "$provider" ] || die "usage: mso models $sub <provider> [--api-key <key>] [--type api-key|oauth]"+ set -- "$provider" "${@:3}"+ configure_ai_provider "$@" ;;rm|remove)provider="${2-}"if [ -z "$provider" ] && tty_ok; thendiff --git a/scripts/mso-model-dx-contract.test.ts b/scripts/mso-model-dx-contract.test.tsindex d013efd1..0fe17465 100644--- a/scripts/mso-model-dx-contract.test.ts+++ b/scripts/mso-model-dx-contract.test.ts@@ -13,6 +13,10 @@ const providerCatalogCli = fs.readFileSync(path.join(root, "scripts/cli/ai-provider-catalog.sh"),"utf8",);+const providerAuthCli = fs.readFileSync(+ path.join(root, "scripts/cli/ai-provider-auth.sh"),+ "utf8",+);const configRoute = fs.readFileSync(path.join(root, "app/api/config/route.ts"),"utf8",@@ -30,7 +34,7 @@ const picker = fs.readFileSync("utf8",);-const all = [cli, commandOwner, agentCli, providerCatalogCli, configRoute, oauthRoute, slash, picker].join("\n");+const all = [cli, commandOwner, agentCli, providerCatalogCli, providerAuthCli, configRoute, oauthRoute, slash, picker].join("\n");describe("MSO model/provider/session CLI contract", () => {it("keeps provider auth (`models`) separate from active selection (`model`)", () => {@@ -41,6 +45,7 @@ describe("MSO model/provider/session CLI contract", () => {expect(agentCli).toContain("run_model_setup()");expect(agentCli).toContain("provider_key_body_unselected");expect(agentCli).toContain("custom_provider_body_unselected");+ expect(providerAuthCli).toContain("configure_ai_provider()");expect(all).toContain("select:false");expect(configRoute).toContain("body.select !== false");expect(oauthRoute).toContain("body.select === true");@@ -71,6 +76,16 @@ describe("MSO model/provider/session CLI contract", () => {expect(providerCatalogCli).toContain('provider account/key and rate limits may still apply');});+ it("adds providers hermes-style: non-interactive flags plus a status <provider> probe", () => {+ expect(providerAuthCli).toContain("usage_models_add()");+ expect(providerAuthCli).toContain("--api-key <key>");+ expect(providerAuthCli).toContain("--type api-key|oauth");+ expect(agentCli).toContain('case "$sub" in\n -h|--help|help) usage_models_add');+ // Picker must not use fs.readFileSync(0): a non-blocking pipe throws EAGAIN.+ expect(picker).toContain("readStdinSync");+ expect(picker).not.toContain("readFileSync(0");+ });+it("supports explicit and slash-containing model IDs without losing provider intent", () => {expect(agentCli).toContain("Model IDs themselves may contain slashes");expect(agentCli).toContain("mso model set <provider> <model>");diff --git a/scripts/mso-tui-select.mjs b/scripts/mso-tui-select.mjsindex 07c32439..5a077f0a 100755--- a/scripts/mso-tui-select.mjs+++ b/scripts/mso-tui-select.mjs@@ -25,6 +25,30 @@ const pad = (value, max) => {return out + " ".repeat(Math.max(0, max - visibleWidth(out)));};+// Read all of fd 0 without fs.readFileSync: a non-blocking pipe makes readFileSync+// throw EAGAIN instead of waiting for the producer to write the candidate rows.+function readStdinSync() {+ const chunks = [];+ const buf = Buffer.alloc(65536);+ const sleeper = new Int32Array(new SharedArrayBuffer(4));+ for (;;) {+ let n;+ try {+ n = fs.readSync(0, buf, 0, buf.length, null);+ } catch (error) {+ if (error && error.code === "EAGAIN") {+ Atomics.wait(sleeper, 0, 0, 5);+ continue;+ }+ if (error && error.code === "EOF") break;+ throw error;+ }+ if (!n) break;+ chunks.push(Buffer.from(buf.subarray(0, n)));+ }+ return Buffer.concat(chunks).toString("utf8");+}+export function parsePickerItems(raw) {return String(raw || "").split(/\r?\n/).filter(Boolean).map((line) => {const [value = "", label = "", meta = "", state = ""] = line.split("\t");@@ -80,7 +104,7 @@ function panel(items, selected, title, query, columns) {async function run() {const title = clean(process.argv[2] || "Select");const activeValue = String(process.argv[3] || "");- const items = parsePickerItems(fs.readFileSync(0, "utf8"));+ const items = parsePickerItems(readStdinSync());if (!items.length) process.exit(2);// One read/write descriptor: no separate pathname check/open or truncating open.