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): name the near-miss flag, and report what's left after a revoke

Rahmanb319d91dc9bb
diff --git a/bin/mso b/bin/mso
index 8f9f660f..0a260703 100755
--- a/bin/mso
+++ b/bin/mso
@@ -58,7 +58,7 @@
# stock <query> [page] Stock-image search (Unsplash key optional, Openverse fallback)
#
# Devices (a local file — these work while the service is down)
-# device * list | pending | approve | revoke | revoke all
+# device * list | pending | approve | revoke | revoke all --yes
# devices Alias for `device list`
# approve <id> [label] Approve a device id
# revoke <id> Revoke one device
diff --git a/bin/mso.test.ts b/bin/mso.test.ts
index b1b804f5..286d5877 100644
--- a/bin/mso.test.ts
+++ b/bin/mso.test.ts
@@ -95,7 +95,45 @@ describe("bin/mso", () => {
expect(() => withStore("device", "revoke", "all")).toThrow();
expect(fs.readFileSync(store, "utf8")).toBe(before);
+ // "-yes" is one character from "--yes"; a near miss must not silently count
+ // as confirmation, and must say which flag was actually seen.
+ let stderr = "";
+ try {
+ withStore("device", "revoke", "all", "-yes");
+ } catch (e) {
+ stderr = String((e as { stderr?: Buffer }).stderr ?? "");
+ }
+ expect(stderr).toContain('you passed "-yes"');
+ expect(fs.readFileSync(store, "utf8")).toBe(before);
+
withStore("device", "revoke", "all", "--yes");
expect(JSON.parse(fs.readFileSync(store, "utf8")).approved).toEqual({});
});
+
+ it("accepts -y as confirmation and reports what is left after a single revoke", () => {
+ const fs = require("node:fs") as typeof import("node:fs");
+ const os = require("node:os") as typeof import("node:os");
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "mso-dev-"));
+ const store = path.join(dir, "devices.json");
+ const ids = ["a".repeat(32), "b".repeat(32)];
+ const seed = () =>
+ fs.writeFileSync(
+ store,
+ JSON.stringify({ approved: { [ids[0]]: { label: "one" }, [ids[1]]: { label: "two" } }, pending: {} }),
+ );
+ const withStore = (...args: string[]) =>
+ execFileSync(CLI, args, {
+ encoding: "utf8",
+ env: { ...process.env, MSO_ENV: "/dev/null", OS_DEVICE_STORE: store },
+ });
+
+ seed();
+ withStore("device", "revoke", "all", "-y");
+ expect(JSON.parse(fs.readFileSync(store, "utf8")).approved).toEqual({});
+
+ // Revoking your last device locks you out of the UI — that has to be loud.
+ seed();
+ expect(withStore("revoke", ids[0])).toContain("1 device(s) still approved");
+ expect(withStore("revoke", ids[1])).toContain("NO devices approved");
+ });
});
diff --git a/scripts/approve-device.js b/scripts/approve-device.js
index 48470775..3cf56500 100644
--- a/scripts/approve-device.js
+++ b/scripts/approve-device.js
@@ -65,8 +65,12 @@ if (args[0] === "--revoke-all") {
const s = read();
const ids = Object.keys(s.approved);
if (!ids.length) { console.log("nothing to revoke — no approved devices"); process.exit(0); }
- if (args[1] !== "--yes") {
+ const confirm = args[1];
+ if (confirm !== "--yes" && confirm !== "-y") {
console.error(`refusing: this revokes ALL ${ids.length} approved devices and signs every browser out.`);
+ // Naming what they actually typed: "-yes" and "--yes" are one character apart
+ // and a bare "re-run with --yes" leaves them re-reading their own line.
+ if (confirm) console.error(`(you passed "${confirm}" — the flag is --yes or -y)`);
console.error("re-run with --yes if that is what you want. Re-approve later with:");
console.error(" mso device approve <deviceId> \"label\"");
process.exit(1);
@@ -88,9 +92,14 @@ if (args[0] === "--revoke") {
if (id === "all") console.error("to revoke every device: mso device revoke all --yes");
process.exit(1);
}
+ const label = s.approved[id].label;
delete s.approved[id];
write(s);
- console.log(`revoked ${id}`);
+ const left = Object.keys(s.approved).length;
+ // Say what is left, so the obvious follow-up (`device list`) isn't needed — and
+ // so revoking your last device is impossible to do without noticing.
+ console.log(`revoked ${id} "${label}"`);
+ console.log(left ? `${left} device(s) still approved.` : "NO devices approved now — nothing can sign in until you approve one.");
process.exit(0);
}