Skip to content

armgit / mso

Public Imported from GitHub
0

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.

fix(cli): four missing verbs, a prod-breaking build, and a silently-wrong --base

Rahman793dfbe499c2
diff --git a/bin/mso b/bin/mso
index 4472e24f..395e81d9 100755
--- a/bin/mso
+++ b/bin/mso
@@ -54,8 +54,9 @@
# config * BYOK provider + model: show | set | rm
# prefs * UI preferences: show | set
# models * Model catalog: list | test
-# skills Skill catalog the assistant sees
+# skills [name] Skill catalog the assistant sees; with a name, its SKILL.md
# mcp * MCP bearer tokens: list | revoke <id> | revoke all
+# oauth <prov> * Provider sign-in (device code): start | poll
# audit [n] [prefix] Audit trail, newest first (writes/exec/auth; reads are not logged)
# stock <query> [page] Stock-image search (Unsplash key optional, Openverse fallback)
#
@@ -70,7 +71,7 @@
#
# Service (local systemd)
# service * status | start | stop | restart | logs
-# build next build
+# build Compile HEAD out-of-tree (safe against the live checkout)
# deploy next build, then restart the service
#
# Escape hatches
@@ -134,7 +135,19 @@ need() { command -v "$1" >/dev/null || die "missing dependency: $1"; }
need curl; need jq
# ── local ops (no HTTP, no login) ───────────────────────────────────────────
-dev_script() { node "$ROOT/scripts/approve-device.js" "$@"; }
+# These edit ~/.mso/auth-devices.json on THIS machine. They are deliberately local
+# (they must keep working while the service is down) — but that makes them the one
+# family of verbs `--base` does not follow. Pointing at a remote host and running
+# `device approve` used to silently edit the LOCAL allowlist and report success,
+# so the operator believed they had approved a device that was still pending.
+dev_script() {
+ case "$B" in
+ http://127.0.0.1:*|http://localhost:*|http://[::1]:*) ;;
+ *) die "device commands edit the LOCAL allowlist (~/.mso/auth-devices.json) and cannot reach $B.
+ Run them ON that host, or over ssh: ssh <host> mso device $*" ;;
+ esac
+ node "$ROOT/scripts/approve-device.js" "$@"
+}
# ── auth ────────────────────────────────────────────────────────────────────
PASS="${MSO_PASSWORD:-${OS_PASSWORD:-${OS_LOGIN_PASSWORD:-}}}"
@@ -221,16 +234,17 @@ verbs() {
# so the help you get when you ask cannot disagree with the help you get when
# you're wrong.
U_camoufox="camoufox status|start|stop|session"
-U_mapp="mapp list|show <id>|logs <id>|backups <id>|jobs <id>|job <id> <jobId>|install <id>|update <id>"
+U_mapp="mapp list|show|logs|backups|jobs|job <id> <jobId>|pending <id>|install|update|power <id> <act>|cancel <id> <jobId>"
U_term="term open [cwd] [cols] [rows]|input <id> <text>|resize <id> <cols> <rows>|stream <id>|close <id>"
U_device="device list|pending|approve <id> [label]|revoke <id>|revoke all --yes"
U_service="service status|start|stop|restart|logs [n]"
-U_threads="threads list|show <id>|rm <id>"
+U_threads="threads list|show <id>|save <json>|rm <id>"
U_memory="memory list|add <text>|rm <id>"
U_config="config show|set <json>|rm <provider>"
U_prefs="prefs show|set <json>"
U_models="models list|test"
U_mcp="mcp list|revoke <id>|revoke all"
+U_oauth="oauth <provider> start|poll e.g. mso oauth openai start"
U_audit="audit [n] [prefix] e.g. mso audit 20 exec."
U_crud="crud list <dir> | get <path> | set <path> <cmd k=v…|text> | del <path> | cmds"
U_api="api <METHOD> <path> [json] e.g. mso api GET /api/v1/sys/stats"
@@ -296,7 +310,13 @@ case "$cmd" in
chk "service unit" "systemctl is-active --quiet mso.service" "mso.service not active — mso service start"
chk "reachable" "curl -fsS --max-time 5 '$B/api/health'" "nothing answering at $B"
d=$(cli_device)
- chk "device known" "dev_script --list | grep -q '$d'" "this CLI device is not approved — mso device approve $d 'mso cli'"
+ # Only meaningful against a local base — the allowlist lives on the host, and
+ # dev_script now refuses a remote one rather than reading the wrong file.
+ case "$B" in
+ http://127.0.0.1:*|http://localhost:*|http://[::1]:*)
+ chk "device known" "dev_script --list | grep -q '$d'" "this CLI device is not approved — mso device approve $d 'mso cli'" ;;
+ *) echo " -- device known (skipped: --base is remote; check it on that host)" ;;
+ esac
chk "session" "[ \"\$(rm -f '$JAR'; jget /api/auth/me | jq -r .authenticated)\" = true ]" "cannot sign in — see the checks above"
echo
[ "$fails" -eq 0 ] && echo "all good." || echo "$fails check(s) failed."
@@ -323,8 +343,15 @@ case "$cmd" in
backups) jget "/api/v1/managed-apps/$(enc "${1:?id}")/backups" ;;
jobs) jget "/api/v1/managed-apps/$(enc "${1:?id}")/jobs" ;;
job) jget "/api/v1/managed-apps/$(enc "${1:?id}")/jobs/$(enc "${2:?jobId}")" ;;
+ # Cached result only. The live probe is `update <id> check` (POST), gated.
+ pending) jget "/api/v1/managed-apps/$(enc "${1:?id}")/update" ;;
install) jpost "/api/v1/managed-apps/$(enc "${1:?id}")/install" "$(kv_args "${@:2}")" ;;
update) jpost "/api/v1/managed-apps/$(enc "${1:?id}")/update" "$(kv_args "${@:2}")" ;;
+ # start|stop|restart|backup — MANAGED_APP_ACTIONS in lib/managed-apps/types.ts.
+ power) [ -n "${2-}" ] || die "usage: mso mapp power <id> <start|stop|restart|backup>"
+ jpost "/api/v1/managed-apps/$(enc "${1:?id}")" "$(jq -n --arg a "$2" '{action:$a}')" ;;
+ cancel) [ -n "${2-}" ] || die "usage: mso mapp cancel <id> <jobId>"
+ jdel "/api/v1/managed-apps/$(enc "${1:?id}")/jobs/$(enc "$2")" ;;
*) die "usage: mso $U_mapp" ;;
esac ;;
@@ -351,6 +378,7 @@ case "$cmd" in
case "${1:-list}" in
list) jget "/api/threads" ;;
show) jget "/api/threads?id=$(enc "${2:?id}")" ;;
+ save) jpost "/api/threads" "${2:?json — {id,messages:[…]}}" ;;
rm) jdel "/api/threads?id=$(enc "${2:?id}")" ;;
*) die "usage: mso $U_threads" ;;
esac ;;
@@ -380,7 +408,7 @@ case "$cmd" in
test) jpost "/api/models/test" ;;
*) die "usage: mso $U_models" ;;
esac ;;
- skills) jget "/api/skills" ;;
+ skills) [ -n "${1-}" ] && jget "/api/skills?name=$(enc "$1")" || jget "/api/skills" ;;
stock) jget "/api/v1/stock/search?q=$(enc "${1:?query}")&page=${2:-1}" ;;
# ── devices (local file, works even when the service is down) ────────────
@@ -401,6 +429,14 @@ case "$cmd" in
dev_script "$1" "${@:2}" ;;
revoke) [ -n "${1-}" ] || die "usage: mso revoke <deviceId> (ids: mso device list)"
dev_script --revoke "$1" ;;
+ # ── provider OAuth (device-code, NOT a browser redirect) ─────────────────
+ oauth)
+ p="${1:?provider (e.g. openai)}"; sub="${2:-start}"
+ case "$sub" in
+ start|poll) jpost "/api/oauth/$(enc "$p")" "$(jq -n --arg a "$sub" '{action:$a}')" ;;
+ *) die "usage: mso $U_oauth" ;;
+ esac ;;
+
# ── MCP tokens (the bearers that let ChatGPT et al. drive this host) ─────
mcp)
case "${1:-list}" in
@@ -430,7 +466,11 @@ case "$cmd" in
logs) journalctl -u mso.service -n "${2:-50}" --no-pager ;;
*) die "usage: mso $U_service" ;;
esac ;;
- build) (cd "$ROOT" && npm run build) ;;
+ # NOT `next build` — this is mso.service's WorkingDirectory, and a build here
+ # deletes .next under the running process, 404ing every chunk until a restart.
+ # verify-build.sh compiles HEAD in a temp dir instead. `deploy` is the in-place
+ # one, and it restarts immediately after.
+ build) (cd "$ROOT" && bash scripts/verify-build.sh) ;;
deploy) (cd "$ROOT" && npm run build) && sudo systemctl restart mso.service && echo "deployed → $B" ;;
# ── editor-document CRUD (one pattern, all editor features) ──────────────
diff --git a/bin/mso.test.ts b/bin/mso.test.ts
index 81ca095c..2932fb79 100644
--- a/bin/mso.test.ts
+++ b/bin/mso.test.ts
@@ -62,32 +62,66 @@ describe("bin/mso", () => {
const p = path.join(dir, e.name);
return e.isDirectory() ? walk(p) : e.name === "route.ts" ? [p] : [];
});
- const routes = walk(path.join(repo, "app/api")).map((p) =>
- "/" + path.relative(repo, p).replace(/^app\//, "").replace(/\/route\.ts$/, ""),
- );
+ // (method, path) pairs, not paths. A path-only check passed while POST
+ // /managed-apps/[id] (start/stop/restart/backup), DELETE
+ // .../jobs/[jobId] and GET /api/skills?name= had no verb at all — the file
+ // merely mentioned the path somewhere for a DIFFERENT method.
+ const files = walk(path.join(repo, "app/api"));
+ const routes = files.flatMap((p) => {
+ const route = "/" + path.relative(repo, p).replace(/^app\//, "").replace(/\/route\.ts$/, "");
+ const src = fs.readFileSync(p, "utf8");
+ return [...src.matchAll(/export async function (GET|POST|PUT|PATCH|DELETE)\b/g)].map(
+ (m) => `${m[1]} ${route}`,
+ );
+ });
const cli = fs.readFileSync(CLI, "utf8");
- // Browser-only surfaces: an OAuth redirect needs a browser to land on, the
- // service worker is fetched by the browser itself, and the managed-app proxy
- // exists to be iframed. /api/auth/devices reads the same store `mso device
- // list` reads straight off disk, which also works with the service down.
+ // Not reachable from a shell, each for its own reason:
+ // • /api/sw is fetched by the browser to install the service worker.
+ // • the managed-app proxy exists to be iframed.
+ // • /api/auth/devices reads the same store `mso device list` reads straight
+ // off disk, which keeps working while the service is down.
+ // OAuth is NOT here any more: it is a device-code POST, not a redirect, so
+ // `mso oauth <provider> start|poll` covers it.
const browserOnly = [
- "/api/oauth/[provider]",
- "/api/sw",
+ "GET /api/sw",
"/api/v1/managed-apps/[id]/proxy/[[...path]]",
"/api/auth/devices",
];
- const uncovered = routes.filter((r) => {
- if (browserOnly.includes(r)) return false;
- // The CLI builds dynamic segments by interpolation, so compare on the
- // literal chunks either side of a [param] rather than the whole path.
- const parts = r.split("/").filter((s) => s && !s.startsWith("["));
+ // The CLI writes each call as `jget "/path"` / `jpost "/path"` / `jdel "/path"`,
+ // so the helper name carries the method. `reqraw` and a bare `req` are the
+ // escape hatches for the calls the json helpers cannot make — binary bodies
+ // (fs/raw, fs/zip), a live SSE stream (term/stream) and multipart (fs/upload)
+ // — and `curl` covers doctor's own probes. They are listed under the method
+ // they actually issue, so this stays a method check, not a free pass.
+ const HELPERS: Record<string, string[]> = {
+ GET: ["jget", "reqraw", "curl"],
+ POST: ["jpost", "req -F", "-X POST"],
+ PUT: ["jput"],
+ PATCH: ["jpatch"],
+ DELETE: ["jdel"],
+ };
+
+ const uncovered = routes.filter((mr) => {
+ const [method, route] = mr.split(" ");
+ if (browserOnly.some((b) => mr === b || route === b)) return false;
+ // Dynamic segments are built by interpolation, so match on the literal
+ // chunks either side of a [param].
+ const parts = route.split("/").filter((s) => s && !s.startsWith("["));
+ const stem = `/${parts.join("/")}`;
const tail = parts[parts.length - 1];
- return !cli.includes(`/${parts.join("/")}`) && !cli.includes(`/${tail}"`) && !cli.includes(`/${tail}?`);
+ return !HELPERS[method].some((h) => {
+ const i = cli.indexOf(h);
+ if (i < 0) return false;
+ // Look for the helper and the path on the same line.
+ return cli
+ .split("\n")
+ .some((line) => line.includes(h) && (line.includes(stem) || line.includes(`/${tail}"`) || line.includes(`/${tail}?`) || line.includes(`/${tail}/`)));
+ });
});
expect(uncovered).toEqual([]);
- expect(routes.length).toBeGreaterThan(40);
+ expect(routes.length).toBeGreaterThan(50);
});
it("refuses `device revoke all` without --yes, and leaves the store intact", () => {
diff --git a/docs/CLI.md b/docs/CLI.md
index fc9318f2..6c6f1b5f 100644
--- a/docs/CLI.md
+++ b/docs/CLI.md
@@ -88,8 +88,9 @@ Commands:
config * BYOK provider + model: show | set | rm
prefs * UI preferences: show | set
models * Model catalog: list | test
- skills Skill catalog the assistant sees
+ skills [name] Skill catalog the assistant sees; with a name, its SKILL.md
mcp * MCP bearer tokens: list | revoke <id> | revoke all
+ oauth <prov> * Provider sign-in (device code): start | poll
audit [n] [prefix] Audit trail, newest first (writes/exec/auth; reads are not logged)
stock <query> [page] Stock-image search (Unsplash key optional, Openverse fallback)
@@ -104,7 +105,7 @@ Commands:
Service (local systemd)
service * status | start | stop | restart | logs
- build next build
+ build Compile HEAD out-of-tree (safe against the live checkout)
deploy next build, then restart the service
Escape hatches