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.2 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { addUsage, contextStatus, estimateTokens, statusParts } from "./mso-agent-status.mjs";

describe("MSO Agent dynamic status", () => {
  it("labels provider-neutral context as an estimate and uses catalog context window", () => {
    expect(estimateTokens("abcd")).toBe(1);
    const ctx = contextStatus([{ role: "user", text: "hello world" }], { context: 128000 });
    expect(ctx.used).toBeGreaterThan(0);
    expect(ctx.limit).toBe(128000);
    expect(ctx.percent).toBeGreaterThanOrEqual(0);
  });

  it("accumulates provider-reported usage without losing fallback status", () => {
    const usage = addUsage(addUsage(null, { inputTokens: 10, outputTokens: 4 }), { input_tokens: 6, output_tokens: 2 });
    expect(usage).toEqual({ apiCalls: 2, inputTokens: 16, outputTokens: 6 });
    const parts = statusParts({
      state: { config: { provider: "openai-codex", model: "gpt-5.6-sol" }, modelMeta: { context: 128000 } },
      history: [{ role: "user", text: "hello" }], usage, agentSession: { id: "20260901_120000_deadbeef" },
    }, "/tmp");
    expect(parts.join(" ")).toContain("openai-codex/gpt-5.6-sol");
    expect(parts.join(" ")).toContain("tokens 16in/6out");
  });

  it("shows whether a skill is queued or really invoked", () => {
    const base = {
      state: { config: { provider: "openai-codex", model: "gpt-5.6-sol" }, modelMeta: null },
      history: [], usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
      agentSession: { id: "20260901_120000_deadbeef" },
    };
    const queued = statusParts({ ...base, pendingSkill: { id: "design", name: "design" } }, "/tmp").join(" ");
    expect(queued).toContain("skill ◆ /design queued");
    const invoked = statusParts({ ...base, lastInvokedSkill: { id: "design", name: "design" } }, "/tmp").join(" ");
    expect(invoked).toContain("skill ✓ /design");
  });

  it("shows compact routing/token-efficiency telemetry without putting it in model history", () => {
    const session = {
      state: { config: { provider: "openai-codex", model: "gpt-5.6-sol" }, modelMeta: { context: 128000 } },
      history: [{ role: "user", text: "check server health" }],
      usage: { inputTokens: 20, outputTokens: 5, totalTokens: 25 },
      lastRouting: { routeIds: ["server-health"], activeTools: 2, fullTools: 70, routingTextBytes: 19, historyBudgetTokens: 8000, historyEstimatedTokens: 1200, omittedRows: 4 },
      agentSession: { id: "20260901_120000_deadbeef", title: "health" },
    };
    const parts = statusParts(session, "/tmp").join(" · ");
    expect(parts).toContain("route server-health · tools 2/70");
  });

  it("uses the human session title in compact status while keeping the id for detailed diagnostics", () => {
    const session = {
      state: { config: { provider: "openai-codex", model: "gpt-5.6-sol" }, modelMeta: null },
      history: [], usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
      agentSession: { id: "20260901_120000_deadbeef", title: "test tui mso" },
    };
    const compact = statusParts(session, "/tmp").join(" · ");
    expect(compact).toContain("session test tui mso");
    expect(compact).not.toContain("permission ask");
    expect(compact).not.toContain("deadbeef");
  });

});