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.

3.9 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { slashCompletionItems } from "./mso-agent-slash.mjs";

const skills = {
  skills: [
    { id: "global-design", name: "design", trust: "local", description: "global design helper" },
    { id: "root/a/design", name: "design", trust: "local", description: "project design helper", project: { id: "root/a", name: "alpha", path: "/srv/alpha" } },
    { id: "root/a/ship-check", name: "ship-check", trust: "local", description: "ship alpha", project: { id: "root/a", name: "alpha", path: "/srv/alpha" } },
    { id: "unsafe", name: "unsafe", trust: "untrusted", description: "do not inject" },
  ],
};

describe("MSO Agent slash completion catalog", () => {
  it("opens the command catalog from a single slash", () => {
    const rows = slashCompletionItems(skills, "/", "/home/operator");
    expect(rows[0]).toMatchObject({ text: "/help", kind: "command" });
    expect(rows.map((row) => row.text)).toContain("/design");
    expect(rows.map((row) => row.text)).toContain("/quit");
    expect(rows.map((row) => row.text)).toContain("/agents");
    expect(rows.map((row) => row.text)).toContain("/new");
    expect(rows.map((row) => row.text)).toContain("/restart");
    expect(rows.map((row) => row.text)).toContain("/message");
    expect(rows.map((row) => row.text)).toContain("/delegate");
    expect(rows.map((row) => row.text)).toContain("/integrations");
    expect(rows.map((row) => row.text)).not.toContain("/provider");
    expect(rows.map((row) => row.text)).not.toContain("/providers");
    expect(rows.map((row) => row.text)).not.toContain("/unsafe");
  });

  it("filters live as the command token is typed", () => {
    expect(slashCompletionItems(skills, "/sess", "/home/operator").map((row) => row.text)).toEqual(["/session"]);
    expect(slashCompletionItems(skills, "/int", "/home/operator").map((row) => row.text)).toEqual(["/integrations"]);
    expect(slashCompletionItems(skills, "/prov", "/home/operator")).toEqual([]);
    expect(slashCompletionItems(skills, "/skills anything", "/home/operator")).toEqual([]);
  });

  it("recommends the current-project skill and labels its project", () => {
    const rows = slashCompletionItems(skills, "/ship", "/srv/alpha/src");
    expect(rows).toHaveLength(1);
    expect(rows[0]).toMatchObject({ text: "/ship-check", kind: "skill" });
    expect(rows[0].meta).toContain("alpha");
  });

  it("prefers a current-project skill over the same-name global skill", () => {
    const [row] = slashCompletionItems(skills, "/design", "/srv/alpha");
    expect(row.kind).toBe("skill");
    const project = "project" in row ? row.project as { id?: string } | null : null;
    expect(project?.id).toBe("root/a");
    expect(row.meta).toContain("project design helper");
  });

  it("exposes ready, queued, and invoked skill state to the slash palette", () => {
    const ready = slashCompletionItems(skills, "/design", "/home/operator")[0];
    expect(ready).toMatchObject({ kind: "skill", state: "ready", skillId: "global-design" });

    const queued = slashCompletionItems(skills, "/design", "/home/operator", {
      pendingSkill: { id: "global-design", name: "design" },
    })[0];
    expect(queued).toMatchObject({ state: "queued" });
    expect(queued.meta).toContain("queued");

    const invoked = slashCompletionItems(skills, "/design", "/home/operator", {
      lastInvokedSkill: { id: "global-design", name: "design" },
    })[0];
    expect(invoked).toMatchObject({ state: "invoked" });
    expect(invoked.meta).toContain("invoked");
  });

  it("keeps the official integrations skill behind the canonical built-in slash command", () => {
    const data = { skills: [{ id: "integrations", name: "integrations", trust: "official", description: "native integration operations" }] };
    const rows = slashCompletionItems(data, "/integrations", "/home/operator");
    expect(rows).toHaveLength(1);
    expect(rows[0]).toMatchObject({ text: "/integrations", kind: "command" });
  });

});